repository = $repository; } /** * Common: 获取代理列表 * Author: wu-hui * Time: 2024/01/29 16:00 * @return mixed */ public function agentList(){ // 参数处理 [$page, $limit] = $this->getPage(); $params = $this->request->params(['is_get_self','not_page']); if((int)$params['is_get_self'] > 0) $params['uid'] = $this->request->uid(); // 信息列表获取 if((int)$params['not_page'] > 0) $data = app()->make(AgentRepository::class)->getAllList((array)$params); else $data = app()->make(AgentRepository::class)->getList((array)$params,(int)$page,(int)$limit); return app('json')->success($data); } /** * Common: 二维码 - 供应商入驻二维码 * Author: wu-hui * Time: 2024/01/29 17:40 * @return mixed */ public function qrCodeInviteSupplier(){ // 参数获取 $params = $this->request->params(['agent_id','type','level']); $qrcode = $this->repository->createQrCode($params); return app('json')->success(['qr_code' => $qrcode]); } /** * Common: 获取单条代理人员信息 * Author: wu-hui * Time: 2024/01/30 9:27 * @param $id * @return mixed */ public function singleAgentInfo($id){ $res = $this->repository->getSingleInfo($id); return app('json')->success($res); } /** * Common: 获取配置信息 * Author: wu-hui * Time: 2024/01/31 15:49 * @return mixed */ public function getConfig(){ $config = app()->make(AgentRepository::class)->getConfig(); return app('json')->success($config); } /** * Common: 申请成为代理 * Author: wu-hui * Time: 2024/02/01 15:14 * @return mixed */ public function apply(){ // 获取申请参数 $params = $this->applyCheckParams(); // 处理数据 $params['user_info'] = $this->request->userInfo(); $params['is_app'] = $this->request->isApp(); $res = app()->make(AgentApplyRepository::class)->editApplyInfo($params); if($res) return $res; else return app('json')->success("操作成功"); } /** * Common: 申请参数获取 & 参数校验 * Author: wu-hui * Time: 2024/02/01 13:41 * @return array */ public function applyCheckParams():array{ // 参数获取 $agentApplyId = (int)$this->request->param('id'); $data = $this->request->params([ ['pid',0], ['agent_type',0], 'contact_name', 'contact_phone', ['province_id',0], ['city_id', 0], ['area_id', 0], ['street_id', 0], 'address', ['mer_name', ''], ['mer_class_id', 0], ['mer_type_id', 0], ['mer_images', []], // 支付相关 'pay_type', 'return_url' ]); $data['uid'] = $this->request->uid(); // 信息验证 if((int)$data['pid'] <= 0) throw new ValidateException('非法请求,无邀请信息!'); if(!in_array((int)$data['agent_type'], [2,3,4,5,6,7,8])) throw new ValidateException('非法请求,代理类型错误!'); if(empty($data['contact_name'])) throw new ValidateException('请输入联系人姓名!'); if(empty($data['contact_phone'])) throw new ValidateException('请输入联系人电话!'); if((int)$data['province_id'] <= 0) throw new ValidateException('请选择地区!'); if(in_array((int)$data['agent_type'], [5,6,7])){ if((int)$data['city_id'] <= 0) throw new ValidateException('请选择地区!'); if((int)$data['area_id'] <= 0) throw new ValidateException('请选择地区!'); } if((int)$data['agent_type'] == 7){ if((int)$data['street_id'] <= 0) throw new ValidateException('请选择地区!'); if(empty($data['address'])) throw new ValidateException('请输入详细地址!'); if(empty($data['mer_name'])) throw new ValidateException('请输入商户名称!'); if((int)$data['mer_class_id'] <= 0) throw new ValidateException('请选择商户分类!'); if((int)$data['mer_type_id'] <= 0) throw new ValidateException('请选择商户类型!'); if(count($data['mer_images']) <= 0) throw new ValidateException('请上传资质证明图片!'); // 判断:商户名称是否重复 $merHas = Merchant::where('mer_name',$data['mer_name'])->count(); if($merHas > 0) throw new ValidateException('商户已经存在!'); // 判断:商户名称是否重复 $isHas = app()->make(AgentApplyRepository::class) ->getSearchModel([]) ->where('mer_name', $data['mer_name']) ->when($agentApplyId > 0,function($query) use ($agentApplyId){ $query->where('id','<>',$agentApplyId); }) ->count(); if($isHas > 0) throw new ValidateException('商户已经存在,请勿重复申请!'); } // 信息是否重复 $isHas = (int)app()->make(AgentApplyRepository::class) ->getSearchModel(['contact_phone'=>$data['contact_phone']]) ->when($agentApplyId > 0,function($query) use ($agentApplyId){ $query->where('id','<>',$agentApplyId); })->count(); if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!'); $isHas = (int)$this->repository ->getSearchModel(['contact_phone'=>$data['contact_phone']]) ->count(); if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!'); // 不能 重复成为当前等级的用户 $isHas = (int)$this->repository ->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']]) ->count(); if($isHas > 0) throw new ValidateException('代理身份信息已经存在!'); $isHas = (int)app()->make(AgentApplyRepository::class) ->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']]) ->when($agentApplyId > 0,function($query) use ($agentApplyId){ $query->where('id','<>',$agentApplyId); })->count(); if($isHas > 0) throw new ValidateException('代理身份信息已经存在,请勿重复申请!'); return compact("agentApplyId", "data"); } /** * Common: 获取申请记录 * Author: wu-hui * Time: 2024/02/01 18:02 * @return mixed */ public function applyRecord(){ [$page, $limit] = $this->getPage(); $params = $this->request->params([]); $params['uid'] = $this->request->uid(); $data = app()->make(AgentApplyRepository::class)->getList((array)$params,(int)$page,(int)$limit); return app('json')->success($data); } /** * Common: 单条申请信息 * Author: wu-hui * Time: 2024/02/01 18:27 * @return mixed */ public function applyInfo(){ $applyId = $this->request->param('apply_id'); $data = app()->make(AgentApplyRepository::class)->getSearchModel(['id'=>$applyId])->findOrEmpty()->toArray(); return app('json')->success($data); } }