AgentApply.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\api\controller\commission;
  3. use app\common\Service\Commission\AgentApply as AgentApplyService;
  4. use app\common\model\commission\Apply as ApplyModel;
  5. use app\api\validate\AgentApply as AgentApplyValidate;
  6. use think\Exception;
  7. use app\api\controller\Base;
  8. class AgentApply extends Base
  9. {
  10. protected $noNeedLogin = ['identities', 'areas', 'checkAreaRequirement'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 获取代理商身份列表
  14. */
  15. public function identities()
  16. {
  17. try {
  18. $service = new AgentApplyService();
  19. $identities = $service->getIdentityList();
  20. $this->success('获取成功', $identities);
  21. } catch (Exception $e) {
  22. $this->error($e->getMessage());
  23. }
  24. }
  25. /**
  26. * 检查代理商身份是否需要地区信息
  27. */
  28. public function checkAreaRequirement()
  29. {
  30. try {
  31. $identityId = $this->request->param('agent_identity_id');
  32. if (empty($identityId)) {
  33. $this->error('代理商身份ID不能为空');
  34. }
  35. $requirement = AgentApplyValidate::getAreaRequirement($identityId);
  36. $this->success('获取成功', $requirement);
  37. } catch (Exception $e) {
  38. $this->error($e->getMessage());
  39. }
  40. }
  41. /**
  42. * 提交代理商申请
  43. */
  44. public function apply()
  45. {
  46. try {
  47. $user = auth_user();
  48. $data = $this->request->param();
  49. // 使用验证器验证参数
  50. $validate = new AgentApplyValidate();
  51. if (!$validate->scene('apply')->check($data)) {
  52. $this->error($validate->getError());
  53. }
  54. $service = new AgentApplyService();
  55. $apply = $service->submitApply($user->id, $data);
  56. if ($apply->status == ApplyModel::STATUS_APPROVED) {
  57. $this->success('申请提交成功,您已成为代理商!', $apply);
  58. } else {
  59. $this->success('申请提交成功,请等待审核!', $apply);
  60. }
  61. } catch (Exception $e) {
  62. $this->error($e->getMessage());
  63. }
  64. }
  65. /**
  66. * 获取申请状态
  67. */
  68. public function status()
  69. {
  70. try {
  71. $user = auth_user();
  72. $service = new AgentApplyService();
  73. $apply = $service->getUserApply($user->id);
  74. if (!$apply) {
  75. $this->success('未找到申请记录', null);
  76. }
  77. // 增强申请数据信息
  78. $data = $apply->toArray();
  79. $this->success('获取成功', $data);
  80. } catch (Exception $e) {
  81. $this->error($e->getMessage());
  82. }
  83. }
  84. }