diff --git a/app/common/dao/marketing/AgentBrokerageDao.php b/app/common/dao/marketing/AgentBrokerageDao.php index c78240c..0376a4b 100644 --- a/app/common/dao/marketing/AgentBrokerageDao.php +++ b/app/common/dao/marketing/AgentBrokerageDao.php @@ -35,6 +35,12 @@ class AgentBrokerageDao extends BaseDao{ ->when(isset($params['province_uid']) && $params['province_uid'] !== '',function($query) use ($params){ $query->where('province_uid', (int)$params['province_uid']); }) + ->when(isset($params['initiator_uid']) && $params['initiator_uid'] !== '',function($query) use ($params){ + $query->where('initiator_uid', (int)$params['initiator_uid']); + }) + ->when(isset($params['field_staff_uid']) && $params['field_staff_uid'] !== '',function($query) use ($params){ + $query->where('field_staff_uid', (int)$params['field_staff_uid']); + }) ->with([ 'userOrder' => function($query){ $query->field('order_id,order_sn,create_time,title'); diff --git a/app/common/repositories/marketing/AgentBrokerageRepository.php b/app/common/repositories/marketing/AgentBrokerageRepository.php index b61668a..6c1d91c 100644 --- a/app/common/repositories/marketing/AgentBrokerageRepository.php +++ b/app/common/repositories/marketing/AgentBrokerageRepository.php @@ -34,6 +34,66 @@ class AgentBrokerageRepository extends BaseRepository{ return compact('count','list'); } + /** + * Common: 获取单个代理人员的佣金明细 + * Author: wu-hui + * Time: 2024/02/02 17:41 + * @param int $agentId + * @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 getAgentCommissionList(int $agentId,int $page,int $limit){ + // 类型:1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商 + $agentInfo = app()->make(AgentRepository::class)->getSearchModel(['id'=>$agentId])->findOrEmpty()->toArray(); + $totalMoney = 0; + switch((int)$agentInfo['agent_type']){ + case 1: + $query = $this->dao->searchList(['initiator_uid'=>$agentInfo['uid']]) + ->field(['*','initiator_brokerage as brokerage']); + $totalMoney = $query->sum('initiator_brokerage'); + break; + case 2: + $query = $this->dao->searchList(['province_uid'=>$agentInfo['uid']]) + ->field(['*','province_brokerage as brokerage']); + $totalMoney = $query->sum('province_brokerage'); + break; + case 3: + $query = $this->dao->searchList(['field_staff_uid'=>$agentInfo['uid']]) + ->field(['*','field_staff_brokerage as brokerage']); + $totalMoney = $query->sum('field_staff_brokerage'); + break; + // case 4: break; + case 5: + $query = $this->dao->searchList(['area_store_uid'=>$agentInfo['uid']]) + ->field(['*','area_store_brokerage as brokerage']); + $totalMoney = $query->sum('area_store_brokerage'); + break; + case 6: + $query = $this->dao->searchList(['area_uid'=>$agentInfo['uid']]) + ->field(['*','area_brokerage as brokerage']); + $totalMoney = $query->sum('area_brokerage'); + break; + case 7: + $query = $this->dao->searchList(['store_uid'=>$agentInfo['uid']]) + ->field(['*','store_brokerage as brokerage']); + $totalMoney = $query->sum('store_brokerage'); + break; + case 8: + $query = $this->dao->searchList(['delivery_uid'=>$agentInfo['uid']]) + ->field(['*','delivery_brokerage as brokerage']); + $totalMoney = $query->sum('delivery_brokerage'); + break; + } + // 列表信息获取 + $count = $query->count(); + $list = $query->page($page,$limit)->select(); + + return compact('count','list', 'totalMoney'); + } /** * Common: 邀请代理人员奖励 * Author: wu-hui @@ -141,5 +201,4 @@ class AgentBrokerageRepository extends BaseRepository{ } - } diff --git a/app/controller/api/Agent.php b/app/controller/api/Agent.php index 83e888b..d6316a8 100644 --- a/app/controller/api/Agent.php +++ b/app/controller/api/Agent.php @@ -5,6 +5,7 @@ namespace app\controller\api; use app\common\model\system\merchant\Merchant; use app\common\repositories\marketing\AgentApplyRepository; +use app\common\repositories\marketing\AgentBrokerageRepository; use app\common\repositories\marketing\AgentRepository; use crmeb\basic\BaseController; use think\App; @@ -199,6 +200,19 @@ class Agent extends BaseController{ return app('json')->success($data); } + /** + * Common: 佣金列表获取 + * Author: wu-hui + * Time: 2024/02/02 17:22 + * @return mixed + */ + public function commissionList(){ + [$page, $limit] = $this->getPage(); + $agentId = $this->request->param('agent_id'); + $data = app()->make(AgentBrokerageRepository::class)->getAgentCommissionList((int)$agentId,(int)$page,(int)$limit); + + return app('json')->success($data); + } } diff --git a/route/api.php b/route/api.php index d9383d5..33be2f1 100644 --- a/route/api.php +++ b/route/api.php @@ -391,7 +391,7 @@ Route::group('api/', function () { Route::post('agent_apply', 'apply');// 提交申请信息 Route::post('apply_record', 'applyRecord');// 申请记录 Route::get('apply_info', 'applyInfo');// 申请信息 - + Route::get('commission_list', 'commissionList');// 佣金明细 })->prefix('api.Agent/');