CustomerService.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Customer;
  5. use App\Model\CustomerInfo;
  6. use App\Model\Depart;
  7. use App\Model\Employee;
  8. use App\Model\FollowUpRecord;
  9. use App\Model\Product;
  10. use App\Model\SeeRange;
  11. use Carbon\Carbon;
  12. use Illuminate\Support\Facades\DB;
  13. /**
  14. * 客户管理相关
  15. */
  16. class CustomerService extends Service
  17. {
  18. /**
  19. * 客户编辑
  20. * @param $data
  21. * @param $user
  22. * @return array
  23. */
  24. public function customerEdit($data,$user){
  25. list($status,$msg) = $this->customerRule($data,$user, false);
  26. if(!$status) return [$status,$msg];
  27. $data['order_number'] = Customer::$order_number . "|" . $data['id'] . "|" . $data['title'];
  28. $params = $this->getDataFile($data);
  29. (new OperationLogService())->setOperationList($params,$user,2);
  30. try {
  31. DB::beginTransaction();
  32. //车型
  33. if(empty($data['car_type']) && ! empty($data['car_type_title'])){
  34. $model_2 = new BasicType();
  35. $model_2->title = $data['car_type_title'];
  36. $model_2->type = 10;
  37. $model_2->depart_id = $data['depart_id'] ?? 0;
  38. $model_2->top_depart_id = $data['top_depart_id'] ?? 0;
  39. $model_2->crt_id = $user['id'];
  40. $model_2->save();
  41. $data['car_type'] = $model_2->id;
  42. }
  43. $model = Customer::where('id',$data['id'])->first();
  44. $model->title = $data['title'];
  45. $model->code = $data['code'] ?? "";
  46. $model->model_type = $data['model_type'];
  47. $model->customer_intention = $data['customer_intention'] ?? 0;
  48. $model->customer_from = $data['customer_from'] ?? 0;
  49. $model->customer_type = $data['customer_type'] ?? 0;
  50. $model->car_type = $data['car_type'] ?? 0;
  51. $model->consulting_product = $data['consulting_product'] ?? '';
  52. $model->intention_product = $data['intention_product'] ?? 0;
  53. $model->progress_stage = $data['progress_stage'] ?? 0;
  54. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  55. $model->address2 = $data['address2'] ?? '';
  56. $model->mark = $data['mark'] ?? '';
  57. $model->importance = $data['importance'] ?? '';
  58. $model->company = $data['company'] ?? '';
  59. // $model->company_short_name = $data['company_short_name'] ?? '';
  60. $model->state_type = $data['state_type'] ?? 0;
  61. $model->customer_state = $data['customer_state'] ?? 0;
  62. $model->save();
  63. $time = time();
  64. $old = CustomerInfo::where('del_time',0)
  65. ->where('customer_id',$data['id'])
  66. ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
  67. ->select('file')
  68. ->get()->toArray();
  69. $old = array_column($old,'file');
  70. CustomerInfo::where('del_time',0)
  71. ->where('customer_id',$data['id'])
  72. ->whereNotIn('type',CustomerInfo::$no_edit)
  73. ->update(['del_time' => $time]);
  74. if(! empty($data['customer_contact'])){
  75. $insert = [];
  76. foreach ($data['customer_contact'] as $value){
  77. $insert[] = [
  78. 'customer_id' => $model->id,
  79. 'contact_type' => $value['id'],
  80. 'contact_info' => $value['info'],
  81. 'type' => CustomerInfo::type_one,
  82. 'crt_time' => $time,
  83. ];
  84. }
  85. CustomerInfo::insert($insert);
  86. }
  87. // if(! empty($data['employee_one'])){
  88. // $insert = [];
  89. // foreach ($data['employee_one'] as $value){
  90. // $insert[] = [
  91. // 'customer_id' => $model->id,
  92. // 'data_id' => $value,
  93. // 'type' => CustomerInfo::type_two,
  94. // 'crt_time' => $time,
  95. // ];
  96. // }
  97. // CustomerInfo::insert($insert);
  98. // }
  99. if(! empty($data['employee_two'])){
  100. $insert = [];
  101. foreach ($data['employee_two'] as $value){
  102. $insert[] = [
  103. 'customer_id' => $model->id,
  104. 'data_id' => $value,
  105. 'type' => CustomerInfo::type_three,
  106. 'crt_time' => $time,
  107. ];
  108. }
  109. CustomerInfo::insert($insert);
  110. }
  111. if(! empty($data['employee_three'])){
  112. $insert = [];
  113. foreach ($data['employee_three'] as $value){
  114. $insert[] = [
  115. 'customer_id' => $model->id,
  116. 'data_id' => $value,
  117. 'type' => CustomerInfo::type_four,
  118. 'crt_time' => $time,
  119. ];
  120. }
  121. CustomerInfo::insert($insert);
  122. }
  123. $new = [];
  124. if(! empty($data['img'])){
  125. $insert = [];
  126. foreach ($data['img'] as $value){
  127. $insert[] = [
  128. 'customer_id' => $model->id,
  129. 'file' => $value['url'],
  130. 'type' => CustomerInfo::type_five,
  131. 'name' => $value['name'],
  132. 'crt_time' => $time,
  133. ];
  134. if(in_array($value['url'], $old)) {
  135. foreach ($old as $o_k => $o_v){
  136. if($o_v == $value['url']) unset($old[$o_k]);
  137. }
  138. }else{
  139. $new[] = $value['url'];
  140. }
  141. }
  142. CustomerInfo::insert($insert);
  143. }
  144. if(! empty($data['file'])){
  145. $insert = [];
  146. foreach ($data['file'] as $value){
  147. $insert[] = [
  148. 'customer_id' => $model->id,
  149. 'file' => $value['url'],
  150. 'type' => CustomerInfo::type_six,
  151. 'name' => $value['name'],
  152. 'crt_time' => $time,
  153. ];
  154. if(in_array($value['url'], $old)) {
  155. foreach ($old as $o_k => $o_v){
  156. if($o_v == $value['url']) unset($old[$o_k]);
  157. }
  158. }else{
  159. $new[] = $value['url'];
  160. }
  161. }
  162. CustomerInfo::insert($insert);
  163. }
  164. DB::commit();
  165. }catch (\Exception $exception){
  166. DB::rollBack();
  167. return [false,$exception->getMessage()];
  168. }
  169. return [true, ['file' => ['new' => $new, 'old' => $old]]];
  170. }
  171. /**
  172. * 客户新增
  173. * @param $data
  174. * @param $user
  175. * @return array
  176. */
  177. public function customerAdd($data,$user){
  178. list($status,$msg) = $this->customerRule($data,$user);
  179. if(!$status) return [$status,$msg];
  180. try {
  181. DB::beginTransaction();
  182. //车型
  183. if(empty($data['car_type']) && ! empty($data['car_type_title'])){
  184. $model_2 = new BasicType();
  185. $model_2->title = $data['car_type_title'];
  186. $model_2->type = 10;
  187. $model_2->depart_id = $data['depart_id'] ?? 0;
  188. $model_2->top_depart_id = $data['top_depart_id'] ?? 0;
  189. $model_2->crt_id = $user['id'];
  190. $model_2->save();
  191. $data['car_type'] = $model_2->id;
  192. }
  193. $model = new Customer();
  194. $model->title = $data['title'];
  195. $model->code = $data['code'] ?? "";
  196. $model->model_type = $data['model_type'];
  197. $model->customer_intention = $data['customer_intention'] ?? 0;
  198. $model->customer_from = $data['customer_from'] ?? 0;
  199. $model->customer_type = $data['customer_type'] ?? 0;
  200. $model->car_type = $data['car_type'] ?? 0;
  201. $model->consulting_product = $data['consulting_product'] ?? '';
  202. $model->intention_product = $data['intention_product'] ?? 0;
  203. $model->progress_stage = $data['progress_stage'] ?? 0;
  204. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  205. $model->address2 = $data['address2'] ?? '';
  206. $model->crt_id = $user['id'];
  207. $model->mark = $data['mark'] ?? '';
  208. $model->importance = $data['importance'] ?? '';
  209. $model->company = $data['company'] ?? '';
  210. // $model->company_short_name = $data['company_short_name'] ?? '';
  211. $model->depart_id = $data['depart_id'] ?? 0;
  212. $model->top_depart_id = $data['top_depart_id'] ?? 0;
  213. $model->state_type = $data['state_type'] ?? 0;
  214. $model->customer_state = $data['customer_state'] ?? 0;
  215. $model->save();
  216. $time = time();
  217. if(! empty($data['customer_contact'])){
  218. $insert = [];
  219. foreach ($data['customer_contact'] as $value){
  220. $insert[] = [
  221. 'customer_id' => $model->id,
  222. 'contact_type' => $value['id'],
  223. 'contact_info' => $value['info'],
  224. 'type' => CustomerInfo::type_one,
  225. 'crt_time' => $time,
  226. ];
  227. }
  228. CustomerInfo::insert($insert);
  229. }
  230. if(! empty($data['employee_one'])){
  231. $insert = [];
  232. foreach ($data['employee_one'] as $value){
  233. $insert[] = [
  234. 'customer_id' => $model->id,
  235. 'data_id' => $value,
  236. 'type' => CustomerInfo::type_two,
  237. 'crt_time' => $time,
  238. ];
  239. }
  240. CustomerInfo::insert($insert);
  241. Customer::where('id',$model->id)->update([
  242. // 'fp_top_depart_id' => $data['fp_top_depart_id'] ?? 0,
  243. 'fp_time' => $time,
  244. ]);
  245. }
  246. if(! empty($data['employee_two'])){
  247. $insert = [];
  248. foreach ($data['employee_two'] as $value){
  249. $insert[] = [
  250. 'customer_id' => $model->id,
  251. 'data_id' => $value,
  252. 'type' => CustomerInfo::type_three,
  253. 'crt_time' => $time,
  254. ];
  255. }
  256. CustomerInfo::insert($insert);
  257. }
  258. if(! empty($data['employee_three'])){
  259. $insert = [];
  260. foreach ($data['employee_three'] as $value){
  261. $insert[] = [
  262. 'customer_id' => $model->id,
  263. 'data_id' => $value,
  264. 'type' => CustomerInfo::type_four,
  265. 'crt_time' => $time,
  266. ];
  267. }
  268. CustomerInfo::insert($insert);
  269. }
  270. $new = [];
  271. if(! empty($data['img'])){
  272. $insert = [];
  273. foreach ($data['img'] as $value){
  274. $insert[] = [
  275. 'customer_id' => $model->id,
  276. 'file' => $value['url'],
  277. 'type' => CustomerInfo::type_five,
  278. 'name' => $value['name'],
  279. 'crt_time' => $time,
  280. ];
  281. if(! empty($value['url'])) $new[] = $value['url'];
  282. }
  283. CustomerInfo::insert($insert);
  284. }
  285. if(! empty($data['file'])){
  286. $insert = [];
  287. foreach ($data['file'] as $value){
  288. $insert[] = [
  289. 'customer_id' => $model->id,
  290. 'file' => $value['url'],
  291. 'type' => CustomerInfo::type_six,
  292. 'name' => $value['name'],
  293. 'crt_time' => $time,
  294. ];
  295. if(! empty($value['url'])) $new[] = $value['url'];
  296. }
  297. CustomerInfo::insert($insert);
  298. }
  299. DB::commit();
  300. }catch (\Exception $exception){
  301. DB::rollBack();
  302. return [false,$exception->getMessage()];
  303. }
  304. $data['order_number'] = Customer::$order_number . "|" . $model->id . "|" . $data['title'];
  305. (new OperationLogService())->setOperationList($data,$user);
  306. return [true, ['file' => ['new' => $new]]];
  307. }
  308. /**
  309. * 客户删除
  310. * @param $data
  311. * @return array
  312. */
  313. public function customerDel($data){
  314. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  315. if($data['id'] < 0) return [false, '系统数据,操作失败!'];
  316. try {
  317. DB::beginTransaction();
  318. Customer::where('id',$data['id'])->update([
  319. 'del_time'=> time()
  320. ]);
  321. $old = CustomerInfo::where('del_time',0)
  322. ->where('customer_id',$data['id'])
  323. ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
  324. ->select('file')
  325. ->get()->toArray();
  326. $old = array_column($old,'file');
  327. CustomerInfo::where('del_time',0)
  328. ->where('customer_id',$data['id'])
  329. ->update(['del_time' => time()]);
  330. (new RangeService())->RangeDelete($data['id'],SeeRange::type_one);
  331. DB::commit();
  332. }catch (\Exception $exception){
  333. DB::rollBack();
  334. return [false,$exception->getMessage()];
  335. }
  336. return [true, ['file' => ['old' => $old]]];
  337. }
  338. /**
  339. * 客户详情
  340. * @param $data
  341. * @return array
  342. */
  343. public function customerDetail($data,$user){
  344. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  345. $customer = Customer::where('del_time',0)
  346. ->where('id',$data['id'])
  347. ->first();
  348. if(empty($customer)) return [false,'客户不存在或已被删除'];
  349. $customer = $customer->toArray();
  350. //是否是总社的客户
  351. $is_main = 0;
  352. if($customer['top_depart_id'] == $user['head']['id']) $is_main = 1;
  353. $customer['is_belong_to_main'] = $is_main;
  354. $customer['order_number'] = Customer::$order_number . "|" . $data['id'] . "|" . $customer['title'];
  355. $customer['intention_product_title'] = Product::where('id',$customer['intention_product'])->value('title') ?? "";
  356. $customer['product_category'] = [];
  357. if(! empty($customer['intention_product'])){
  358. $pro = (new ProductService())->getProductDetail([$customer['intention_product']]);
  359. $product_category = $pro[$customer['intention_product']]['product_category'] ?? '';
  360. $customer['product_category'] = $product_category ? json_decode($product_category,true) : [];
  361. }
  362. $address_map = config('address');
  363. $address_str = [];
  364. if(! empty($customer['address1'])) {
  365. $tmp = json_decode($customer['address1'],true);
  366. $this->findLabelsByValue($address_map,$tmp,$address_str);
  367. $customer['address1'] = $tmp;
  368. $tmp = implode(' ',$address_str);
  369. $tmp .= ' ' . $customer['address2'];
  370. $address = $tmp;
  371. }else{
  372. $address = $customer['address2'];
  373. }
  374. $customer['address'] = $address;
  375. $customer['customer_contact'] = $customer['employee_one'] = $customer['employee_two'] = $customer['employee_three'] = $customer['img'] = $customer['file'] = $customer['old_employee_one'] = [];
  376. $array = [
  377. $customer['customer_intention'],
  378. $customer['customer_from'],
  379. $customer['customer_type'],
  380. $customer['car_type'],
  381. $customer['progress_stage'],
  382. $customer['state_type'],
  383. $customer['customer_state'],
  384. ];
  385. $basic_map = BasicType::whereIn('id',$array)
  386. ->pluck('title','id')
  387. ->toArray();
  388. $depart_title = Depart::where('id',$customer['depart_id'])->select('title')->value('title');
  389. $customer = [$customer];
  390. foreach ($customer as $key => $value){
  391. $customer[$key]['customer_intention_title'] = $basic_map[$value['customer_intention']] ?? '';
  392. $customer[$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
  393. $customer[$key]['customer_type_title'] = $basic_map[$value['customer_type']] ?? '';
  394. $customer[$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
  395. $customer[$key]['progress_stage_title'] = $basic_map[$value['progress_stage']] ?? '';
  396. $customer[$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
  397. $customer[$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';
  398. $customer[$key]['depart_title'] = $depart_title ?? '';
  399. }
  400. $customer = $customer[0];
  401. $customer_info = CustomerInfo::where('del_time',0)
  402. ->where('customer_id',$customer['id'])
  403. ->select('id','customer_id','contact_type','contact_info','data_id','file','type','name')
  404. ->get()->toArray();
  405. $emp_id = [];
  406. $emp_id[] = $customer['crt_id'];
  407. foreach ($customer_info as $value){
  408. if(in_array($value['type'], CustomerInfo::$man)){
  409. $emp_id[] = $value['data_id'];
  410. }
  411. }
  412. $emp_map = Employee::whereIn('id',array_unique($emp_id))
  413. ->pluck('emp_name','id')
  414. ->toArray();
  415. $basic_map2 = BasicType::whereIn('id',array_unique(array_column($customer_info,'contact_type')))
  416. ->pluck('title','id')
  417. ->toArray();
  418. $fileUploadService = new FileUploadService();
  419. foreach ($customer_info as $value){
  420. if($value['type'] == CustomerInfo::type_one){
  421. $tmp = [
  422. 'id' => $value['contact_type'],
  423. 'title' => $basic_map2[$value['contact_type']] ?? '',
  424. 'info' => $value['contact_info']
  425. ];
  426. $customer['customer_contact'][] = $tmp;
  427. }elseif ($value['type'] == CustomerInfo::type_two){
  428. $tmp = [
  429. 'id' => $value['data_id'],
  430. 'name' => $emp_map[$value['data_id']] ?? '',
  431. ];
  432. $customer['employee_one'][] = $tmp;
  433. }elseif ($value['type'] == CustomerInfo::type_three){
  434. $tmp = [
  435. 'id' => $value['data_id'],
  436. 'name' => $emp_map[$value['data_id']] ?? '',
  437. ];
  438. $customer['employee_two'][] = $tmp;
  439. }elseif ($value['type'] == CustomerInfo::type_four){
  440. $tmp = [
  441. 'id' => $value['data_id'],
  442. 'name' => $emp_map[$value['data_id']] ?? '',
  443. ];
  444. $customer['employee_three'][] = $tmp;
  445. }elseif ($value['type'] == CustomerInfo::type_five){
  446. $tmp = [
  447. 'url' => $value['file'],
  448. 'name' => $value['name'],
  449. 'show_url' => $fileUploadService->getFileShow($value['file']),
  450. ];
  451. $customer['img'][] = $tmp;
  452. }elseif ($value['type'] == CustomerInfo::type_six){
  453. $tmp = [
  454. 'url' => $value['file'],
  455. 'name' => $value['name'],
  456. 'show_url' => $fileUploadService->getFileShow($value['file']),
  457. ];
  458. $customer['file'][] = $tmp;
  459. }elseif ($value['type'] == CustomerInfo::type_nine){
  460. $tmp = [
  461. 'id' => $value['data_id'],
  462. 'name' => $emp_map[$value['data_id']] ?? '',
  463. ];
  464. $customer['old_employee_one'][] = $tmp;
  465. }
  466. }
  467. $customer['crt_name'] = $emp_map[$customer['crt_id']] ?? '';
  468. $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
  469. //可见范围
  470. $return = (new RangeService())->RangeDetail($data['id'],SeeRange::type_one);
  471. $customer['depart'] = $return[0] ?? [];
  472. $customer['employee'] = $return[1] ?? [];
  473. return [true, $customer];
  474. }
  475. public function customerCommonSearch($data,$user){
  476. $model = Customer::Clear($user,$data);
  477. $model = $model->where('del_time',0)
  478. ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id')
  479. ->orderby('id', 'desc');
  480. if(! empty($data['id'])) $model->where('id', $data['id']);
  481. if(! empty($data['my_fz']) || ! empty($data['my_xt'])){
  482. $id = $this->getCustomerId($data,$user);
  483. $model->whereIn('id',$id);
  484. }
  485. if(! empty($data['pond_state'])) {
  486. $search_depart_id = $data['top_depart_id'] ?? 0; //顶级公司
  487. if(empty($search_depart_id)){
  488. $top_depart_id = $user['depart_top'][0] ?? [];
  489. $top_depart_id = $top_depart_id['depart_id'] ?? 0;
  490. }else{
  491. //查询 顶级公司
  492. $top_depart_id = $search_depart_id;
  493. }
  494. // 进入公海池的客户 公司下所有人可见
  495. $model->where('pond_state', '>',0)->where('top_depart_id',$top_depart_id);
  496. }
  497. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  498. if(! empty($data['time_type'])) {
  499. if($data['time_type'] == 1) {
  500. $start = strtotime('today');
  501. $end = strtotime('tomorrow') - 1;
  502. }elseif ($data['time_type'] == 2){
  503. $start = strtotime('this week',strtotime('today'));
  504. $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
  505. }
  506. if(! empty($start) && ! empty($end)) {
  507. $model->where('crt_time','>=',$start);
  508. $model->where('crt_time','<=',$end);
  509. }
  510. }
  511. if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
  512. if(! empty($data['consulting_product'])) $model->where('consulting_product','LIKE', '%'.$data['consulting_product'].'%');
  513. if(! empty($data['mark'])) $model->where('mark','LIKE', '%'.$data['mark'].'%');
  514. if(! empty($data['customer_intention'])) $model->where('customer_intention',$data['customer_intention']);
  515. if(! empty($data['customer_from'])) $model->where('customer_from',$data['customer_from']);
  516. if(! empty($data['customer_type'])) $model->where('customer_type',$data['customer_type']);
  517. if(! empty($data['customer_intention_title'])){
  518. $id = (new RangeService())->customerBasicTypeSearch($data['customer_intention_title'],[1]);
  519. $model->whereIn('customer_intention', $id);
  520. }
  521. if(! empty($data['customer_from_title'])){
  522. $id = (new RangeService())->customerBasicTypeSearch($data['customer_from_title'],[2]);
  523. $model->whereIn('customer_from', $id);
  524. }
  525. if(! empty($data['customer_type_title'])) {
  526. $id = (new RangeService())->customerBasicTypeSearch($data['customer_type_title'],[3,30,31]);
  527. $model->whereIn('customer_type', $id);
  528. }
  529. if(! empty($data['progress_stage_title'])){
  530. $id = (new RangeService())->customerBasicTypeSearch($data['progress_stage_title'],[5]);
  531. $model->whereIn('progress_stage', $id);
  532. }
  533. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
  534. $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
  535. $model->where('crt_time','>=',$return[0]);
  536. $model->where('crt_time','<=',$return[1]);
  537. }
  538. if(! empty($data['crt_name'])){
  539. $id = (new RangeService())->crtNameSearch($data);
  540. $model->whereIn('crt_id',$id);
  541. }
  542. if(! empty($data['fz'])){
  543. $id = (new RangeService())->customerSearch($data);
  544. $model->whereIn('id',$id);
  545. }
  546. if(! empty($data['last_visit_time'])){
  547. $id = (new FollowUpRecordService())->getLastVisitData($data['last_visit_time']);
  548. $model->whereIn('id',$id);
  549. }
  550. if(! empty($data['contact_info'])){
  551. $customer_info = CustomerInfo::where('del_time',0)
  552. ->where("type",CustomerInfo::type_one)
  553. ->where('contact_info','LIKE', '%'.$data['contact_info'].'%')
  554. ->select('customer_id')
  555. ->get()->toArray();
  556. $model->whereIn('id',array_column($customer_info,'customer_id'));
  557. }
  558. if(! empty($data['no_fp_time'])) $model->where('fp_time', 0);
  559. if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
  560. $model->where('crt_time','>=',$data['wx_crt_time'][0]);
  561. $model->where('crt_time','<=',$data['wx_crt_time'][1]);
  562. }
  563. return $model;
  564. }
  565. /**
  566. * 客户列表
  567. * @param $data
  568. * @param $user
  569. * @return array
  570. */
  571. public function customerList($data,$user){
  572. $model = $this->customerCommonSearch($data,$user);
  573. $list = $this->limit($model,'',$data);
  574. $list = $this->fillData($list,$data);
  575. //微信数据
  576. $count = $this->countData("crt_time", $data, $user);
  577. $list['today'] = $count[0] ?? 0;
  578. $list['yesterday'] = $count[1] ?? 0;
  579. return [true, $list];
  580. }
  581. public function customer2CommonSearch($data,$user){
  582. $model = Customer::Clear($user,$data);
  583. $model = $model->where('del_time',0)
  584. ->where('fp_time','>',0)
  585. ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id')
  586. ->orderby('fp_time', 'desc');
  587. if(! empty($data['my_fz']) || ! empty($data['my_xt'])){
  588. $id = $this->getCustomerId($data,$user);
  589. $model->whereIn('id',$id);
  590. }
  591. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  592. if(! empty($data['time_type'])) {
  593. if($data['time_type'] == 1) {
  594. $start = strtotime('today');
  595. $end = strtotime('tomorrow') - 1;
  596. }elseif ($data['time_type'] == 2){
  597. $start = strtotime('this week',strtotime('today'));
  598. $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
  599. }
  600. if(! empty($start) && ! empty($end)) {
  601. $model->where('crt_time','>=',$start);
  602. $model->where('crt_time','<=',$end);
  603. }
  604. }
  605. if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
  606. if(! empty($data['consulting_product'])) $model->where('consulting_product','LIKE', '%'.$data['consulting_product'].'%');
  607. if(! empty($data['mark'])) $model->where('mark','LIKE', '%'.$data['mark'].'%');
  608. if(! empty($data['customer_intention'])) $model->where('customer_intention',$data['customer_intention']);
  609. if(! empty($data['customer_from'])) $model->where('customer_from',$data['customer_from']);
  610. if(! empty($data['customer_type'])) $model->where('customer_type',$data['customer_type']);
  611. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
  612. $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
  613. $model->where('crt_time','>=',$return[0]);
  614. $model->where('crt_time','<=',$return[1]);
  615. }
  616. if(! empty($data['crt_name'])){
  617. $id = (new RangeService())->crtNameSearch($data);
  618. $model->whereIn('crt_id',$id);
  619. }
  620. if(! empty($data['fz'])){
  621. $id = (new RangeService())->customerSearch($data);
  622. $model->whereIn('id',$id);
  623. }
  624. if(! empty($data['last_visit_time'])){
  625. $id = (new FollowUpRecordService())->getLastVisitData($data['last_visit_time']);
  626. $model->whereIn('id',$id);
  627. }
  628. if(! empty($data['contact_info'])){
  629. $customer_info = CustomerInfo::where('del_time',0)
  630. ->where("type",CustomerInfo::type_one)
  631. ->where('contact_info','LIKE', '%'.$data['contact_info'].'%')
  632. ->select('customer_id')
  633. ->get()->toArray();
  634. $model->whereIn('id',array_column($customer_info,'customer_id'));
  635. }
  636. if(! empty($data['fp_time'][0]) && ! empty($data['fp_time'][1])){
  637. $return = $this->changeDateToTimeStampAboutRange($data['fp_time']);
  638. $model->where('fp_time','>=',$return[0]);
  639. $model->where('fp_time','<=',$return[1]);
  640. }
  641. if(! empty($data['belong_top_depart_title'])){
  642. $id = $this->searchCustomerDepart($data['belong_top_depart_title']);
  643. $model->whereIn('id', $id);
  644. }
  645. if(! empty($data['wx_fp_time'][0]) && ! empty($data['wx_fp_time'][1])) {
  646. $model->where('fp_time','>=',$data['wx_fp_time'][0]);
  647. $model->where('fp_time','<=',$data['wx_fp_time'][1]);
  648. }
  649. return $model;
  650. }
  651. public function customerList2($data,$user){
  652. $model = $this->customer2CommonSearch($data, $user);
  653. $list = $this->limit($model,'',$data);
  654. $list = $this->fillData($list,$data);
  655. //微信数据
  656. $count = $this->countData2("fp_time", $data, $user);
  657. $list['today'] = $count[0] ?? 0;
  658. $list['yesterday'] = $count[1] ?? 0;
  659. return [true, $list];
  660. }
  661. public function getCustomerId($data,$user){
  662. $return = [];
  663. if(! empty($data['my_fz'])){
  664. $info = CustomerInfo::where('del_time',0)
  665. ->where('data_id',$user['id'])
  666. ->where('type',CustomerInfo::type_two)
  667. ->select('customer_id')
  668. ->get()->toArray();
  669. $return = array_unique(array_column($info,'customer_id'));
  670. }
  671. if(! empty($data['my_xt'])){
  672. $info = CustomerInfo::where('del_time',0)
  673. ->where('data_id',$user['id'])
  674. ->where('type',CustomerInfo::type_three)
  675. ->select('customer_id')
  676. ->get()->toArray();
  677. $return = array_unique(array_column($info,'customer_id'));
  678. }
  679. return $return;
  680. }
  681. /**
  682. * 客户参数规则
  683. * @param $data
  684. * @param $is_add
  685. * @return array
  686. */
  687. public function customerRule(&$data, $user, $is_add = true){
  688. if(empty($data['model_type'])) return [false,'客户模板类型不能为空'];
  689. if(! in_array($data['model_type'],Customer::$model_type)) return [false,'客户模板类型错误'];
  690. if(empty($data['title'])) return [false,'客户名称不能为空'];
  691. //所属部门 以及 顶级部门
  692. if(empty($data['depart_id'])) {
  693. $data['depart_id'] = $this->getDepart($user);
  694. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  695. }
  696. if($data['model_type'] == Customer::Model_type_one){
  697. // if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
  698. // if(empty($data['customer_type'])) return [false,'客户类别不能为空'];
  699. // if(empty($data['consulting_product'])) return [false,'咨询产品不能为空'];
  700. // if(empty($data['progress_stage'])) return [false,'进展阶段不能为空'];
  701. // if(empty($data['employee_one'])) return [false,'销售SA不能为空'];
  702. }else{
  703. // if(empty($data['car_type'])) return [false,'车型不能为空'];
  704. // if(empty($data['customer_contact'])) return [false,'客户联系方式不能为空'];
  705. }
  706. if(empty($data['car_type']) && ! empty($data['car_type_title'])){
  707. $bool = BasicType::where('title',$data['car_type_title'])
  708. ->where('top_depart_id',$data['top_depart_id'])
  709. ->where('type',10)
  710. ->where('del_time',0)
  711. ->exists();
  712. if($bool) return [false,'车型名称已存在'];
  713. }
  714. if($is_add){
  715. $bool = Customer::where('del_time',0)
  716. ->where('top_depart_id',$data['top_depart_id'])
  717. ->where('title',$data['title'])
  718. // ->where('model_type',$data['model_type'])
  719. ->exists();
  720. if(! empty($data['customer_contact'])) {
  721. $search = [];
  722. foreach ($data['customer_contact'] as $value){
  723. $search[] = $value['info'];
  724. }
  725. $boolean = CustomerInfo::from('customer_info as a')
  726. ->join('customer as b','b.id','a.customer_id')
  727. ->where('a.del_time',0)
  728. ->where('b.del_time',0)
  729. ->where('b.top_depart_id',$data['top_depart_id'])
  730. ->whereIn('a.contact_info', $search)
  731. ->exists();
  732. if($boolean) return [false,'客户联系内容已存在'];
  733. }
  734. }else{
  735. if(empty($data['id'])) return [false,'ID不能为空'];
  736. $bool = Customer::where('del_time',0)
  737. ->where('id','<>',$data['id'])
  738. ->where('top_depart_id',$data['top_depart_id'])
  739. ->where('title',$data['title'])
  740. // ->where('model_type',$data['model_type'])
  741. ->exists();
  742. if(! empty($data['customer_contact'])) {
  743. $search = [];
  744. foreach ($data['customer_contact'] as $value){
  745. $search[] = $value['info'];
  746. }
  747. $boolean = CustomerInfo::from('customer_info as a')
  748. ->join('customer as b','b.id','a.customer_id')
  749. ->where('b.id','<>',$data['id'])
  750. ->where('a.del_time',0)
  751. ->where('b.del_time',0)
  752. ->where('b.top_depart_id',$data['top_depart_id'])
  753. ->whereIn('a.contact_info', $search)
  754. ->exists();
  755. if($boolean) return [false,'客户联系内容已存在'];
  756. }
  757. }
  758. if($bool) return [false,'客户名称不能重复'];
  759. return [true, ''];
  760. }
  761. /**
  762. * 拼接数据
  763. * @param $data
  764. * @return array
  765. */
  766. public function fillData($data,$ergs){
  767. if(empty($data['data'])) return $data;
  768. $array = array_unique(array_merge_recursive(array_column($data['data'],'customer_intention'),array_column($data['data'],'customer_from'),array_column($data['data'],'customer_type'),array_column($data['data'],'car_type'),array_column($data['data'],'progress_stage'),array_column($data['data'],'state_type'),array_column($data['data'],'customer_state')));
  769. $basic_map = BasicType::whereIn('id',$array)
  770. ->pluck('title','id')
  771. ->toArray();
  772. $depart_title = Depart::where('id',array_unique(array_column($data['data'],'depart_id')))
  773. ->pluck('title','id')
  774. ->toArray();
  775. $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
  776. ->pluck('emp_name','id')
  777. ->toArray();
  778. $product = Product::whereIn('id',array_unique(array_column($data['data'],'intention_product')))
  779. ->pluck('title','id')
  780. ->toArray();
  781. $customer_id = array_column($data['data'],'id');
  782. //跟进记录
  783. $record_array = (new FollowUpRecordService())->getVisitDataOfTime($customer_id, FollowUpRecord::type_one);
  784. $customer_info = CustomerInfo::where('del_time',0)
  785. ->whereIn('customer_id',$customer_id)
  786. ->whereIn('type',[CustomerInfo::type_one,CustomerInfo::type_two,CustomerInfo::type_three])
  787. ->select('type','contact_type','contact_info','customer_id','data_id')
  788. ->get()->toArray();
  789. //客户的联系方式 客户的负责人 协同人
  790. $customer_info_map = $fz = $customer_info_map2 = $xt = [];
  791. $emp_map = Employee::whereIn('id',array_filter(array_column($customer_info,'data_id')))
  792. ->pluck('emp_name','id')
  793. ->toArray();
  794. $basic_maps = BasicType::whereIn('id',array_unique(array_filter(array_column($customer_info,'contact_type'))))->pluck('title','id')->toArray();
  795. foreach ($customer_info as $value){
  796. if($value['type'] == CustomerInfo::type_one){
  797. $value['contact_type_title'] = $basic_maps[$value['contact_type']] ?? "";
  798. $customer_info_map[$value['customer_id']][] = $value;
  799. if(! isset($customer_info_map2[$value['customer_id']])){
  800. $customer_info_map2[$value['customer_id']] = $value['contact_type_title'] . ": " . $value['contact_info'];
  801. }else{
  802. $customer_info_map2[$value['customer_id']] .= ',' . $value['contact_type_title'] . ": " . $value['contact_info'];
  803. }
  804. }elseif($value['type'] == CustomerInfo::type_two){
  805. $tmp = $emp_map[$value['data_id']] ?? "";
  806. if(isset($fz[$value['customer_id']])){
  807. $fz[$value['customer_id']] .= ',' . $tmp;
  808. }else{
  809. $fz[$value['customer_id']] = $tmp;
  810. }
  811. }else{
  812. $tmp = $emp_map[$value['data_id']] ?? "";
  813. if(isset($xt[$value['customer_id']])){
  814. $xt[$value['customer_id']] .= ',' . $tmp;
  815. }else{
  816. $xt[$value['customer_id']] = $tmp;
  817. }
  818. }
  819. }
  820. $array2 = array_unique(array_column($data['data'],'top_depart_id'));
  821. $depart = Depart::whereIn('id',$array2)->pluck('title','id')->toArray();
  822. $depart2_map = $this->getCustomerDepart($customer_id);
  823. $address_map = config('address');
  824. foreach ($data['data'] as $key => $value){
  825. $address_str = [];
  826. if(! empty($value['address1'])) {
  827. $tmp = json_decode($value['address1'],true);
  828. $this->findLabelsByValue($address_map,$tmp,$address_str);
  829. $tmp = implode(' ',$address_str);
  830. $tmp .= ' ' . $value['address2'];
  831. $address = $tmp;
  832. }else{
  833. $address = $value['address2'];
  834. }
  835. $data['data'][$key]['address'] = $address;
  836. $data['data'][$key]['customer_intention_title'] = $basic_map[$value['customer_intention']] ?? '';
  837. $data['data'][$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
  838. $data['data'][$key]['customer_type_title'] = $basic_map[$value['customer_type']] ?? '';
  839. $data['data'][$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
  840. $data['data'][$key]['intention_product_title'] = $product[$value['intention_product']] ?? '';
  841. $data['data'][$key]['progress_stage_title'] = $basic_map[$value['progress_stage']] ?? '';
  842. $data['data'][$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
  843. $data['data'][$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';
  844. $data['data'][$key]['depart_title'] = $depart_title[$value['depart_id']] ?? '';
  845. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  846. $data['data'][$key]['fp_time'] = $value['fp_time'] ? date('Y-m-d H:i:s',$value['fp_time']) : '';
  847. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  848. $customer_tmp = $customer_info_map[$value['id']] ?? [];
  849. $data['data'][$key]['customer_detail'] = $customer_tmp;
  850. $data['data'][$key]['customer_detail2'] = $customer_info_map2[$value['id']] ?? "";
  851. $data['data'][$key]['fz'] = $fz[$value['id']] ?? [];
  852. $record_tmp = $record_array[$value['id']] ?? "";
  853. $data['data'][$key]['has_record'] = $record_tmp ? "查看" : "无记录";
  854. $data['data'][$key]['follow_record'] = $record_array[$value['id']] ?? "";
  855. $data['data'][$key]['order_number'] = Customer::$order_number . "|" . $value['id'] . "|" . $value['title'];
  856. $data['data'][$key]['top_depart_title'] = $depart[$value['top_depart_id']] ?? "";
  857. $data['data'][$key]['fp_top_depart_title'] = $depart2_map[$value['id']] ?? "";
  858. $data['data'][$key]['xt'] = $xt[$value['id']] ?? "";
  859. }
  860. return $data;
  861. }
  862. public function countData($column = "", $data, $user){
  863. if(empty($column) || empty($data['from_wx'])) return [0, 0];
  864. // 获取今天的开始和结束时间戳
  865. $todayStart = Carbon::today()->startOfDay()->timestamp;
  866. $todayEnd = Carbon::today()->endOfDay()->timestamp;
  867. // 获取昨天的开始和结束时间戳
  868. $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
  869. $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
  870. $data['wx_' . $column] = [$todayStart, $todayEnd];
  871. $model = $this->customerCommonSearch($data, $user);
  872. // 查询今天的数据条数
  873. $todayCount = $model->count();
  874. $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
  875. $model = $this->customerCommonSearch($data, $user);
  876. // 查询昨天的数据条数
  877. $yesterdayCount = $model->count();
  878. return [$todayCount, $yesterdayCount];
  879. }
  880. public function countData2($column = "", $data, $user){
  881. if(empty($column) || empty($data['from_wx'])) return [0, 0];
  882. // 获取今天的开始和结束时间戳
  883. $todayStart = Carbon::today()->startOfDay()->timestamp;
  884. $todayEnd = Carbon::today()->endOfDay()->timestamp;
  885. // 获取昨天的开始和结束时间戳
  886. $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
  887. $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
  888. $data['wx_' . $column] = [$todayStart, $todayEnd];
  889. $model = $this->customer2CommonSearch($data, $user);
  890. // 查询今天的数据条数
  891. $todayCount = $model->count();
  892. $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
  893. $model = $this->customer2CommonSearch($data, $user);
  894. // 查询昨天的数据条数
  895. $yesterdayCount = $model->count();
  896. return [$todayCount, $yesterdayCount];
  897. }
  898. //获取客资门店
  899. public function getCustomerDepart($customer_id = []){
  900. if(empty($customer_id)) return [];
  901. $result = SeeRange::where('del_time',0)
  902. ->whereIn('data_id', $customer_id)
  903. ->where('data_type',SeeRange::type_one)
  904. ->where('type',SeeRange::data_three)
  905. ->select('data_id as customer_id','param_id as top_depart_id')
  906. ->get()->toArray();
  907. $depart_map = Depart::whereIn('id',array_unique(array_column($result,'top_depart_id')))->pluck('title','id')->toArray();
  908. $return = [];
  909. foreach ($result as $value){
  910. $tmp = $depart_map[$value['top_depart_id']] ?? "";
  911. if(! $tmp) continue;
  912. if(isset($return[$value['customer_id']])){
  913. $return[$value['customer_id']] .= ',' . $tmp;
  914. }else{
  915. $return[$value['customer_id']] = $tmp;
  916. }
  917. }
  918. return $return;
  919. }
  920. //客资门店搜索
  921. public function searchCustomerDepart($depart_title = ""){
  922. $customer_id = [];
  923. if(empty($depart_title)) return $customer_id;
  924. $depart_id = Depart::where('del_time', 0)
  925. ->where('parent_id', 0)
  926. ->where('title', 'LIKE', '%'. $depart_title .'%')
  927. ->select('id')->get()->toArray();
  928. $depart_id = array_column($depart_id, 'id');
  929. if(empty($depart_id)) return $customer_id;
  930. $customer_id = SeeRange::where('del_time',0)
  931. ->whereIn('param_id', $depart_id)
  932. ->where('data_type',SeeRange::type_one)
  933. ->where('type',SeeRange::data_three)
  934. ->select('data_id as customer_id')
  935. ->get()->toArray();
  936. $customer_id = array_column($customer_id, 'customer_id');
  937. return $customer_id;
  938. }
  939. //抢客户
  940. public function customerGrabbing($data, $user){
  941. $key = Customer::$limitKey . $data['customer_id'];
  942. list($status,$msg) = $this->customerGrabbingRule($data,$key);
  943. if(! $status) {
  944. //释放锁
  945. $this->dellimitingSendRequestBackg($key);
  946. return [false,$msg];
  947. }
  948. try {
  949. DB::beginTransaction();
  950. $time = time();
  951. $insert = [];
  952. //负责人获取 改为前负责人
  953. $man = CustomerInfo::where('del_time',0)
  954. ->where('customer_id',$data['customer_id'])
  955. ->where('type', CustomerInfo::type_two)
  956. ->get()->toArray();
  957. foreach ($man as $value){
  958. $insert[] = [
  959. 'customer_id' => $data['customer_id'],
  960. 'data_id' => $value['data_id'],
  961. 'type' => CustomerInfo::type_nine,
  962. 'crt_time' => $time
  963. ];
  964. }
  965. //增加自己为负责人
  966. $insert[] = [
  967. 'customer_id' => $data['customer_id'],
  968. 'data_id' => $user['id'],
  969. 'type' => CustomerInfo::type_two,
  970. 'crt_time' => $time
  971. ];
  972. //人员清空
  973. CustomerInfo::where('del_time',0)
  974. ->where('customer_id',$data['customer_id'])
  975. ->whereIn('type', CustomerInfo::$man2)
  976. ->update(['del_time' => $time]);
  977. //写入最新人员
  978. CustomerInfo::insert($insert);
  979. //更新公海池状态
  980. Customer::where('id',$data['customer_id'])->update([
  981. 'pond_state' => 0
  982. ]);
  983. DB::commit();
  984. }catch (\Exception $exception){
  985. //释放锁
  986. $this->dellimitingSendRequestBackg($key);
  987. DB::rollBack();
  988. return [false,$exception->getMessage()];
  989. }
  990. //释放锁
  991. $this->dellimitingSendRequestBackg($key);
  992. return [true, ''];
  993. }
  994. public function customerGrabbingRule($data, $key){
  995. if(empty($data['customer_id'])) return [false,'请选择客户'];
  996. //上锁
  997. list($status,$msg) = $this->limitingSendRequestBackg($key);
  998. if(! $status) return [false,$msg];
  999. $customer = Customer::where('del_time',0)->where('id',$data['customer_id'])->first();
  1000. if(empty($customer)) return [false,'客户不存在或已被删除'];
  1001. $customer = $customer->toArray();
  1002. if(empty($customer['pond_state'])) return [false,'客户已退出公海池'];
  1003. return [true,''];
  1004. }
  1005. public function searchBy($data,$user){
  1006. $model = BasicType::TopClear($user,$data);
  1007. $result = $model->where('del_time',0)
  1008. ->where('type', 2)
  1009. ->where('title', 'LIKE', '%'.$data['customer_from'].'%')
  1010. ->select('id')
  1011. ->get()->toArray();
  1012. $model2 = Customer::Clear($user,$data);
  1013. $customer = $model2->where('del_time',0)
  1014. ->whereIn('customer_from', array_column($result,'id'))
  1015. ->select('id')
  1016. ->get()->toArray();
  1017. return array_column($customer,'id');
  1018. }
  1019. }