Division.php 8.8 KB

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