| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | <?phpnamespace app\api\controller\commission;use app\common\Service\Commission\AgentApply as AgentApplyService;use app\common\model\commission\Apply as ApplyModel;use app\api\validate\AgentApply as AgentApplyValidate;use think\Exception;use app\api\controller\Base;class AgentApply extends Base{    protected $noNeedLogin = ['identities', 'areas', 'checkAreaRequirement'];    protected $noNeedRight = ['*'];    /**     * 获取代理商身份列表     */    public function identities()    {        try {            $service = new AgentApplyService();            $identities = $service->getIdentityList();            $this->success('获取成功', $identities);        } catch (Exception $e) {            $this->error($e->getMessage());        }    }    /**     * 检查代理商身份是否需要地区信息     */    public function checkAreaRequirement()    {        try {            $identityId = $this->request->param('agent_identity_id');                        if (empty($identityId)) {                $this->error('代理商身份ID不能为空');            }                        $requirement = AgentApplyValidate::getAreaRequirement($identityId);            $this->success('获取成功', $requirement);        } catch (Exception $e) {            $this->error($e->getMessage());        }    }    /**     * 提交代理商申请     */    public function apply()    {        try {            $user = auth_user();            $data = $this->request->param();                        // 使用验证器验证参数            $validate = new AgentApplyValidate();            if (!$validate->scene('apply')->check($data)) {                $this->error($validate->getError());            }                        $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());        }    }}
 |