DivisionController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\api\controller\v1\user;
  3. use app\Request;
  4. use app\services\agent\DivisionAgentApplyServices;
  5. use app\services\other\AgreementServices;
  6. use app\services\user\UserServices;
  7. use crmeb\exceptions\AdminException;
  8. use crmeb\services\CacheService;
  9. class DivisionController
  10. {
  11. protected $services = NUll;
  12. /**
  13. * DivisionController constructor.
  14. * @param DivisionAgentApplyServices $services
  15. */
  16. public function __construct(DivisionAgentApplyServices $services)
  17. {
  18. $this->services = $services;
  19. }
  20. /**
  21. * 申请代理商
  22. * @param Request $request
  23. * @param $id
  24. * @return mixed
  25. */
  26. public function applyAgent(Request $request, $id)
  27. {
  28. $data = $request->postMore([
  29. ['uid', 0],
  30. ['agent_name', ''],
  31. ['name', ''],
  32. ['phone', 0],
  33. ['code', 0],
  34. ['division_invite', 0],
  35. ['images', []]
  36. ]);
  37. $verifyCode = CacheService::get('code_' . $data['phone']);
  38. if ($verifyCode != $data['code']) return app('json')->fail('验证码错误');
  39. $this->services->applyAgent($data, $id);
  40. return app('json')->success('提交成功');
  41. }
  42. /**
  43. * 申请详情
  44. * @param Request $request
  45. * @return mixed
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function applyInfo(Request $request)
  51. {
  52. $uid = $request->uid();
  53. $data = $this->services->applyInfo($uid);
  54. return app('json')->success($data);
  55. }
  56. /**
  57. * 移动端获取规则
  58. * @param AgreementServices $agreementServices
  59. * @return mixed
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function getAgentAgreement(AgreementServices $agreementServices)
  65. {
  66. $data = $agreementServices->getAgreementBytype(2);
  67. return app('json')->success($data);
  68. }
  69. /**
  70. * 员工列表
  71. * @param Request $request
  72. * @return mixed
  73. */
  74. public function getStaffList(Request $request)
  75. {
  76. $where = $request->postMore([
  77. ['keyword', ''],
  78. ['sort', ''],
  79. ]);
  80. $where['agent_id'] = $request->uid();
  81. return app('json')->successful($this->services->getStaffList($request->user(), $where));
  82. }
  83. /**
  84. * 设置员工比例
  85. * @param Request $request
  86. * @return mixed
  87. */
  88. public function setStaffPercent(Request $request)
  89. {
  90. [$agentPercent, $uid] = $request->postMore([
  91. ['agent_percent', ''],
  92. ['uid', 0],
  93. ], true);
  94. $agentId = $request->uid();
  95. if (!$uid) return app('json')->fail('参数错误');
  96. /** @var UserServices $userService */
  97. $userService = app()->make(UserServices::class);
  98. $upPercent = $userService->value(['uid' => $agentId], 'division_percent');
  99. if ($agentPercent >= $upPercent) return app('json')->fail('比例不能大于您的比例');
  100. $userService->update(['uid' => $uid, 'agent_id' => $agentId], ['division_percent' => $agentPercent]);
  101. return app('json')->success('设置成功');
  102. }
  103. /**
  104. * 删除员工
  105. * @param Request $request
  106. * @param $uid
  107. * @return mixed
  108. */
  109. public function delStaff(Request $request, $uid)
  110. {
  111. if (!$uid) return app('json')->fail('参数错误');
  112. $agentId = $request->uid();
  113. /** @var UserServices $userService */
  114. $userService = app()->make(UserServices::class);
  115. $userService->update(['uid' => $uid, 'agent_id' => $agentId], ['division_percent' => 0, 'agent_id' => 0, 'division_id' => 0, 'staff_id' => 0, 'division_type' => 0, 'is_staff' => 0]);
  116. return app('json')->success('删除成功');
  117. }
  118. }