getIdentityList(); $this->success('获取成功', $identities); } catch (Exception $e) { $this->error($e->getMessage()); } } /** * 提交代理商申请 */ public function apply() { try { $user = auth_user(); $data = $this->request->param(); // 验证必要参数 $this->validateApplyParams($data); $service = new AgentApplyService(); $apply = $service->submitApply($user->id, $data); if ($apply->status == ApplyModel::STATUS_APPROVED) { $this->success('申请提交成功,您已成为代理商!', $apply); } else { $this->success('申请提交成功,请等待审核!', $apply); } } catch (Exception $e) { $this->error($e->getMessage()); } } /** * 获取申请状态 */ public function status() { try { $user = auth_user(); $service = new AgentApplyService(); $apply = $service->getUserApply($user->id); if (!$apply) { $this->success('未找到申请记录', null); } // 增强申请数据信息 $data = $apply->toArray(); $this->success('获取成功', $data); } catch (Exception $e) { $this->error($e->getMessage()); } } /** * 验证申请参数 */ private function validateApplyParams($data) { $requiredFields = ['apply_type', 'agent_identity_id', 'province_id', 'city_id', 'district_id']; foreach ($requiredFields as $field) { if (!isset($data[$field]) || $data[$field] === '') { throw new Exception('参数' . $field . '不能为空'); } } if (!in_array($data['apply_type'], [ApplyModel::APPLY_TYPE_PERSONAL, ApplyModel::APPLY_TYPE_COMPANY])) { throw new Exception('申请类型不正确'); } } }