From 3a37efbc2b67a86b26794fc05b3dba7bf7f11bef Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 12 Jan 2024 17:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E4=B9=B0=E5=8D=95=E8=AE=B0=E5=BD=95=E6=9F=A5=E7=9C=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E4=B9=B0=E5=8D=95=E6=94=AF=E4=BB=98=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?=E8=B5=A0=E9=80=81=E5=85=91=E6=8D=A2=E7=A7=AF=E5=88=86=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=85=91=E6=8D=A2=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E6=8C=81=E6=9C=89=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/user/ExchangeIntegralRecordDao.php | 23 ++++++++ .../model/user/ExchangeIntegralRecord.php | 47 +++++++++++++++ .../store/order/StoreOrderRepository.php | 50 ++++++++++++++++ .../user/ExchangeIntegralRecordRepository.php | 50 ++++++++++++++++ app/controller/admin/order/Order.php | 37 ++++++++++++ app/controller/admin/user/ExchangeQuota.php | 59 +++++++++++++++++++ .../exchangeQuota/OrderPaySuccessEvent.php | 40 ++++++++++++- route/admin/marketing.php | 14 +++++ route/admin/order.php | 20 ++++++- 9 files changed, 336 insertions(+), 4 deletions(-) create mode 100644 app/common/dao/user/ExchangeIntegralRecordDao.php create mode 100644 app/common/model/user/ExchangeIntegralRecord.php create mode 100644 app/common/repositories/user/ExchangeIntegralRecordRepository.php diff --git a/app/common/dao/user/ExchangeIntegralRecordDao.php b/app/common/dao/user/ExchangeIntegralRecordDao.php new file mode 100644 index 0000000..c2eaccb --- /dev/null +++ b/app/common/dao/user/ExchangeIntegralRecordDao.php @@ -0,0 +1,23 @@ +hasOne(User::class, 'uid', 'uid'); + } + + +} diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 8da4c06..82f4f94 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2443,4 +2443,54 @@ class StoreOrderRepository extends BaseRepository if (!$order) return null; return $order; } + + /** + * Common: 在线买单 - 统计 + * Author: wu-hui + * Time: 2024/01/12 16:54 + * @return array + */ + public function getOnlineOrderStat():array{ + $model = $this->dao->getSearch([])->where('activity_type',30); + return [ + 'total_pay_price' => $model->sum('pay_price'),// 总买单金额 + 'total_people_num' => $model->count('uid'),// 参与人数 + ]; + } + /** + * Common: 在线买单 - 记录列表获取 + * Author: wu-hui + * Time: 2024/01/12 17:01 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function getOnlineOrderList(array $params,int $page,int $limit):array{ + $query = $this->dao->getSearch([]) + ->when((int)$params['uid'] > 0,function($query) use ($params){ + $query->where('uid', (int)$params['uid']); + }) + ->when((int)$params['mer_id'] > 0,function($query) use ($params){ + $query->where('mer_id', (int)$params['mer_id']); + }) + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar')->bind(['nickname','avatar']); + }, + 'merchant' => function($query){ + $query->field('mer_id,mer_name,mer_avatar')->bind(['mer_name','mer_avatar']); + }, + ]) + ->order('create_time DESC,order_id DESC'); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list'); + } + + } diff --git a/app/common/repositories/user/ExchangeIntegralRecordRepository.php b/app/common/repositories/user/ExchangeIntegralRecordRepository.php new file mode 100644 index 0000000..0b9f5a0 --- /dev/null +++ b/app/common/repositories/user/ExchangeIntegralRecordRepository.php @@ -0,0 +1,50 @@ +dao = $dao; + } + /** + * Common: 获取信息列表 + * Author: wu-hui + * Time: 2024/01/12 17:25 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $params,int $page,int $limit):array{ + $query = $this->dao->getSearch([]) + ->when((int)$params['uid'] > 0,function($query) use ($params){ + $query->where('uid', (int)$params['uid']); + }) + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar')->bind(['nickname','avatar']); + } + ]) + ->order('create_time DESC,id DESC'); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list'); + } + + + + + + + +} diff --git a/app/controller/admin/order/Order.php b/app/controller/admin/order/Order.php index 1517f08..1dcbaee 100644 --- a/app/controller/admin/order/Order.php +++ b/app/controller/admin/order/Order.php @@ -208,4 +208,41 @@ class Order extends BaseController $data = $this->repository->childrenList($id, 0); return app('json')->success($data); } + /** + * Common: 在线买单 - 统计信息 + * Author: wu-hui + * Time: 2024/01/12 16:58 + * @return mixed + */ + public function onlineTitle(){ + $statInfo = $this->repository->getOnlineOrderStat(); + + $data = [ + ['className' => 'el-icon-coin','count' => $statInfo['total_pay_price'],'field' => '元','name' => '总金额'], + ['className' => 'el-icon-coin','count' => $statInfo['total_people_num'],'field' => '元','name' => '买单次数'], + ]; + + return app('json')->success($data); + } + /** + * Common: 在线买单 - 信息列表 + * Author: wu-hui + * Time: 2024/01/12 17:01 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function onlineList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['uid','mer_id']); + + $data = $this->repository->getOnlineOrderList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + + + + } diff --git a/app/controller/admin/user/ExchangeQuota.php b/app/controller/admin/user/ExchangeQuota.php index e5bea74..2d8cf8e 100644 --- a/app/controller/admin/user/ExchangeQuota.php +++ b/app/controller/admin/user/ExchangeQuota.php @@ -2,9 +2,11 @@ namespace app\controller\admin\user; +use app\common\repositories\user\ExchangeIntegralRecordRepository; use app\common\repositories\user\ExchangeQuotaRecordRepository; use app\common\repositories\user\ExchangeQuotaRepository; use crmeb\basic\BaseController; +use app\common\model\user\User; class ExchangeQuota extends BaseController @@ -59,5 +61,62 @@ class ExchangeQuota extends BaseController } + /** + * Common: 兑换积分 - 统计 + * Author: wu-hui + * Time: 2024/01/12 17:38 + * @return mixed + */ + public function integralTitle(){ + $model = new User(); + + $data = [ + ['className' => 'el-icon-coin','count' => $model->sum('exchange_integral'),'field' => '分','name' => '总兑换积分'], + ]; + + return app('json')->success($data); + } + /** + * Common: 兑换积分 - 额度持有信息 + * Author: wu-hui + * Time: 2024/01/12 17:39 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function integralList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['uid']); + + $query = (new User()) + ->when((int)$params['uid'] > 0,function($query) use ($params){ + $query->where('uid', (int)$params['uid']); + }) + ->where('exchange_integral','>',0) + ->order('create_time DESC,uid DESC'); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return app('json')->success(compact('count','list')); + } + /** + * Common: 兑换积分 - 变更记录 + * Author: wu-hui + * Time: 2024/01/12 17:40 + * @return mixed + */ + public function integralRecordList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['uid']); + + $data = app()->make(ExchangeIntegralRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + + + + } diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index 8314125..63919d6 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -2,8 +2,10 @@ namespace app\listener\exchangeQuota; +use app\common\model\user\ExchangeIntegralRecord; use app\common\model\user\ExchangeQuota; use app\common\model\user\ExchangeQuotaRecord; +use app\common\model\user\User; use think\facade\Log; class OrderPaySuccessEvent{ @@ -13,7 +15,13 @@ class OrderPaySuccessEvent{ $groupOrder = $groupOrder['groupOrder']; try{ // Log::info('支付成功 - 赠送兑换额度 - 开始: '.var_export(['uid'=>$groupOrder->uid,'group_order_id'=>$groupOrder->group_order_id],1)); - $this->orderPaySuccessHandle($groupOrder); + if($groupOrder->activity_type == 30){ + // 在线支付订单 + $this->giveExchangeIntegral($groupOrder); + }else{ + // 其他订单 + $this->orderPaySuccessHandle($groupOrder); + } }catch(\Exception $e){ $data = [ @@ -62,6 +70,36 @@ class OrderPaySuccessEvent{ return true; } + // 支付成功 - 赠送兑换积分 + public function giveExchangeIntegral($groupOrder){ + // 获取用户当前持有 + $userHoldInfo = User::where('uid',$groupOrder->uid)->findOrEmpty(); + // 循环处理单个商品 + $insertData = []; + foreach($groupOrder->orderList as $orderInfo){ + // 赠送 支付的金额=赠送的兑换积分 + $changeFront = (float)$userHoldInfo->exchange_integral; + $userHoldInfo->exchange_integral += (float)$orderInfo->pay_price;// 总额度 + // 记录 + $insertData[] = [ + 'uid' => $orderInfo->uid, + 'product_id' => $orderInfo->product_id ?? 0, + 'order_id' => $orderInfo->order_id ?? 0, + 'order_product_id' => $orderInfo->order_product_id ?? 0, + 'change_type' => 1, + 'change_quantity' => (float)$orderInfo->pay_price, + 'change_front' => $changeFront, + 'change_after' => (float)$userHoldInfo->exchange_integral, + 'remark' => "消费赠送兑换积分", + ]; + } + // 修改用户持有 + $userHoldInfo->save(); + // 记录兑换额度信息 + if(count($insertData) > 0) ExchangeIntegralRecord::insertAll($insertData); + + return true; + } diff --git a/route/admin/marketing.php b/route/admin/marketing.php index 69410fd..b6e2940 100644 --- a/route/admin/marketing.php +++ b/route/admin/marketing.php @@ -427,6 +427,7 @@ Route::group(function () { ]); // 兑换额度 Route::group('user/exchange_quota', function () { + // 兑换额度相关 Route::get('quota_title','.ExchangeQuota/quotaTitle')->name('systemUserExchangeQuotaTitle')->option([ '_alias' => '额度统计', ]); @@ -436,6 +437,19 @@ Route::group(function () { Route::get('quota_record_list', '.ExchangeQuota/quotaRecordList')->name('systemUserExchangeQuotaRecordList')->option([ '_alias' => '额度变更记录', ]); + // 兑换积分相关 + Route::get('integral_title','.ExchangeQuota/integralTitle')->name('systemUserExchangeIntegralTitle')->option([ + '_alias' => '额度统计', + ]); + Route::get('integral_list', '.ExchangeQuota/integralList')->name('systemUserExchangeIntegralList')->option([ + '_alias' => '额度持有信息', + ]); + Route::get('integral_record_list', '.ExchangeQuota/integralRecordList')->name('systemUserExchangeIntegralRecordList')->option([ + '_alias' => '额度变更记录', + ]); + + + diff --git a/route/admin/order.php b/route/admin/order.php index 960caeb..2eb50e5 100644 --- a/route/admin/order.php +++ b/route/admin/order.php @@ -37,7 +37,6 @@ Route::group(function () { '_path' => '/promoter/orderList', '_auth' => true, ])->append(['is_spread' => 1]); - Route::group('order', function () { Route::get('lst', 'Order/getAllList')->name('systemOrderLst')->option([ '_alias' => '列表', @@ -81,7 +80,6 @@ Route::group(function () { ], ] ]); - Route::group('order', function () { Route::get('take_title', 'Order/takeTitle')->name('systemOrderTakeStat')->option([ @@ -97,7 +95,6 @@ Route::group(function () { '_path' => '/order/cancellation', '_auth' => true, ]); - Route::group('order', function () { Route::get('refund/lst', 'RefundOrder/getAllList')->name('systemRefundOrderLst')->option([ '_alias' => '列表', @@ -124,6 +121,23 @@ Route::group(function () { ] ]); + Route::group('order', function () { + Route::get('online_title', 'Order/onlineTitle')->name('systemOrderOnlineTitle')->option([ + '_alias' => '在线买单统计', + ]); + Route::get('online_list', 'Order/onlineList')->name('systemOrderOnlineList')->option([ + '_alias' => '在线买单列表', + ]); + })->prefix('admin.order.')->option([ + '_path' => '/order/onlinePay', + '_auth' => true, + ]); + + + + + + })->middleware(AllowOriginMiddleware::class) ->middleware(AdminTokenMiddleware::class, true)