Division.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. */
  117. public function divisionAgentSave(UserServices $userServices)
  118. {
  119. $data = $this->request->postMore([
  120. ['uid', 0],
  121. ['division_percent', 0],
  122. ['division_end_time', ''],
  123. ['division_status', 1],
  124. ['edit', 0],
  125. ]);
  126. $userInfo = $userServices->get((int)$data['uid']);
  127. if (!$userInfo) throw new AdminException(100100);
  128. $data['division_id'] = $this->adminInfo['division_id'];
  129. $this->services->divisionAgentSave($data);
  130. return app('json')->success(100000);
  131. }
  132. /**
  133. * 设置状态
  134. * @param $status
  135. * @param $uid
  136. * @return mixed
  137. */
  138. public function setDivisionStatus($status, $uid)
  139. {
  140. $this->services->setDivisionStatus($status, $uid);
  141. return app('json')->success(100014);
  142. }
  143. /**
  144. * 删除成功
  145. * @param $type
  146. * @param $uid
  147. * @return mixed
  148. */
  149. public function delDivision($type, $uid)
  150. {
  151. $this->services->delDivision($type, $uid);
  152. return app('json')->success(100002);
  153. }
  154. /**
  155. * 后台申请列表
  156. * @return mixed
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\DbException
  159. * @throws \think\db\exception\ModelNotFoundException
  160. */
  161. public function AdminApplyList()
  162. {
  163. $where = $this->request->getMore([
  164. ['uid', 0],
  165. ['division_id', 0],
  166. ['division_invite', ''],
  167. ['status', ''],
  168. ['keyword', ''],
  169. ['time', ''],
  170. ]);
  171. $where['division_id'] = $this->adminInfo['division_id'];
  172. /** @var DivisionAgentApplyServices $applyServices */
  173. $applyServices = app()->make(DivisionAgentApplyServices::class);
  174. $data = $applyServices->AdminApplyList($where);
  175. return app('json')->success($data);
  176. }
  177. /**
  178. * 审核表单
  179. * @param $id
  180. * @param $type
  181. * @return mixed
  182. * @throws \FormBuilder\Exception\FormBuilderException
  183. */
  184. public function examineApply($id, $type)
  185. {
  186. /** @var DivisionAgentApplyServices $applyServices */
  187. $applyServices = app()->make(DivisionAgentApplyServices::class);
  188. $data = $applyServices->examineApply($id, $type);
  189. return app('json')->success($data);
  190. }
  191. /**
  192. * 代理商审核
  193. * @return mixed
  194. * @throws \think\db\exception\DataNotFoundException
  195. * @throws \think\db\exception\DbException
  196. * @throws \think\db\exception\ModelNotFoundException
  197. */
  198. public function applyAgentSave()
  199. {
  200. $data = $this->request->getMore([
  201. ['type', 0],
  202. ['id', 0],
  203. ['division_percent', ''],
  204. ['division_end_time', ''],
  205. ['division_status', ''],
  206. ['refusal_reason', 0]
  207. ]);
  208. /** @var DivisionAgentApplyServices $applyServices */
  209. $applyServices = app()->make(DivisionAgentApplyServices::class);
  210. $data = $applyServices->applyAgentSave($data);
  211. return app('json')->success(100014);
  212. }
  213. /**
  214. * 删除代理商审核
  215. * @param $id
  216. * @return mixed
  217. */
  218. public function delApply($id)
  219. {
  220. /** @var DivisionAgentApplyServices $applyServices */
  221. $applyServices = app()->make(DivisionAgentApplyServices::class);
  222. $applyServices->delApply($id);
  223. return app('json')->success(100002);
  224. }
  225. }