DivisionController.php 3.9 KB

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