CustomService.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. <?php
  2. namespace app\admin\service\consultant;
  3. use app\admin\service\member\MemberService;
  4. use app\model\Consultant;
  5. use app\model\MarketCustomer;
  6. use app\model\MarketCustomerFollow;
  7. use app\model\MarketCustomerLogs;
  8. use app\model\Member;
  9. use app\model\SysDept;
  10. use support\Db;
  11. use support\exception\BusinessException;
  12. use support\Request;
  13. use Tinywan\Jwt\JwtToken;
  14. class CustomService
  15. {
  16. const DIFF_TIME = (60 * 60 * 24 * 30); //调入团队公池 x4 = 调入集团公池
  17. /**
  18. * Notes: 返回选项配置信息
  19. * User: yb
  20. * Date: 2024/8/5
  21. * Time: 16:05
  22. * @return array
  23. */
  24. public static function config()
  25. {
  26. return MarketCustomer::config();
  27. }
  28. public static function commonSearch($params)
  29. {
  30. $where = [];
  31. $currentTime = time();
  32. $diffNums = self::DIFF_TIME;
  33. $deptIds = TeamService::getIdsByUser();
  34. if (false === $deptIds) {
  35. //无权限
  36. $where[] = ['dept_id', '=', 0];
  37. } else if (is_array($deptIds)) {
  38. //指定团队下的权限
  39. if (!empty($params['dept_id'])) {
  40. $deptId = end($params['dept_id']);
  41. $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
  42. }
  43. $where[] = [function($query) use ($deptIds) {
  44. $query->whereIn('dept_id', $deptIds);
  45. }];
  46. } else {
  47. if (!empty($params['dept_id'])) {
  48. $deptId = end($params['dept_id']);
  49. $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
  50. $where[] = [function($query) use ($deptIds) {
  51. $query->whereIn('dept_id', $deptIds);
  52. }];
  53. }
  54. }
  55. if (!empty($params['name'])) {
  56. $keywords = $params['name'];
  57. $where[] = [function($query) use ($keywords) {
  58. $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
  59. }];
  60. }
  61. if (!empty($params['mobile'])) {
  62. $mobile = $params['mobile'];
  63. $where[] = [function($query) use ($mobile) {
  64. $query->where('mobile', 'like', "%{$mobile}%");
  65. }];
  66. }
  67. if (!empty($params['report_status'])) {
  68. $where[] = ['check_status', '=', $params['report_status']];
  69. // if ($params['report_status'] == -1) {
  70. // //待审核
  71. // $where[] = ['check_status', '=', 1];
  72. // } else {
  73. // $where[] = ['check_status', '=', 2];
  74. // }
  75. // if ($params['report_status'] == 1) {
  76. // //已报备
  77. // $where[] = [function($query) use ($diffNums, $currentTime) {
  78. // $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
  79. // }];
  80. // } else if ($params['report_status'] == 3) {
  81. // //已锁定
  82. // $where[] = [function($query) {
  83. // $query->whereIn('current_status', [2,3,4]);
  84. // }];
  85. // } else if ($params['report_status'] == 2) {
  86. // //已失效
  87. // $where[] = [function($query) use ($diffNums, $currentTime){
  88. // $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)");
  89. // }];
  90. // }
  91. }
  92. if (!empty($params['consultant_name'])) {
  93. $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id');
  94. $where[] = [function($query) use ($consultantIds) {
  95. $query->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
  96. }];
  97. }
  98. if (!empty($params['type'])) {
  99. $where[] = ['type', '=', $params['type']];
  100. }
  101. if (!empty($params['visit_time'])) {
  102. $datetime = $params['visit_time'];
  103. $datetime[0] = strtotime($datetime[0].' 00:00:00');
  104. $datetime[1] = strtotime($datetime[1].' 23:59:59');
  105. $where[] = [function($query) use ($datetime) {
  106. $query->whereBetween('visit_time', $datetime);
  107. }];
  108. }
  109. if (!empty($params['visit_date'])) {
  110. $visitDate = $params['visit_date'];
  111. $visitDate[0] = strtotime($visitDate[0].' 00:00:00');
  112. $visitDate[1] = strtotime($visitDate[1].' 23:59:59');
  113. $where[] = [function($query) use ($visitDate) {
  114. $query->whereBetween('visit_time', $visitDate);
  115. }];
  116. }
  117. if (!empty($params['created_date'])) {
  118. $createdDate = $params['created_date'];
  119. $createdDate[0] = strtotime($createdDate[0].' 00:00:00');
  120. $createdDate[1] = strtotime($createdDate[1].' 23:59:59');
  121. $where[] = [function($query) use ($createdDate) {
  122. $query->whereBetween('created_at', $createdDate);
  123. }];
  124. }
  125. if (!empty($params['current_status'])) {
  126. $currentStatus = $params['current_status'];
  127. if ($currentStatus == 1) {
  128. $where[] = ['current_status', '=', $currentStatus];
  129. } else {
  130. $where[] = [function($query) use ($currentStatus){
  131. $query->where('current_status', '=', $currentStatus)->where('check_status', '<>', 1);
  132. }];
  133. }
  134. }
  135. if (!empty($params['consultant_id'])) {
  136. $consultantId = $params['consultant_id'];
  137. $where[] = [function($query) use ($consultantId) {
  138. $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
  139. }];
  140. }
  141. if (!empty($params['custom'])) {
  142. $keywords = $params['custom'];
  143. $where[] = [function($query) use ($keywords) {
  144. $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
  145. }];
  146. }
  147. if (!empty($params['check_status'])) {
  148. $where[] = ['check_status', '=', $params['check_status']];
  149. }
  150. if (!empty($params['stat_report_status'])) {
  151. //已报备 1
  152. $statReportStatus = $params['stat_report_status'];
  153. if ($statReportStatus == 1) {
  154. $where[] = [function($query) use ($diffNums, $currentTime) {
  155. $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1)->where('check_status', '=', 2);
  156. }];
  157. }
  158. //已锁定 2
  159. if ($statReportStatus == 2) {
  160. $where[] = [function($query) {
  161. $query->whereIn('current_status', [2,3,4])->where('check_status', '=', 2);
  162. }];
  163. }
  164. //已失效 -1
  165. if ($statReportStatus == -1) {
  166. $where[] = [function($query) use ($diffNums, $currentTime){
  167. $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)")->orWhere('check_status', '=', -1);
  168. }];
  169. }
  170. }
  171. if (isset($params['require_area'])) {
  172. if (is_numeric($params['require_area'])) {
  173. $where[] = ['require_area', '=', ($params['require_area'] + 1)];
  174. }
  175. }
  176. if (isset($params['requirement'])) {
  177. if (is_numeric($params['requirement'])) {
  178. $where[] = ['requirement', '=', ($params['requirement'] + 1)];
  179. }
  180. }
  181. if (isset($params['age_range'])) {
  182. if (is_numeric($params['age_range'])) {
  183. $where[] = ['age_range', '=', ($params['age_range'] + 1)];
  184. }
  185. }
  186. if (isset($params['visit_type'])) {
  187. if (is_numeric($params['visit_type'])) {
  188. $where[] = ['visit_type', '=', $params['visit_type']];
  189. }
  190. }
  191. if (isset($params['region'])) {
  192. if (is_numeric($params['region'])) {
  193. $where[] = ['region', '=', ($params['region'] + 1)];
  194. }
  195. }
  196. if (isset($params['purpose'])) {
  197. if (is_numeric($params['purpose'])) {
  198. $where[] = ['purpose', '=', ($params['purpose'] + 1)];
  199. }
  200. }
  201. if (isset($params['level'])) {
  202. if (is_numeric($params['level'])) {
  203. $where[] = ['level', '=', ($params['level'] + 1)];
  204. }
  205. }
  206. if (!empty($params['belong_status'])) {
  207. $belongStatus = $params['belong_status'];
  208. if ($belongStatus == 1) {
  209. //未流入公池
  210. $where[] = ['belong_status', '=', 1];
  211. $where[] = [function($query) use ($diffNums, $currentTime){
  212. $query->orWhereRaw("check_status IN (-1, 1)")
  213. ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
  214. ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
  215. }];
  216. } else {
  217. if (true === $deptIds) {
  218. if (!empty($params['pub_status'])) {
  219. if ($params['pub_status'] == 2) {
  220. //仅检索团队公池
  221. $where[] = [function($query) use ($diffNums, $currentTime){
  222. $query->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);
  223. }];
  224. } else {
  225. //仅检索集团公池
  226. $where[] = [function($query) use ($diffNums, $currentTime){
  227. $query->orWhereRaw("((visit_time + ({$diffNums} * 4)) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
  228. }];
  229. }
  230. } else {
  231. //超管权限
  232. $where[] = [function($query) use ($diffNums, $currentTime){
  233. $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
  234. }];
  235. }
  236. } else if (is_array($deptIds)) {
  237. //团队权限
  238. $where[] = [function($query) use ($diffNums, $currentTime){
  239. $query->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);
  240. }];
  241. } else {
  242. //无权限
  243. }
  244. }
  245. }
  246. return $where;
  247. }
  248. /**
  249. * Notes: 列表
  250. * User: yb
  251. * Date: 2024/8/6
  252. * Time: 15:07
  253. * @param Request $request
  254. */
  255. public static function index(Request $request)
  256. {
  257. $format = $request->get('format', 'normal');
  258. $limit = (int)$request->get('pageSize', $format === 'tree' ? 1000 : 10);
  259. $limit = $limit <= 0 ? 10 : $limit;
  260. $params = $request->get();
  261. $page = (int)$request->get('page');
  262. $page = $page > 0 ? $page : 1;
  263. $currentTime = time();
  264. $diffNums = self::DIFF_TIME;
  265. $where = self::commonSearch($params);
  266. $paginator = MarketCustomer::where($where)->orderBy('visit_time', 'desc')->paginate($limit, '*', 'page', $page);
  267. $total = $paginator->total();
  268. $items = $paginator->items();
  269. if (!empty($items)) {
  270. //查询顾问信息
  271. $consultantKeys = [];
  272. $reportConsultantIds = $paginator->pluck('report_consultant_id')->toArray();
  273. $consultantIds = $paginator->pluck('consultant_id')->toArray();
  274. if (!empty($consultantIds) || !empty($reportConsultantIds)) {
  275. if (!empty($consultantIds)) {
  276. //去重
  277. $consultantIds = array_unique($consultantIds);
  278. //排序
  279. $consultantIds = array_values($consultantIds);
  280. }
  281. if (!empty($reportConsultantIds)) {
  282. //去重
  283. $reportConsultantIds = array_unique($reportConsultantIds);
  284. //排序
  285. $reportConsultantIds = array_values($reportConsultantIds);
  286. }
  287. $consultantIds = array_merge($consultantIds, $reportConsultantIds);
  288. $consultantList = Consultant::whereIn('id', $consultantIds)->select(['id', 'name', 'mobile'])->get();
  289. if (!$consultantList->isEmpty()) {
  290. foreach ($consultantList->toArray() as $consultantItem) {
  291. $consultantKeys[$consultantItem['id']] = $consultantItem;
  292. }
  293. }
  294. }
  295. $teamKeys = TeamService::getItemKeys();
  296. foreach ($items as &$item) {
  297. $visitTime = $item->visit_time;
  298. $visitTimeStamp = strtotime($visitTime);
  299. $diff = ($visitTimeStamp + $diffNums) - $currentTime;
  300. if ($diff > 0) {
  301. $item->belong_status = 1;
  302. } else {
  303. if (abs($diff) - (4*$diffNums) > 0) {
  304. $item->belong_status = 3;
  305. } else {
  306. $item->belong_status = 2;
  307. }
  308. }
  309. $item->diff_nums = ($diff > 0) ? $diff : 0;
  310. $item->consultant_name = $consultantKeys[$item->consultant_id]['name'] ?? '';
  311. $item->consultant_mobile = $consultantKeys[$item->consultant_id]['mobile'] ?? '';
  312. $item->report_consultant_name = $consultantKeys[$item->report_consultant_id]['name'] ?? '';
  313. $item->report_consultant_mobile = $consultantKeys[$item->report_consultant_id]['mobile'] ?? '';
  314. $item->team_name = TeamService::getTeamName($teamKeys, $item->dept_id);
  315. $item->mask_mobile = self::handlePhone($item->mobile);
  316. }
  317. }
  318. $data = [
  319. 'total' => $total,
  320. 'rows' => $items
  321. ];
  322. return json_success('success', $data);
  323. }
  324. /**
  325. * Notes: 添加客户
  326. * User: yb
  327. * Date: 2024/8/6
  328. * Time: 11:20
  329. */
  330. public static function add($params)
  331. {
  332. $params = MarketCustomer::handleNumParams($params);
  333. $mobile = $params['mobile'];
  334. //查询客户手机号是否已经存在
  335. if (MarketCustomer::checkCustomExists($mobile)) {
  336. return json_fail('客户已经登记过了');
  337. }
  338. //查询顾问信息
  339. $reportConsultantId = $params['report_consultant_id'];
  340. $consultantInfo = Consultant::firstWhere(['id' => $reportConsultantId]);
  341. if (empty($consultantInfo)) {
  342. return json_fail('报备顾问信息不存在');
  343. }
  344. $deptId = $consultantInfo->dept_id;
  345. $insertData = [
  346. 'name' => $params['name'],
  347. 'mobile' => $mobile,
  348. 'consultant_id' => 0,
  349. 'create_consultant_id' => $reportConsultantId,
  350. 'report_consultant_id' => $reportConsultantId,
  351. 'dept_id' => $deptId,
  352. 'gender' => $params['gender'] ?? null,
  353. 'visit_type' => $params['visit_type'] ?? null,
  354. 'require_area' => $params['require_area'] ?? null,
  355. 'area' => $params['area'] ?? null,
  356. 'requirement' => $params['requirement'] ?? null,
  357. 'age_range' => $params['age_range'] ?? null,
  358. 'focus' => $params['focus'] ?? null,
  359. 'region' => $params['region'] ?? null,
  360. 'purpose' => $params['purpose'] ?? null,
  361. 'level' => $params['level'] ?? null,
  362. 'type' => $params['type'] ?? null,
  363. 'check_status' => 1,
  364. 'visit_time' => $params['visit_time'] ?? null,
  365. 'note' => $params['note'] ?? '',
  366. 'belong_status' => 1,
  367. 'current_status' => $params['current_status'] ?? null,
  368. 'created_at' => time()
  369. ];
  370. Db::beginTransaction();
  371. try {
  372. //查询会员表中是否存在该客户
  373. // $memberId = Member::where('member_mobile', $insertData['mobile'])->value('member_id');
  374. // if (empty($memberId)) {
  375. // $result = MemberService::add([
  376. // 'account_name'=> $insertData['name'],
  377. // 'member_category' => '售房客户',
  378. // 'mobile' => $insertData['mobile'],
  379. // 'source' => 'HOUSE']);
  380. // $code = $result->getStatusCode();
  381. // if ($code == 200) {
  382. // $content = $result->rawBody();
  383. // if (is_json($content)) {
  384. // $content = json_decode($content, 1);
  385. // if ($content['code'] == 200) {
  386. // $memberId = $content['data']['member_id'];
  387. // } else {
  388. // throw new BusinessException('新增会员失败');
  389. // }
  390. // } else {
  391. // throw new BusinessException('新增会员失败');
  392. // }
  393. // } else {
  394. // throw new BusinessException('新增会员失败');
  395. // }
  396. // }
  397. // $insertData['member_id'] = $memberId;
  398. $customId = MarketCustomer::insertGetId($insertData);
  399. Db::commit();
  400. }catch (BusinessException|\Exception $e){
  401. Db::rollBack();
  402. return json_fail($e->getMessage());
  403. }
  404. if ($customId) {
  405. return json_success('添加成功');
  406. } else {
  407. return json_fail('添加失败');
  408. }
  409. }
  410. /**
  411. * Notes: 编辑客户
  412. * User: yb
  413. * Date: 2024/8/6
  414. * Time: 16:53
  415. * @param $params
  416. */
  417. public static function update($params)
  418. {
  419. $params = MarketCustomer::handleNumParams($params);
  420. $mobile = $params['mobile'];
  421. //查询客户手机号是否已经存在
  422. if (MarketCustomer::checkCustomExists($mobile, $params['id'])) {
  423. return json_fail('客户已经登记过了');
  424. }
  425. $updateData = [
  426. 'name' => $params['name'],
  427. 'mobile' => $params['mobile'],
  428. 'gender' => $params['gender'] ?? null,
  429. 'visit_type' => $params['visit_type'] ?? null,
  430. 'require_area' => $params['require_area'] ?? null,
  431. 'area' => $params['area'] ?? null,
  432. 'requirement' => $params['requirement'] ?? null,
  433. 'age_range' => $params['age_range'] ?? null,
  434. 'focus' => $params['focus'] ?? null,
  435. 'region' => $params['region'] ?? null,
  436. 'purpose' => $params['purpose'] ?? null,
  437. 'level' => $params['level'] ?? null,
  438. 'type' => $params['type'] ?? null,
  439. 'note' => $params['note'] ?? '',
  440. 'current_status' => $params['current_status'] ?? null,
  441. 'updated_at' => time()
  442. ];
  443. if (!empty($params['update_visit_time'])) {
  444. if ($params['update_visit_time'] == 1) {
  445. $updateData['visit_time'] = $params['visit_time'] ?? null;
  446. }
  447. }
  448. $result = MarketCustomer::where('id', $params['id'])->update($updateData);
  449. if ($result) {
  450. return json_success('编辑成功');
  451. } else {
  452. return json_fail('编辑失败');
  453. }
  454. }
  455. /**
  456. * Notes: 删除客户
  457. * User: yb
  458. * Date: 2024/8/2
  459. * Time: 13:33
  460. * @param $ids
  461. * @return \support\Response
  462. */
  463. public static function delete($ids)
  464. {
  465. if (!$ids) {
  466. return json_fail("数据错误");
  467. }
  468. if (!is_array($ids)) {
  469. $ids = [$ids];
  470. }
  471. try {
  472. if (is_array($ids)) {
  473. MarketCustomer::whereIn('id', $ids)->delete();
  474. } else {
  475. MarketCustomer::where('id', $ids)->delete();
  476. }
  477. } catch (\Exception $e) {
  478. return json_fail('删除失败');
  479. }
  480. return json_success('删除成功');
  481. }
  482. /**
  483. * Notes: 跟进记录
  484. * User: yb
  485. * Date: 2024/8/7
  486. * Time: 9:00
  487. * @param Request $request
  488. */
  489. public static function follow(Request $request)
  490. {
  491. $format = $request->get('format', 'normal');
  492. $limit = (int)$request->get('pageSize', $format === 'tree' ? 1000 : 10);
  493. $limit = $limit <= 0 ? 10 : $limit;
  494. $params = $request->get();
  495. $page = (int)$request->get('page');
  496. $page = $page > 0 ? $page : 1;
  497. $where = [];
  498. $whereCustom = [];
  499. $whereConsultant = [];
  500. if (!empty($params['market_customer_id'])) {
  501. $marketCustomerIds = $params['market_customer_id'];
  502. $where[] = [function($query) use ($marketCustomerIds) {
  503. $query->whereIn('market_customer_id', $marketCustomerIds);
  504. }];
  505. }
  506. if (!empty($params['consultant_id'])) {
  507. $consultantId = $params['consultant_id'];
  508. $where[] = [function($query) use ($consultantId) {
  509. $query->whereIn('consultant_id', $consultantId);
  510. }];
  511. }
  512. if (!empty($params['follow_way'])) {
  513. $where[] = ['follow_way', '=', $params['follow_way']];
  514. }
  515. if (!empty($params['custom'])) {
  516. $custom = $params['custom'];
  517. $whereCustom[] = [function($query) use ($custom) {
  518. $query->orWhere('name', 'like', "%{$custom}%")->orWhere('mobile', 'like', "%{$custom}%");
  519. }];
  520. }
  521. if (!empty($params['consultant'])) {
  522. $consultant = $params['consultant'];
  523. $whereConsultant[] = [function($query) use ($consultant) {
  524. $query->orWhere('name', 'like', "%{$consultant}%")->orWhere('mobile', 'like', "%{$consultant}%");
  525. }];
  526. }
  527. if (!empty($params['follow_time'])) {
  528. $datetime = $params['follow_time'];
  529. $datetime[0] = strtotime($datetime[0].' 00:00:00');
  530. $datetime[1] = strtotime($datetime[1].' 23:59:59');
  531. $where[] = [function($query) use ($datetime) {
  532. $query->whereBetween('follow_time', $datetime);
  533. }];
  534. }
  535. $paginator = MarketCustomerFollow::with(['custom', 'consultant'])->whereHas('custom', function($query) use ($whereCustom){
  536. $query->where($whereCustom);
  537. })->whereHas('consultant', function($query) use ($whereConsultant) {
  538. $query->where($whereConsultant);
  539. })->where($where)->orderBy('follow_time', 'desc')->paginate($limit, '*', 'page', $page);
  540. $total = $paginator->total();
  541. $items = $paginator->items();
  542. foreach ($items as &$item) {
  543. if (!empty($item->custom)) {
  544. $item->custom->mask_mobile = self::handlePhone($item->custom->mobile);
  545. }
  546. }
  547. $data = [
  548. 'total' => $total,
  549. 'rows' => $items
  550. ];
  551. return json_success('success', $data);
  552. }
  553. /**
  554. * Notes: 删除跟进记录
  555. * User: yb
  556. * Date: 2024/8/7
  557. * Time: 11:25
  558. * @param $ids
  559. */
  560. public static function deleteFollow($ids)
  561. {
  562. if (!$ids) {
  563. return json_fail("数据错误");
  564. }
  565. if (!is_array($ids)) {
  566. $ids = [$ids];
  567. }
  568. try {
  569. if (is_array($ids)) {
  570. MarketCustomerFollow::whereIn('id', $ids)->delete();
  571. } else {
  572. MarketCustomerFollow::where('id', $ids)->delete();
  573. }
  574. } catch (\Exception $e) {
  575. return json_fail('删除失败');
  576. }
  577. return json_success('删除成功');
  578. }
  579. /**
  580. * Notes: 转移客户
  581. * User: yb
  582. * Date: 2024/8/7
  583. * Time: 14:27
  584. * @param $params
  585. */
  586. public static function moveCustom($params)
  587. {
  588. $userId = JwtToken::getCurrentId();
  589. $moveType = $params['move_type'] ?? 0;
  590. if ($moveType == 1) {
  591. $currentDeptId = $params['dept_id'];
  592. $currentConsultantId = 0;
  593. } else {
  594. $currentConsultantId = $params['consultant_id'] ?? 0; //当前顾问
  595. $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]);
  596. if (empty($consultantInfo)) {
  597. return json_fail('顾问不存在');
  598. }
  599. $currentDeptId = $consultantInfo->dept_id; //当前部门
  600. }
  601. $consultantIds = $params['move_consultant_id'] ?? [];
  602. $customIds = $params['move_market_customer_id'] ?? [];
  603. $note = $params['note'] ?? '';
  604. $logsInertData = [];
  605. $now = time();
  606. $whereCustom = [];
  607. if (!empty($customIds)) {
  608. $whereCustom[] = [function($query) use ($customIds) {
  609. $query->whereIn('id', $customIds);
  610. }];
  611. }
  612. if (!empty($consultantIds)) {
  613. $whereCustom[] = [function($query) use ($consultantIds) {
  614. $query->whereIn('consultant_id', $consultantIds);
  615. }];
  616. }
  617. $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time'])->get();
  618. if (!$customList->isEmpty()) {
  619. foreach ($customList as$item) {
  620. $logsInertData[] = [
  621. 'market_customer_id' => $item->id,
  622. 'consultant_id' => $currentConsultantId,
  623. 'dept_id' => $currentDeptId,
  624. 'before_consultant_id' => $item->consultant_id,
  625. 'before_dept_id' => $item->dept_id,
  626. 'note' => $note,
  627. 'change_user_id' => $userId,
  628. 'created_at' => $now
  629. ];
  630. }
  631. }
  632. if ($customList->isEmpty()) {
  633. return json_fail('移交的客户信息不存在');
  634. }
  635. if (empty($logsInertData)) {
  636. return json_fail('移交记录不能为空');
  637. }
  638. $diffTime = self::DIFF_TIME;
  639. Db::beginTransaction();
  640. $result = false;
  641. try {
  642. foreach ($customList as $item) {
  643. if ($currentConsultantId != 0) {
  644. //移交至指定顾问
  645. //判断一下是否到了到访的过期时间,如果过期了就更新到访时间,没过期时间就不变
  646. $visitTime = $item->visit_time;
  647. $diff = strtotime($visitTime) + $diffTime - time();
  648. if ($diff <= 0) {
  649. $item->visit_time = time();
  650. }
  651. } else {
  652. //移交至其他团队
  653. $item->visit_time = time() - self::DIFF_TIME;
  654. }
  655. $item->consultant_id = $currentConsultantId;
  656. $item->dept_id = $currentDeptId;
  657. $item->save();
  658. }
  659. $result = MarketCustomerLogs::insert($logsInertData);
  660. Db::commit();
  661. }catch (BusinessException|\Exception $e) {
  662. Db::rollBack();
  663. return json_fail($e->getMessage());
  664. }
  665. if ($result) {
  666. return json_success('移交成功');
  667. } else {
  668. return json_fail('移交失败');
  669. }
  670. }
  671. /**
  672. * Notes: 转移记录
  673. * User: yb
  674. * Date: 2024/8/7
  675. * Time: 15:33
  676. * @param Request $request
  677. */
  678. public static function moveLogs(Request $request)
  679. {
  680. $format = $request->get('format', 'normal');
  681. $limit = (int)$request->get('pageSize', $format === 'tree' ? 1000 : 10);
  682. $limit = $limit <= 0 ? 10 : $limit;
  683. $params = $request->get();
  684. $page = (int)$request->get('page');
  685. $page = $page > 0 ? $page : 1;
  686. $platform = 0;
  687. $where = [];
  688. $whereCustom = [];
  689. $whereCurrent = [];
  690. $whereBefore = [];
  691. $whereOpBack = [];
  692. $whereOpFront = [];
  693. if (!empty($params['market_customer_id'])) {
  694. $where[] = ['market_customer_id', '=', $params['market_customer_id']];
  695. }
  696. if (!empty($params['consultant_id'])) {
  697. $consultantIds = $params['consultant_id'];
  698. $where[] = [function($query) use ($consultantIds) {
  699. $query->orWhereIn('consultant_id', $consultantIds)->orWhereIn('before_consultant_id', $consultantIds);
  700. }];
  701. }
  702. if (!empty($params['custom'])) {
  703. //客户信息
  704. $custom = $params['custom'];
  705. $whereCustom[] = ['name', 'like', "%{$custom}%"];
  706. }
  707. if (!empty($params['current_consultant'])) {
  708. //当前员工信息
  709. $current = $params['current_consultant'];
  710. $whereCurrent[] = ['name', 'like', "%{$current}%"];
  711. }
  712. if (!empty($params['before_consultant'])) {
  713. //转移前员工信息
  714. $before = $params['before_consultant'];
  715. $whereBefore[] = ['name', 'like', "%{$before}%"];
  716. }
  717. if (!empty($params['platform'])) {
  718. $platform = $params['platform'];
  719. if ($platform == 1) {
  720. //后台
  721. $where[] = ['change_user_id', '<>', null];
  722. $where[] = ['change_user_id', '=', null];
  723. } else {
  724. //小程序
  725. $where[] = ['change_user_id', '=', null];
  726. $where[] = ['change_user_id', '<>', null];
  727. }
  728. }
  729. if (!empty($params['op_name'])) {
  730. $opName = $params['op_name'];
  731. if (!empty($platform)) {
  732. if ($platform == 1) {
  733. $whereOpBack[] = ['user_name', 'like', "%{$opName}%"];
  734. } else {
  735. $whereOpFront[] = ['name', 'like', "%{$opName}%"];
  736. }
  737. } else {
  738. $whereOpBack[] = [function($query) use ($opName) {
  739. $query->orWhere('user_name', 'like', "%{$opName}%");
  740. }];
  741. $whereOpFront[] = [function($query) use ($opName) {
  742. $query->orWhere('name', 'like', "%{$opName}%");
  743. }];
  744. }
  745. }
  746. if (!empty($params['created_at'])) {
  747. $createdDate = $params['created_at'];
  748. $createdDate[0] = strtotime($createdDate[0].' 00:00:00');
  749. $createdDate[1] = strtotime($createdDate[1].' 23:59:59');
  750. $where[] = [function($query) use ($createdDate) {
  751. $query->whereBetween('created_at', $createdDate);
  752. }];
  753. }
  754. $paginator = MarketCustomerLogs::with(['custom' => function($query) {
  755. $query->select('id', 'name', 'mobile');
  756. }, 'beforeMan' => function($query) {
  757. $query->select('id', 'name', 'mobile');
  758. }, 'currentMan' => function($query) {
  759. $query->select('id', 'name', 'mobile');
  760. }, 'beforeDept' => function($query) {
  761. $query->select('dept_id', 'dept_name');
  762. }, 'currentDept' => function($query) {
  763. $query->select('dept_id', 'dept_name');
  764. }])
  765. // ->whereHas('custom', function ($query) use ($whereCustom) {
  766. // $query->where($whereCustom);
  767. // })
  768. // ->whereHas('currentMan', function ($query) use ($whereCurrent) {
  769. // $query->where($whereCurrent);
  770. // })
  771. // ->whereHas('beforeMan', function ($query) use ($whereBefore) {
  772. // $query->where($whereBefore);
  773. // })
  774. ->where($where)
  775. ->orderBy('created_at', 'desc')
  776. ->paginate($limit, '*', 'page', $page);
  777. $total = $paginator->total();
  778. $items = $paginator->items();
  779. foreach ($items as &$item) {
  780. if (!empty($item->custom)) {
  781. $item->custom->mask_mobile = self::handlePhone($item->custom->mobile);
  782. }
  783. }
  784. $data = [
  785. 'total' => $total,
  786. 'rows' => $items
  787. ];
  788. return json_success('success', $data);
  789. }
  790. /**
  791. * Notes: 审核客户
  792. * User: yb
  793. * Date: 2024/8/16
  794. * Time: 11:21
  795. * @param $params
  796. */
  797. public static function checkCustom($params)
  798. {
  799. $adminId = JwtToken::getCurrentId();
  800. //查询客户是否已经存在
  801. $customId = $params['id'];
  802. $checkStatus = $params['check_status'];
  803. if (!in_array($checkStatus, [-1,2])) {
  804. return json_fail('状态值非法');
  805. }
  806. $info = MarketCustomer::firstWhere(['id' => $customId]);
  807. if (empty($info)) {
  808. return json_fail('客户不存在');
  809. }
  810. $status = $info->check_status;
  811. if ($status != 1) {
  812. return json_fail('客户不是待转到访状态');
  813. }
  814. $mobile = $info->mobile;
  815. if ($checkStatus == 2) {
  816. if (MarketCustomer::checkCustomExists($mobile)) {
  817. return json_fail('客户已经存在');
  818. }
  819. }
  820. $result = false;
  821. Db::beginTransaction();
  822. try {
  823. $info->check_status = $checkStatus;
  824. $info->current_status = $checkStatus;
  825. if ($checkStatus == -1) {
  826. //拒绝录入拒绝理由
  827. $info->check_note = $params['note'] ?? '无拒绝理由';
  828. }
  829. if ($checkStatus == 2) {
  830. //更新到访保护期时间
  831. $info->visit_time = time();
  832. }
  833. $info->consultant_id = $params['consultant_id'];
  834. $info->check_time = time();
  835. $info->check_admin_id = $adminId;
  836. $result = $info->save();
  837. if ($checkStatus == 2) {
  838. //将其他待审的相同手机号的改拒绝
  839. $where = [
  840. ['mobile' , '=', $mobile],
  841. ['check_status', '=', 1],
  842. ['id', '<>', $customId]
  843. ];
  844. MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1, 'current_status' => -1,'check_note' => '客户已经被其他登记']);
  845. }
  846. Db::commit();
  847. }catch (BusinessException|\Exception $e){
  848. Db::rollBack();
  849. return json_fail($e->getMessage());
  850. }
  851. if ($result) {
  852. return json_success('操作成功');
  853. } else {
  854. return json_fail('操作失败');
  855. }
  856. }
  857. /**
  858. * Notes: 数据统计分析
  859. * User: yb
  860. * Date: 2024/8/17
  861. * Time: 11:27
  862. * @param $params
  863. */
  864. public static function statisticsIndex(Request $request)
  865. {
  866. $params = $request->get();
  867. $where = self::commonSearch($params);
  868. //客户总数
  869. $total = MarketCustomer::where($where)->count();
  870. //公池客户
  871. $pubTotal = MarketCustomer::where($where)->where([[function($query){
  872. $diffNums = self::DIFF_TIME;
  873. $query->orWhereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
  874. }]])->count();
  875. //已报备
  876. $checkTotal = MarketCustomer::where($where)->where('check_status', 1)->count();
  877. //已到访
  878. $visitTotal = MarketCustomer::where($where)->where(
  879. [[function($query) {
  880. $diffNums = self::DIFF_TIME;
  881. $query->whereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() > 0) AND current_status = 2 AND check_status = 2")->where('belong_status', 1);
  882. }]]
  883. )->count();
  884. //已来电
  885. $mobileTotal = MarketCustomer::where($where)->where([[function($query) {
  886. $query->where('check_status', '=', 2)->where('current_status', '=', 1);
  887. }]])->count();
  888. //已到访
  889. // $visitTotal = MarketCustomer::where($where)->where([[function($query) {
  890. // $query->where('check_status', '=', 2)->where('current_status', '=', 2);
  891. // }]])->count();
  892. //已缴费
  893. $payTotal = MarketCustomer::where($where)->where([[function($query) {
  894. $query->where('check_status', '=', 2)->where('current_status', '=', 3)->where('belong_status', 1);
  895. }]])->count();
  896. //已成交
  897. $dealTotal = MarketCustomer::where($where)->where([[function($query) {
  898. $query->where('check_status', '=', 2)->where('current_status', '=', 4)->where('belong_status', 1);
  899. }]])->count();
  900. //已缴费 + 已成交 / 客户总数
  901. //报备失败
  902. $failTotal = MarketCustomer::where($where)->where('current_status', -1)->count();
  903. $rant = 0;
  904. if ($total > 0) {
  905. $rant = ($payTotal + $dealTotal) / $total;
  906. }
  907. $rant = sprintf('%.2f', $rant);
  908. $data = [
  909. 'total' => $total,
  910. 'pub_total' => $pubTotal,
  911. 'check_total' => $checkTotal,
  912. 'report_total' => 0,
  913. 'mobile_total' => $mobileTotal,
  914. 'visit_total' => $visitTotal,
  915. 'pay_total' => $payTotal,
  916. 'deal_total' => $dealTotal,
  917. 'fail_total' => $failTotal,
  918. 'rant' => $rant,
  919. ];
  920. return json_success('请求成功', $data);
  921. }
  922. /**
  923. * Notes: 前12个月统计数据
  924. * User: yb
  925. * Date: 2024/8/21
  926. * Time: 15:56
  927. */
  928. public static function statisticsMonth()
  929. {
  930. $months = month_12();
  931. sort($months);
  932. $startDate = $months[0];
  933. $startDateTime = strtotime($startDate.'/01 00:00:00');
  934. $endDateTime = time();
  935. $where = [
  936. ['created_at', '>=', $startDateTime],
  937. ['created_at', '<=', $endDateTime]
  938. ];
  939. $currentTime = time();
  940. $diffNums = self::DIFF_TIME;
  941. $deptIds = TeamService::getIdsByUser();
  942. if (false === $deptIds) {
  943. //无权限
  944. $where[] = ['dept_id', '=', 0];
  945. } else if (is_array($deptIds)) {
  946. //指定团队下的权限
  947. if (!empty($params['dept_id'])) {
  948. $deptId = end($params['dept_id']);
  949. $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
  950. }
  951. $where[] = [function($query) use ($deptIds) {
  952. $query->whereIn('dept_id', $deptIds);
  953. }];
  954. } else {
  955. if (!empty($params['dept_id'])) {
  956. $deptId = end($params['dept_id']);
  957. $deptIds = SysDept::where('dept_super_path','like', "%/{$deptId}/%")->where('dept_category', '=', TeamService::DEPT_CATEGORY)->pluck('dept_id')->toArray();
  958. $where[] = [function($query) use ($deptIds) {
  959. $query->whereIn('dept_id', $deptIds);
  960. }];
  961. }
  962. }
  963. $selectRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m') as date,count(*) as nums");
  964. $groupRaw = Db::raw("DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y/%m')");
  965. $totalData = MarketCustomer::where($where)->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
  966. $payData = MarketCustomer::where($where)->where([['current_status', '=', 3], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
  967. $visitData = MarketCustomer::where($where)->where([['current_status', '=', 2], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
  968. $dealData = MarketCustomer::where($where)->where([['current_status', '=', 4], ['check_status', '=', 2]])->selectRaw($selectRaw)->groupByRaw($groupRaw)->get();
  969. $returnData = [
  970. 'total' => $totalData->pluck('nums','date'),
  971. 'pay' => $payData->pluck('nums','date'),
  972. 'visit' => $visitData->pluck('nums','date'),
  973. 'deal' => $dealData->pluck('nums','date'),
  974. 'date' => $months
  975. ];
  976. return json_success('请求成功', $returnData);
  977. }
  978. /**
  979. * Notes: 导出数据
  980. * User: yb
  981. * Date: 2024/8/17
  982. * Time: 13:01
  983. */
  984. public static function exportData(Request $request)
  985. {
  986. $currentTime = time();
  987. $diffNums = self::DIFF_TIME;
  988. $params = $request->get();
  989. $where = self::commonSearch($params);
  990. if (!empty($params['custom_ids'])) {
  991. $customIds = $params['custom_ids'];
  992. $where[] = [function($query) use ($customIds){
  993. $query->whereIn('id', $customIds);
  994. }];
  995. }
  996. $list = MarketCustomer::where($where)->orderBy('visit_time', 'desc')->get();
  997. if (!$list->isEmpty()) {
  998. $consultantKeys = [];
  999. //查询顾问信息
  1000. $consultantList = Consultant::select(['id', 'name', 'mobile'])->get();
  1001. if (!$consultantList->isEmpty()) {
  1002. foreach ($consultantList->toArray() as $consultantItem) {
  1003. $consultantKeys[$consultantItem['id']] = $consultantItem;
  1004. }
  1005. }
  1006. $teamKeys = TeamService::getItemKeys();
  1007. $returnData = [];
  1008. $genderData = ['', '男', '女'];
  1009. $typeData = ['', '来电', '来访'];
  1010. $currentStatusData = [-1 => '无效客户', 1 => '已来电', 2 => '已到访', 3 => '已缴费', 4 => '已成交'];
  1011. foreach ($list as &$item) {
  1012. $visitTime = $item->visit_time;
  1013. $visitTimeStamp = strtotime($visitTime);
  1014. $diff = ($visitTimeStamp + $diffNums) - $currentTime;
  1015. $currentStatus = $item->current_status;//当前状态
  1016. $checkStatus = $item->check_status;//审核状态
  1017. if ($checkStatus == 1) {
  1018. $currentStatusText = '待审核';
  1019. }
  1020. if ($checkStatus == -1) {
  1021. $currentStatusText = '已失效';
  1022. }
  1023. if ($checkStatus == 2) {
  1024. //审核通过
  1025. if ($currentStatus > 1) {
  1026. $currentStatusText = $currentStatusData[$currentStatus] ?? '';
  1027. }
  1028. if ($currentStatus == 1) {
  1029. if ($diff > 0) {
  1030. $currentStatusText = $currentStatusData[$currentStatus] ?? '';
  1031. } else {
  1032. $currentStatusText = '已失效';
  1033. }
  1034. }
  1035. if ($currentStatus == -1) {
  1036. $currentStatusText = '无效客户';
  1037. }
  1038. }
  1039. $returnData[] = [
  1040. 'name' => $item->name,
  1041. 'mobile' => $item->mobile,
  1042. 'mask_mobile' => self::handlePhone($item->mobile),
  1043. 'gender' => $genderData[$item->gender] ?? '',
  1044. 'type' => $typeData[$item->type] ?? '',
  1045. 'consultant_name' => $consultantKeys[$item->consultant_id]['name'] ?? '',
  1046. 'consultant_mobile' => $consultantKeys[$item->consultant_id]['mobile'] ?? '',
  1047. 'team_name' => TeamService::getTeamName($teamKeys, $item->dept_id),
  1048. 'current_status' => $currentStatusText, //当前状态
  1049. 'visit_time' => $item->visit_time,
  1050. 'created_at' => date('Y-m-d H:i:s',strtotime($item->created_at))
  1051. ];
  1052. }
  1053. return json_success('请求成功', $returnData);
  1054. }
  1055. }
  1056. /**
  1057. * Notes: 对手机号加密处理
  1058. * User: yb
  1059. * Date: 2024/8/8
  1060. * Time: 15:41
  1061. * @param $val
  1062. * @return string|string[]
  1063. */
  1064. public static function handlePhone($val)
  1065. {
  1066. return substr_replace($val, '****', 3, 4);
  1067. }
  1068. /**
  1069. * Notes: 判客指定顾问
  1070. * User: yb
  1071. * Date: 2024/9/5
  1072. * Time: 15:50
  1073. * @param $params
  1074. */
  1075. /**
  1076. * Notes: 指定顾问
  1077. * User: yb
  1078. * Date: 2024/9/5
  1079. * Time: 12:52
  1080. * @param $params
  1081. */
  1082. public static function appoint($params)
  1083. {
  1084. if (empty($params['id'])) {
  1085. return json_fail('请选择客户');
  1086. }
  1087. if (empty($params['report_consultant_id'])) {
  1088. return json_fail('请选择指定顾问');
  1089. }
  1090. $userId = JwtToken::getCurrentId();
  1091. $relationUserId = $userId;
  1092. $customId = $params['id'];
  1093. $reportConsultantId = $params['report_consultant_id'];
  1094. $customInfo = MarketCustomer::firstWhere(['id' => $customId]);
  1095. if (empty($customInfo)) {
  1096. return json_fail('客户信息不存在');
  1097. }
  1098. $consultantInfo = Consultant::firstWhere(['id' => $reportConsultantId]);
  1099. if (empty($consultantInfo)) {
  1100. return json_fail('顾问信息不存在');
  1101. }
  1102. $currentDeptId = $consultantInfo->dept_id; //当前部门
  1103. $now = time();
  1104. $logData = [
  1105. 'market_customer_id' => $customId,
  1106. 'consultant_id' => $reportConsultantId,
  1107. 'dept_id' => $currentDeptId,
  1108. 'before_consultant_id' => $customInfo->report_consultant_id,
  1109. 'before_dept_id' => $customInfo->dept_id,
  1110. 'note' => $params['note'] ?? '判客指定报备顾问',
  1111. 'change_user_id' => $relationUserId,
  1112. 'change_consultant_id' => 0,
  1113. 'created_at' => $now
  1114. ];
  1115. Db::beginTransaction();
  1116. $result = false;
  1117. try {
  1118. $customInfo->report_consultant_id = $reportConsultantId;
  1119. $customInfo->dept_id = $currentDeptId;
  1120. $result = $customInfo->save();
  1121. MarketCustomerLogs::insert($logData);
  1122. Db::commit();
  1123. }catch (BusinessException|\Exception $e) {
  1124. Db::rollBack();
  1125. return json_fail($e->getMessage());
  1126. }
  1127. if ($result) {
  1128. return json_success('指定成功');
  1129. } else {
  1130. return json_fail('指定失败');
  1131. }
  1132. }
  1133. }