CustomService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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\MarketCustomerLogs;
  7. use app\wechat\validate\CustomValidate;
  8. use support\Db;
  9. use support\exception\BusinessException;
  10. use Tinywan\Jwt\JwtToken;
  11. class CustomService
  12. {
  13. const DIFF_TIME = (60 * 60 * 24 * 30);
  14. /**
  15. * Notes: 选项配置
  16. * User: yb
  17. * Date: 2024/8/8
  18. * Time: 15:18
  19. * @return array
  20. */
  21. public static function config()
  22. {
  23. $options = MarketCustomer::config();
  24. if (isset($options['visit_type'])) {
  25. //如果存在拜访方式,直接在后台处理完成后返回前台
  26. foreach ($options['visit_type'] as $key => $val) {
  27. $data = [];
  28. foreach ($val as $index => $item) {
  29. $data[] = ['text' => $item, 'value' => $index];
  30. }
  31. $options['visit_type'][$key] = $data;
  32. }
  33. }
  34. return $options;
  35. }
  36. /**
  37. * Notes: 客户列表
  38. * User: yb
  39. * Date: 2024/8/12
  40. * Time: 11:08
  41. * @param $params
  42. */
  43. public static function index($params)
  44. {
  45. $page = $params['page'] ?? 1;
  46. $size = $params['size'] ?? 10;
  47. //查询顾问信息
  48. $consultantId = JwtToken::getCurrentId();
  49. $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
  50. $deptId = $consultantInfo->dept_id;
  51. $type = $consultantInfo->type;
  52. $currentTime = time();
  53. $diffNums = self::DIFF_TIME;
  54. $where = [];
  55. $whereFollow = [];
  56. if ($type == 1) {
  57. //团队下所有的
  58. $deptIds = TeamService::getIds($deptId);
  59. $where[] = [function($query) use ($deptIds) {
  60. $query->whereIn('dept_id', $deptIds);
  61. }];
  62. if (!empty($params['consultant_id'])) {
  63. $where[] = ['consultant_id', '=', $params['consultant_id']];
  64. $whereFollow[] = ['consultant_id', '=', $params['consultant_id']];
  65. } else {
  66. $consultantIds = UserService::getIds(1);
  67. $whereFollow[] = [function($query) use ($consultantIds) {
  68. $query->whereIn('consultant_id', $consultantIds);
  69. }];
  70. }
  71. } else {
  72. //个人的
  73. $where[] = ['consultant_id', '=', $consultantId];
  74. $whereFollow[] = ['consultant_id', '=', $consultantId];
  75. }
  76. if (!empty($params['custom'])) {
  77. $keywords = $params['custom'];
  78. $where[] = [function($query) use ($keywords) {
  79. $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
  80. }];
  81. }
  82. if (!empty($params['report_status'])) {
  83. if ($params['report_status'] == 1) {
  84. //已报备
  85. $where[] = [function($query) use ($diffNums, $currentTime) {
  86. $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1)->where('check_status', '=', 2);
  87. }];
  88. } else if ($params['report_status'] == 3) {
  89. //已锁定
  90. $where[] = [function($query) {
  91. $query->whereIn('current_status', [2,3,4])->where('check_status', '=', 2);
  92. }];
  93. } else if ($params['report_status'] == 2) {
  94. //已失效
  95. $where[] = [function($query) use ($diffNums, $currentTime){
  96. $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1)");
  97. }];
  98. $where[] = ['check_status', '=', 2];
  99. } else if ($params['report_status'] == '-1') {
  100. //待审核
  101. $where[] = ['check_status', '=', 1];
  102. }
  103. }
  104. if (!empty($params['check_status'])) {
  105. $where[] = ['check_status', '=', $params['check_status']];
  106. }
  107. if (!empty($params['type'])) {
  108. $where[] = ['type', '=', $params['type']];
  109. }
  110. if (!empty($params['visit_time'])) {
  111. $datetime = $params['visit_time'];
  112. $startTime = strtotime($datetime['start'].' 00:00:00');
  113. $endTime = strtotime($datetime['end'].' 23:59:59');
  114. $where[] = [function($query) use ($startTime, $endTime) {
  115. $query->whereBetween('visit_time', [$startTime, $endTime]);
  116. }];
  117. }
  118. if (!empty($params['current_status'])) {
  119. $currentStatus = $params['current_status'];
  120. $where[] = [function($query) use ($currentStatus) {
  121. $query->where('current_status', $currentStatus)->where('check_status', 2);
  122. }];
  123. }
  124. if (!empty($params['created_at'])) {
  125. $createdAt = $params['created_at'];
  126. if (is_array($createdAt)) {
  127. $createdAtStart = strtotime($createdAt[0]);
  128. $createdAtEnd = strtotime($createdAt[1]);
  129. } else {
  130. //本月开始和结束
  131. $createdAtStart = strtotime(date('Y-m-01 00:00:00'));
  132. $createdAtEnd = strtotime(date('Y-m-t 23:59:59'));
  133. }
  134. $where[] = [function($query) use ($createdAtStart,$createdAtEnd) {
  135. $query->whereBetween('created_at', [$createdAtStart, $createdAtEnd]);
  136. }];
  137. }
  138. $fn = function ($query) {
  139. $query->select('name', 'mobile', 'id');
  140. };
  141. $paginator = MarketCustomer::with(['consultant' => $fn])->where($where)->orderBy('visit_time', 'desc')->paginate($size, '*', 'page', $page);
  142. $total = $paginator->total();
  143. $items = $paginator->items();
  144. if (!empty($items)) {
  145. $now = time();
  146. foreach ($items as &$item) {
  147. $item->mask_mobile = self::handlePhone($item->mobile);
  148. $visitTimeInt = strtotime($item->visit_time);
  149. $endTime = $visitTimeInt + 60 * 60 * 24 * 30;
  150. $visitTimeInt = $endTime - $now;
  151. if ($visitTimeInt <= 0) {
  152. $visitTimeInt = 0;
  153. }
  154. $item->visit_time_int = $visitTimeInt;
  155. }
  156. }
  157. //本日新增
  158. $date = date('Y-m-d');
  159. $start = strtotime($date.' 00:00:00');
  160. $end = strtotime($date.' 23:59:59');
  161. $newNums = MarketCustomer::where($where)->whereBetween('created_at', [$start, $end])->count();
  162. $followNums = MarketCustomerFollow::where($whereFollow)->whereBetween('created_at', [$start, $end])->count();
  163. $data = [
  164. 'new_follow_num' => $followNums,
  165. 'new_custom_num' => $newNums,
  166. 'total' => $total,
  167. 'rows' => $items
  168. ];
  169. return json_success('success', $data);
  170. }
  171. /**
  172. * Notes: 我的客户
  173. * User: yb
  174. * Date: 2024/8/13
  175. * Time: 15:14
  176. * @param $params
  177. */
  178. public static function myCustomList($params)
  179. {
  180. $page = $params['page'] ?? 1;
  181. $size = $params['size'] ?? 10;
  182. //查询有效顾问信息
  183. $consultantId = JwtToken::getCurrentId();
  184. $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
  185. $deptId = $consultantInfo->dept_id;
  186. $type = $consultantInfo->type;
  187. $where = [];
  188. if ($type == 1) {
  189. //团队下所有的
  190. $deptIds = TeamService::getIds($deptId);
  191. $where[] = [function($query) use ($deptIds) {
  192. $query->whereIn('dept_id', $deptIds);
  193. }];
  194. } else {
  195. //个人的
  196. $where[] = ['consultant_id', '=', $consultantId];
  197. }
  198. $where[] = ['check_status', '=', 2];
  199. $where[] = [function($query) {
  200. $query->orWhere(function ($query){
  201. $diffNums = (60 * 60 * 24 * 30);
  202. $currentTime = time();
  203. $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
  204. })->orWhereIn('current_status', [2,3,4]);
  205. }];
  206. if (!empty($params['custom'])) {
  207. $keywords = $params['custom'];
  208. $where[] = [function($query) use ($keywords) {
  209. $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
  210. }];
  211. }
  212. $paginator = MarketCustomer::where($where)->orderBy('created_at', 'desc')->paginate($size, ['id','name','mobile','gender'], 'page', $page);
  213. $total = $paginator->total();
  214. $items = $paginator->items();
  215. if (!empty($items)) {
  216. foreach ($items as &$item) {
  217. $item->mask_mobile = self::handlePhone($item->mobile);
  218. }
  219. }
  220. $data = [
  221. 'total' => $total,
  222. 'rows' => $items
  223. ];
  224. return json_success('success', $data);
  225. }
  226. /**
  227. * Notes: 添加客户
  228. * User: yb
  229. * Date: 2024/8/6
  230. * Time: 11:20
  231. */
  232. public static function add($params)
  233. {
  234. $params = MarketCustomer::handleNumParams($params);
  235. $mobile = $params['mobile'];
  236. //查询客户手机号是否已经存在
  237. if (MarketCustomer::checkCustomExists($mobile)) {
  238. return json_fail('客户已经登记过了');
  239. }
  240. //查询顾问信息
  241. $consultantId = JwtToken::getCurrentId();
  242. $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
  243. if (empty($consultantInfo)) {
  244. return json_fail('顾问信息不存在');
  245. }
  246. $deptId = $consultantInfo->dept_id;
  247. $insertData = [
  248. 'name' => $params['name'],
  249. 'mobile' => $mobile,
  250. 'consultant_id' => $consultantId,
  251. 'dept_id' => $deptId,
  252. 'gender' => $params['gender'] ?? null,
  253. 'visit_type' => $params['visit_type'] ?? null,
  254. 'require_area' => $params['require_area'] ?? null,
  255. 'area' => $params['area'] ?? null,
  256. 'requirement' => $params['requirement'] ?? null,
  257. 'age_range' => $params['age_range'] ?? null,
  258. 'focus' => $params['focus'] ?? null,
  259. 'region' => $params['region'] ?? null,
  260. 'purpose' => $params['purpose'] ?? null,
  261. 'level' => $params['level'] ?? null,
  262. 'type' => $params['type'] ?? null,
  263. 'visit_time' => time(),
  264. 'note' => $params['note'] ?? '',
  265. 'check_status' => 1,
  266. 'current_status' => $params['current_status'] ?? null,
  267. 'created_at' => time()
  268. ];
  269. if ($insertData['type'] == 1) {
  270. $insertData['current_status'] = 1;
  271. } else if ($insertData['type'] == 2) {
  272. $insertData['current_status'] = 2;
  273. }
  274. Db::beginTransaction();
  275. try {
  276. $customId = MarketCustomer::insertGetId($insertData);
  277. Db::commit();
  278. }catch (BusinessException|\Exception $e){
  279. Db::rollBack();
  280. return json_fail($e->getMessage());
  281. }
  282. if ($customId) {
  283. return json_success('添加成功');
  284. } else {
  285. return json_fail('添加失败');
  286. }
  287. }
  288. /**
  289. * Notes: 编辑客户
  290. * User: yb
  291. * Date: 2024/8/12
  292. * Time: 10:23
  293. * @param $params
  294. * @return \support\Response
  295. */
  296. public static function edit($params)
  297. {
  298. $consultantId = JwtToken::getCurrentId();
  299. $params = MarketCustomer::handleNumParams($params);
  300. if (empty($params['id'])) {
  301. return json_fail('客户id不能为空');
  302. }
  303. $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
  304. if (empty($consultantInfo)) {
  305. return json_fail('顾问信息不存在');
  306. }
  307. $info = MarketCustomer::firstWhere(['id' => $params['id'], 'consultant_id' => $consultantId]);
  308. if (empty($info)) {
  309. return json_fail('客户信息不存在');
  310. }
  311. $updateData = [
  312. 'name' => $params['name'],
  313. 'gender' => $params['gender'] ?? null,
  314. 'visit_type' => $params['visit_type'] ?? null,
  315. 'require_area' => $params['require_area'] ?? null,
  316. 'area' => $params['area'] ?? null,
  317. 'requirement' => $params['requirement'] ?? null,
  318. 'age_range' => $params['age_range'] ?? null,
  319. 'focus' => $params['focus'] ?? null,
  320. 'region' => $params['region'] ?? null,
  321. 'purpose' => $params['purpose'] ?? null,
  322. 'level' => $params['level'] ?? null,
  323. 'type' => $params['type'] ?? null,
  324. 'note' => $params['note'] ?? '',
  325. 'updated_at' => time()
  326. ];
  327. if (empty($params['mobile'])) {
  328. return json_fail('手机号不能为空');
  329. }
  330. $mobile = $params['mobile'];
  331. if (false === strpos($mobile,'****')) {
  332. //校验手机号格式
  333. $validate = new CustomValidate();
  334. if (!$validate->scene('phone')->check(['mobile' => $mobile])) {
  335. return json_fail($validate->getError());
  336. }
  337. //修改手机号操作
  338. if (MarketCustomer::checkCustomExists($mobile, $params['id'])) {
  339. return json_fail('客户已经登记过了');
  340. }
  341. $updateData['mobile'] = $mobile;
  342. }
  343. $currentStatus = $info->current_status;
  344. if ($currentStatus == 1) {
  345. //已来电改为已到访
  346. if ($params['type'] == 2) {
  347. $updateData['current_status'] = 2;
  348. }
  349. }
  350. $result = false;
  351. Db::beginTransaction();
  352. try {
  353. $result = MarketCustomer::where('id', $params['id'])->update($updateData);
  354. Db::commit();
  355. }catch (BusinessException|\Exception $e){
  356. Db::rollBack();
  357. return json_fail($e->getMessage());
  358. }
  359. if ($result) {
  360. return json_success('编辑成功');
  361. } else {
  362. return json_fail('编辑失败');
  363. }
  364. }
  365. /**
  366. * Notes: 客户详情
  367. * User: yb
  368. * Date: 2024/8/8
  369. * Time: 15:36
  370. * @param $params
  371. */
  372. public static function info($id)
  373. {
  374. $customInfo = MarketCustomer::firstWhere(['id' => $id]);
  375. if (empty($customInfo)) {
  376. return json_fail('客户不存在');
  377. }
  378. //手机号加密处理
  379. $customInfo->mask_mobile = self::handlePhone($customInfo->mobile);
  380. //查询负责顾问
  381. $consultantName = Consultant::where('id', $customInfo->consultant_id)->value('name');
  382. $customInfo->consultant_name = $consultantName;
  383. //查询最新的跟进记录
  384. $follow = MarketCustomerFollow::where('market_customer_id', $id)->orderBy('created_at', 'desc')->first();
  385. $customInfo->follow = $follow;
  386. $focus = $customInfo->focus;
  387. if (!empty($focus)) {
  388. $customInfo->focus = explode(',', $focus);
  389. }
  390. return json_success('', $customInfo);
  391. }
  392. /**
  393. * Notes: 更新客户状态
  394. * User: yb
  395. * Date: 2024/8/14
  396. * Time: 13:23
  397. * @param $params
  398. */
  399. public static function updateStatus($params)
  400. {
  401. $customId = $params['id'];
  402. $currentStatus = $params['current_status'];
  403. if (!in_array($currentStatus, [-1, 3, 4])) {
  404. return json_fail('状态值非法');
  405. }
  406. $info = MarketCustomer::firstWhere(['id' => $customId]);
  407. if (empty($info)) {
  408. return json_fail('客户不存在');
  409. }
  410. $info->current_status = $currentStatus;
  411. $result = $info->save();
  412. if ($result) {
  413. return json_success('更新成功');
  414. } else {
  415. return json_fail('更新失败');
  416. }
  417. }
  418. /**
  419. * Notes: 转移客户
  420. * User: yb
  421. * Date: 2024/8/7
  422. * Time: 14:27
  423. * @param $params
  424. */
  425. public static function moveCustom($params)
  426. {
  427. $userId = JwtToken::getCurrentId();
  428. //获取绑定的管理信息
  429. $userInfo = Consultant::firstWhere(['id' => $userId]);
  430. if (empty($userInfo)) {
  431. return json_fail('管理员信息不存在');
  432. }
  433. if ($userInfo->type != 1) {
  434. return json_fail('操作权限不足');
  435. }
  436. $relationUserId = $userInfo->relation_user_id;
  437. $currentConsultantId = $params['consultant_id']; //当前顾问
  438. $consultantId = $params['move_consultant_id'] ?? 0;
  439. $customId = $params['move_market_customer_id'] ?? 0;
  440. $note = $params['note'] ?? '';
  441. $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]);
  442. if (empty($consultantInfo)) {
  443. return json_fail('接收成员不存在');
  444. }
  445. $currentDeptId = $consultantInfo->dept_id; //当前部门
  446. $logsInertData = [];
  447. $now = time();
  448. $whereCustom = [];
  449. if (!empty($customId)) {
  450. $whereCustom[] = ['id', '=', $customId];
  451. }
  452. if (!empty($consultantId)) {
  453. $whereCustom[] = ['consultant_id', '=', $consultantId];
  454. }
  455. $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
  456. if (!$customList->isEmpty()) {
  457. foreach ($customList as$item) {
  458. $logsInertData[] = [
  459. 'market_customer_id' => $item->id,
  460. 'consultant_id' => $currentConsultantId,
  461. 'dept_id' => $currentDeptId,
  462. 'before_consultant_id' => $item->consultant_id,
  463. 'before_dept_id' => $item->dept_id,
  464. 'note' => $note,
  465. 'change_user_id' => $relationUserId,
  466. 'change_consultant_id' => $userId,
  467. 'created_at' => $now
  468. ];
  469. }
  470. }
  471. if ($customList->isEmpty()) {
  472. return json_fail('成员没有客户记录');
  473. }
  474. if (empty($logsInertData)) {
  475. return json_fail('移交记录不能为空');
  476. }
  477. Db::beginTransaction();
  478. $result = false;
  479. try {
  480. foreach ($customList as $item) {
  481. $item->consultant_id = $currentConsultantId;
  482. $item->dept_id = $currentDeptId;
  483. $item->save();
  484. }
  485. $result = MarketCustomerLogs::insert($logsInertData);
  486. Db::commit();
  487. }catch (BusinessException|\Exception $e) {
  488. Db::rollBack();
  489. return json_fail($e->getMessage());
  490. }
  491. if ($result) {
  492. return json_success('移交成功');
  493. } else {
  494. return json_fail('移交失败');
  495. }
  496. }
  497. /**
  498. * Notes: 转移记录
  499. * User: yb
  500. * Date: 2024/8/7
  501. * Time: 15:33
  502. * @param $params
  503. */
  504. public static function moveLogs($params)
  505. {
  506. $page = $params['page'] ?? 1;
  507. $size = $params['size'] ?? 10;
  508. $where = [];
  509. if (!empty($params['custom_id'])) {
  510. $where[] = ['market_customer_id', '=', $params['custom_id']];
  511. }
  512. $selectFn = function ($query){
  513. $query->select('name', 'mobile', 'id');
  514. };
  515. $paginator = MarketCustomerLogs::with(['custom' => $selectFn, 'beforeMan' => $selectFn, 'currentMan' => $selectFn])
  516. ->where($where)
  517. ->orderBy('created_at', 'desc')
  518. ->paginate($size, '*', 'page', $page);
  519. $total = $paginator->total();
  520. $items = $paginator->items();
  521. $data = [
  522. 'total' => $total,
  523. 'rows' => $items
  524. ];
  525. return json_success('success', $data);
  526. }
  527. /**
  528. * Notes: 审核客户
  529. * User: yb
  530. * Date: 2024/8/16
  531. * Time: 11:21
  532. * @param $params
  533. */
  534. public static function checkCustom($params)
  535. {
  536. $userId = JwtToken::getCurrentId();
  537. $adminId = Consultant::where('id', '=', $userId)->value('relation_user_id');
  538. //查询客户是否已经存在
  539. $customId = $params['id'];
  540. $checkStatus = $params['check_status'];
  541. if (!in_array($checkStatus, [-1,2])) {
  542. return json_fail('状态值非法');
  543. }
  544. $info = MarketCustomer::firstWhere(['id' => $customId]);
  545. if (empty($info)) {
  546. return json_fail('客户不存在');
  547. }
  548. $status = $info->check_status;
  549. if ($status != 1) {
  550. return json_fail('客户不是待审核状态');
  551. }
  552. $mobile = $info->mobile;
  553. if ($checkStatus == 2) {
  554. if (MarketCustomer::checkCustomExists($mobile)) {
  555. return json_fail('客户已经存在');
  556. }
  557. }
  558. $result = false;
  559. Db::beginTransaction();
  560. try {
  561. $info->check_status = $checkStatus;
  562. if ($checkStatus == -1) {
  563. //拒绝录入拒绝理由
  564. $info->check_note = $params['note'] ?? '无拒绝理由';
  565. }
  566. $info->check_time = time();
  567. $info->check_admin_id = $adminId;
  568. $info->check_consultant_id = $userId;
  569. $result = $info->save();
  570. if ($checkStatus == 2) {
  571. //将其他待审的相同手机号的改拒绝
  572. $where = [
  573. ['mobile' , '=', $mobile],
  574. ['check_status', '=', 1],
  575. ['id', '<>', $customId]
  576. ];
  577. MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1,'check_note' => '客户已经被其他顾问报备']);
  578. }
  579. Db::commit();
  580. }catch (BusinessException|\Exception $e){
  581. Db::rollBack();
  582. return json_fail($e->getMessage());
  583. }
  584. if ($result) {
  585. return json_success('审核成功');
  586. } else {
  587. return json_fail('审核失败');
  588. }
  589. }
  590. /**
  591. * Notes: 检查客户是否已经登记
  592. * User: yb
  593. * Date: 2024/8/21
  594. * Time: 9:40
  595. * @param $params
  596. * @return \support\Response
  597. */
  598. public static function checkPhone($params)
  599. {
  600. if (empty($params['mobile'])) {
  601. return json_fail('请输入联系电话');
  602. }
  603. $mobile = $params['mobile'];
  604. //添加和编辑
  605. if (!empty($params['id'])) {
  606. //编辑的情况
  607. if (false === strpos($mobile,'****')) {
  608. //校验手机号格式
  609. $validate = new CustomValidate();
  610. if (!$validate->scene('phone')->check(['mobile' => $mobile])) {
  611. return json_fail($validate->getError());
  612. }
  613. //修改手机号操作
  614. if (MarketCustomer::checkCustomExists($mobile, $params['id'])) {
  615. return json_fail('客户已经登记过了');
  616. }
  617. }
  618. return json_success('请求成功',['is_ex' => 2]);
  619. } else {
  620. $validate = new CustomValidate();
  621. if (!$validate->scene('phone')->check(['mobile' => $mobile])) {
  622. return json_fail($validate->getError());
  623. }
  624. //添加
  625. $result = MarketCustomer::checkCustomExists($mobile);
  626. if ($result) {
  627. $isEx = 1;
  628. } else {
  629. $isEx = 2;
  630. }
  631. return json_success('请求成功',['is_ex' => $isEx]);
  632. }
  633. }
  634. /**
  635. * Notes: 对手机号加密处理
  636. * User: yb
  637. * Date: 2024/8/8
  638. * Time: 15:41
  639. * @param $val
  640. * @return string|string[]
  641. */
  642. public static function handlePhone($val)
  643. {
  644. return substr_replace($val, '****', 3, 4);
  645. }
  646. /**
  647. * Notes: 处理拜访时间
  648. * User: yb
  649. * Date: 2024/8/8
  650. * Time: 16:06
  651. * @param $val
  652. * @return float|int
  653. */
  654. protected static function handleVisitTime($val) {
  655. return (strtotime($val) * 1000);
  656. }
  657. }