Division.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\agent;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\agent\DivisionAgentApplyServices;
  14. use app\services\agent\DivisionServices;
  15. use app\services\other\AgreementServices;
  16. use app\services\user\UserServices;
  17. use crmeb\exceptions\AdminException;
  18. use think\facade\App;
  19. /**
  20. * 事业部控制器
  21. * Class Division
  22. * @package app\adminapi\controller\v1\agent
  23. */
  24. class Division extends AuthController
  25. {
  26. /**
  27. * Division constructor.
  28. * @param App $app
  29. * @param DivisionServices $services
  30. */
  31. public function __construct(App $app, DivisionServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 事业部列表
  38. * @return mixed
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function divisionList()
  44. {
  45. $where = $this->request->getMore([
  46. ['division_type', 0],
  47. ['keyword', '']
  48. ]);
  49. if ($where['division_type'] == 2) {
  50. $where['division_id'] = $this->adminInfo['division_id'];
  51. }
  52. $data = $this->services->getDivisionList($where);
  53. return app('json')->success($data);
  54. }
  55. /**
  56. * 下级列表
  57. * @return mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function divisionDownList()
  63. {
  64. [$type, $uid] = $this->request->getMore([
  65. ['division_type', 0],
  66. ['uid', 0],
  67. ], true);
  68. $data = $this->services->divisionDownList($type, $uid);
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * 添加编辑事业部
  73. * @param $uid
  74. * @return mixed
  75. * @throws \FormBuilder\Exception\FormBuilderException
  76. */
  77. public function divisionCreate($uid)
  78. {
  79. return app('json')->success($this->services->getDivisionForm((int)$uid));
  80. }
  81. /**
  82. * 保存事业部
  83. * @return mixed
  84. */
  85. public function divisionSave()
  86. {
  87. $data = $this->request->postMore([
  88. ['uid', 0],
  89. ['aid', 0],
  90. ['division_percent', 0],
  91. ['division_end_time', ''],
  92. ['division_status', 1],
  93. ['account', ''],
  94. ['pwd', ''],
  95. ['conf_pwd', ''],
  96. ['real_name', ''],
  97. ['roles', []]
  98. ]);
  99. $this->services->divisionSave($data);
  100. return app('json')->success(100000);
  101. }
  102. /**
  103. * 添加编辑代理商
  104. * @param $uid
  105. * @return mixed
  106. * @throws \FormBuilder\Exception\FormBuilderException
  107. */
  108. public function divisionAgentCreate($uid)
  109. {
  110. return app('json')->success($this->services->getDivisionAgentForm((int)$uid));
  111. }
  112. /**
  113. * 保存代理商
  114. * @param UserServices $userServices
  115. * @return mixed
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\DbException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. */
  120. public function divisionAgentSave(UserServices $userServices)
  121. {
  122. $data = $this->request->postMore([
  123. ['division_id', 0],
  124. ['uid', 0],
  125. ['division_percent', 0],
  126. ['division_end_time', ''],
  127. ['division_status', 1],
  128. ['edit', 0],
  129. ]);
  130. $userInfo = $userServices->count(['uid' => (int)$data['uid']]);
  131. if (!$userInfo) throw new AdminException(100100);
  132. $divisionUserInfo = $userServices->count(['uid' => (int)$data['division_id'], 'is_division' => 1, 'division_id' => $data['division_id']]);
  133. if (!$divisionUserInfo) throw new AdminException(100100);
  134. $this->services->divisionAgentSave($data);
  135. return app('json')->success(100000);
  136. }
  137. /**
  138. * 设置状态
  139. * @param $status
  140. * @param $uid
  141. * @return mixed
  142. */
  143. public function setDivisionStatus($status, $uid)
  144. {
  145. $this->services->setDivisionStatus($status, $uid);
  146. return app('json')->success(100014);
  147. }
  148. /**
  149. * 删除成功
  150. * @param $type
  151. * @param $uid
  152. * @return mixed
  153. */
  154. public function delDivision($type, $uid)
  155. {
  156. $this->services->delDivision($type, $uid);
  157. return app('json')->success(100002);
  158. }
  159. /**
  160. * 后台申请列表
  161. * @return mixed
  162. * @throws \think\db\exception\DataNotFoundException
  163. * @throws \think\db\exception\DbException
  164. * @throws \think\db\exception\ModelNotFoundException
  165. */
  166. public function AdminApplyList()
  167. {
  168. $where = $this->request->getMore([
  169. ['uid', 0],
  170. ['division_id', 0],
  171. ['division_invite', ''],
  172. ['status', ''],
  173. ['keyword', ''],
  174. ['time', ''],
  175. ]);
  176. $where['division_id'] = $this->adminInfo['division_id'];
  177. /** @var DivisionAgentApplyServices $applyServices */
  178. $applyServices = app()->make(DivisionAgentApplyServices::class);
  179. $data = $applyServices->AdminApplyList($where);
  180. return app('json')->success($data);
  181. }
  182. /**
  183. * 审核表单
  184. * @param $id
  185. * @param $type
  186. * @return mixed
  187. * @throws \FormBuilder\Exception\FormBuilderException
  188. */
  189. public function examineApply($id, $type)
  190. {
  191. /** @var DivisionAgentApplyServices $applyServices */
  192. $applyServices = app()->make(DivisionAgentApplyServices::class);
  193. $data = $applyServices->examineApply($id, $type);
  194. return app('json')->success($data);
  195. }
  196. /**
  197. * 代理商审核
  198. * @return mixed
  199. * @throws \think\db\exception\DataNotFoundException
  200. * @throws \think\db\exception\DbException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. */
  203. public function applyAgentSave()
  204. {
  205. $data = $this->request->getMore([
  206. ['type', 0],
  207. ['id', 0],
  208. ['division_percent', ''],
  209. ['division_end_time', ''],
  210. ['division_status', ''],
  211. ['refusal_reason', 0]
  212. ]);
  213. /** @var DivisionAgentApplyServices $applyServices */
  214. $applyServices = app()->make(DivisionAgentApplyServices::class);
  215. $data = $applyServices->applyAgentSave($data);
  216. return app('json')->success(100014);
  217. }
  218. /**
  219. * 删除代理商审核
  220. * @param $id
  221. * @return mixed
  222. */
  223. public function delApply($id)
  224. {
  225. /** @var DivisionAgentApplyServices $applyServices */
  226. $applyServices = app()->make(DivisionAgentApplyServices::class);
  227. $applyServices->delApply($id);
  228. return app('json')->success(100002);
  229. }
  230. }