UserController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. namespace app\wechat\controller;
  3. use app\common\Tree;
  4. use app\wechat\IndexController;
  5. use app\wechat\service\UserService;
  6. use support\Request;
  7. use support\Response;
  8. class UserController extends IndexController
  9. {
  10. public $notNeedLogin = ['login'];
  11. public function index(Request $request)
  12. {
  13. $params = $request->post();
  14. return UserService::getAll($params);
  15. }
  16. /**
  17. * Notes:
  18. * User: yb
  19. * Date: 2024/8/8
  20. * Time: 9:19
  21. * @param Request $request
  22. * @return \support\Response
  23. */
  24. public function login(Request $request)
  25. {
  26. $params = $request->post();
  27. if (empty($params['mobile'])) {
  28. return json_fail('手机号不能为空');
  29. }
  30. if (empty($params['password'])) {
  31. return json_fail('密码不能为空');
  32. }
  33. return UserService::login($params);
  34. }
  35. /**
  36. * Notes: 验证身份
  37. * User: yb
  38. * Date: 2024/8/8
  39. * Time: 10:08
  40. * @param Request $request
  41. */
  42. public function auth()
  43. {
  44. return UserService::auth();
  45. }
  46. /**
  47. * Notes: 统计分析
  48. * User: yb
  49. * Date: 2024/8/14
  50. * Time: 10:22
  51. */
  52. public function statistics(Request $request)
  53. {
  54. $params = $request->post();
  55. return UserService::statistics($params);
  56. }
  57. /**
  58. * Notes: 客户数量走势
  59. * User: yb
  60. * Date: 2024/8/17
  61. * Time: 17:51
  62. */
  63. public function customTrend(Request $request)
  64. {
  65. $params = $request->post();
  66. return UserService::customTrend($params);
  67. }
  68. /**
  69. * Notes: 用户详情
  70. * User: yb
  71. * Date: 2024/8/14
  72. * Time: 13:34
  73. */
  74. public function info()
  75. {
  76. return UserService::info();
  77. }
  78. /**
  79. * Notes: 成员详情
  80. * User: yb
  81. * Date: 2024/8/15
  82. * Time: 10:22
  83. * @param Request $request
  84. * @return Response
  85. */
  86. public function infoById(Request $request)
  87. {
  88. $params = $request->post();
  89. if (empty($params['id'])) {
  90. return json_fail('成员id不能为空');
  91. }
  92. return UserService::getInfoById($params['id']);
  93. }
  94. /**
  95. * Notes: 编辑成员
  96. * User: yb
  97. * Date: 2024/8/15
  98. * Time: 10:27
  99. * @param Request $request
  100. */
  101. public function updateUserById(Request $request)
  102. {
  103. $params = $request->post();
  104. if (empty($params['mobile'])) {
  105. return json_fail('手机号不能为空');
  106. }
  107. if (empty($params['name'])) {
  108. return json_fail('姓名不能为空');
  109. }
  110. if (empty($params['gender'])) {
  111. return json_fail('性别不能为空');
  112. }
  113. if (empty($params['dept_id'])) {
  114. return json_fail('所属部门不能为空');
  115. }
  116. if (empty($params['status'])) {
  117. return json_fail('状态不能为空');
  118. }
  119. return UserService::updateById($params);
  120. }
  121. /**
  122. * Notes: 更新用户
  123. * User: yb
  124. * Date: 2024/8/14
  125. * Time: 14:29
  126. */
  127. public function updateUser(Request $request)
  128. {
  129. $params = $request->post();
  130. if (empty($params['mobile'])) {
  131. return json_fail('手机号不能为空');
  132. }
  133. if (empty($params['name'])) {
  134. return json_fail('姓名不能为空');
  135. }
  136. if (empty($params['gender'])) {
  137. return json_fail('性别不能为空');
  138. }
  139. return UserService::update($params);
  140. }
  141. /**
  142. * Notes: 删除成员
  143. * User: yb
  144. * Date: 2024/8/15
  145. * Time: 11:38
  146. * @param Request $request
  147. */
  148. public function deleteUser(Request $request)
  149. {
  150. $params = $request->post();
  151. if (empty($params['id'])) {
  152. return json_fail('成员id不能为空');
  153. }
  154. return UserService::del($params['id']);
  155. }
  156. /**
  157. * Notes: 设置密码
  158. * User: yb
  159. * Date: 2024/8/14
  160. * Time: 14:44
  161. */
  162. public function setPassword(Request $request)
  163. {
  164. $params = $request->post();
  165. if (empty($params['old_password'])) {
  166. return json_fail('旧密码不能为空');
  167. }
  168. if (empty($params['new_password'])) {
  169. return json_fail('新密码不能为空');
  170. }
  171. return UserService::editPassword($params);
  172. }
  173. /**
  174. * Notes: 我的成员
  175. * User: yb
  176. * Date: 2024/8/14
  177. * Time: 15:24
  178. */
  179. public function userList(Request $request)
  180. {
  181. $params = $request->post();
  182. return UserService::index($params);
  183. }
  184. /**
  185. * Notes: 添加员工
  186. * User: yb
  187. * Date: 2024/8/15
  188. * Time: 9:54
  189. * @param Request $request
  190. * @return Response
  191. */
  192. public function addUser(Request $request)
  193. {
  194. $params = $request->post();
  195. if (empty($params['mobile'])) {
  196. return json_fail('手机号不能为空');
  197. }
  198. if (empty($params['name'])) {
  199. return json_fail('姓名不能为空');
  200. }
  201. if (empty($params['gender'])) {
  202. return json_fail('性别不能为空');
  203. }
  204. if (empty($params['dept_id'])) {
  205. return json_fail('所属部门不能为空');
  206. }
  207. if (empty($params['status'])) {
  208. return json_fail('状态不能为空');
  209. }
  210. return UserService::add($params);
  211. }
  212. /**
  213. * Notes: 我的团队
  214. * User: yb
  215. * Date: 2024/8/14
  216. * Time: 16:38
  217. * @return \support\Response
  218. */
  219. public function teamList()
  220. {
  221. return $this->formatTree(UserService::getTeamList());
  222. }
  223. protected function formatTree($items): Response
  224. {
  225. $format_items = [];
  226. foreach ($items as $item) {
  227. $format_items[] = [
  228. 'label' => $item->dept_name,
  229. 'value' => (string)$item->dept_id,
  230. 'id' => $item->id ?? $item->dept_id,
  231. 'pid' => $item->pid ?? $item->dept_super_id
  232. ];
  233. }
  234. $tree = new Tree($format_items);
  235. return json_success('success', $tree->getTree());
  236. }
  237. }