From 59c49dea4e9a92836b1a5d9e4071fb09c9675da7 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 16 Jan 2024 13:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=85=91=E6=8D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B6=88=E8=B4=B9=E8=80=85=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/Exchange.php | 67 ++++++++++++++++++++++++++-- route/api.php | 3 +- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/app/controller/api/user/Exchange.php b/app/controller/api/user/Exchange.php index cb93371..fb76485 100644 --- a/app/controller/api/user/Exchange.php +++ b/app/controller/api/user/Exchange.php @@ -11,6 +11,7 @@ use app\common\model\user\User; use app\common\repositories\user\ExchangePickupPointRepository; use app\common\repositories\user\ExchangePickupRecordRepository; use app\common\repositories\user\ExchangeQuotaRepository; +use app\common\repositories\user\UserRepository; use crmeb\basic\BaseController; use crmeb\services\QrcodeService; use crmeb\services\wechat\MiniProgram; @@ -32,7 +33,10 @@ class Exchange extends BaseController{ * @return mixed */ public function getUserHold(){ + $params = $this->request->params(['consume_uid']); $uid = $this->request->uid(); + // 判断:是否存在指定消费者,不存在则使用当前登录用户 + $uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid; // 获取额度 $info = app()->make(ExchangeQuotaRepository::class) ->getSearch([]) @@ -43,7 +47,8 @@ class Exchange extends BaseController{ ]) ->where('uid',$uid) ->findOrEmpty(); - $info->available_integral = $this->user->exchange_integral; + $info->available = (float)$info->available; + $info->available_integral = (float)$this->user->exchange_integral; $info->diff_rate = 30;// 差价 应补金额,默认为30% return app('json')->success($info); @@ -71,10 +76,12 @@ class Exchange extends BaseController{ public function exchangeHandle(){ // 参数获取 $uid = $this->request->uid(); - $data = $this->request->params(['total_money','use_integral','diff_money','diff_money_pay','point_id','staff_uid']); + $data = $this->request->params(['total_money','use_integral','diff_money','diff_money_pay','point_id','staff_uid','consume_uid']); if ((float)$data['total_money'] <= 0) return app('json')->fail('价值必须大于0!'); if ((float)$data['point_id'] <= 0) return app('json')->fail('请选择提货点!'); if ((float)$data['staff_uid'] <= 0) return app('json')->fail('请选择操作员!'); + // 判断:是否存在指定消费者,不存在则使用当前登录用户 + $uid = (int)$data['consume_uid'] > 0 ? (int)$data['consume_uid'] : $uid; if ($data['staff_uid'] == $uid) return app('json')->fail('操作员和消费用户不能是同一人!'); // 添加兑换记录 try{ @@ -149,6 +156,33 @@ class Exchange extends BaseController{ return app('json')->success($data); } + /** + * Common: 获取消费者列表 + * Author: wu-hui + * Time: 2024/01/16 11:16 + * @return mixed + */ + public function getConsumeList(){ + $search = $this->request->params(['search_text', 'default_consume_id']); + $list = app()->make(UserRepository::class) + ->getSearch([]) + ->field(['uid','real_name','nickname','avatar','phone']) + ->where(function($query) use ($search){ + // 用户ID/用户昵称/真实姓名/联系电话 + $query->where('uid',$search['search_text']) + ->whereOr('nickname','like',"%{$search['search_text']}%") + ->whereOr('real_name','like',"%{$search['search_text']}%") + ->whereOr('phone','like',"%{$search['search_text']}%"); + }) + ->when(isset($search['default_consume_id']) && $search['default_consume_id'] > 0,function($query) use ($search){ + $query->where('uid',$search['default_consume_id']); + }) + ->page(1, 30) + ->select() + ->toArray(); + + return app('json')->success($list); + } /** @@ -181,7 +215,7 @@ class Exchange extends BaseController{ return app('json')->success($data); } /** - * Common: 获取兑换二维码显示 + * Common: 获取兑换二维码显示(操作员二维码) * Author: wu-hui * Time: 2024/01/15 14:37 * @return mixed @@ -210,7 +244,34 @@ class Exchange extends BaseController{ return app('json')->fail('小程序码生成失败!'); } + /** + * Common: 获取兑换二维码(用户二维码) + * Author: wu-hui + * Time: 2024/01/16 10:17 + * @return mixed + */ + public function userQrCode(){ + // 参数获取 + $uid = $this->request->uid(); + if((int)$uid > 0){ + try{ + $valueData = 'consume_uid=' . $uid; + $name = md5('consume_qrcode_'.$valueData) . '.jpg'; + $qrcode = app()->make(QrcodeService::class)->getRoutineQrcodePath($name, 'pages/users/online_payment/exchange/index', $valueData); + if (!$qrcode) throw new \Exception('二维码生成失败'); + 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')->fail('小程序码生成失败!'); + } } diff --git a/route/api.php b/route/api.php index a66e41f..5955b03 100644 --- a/route/api.php +++ b/route/api.php @@ -353,11 +353,12 @@ Route::group('api/', function () { Route::get('userHold', 'Exchange/getUserHold'); Route::get('exchangeHandle', 'Exchange/exchangeHandle'); Route::get('exchangeRecord', 'Exchange/exchangeRecord'); + Route::get('consumeList', 'Exchange/getConsumeList'); // 站点管理相关 Route::get('site_list', 'Exchange/siteList'); Route::get('site_exchange_record', 'Exchange/siteExchangeRecord'); Route::get('site_qr_code', 'Exchange/siteQrCode'); - + Route::get('user_qr_code', 'Exchange/userQrCode'); })->prefix('api.user.');