CustomService.php 25 KB

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