ConstructionService.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Construction;
  5. use App\Model\ConstructionFile;
  6. use App\Model\ConstructionInfo;
  7. use App\Model\ConstructionProductInfo;
  8. use App\Model\Customer;
  9. use App\Model\CustomerInfo;
  10. use App\Model\DeliveryNote;
  11. use App\Model\Depart;
  12. use App\Model\Employee;
  13. use App\Model\EmployeeDepartPermission;
  14. use App\Model\Oa;
  15. use App\Model\OaSub;
  16. use App\Model\OaSubEmployee;
  17. use App\Model\OaSubReportEmployee;
  18. use App\Model\OaSubRule;
  19. use App\Model\Product;
  20. use App\Model\SalesOrder;
  21. use App\Model\SalesOrderInfo;
  22. use App\Model\SalesOrderProductInfo;
  23. use App\Model\ScheduleInfo;
  24. use App\Model\SeeRange;
  25. use App\Model\Storehouse;
  26. use Illuminate\Support\Facades\DB;
  27. //use Barryvdh\DomPDF\Facade as PDF;
  28. use Barryvdh\DomPDF\PDF;
  29. /**
  30. * 施工订单
  31. */
  32. class ConstructionService extends Service
  33. {
  34. /**
  35. * 施工订单编辑
  36. * @param $data
  37. * @param $user
  38. * @return array
  39. */
  40. public function constructionEdit($data,$user){
  41. list($status,$msg) = $this->constructionRule($data, $user, false);
  42. if(!$status) return [$status,$msg];
  43. $params = $this->getDataFile($data);
  44. (new OperationLogService())->setOperationList($params,$user,2);
  45. try {
  46. DB::beginTransaction();
  47. $model = Construction::where('id', $data['id'])->first();
  48. $model->model_type = $data['model_type'];
  49. $model->order_number = $data['order_number'];
  50. $model->title = $data['title'] ?? '';
  51. $model->customer_id = $data['customer_id'] ?? 0;
  52. $model->customer_contact_id = $data['customer_contact_id'] ?? 0;
  53. $model->install_method = $data['install_method'] ?? 0;
  54. $model->install_position = $data['install_position'] ?? 0;
  55. $model->sales_order_id = $data['sales_order_id'] ?? 0;
  56. $model->construction_fee = $data['construction_fee'] ?? 0;
  57. $model->service_price = $data['service_price'] ?? 0;
  58. $model->construction_time = $data['construction_time'] ?? 0;
  59. $model->handover_time = $data['handover_time'] ?? 0;
  60. $model->urgency = $data['urgency'] ?? 0;
  61. $model->mark = $data['mark'] ?? '';
  62. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  63. $model->address2 = $data['address2'] ?? '';
  64. $model->introduction = $data['introduction'] ?? '';
  65. $model->storehouse_id = $data['storehouse_id'] ?? 0;
  66. $model->start_time = $data['start_time'] ?? 0;
  67. $model->end_time = $data['end_time'] ?? 0;
  68. $model->schedule_id = $data['schedule_id'] ?? 0;
  69. $model->day_stamp = $data['day_stamp'] ?? 0;
  70. $model->day_start_stamp = $data['day_start_stamp'] ?? 0;
  71. $model->day_end_stamp = $data['day_end_stamp'] ?? 0;
  72. $model->save();
  73. $time = time();
  74. ConstructionInfo::where('del_time',0)
  75. ->where('construction_id',$data['id'])
  76. ->update(['del_time' => $time]);
  77. ConstructionProductInfo::where('del_time',0)
  78. ->where('construction_id',$data['id'])
  79. ->update(['del_time' => $time]);
  80. $old = ConstructionFile::where('del_time',0)
  81. ->where('construction_id',$data['id'])
  82. ->select('file')
  83. ->get()->toArray();
  84. $old = array_column($old,'file');
  85. ConstructionFile::where('del_time',0)
  86. ->where('construction_id',$data['id'])
  87. ->update(['del_time' => $time]);
  88. if(! empty($data['construction_contact'])){
  89. $insert = [];
  90. foreach ($data['construction_contact'] as $value){
  91. $insert[] = [
  92. 'construction_id' => $model->id,
  93. 'contact_type' => $value['id'],
  94. 'contact_info' => $value['info'],
  95. 'type' => ConstructionInfo::type_one,
  96. 'crt_time' => $time,
  97. ];
  98. }
  99. ConstructionInfo::insert($insert);
  100. }
  101. if(! empty($data['employee_one'])){
  102. $insert = [];
  103. foreach ($data['employee_one'] as $value){
  104. $insert[] = [
  105. 'construction_id' => $model->id,
  106. 'employee_id' => $value,
  107. 'type' => ConstructionInfo::type_two,
  108. 'crt_time' => $time,
  109. ];
  110. }
  111. ConstructionInfo::insert($insert);
  112. }
  113. if(! empty($data['product'])){
  114. $insert = [];
  115. foreach ($data['product'] as $value){
  116. $insert[] = [
  117. 'construction_id' => $model->id,
  118. 'product_id' => $value['product_id'],
  119. 'number' => $value['number'],
  120. 'cost' => $value['cost'] ?? 0,
  121. 'retail_price' => $value['retail_price'] ?? 0,
  122. 'mark' => $value['mark'] ?? '',
  123. 'crt_time' => $time,
  124. 'storehouse_id' => $data['storehouse_id'] ?? 0,
  125. 'basic_type_id' => $value['basic_type_id'],
  126. 'price' => $value['price'],
  127. 'final_amount' => $value['final_amount'] ?? 0,
  128. ];
  129. }
  130. ConstructionProductInfo::insert($insert);
  131. //锁定库存
  132. ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
  133. }
  134. if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
  135. $new = [];
  136. if(! empty($data['file'])){
  137. $insert = [];
  138. foreach ($data['file'] as $value){
  139. $insert[] = [
  140. 'order_number' => $data['order_number'],
  141. 'construction_id' => $data['id'],
  142. 'file' => $value['url'],
  143. 'name' => $value['name'],
  144. 'mark' => $value['mark'] ?? "",
  145. 'crt_time' => $time,
  146. ];
  147. $new[]= $value['url'];
  148. }
  149. ConstructionFile::insert($insert);
  150. }
  151. DB::commit();
  152. }catch (\Exception $exception){
  153. DB::rollBack();
  154. return [false,$exception->getMessage()];
  155. }
  156. $this->delStorageFile($old, $new);
  157. return [true,''];
  158. }
  159. /**
  160. * 施工订单新增
  161. * @param $data
  162. * @param $user
  163. * @return array
  164. */
  165. public function constructionAdd($data,$user){
  166. list($status,$msg) = $this->constructionRule($data,$user);
  167. if(!$status) return [$status,$msg];
  168. try {
  169. DB::beginTransaction();
  170. $model = new Construction();
  171. $model->model_type = $data['model_type'];
  172. $model->order_number = $data['order_number'];
  173. $model->title = $data['title'] ?? '';
  174. $model->customer_id = $data['customer_id'] ?? 0;
  175. $model->customer_contact_id = $data['customer_contact_id'] ?? 0;
  176. $model->install_method = $data['install_method'] ?? 0;
  177. $model->install_position = $data['install_position'] ?? 0;
  178. $model->sales_order_id = $data['sales_order_id'] ?? 0;
  179. $model->construction_fee = $data['construction_fee'] ?? 0;
  180. $model->service_price = $data['service_price'] ?? 0;
  181. $model->construction_time = $data['construction_time'] ?? 0;
  182. $model->handover_time = $data['handover_time'] ?? 0;
  183. $model->urgency = $data['urgency'] ?? 0;
  184. $model->mark = $data['mark'] ?? '';
  185. $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
  186. $model->address2 = $data['address2'] ?? '';
  187. $model->introduction = $data['introduction'] ?? '';
  188. $model->crt_id = $user['id'];
  189. $model->depart_id = $data['depart_id'] ?? 0;
  190. $model->top_depart_id = $data['top_depart_id'] ?? 0;
  191. $model->storehouse_id = $data['storehouse_id'] ?? 0;
  192. $model->start_time = $data['start_time'] ?? 0;
  193. $model->end_time = $data['end_time'] ?? 0;
  194. $model->schedule_id = $data['schedule_id'] ?? 0;
  195. $model->day_stamp = $data['day_stamp'] ?? 0;
  196. $model->day_start_stamp = $data['day_start_stamp'] ?? 0;
  197. $model->day_end_stamp = $data['day_end_stamp'] ?? 0;
  198. $model->save();
  199. $time = time();
  200. if(! empty($data['construction_contact'])){
  201. $insert = [];
  202. foreach ($data['construction_contact'] as $value){
  203. $insert[] = [
  204. 'construction_id' => $model->id,
  205. 'contact_type' => $value['id'],
  206. 'contact_info' => $value['info'],
  207. 'type' => ConstructionInfo::type_one,
  208. 'crt_time' => $time,
  209. ];
  210. }
  211. ConstructionInfo::insert($insert);
  212. }
  213. if(! empty($data['employee_one'])){
  214. $insert = [];
  215. foreach ($data['employee_one'] as $value){
  216. $insert[] = [
  217. 'construction_id' => $model->id,
  218. 'employee_id' => $value,
  219. 'type' => ConstructionInfo::type_two,
  220. 'crt_time' => $time,
  221. ];
  222. }
  223. ConstructionInfo::insert($insert);
  224. }
  225. if(! empty($data['product'])){
  226. $insert = [];
  227. foreach ($data['product'] as $value){
  228. $insert[] = [
  229. 'construction_id' => $model->id,
  230. 'product_id' => $value['product_id'],
  231. 'number' => $value['number'],
  232. 'cost' => $value['cost'] ?? 0,
  233. 'retail_price' => $value['retail_price'] ?? 0,
  234. 'mark' => $value['mark'] ?? '',
  235. 'crt_time' => $time,
  236. 'storehouse_id' => $data['storehouse_id'] ?? 0,
  237. 'basic_type_id' => $value['basic_type_id'],
  238. 'price' => $value['price'],
  239. 'final_amount' => $value['final_amount'] ?? 0,
  240. ];
  241. }
  242. ConstructionProductInfo::insert($insert);
  243. //锁定库存
  244. ProductInventoryService::changeLockNumber($user,$msg[0],[]);
  245. }
  246. if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
  247. if(! empty($data['file'])){
  248. $insert = [];
  249. foreach ($data['file'] as $value){
  250. $insert[] = [
  251. 'order_number' => $data['order_number'],
  252. 'construction_id' => $model->id,
  253. 'file' => $value['url'],
  254. 'name' => $value['name'],
  255. 'mark' => $value['mark'] ?? "",
  256. 'crt_time' => $time,
  257. ];
  258. }
  259. ConstructionFile::insert($insert);
  260. }
  261. DB::commit();
  262. }catch (\Exception $exception){
  263. DB::rollBack();
  264. return [false,$exception->getMessage()];
  265. }
  266. (new OperationLogService())->setOperationList($data,$user);
  267. return [true,''];
  268. }
  269. /**
  270. * 施工订单删除
  271. * @param $data
  272. * @return array
  273. */
  274. public function constructionDel($data,$user){
  275. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  276. $construction = Construction::where('del_time',0)->where('id',$data['id'])->first();
  277. if(empty($construction)) return [false,'施工单不存在或已被删除'];
  278. $construction = $construction->toArray();
  279. if($construction['state'] > Construction::STATE_ZERO) return [false,'请确认施工单状态,操作失败'];
  280. $product_save = $this->getSaveDetail($data['id']);
  281. try {
  282. DB::beginTransaction();
  283. Construction::where('id',$data['id'])->update([
  284. 'del_time'=> time()
  285. ]);
  286. ConstructionInfo::where('del_time',0)
  287. ->where('construction_id',$data['id'])
  288. ->update(['del_time' => time()]);
  289. $old = ConstructionFile::where('del_time',0)
  290. ->where('construction_id',$data['id'])
  291. ->select('file')
  292. ->get()->toArray();
  293. $old = array_column($old,'file');
  294. ConstructionFile::where('del_time',0)
  295. ->where('construction_id',$data['id'])
  296. ->update(['del_time' => time()]);
  297. ConstructionProductInfo::where('del_time',0)
  298. ->where('construction_id',$data['id'])
  299. ->update(['del_time' => time()]);
  300. (new RangeService())->RangeDelete($data['id'],SeeRange::type_two);
  301. //锁定库存释放
  302. ProductInventoryService::changeLockNumber($user,[],$product_save);
  303. //排班修改
  304. // $schedule = ScheduleInfo::where('del_time',0)
  305. // ->where('schedule_id',$construction['schedule_id'])
  306. // ->where('start_time',$construction['day_start_stamp'])
  307. // ->where('end_time',$construction['day_end_stamp'])
  308. // ->where('is_use','>', ScheduleInfo::not_use)
  309. // ->first();
  310. // if(! empty($schedule)) ScheduleInfo::where('id',$schedule->id)->update(['is_use' => ScheduleInfo::not_use]);
  311. DB::commit();
  312. }catch (\Exception $exception){
  313. DB::rollBack();
  314. return [false,$exception->getMessage()];
  315. }
  316. $this->delStorageFile($old);
  317. return [true,''];
  318. }
  319. /**
  320. * 施工订单详情
  321. * @param $data
  322. * @return array
  323. */
  324. public function detail($data){
  325. if(empty($data['id']) && empty($data['order_number'])) return [false,'请选择数据!'];
  326. if(! empty($data['id'])){
  327. $construction = Construction::where('del_time',0)
  328. ->where('id',$data['id'])
  329. ->first();
  330. }else{
  331. $construction = Construction::where('del_time',0)
  332. ->where('order_number',$data['order_number'])
  333. ->first();
  334. $data['id'] = empty($construction->id) ? 0 : $construction->id;
  335. }
  336. if(empty($construction)) return [false,'施工订单不存在或已被删除'];
  337. $construction = $construction->toArray();
  338. $construction['state_title'] = Construction::$name[$construction['state']] ?? '';
  339. $construction['pq_state_title'] = Construction::$pq_name[$construction['pq_state']] ?? '';
  340. if(! empty($construction['address1'])) {
  341. $tmp = json_decode($construction['address1'],true);
  342. $construction['address1'] = $tmp;
  343. $tmp = implode(' ',$tmp);
  344. $tmp .= ' ' . $construction['address2'];
  345. $address = $tmp;
  346. }else{
  347. $address = $construction['address2'];
  348. }
  349. $construction['address'] = $address;
  350. $start_time = $construction['start_time'] ? date("Y-m-d H:i",$construction['start_time']) : '';
  351. $end_time = $construction['end_time'] ? date("Y-m-d H:i",$construction['end_time']) : '';
  352. $construction['construction_period'] = $start_time . '——' . $end_time;
  353. $sales = SalesOrder::where('id',$construction['sales_order_id'])->value('order_number');
  354. $construction['sales_order_number'] = $sales;
  355. $customer_title = Customer::where('id',$construction['customer_id'])->value('title');
  356. $construction['customer_title'] = $customer_title ?? "";
  357. $info = CustomerInfo::from('customer_info as a')
  358. ->leftJoin('basic_type as b','b.id','a.contact_type')
  359. ->where('a.del_time',0)
  360. ->where('a.customer_id',$construction['customer_id'])
  361. ->where('a.contact_type','>',0)
  362. ->select('b.title','a.contact_info')
  363. ->get()->toArray();
  364. $construction['customer_array'] = $info;
  365. $info = CustomerInfo::from('customer_info as a')
  366. ->leftJoin('basic_type as b','b.id','a.contact_type')
  367. ->where('a.del_time',0)
  368. ->where('a.customer_id',$construction['customer_id'])
  369. ->where('a.contact_type','>',0)
  370. ->select('b.title','a.contact_info')
  371. ->get()->toArray();
  372. $construction['customer_array'] = $info;
  373. $construction['storehouse_title'] = Storehouse::where('id',$construction['storehouse_id'])->value('title');
  374. $emp_title = Employee::where('id',$construction['customer_contact_id'])->value('emp_name');
  375. $construction['customer_contact_title'] = $emp_title;
  376. $construction['employee_one'] = $construction['construction_contact'] = $construction['product'] = [];
  377. $array = [
  378. $construction['install_method'],
  379. $construction['install_position'],
  380. $construction['urgency'],
  381. ];
  382. $basic_map = BasicType::whereIn('id',$array)
  383. ->pluck('title','id')
  384. ->toArray();
  385. $construction = [$construction];
  386. foreach ($construction as $key => $value){
  387. $construction[$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
  388. $construction[$key]['install_position_title'] = $basic_map[$value['install_position']] ?? '';
  389. $construction[$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
  390. }
  391. $construction = $construction[0];
  392. $construction['file'] = [];
  393. $file = ConstructionFile::where('del_time',0)
  394. ->where('construction_id',$construction['id'])
  395. ->select('id','construction_id','file','name','mark')
  396. ->get()->toArray();
  397. foreach ($file as $value){
  398. $construction['file'][] = [
  399. 'url' => $value['file'],
  400. 'name' => $value['name'],
  401. 'mark' => $value['mark'],
  402. ];
  403. }
  404. $construction_info = ConstructionInfo::where('del_time',0)
  405. ->where('construction_id',$construction['id'])
  406. ->select('id','construction_id','employee_id','type','contact_type','contact_info')
  407. ->get()->toArray();
  408. $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$construction['crt_id']],array_column($construction_info,'employee_id'))))
  409. ->pluck('emp_name','id')
  410. ->toArray();
  411. $basic_map2 = BasicType::whereIn('id',array_unique(array_column($construction_info,'contact_type')))
  412. ->pluck('title','id')
  413. ->toArray();
  414. foreach ($construction_info as $value){
  415. if($value['type'] == ConstructionInfo::type_one){
  416. $tmp = [
  417. 'id' => $value['contact_type'],
  418. 'title' => $basic_map2[$value['contact_type']] ?? '',
  419. 'info' => $value['contact_info']
  420. ];
  421. $construction['construction_contact'][] = $tmp;
  422. }elseif ($value['type'] == ConstructionInfo::type_two){
  423. $tmp = [
  424. 'id' => $value['employee_id'],
  425. 'name' => $emp_map[$value['employee_id']] ?? '',
  426. ];
  427. $construction['employee_one'][] = $tmp;
  428. }
  429. }
  430. $p_info = ConstructionProductInfo::where('del_time',0)
  431. ->where('construction_id',$construction['id'])
  432. ->get()->toArray();
  433. $basic_price = BasicType::whereIn('id',array_unique(array_column($p_info,'basic_type_id')))->pluck('title','id')->toArray();
  434. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  435. foreach ($p_info as $value){
  436. $tmp = $map[$value['product_id']] ?? [];
  437. $value['title'] = $tmp['title'] ?? "";
  438. $value['code'] = $tmp['code'] ?? "";
  439. $value['size'] = $tmp['size'] ?? "";
  440. $value['unit'] = $tmp['unit'] ?? "";
  441. $value['bar_code'] = $tmp['bar_code'] ?? "";
  442. $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
  443. $construction['product'][] = $value;
  444. }
  445. $construction['crt_name'] = $emp_map[$construction['crt_id']] ?? '';
  446. $construction['crt_time'] = $construction['crt_time'] ? date("Y-m-d H:i:s",$construction['crt_time']): '';
  447. //可见范围
  448. $return = (new RangeService())->RangeDetail($data['id'],SeeRange::type_two);
  449. $construction['depart'] = $return[0] ?? [];
  450. $construction['employee'] = $return[1] ?? [];
  451. return [true, $construction];
  452. }
  453. /**
  454. * 施工订单列表
  455. * @param $data
  456. * @param $user
  457. * @return array
  458. */
  459. public function constructionList($data,$user){
  460. $model = Construction::Clear($user,$data);
  461. $model = $model->where('del_time',0)
  462. ->select('title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id','start_time','end_time','pq_state','day_start_stamp','day_end_stamp')
  463. ->orderby('id', 'desc');
  464. if(isset($data['state'])) $model->where('state', $data['state']);
  465. if(isset($data['pq_state'])) $model->where('pq_state', $data['pq_state']);
  466. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  467. if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
  468. if(! empty($data['time_type'])) {
  469. if($data['time_type'] == 1) {
  470. $start = strtotime('today');
  471. $end = strtotime('tomorrow') - 1;
  472. }elseif ($data['time_type'] == 2){
  473. $start = strtotime('this week',strtotime('today'));
  474. $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
  475. }
  476. if(! empty($start) && ! empty($end)) {
  477. $model->where('crt_time','>=',$start);
  478. $model->where('crt_time','<=',$end);
  479. }
  480. }
  481. if(! empty($data['construction_period'][0]) && ! empty($data['construction_period'][1])) {
  482. $return = $this->changeDateToTimeStampAboutRange($data['construction_period']);
  483. $model->where('start_time','>=',$return[0]);
  484. $model->where('end_time','<=',$return[1]);
  485. }
  486. if(! empty($data['pq_period'][0]) && ! empty($data['pq_period'][1])) {
  487. $model->where('day_start_stamp','>=',$this->changeDateToDateMin($data['pq_period'][0]));
  488. $model->where('day_end_stamp','<=',$this->changeDateToDateMin($data['pq_period'][1]));
  489. }
  490. if(! empty($data['sale_order'])){
  491. $model2 = SalesOrder::Clear($user,$data);
  492. $sale = $model2->where('del_time',0)
  493. ->where('order_number', 'LIKE', '%'.$data['sale_order'].'%')
  494. ->select('id')
  495. ->get()->toArray();
  496. $model->whereIn('sales_order_id',array_unique(array_column($sale,'id')));
  497. }
  498. if(! empty($data['install_method'])) $model->where('install_method',$data['install_method']);
  499. if(! empty($data['install_position'])) $model->where('install_position',$data['install_position']);
  500. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  501. $list = $this->limit($model,'',$data);
  502. $list = $this->fillData($list);
  503. return [true, $list];
  504. }
  505. /**
  506. * 参数规则
  507. * @param $data
  508. * @param $user
  509. * @param $is_add
  510. * @return array
  511. */
  512. public function constructionRule(&$data, $user, $is_add = true){
  513. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  514. if(! in_array($data['model_type'],Construction::$model_type)) return [false,'工单模板类型错误'];
  515. if(empty($data['order_number'])) return [false,'工单编号不能为空'];
  516. if(empty($data['storehouse_id'])) return [false,'请选择仓库'];
  517. if(empty($data['sales_order_id'])) return [false,'请选择合同'];
  518. $sale = SalesOrder::where('del_time',0)->where('id',$data['sales_order_id'])->first();
  519. if(empty($sale)) return [false,'合同不存在或已被删除'];
  520. $sale = $sale->toArray();
  521. if($sale['state'] < SalesOrder::State_two) return [false,'合同未派单,不允许新建施工单'];
  522. list($status,$msg) = $this->limitingSendRequestBackgExpire("construction" . $sale['order_number']);
  523. if(! $status) return [false, $msg];
  524. if(empty($data['product'])) return [false,'请选择产品'];
  525. if(empty($data['construction_period'][0]) || empty($data['construction_period'][1])) return [false,'请填写施工时间范围'];
  526. $data['start_time'] = $this->changeDateToDateMin($data['construction_period'][0]);
  527. $data['end_time'] = $this->changeDateToDateMin($data['construction_period'][1]);
  528. if(! empty($data['construction_fee'])){
  529. $res = $this->checkNumber($data['construction_fee']);
  530. if(! $res) return [false,'施工费用请输入不超过两位小数并且大于0的数值'];
  531. }
  532. if(! empty($data['service_price'])){
  533. $res = $this->checkNumber($data['service_price']);
  534. if(! $res) return [false,'服务价格请输入不超过两位小数并且大于0的数值'];
  535. }
  536. if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
  537. if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
  538. if($data['model_type'] == Construction::Model_type_one){
  539. // if(empty($data['install_method'])) return [false,'安装方式不能为空'];
  540. // if(empty($data['install_position'])) return [false,'安装地点不能为空'];
  541. }else{
  542. // if(empty($data['construction_contact'])) return [false,'联系方式不能为空'];
  543. // if(empty($data['address1']) || empty($data['address2'])) return [false,'地址不能为空'];
  544. }
  545. //所属部门 以及 顶级部门
  546. if(empty($data['depart_id'])) {
  547. $data['depart_id'] = $this->getDepart($user);
  548. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  549. }
  550. $product_submit = $product_id = [];
  551. foreach ($data['product'] as $value){
  552. if(empty($value['number'])) return [false,'产品数量不能为空'];
  553. $res = $this->checkNumber($value['number']);
  554. if(! $res) return [false,'请输入正确的产品数量'];
  555. $key = $value['product_id'] . ',' .$data['storehouse_id'];
  556. if(isset($product_submit[$key])){
  557. $product_submit[$key] += $value['number'];
  558. }else{
  559. $product_submit[$key] = $value['number'];
  560. }
  561. $product_id[] = $value['product_id'];
  562. }
  563. //剩余能施工
  564. $id = $data['id'] ?? 0;
  565. $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
  566. //比较
  567. foreach ($product_submit as $pro => $number){
  568. $tmp = explode(',',$pro);
  569. $p = $tmp[0];
  570. if(! isset($s_product[$p])) return [false,'施工产品错误,合同中不存在该产品'];
  571. $s_number = $s_product[$p];
  572. if($number > $s_number) return [false,'施工产品数量不能超过合同产品数据'];
  573. }
  574. $id = $data['id'] ?? 0;
  575. $product_save = $this->getSaveDetail($id);
  576. //是否校验库存
  577. ProductInventoryService::is_check($user,$data);
  578. list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
  579. if(! $status) return [false, $msg];
  580. $start_time = date("Y-m-d H:i",$data['start_time']);
  581. $end_time = date("Y-m-d H:i",$data['end_time']);
  582. if($is_add){
  583. $bool = Construction::where('del_time',0)
  584. ->where('order_number',$data['order_number'])
  585. ->exists();
  586. if($bool) return [false,'工单编号已存在,请重新获取'];
  587. $bool = Construction::where('del_time',0)
  588. ->where('sales_order_id',$data['sales_order_id'])
  589. ->where('start_time', '<=', $data['end_time'])
  590. ->where('end_time', '>=', $data['start_time'])
  591. ->exists();
  592. if($bool) return [false,'合同:' . $sale['order_number'] . '在' . $start_time . '——' . $end_time . '已下施工单'];
  593. }else{
  594. if(empty($data['id'])) return [false,'ID不能为空'];
  595. $bool = Construction::where('del_time',0)
  596. ->where('id','<>',$data['id'])
  597. ->where('sales_order_id',$data['sales_order_id'])
  598. ->where('start_time', '<=', $data['end_time'])
  599. ->where('end_time', '>=', $data['start_time'])
  600. ->exists();
  601. if($bool) return [false,'合同:' . $sale['order_number'] . '在' . $start_time . '——' . $end_time . '已下施工单'];
  602. }
  603. return [true, [$product_submit, $product_save]];
  604. }
  605. /**
  606. * 数据拼接
  607. * @param $data
  608. * @return array
  609. */
  610. public function fillData($data){
  611. if(empty($data['data'])) return $data;
  612. $array = array_unique(array_merge_recursive(array_column($data['data'],'install_method'),array_column($data['data'],'urgency'),array_column($data['data'],'install_position')));
  613. $basic_map = BasicType::whereIn('id',$array)
  614. ->pluck('title','id')
  615. ->toArray();
  616. $emp = Employee::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'crt_id'),array_column($data['data'],'customer_contact_id'))))
  617. ->pluck('emp_name','id')
  618. ->toArray();
  619. $customer = Customer::whereIn('id',array_unique(array_column($data['data'],'customer_id')))
  620. ->pluck('title','id')
  621. ->toArray();
  622. $sales = SalesOrder::whereIn('id',array_unique(array_column($data['data'],'sales_order_id')))->select('order_number','id','handover_time')->get()->toArray();
  623. $sales_map = [];
  624. foreach ($sales as $value){
  625. $sales_map[$value['id']] = $value;
  626. }
  627. $storehouse = Storehouse::whereIn('id',array_unique(array_column($data['data'],'storehouse_id')))
  628. ->pluck('title','id')
  629. ->toArray();
  630. //分派的总社或分社
  631. $dispatch = $this->getDispatchData($data['data']);
  632. //施工产品
  633. $product_map = $this->getProduct($data['data']);
  634. foreach ($data['data'] as $key => $value){
  635. $product_tmp = $product_map[$value['id']] ?? [];
  636. $data['data'][$key]['product_detail'] = implode(',',$product_tmp);
  637. if(! empty($value['address1'])) {
  638. $tmp = json_decode($value['address1'],true);
  639. $tmp = implode(' ',$tmp);
  640. $tmp .= ' ' . $value['address2'];
  641. $address = $tmp;
  642. }else{
  643. $address = $value['address2'];
  644. }
  645. $start_time = $value['start_time'] ? date("Y-m-d H:i",$value['start_time']) : '';
  646. $end_time = $value['end_time'] ? date("Y-m-d H:i",$value['end_time']) : '';
  647. $data['data'][$key]['construction_period'] = $start_time . '——' . $end_time;
  648. $data['data'][$key]['address'] = $address;
  649. $data['data'][$key]['model_type_title'] = Construction::$model_type_title[$value['model_type']] ?? '';
  650. $data['data'][$key]['install_position_title'] = $basic_map[$value['install_position']] ?? '';
  651. $data['data'][$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
  652. $data['data'][$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
  653. $data['data'][$key]['customer_title'] = $customer[$value['customer_id']] ?? '';
  654. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  655. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  656. $data['data'][$key]['customer_contact_title'] = $emp[$value['customer_contact_id']] ?? '';
  657. $data['data'][$key]['state_title'] = Construction::$name[$value['state']] ?? '';
  658. $tmp_sales = $sales_map[$value['sales_order_id']] ?? [];
  659. // $tmp_sales_time = $tmp_sales['handover_time'] ? date("Y-m-d") : "";
  660. $data['data'][$key]['sales_order_number'] = $tmp_sales['order_number'];
  661. $data['data'][$key]['handover_time'] = $value['handover_time'] ? date("Y-m-d") : "";
  662. $data['data'][$key]['storehouse_title'] = $storehouse[$value['storehouse_id']] ?? '';
  663. $data['data'][$key]['dispatch_company'] = $dispatch[$value['sales_order_id']] ?? '';
  664. $data['data'][$key]['pq_state_title'] = Construction::$pq_name[$value['pq_state']] ?? '';
  665. $str = "";
  666. $start_time = $value['day_start_stamp'] ? date("Y-m-d H:i",$value['day_start_stamp']) : '';
  667. $end_time = $value['day_end_stamp'] ? date("Y-m-d H:i",$value['day_end_stamp']) : '';
  668. if(! empty($start_time) && ! empty($end_time)) $str = $start_time . '——' . $end_time;
  669. $data['data'][$key]['pq_period'] = $str;
  670. }
  671. return $data;
  672. }
  673. public function getProduct($data){
  674. $search_id = array_column($data,'id');
  675. if(empty($search_id)) return [];
  676. $product = ConstructionProductInfo::where('del_time',0)
  677. ->whereIn('construction_id',$search_id)
  678. ->select('product_id','construction_id')
  679. ->get()->toArray();
  680. $product_map = Product::whereIn('id',array_unique(array_column($product,'product_id')))->pluck('title','id')->toArray();
  681. $return = [];
  682. foreach ($product as $value){
  683. $product_tmp = $product_map[$value['product_id']] ?? "";
  684. if($product_tmp) $return[$value['construction_id']][] = $product_tmp;
  685. }
  686. return $return;
  687. }
  688. public function getDispatchData($data){
  689. $search_id = [];
  690. foreach ($data as $value){
  691. $search_id[] = $value['sales_order_id'];
  692. }
  693. if(empty($search_id)) return [];
  694. $see = SeeRange::where('del_time',0)
  695. ->whereIn('data_id',$search_id)
  696. ->where('data_type',SeeRange::type_seven)
  697. ->where('type',SeeRange::data_three)
  698. ->select('data_id','param_id')
  699. ->get()->toArray();
  700. $map = Depart::whereIn('id',array_unique(array_column($see,'param_id')))
  701. ->pluck('title','id')
  702. ->toArray();
  703. $see_array = [];
  704. foreach ($see as $value){
  705. $see_array[$value['data_id']] = $map[$value['param_id']] ?? "";
  706. }
  707. return $see_array;
  708. }
  709. /**
  710. * 获取施工单号
  711. * @param $data
  712. * @return array
  713. */
  714. public function constructionGet($data){
  715. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  716. if(! isset(Construction::$prefix[$data['model_type']])) return [false,'工单模板类型错误'];
  717. $prefix = Construction::$prefix[$data['model_type']];
  718. $order_number = OrderNoService::createConstructionOrderNumber($prefix);
  719. if(! $order_number) return [false,'工单编号生成失败!'];
  720. return [true,['order_number' => $order_number]];
  721. }
  722. /**
  723. * 获取保存详情
  724. * @param $id
  725. * @return array
  726. */
  727. public function getSaveDetail($id){
  728. $product_save = [];
  729. if(empty($id)) return $product_save;
  730. $sub = ConstructionProductInfo::where('construction_id',$id)
  731. ->where('del_time',0)
  732. ->get()->toArray();
  733. foreach ($sub as $value){
  734. $key = $value['product_id'] . ',' . $value['storehouse_id'];
  735. if(isset($product_save[$key])){
  736. $product_save[$key] += $value['number'];
  737. }else{
  738. $product_save[$key] = $value['number'];
  739. }
  740. }
  741. return $product_save;
  742. }
  743. public function getSaveReturnCompareMessage($id = 0, $sales_order_id = 0){
  744. $construction = Construction::where('del_time',0)
  745. ->where('sales_order_id',$sales_order_id)
  746. ->select('id')->get()->toArray();
  747. $construction_id = array_column($construction,'id');
  748. $product_save = [];
  749. $sub = ConstructionProductInfo::where('del_time',0)
  750. ->whereIn('construction_id',$construction_id)
  751. ->when(! empty($id), function ($query) use ($id) {
  752. return $query->where('construction_id', '<>',$id);
  753. })
  754. ->get()->toArray();
  755. foreach ($sub as $value){
  756. if(isset($product_save[$value['product_id']])){
  757. $product_save[$value['product_id']] += $value['number'];
  758. }else{
  759. $product_save[$value['product_id']] = $value['number'];
  760. }
  761. }
  762. $sales_order_product = [];
  763. $sales_product = SalesOrderProductInfo::where('del_time',0)
  764. ->where('sales_order_id',$sales_order_id)
  765. ->get()->toArray();
  766. foreach ($sales_product as $value){
  767. $product_save_tmp = $product_save[$value['product_id']] ?? 0;
  768. if(isset($sales_order_product[$value['product_id']])){
  769. $sales_order_product[$value['product_id']] += $value['number'];
  770. }else{
  771. $sales_order_product[$value['product_id']] = $value['number'] - $product_save_tmp;
  772. }
  773. }
  774. return $sales_order_product;
  775. }
  776. public function deliveryNoteEdit($data,$user){
  777. $id = $user['id'];
  778. if(isset($data['id'])) {
  779. $model = DeliveryNote::where('id',$data['id'])->first();
  780. if($model->img3) return [false,'客户已签字,无法编辑!'];
  781. if(DeliveryNote::where('del_time',0)->where('construction_order_number',$data['construction_order_number'])->where('id','<>',$data['id'])->first()) return [false,'施工单客户确认单已存在!'];
  782. }
  783. else {
  784. $model = new DeliveryNote();
  785. $model->crt_id = $id;
  786. }
  787. try {
  788. $model->upd_id = $id;
  789. $model->construction_order_number = $data['construction_order_number'] ?? '';
  790. $model->start_time = $data['start_time'] ?? '';
  791. $model->end_time = $data['end_time'] ?? '';
  792. $model->vin_no = $data['vin_no'] ?? '';
  793. $model->system = $data['system'] ?? '';
  794. $model->mile = $data['mile'] ?? '';
  795. $model->is_wait = $data['is_wait'] ?? '';
  796. $model->customer_name = $data['customer_name'] ?? '';
  797. $model->customer_mobile = $data['customer_mobile'] ?? '';
  798. $model->sale_man = $data['sale_man'] ?? '';
  799. $model->install_man = $data['install_man'] ?? '';
  800. $model->is_brash = $data['is_brash'] ?? '';
  801. $model->is_chong = $data['is_chong'] ?? '';
  802. $model->service_mark = $data['service_mark'] ?? '';
  803. $model->mark = $data['mark'] ?? '';
  804. $model->break = $data['break'] ? json_encode($data['break']):json_encode([]);
  805. $model->break_mark = $data['break_mark'] ? json_encode($data['break_mark']):json_encode([]);
  806. $model->project_id = $data['project_id'] ? json_encode($data['project_id']):json_encode([]);
  807. $model->other_project_mark = $data['other_project_mark'] ?? '';
  808. $model->img = $data['img'] ?? '';
  809. $model->img1 = $data['img1'] ?? '';
  810. $model->img2 = $data['img2'] ?? '';
  811. $model->img3 = $data['img3'] ?? '';
  812. $model->save();
  813. return [true,'保存成功!'];
  814. }catch (\Throwable $e){
  815. return [true,'保存成功!'];
  816. }
  817. }
  818. public function deliveryNoteList($data)
  819. {
  820. $list = DeliveryNote::where('del_time',0);
  821. $list = $this->limit($list,'*',$data);
  822. return [true,$list];
  823. }
  824. public function deliveryNoteDetail($data){
  825. if(isset($data['id'])) $model = DeliveryNote::where('id',$data['id'])->where('del_time',0)->first();
  826. if(isset($data['construction_order_number'])) $model = DeliveryNote::where('id',$data['construction_order_number'])->where('del_time',0)->first();
  827. if(empty($model)) return [false,'数据不存在!'];
  828. $employee_key_list = Employee::pluck('emp_name','id')->toArray();
  829. $detail = $model->toArray();
  830. $detail['install_man_title'] = $employee_key_list[$detail['install_man']] ?? "";
  831. $detail['sale_man_title'] = $employee_key_list[$detail['sale_man']] ?? "";
  832. $img_list = ConstructionFile::where('order_number',$detail['construction_order_number'])->where('del_time',0)->select('file as url','name','mark')->get()->toArray();
  833. $detail['file'] = $img_list;
  834. return [true,$detail];
  835. }
  836. public function deliveryNoteDel($data,$user){
  837. DeliveryNote::where('id',$data['id'])->update(
  838. [
  839. 'del_time' => time(),
  840. 'upd_id' => $user['id'],
  841. ]
  842. );
  843. return [true,'删除成功!'];
  844. }
  845. public function constructionPdf($data, $user){
  846. if(empty($data['id'])) return [false, '请选择下载的施工单'];
  847. $construction = Construction::where('del_time',0)
  848. ->where('id',$data['id'])
  849. ->first();
  850. if(empty($construction)) return [false, '施工单不存在或已被删除'];
  851. $construction = $construction->toArray();
  852. $customer_title = Customer::where('id',$construction['customer_id'])->value('title');
  853. $construction['customer_title'] = $customer_title ?? "";
  854. $construction['sales_order_number'] = SalesOrder::where('id',$construction['sales_order_id'])->value('order_number') ?? '';
  855. $construction['handover_time'] = $construction['handover_time'] ? date("Y-m-d H:i:s",$construction['handover_time']): '';
  856. $construction['crt_time'] = $construction['crt_time'] ? date("Y-m-d H:i:s",$construction['crt_time']): '';
  857. $construction_info = ConstructionInfo::where('del_time',0)
  858. ->where('construction_id',$construction['id'])
  859. ->where('type',CustomerInfo::type_two)
  860. ->select('id','employee_id')
  861. ->get()->toArray();
  862. $emp_list = Employee::whereIn('id',array_unique(array_merge_recursive([$construction['crt_id']],array_column($construction_info,'employee_id'))))
  863. ->select('emp_name','id','mobile')
  864. ->get()->toArray();
  865. $emp_map = [];
  866. foreach ($emp_list as $value){
  867. $emp_map[$value['id']] = [
  868. 'name' => $value['emp_name'],
  869. 'mobile' => $value['mobile'],
  870. ];
  871. }
  872. $emp_message = EmployeeDepartPermission::from('employee_depart_permission as a')
  873. ->leftJoin('depart as b', 'b.id', 'a.depart_id')
  874. ->select('a.employee_id', 'b.title')
  875. ->whereIn('employee_id',array_column($emp_list,'id'))
  876. ->get()->toArray();
  877. $emp_message_map = [];
  878. foreach ($emp_message as $value){
  879. if(isset($emp_message_map[$value['employee_id']])){
  880. $emp_message_map[$value['employee_id']] .= ',' . $value['title'];
  881. }else{
  882. $emp_message_map[$value['employee_id']] = $value['title'];
  883. }
  884. }
  885. $crt_name = ($emp_map[$construction['crt_id']]['name'] ?? '') . ' ' . ($emp_message_map[$construction['crt_id']] ?? '') . ' ' . ($emp_map[$construction['crt_id']]['mobile'] ?? '');
  886. $construction['crt_name'] = $crt_name;
  887. $xt_name = "";
  888. foreach ($construction_info as $value){
  889. $xt_name .= ($emp_map[$value['employee_id']]['name'] ?? '') . ' ' . ($emp_message_map[$value['employee_id']] ?? '') . ' ' . ($emp_map[$value['employee_id']]['mobile'] ?? '') . " | ";
  890. }
  891. $xt_name = rtrim($xt_name, " | ");
  892. $construction['xt_name'] = $xt_name;
  893. $p_info = ConstructionProductInfo::where('del_time',0)
  894. ->where('construction_id',$construction['id'])
  895. ->get()->toArray();
  896. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  897. $unit_map = BasicType::whereIn('id',array_column($map,'unit'))
  898. ->pluck('title','id')->toArray();
  899. $product = [];
  900. $count = 0;
  901. foreach ($p_info as $value){
  902. $tmp = $map[$value['product_id']] ?? [];
  903. $value['count'] = $count+1;
  904. $value['title'] = $tmp['title'] ?? "";
  905. $value['code'] = $tmp['code'] ?? "";
  906. $value['size'] = $tmp['size'] ?? "";
  907. $value['unit'] = $unit_map[$tmp['unit']] ?? "";
  908. $product[] = $value;
  909. }
  910. //工单进展
  911. $detail = $this->getOaJz($data,$user);
  912. $order_message = ['order' => $construction, 'product' => $product,'detail'=> $detail];
  913. $pdf = app('dompdf.wrapper')->loadView('pdf.construction', $order_message);
  914. $file_name = time().rand(1000,9999);
  915. $filename = '施工单_' . $file_name.'.' . 'pdf';
  916. $pdf->save(storage_path('app/public/export/' . $filename));
  917. return [true, ['file' => $filename]];
  918. }
  919. public function getOaJz($data,$user)
  920. {
  921. $oa = Oa::where('menu_id', 34)
  922. ->where('del_time',0)
  923. ->where('channel',$user['depart_top'][0]['depart_id'])
  924. ->first();
  925. if(empty($oa)) return [];
  926. $oa = $oa->toArray();
  927. $list = OaSub::where('oa_id', $oa['id'])->where('del_time', 0)->get()->toArray();
  928. $oa_sub_ids = [];
  929. foreach ($list as $v) {
  930. $oa_sub_ids[] = $v['id'];
  931. }
  932. $oaEmployee = OaSubEmployee::wherein('oa_sub_id', $oa_sub_ids)->get()->toArray();
  933. $emp_list = Employee::whereIn('id',array_column($oaEmployee,'employee_id'))
  934. ->select('emp_name','id','mobile')
  935. ->get()->toArray();
  936. $emp_map = [];
  937. foreach ($emp_list as $value){
  938. $emp_map[$value['id']] = [
  939. 'name' => $value['emp_name'],
  940. 'mobile' => $value['mobile'],
  941. ];
  942. }
  943. $emp_message = EmployeeDepartPermission::from('employee_depart_permission as a')
  944. ->leftJoin('depart as b', 'b.id', 'a.depart_id')
  945. ->whereIn('a.employee_id',array_column($emp_list,'id'))
  946. ->select('a.employee_id', 'b.title')
  947. ->get()->toArray();
  948. $emp_message_map = [];
  949. foreach ($emp_message as $value){
  950. if(isset($emp_message_map[$value['employee_id']])){
  951. $emp_message_map[$value['employee_id']] .= ',' . $value['title'];
  952. }else{
  953. $emp_message_map[$value['employee_id']] = $value['title'];
  954. }
  955. }
  956. $oaEmployeeKey = [];
  957. foreach ($oaEmployee as $v) {
  958. $str = "";
  959. $tmp = $emp_map[$v['employee_id']] ?? [];
  960. $tmp2 = $emp_message_map[$v['employee_id']] ?? "";
  961. $str = $tmp['name'] . " " . $tmp2 . " " . $tmp['mobile'];
  962. $oaEmployeeKey[$v['oa_sub_id']][] = [
  963. 'id' => $v['employee_id'],
  964. 'emp_name' => $str,
  965. ];
  966. }
  967. $return = [];
  968. foreach ($list as $v) {
  969. $return[$v['sort']][] = [
  970. 'emp_id' => $oaEmployeeKey[$v['id']],
  971. 'index' => $v['h5_key'],
  972. ];
  973. }
  974. $detail = [];
  975. foreach ($return as $v) {
  976. $children = "";
  977. foreach ($v as $vv) {
  978. $children .= implode('|',array_column($vv['emp_id'],'emp_name')) . ',';
  979. }
  980. $detail[] = rtrim($children,',');
  981. }
  982. return $detail;
  983. }
  984. }