Division.php 7.1 KB

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