优化:商户相关二维码生成流程优化

This commit is contained in:
wuhui_zzw 2024-01-23 14:33:51 +08:00
parent 647e1601de
commit cac4627b4a
5 changed files with 78 additions and 17 deletions

View File

@ -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('小程序码生成失败!');
}
}

View File

@ -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
}

View File

@ -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()

View File

@ -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());
}
}
}

View File

@ -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');// 买单二维码