From cac4627b4a27801877b1aa486cf4d8bc658e0c1b Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 23 Jan 2024 14:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=95=86=E6=88=B7?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/merchant/MerchantRepository.php | 27 ++++++++++++++ .../api/store/merchant/Merchant.php | 35 ++++++++++--------- app/controller/api/store/order/OnlinePay.php | 5 ++- crmeb/services/QrcodeService.php | 27 ++++++++++++++ route/api.php | 1 + 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 2d4b5da..ce3722e 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -843,4 +843,31 @@ class MerchantRepository extends BaseRepository $data['mer_certificate'] = merchantConfig($id, 'mer_certificate'); return $data; } + /** + * Common: 二维码生成 + * Author: wu-hui + * Time: 2024/01/23 14:27 + * @param array $data + * @param string $type + * @return mixed + */ + public function createQrCode(array $data,string $type = 'promote'){ + // 参数获取 + switch($type){ + case 'promote': + $valueData = 'mer_id=' . $data['mer_id']; + $path = 'pages/annex/vip_center/index'; + return app()->make(QrcodeService::class)->createQrCode($valueData,$path); + break; + case 'online_payment': + $valueData = 'mer_id=' . $data['mer_id']; + $path = 'pages/users/online_payment/payment/index'; + return app()->make(QrcodeService::class)->createQrCode($valueData,$path); + break; + } + + throw new ValidateException('小程序码生成失败!'); + } + + } diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index cf4166e..0579ddd 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -116,22 +116,26 @@ class Merchant extends BaseController // 参数获取 $merId = $this->request->param('mer_id'); if((int)$merId > 0){ - try{ - // 生成参数 - $valueData = 'mer_id=' . $merId; - $path = 'pages/annex/vip_center/index'; - $name = md5($path . $valueData) . '.jpg'; - $qrcode = app()->make(QrcodeService::class)->getRoutineQrcodePath($name, $path, $valueData); - if (!$qrcode) throw new \Exception('二维码生成失败'); + $qrcode = $this->repository->createQrCode(['mer_id'=>$merId]); - return app('json')->success([ - 'qr_code' => $qrcode - ]); - }catch(\Exception $e){ - return app('json')->fail($e->getMessage()); - }catch(\Throwable $e){ - return app('json')->fail($e->getMessage()); - } + return app('json')->success(['qr_code' => $qrcode]); + } + + return app('json')->fail('小程序码生成失败!'); + } + /** + * Common: 员工买单二维码 + * Author: wu-hui + * Time: 2024/01/23 13:56 + * @return mixed + */ + public function onlinePaymentQrCode(){ + // 参数获取 + $merId = $this->request->param('mer_id'); + if((int)$merId > 0){ + $qrcode = $this->repository->createQrCode(['mer_id'=>$merId],'online_payment'); + + return app('json')->success(['qr_code' => $qrcode]); } return app('json')->fail('小程序码生成失败!'); @@ -139,5 +143,4 @@ class Merchant extends BaseController - } diff --git a/app/controller/api/store/order/OnlinePay.php b/app/controller/api/store/order/OnlinePay.php index 9f1d7fe..8b5c510 100644 --- a/app/controller/api/store/order/OnlinePay.php +++ b/app/controller/api/store/order/OnlinePay.php @@ -16,7 +16,7 @@ class OnlinePay extends BaseController{ * @return mixed */ public function searchMer(){ - $search = $this->request->params(['search_text']); + $search = $this->request->params(['search_text','mer_id']); // if(empty($search['search_text'])) return app('json')->fail('请输入搜索内容!'); // 内容查询 $list = app()->make(MerchantRepository::class) @@ -29,6 +29,9 @@ class OnlinePay extends BaseController{ $query->where('mer_name','like',"%{$search['search_text']}%") ->whereOr('mer_address','like',"%{$search['search_text']}%"); }) + ->when((int)$search['mer_id'] > 0,function($query) use ($search){ + $query->where('mer_id',$search['mer_id']); + }) ->order('create_time desc,mer_id desc') ->limit(100) ->select() diff --git a/crmeb/services/QrcodeService.php b/crmeb/services/QrcodeService.php index 1b56cf5..8a54d26 100644 --- a/crmeb/services/QrcodeService.php +++ b/crmeb/services/QrcodeService.php @@ -10,6 +10,7 @@ use app\common\repositories\system\attachment\AttachmentRepository; use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\wechat\RoutineQrcodeRepository; use Endroid\QrCode\QrCode; +use think\exception\ValidateException; use think\facade\Config; class QrcodeService @@ -182,4 +183,30 @@ class QrcodeService } } + /** + * Common: 二维码生成 + * Author: wu-hui + * Time: 2024/01/23 14:20 + * @param $valueData + * @param $path + * @return mixed + */ + public function createQrCode($valueData,$path){ + // 参数获取 + try{ + // 生成参数 + $name = md5($path . $valueData) . '.jpg'; + $qrcode = $this->getRoutineQrcodePath($name, $path, $valueData); + if (!$qrcode) throw new \Exception('二维码生成失败'); + + return $qrcode; + }catch(\Exception $e){ + throw new ValidateException($e->getMessage()); + }catch(\Throwable $e){ + throw new ValidateException($e->getMessage()); + } + } + + + } diff --git a/route/api.php b/route/api.php index f642c1f..72edefe 100644 --- a/route/api.php +++ b/route/api.php @@ -380,6 +380,7 @@ Route::group('api/', function () { // 移动端商户管理 Route::group('merchant', function () { Route::get('promote_qr_code', 'Merchant/promoteQrCode');// 推广二维码 + Route::get('online_payment_qr_code', 'Merchant/onlinePaymentQrCode');// 买单二维码