Division.php 9.5 KB

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