diff --git a/app/common/dao/marketing/AgentApplyDao.php b/app/common/dao/marketing/AgentApplyDao.php index 424da28..e5a2f2d 100644 --- a/app/common/dao/marketing/AgentApplyDao.php +++ b/app/common/dao/marketing/AgentApplyDao.php @@ -28,6 +28,9 @@ class AgentApplyDao extends BaseDao{ ->when(isset($params['pid']) && $params['pid'] !== '',function($query) use ($params){ $query->where('pid', (int)$params['pid']); }) + ->when(isset($params['mer_name']) && $params['mer_name'] !== '',function($query) use ($params){ + $query->where('mer_name', 'like', "%{$params['mer_name']}%"); + }) ->when(isset($params['contact_name']) && $params['contact_name'] !== '',function($query) use ($params){ $query->where('contact_name', 'like', "%{$params['contact_name']}%"); }) @@ -37,6 +40,9 @@ class AgentApplyDao extends BaseDao{ ->when(isset($params['agent_type']) && $params['agent_type'] !== '',function($query) use ($params){ $query->where('agent_type', (int)$params['agent_type']); }) + ->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){ + $query->where('status', (int)$params['status']); + }) ->with([ 'user' => function($query){ $query->field('uid,nickname,avatar'); @@ -61,6 +67,15 @@ class AgentApplyDao extends BaseDao{ } ]); }, + 'merClass' => function($query){ + $query->field('merchant_category_id,category_name as mer_category_name')->bind(['mer_category_name']); + }, + 'merType' => function($query){ + $query->field('mer_type_id,type_name as mer_type_name')->bind(['mer_type_name']); + }, + 'orderInfo' => function($query){ + $query->field('order_id,status,order_sn'); + }, ]) ->order('create_time DESC,id DESC'); } diff --git a/app/common/model/marketing/AgentApply.php b/app/common/model/marketing/AgentApply.php index 9cd5dbb..2402c86 100644 --- a/app/common/model/marketing/AgentApply.php +++ b/app/common/model/marketing/AgentApply.php @@ -3,6 +3,9 @@ namespace app\common\model\marketing; use app\common\model\BaseModel; use app\common\model\store\CityArea; +use app\common\model\store\order\StoreOrder; +use app\common\model\system\merchant\MerchantCategory; +use app\common\model\system\merchant\MerchantType; use app\common\model\user\User; @@ -18,11 +21,24 @@ class AgentApply extends BaseModel{ } + public function setMerImagesAttr($value){ + return implode(',',$value); + } + public function getMerImagesAttr($value){ + if(!empty($value)) return explode(',',$value); + + return []; + } + + + + + public function user(){ return $this->hasOne(User::class, 'uid', 'uid'); } public function parent(){ - return $this->hasOne(self::class, 'id', 'pid'); + return $this->hasOne(Agent::class, 'id', 'pid'); } public function province(){ return $this->hasOne(CityArea::class, 'id', 'province_id'); @@ -36,4 +52,18 @@ class AgentApply extends BaseModel{ public function street(){ return $this->hasOne(CityArea::class, 'id', 'street_id'); } + + public function merClass(){ + return $this->hasOne(MerchantCategory::class, 'merchant_category_id', 'mer_class_id'); + } + public function merType(){ + return $this->hasOne(MerchantType::class, 'mer_type_id', 'mer_type_id'); + } + public function orderInfo(){ + return $this->hasOne(StoreOrder::class, 'order_id', 'order_id'); + } + + + + } diff --git a/app/common/repositories/marketing/AgentApplyRepository.php b/app/common/repositories/marketing/AgentApplyRepository.php index 4fa84cf..02cdfcb 100644 --- a/app/common/repositories/marketing/AgentApplyRepository.php +++ b/app/common/repositories/marketing/AgentApplyRepository.php @@ -3,9 +3,13 @@ namespace app\common\repositories\marketing; use app\common\dao\marketing\AgentApplyDao; +use app\common\model\marketing\Agent; +use app\common\model\user\User; use app\common\repositories\BaseRepository; use app\common\repositories\store\order\StoreOrderCreateRepository; use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\store\service\StoreServiceRepository; +use app\common\repositories\system\merchant\MerchantRepository; use crmeb\services\LockService; use think\facade\Db; @@ -26,7 +30,25 @@ class AgentApplyRepository extends BaseRepository{ public function getSearchModel($search){ return $this->dao->searchList($search); } + /** + * Common: 列表获取 + * Author: wu-hui + * Time: 2024/02/01 15:47 + * @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'); + } // 提交申请信息(同步生成订单) public function editApplyInfo($params){ return Db::transaction(function() use ($params){ @@ -106,9 +128,80 @@ class AgentApplyRepository extends BaseRepository{ } }); } + /** + * Common: 审核通过 + * Author: wu-hui + * Time: 2024/02/01 17:10 + * @param $params + * @return mixed + */ + public function toExaminePass($params){ + return Db::transaction(function() use ($params){ + // 修改状态 + $this->dao->update($params['id'],['status'=>$params['status']]); + // 生成代理信息 + $applyInfo = $this->getSearchModel(['id'=>$params['id']])->findOrEmpty()->toArray(); + $keys = array_flip((array)[ + "uid", + "pid", + "agent_type", + "contact_name", + "contact_phone", + "province_id", + "city_id", + "area_id", + "street_id", + "address", + ]); + $insertInfo = array_intersect_key($applyInfo, $keys); + $insertInfo['apply_id'] = $applyInfo['id']; + $agentId = Agent::insertGetId($insertInfo); + // 判断:如果是餐厅 生成商户信息 + if((int)$insertInfo['agent_type'] == 7){ + $password = substr($applyInfo['contact_phone'],-6); + $config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']); + $merchant = app()->make(MerchantRepository::class)->createMerchant([ + 'mer_name' => $applyInfo['mer_name'], + 'mer_phone' => $applyInfo['contact_phone'], + 'mer_account' => $applyInfo['contact_phone'], + 'category_id' => $applyInfo['mer_class_id'], + 'type_id' => $applyInfo['mer_type_id'], + 'real_name' => $applyInfo['contact_name'], + 'status' => 1, + 'is_audit' => 1, + 'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1, + 'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1, + 'mer_password' => $password, + 'is_margin' => $margin['is_margin'] ?? -1, + 'margin' => $margin['margin'] ?? 0, + 'agent_id' => $agentId + ]); + // 存在默认管理员信息 生成管理员 + $staffUserInfo = User::where('uid', $applyInfo['uid'])->findOrEmpty()->toArray(); + $staffData = [ + 'uid' => $applyInfo['uid'], + 'nickname' => $staffUserInfo['nickname'] ?? $staffUserInfo['real_name'], + 'account' => $applyInfo['contact_phone'], + 'pwd' => $password, + 'is_open' => 1, + 'status' => 1, + 'customer' => 1, + 'is_verify' => 1, + 'is_goods' => 1, + 'is_user' => 1, + 'staff_manage' => 1, + 'notify' => 1, + 'avatar' => $staffUserInfo['avatar'] ?? '', + 'phone' => $applyInfo['contact_phone'], + 'sort' => 1, + 'mer_id' => $merchant->mer_id, + 'is_manage' => 1 + ]; + app()->make(StoreServiceRepository::class)->createInfo($staffData); + } - - + }); + } diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index ad95032..eae547d 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -112,7 +112,7 @@ class AgentRepository extends BaseRepository{ // 处理当前角色用户信息 if($agentId > 0) $this->currentRoleHandle($agentId, $data); // 处理子类信息 - if(count($childrenList) > 0) $this->childrenListHandle($agentId, $childrenList); + $this->childrenListHandle($agentId, $childrenList); }); } /** diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index 466eae9..f595efe 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -2,9 +2,9 @@ namespace app\controller\admin\marketing; +use app\common\repositories\marketing\AgentApplyRepository; use app\common\repositories\marketing\AgentBrokerageRepository; use app\common\repositories\marketing\AgentRepository; -use app\common\repositories\system\CacheRepository; use app\common\repositories\system\config\ConfigClassifyRepository; use app\common\repositories\system\config\ConfigValueRepository; use app\common\repositories\system\merchant\MerchantRepository; @@ -206,6 +206,39 @@ class Agent extends BaseController{ return app('json')->success($data); } + /** + * Common: 申请列表获取 + * Author: wu-hui + * Time: 2024/02/01 15:48 + * @return mixed + */ + public function applyList(){ + $params = $this->request->params(['uid','agent_type','contact_name','contact_phone','mer_name','status']); + [$page, $limit] = $this->getPage(); + $data = app()->make(AgentApplyRepository::class)->getList($params, $page, $limit); + + return app('json')->success($data); + } + // 审核 + public function toExamine(){ + // 参数获取 + $params = $this->request->params(['id','status','reason']); + if($params['id'] <= 0) throw new ValidateException('方法请求,信息不明确!'); + // 审核通过 主动生成账号 + if((int)$params['status'] === 1){ + // 审核通过 + app()->make(AgentApplyRepository::class)->toExaminePass((array)$params); + }else{ + // 驳回 + app()->make(AgentApplyRepository::class)->update($params['id'],['status'=>$params['status'],'reason'=>$params['reason']]); + } + + return app('json')->success('操作成功'); + } + + + + /** * Common: 配置信息 - 修改配置信息 * Author: wu-hui @@ -275,9 +308,6 @@ class Agent extends BaseController{ return app('json')->success($config); } - - - /** * Common: 佣金列表 * Author: wu-hui @@ -291,15 +321,4 @@ class Agent extends BaseController{ return app('json')->success($data); } - - - - - - - - - - - } diff --git a/route/admin/marketing.php b/route/admin/marketing.php index e2a8480..8350eba 100644 --- a/route/admin/marketing.php +++ b/route/admin/marketing.php @@ -475,6 +475,17 @@ Route::group(function () { Route::get('get_edit_info','/getEditInfo')->name('systemMarketingAgentGetEditInfo')->option([ '_alias' => '获取编辑信息', ]); + // 申请审核 + Route::get('apply_list', '/applyList')->name('systemMarketingAgentApplyList')->option([ + '_alias' => '代理申请列表', + ]); + Route::post('apply_to_examine', '/toExamine')->name('systemMarketingAgentToExamine')->option([ + '_alias' => '代理申请审核', + ]); + + + + // 代理配置相关 Route::post('config','/setConfig')->name('systemMarketingAgentSetConfig')->option([ '_alias' => '设置配置信息', @@ -488,7 +499,6 @@ Route::group(function () { ]); - })->prefix('admin.marketing.Agent')->option([ '_path' => '/marketing/agent/list', '_auth' => true,