getPage(); $params = $this->request->params(['uid','agent_type','contact_name','contact_phone','is_invite_supplier']); $data = app()->make(AgentRepository::class)->getList((array)$params,(int)$page,(int)$limit); return app('json')->success($data); } /** * Common: 编辑信息 * Author: wu-hui * Time: 2024/01/24 16:05 * @return mixed */ public function editInfo(){ // 参数获取 $params = $this->checkParams(); // 数据处理 app()->make(AgentRepository::class)->editInfo((int)$params['agentId'],(array)$params['data'],(array)$params['childrenList']); return app('json')->success('操作成功'); } /** * Common: 编辑参数获取 & 参数校验 * Author: wu-hui * Time: 2024/01/24 14:16 * @return array */ public function checkParams(){ // 参数获取 $data = $this->request->params([ ['uid',0], ['pid',0], ['agent_type',0], ['agent_stock',0], 'contact_name', 'contact_phone', ['province_id',0], ['city_id', 0], ['area_id', 0], ['street_id', 0], 'address', 'lat', 'lng', ['mer_id', 0], ['mer_id_list', []], ['is_headquarters', 0] ]); $agentId = (int)$this->request->param('id'); $childrenList = $this->request->param('children_list'); // 判断:如果$agentId 为空或者0则当前操作为编辑发起人,至少有一个发起人信息 if($agentId <= 0){ if(count($childrenList) <= 0) throw new ValidateException('请至少添加一个发起人!'); $agentStock = (float)array_sum(array_column($childrenList,'agent_stock')); if($agentStock != 100) throw new ValidateException('所有发起人的股份总和必须等于100!'); } // 循环判断:$childrenList 的数据是否完善 类型:1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商 foreach($childrenList as $childrenItem){ if(empty($childrenItem['contact_name'])) throw new ValidateException('请输入联系人姓名!'); if(empty($childrenItem['contact_phone'])) throw new ValidateException('请输入联系人电话!'); if(isPhone($childrenItem['contact_phone'])) throw new ValidateException('请输入正确的联系人电话!'); // 判断:根据当前角色判断 数据 switch((int)$childrenItem['agent_type']){ case 1: // if((float)$childrenItem['agent_stock'] <= 0) throw new ValidateException('发起人的股份必须大于0!'); break; case 2: case 3: case 4: if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 5: case 6: if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 7: if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$childrenItem['street_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(empty($childrenItem['address']) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(((float)$childrenItem['lat'] <= 0 || (float)$childrenItem['lng'] <= 0) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); if((float)$childrenItem['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); break; case 8: if(count($childrenItem['mer_id_list']) <= 0) throw new ValidateException('配送商至少关联一个商户!'); break; } } // 判断:餐厅关联的商户是否重复 $merIds = array_filter(array_column($childrenList,'mer_id')); if(count($merIds) > 0){ // 判断:是否存在重复 if(count($merIds) != count(array_unique($merIds))) throw new ValidateException('每个商户只能关联一个餐厅,请勿重复关联!'); // 判断:当前关联商户中,是否存在其他已经被关联的商户 $ids = array_filter(array_column($childrenList,'id')); $isHas = (int)app()->make(AgentRepository::class) ->getSearch([]) ->whereNotIn('id',$ids) ->whereIn('mer_id',$merIds) ->count(); if($isHas > 0) throw new ValidateException('每个商户只能关联一个餐厅,请勿重复关联!'); } // 判断:配送商关联的商户是否重复 $merIdList = array_filter(array_column($childrenList,'mer_id_list')); if(count($merIdList) > 0){ // 判断:是否存在重复 $newMerIdList = call_user_func_array('array_merge', $merIdList); if(count($newMerIdList) != count(array_unique($newMerIdList))) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); // 判断:当前关联商户中,是否存在其他已经被关联的商户 $ids = array_filter(array_column($childrenList,'id')); $isHas = (int)app()->make(MerchantRepository::class) ->getSearch([]) ->whereNotIn('agent_id',$ids) ->whereIn('mer_id',$newMerIdList) ->count(); if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); } // 判断:agentId 大于0,验证data的信息 if($agentId > 0){ if(empty($data['contact_name'])) throw new ValidateException('请输入联系人姓名!'); if(empty($data['contact_phone'])) throw new ValidateException('请输入联系人电话!'); if(isPhone($data['contact_phone'])) throw new ValidateException('请输入正确的联系人电话!'); // 判断:根据当前角色判断 数据 switch((int)$data['agent_type']){ case 2: case 3: case 4: if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 5: case 6: if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 7: if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if((float)$data['street_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(empty($data['address']) && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0) && $data['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); if((float)$data['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); break; case 8: if(count($data['mer_id_list']) <= 0) throw new ValidateException('配送商至少关联一个商户!'); break; } // 判断:餐厅关联的商户是否重复 if((int)$data['mer_id'] > 0){ // 判断:当前关联商户中,是否存在其他已经被关联的商户 $isHas = (int)app()->make(AgentRepository::class) ->getSearch([]) ->where('id','<>',$agentId) ->where('mer_id',(int)$data['mer_id']) ->count(); if($isHas > 0) throw new ValidateException('每个商户只能关联一个餐厅,请勿重复关联!'); } // 判断:配送商关联的商户是否重复 $merIdList = is_array($data['mer_id_list']) ? $data['mer_id_list'] : []; if(count($merIdList) > 0){ // 判断:当前关联商户中,是否存在其他已经被关联的商户 $isHas = (int)app()->make(MerchantRepository::class) ->getSearch([]) ->where('agent_id','<>',$agentId) ->whereIn('mer_id',$data['mer_id_list']) ->count(); if($isHas > 0) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!'); } } return compact("data", "agentId", "childrenList"); } /** * Common: 获取编辑信息 * Author: wu-hui * Time: 2024/01/24 18:25 * @return mixed */ public function getEditInfo(){ // 参数获取 $params = $this->request->params(['agent_id']); $data = app()->make(AgentRepository::class)->getEditInfo((array)$params); 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); } /** * Common: 审核 * Author: wu-hui * Time: 2024/02/01 18:00 * @return mixed */ 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 * Time: 2024/01/31 14:15 * @return mixed */ public function setConfig(){ $config = $this->request->params([ ['delivery_money',0], ['delivery_money_field_staff',0], ['delivery_money_initiator',0], ['delivery_money_operator',0], ['delivery_money_partner',0], ['delivery_money_platform',0], ['delivery_money_province',0], ['delivery_process',0], ['field_staff_money',0], ['field_staff_money_initiator',0], ['field_staff_money_platform',0], ['field_staff_money_province',0], ['field_staff_process',0], ['internal_staff_money',0], ['internal_staff_money_initiator',0], ['internal_staff_money_platform',0], ['internal_staff_money_province',0], ['internal_staff_process',0], ['mer_money',0], ['mer_money_field_staff',0], ['mer_money_initiator',0], ['mer_money_operator',0], ['mer_money_partner',0], ['mer_money_platform',0], ['mer_money_province',0], ['mer_process',0], ['operator_money',0], ['operator_money_field_staff',0], ['operator_money_initiator',0], ['operator_money_platform',0], ['operator_money_province',0], ['operator_process',0], ['partner_money',0], ['partner_money_field_staff',0], ['partner_money_initiator',0], ['partner_money_operator',0], ['partner_money_platform',0], ['partner_money_province',0], ['partner_process',0], ['province_money',0], ['province_money_initiator',0], ['province_money_platform',0], ['province_process',0], ]); // 保存信息 $cid = app()->make(ConfigClassifyRepository::class)->getConfigClassifyKeyById('agent_config', '代理中心配置'); if (!$cid) return app('json')->fail('保存失败'); app()->make(ConfigValueRepository::class)->setFormData($config,$this->request->merId()); return app('json')->success('保存成功'); } /** * Common: 配置信息 - 获取配置信息 * Author: wu-hui * Time: 2024/01/31 14:32 * @return mixed */ public function getConfig(){ $config = app()->make(AgentRepository::class)->getConfig(); return app('json')->success($config); } /** * 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); } }