diff --git a/app/common/dao/marketing/AgentBrokerageDao.php b/app/common/dao/marketing/AgentBrokerageDao.php new file mode 100644 index 0000000..26ed8fd --- /dev/null +++ b/app/common/dao/marketing/AgentBrokerageDao.php @@ -0,0 +1,70 @@ +when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ + $query->where('id', (int)$params['id']); + }) + ->when(isset($params['staff_uid']) && $params['staff_uid'] !== '',function($query) use ($params){ + $query->where('staff_uid', (int)$params['staff_uid']); + }) + ->when(isset($params['store_uid']) && $params['store_uid'] !== '',function($query) use ($params){ + $query->where('store_uid', (int)$params['store_uid']); + }) + ->when(isset($params['store_uid']) && $params['store_uid'] !== '',function($query) use ($params){ + $query->where('store_uid', (int)$params['store_uid']); + }) + ->when(isset($params['area_store_uid']) && $params['area_store_uid'] !== '',function($query) use ($params){ + $query->where('area_store_uid', (int)$params['area_store_uid']); + }) + ->when(isset($params['delivery_uid']) && $params['delivery_uid'] !== '',function($query) use ($params){ + $query->where('delivery_uid', (int)$params['delivery_uid']); + }) + ->when(isset($params['province_uid']) && $params['province_uid'] !== '',function($query) use ($params){ + $query->where('province_uid', (int)$params['province_uid']); + }) + ->with([ + 'userOrder' => function($query){ + $query->field('order_id,order_sn,create_time,title'); + }, + 'staff' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'store' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'area' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'areaStore' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'delivery' => function($query){ + $query->field('uid,nickname,avatar'); + }, + 'province' => function($query){ + $query->field('uid,nickname,avatar'); + }, + ]) + ->order('create_time DESC,id DESC'); + } + + + + + + + +} diff --git a/app/common/model/marketing/AgentBrokerage.php b/app/common/model/marketing/AgentBrokerage.php new file mode 100644 index 0000000..9125ee4 --- /dev/null +++ b/app/common/model/marketing/AgentBrokerage.php @@ -0,0 +1,44 @@ +hasOne(UserOrder::class,'order_id', 'user_order_id'); + } + public function staff(){ + return $this->hasOne(User::class,'uid', 'staff_uid'); + } + public function store(){ + return $this->hasOne(User::class,'uid', 'store_uid'); + } + public function area(){ + return $this->hasOne(User::class,'uid', 'area_uid'); + } + public function areaStore(){ + return $this->hasOne(User::class,'uid', 'area_store_uid'); + } + public function delivery(){ + return $this->hasOne(User::class,'uid', 'delivery_uid'); + } + public function province(){ + return $this->hasOne(User::class,'uid', 'province_uid'); + } + + + +} diff --git a/app/common/repositories/marketing/AgentBrokerageRepository.php b/app/common/repositories/marketing/AgentBrokerageRepository.php new file mode 100644 index 0000000..6392ee3 --- /dev/null +++ b/app/common/repositories/marketing/AgentBrokerageRepository.php @@ -0,0 +1,47 @@ +dao = $dao; + } + /** + * Common: 获取信息列表 + * Author: wu-hui + * Time: 2024/01/26 20:38 + * @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->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list'); + } + + + + + + + + + + + + +} diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index ce3722e..7038b80 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -855,7 +855,7 @@ class MerchantRepository extends BaseRepository // 参数获取 switch($type){ case 'promote': - $valueData = 'mer_id=' . $data['mer_id']; + $valueData = 'mid=' . $data['mid']. '&suid=' .$data['suid']; $path = 'pages/annex/vip_center/index'; return app()->make(QrcodeService::class)->createQrCode($valueData,$path); break; diff --git a/app/common/repositories/user/UserOrderRepository.php b/app/common/repositories/user/UserOrderRepository.php index bb20593..9fa4b0d 100644 --- a/app/common/repositories/user/UserOrderRepository.php +++ b/app/common/repositories/user/UserOrderRepository.php @@ -72,6 +72,8 @@ class UserOrderRepository extends BaseRepository 'pay_type' => $res['value']['price'] == 0 ? 'free' : $params['pay_type'], 'status' => 1, 'other' => $user->is_svip == -1 ? 'first' : '', + 'bind_mer_id' => $params['bind_mer_id'] ?? '', + 'bind_staff_id' => $params['bind_staff_id'] ?? '', ]; $body = [ 'order_sn' => $order_sn, diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index 7b076c0..fd2d71e 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -2,6 +2,7 @@ namespace app\controller\admin\marketing; +use app\common\repositories\marketing\AgentBrokerageRepository; use app\common\repositories\marketing\AgentRepository; use app\common\repositories\system\merchant\MerchantRepository; use crmeb\basic\BaseController; @@ -204,7 +205,19 @@ class Agent extends BaseController{ } + /** + * Common: 佣金列表 + * Author: wu-hui + * Time: 2024/01/26 20:36 + * @return mixed + */ + public function commissionList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['staff_uid','store_uid','store_uid','area_store_uid','delivery_uid','province_uid']); + $data = app()->make(AgentBrokerageRepository::class)->getList((array)$params,(int)$page,(int)$limit); + return app('json')->success($data); + } diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 0579ddd..cb22f24 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -116,7 +116,7 @@ class Merchant extends BaseController // 参数获取 $merId = $this->request->param('mer_id'); if((int)$merId > 0){ - $qrcode = $this->repository->createQrCode(['mer_id'=>$merId]); + $qrcode = $this->repository->createQrCode(['mid'=>$merId,'suid'=>$this->request->uid()]); return app('json')->success(['qr_code' => $qrcode]); } diff --git a/app/controller/api/user/Svip.php b/app/controller/api/user/Svip.php index ed82f03..fa20dc8 100644 --- a/app/controller/api/user/Svip.php +++ b/app/controller/api/user/Svip.php @@ -71,7 +71,7 @@ class Svip extends BaseController */ public function createOrder($id, GroupDataRepository $groupDataRepository, UserOrderRepository $userOrderRepository) { - $params = $this->request->params(['pay_type','return_url']); + $params = $this->request->params(['pay_type','return_url','bind_mer_id','bind_staff_id']); if (!in_array($params['pay_type'], ['weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr'], true)) return app('json')->fail('请选择正确的支付方式'); $res = $groupDataRepository->getWhere(['group_data_id' => $id, 'status' => 1]); diff --git a/app/listener/exchangeQuota/OrderVipPayEvent.php b/app/listener/exchangeQuota/OrderVipPayEvent.php index a3dec56..7eb1665 100644 --- a/app/listener/exchangeQuota/OrderVipPayEvent.php +++ b/app/listener/exchangeQuota/OrderVipPayEvent.php @@ -3,6 +3,10 @@ namespace app\listener\exchangeQuota; +use app\common\model\marketing\Agent; +use app\common\model\marketing\AgentBrokerage; +use app\common\model\store\service\StoreService; +use app\common\model\system\merchant\Merchant; use app\common\model\user\ExchangeQuota; use app\common\model\user\ExchangeQuotaRecord; use think\facade\Log; @@ -63,26 +67,52 @@ class OrderVipPayEvent{ // 会员卡开通成功 - 分佣操作 private function agentBrokerageHandle($order, $vipInfo){ Log::info('会员卡开通成功 - 分佣操作 - 开始: '.var_export($vipInfo,1)); + // 获取用户各个角色信息 + $bindStaffId = $order->bind_staff_id ?? 0; + $bindMerId = $order->bind_mer_id ?? 0; + $isOpenBrokerage = $vipInfo['is_open_brokerage'] ?? 0; + if($bindStaffId > 0 && $bindMerId > 0 && $isOpenBrokerage == 2){ + // 获取 门店员工在员工表的id + $serviceId = StoreService::where('uid',$bindStaffId)->where('mer_id',$bindMerId)->value('service_id'); + // 获取 门店(餐厅信息) + $agent7 = Agent::where('mer_id',$bindMerId)->where('agent_type',7)->findOrEmpty(); + // 获取 区县合伙人 + $agent6 = Agent::where('id',($agent7->pid ?? 0))->where('agent_type',6)->findOrEmpty(); + // 获取 区县运营商 + $agent5 = Agent::where('id',($agent6->pid ?? 0))->where('agent_type',5)->findOrEmpty(); + // 获取 省合伙人(外勤) + $agent3 = Agent::where('id',($agent5->pid ?? 0))->where('agent_type',3)->findOrEmpty(); + // 获取 省公司 + $agent2 = Agent::where('id',($agent3->pid ?? 0))->where('agent_type',2)->findOrEmpty(); + // 获取 配送商 + $deliveryAgentId = (int)Merchant::where('mer_id',$bindMerId)->value('agent_id'); + $agent8 = Agent::where('id',$deliveryAgentId)->where('agent_type',8)->findOrEmpty(); + $data = [ + 'user_order_id' => $order->order_id, + 'staff_uid' => $bindStaffId, + 'staff_id' => $serviceId, + 'staff_brokerage' => (float)$vipInfo['brokerage_staff'], + 'store_uid' => $agent7->uid ?? 0, + 'store_agent_id' => $agent7->id ?? 0, + 'store_brokerage' => (float)$vipInfo['brokerage_store'], + 'area_uid' => $agent6->uid ?? 0, + 'area_agent_id' => $agent6->id ?? 0, + 'area_brokerage' => (float)$vipInfo['brokerage_area'], + 'area_store_uid' => $agent5->uid ?? 0, + 'area_store_agent_id' => $agent5->id ?? 0, + 'area_store_brokerage' => (float)$vipInfo['brokerage_area_store'], + 'delivery_uid' => $agent8->uid ?? 0, + 'delivery_agent_id' => $agent8->id ?? 0, + 'delivery_brokerage' => (float)$vipInfo['brokerage_delivery'], + 'province_uid' => $agent2->uid ?? 0, + 'province_agent_id' => $agent2->id ?? 0, + 'province_brokerage' => (float)$vipInfo['brokerage_province'], + 'platform_brokerage' => (float)$vipInfo['brokerage_platform'], + ]; - - - - - - + AgentBrokerage::insert($data); + } } - - - - - - - - - - - - } \ No newline at end of file diff --git a/route/admin/marketing.php b/route/admin/marketing.php index 60fdade..dbab205 100644 --- a/route/admin/marketing.php +++ b/route/admin/marketing.php @@ -475,6 +475,12 @@ Route::group(function () { Route::get('get_edit_info','/getEditInfo')->name('systemMarketingAgentGetEditInfo')->option([ '_alias' => '获取编辑信息', ]); + // 代理商佣金明细 + Route::get('commission_list','/commissionList')->name('systemMarketingAgentCommissionList')->option([ + '_alias' => '佣金明细', + ]); + + })->prefix('admin.marketing.Agent')->option([ '_path' => '/marketing/agent/list',