UserService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. namespace app\wechat\service;
  3. use app\model\Consultant;
  4. use app\model\MarketCustomer;
  5. use app\model\MarketCustomerFollow;
  6. use app\model\SysDept;
  7. use Carbon\Carbon;
  8. use support\Db;
  9. use support\exception\BusinessException;
  10. use Tinywan\Jwt\JwtToken;
  11. class UserService
  12. {
  13. /**
  14. * Notes: 获取所有顾问
  15. * User: yb
  16. * Date: 2024/8/15
  17. * Time: 11:51
  18. * @param $params
  19. */
  20. public static function getAll($params)
  21. {
  22. $ids = self::getIds(1);
  23. $where = [
  24. [function($query) use ($ids) {
  25. $query->whereIn('id', $ids);
  26. }]
  27. ];
  28. if (!empty($params['not_id'])) {
  29. $where[] = ['id', '<>', $params['not_id']];
  30. }
  31. //获取所有团队
  32. $teamKeys = TeamService::getTeams()->pluck('dept_name', 'dept_id');
  33. $list = Consultant::where($where)->select(['id','name','mobile','gender','status','dept_id','created_at'])->orderBy('created_at', 'desc')->get();
  34. if (!empty($list)) {
  35. foreach ($list as $item) {
  36. $item->dept_name = $teamKeys[$item->dept_id] ?? '';
  37. }
  38. }
  39. return json_success('请求成功', $list);
  40. }
  41. /**
  42. * Notes: 团队成员
  43. * User: yb
  44. * Date: 2024/8/14
  45. * Time: 15:34
  46. * @param $params
  47. */
  48. public static function index($params)
  49. {
  50. $page = $params['page'] ?? 1;
  51. $size = $params['size'] ?? 10;
  52. $ids = self::getIds(1);
  53. $where = [
  54. [function($query) use ($ids) {
  55. $query->whereIn('id', $ids);
  56. }]
  57. ];
  58. if (!empty($params['status'])) {
  59. $where[] = ['status', '=', $params['status']];
  60. }
  61. if (!empty($params['consultant'])) {
  62. $keywords = $params['consultant'];
  63. $where[] = [function($query) use ($keywords) {
  64. $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
  65. }];
  66. }
  67. if (!empty($params['dept_id'])) {
  68. $deptIds = $params['dept_id'];
  69. $deptId = end($deptIds);
  70. $where[] = ['dept_id', '=', $deptId];
  71. }
  72. if (!empty($params['created_at'])) {
  73. $datetime = $params['created_at'];
  74. $startTime = strtotime($datetime['start'].' 00:00:00');
  75. $endTime = strtotime($datetime['end'].' 23:59:59');
  76. $where[] = [function($query) use ($startTime, $endTime) {
  77. $query->whereBetween('created_at', [$startTime, $endTime]);
  78. }];
  79. }
  80. $paginator = Consultant::where($where)->orderBy('created_at', 'desc')->paginate($size, ['id','name','mobile','gender','status','dept_id','created_at'], 'page', $page);
  81. $total = $paginator->total();
  82. $items = $paginator->items();
  83. $data = [
  84. 'total' => $total,
  85. 'rows' => $items
  86. ];
  87. return json_success('success', $data);
  88. }
  89. /**
  90. * Notes: 删除成员
  91. * User: yb
  92. * Date: 2024/8/15
  93. * Time: 11:39
  94. * @param $id
  95. */
  96. public static function del($id)
  97. {
  98. if(MarketCustomer::where('consultant_id', $id)->exists()) {
  99. return json_fail('成员下存在客户,请移交客户后删除成员');
  100. }
  101. $result = Consultant::where('id', $id)->delete();
  102. if ($result) {
  103. return json_success('删除成功');
  104. } else {
  105. return json_fail('删除失败');
  106. }
  107. }
  108. /**
  109. * Notes: 成员详情
  110. * User: yb
  111. * Date: 2024/8/15
  112. * Time: 10:19
  113. * @param $id
  114. */
  115. public static function getInfoById($id)
  116. {
  117. $info = Consultant::firstWhere(['id' => $id]);
  118. if (empty($info)) {
  119. return json_fail('成员信息不存在');
  120. }
  121. return json_success('请求成功', $info);
  122. }
  123. /**
  124. * Notes: 编辑成员
  125. * User: yb
  126. * Date: 2024/8/15
  127. * Time: 10:28
  128. * @param $params
  129. */
  130. public static function updateById($params)
  131. {
  132. if (empty($params['id'])) {
  133. return json_fail('成员id不能为空');
  134. }
  135. //查找员工信息
  136. $info = Consultant::find($params['id']);
  137. $oldDeptId = $info->dept_id;
  138. if (empty($info)) {
  139. return json_fail('成员不存在');
  140. }
  141. if (!self::checkMobile($params['mobile'])) {
  142. return json_fail('请输入正确的手机号');
  143. }
  144. //查询员工是否已被注册
  145. if (Consultant::where('mobile', $params['mobile'])->where('id', '<>', $params['id'])->exists()) {
  146. return json_fail('手机号已存在,成员已被注册');
  147. }
  148. //校验密码规则
  149. if (!empty($params['password'])) {
  150. $passwordLen = strlen($params['password']);
  151. if ($passwordLen > 20 || $passwordLen < 6) {
  152. return json_fail('请输入6-20位密码');
  153. }
  154. $password = self::handlePassword($params['password']);
  155. }
  156. //查询上级团队
  157. $topDeptId = SysDept::where('dept_id', $params['dept_id'])->where('dept_category', TeamService::DEPT_CATEGORY)->value('dept_super_id');
  158. if (!is_numeric($topDeptId)) {
  159. return json_fail('团队不存在');
  160. }
  161. $updateData = [
  162. 'name' => $params['name'],
  163. 'mobile' => $params['mobile'],
  164. 'dept_id' => $params['dept_id'],
  165. 'top_dept_id' => $topDeptId,
  166. 'gender' => $params['gender'] ?? 1,
  167. 'status' => $params['status'] ?? 1,
  168. 'updated_at' => time()
  169. ];
  170. if (!empty($params['password'])) {
  171. $updateData['password'] = $password;
  172. }
  173. $result = false;
  174. Db::beginTransaction();
  175. try {
  176. $result = Consultant::where('id', $params['id'])->update($updateData);
  177. if ($updateData['dept_id'] != $oldDeptId) {
  178. //修改成员所属部门
  179. MarketCustomer::where('consultant_id', '=', $params['id'])->update(['updated_at' => time(), 'dept_id' => $updateData['dept_id']]);
  180. }
  181. Db::commit();
  182. }catch (BusinessException|\Exception $e) {
  183. Db::rollBack();
  184. return json_fail($e->getMessage());
  185. }
  186. if ($result) {
  187. return json_success('编辑成功');
  188. } else {
  189. return json_fail('编辑失败');
  190. }
  191. }
  192. /**
  193. * Notes: 添加员工
  194. * User: yb
  195. * Date: 2024/8/15
  196. * Time: 9:55
  197. * @param $params
  198. */
  199. public static function add($params)
  200. {
  201. if (!self::checkMobile($params['mobile'])) {
  202. return json_fail('请输入正确的手机号');
  203. }
  204. //查询员工是否已被注册
  205. if (Consultant::where('mobile', $params['mobile'])->exists()) {
  206. return json_fail('手机号已存在,成员已被注册');
  207. }
  208. //校验密码规则
  209. if (!empty($params['password'])) {
  210. $passwordLen = strlen($params['password']);
  211. if ($passwordLen > 20 || $passwordLen < 6) {
  212. return json_fail('请输入6-20位密码');
  213. }
  214. }
  215. //查询上级团队
  216. $topDeptId = SysDept::where('dept_id', $params['dept_id'])->where('dept_category', TeamService::DEPT_CATEGORY)->value('dept_super_id');
  217. if (!is_numeric($topDeptId)) {
  218. return json_fail('团队不存在');
  219. }
  220. if (empty($params['password'])) {
  221. $showPassword = substr($params['mobile'], 5);
  222. $password = self::handlePassword($showPassword);
  223. } else {
  224. $password = self::handlePassword($params['password']);
  225. }
  226. $insertData = [
  227. 'name' => $params['name'],
  228. 'mobile' => $params['mobile'],
  229. 'dept_id' => $params['dept_id'],
  230. 'top_dept_id' => $topDeptId,
  231. 'gender' => $params['gender'] ?? 1,
  232. 'password' => $password,
  233. 'status' => $params['status'] ?? 1,
  234. 'relation_user_id' => $params['relation_user_id'] ?? null,
  235. 'type' => 2,
  236. 'created_at' => time()
  237. ];
  238. $result = Consultant::insert($insertData);
  239. if ($result) {
  240. return json_success('新增成功');
  241. } else {
  242. return json_fail('新增失败');
  243. }
  244. }
  245. /**
  246. * Notes: 登录
  247. * User: yb
  248. * Date: 2024/8/8
  249. * Time: 9:20
  250. * @param $data
  251. */
  252. public static function login($data)
  253. {
  254. $password = $data['password'];
  255. $mobile = $data['mobile'];
  256. $userInfo = Consultant::firstWhere(['mobile' => $mobile]);
  257. if (empty($userInfo)) {
  258. return json_fail('用户不存在');
  259. }
  260. //校验密码
  261. $confoundPassword = $userInfo->password;
  262. if ($confoundPassword != md5(md5($password))) {
  263. return json_fail('密码错误');
  264. }
  265. $status = $userInfo->status;
  266. if ($status != 1) {
  267. return json_fail('用户已离职');
  268. }
  269. $extend = [
  270. 'id' => $userInfo->id,
  271. 'client' => 'wechat',
  272. 'name'=> $userInfo->name,
  273. 'user_type' => $userInfo->type
  274. ];
  275. $token = JwtToken::generateToken($extend);
  276. $token['user_type'] = $extend['user_type'];
  277. return json_success('', $token);
  278. }
  279. /**
  280. * Notes: 获取身份信息
  281. * User: yb
  282. * Date: 2024/8/8
  283. * Time: 10:09
  284. */
  285. public static function auth()
  286. {
  287. $userId = JwtToken::getCurrentId();
  288. $userInfo = Consultant::firstWhere(['id' => $userId]);
  289. if (empty($userInfo)) {
  290. return json_fail('用户不存在');
  291. }
  292. $status = $userInfo->status;
  293. if ($status != 1) {
  294. return json_fail('用户已离职');
  295. }
  296. $type = $userInfo->type;
  297. $relationUserId = $userInfo->relation_user_id;
  298. return json_success('请求成功', ['type' => $type, 'relation_user_id' => $relationUserId]);
  299. }
  300. /**
  301. * Notes: 获取需要查询的ids
  302. * User: yb
  303. * Date: 2024/8/13
  304. * Time: 15:58
  305. * @return array
  306. */
  307. public static function getIds($clearSelf = 0)
  308. {
  309. $userId = JwtToken::getCurrentId();
  310. $userInfo = Consultant::firstWhere(['id' => $userId]);
  311. if (empty($userInfo)) {
  312. return [];
  313. }
  314. $ids = [];
  315. if ($userInfo->type == 1) {
  316. //管理账号
  317. $deptId = $userInfo->dept_id;
  318. $deptIds = TeamService::getIds($deptId);
  319. //团队下的所有员工
  320. $where = [
  321. [function($query) use ($deptIds) {
  322. $query->whereIn('dept_id', $deptIds);
  323. }]
  324. ];
  325. if ($clearSelf == 1) {
  326. $where[] = ['id', '<>', $userId];
  327. }
  328. $ids = Consultant::where($where)->pluck('id')->toArray();
  329. } else if ($userInfo->type == 2){
  330. //普通账号
  331. $ids[] = $userId;
  332. } else if ($userInfo->type == 3) {
  333. //判客账户
  334. $ids = Consultant::pluck('id')->toArray();
  335. }
  336. return $ids;
  337. }
  338. /**
  339. * Notes: 首页统计分析
  340. * User: yb
  341. * Date: 2024/8/14
  342. * Time: 10:23
  343. */
  344. public static function statistics($params)
  345. {
  346. //统计客户总数
  347. $userIds = self::getIds();
  348. $currentTime = time();
  349. $diffNums = CustomService::DIFF_TIME;
  350. $whereFollow = [
  351. [function($query) use ($userIds) {
  352. $query->whereIn('consultant_id', $userIds);
  353. }]
  354. ];
  355. $where = [];
  356. $where[] = [function($query) use ($userIds) {
  357. $query->orWhereIn('consultant_id', $userIds)->orWhereIn('report_consultant_id', $userIds);
  358. }];
  359. $where[] = [function($query) use ($diffNums, $currentTime){
  360. $query->orWhereRaw("check_status IN (-1, 1)")
  361. ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
  362. ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)")
  363. ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
  364. }];
  365. //客户总量
  366. $customNums = MarketCustomer::where($where)->count();
  367. if (!empty($params['time'])) {
  368. $time = $params['time'];
  369. $start = strtotime($time[0]);
  370. $end = strtotime($time[1]);
  371. } else {
  372. $startDate = date('Y-m-01', strtotime(date('Y-m-d')));
  373. $endDate = date('Y-m-t', strtotime(date('Y-m-d')));
  374. $start = strtotime($startDate.' 00:00:00');
  375. $end = strtotime($endDate.' 23:59:59');
  376. }
  377. $where[] = [function($query) use ($start, $end) {
  378. $query->whereBetween('created_at', [$start, $end]);
  379. }];
  380. $whereFollow[] = [function($query) use ($start, $end) {
  381. $query->whereBetween('created_at', [$start, $end]);
  382. }];
  383. //待转到访客户数量
  384. $checkCustomNums = MarketCustomer::where($where)->where('check_status', 1)->where('current_status', 1)->count();
  385. //新增客户
  386. $newCustomNums = MarketCustomer::where($where)->count();
  387. //已报备客户数
  388. $reportCustomNums = MarketCustomer::where($where)->where('current_status', 1)->count();
  389. //已到访客户数量
  390. $visitCustomNums = MarketCustomer::where($where)->where('current_status', 2)->where('check_status', 2)->count();
  391. //已缴费客户数量
  392. $payCustomNums = MarketCustomer::where($where)->where('current_status', 3)->where('check_status', 2)->count();
  393. //已成交客户数量
  394. $dealCustomNums = MarketCustomer::where($where)->where('current_status', 4)->where('check_status', 2)->count();
  395. //新增跟进记录数量
  396. $newFollowNums = MarketCustomerFollow::where($whereFollow)->count();
  397. /* 男女数量 */
  398. $genderDataNums = [
  399. ['label' => '男', 'value' => 1, 'nums' => 0],
  400. ['label' => '女', 'value' => 2, 'nums' => 0],
  401. ];
  402. $genderData = MarketCustomer::where($where)->select(Db::raw('gender, count(*) as nums'))->groupBy('gender')->get();
  403. if (!$genderData->isEmpty()) {
  404. $genderData = $genderData->toArray();
  405. foreach ($genderDataNums as $genderKey => $genderVal) {
  406. foreach ($genderData as $genderItem) {
  407. if ($genderItem['gender'] == $genderVal['value']) {
  408. $genderDataNums[$genderKey]['nums'] = $genderItem['nums'];
  409. }
  410. }
  411. }
  412. }
  413. /* 客户级别 */
  414. $levelDataNums = [
  415. ['label' => 'A类', 'value' => 1, 'nums' => 0],
  416. ['label' => 'B类', 'value' => 2, 'nums' => 0],
  417. ['label' => 'C类', 'value' => 3, 'nums' => 0],
  418. ['label' => 'D类', 'value' => 4, 'nums' => 0],
  419. ['label' => '其他', 'value' => "", 'nums' => 0],
  420. ];
  421. $levelData = MarketCustomer::where($where)->select(Db::raw('level, count(*) as nums'))->groupBy('level')->get();
  422. if (!$levelData->isEmpty()) {
  423. $levelData = $levelData->toArray();
  424. $levelData = array_column($levelData, 'nums', 'level');
  425. foreach ($levelDataNums as $levelKey => $levelVal) {
  426. if (isset($levelData[$levelVal['value']])) {
  427. $levelDataNums[$levelKey]['nums'] = $levelData[$levelVal['value']];
  428. }
  429. }
  430. }
  431. $data = [
  432. 'custom_nums' => $customNums,
  433. 'check_custom_nums' => $checkCustomNums,
  434. 'new_custom_nums' => $newCustomNums,
  435. 'report_custom_nums' => $reportCustomNums,
  436. 'visit_custom_nums' => $visitCustomNums,
  437. 'pay_custom_nums' => $payCustomNums,
  438. 'deal_custom_nums' => $dealCustomNums,
  439. 'new_follow_nums' => $newFollowNums,
  440. 'gender_data_nums' => $genderDataNums,
  441. 'level_data_nums' => $levelDataNums
  442. ];
  443. return json_success('请求成功', $data);
  444. }
  445. /**
  446. * Notes: 近7日客户走势
  447. * User: yb
  448. * Date: 2024/8/17
  449. * Time: 17:44
  450. */
  451. public static function customTrend($params)
  452. {
  453. $currentTime = time();
  454. $diffNums = CustomService::DIFF_TIME;
  455. //统计客户总数
  456. $userIds = self::getIds();
  457. $where = [
  458. [function($query) use ($userIds) {
  459. $query->whereIn('consultant_id', $userIds);
  460. }],
  461. [function($query) use ($diffNums, $currentTime){
  462. $query->orWhereRaw("check_status IN (-1, 1)")
  463. ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
  464. ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
  465. }]
  466. ];
  467. $whereTrend = [];
  468. if (!empty($params['type'])) {
  469. $whereTrend[] = ['current_status', '=', $params['type']];
  470. }
  471. // 获取当前日期
  472. $today = Carbon::now();
  473. // 初始化日期数组和数量数组
  474. $dates = [date('Y-m-d')];
  475. // 循环7次,获取从今天开始往前推7天的日期
  476. for ($i = 0; $i < 6; $i++) {
  477. // 将日期推回到7天前
  478. $date = $today->subDay()->toDateString();
  479. // 将日期字符串存入数组
  480. $dates[] = $date;
  481. }
  482. // 逆序日期数组,因为我们是从今天往前计算的
  483. $dates = array_reverse($dates);
  484. $dateList = [];
  485. foreach ($dates as $item) {
  486. $dateList[] = ['label' => $item, 'nums' => 0, 'label_sim' => date('m/d', strtotime($item))];
  487. }
  488. $datesStr = implode('","', $dates);
  489. $datesStr = '"'.$datesStr.'"';
  490. $dateRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d') IN ({$datesStr})");
  491. // 构建查询,使用whereBetween或whereIn根据需要筛选日期
  492. $results = MarketCustomer::select(Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d') AS date,count(*) AS nums"))
  493. ->where($where)
  494. ->where($whereTrend)
  495. ->whereRaw($dateRaw)
  496. ->groupBy('date')->get();
  497. if (!$results->isEmpty()) {
  498. $results = $results->toArray();
  499. $results = array_column($results, 'nums', 'date');
  500. foreach ($dateList as $key => $val) {
  501. $dateList[$key]['nums'] = $results[$val['label']] ?? 0;
  502. }
  503. }
  504. //总数
  505. $customNums = MarketCustomer::where($where)->whereRaw($dateRaw)->count();
  506. //到访数
  507. $visitCustomNums = MarketCustomer::where($where)->whereRaw($dateRaw)->where('current_status', 2)->count();
  508. //已缴费数
  509. $payCustomNums = MarketCustomer::where($where)->whereRaw($dateRaw)->where('current_status', 3)->count();
  510. //已成交数
  511. $dealCustomNums = MarketCustomer::where($where)->whereRaw($dateRaw)->where('current_status', 4)->count();
  512. $data = [
  513. 'dateList' => $dateList,
  514. 'visit_nums' => $visitCustomNums,
  515. 'pay_nums' => $payCustomNums,
  516. 'deal_nums' => $dealCustomNums,
  517. 'total_nums' => $customNums
  518. ];
  519. return json_success('请求成功', $data);
  520. }
  521. /**
  522. * Notes: 用户详情
  523. * User: yb
  524. * Date: 2024/8/14
  525. * Time: 13:35
  526. */
  527. public static function info()
  528. {
  529. $userId = JwtToken::getCurrentId();
  530. $info = Consultant::firstWhere(['id' => $userId]);
  531. if (!empty($info)) {
  532. $info->dept_name = SysDept::where('dept_id', $info->dept_id)->value('dept_name');
  533. }
  534. return json_success('请求成功', $info);
  535. }
  536. /**
  537. * Notes: 修改个人信息
  538. * User: yb
  539. * Date: 2024/8/14
  540. * Time: 14:19
  541. * @param $params
  542. */
  543. public static function update($params)
  544. {
  545. $userId = JwtToken::getCurrentId();
  546. if (!self::checkMobile($params['mobile'])) {
  547. return json_fail('请输入正确的手机号');
  548. }
  549. //查询员工是否已被注册
  550. if (Consultant::where('mobile', $params['mobile'])->where('id', '<>', $userId)->exists()) {
  551. return json_fail('手机号已存在');
  552. }
  553. $info = Consultant::firstWhere(['id' => $userId]);
  554. if (empty($info)) {
  555. return json_fail('用户不存在');
  556. }
  557. $info->name = $params['name'];
  558. $info->gender = $params['gender'];
  559. $info->mobile = $params['mobile'];
  560. $result = $info->save();
  561. if ($result) {
  562. return json_success('修改成功');
  563. } else {
  564. return json_fail('修改失败');
  565. }
  566. }
  567. /**
  568. * Notes: 修改密码
  569. * User: yb
  570. * Date: 2024/8/14
  571. * Time: 14:20
  572. * @param $params
  573. */
  574. public static function editPassword($params)
  575. {
  576. $oldPassword = $params['old_password'];
  577. $password = $params['new_password'];
  578. $rePassword = $params['check_password'] ?? '';
  579. $len = mb_strlen($password);
  580. if ($len < 6) {
  581. return json_fail('密码长度最少为6位');
  582. }
  583. if ($len > 20) {
  584. return json_fail('密码长度最大为20位');
  585. }
  586. if ($password != $rePassword) {
  587. return json_fail('密码与确认密码不一致');
  588. }
  589. $userId = JwtToken::getCurrentId();
  590. $info = Consultant::firstWhere(['id' => $userId]);
  591. if (empty($info)) {
  592. return json_fail('用户不存在');
  593. }
  594. //校验密码
  595. $confoundPassword = $info->password;
  596. if ($confoundPassword != md5(md5($oldPassword))) {
  597. return json_fail('旧密码错误');
  598. }
  599. $info->password = md5(md5($password));
  600. $result = $info->save();
  601. if ($result) {
  602. return json_success('修改成功');
  603. } else {
  604. return json_fail('修改失败');
  605. }
  606. }
  607. /**
  608. * Notes: 团队列表
  609. * User: yb
  610. * Date: 2024/8/14
  611. * Time: 16:32
  612. */
  613. public static function getTeamList()
  614. {
  615. $userId = JwtToken::getCurrentId();
  616. $info = Consultant::firstWhere(['id' => $userId]);
  617. if (empty($info)) {
  618. return json_success('请求成功');
  619. }
  620. $deptId = $info->dept_id;
  621. $list = TeamService::getTeamList($deptId);
  622. return $list;
  623. }
  624. /**
  625. * Notes:校验手机号
  626. * User: yb
  627. * Date: 2024/8/2
  628. * Time: 11:12
  629. * @param $mobile
  630. * @return bool
  631. */
  632. protected static function checkMobile($mobile)
  633. {
  634. if (preg_match('/^1[0-9]\d{9}$/', $mobile)) {
  635. return true;
  636. } else {
  637. return false;
  638. }
  639. }
  640. /**
  641. * Notes: 处理密码
  642. * User: yb
  643. * Date: 2024/8/2
  644. * Time: 11:19
  645. * @param $password
  646. * @return mixed
  647. */
  648. protected static function handlePassword($password)
  649. {
  650. return md5(md5($password));
  651. }
  652. }