1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\api\controller\commission;
- use app\common\Service\Commission\AgentApply as AgentApplyService;
- use app\common\model\commission\Apply as ApplyModel;
- use think\Exception;
- use app\api\controller\Base;
- class AgentApply extends Base
- {
- protected $noNeedLogin = ['identities', 'areas'];
- protected $noNeedRight = ['*'];
- /**
- * 获取代理商身份列表
- */
- public function identities()
- {
- try {
- $service = new AgentApplyService();
- $identities = $service->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('申请类型不正确');
- }
- }
- }
|