From 5d3a8f685f958db45a26c99fe6f465a2f9a8b2bb Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 18 Jun 2024 16:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E9=85=8D=E9=80=81?= =?UTF-8?q?=E5=95=86=E7=BC=B4=E8=B4=B9=E8=AE=A2=E5=8D=95=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=8F=8A=E5=88=86=E9=85=8D=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/marketing/agent/AgentDeliveryDao.php | 39 +++++++---- .../model/marketing/agent/AgentDelivery.php | 7 +- .../agent/AgentDeliveryRepository.php | 70 +++++++++++++++++++ .../api/marketing/agent/Delivery.php | 44 ++++++++++-- .../exchangeQuota/OrderPaySuccessEvent.php | 8 +-- route/api.php | 2 +- 6 files changed, 144 insertions(+), 26 deletions(-) diff --git a/app/common/dao/marketing/agent/AgentDeliveryDao.php b/app/common/dao/marketing/agent/AgentDeliveryDao.php index b3a4b7f..56e70f7 100644 --- a/app/common/dao/marketing/agent/AgentDeliveryDao.php +++ b/app/common/dao/marketing/agent/AgentDeliveryDao.php @@ -18,27 +18,40 @@ class AgentDeliveryDao extends BaseDao{ * @return AgentDelivery */ public function searchList(array $params){ - return (new AgentDelivery()) - ->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ - $query->where('id', (int)$params['id']); + return (new AgentDelivery())->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ + $query->where('id',(int)$params['id']); }) - ->when(isset($params['agent_id']) && $params['agent_id'] !== '',function($query) use ($params){ - $query->where('agent_id', (int)$params['agent_id']); + ->when(isset($params['agent_id']) && $params['agent_id'] !== '',function($query) use ($params){ + $query->where('agent_id',(int)$params['agent_id']); }) - ->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){ - $query->where('mer_id', (int)$params['mer_id']); + ->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){ + $query->where('mer_id',(int)$params['mer_id']); }) - ->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){ - $query->where('status', $params['status']); + ->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){ + $query->where('status',$params['status']); }) - ->when(isset($params['order_id']) && $params['order_id'] !== '',function($query) use ($params){ - $query->where('order_id', $params['order_id']); + ->when(isset($params['order_id']) && $params['order_id'] !== '',function($query) use ($params){ + $query->where('order_id',$params['order_id']); + }) + ->when(isset($params['is_bind']) && $params['is_bind'] !== '',function($query) use ($params){ + // 判断:缴费记录是否绑定商户 + $query->where('mer_id', $params['is_bind'] == 'bind' ? '>' : '<=' , 0); }) ->with([ - 'agent', - 'mer' => function($query){ + 'agent' => function($query){ + $query->field('id,uid,contact_name,contact_phone') + ->with([ + 'user' => function($query){ + $query->field('uid,nickname,avatar,phone')->bind(['nickname','avatar','phone']); + } + ]); + }, + 'mer' => function($query){ $query->field('mer_id,mer_name,mer_avatar'); }, + 'store_order' => function($query){ + $query->field('order_id,order_sn,pay_price,group_order_id,status'); + }, ]) ->order('create_time DESC,id DESC'); } diff --git a/app/common/model/marketing/agent/AgentDelivery.php b/app/common/model/marketing/agent/AgentDelivery.php index b5f7c88..ad02733 100644 --- a/app/common/model/marketing/agent/AgentDelivery.php +++ b/app/common/model/marketing/agent/AgentDelivery.php @@ -4,6 +4,7 @@ namespace app\common\model\marketing\agent; use app\common\model\BaseModel; use app\common\model\marketing\Agent; +use app\common\model\store\order\StoreOrder; use app\common\model\system\merchant\Merchant; class AgentDelivery extends BaseModel{ @@ -20,14 +21,16 @@ class AgentDelivery extends BaseModel{ public function agent(){ - return $this->hasOne(Agent::class, 'agent_id', 'id'); + return $this->hasOne(Agent::class, 'id', 'agent_id'); } public function mer(){ return $this->hasOne(Merchant::class, 'mer_id', 'mer_id'); } - + public function storeOrder(){ + return $this->hasOne(StoreOrder::class, 'order_id', 'order_id'); + } diff --git a/app/common/repositories/marketing/agent/AgentDeliveryRepository.php b/app/common/repositories/marketing/agent/AgentDeliveryRepository.php index f54969a..4344604 100644 --- a/app/common/repositories/marketing/agent/AgentDeliveryRepository.php +++ b/app/common/repositories/marketing/agent/AgentDeliveryRepository.php @@ -9,7 +9,9 @@ use app\common\repositories\BaseRepository; use app\common\repositories\marketing\AgentRepository; use app\common\repositories\store\order\StoreOrderCreateRepository; use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\system\merchant\MerchantQuotaRecordRepository; use crmeb\services\LockService; +use think\exception\ValidateException; use think\facade\Db; class AgentDeliveryRepository extends BaseRepository{ @@ -29,6 +31,25 @@ class AgentDeliveryRepository extends BaseRepository{ public function getSearchModel($search){ return $this->dao->searchList($search); } + /** + * Common: 获取配送商缴费记录 + * Author: wu-hui + * Time: 2024/06/18 14: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){ + $query = $this->dao->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select()->toArray(); + + return compact('count','list'); + } /** * Common: 缴费订单生成 * Author: wu-hui @@ -110,6 +131,55 @@ class AgentDeliveryRepository extends BaseRepository{ return compact('count','list'); } + /** + * Common: 分配订单 + * Author: wu-hui + * Time: 2024/06/18 16:53 + * @param int $merId + * @param int $agentDeliveryId + * @return mixed + */ + public function allocationOrder(int $merId,int $agentDeliveryId){ + // 缴费记录信息 + $agentDeliveryInfo = $this->getSearchModel(['id'=>$agentDeliveryId])->findOrEmpty()->toArray(); + if($agentDeliveryInfo['status'] != 1) throw new ValidateException('状态错误,当前订单不可分配!'); + // 分配操作 + return Db::transaction(function() use ($merId, $agentDeliveryInfo){ + $titleQuota = $agentDeliveryInfo['title_quota'] ?? 0; + $otherQuota = $agentDeliveryInfo['other_quota'] ?? 0; + // 分配额度 + if($titleQuota > 0){ + app()->make(MerchantQuotaRecordRepository::class)->changeQuota([ + 'mer_id' => $merId, + 'change_type' => 1, + 'quota_type' => 0, + 'quantity' => $titleQuota, + 'source' => 3, + 'order_id' => $agentDeliveryInfo['order_id'], + ]); + } + if($otherQuota > 0){ + app()->make(MerchantQuotaRecordRepository::class)->changeQuota([ + 'mer_id' => $merId, + 'change_type' => 1, + 'quota_type' => 1, + 'quantity' => $otherQuota, + 'source' => 3, + 'order_id' => $agentDeliveryInfo['order_id'], + ]); + } + // 增加修改 + AgentDelivery::update([ + 'mer_id' => $merId, + 'status' => 2 + ],['id' => $agentDeliveryInfo['id']]); + + return true; + }); + } + + + diff --git a/app/controller/api/marketing/agent/Delivery.php b/app/controller/api/marketing/agent/Delivery.php index d8bcee4..9b439c8 100644 --- a/app/controller/api/marketing/agent/Delivery.php +++ b/app/controller/api/marketing/agent/Delivery.php @@ -36,7 +36,6 @@ class Delivery extends BaseController{ $config = $this->agentRepository->getConfig(); $paymentList = $config['payment_list'] ?? []; - return app('json')->success($paymentList); } /** @@ -66,8 +65,28 @@ class Delivery extends BaseController{ if($res) return $res; else return app('json')->success("操作成功"); } - // 缴费记录获取 - public function paymentRecord(){} + /** + * Common: 配送商缴费记录 + * Author: wu-hui + * Time: 2024/06/18 14:25 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function paymentRecord(){ + // 参数处理 + [$page,$limit] = $this->getPage(); + $params = $this->request->params([ + ['agent_id', 0], + 'is_bind', + 'status' + ]); + // 信息列表获取 + $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } /** * Common: 获取相关商户 * Author: wu-hui @@ -89,11 +108,24 @@ class Delivery extends BaseController{ return app('json')->success($data); } + /** + * Common: 分配缴费记录给商户 + * Author: wu-hui + * Time: 2024/06/18 16:53 + * @return mixed + */ + public function allocationOrder(){ + // 参数获取 + $params = $this->request->params([ + ['mer_id', 0], + ['agent_delivery_id', 0], + ]); + // 分配到订单 + $this->repository->allocationOrder((int)$params['mer_id'], (int)$params['agent_delivery_id']); - - - + return app('json')->success(); + } diff --git a/app/listener/exchangeQuota/OrderPaySuccessEvent.php b/app/listener/exchangeQuota/OrderPaySuccessEvent.php index d8f95f7..737a11f 100644 --- a/app/listener/exchangeQuota/OrderPaySuccessEvent.php +++ b/app/listener/exchangeQuota/OrderPaySuccessEvent.php @@ -3,6 +3,7 @@ namespace app\listener\exchangeQuota; use app\common\model\marketing\activity\Record; +use app\common\model\marketing\agent\AgentDelivery; use app\common\model\user\ExchangeIntegralRecord; use app\common\model\user\ExchangeQuota; use app\common\model\user\ExchangeQuotaRecord; @@ -64,10 +65,9 @@ class OrderPaySuccessEvent{ } else if($groupOrder->activity_type == 38){ // 配送商缴费支付成功 - - - - + foreach($groupOrder->orderList as $orderInfo){ + AgentDelivery::update(['status' => 1],['order_id' => (int)$orderInfo->order_id]); + } } else{ // 其他订单 diff --git a/route/api.php b/route/api.php index a21c37d..d21970d 100644 --- a/route/api.php +++ b/route/api.php @@ -422,8 +422,8 @@ Route::group('api/', function () { Route::get('delivery/payment_list', 'Delivery/paymentList');// 获取支付项列表 Route::post('delivery/create_order', 'Delivery/createOrder');// 生成支付订单 Route::get('delivery/payment_record', 'Delivery/paymentRecord');// 缴费记录 - Route::get('delivery/mer_list', 'Delivery/merList');// 绑定商户 + Route::post('delivery/allocation_order', 'Delivery/allocationOrder');// 分配缴费记录