ConstructionService.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. $list = $this->limit($model,'',$data);
  501. $list = $this->fillData($list);
  502. return [true, $list];
  503. }
  504. /**
  505. * 参数规则
  506. * @param $data
  507. * @param $user
  508. * @param $is_add
  509. * @return array
  510. */
  511. public function constructionRule(&$data, $user, $is_add = true){
  512. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  513. if(! in_array($data['model_type'],Construction::$model_type)) return [false,'工单模板类型错误'];
  514. if(empty($data['order_number'])) return [false,'工单编号不能为空'];
  515. if(empty($data['storehouse_id'])) return [false,'请选择仓库'];
  516. if(empty($data['sales_order_id'])) return [false,'请选择合同'];
  517. $sale = SalesOrder::where('del_time',0)->where('id',$data['sales_order_id'])->first();
  518. if(empty($sale)) return [false,'合同不存在或已被删除'];
  519. $sale = $sale->toArray();
  520. if($sale['state'] < SalesOrder::State_two) return [false,'合同未派单,不允许新建施工单'];
  521. list($status,$msg) = $this->limitingSendRequestBackgExpire("construction" . $sale['order_number']);
  522. if(! $status) return [false, $msg];
  523. if(empty($data['product'])) return [false,'请选择产品'];
  524. if(empty($data['construction_period'][0]) || empty($data['construction_period'][1])) return [false,'请填写施工时间范围'];
  525. $data['start_time'] = $this->changeDateToDateMin($data['construction_period'][0]);
  526. $data['end_time'] = $this->changeDateToDateMin($data['construction_period'][1]);
  527. if(! empty($data['construction_fee'])){
  528. $res = $this->checkNumber($data['construction_fee']);
  529. if(! $res) return [false,'施工费用请输入不超过两位小数并且大于0的数值'];
  530. }
  531. if(! empty($data['service_price'])){
  532. $res = $this->checkNumber($data['service_price']);
  533. if(! $res) return [false,'服务价格请输入不超过两位小数并且大于0的数值'];
  534. }
  535. if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
  536. if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
  537. if($data['model_type'] == Construction::Model_type_one){
  538. // if(empty($data['install_method'])) return [false,'安装方式不能为空'];
  539. // if(empty($data['install_position'])) return [false,'安装地点不能为空'];
  540. }else{
  541. // if(empty($data['construction_contact'])) return [false,'联系方式不能为空'];
  542. // if(empty($data['address1']) || empty($data['address2'])) return [false,'地址不能为空'];
  543. }
  544. //所属部门 以及 顶级部门
  545. if(empty($data['depart_id'])) {
  546. $data['depart_id'] = $this->getDepart($user);
  547. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  548. }
  549. $product_submit = $product_id = [];
  550. foreach ($data['product'] as $value){
  551. if(empty($value['number'])) return [false,'产品数量不能为空'];
  552. $res = $this->checkNumber($value['number']);
  553. if(! $res) return [false,'请输入正确的产品数量'];
  554. $key = $value['product_id'] . ',' .$data['storehouse_id'];
  555. if(isset($product_submit[$key])){
  556. $product_submit[$key] += $value['number'];
  557. }else{
  558. $product_submit[$key] = $value['number'];
  559. }
  560. $product_id[] = $value['product_id'];
  561. }
  562. //剩余能施工
  563. $id = $data['id'] ?? 0;
  564. $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
  565. //比较
  566. foreach ($product_submit as $pro => $number){
  567. $tmp = explode(',',$pro);
  568. $p = $tmp[0];
  569. if(! isset($s_product[$p])) return [false,'施工产品错误,合同中不存在该产品'];
  570. $s_number = $s_product[$p];
  571. if($number > $s_number) return [false,'施工产品数量不能超过合同产品数据'];
  572. }
  573. $id = $data['id'] ?? 0;
  574. $product_save = $this->getSaveDetail($id);
  575. //是否校验库存
  576. ProductInventoryService::is_check($user,$data);
  577. list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
  578. if(! $status) return [false, $msg];
  579. $start_time = date("Y-m-d H:i",$data['start_time']);
  580. $end_time = date("Y-m-d H:i",$data['end_time']);
  581. if($is_add){
  582. $bool = Construction::where('del_time',0)
  583. ->where('order_number',$data['order_number'])
  584. ->exists();
  585. if($bool) return [false,'工单编号已存在,请重新获取'];
  586. $bool = Construction::where('del_time',0)
  587. ->where('sales_order_id',$data['sales_order_id'])
  588. ->where('start_time', '<=', $data['end_time'])
  589. ->where('end_time', '>=', $data['start_time'])
  590. ->exists();
  591. if($bool) return [false,'合同:' . $sale['order_number'] . '在' . $start_time . '——' . $end_time . '已下施工单'];
  592. }else{
  593. if(empty($data['id'])) return [false,'ID不能为空'];
  594. $bool = Construction::where('del_time',0)
  595. ->where('id','<>',$data['id'])
  596. ->where('sales_order_id',$data['sales_order_id'])
  597. ->where('start_time', '<=', $data['end_time'])
  598. ->where('end_time', '>=', $data['start_time'])
  599. ->exists();
  600. if($bool) return [false,'合同:' . $sale['order_number'] . '在' . $start_time . '——' . $end_time . '已下施工单'];
  601. }
  602. return [true, [$product_submit, $product_save]];
  603. }
  604. /**
  605. * 数据拼接
  606. * @param $data
  607. * @return array
  608. */
  609. public function fillData($data){
  610. if(empty($data['data'])) return $data;
  611. $array = array_unique(array_merge_recursive(array_column($data['data'],'install_method'),array_column($data['data'],'urgency'),array_column($data['data'],'install_position')));
  612. $basic_map = BasicType::whereIn('id',$array)
  613. ->pluck('title','id')
  614. ->toArray();
  615. $emp = Employee::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'crt_id'),array_column($data['data'],'customer_contact_id'))))
  616. ->pluck('emp_name','id')
  617. ->toArray();
  618. $customer = Customer::whereIn('id',array_unique(array_column($data['data'],'customer_id')))
  619. ->pluck('title','id')
  620. ->toArray();
  621. $sales = SalesOrder::whereIn('id',array_unique(array_column($data['data'],'sales_order_id')))->select('order_number','id','handover_time')->get()->toArray();
  622. $sales_map = [];
  623. foreach ($sales as $value){
  624. $sales_map[$value['id']] = $value;
  625. }
  626. $storehouse = Storehouse::whereIn('id',array_unique(array_column($data['data'],'storehouse_id')))
  627. ->pluck('title','id')
  628. ->toArray();
  629. //分派的总社或分社
  630. $dispatch = $this->getDispatchData($data['data']);
  631. //施工产品
  632. $product_map = $this->getProduct($data['data']);
  633. foreach ($data['data'] as $key => $value){
  634. $product_tmp = $product_map[$value['id']] ?? [];
  635. $data['data'][$key]['product_detail'] = implode(',',$product_tmp);
  636. if(! empty($value['address1'])) {
  637. $tmp = json_decode($value['address1'],true);
  638. $tmp = implode(' ',$tmp);
  639. $tmp .= ' ' . $value['address2'];
  640. $address = $tmp;
  641. }else{
  642. $address = $value['address2'];
  643. }
  644. $start_time = $value['start_time'] ? date("Y-m-d H:i",$value['start_time']) : '';
  645. $end_time = $value['end_time'] ? date("Y-m-d H:i",$value['end_time']) : '';
  646. $data['data'][$key]['construction_period'] = $start_time . '——' . $end_time;
  647. $data['data'][$key]['address'] = $address;
  648. $data['data'][$key]['model_type_title'] = Construction::$model_type_title[$value['model_type']] ?? '';
  649. $data['data'][$key]['install_position_title'] = $basic_map[$value['install_position']] ?? '';
  650. $data['data'][$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
  651. $data['data'][$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
  652. $data['data'][$key]['customer_title'] = $customer[$value['customer_id']] ?? '';
  653. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  654. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  655. $data['data'][$key]['customer_contact_title'] = $emp[$value['customer_contact_id']] ?? '';
  656. $data['data'][$key]['state_title'] = Construction::$name[$value['state']] ?? '';
  657. $tmp_sales = $sales_map[$value['sales_order_id']] ?? [];
  658. $tmp_sales_time = $tmp_sales['handover_time'] ? date("Y-m-d") : "";
  659. $data['data'][$key]['sales_order_number'] = $tmp_sales['order_number'];
  660. $data['data'][$key]['handover_time'] = $tmp_sales_time;
  661. $data['data'][$key]['storehouse_title'] = $storehouse[$value['storehouse_id']] ?? '';
  662. $data['data'][$key]['dispatch_company'] = $dispatch[$value['sales_order_id']] ?? '';
  663. $data['data'][$key]['pq_state_title'] = Construction::$pq_name[$value['pq_state']] ?? '';
  664. $str = "";
  665. $start_time = $value['day_start_stamp'] ? date("Y-m-d H:i",$value['day_start_stamp']) : '';
  666. $end_time = $value['day_end_stamp'] ? date("Y-m-d H:i",$value['day_end_stamp']) : '';
  667. if(! empty($start_time) && ! empty($end_time)) $str = $start_time . '——' . $end_time;
  668. $data['data'][$key]['pq_period'] = $str;
  669. }
  670. return $data;
  671. }
  672. public function getProduct($data){
  673. $search_id = array_column($data,'id');
  674. if(empty($search_id)) return [];
  675. $product = ConstructionProductInfo::where('del_time',0)
  676. ->whereIn('construction_id',$search_id)
  677. ->select('product_id','construction_id')
  678. ->get()->toArray();
  679. $product_map = Product::whereIn('id',array_unique(array_column($product,'product_id')))->pluck('title','id')->toArray();
  680. $return = [];
  681. foreach ($product as $value){
  682. $product_tmp = $product_map[$value['product_id']] ?? "";
  683. if($product_tmp) $return[$value['construction_id']][] = $product_tmp;
  684. }
  685. return $return;
  686. }
  687. public function getDispatchData($data){
  688. $search_id = [];
  689. foreach ($data as $value){
  690. $search_id[] = $value['sales_order_id'];
  691. }
  692. if(empty($search_id)) return [];
  693. $see = SeeRange::where('del_time',0)
  694. ->whereIn('data_id',$search_id)
  695. ->where('data_type',SeeRange::type_seven)
  696. ->where('type',SeeRange::data_three)
  697. ->select('data_id','param_id')
  698. ->get()->toArray();
  699. $map = Depart::whereIn('id',array_unique(array_column($see,'param_id')))
  700. ->pluck('title','id')
  701. ->toArray();
  702. $see_array = [];
  703. foreach ($see as $value){
  704. $see_array[$value['data_id']] = $map[$value['param_id']] ?? "";
  705. }
  706. return $see_array;
  707. }
  708. /**
  709. * 获取施工单号
  710. * @param $data
  711. * @return array
  712. */
  713. public function constructionGet($data){
  714. if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
  715. if(! isset(Construction::$prefix[$data['model_type']])) return [false,'工单模板类型错误'];
  716. $prefix = Construction::$prefix[$data['model_type']];
  717. $order_number = OrderNoService::createConstructionOrderNumber($prefix);
  718. if(! $order_number) return [false,'工单编号生成失败!'];
  719. return [true,['order_number' => $order_number]];
  720. }
  721. /**
  722. * 获取保存详情
  723. * @param $id
  724. * @return array
  725. */
  726. public function getSaveDetail($id){
  727. $product_save = [];
  728. if(empty($id)) return $product_save;
  729. $sub = ConstructionProductInfo::where('construction_id',$id)
  730. ->where('del_time',0)
  731. ->get()->toArray();
  732. foreach ($sub as $value){
  733. $key = $value['product_id'] . ',' . $value['storehouse_id'];
  734. if(isset($product_save[$key])){
  735. $product_save[$key] += $value['number'];
  736. }else{
  737. $product_save[$key] = $value['number'];
  738. }
  739. }
  740. return $product_save;
  741. }
  742. public function getSaveReturnCompareMessage($id = 0, $sales_order_id = 0){
  743. $construction = Construction::where('del_time',0)
  744. ->where('sales_order_id',$sales_order_id)
  745. ->select('id')->get()->toArray();
  746. $construction_id = array_column($construction,'id');
  747. $product_save = [];
  748. $sub = ConstructionProductInfo::where('del_time',0)
  749. ->whereIn('construction_id',$construction_id)
  750. ->when(! empty($id), function ($query) use ($id) {
  751. return $query->where('construction_id', '<>',$id);
  752. })
  753. ->get()->toArray();
  754. foreach ($sub as $value){
  755. if(isset($product_save[$value['product_id']])){
  756. $product_save[$value['product_id']] += $value['number'];
  757. }else{
  758. $product_save[$value['product_id']] = $value['number'];
  759. }
  760. }
  761. $sales_order_product = [];
  762. $sales_product = SalesOrderProductInfo::where('del_time',0)
  763. ->where('sales_order_id',$sales_order_id)
  764. ->get()->toArray();
  765. foreach ($sales_product as $value){
  766. $product_save_tmp = $product_save[$value['product_id']] ?? 0;
  767. if(isset($sales_order_product[$value['product_id']])){
  768. $sales_order_product[$value['product_id']] += $value['number'];
  769. }else{
  770. $sales_order_product[$value['product_id']] = $value['number'] - $product_save_tmp;
  771. }
  772. }
  773. return $sales_order_product;
  774. }
  775. public function deliveryNoteEdit($data,$user){
  776. $id = $user['id'];
  777. if(isset($data['id'])) {
  778. $model = DeliveryNote::where('id',$data['id'])->first();
  779. if($model->img3) return [false,'客户已签字,无法编辑!'];
  780. if(DeliveryNote::where('del_time',0)->where('construction_order_number',$data['construction_order_number'])->where('id','<>',$data['id'])->first()) return [false,'施工单客户确认单已存在!'];
  781. }
  782. else {
  783. $model = new DeliveryNote();
  784. $model->crt_id = $id;
  785. }
  786. try {
  787. $model->upd_id = $id;
  788. $model->construction_order_number = $data['construction_order_number'] ?? '';
  789. $model->start_time = $data['start_time'] ?? '';
  790. $model->end_time = $data['end_time'] ?? '';
  791. $model->vin_no = $data['vin_no'] ?? '';
  792. $model->system = $data['system'] ?? '';
  793. $model->mile = $data['mile'] ?? '';
  794. $model->is_wait = $data['is_wait'] ?? '';
  795. $model->customer_name = $data['customer_name'] ?? '';
  796. $model->customer_mobile = $data['customer_mobile'] ?? '';
  797. $model->sale_man = $data['sale_man'] ?? '';
  798. $model->install_man = $data['install_man'] ?? '';
  799. $model->is_brash = $data['is_brash'] ?? '';
  800. $model->is_chong = $data['is_chong'] ?? '';
  801. $model->service_mark = $data['service_mark'] ?? '';
  802. $model->mark = $data['mark'] ?? '';
  803. $model->break = $data['break'] ? json_encode($data['break']):json_encode([]);
  804. $model->break_mark = $data['break_mark'] ? json_encode($data['break_mark']):json_encode([]);
  805. $model->project_id = $data['project_id'] ? json_encode($data['project_id']):json_encode([]);
  806. $model->other_project_mark = $data['other_project_mark'] ?? '';
  807. $model->img = $data['img'] ?? '';
  808. $model->img1 = $data['img1'] ?? '';
  809. $model->img2 = $data['img2'] ?? '';
  810. $model->img3 = $data['img3'] ?? '';
  811. $model->save();
  812. return [true,'保存成功!'];
  813. }catch (\Throwable $e){
  814. return [true,'保存成功!'];
  815. }
  816. }
  817. public function deliveryNoteList($data)
  818. {
  819. $list = DeliveryNote::where('del_time',0);
  820. $list = $this->limit($list,'*',$data);
  821. return [true,$list];
  822. }
  823. public function deliveryNoteDetail($data){
  824. if(isset($data['id'])) $model = DeliveryNote::where('id',$data['id'])->where('del_time',0)->first();
  825. if(isset($data['construction_order_number'])) $model = DeliveryNote::where('id',$data['construction_order_number'])->where('del_time',0)->first();
  826. if(empty($model)) return [false,'数据不存在!'];
  827. $employee_key_list = Employee::pluck('emp_name','id')->toArray();
  828. $detail = $model->toArray();
  829. $detail['install_man_title'] = $employee_key_list[$detail['install_man']] ?? "";
  830. $detail['sale_man_title'] = $employee_key_list[$detail['sale_man']] ?? "";
  831. $img_list = ConstructionFile::where('order_number',$detail['construction_order_number'])->where('del_time',0)->select('file as url','name','mark')->get()->toArray();
  832. $detail['file'] = $img_list;
  833. return [true,$detail];
  834. }
  835. public function deliveryNoteDel($data,$user){
  836. DeliveryNote::where('id',$data['id'])->update(
  837. [
  838. 'del_time' => time(),
  839. 'upd_id' => $user['id'],
  840. ]
  841. );
  842. return [true,'删除成功!'];
  843. }
  844. public function constructionPdf($data, $user){
  845. if(empty($data['id'])) return [false, '请选择下载的施工单'];
  846. $construction = Construction::where('del_time',0)
  847. ->where('id',$data['id'])
  848. ->first();
  849. if(empty($construction)) return [false, '施工单不存在或已被删除'];
  850. $construction = $construction->toArray();
  851. $customer_title = Customer::where('id',$construction['customer_id'])->value('title');
  852. $construction['customer_title'] = $customer_title ?? "";
  853. $construction['sales_order_number'] = SalesOrder::where('id',$construction['sales_order_id'])->value('order_number') ?? '';
  854. $construction['handover_time'] = $construction['handover_time'] ? date("Y-m-d H:i:s",$construction['handover_time']): '';
  855. $construction['crt_time'] = $construction['crt_time'] ? date("Y-m-d H:i:s",$construction['crt_time']): '';
  856. $construction_info = ConstructionInfo::where('del_time',0)
  857. ->where('construction_id',$construction['id'])
  858. ->where('type',CustomerInfo::type_two)
  859. ->select('id','employee_id')
  860. ->get()->toArray();
  861. $emp_list = Employee::whereIn('id',array_unique(array_merge_recursive([$construction['crt_id']],array_column($construction_info,'employee_id'))))
  862. ->select('emp_name','id','mobile')
  863. ->get()->toArray();
  864. $emp_map = [];
  865. foreach ($emp_list as $value){
  866. $emp_map[$value['id']] = [
  867. 'name' => $value['emp_name'],
  868. 'mobile' => $value['mobile'],
  869. ];
  870. }
  871. $emp_message = EmployeeDepartPermission::from('employee_depart_permission as a')
  872. ->leftJoin('depart as b', 'b.id', 'a.depart_id')
  873. ->select('a.employee_id', 'b.title')
  874. ->whereIn('employee_id',array_column($emp_list,'id'))
  875. ->get()->toArray();
  876. $emp_message_map = [];
  877. foreach ($emp_message as $value){
  878. if(isset($emp_message_map[$value['employee_id']])){
  879. $emp_message_map[$value['employee_id']] .= ',' . $value['title'];
  880. }else{
  881. $emp_message_map[$value['employee_id']] = $value['title'];
  882. }
  883. }
  884. $crt_name = ($emp_map[$construction['crt_id']]['name'] ?? '') . ' ' . ($emp_message_map[$construction['crt_id']] ?? '') . ' ' . ($emp_map[$construction['crt_id']]['mobile'] ?? '');
  885. $construction['crt_name'] = $crt_name;
  886. $xt_name = "";
  887. foreach ($construction_info as $value){
  888. $xt_name .= ($emp_map[$value['employee_id']]['name'] ?? '') . ' ' . ($emp_message_map[$value['employee_id']] ?? '') . ' ' . ($emp_map[$value['employee_id']]['mobile'] ?? '') . " | ";
  889. }
  890. $xt_name = rtrim($xt_name, " | ");
  891. $construction['xt_name'] = $xt_name;
  892. $p_info = ConstructionProductInfo::where('del_time',0)
  893. ->where('construction_id',$construction['id'])
  894. ->get()->toArray();
  895. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  896. $unit_map = BasicType::whereIn('id',array_column($map,'unit'))
  897. ->pluck('title','id')->toArray();
  898. $product = [];
  899. $count = 0;
  900. foreach ($p_info as $value){
  901. $tmp = $map[$value['product_id']] ?? [];
  902. $value['count'] = $count+1;
  903. $value['title'] = $tmp['title'] ?? "";
  904. $value['code'] = $tmp['code'] ?? "";
  905. $value['size'] = $tmp['size'] ?? "";
  906. $value['unit'] = $unit_map[$tmp['unit']] ?? "";
  907. $product[] = $value;
  908. }
  909. //工单进展
  910. $detail = $this->getOaJz($data,$user);
  911. $order_message = ['order' => $construction, 'product' => $product,'detail'=> $detail];
  912. $pdf = app('dompdf.wrapper')->loadView('pdf.construction', $order_message);
  913. $file_name = time().rand(1000,9999);
  914. $filename = '施工单_' . $file_name.'.' . 'pdf';
  915. $pdf->save(storage_path('app/public/export/' . $filename));
  916. return [true, ['file' => $filename]];
  917. }
  918. public function getOaJz($data,$user)
  919. {
  920. $oa = Oa::where('menu_id', 34)
  921. ->where('del_time',0)
  922. ->where('channel',$user['depart_top'][0]['depart_id'])
  923. ->first();
  924. if(empty($oa)) return [];
  925. $oa = $oa->toArray();
  926. $list = OaSub::where('oa_id', $oa['id'])->where('del_time', 0)->get()->toArray();
  927. $oa_sub_ids = [];
  928. foreach ($list as $v) {
  929. $oa_sub_ids[] = $v['id'];
  930. }
  931. $oaEmployee = OaSubEmployee::wherein('oa_sub_id', $oa_sub_ids)->get()->toArray();
  932. $emp_list = Employee::whereIn('id',array_column($oaEmployee,'employee_id'))
  933. ->select('emp_name','id','mobile')
  934. ->get()->toArray();
  935. $emp_map = [];
  936. foreach ($emp_list as $value){
  937. $emp_map[$value['id']] = [
  938. 'name' => $value['emp_name'],
  939. 'mobile' => $value['mobile'],
  940. ];
  941. }
  942. $emp_message = EmployeeDepartPermission::from('employee_depart_permission as a')
  943. ->leftJoin('depart as b', 'b.id', 'a.depart_id')
  944. ->whereIn('a.employee_id',array_column($emp_list,'id'))
  945. ->select('a.employee_id', 'b.title')
  946. ->get()->toArray();
  947. $emp_message_map = [];
  948. foreach ($emp_message as $value){
  949. if(isset($emp_message_map[$value['employee_id']])){
  950. $emp_message_map[$value['employee_id']] .= ',' . $value['title'];
  951. }else{
  952. $emp_message_map[$value['employee_id']] = $value['title'];
  953. }
  954. }
  955. $oaEmployeeKey = [];
  956. foreach ($oaEmployee as $v) {
  957. $str = "";
  958. $tmp = $emp_map[$v['employee_id']] ?? [];
  959. $tmp2 = $emp_message_map[$v['employee_id']] ?? "";
  960. $str = $tmp['name'] . " " . $tmp2 . " " . $tmp['mobile'];dump($str);
  961. $oaEmployeeKey[$v['oa_sub_id']][] = [
  962. 'id' => $v['employee_id'],
  963. 'emp_name' => $str,
  964. ];
  965. }
  966. $return = [];
  967. foreach ($list as $v) {
  968. $return[$v['sort']][] = [
  969. 'emp_id' => $oaEmployeeKey[$v['id']],
  970. 'index' => $v['h5_key'],
  971. ];
  972. }
  973. $detail = [];
  974. foreach ($return as $v) {
  975. $children = "";
  976. foreach ($v as $vv) {
  977. $children .= implode('|',array_column($vv['emp_id'],'emp_name')) . ',';
  978. }
  979. $detail[] = rtrim($children,',');
  980. }
  981. return $detail;
  982. }
  983. }