Division.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. ['image', []]
  99. ]);
  100. $this->services->divisionSave($data);
  101. return app('json')->success(100000);
  102. }
  103. /**
  104. * 添加编辑代理商
  105. * @param $uid
  106. * @return mixed
  107. * @throws \FormBuilder\Exception\FormBuilderException
  108. */
  109. public function divisionAgentCreate($uid)
  110. {
  111. return app('json')->success($this->services->getDivisionAgentForm((int)$uid));
  112. }
  113. /**
  114. * 保存代理商
  115. * @param UserServices $userServices
  116. * @return mixed
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\DbException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. */
  121. public function divisionAgentSave(UserServices $userServices)
  122. {
  123. $data = $this->request->postMore([
  124. ['division_id', 0],
  125. ['uid', 0],
  126. ['division_percent', 0],
  127. ['division_end_time', ''],
  128. ['division_status', 1],
  129. ['edit', 0],
  130. ['image', []],
  131. ]);
  132. if ((int)$data['uid'] == 0) $data['uid'] = $data['image']['uid'];
  133. $userInfo = $userServices->getUserInfo($data['uid'], 'is_division,is_agent,is_staff');
  134. if (!$userInfo) throw new AdminException(100100);
  135. if ($userInfo['is_division']) throw new AdminException('此用户是事业部,请勿添加为代理商');
  136. if ($userInfo['is_agent']) throw new AdminException('此用户是代理商,无法重复添加');
  137. if ($userInfo['is_staff']) throw new AdminException('此用户是下级员工,无法添加为代理商');
  138. $divisionUserInfo = $userServices->count(['uid' => (int)$data['division_id'], 'is_division' => 1, 'division_id' => $data['division_id']]);
  139. if (!$divisionUserInfo) throw new AdminException(100100);
  140. $this->services->divisionAgentSave($data);
  141. return app('json')->success(100000);
  142. }
  143. /**
  144. * 设置状态
  145. * @param $status
  146. * @param $uid
  147. * @return mixed
  148. */
  149. public function setDivisionStatus($status, $uid)
  150. {
  151. $this->services->setDivisionStatus($status, $uid);
  152. return app('json')->success(100014);
  153. }
  154. /**
  155. * 删除成功
  156. * @param $type
  157. * @param $uid
  158. * @return mixed
  159. */
  160. public function delDivision($type, $uid)
  161. {
  162. $this->services->delDivision($type, $uid);
  163. return app('json')->success(100002);
  164. }
  165. /**
  166. * 后台申请列表
  167. * @return mixed
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\DbException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. */
  172. public function AdminApplyList()
  173. {
  174. $where = $this->request->getMore([
  175. ['uid', 0],
  176. ['division_id', 0],
  177. ['division_invite', ''],
  178. ['status', ''],
  179. ['keyword', ''],
  180. ['time', ''],
  181. ]);
  182. $where['division_id'] = $this->adminInfo['division_id'];
  183. /** @var DivisionAgentApplyServices $applyServices */
  184. $applyServices = app()->make(DivisionAgentApplyServices::class);
  185. $data = $applyServices->AdminApplyList($where);
  186. return app('json')->success($data);
  187. }
  188. /**
  189. * 审核表单
  190. * @param $id
  191. * @param $type
  192. * @return mixed
  193. * @throws \FormBuilder\Exception\FormBuilderException
  194. */
  195. public function examineApply($id, $type)
  196. {
  197. /** @var DivisionAgentApplyServices $applyServices */
  198. $applyServices = app()->make(DivisionAgentApplyServices::class);
  199. $data = $applyServices->examineApply($id, $type);
  200. return app('json')->success($data);
  201. }
  202. /**
  203. * 代理商审核
  204. * @return mixed
  205. * @throws \think\db\exception\DataNotFoundException
  206. * @throws \think\db\exception\DbException
  207. * @throws \think\db\exception\ModelNotFoundException
  208. */
  209. public function applyAgentSave()
  210. {
  211. $data = $this->request->getMore([
  212. ['type', 0],
  213. ['id', 0],
  214. ['division_percent', ''],
  215. ['division_end_time', ''],
  216. ['division_status', ''],
  217. ['refusal_reason', 0]
  218. ]);
  219. /** @var DivisionAgentApplyServices $applyServices */
  220. $applyServices = app()->make(DivisionAgentApplyServices::class);
  221. $data = $applyServices->applyAgentSave($data);
  222. return app('json')->success(100014);
  223. }
  224. /**
  225. * 删除代理商审核
  226. * @param $id
  227. * @return mixed
  228. */
  229. public function delApply($id)
  230. {
  231. /** @var DivisionAgentApplyServices $applyServices */
  232. $applyServices = app()->make(DivisionAgentApplyServices::class);
  233. $applyServices->delApply($id);
  234. return app('json')->success(100002);
  235. }
  236. /**
  237. * 添加员工表单
  238. * @param $uid
  239. * @return \think\Response
  240. * @throws \FormBuilder\Exception\FormBuilderException
  241. * @author 吴汐
  242. * @email 442384644@qq.com
  243. * @date 2024/1/22
  244. */
  245. public function divisionStaffCreate($uid)
  246. {
  247. return app('json')->success($this->services->getDivisionStaffForm((int)$uid));
  248. }
  249. /**
  250. * 保存员工
  251. * @return \think\Response
  252. * @throws \think\db\exception\DataNotFoundException
  253. * @throws \think\db\exception\DbException
  254. * @throws \think\db\exception\ModelNotFoundException
  255. * @author 吴汐
  256. * @email 442384644@qq.com
  257. * @date 2024/1/22
  258. */
  259. public function divisionStaffSave()
  260. {
  261. $data = $this->request->getMore([
  262. ['uid', 0],
  263. ['division_percent', 0],
  264. ['agent_id', 0],
  265. ['image', []],
  266. ]);
  267. $this->services->divisionStaffSave($data);
  268. return app('json')->success(100000);
  269. }
  270. }