ExportFileService.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. namespace App\Service;
  3. use App\Exports\ExportOrder;
  4. use App\Exports\MyExport;
  5. use App\Model\Area;
  6. use App\Model\BasicMaterial;
  7. use App\Model\BasicRollFilm;
  8. use App\Model\BasicType;
  9. use App\Model\CarDepart;
  10. use App\Model\CarFiles;
  11. use App\Model\CarType;
  12. use App\Model\Company;
  13. use App\Model\Construction;
  14. use App\Model\ConstructionOrder;
  15. use App\Model\ConstructionOrderImg;
  16. use App\Model\ConstructionOrderSub;
  17. use App\Model\ConstructionProductInfo;
  18. use App\Model\Employee;
  19. use App\Model\FoursShop;
  20. use App\Model\InOutRecord;
  21. use App\Model\Inventory;
  22. use App\Model\InventorySub;
  23. use App\Model\Material;
  24. use App\Model\MaterialCharge;
  25. use App\Model\MaterialChargeSub;
  26. use App\Model\MaterialOrder;
  27. use App\Model\MaterialOrderApply;
  28. use App\Model\MaterialOrderIn;
  29. use App\Model\MaterialOrderSend;
  30. use App\Model\MaterialOrderSendSub;
  31. use App\Model\MaterialReturn;
  32. use App\Model\MaterialReturnSub;
  33. use App\Model\PaymentReceipt;
  34. use App\Model\PaymentReceiptInfo;
  35. use App\Model\RollFilm;
  36. use App\Model\RollFilmCombine;
  37. use App\Model\RollFilmCompany;
  38. use App\Model\RollFilmInventory;
  39. use App\Model\SalesOrder;
  40. use App\Model\SalesOrderOtherFee;
  41. use App\Model\SalesOrderProductInfo;
  42. use App\Model\Storehouse;
  43. use App\Model\Transfer;
  44. use App\Model\TransferSub;
  45. use Illuminate\Support\Facades\DB;
  46. use Maatwebsite\Excel\Facades\Excel;
  47. class ExportFileService extends Service
  48. {
  49. //导出文件
  50. const type_one = 1;
  51. const type_two = 2;
  52. const type_three = 3;
  53. const type_four = 4;
  54. const type_five = 5;
  55. const type_six = 6;
  56. const type_seven = 7;
  57. //导出文件方法
  58. protected static $fuc = [
  59. self::type_one => 'one',
  60. self::type_two => 'two',
  61. self::type_three => 'three',
  62. self::type_four => 'four',
  63. ];
  64. protected static $fuc_name = [
  65. self::type_one => '合同订单',
  66. self::type_two => '派工订单',
  67. self::type_three => '收付款单',
  68. self::type_four => '施工单',
  69. ];
  70. public static $filename = "";
  71. public function exportAll($data,$user){
  72. if(empty($data['id'])) return [false,'请选择导出数据'];
  73. if(empty($data['type']) || ! isset(self::$fuc[$data['type']])) return [false,'导出文件类型错误或者不存在'];
  74. self::$filename = self::$fuc_name[$data['type']] ?? "";
  75. //不超时
  76. ini_set('max_execution_time', 0);
  77. //内存设置
  78. ini_set('memory_limit', -1);
  79. $function = self::$fuc[$data['type']];
  80. $return = $this->$function($data);
  81. return [true, $return];
  82. }
  83. public function one($ergs){
  84. $id = $ergs['id'];
  85. // 导出数据
  86. $return = [];
  87. DB::table('sales_order')
  88. ->whereIn('id', $id)
  89. ->select('id','order_number','model_type','sales_order_type','sign_time','plat_order','plat_type','product_total','other_fee','discount_fee','contract_fee','crt_time','crt_id','state','invoice_state','pay_way')
  90. ->orderBy('id','desc')
  91. ->chunk(500,function ($data) use(&$return){
  92. $data = $data->toArray();
  93. $data_id = array_unique(array_column($data,'id'));
  94. $emp_map = Employee::whereIn('id',array_unique(array_column($data,'crt_id')))
  95. ->pluck('emp_name','id')
  96. ->toArray();
  97. //获取分社订货合同关联的发货单
  98. $id = [];
  99. foreach ($data as $value){
  100. $id[] = [
  101. 'id' => $value->id,
  102. 'invoice_state' => $value->invoice_state,
  103. ];
  104. }
  105. $invoiceData = (new SalesOrderService())->getInvoiceOrderData($id);
  106. $array = array_unique(array_merge_recursive(array_column($data,'car_type'),array_column($data,'pay_way'),array_column($data,'install_position'),array_column($data,'install_method'),array_column($data,'plat_type')));
  107. $basic_map = BasicType::whereIn('id',$array)
  108. ->pluck('title','id')
  109. ->toArray();
  110. $product = [];
  111. $sales_p_info = SalesOrderProductInfo::where('del_time',0)
  112. ->whereIn('sales_order_id',$data_id)
  113. ->get()->toArray();
  114. $basic_price = BasicType::whereIn('id',array_unique(array_column($sales_p_info,'basic_type_id')))->pluck('title','id')->toArray();
  115. $map = (new ProductService())->getProductDetail(array_column($sales_p_info,'product_id'));
  116. foreach ($sales_p_info as $value){
  117. $tmp = $map[$value['product_id']] ?? [];
  118. $value['title'] = $tmp['title'] ?? "";
  119. $value['code'] = $tmp['code'] ?? "";
  120. $value['size'] = $tmp['size'] ?? "";
  121. $value['bar_code'] = $tmp['bar_code'] ?? "";
  122. $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
  123. $value['install_time'] = $tmp['install_time'] ?? 0;
  124. $product[$value['sales_order_id']][] = $value;
  125. }
  126. $flag = [];
  127. foreach ($data as $value){
  128. $tmp = $invoiceData[$value->id] ?? [];
  129. $invoice_arr = implode(',', $tmp);
  130. $model_type_title = SalesOrder::$model_type_title[$value->model_type] ?? '';
  131. $plat_type_title = $basic_map[$value->plat_type] ?? '';
  132. $sales_order_type_title = SalesOrder::$order_type[$value->sales_order_type] ?? '';
  133. $crt_time = empty($value->crt_time) ? '' : date('Y-m-d',$value->crt_time);
  134. $sign_time = empty($value->sign_time) ? '' : date('Y-m-d',$value->sign_time);
  135. $product_tmp = $product[$value->id] ?? [];
  136. if($value->sales_order_type == SalesOrder::Order_type_one){
  137. if($value->model_type == SalesOrder::Model_type_four){
  138. $state = SalesOrder::$state[$value->state] ?? '';
  139. }else{
  140. $state = SalesOrder::$state_2[$value->state] ?? '';
  141. }
  142. }else{
  143. $state = SalesOrder::$state2[$value->state] ?? '';
  144. }
  145. foreach ($product_tmp as $val){
  146. if(in_array($val['sales_order_id'], $flag)){
  147. $return[] = [
  148. 'order_number' => "",
  149. 'model_type_title' => "",
  150. 'sales_order_type_title' => "",
  151. 'sign_time' => "",
  152. 'plat_order' => "",
  153. 'plat_type_title' => "",
  154. 'product_total' => "",
  155. 'other_fee' => "",
  156. 'discount_fee' => "",
  157. 'contract_fee' => "",
  158. 'crt_time' => "",
  159. 'crt_name' => "",
  160. 'state_title' => "",
  161. 'invoice_state_title' =>"",
  162. 'invoice_arr' => "",
  163. 'pay_way' => "",
  164. 'product_title' => $val['title'],
  165. 'product_code' => $val['code'],
  166. 'product_size' => $val['size'],
  167. 'product_rate' => $val['rate'],
  168. 'product_price' => $val['price'],
  169. 'product_num' => $val['number'],
  170. 'product_final_amount' => $val['final_amount'],
  171. ];
  172. }else{
  173. $flag[] = $val['sales_order_id'];
  174. $return[] = [
  175. 'order_number' => $value->order_number,
  176. 'model_type_title' => $model_type_title,
  177. 'sales_order_type_title' => $sales_order_type_title,
  178. 'sign_time' => $sign_time,
  179. 'plat_order' => $value->plat_order,
  180. 'plat_type_title' => $plat_type_title,
  181. 'product_total' => $value->product_total,
  182. 'other_fee' => $value->other_fee,
  183. 'discount_fee' => $value->discount_fee,
  184. 'contract_fee' => $value->contract_fee,
  185. 'crt_time' => $crt_time,
  186. 'crt_name' => $emp_map[$value->crt_id] ?? "",
  187. 'state_title' => $state,
  188. 'invoice_state_title' => SalesOrder::$invoice_state[$value->invoice_state] ?? '',
  189. 'invoice_arr' => $invoice_arr,
  190. 'pay_way' => $basic_map[$value->pay_way] ?? "",
  191. 'product_title' => $val['title'],
  192. 'product_code' => $val['code'],
  193. 'product_size' => $val['size'],
  194. 'product_rate' => $val['rate'],
  195. 'product_price' => $val['price'],
  196. 'product_num' => $val['number'],
  197. 'product_final_amount' => $val['final_amount'],
  198. ];
  199. }
  200. }
  201. }
  202. });
  203. $header = ['合同单号','销售类型','产品类型','签订时间','平台单号','平台类型','产品合计','其他费用','优惠金额','合同金额','创建时间','创建人','订单状态','发货状态','发货单号','付款方式','产品名称','产品编码','产品规格','产品税率','产品单价','产品数量','产品合同金额'];
  204. return $this->saveExportData($return,$header);
  205. }
  206. public function two($ergs){
  207. $id = $ergs['id'];
  208. // 导出数据
  209. $return = [];
  210. DB::table('sales_order')
  211. ->whereIn('id', $id)
  212. ->select('id','order_number','model_type','sales_order_type','sign_time','plat_order','plat_type','product_total','other_fee','discount_fee','contract_fee','crt_time','crt_id','state','invoice_state','pay_way')
  213. ->orderBy('id','desc')
  214. ->chunk(500,function ($data) use(&$return){
  215. $data = $data->toArray();
  216. $data_id = array_unique(array_column($data,'id'));
  217. $emp_map = Employee::whereIn('id',array_unique(array_column($data,'crt_id')))
  218. ->pluck('emp_name','id')
  219. ->toArray();
  220. //获取分社订货合同关联的发货单
  221. $id = [];
  222. foreach ($data as $value){
  223. $id[] = [
  224. 'id' => $value->id,
  225. 'invoice_state' => $value->invoice_state,
  226. 'state' => $value->state,
  227. ];
  228. }
  229. $invoiceData = (new SalesOrderService())->getInvoiceOrderData($id);
  230. $array = array_unique(array_merge_recursive(array_column($data,'car_type'),array_column($data,'pay_way'),array_column($data,'install_position'),array_column($data,'install_method'),array_column($data,'plat_type')));
  231. $basic_map = BasicType::whereIn('id',$array)
  232. ->pluck('title','id')
  233. ->toArray();
  234. $product = [];
  235. $sales_p_info = SalesOrderProductInfo::where('del_time',0)
  236. ->whereIn('sales_order_id',$data_id)
  237. ->get()->toArray();
  238. $basic_price = BasicType::whereIn('id',array_unique(array_column($sales_p_info,'basic_type_id')))->pluck('title','id')->toArray();
  239. $map = (new ProductService())->getProductDetail(array_column($sales_p_info,'product_id'));
  240. //指派金额
  241. $fee = [];
  242. $sales_o_info = SalesOrderOtherFee::where('del_time',0)
  243. ->whereIn('sales_order_id',$data_id)
  244. ->get()->toArray();
  245. foreach ($sales_o_info as $value){
  246. $fee[$value['sales_order_id']] = $value['other_fee_1'];
  247. }
  248. foreach ($sales_p_info as $value){
  249. $tmp = $map[$value['product_id']] ?? [];
  250. $value['title'] = $tmp['title'] ?? "";
  251. $value['code'] = $tmp['code'] ?? "";
  252. $value['size'] = $tmp['size'] ?? "";
  253. $value['bar_code'] = $tmp['bar_code'] ?? "";
  254. $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
  255. $value['install_time'] = $tmp['install_time'] ?? 0;
  256. $product[$value['sales_order_id']][] = $value;
  257. }
  258. //分派的总社或分社
  259. $dispatch = (new SalesOrderService())->getDispatchData($id);
  260. $flag = [];
  261. foreach ($data as $value){
  262. $tmp = $invoiceData[$value->id] ?? [];
  263. $invoice_arr = implode(',', $tmp);
  264. $model_type_title = SalesOrder::$model_type_title[$value->model_type] ?? '';
  265. $plat_type_title = $basic_map[$value->plat_type] ?? '';
  266. $sales_order_type_title = SalesOrder::$order_type[$value->sales_order_type] ?? '';
  267. $crt_time = empty($value->crt_time) ? '' : date('Y-m-d',$value->crt_time);
  268. $sign_time = empty($value->sign_time) ? '' : date('Y-m-d',$value->sign_time);
  269. $product_tmp = $product[$value->id] ?? [];
  270. if($value->sales_order_type == SalesOrder::Order_type_one){
  271. if($value->model_type == SalesOrder::Model_type_four){
  272. $state = SalesOrder::$state[$value->state] ?? '';
  273. }else{
  274. $state = SalesOrder::$state_2[$value->state] ?? '';
  275. }
  276. }else{
  277. $state = SalesOrder::$state2[$value->state] ?? '';
  278. }
  279. foreach ($product_tmp as $val){
  280. if(in_array($val['sales_order_id'], $flag)){
  281. $return[] = [
  282. 'order_number' => "",
  283. 'model_type_title' => "",
  284. 'sales_order_type_title' => "",
  285. 'sign_time' => "",
  286. 'plat_order' => "",
  287. 'plat_type_title' => "",
  288. 'product_total' => "",
  289. 'other_fee' => "",
  290. 'discount_fee' => "",
  291. 'contract_fee' => "",
  292. 'fee' => "",
  293. 'dispatch_company' => "",
  294. 'crt_time' => "",
  295. 'crt_name' => "",
  296. 'state_title' => "",
  297. 'invoice_state_title' =>"",
  298. 'invoice_arr' => "",
  299. 'pay_way' => "",
  300. 'product_title' => $val['title'],
  301. 'product_code' => $val['code'],
  302. 'product_size' => $val['size'],
  303. 'product_rate' => $val['rate'],
  304. 'product_price' => $val['price'],
  305. 'product_num' => $val['number'],
  306. 'product_final_amount' => $val['final_amount'],
  307. ];
  308. }else{
  309. $flag[] = $val['sales_order_id'];
  310. $return[] = [
  311. 'order_number' => $value->order_number,
  312. 'model_type_title' => $model_type_title,
  313. 'sales_order_type_title' => $sales_order_type_title,
  314. 'sign_time' => $sign_time,
  315. 'plat_order' => $value->plat_order,
  316. 'plat_type_title' => $plat_type_title,
  317. 'product_total' => $value->product_total,
  318. 'other_fee' => $value->other_fee,
  319. 'discount_fee' => $value->discount_fee,
  320. 'contract_fee' => $value->contract_fee,
  321. 'fee' => $fee[$value->id] ?? "",
  322. 'dispatch_company' => $dispatch[$value->id] ?? '',
  323. 'crt_time' => $crt_time,
  324. 'crt_name' => $emp_map[$value->crt_id] ?? "",
  325. 'state_title' => $state,
  326. 'invoice_state_title' => SalesOrder::$invoice_state[$value->invoice_state] ?? '',
  327. 'invoice_arr' => $invoice_arr,
  328. 'pay_way' => $basic_map[$value->pay_way] ?? "",
  329. 'product_title' => $val['title'],
  330. 'product_code' => $val['code'],
  331. 'product_size' => $val['size'],
  332. 'product_rate' => $val['rate'],
  333. 'product_price' => $val['price'],
  334. 'product_num' => $val['number'],
  335. 'product_final_amount' => $val['final_amount'],
  336. ];
  337. }
  338. }
  339. }
  340. });
  341. $header = ['合同单号','销售类型','产品类型','签订时间','平台单号','平台类型','产品合计','其他费用','优惠金额','合同金额','指派金额','派遣门店','创建时间','创建人','订单状态','发货状态','发货单号','付款方式','产品名称','产品编码','产品规格','产品税率','产品单价','产品数量','产品合同金额'];
  342. return $this->saveExportData($return,$header);
  343. }
  344. public function three($ergs){
  345. $id = $ergs['id'];
  346. // 导出数据
  347. $return = [];
  348. DB::table('payment_receipt')
  349. ->whereIn('id', $id)
  350. ->select('id','order_number','account','pay_way','type','data_type','payment_receipt_date','mark','crt_time','crt_id','state')
  351. ->orderBy('id','desc')
  352. ->chunk(500,function ($data) use(&$return){
  353. $data = $data->toArray();
  354. $emp_map = Employee::whereIn('id',array_unique(array_column($data,'crt_id')))
  355. ->pluck('emp_name','id')
  356. ->toArray();
  357. $array = array_unique(array_merge_recursive(array_column($data,'account'),array_column($data,'pay_way')));
  358. $basic_map = BasicType::whereIn('id',$array)
  359. ->pluck('title','id')
  360. ->toArray();
  361. $info = PaymentReceiptInfo::where('del_time',0)
  362. ->where('type',PaymentReceiptInfo::type_three)
  363. ->whereIn('payment_receipt_id',array_column($data,'id'))
  364. ->get()->toArray();
  365. $map = [];
  366. foreach ($info as $value){
  367. $map[$value['payment_receipt_id']][] = [
  368. 'payment_receipt_id' => $value['payment_receipt_id'],
  369. 'data_order_no' => $value['data_order_no'],
  370. 'amount' => $value['amount']
  371. ];
  372. }
  373. $flag = [];
  374. foreach ($data as $value){
  375. $account_title = $basic_map[$value->account] ?? '';
  376. $pay_way_title = $basic_map[$value->pay_way] ?? '';
  377. $crt_time = empty($value->crt_time) ? '' : date('Y-m-d',$value->crt_time);
  378. $payment_receipt_date= empty($value->payment_receipt_date) ? '' : date('Y-m-d',$value->payment_receipt_date);
  379. $state_title = PaymentReceipt::$name[$value->state] ?? '';
  380. $product_tmp = $map[$value->id] ?? [];
  381. foreach ($product_tmp as $val){
  382. if(in_array($val['payment_receipt_id'], $flag)){
  383. $return[] = [
  384. 'order_number' => "",
  385. 'account' => "",
  386. 'pay_way' => "",
  387. 'type' => "",
  388. 'data_type' => "",
  389. 'payment_receipt_date' => "",
  390. 'mark' => "",
  391. 'crt_time' => "",
  392. 'crt_name' => "",
  393. 'state_title' => "",
  394. 'data_order_no' => $val['data_order_no'],
  395. 'amount' => $val['amount'],
  396. ];
  397. }else{
  398. $flag[] = $val['payment_receipt_id'];
  399. $return[] = [
  400. 'order_number' => $value->order_number,
  401. 'account' => $account_title,
  402. 'pay_way' => $pay_way_title,
  403. 'type' => PaymentReceipt::$model_type[$value->type] ?? '',
  404. 'data_type' => PaymentReceipt::$data_type[$value->data_type] ?? '',
  405. 'payment_receipt_date' => $payment_receipt_date,
  406. 'mark' => $value->mark,
  407. 'crt_time' => $crt_time,
  408. 'crt_name' => $emp_map[$value->crt_id] ?? "",
  409. 'state_title' => $state_title,
  410. 'data_order_no' => $val['data_order_no'],
  411. 'amount' => $val['amount'],
  412. ];
  413. }
  414. }
  415. }
  416. });
  417. $header = ['收付款单号','收付款账户','支付方式','收付款类型','关联单号类型','回款日期','备注','创建时间','创建人','订单状态','关联单号','金额'];
  418. return $this->saveExportData($return,$header);
  419. }
  420. public function four($ergs){
  421. $id = $ergs['id'];
  422. // 导出数据
  423. $return = [];
  424. DB::table('construction')
  425. ->whereIn('id', $id)
  426. ->select('id','order_number','title','sales_order_id','handover_time','install_method','install_position','mark','urgency','start_time','end_time','crt_time','crt_id','state','pq_state','day_start_stamp','day_end_stamp')
  427. ->orderBy('id','desc')
  428. ->chunk(500,function ($data) use(&$return){
  429. $data = $data->toArray();
  430. $emp_map = Employee::whereIn('id',array_unique(array_column($data,'crt_id')))
  431. ->pluck('emp_name','id')
  432. ->toArray();
  433. $sales = SalesOrder::whereIn('id',array_unique(array_column($data,'sales_order_id')))->select('order_number','id','handover_time')->get()->toArray();
  434. $sales_map = [];
  435. foreach ($sales as $value){
  436. $sales_map[$value['id']] = $value;
  437. }
  438. $array = array_unique(array_merge_recursive(array_column($data,'install_method'),array_column($data,'urgency'),array_column($data,'install_position')));
  439. $basic_map = BasicType::whereIn('id',$array)
  440. ->pluck('title','id')
  441. ->toArray();
  442. $product = [];
  443. $p_info = ConstructionProductInfo::where('del_time',0)
  444. ->whereIn('construction_id',array_unique(array_column($data,'id')))
  445. ->get()->toArray();
  446. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  447. foreach ($p_info as $value){
  448. $tmp = $map[$value['product_id']] ?? [];
  449. $value['title'] = $tmp['title'] ?? "";
  450. $value['code'] = $tmp['code'] ?? "";
  451. $value['size'] = $tmp['size'] ?? "";
  452. $value['unit'] = $tmp['unit'] ?? "";
  453. $value['bar_code'] = $tmp['bar_code'] ?? "";
  454. $product[$value['construction_id']][] = $value;
  455. }
  456. $flag = [];
  457. foreach ($data as $value){
  458. $tmp_sales = $sales_map[$value->sales_order_id] ?? [];
  459. $handover_time = $value->handover_time ? date("Y-m-d") : "";
  460. $sales_order_number = $tmp_sales['order_number'];
  461. $crt_time = empty($value->crt_time) ? '' : date('Y-m-d',$value->crt_time);
  462. $install_position_title = $basic_map[$value->install_position] ?? '';
  463. $install_method_title = $basic_map[$value->install_position] ?? '';
  464. $urgency_title = $basic_map[$value->urgency] ?? '';
  465. $start_time = $value->start_time ? date("Y-m-d H:i",$value->start_time) : '';
  466. $end_time = $value->end_time ? date("Y-m-d H:i",$value->end_time) : '';
  467. $construction_period = $start_time . '——' . $end_time;
  468. $state = Construction::$name[$value->state] ?? '';
  469. $pq_state = Construction::$pq_name[$value->pq_state] ?? '';
  470. $str = "";
  471. $start_time = $value->day_start_stamp ? date("Y-m-d H:i",$value->day_start_stamp) : '';
  472. $end_time = $value->day_end_stamp ? date("Y-m-d H:i",$value->day_end_stamp) : '';
  473. if(! empty($start_time) && ! empty($end_time)) $str = $start_time . '——' . $end_time;
  474. $pq_period = $str;
  475. $product_tmp = $product[$value->id] ?? [];
  476. foreach ($product_tmp as $val){
  477. if(in_array($val['construction_id'], $flag)){
  478. $return[] = [
  479. 'order_number' => "",
  480. 'title' => "",
  481. 'sales_order_title' => "",
  482. 'handover_time' => "",
  483. 'install_method' => "",
  484. 'install_position' => "",
  485. 'mark' => "",
  486. 'urgency' => "",
  487. 'construction_period' => "",
  488. 'state_title' => "",
  489. 'pq_state' => "",
  490. 'pq_period' => "",
  491. 'crt_time' => "",
  492. 'crt_name' => "",
  493. 'product_title' => $val['title'],
  494. 'product_code' => $val['code'],
  495. 'product_size' => $val['size'],
  496. 'product_price' => $val['price'],
  497. 'product_num' => $val['number'],
  498. 'product_final_amount' => $val['final_amount'],
  499. ];
  500. }else{
  501. $flag[] = $val['construction_id'];
  502. $return[] = [
  503. 'order_number' => $value->order_number,
  504. 'title' => $value->title,
  505. 'sales_order_title' => $sales_order_number,
  506. 'handover_time' => $handover_time,
  507. 'install_method' => $install_method_title,
  508. 'install_position' => $install_position_title,
  509. 'mark' => $value->mark,
  510. 'urgency' => $urgency_title,
  511. 'construction_period' => $construction_period,
  512. 'state_title' => $state,
  513. 'pq_state' => $pq_state,
  514. 'pq_period' => $pq_period,
  515. 'crt_time' => $crt_time,
  516. 'crt_name' => $emp_map[$value->crt_id] ?? "",
  517. 'product_title' => $val['title'],
  518. 'product_code' => $val['code'],
  519. 'product_size' => $val['size'],
  520. 'product_price' => $val['price'],
  521. 'product_num' => $val['number'],
  522. 'product_final_amount' => $val['final_amount'],
  523. ];
  524. }
  525. }
  526. }
  527. });
  528. $header = ['施工单号','工单来源','关联单号','交车日期','安装方式','安装地点','备注','紧急程度','施工时间','订单状态','是否排期','排期时间','创建时间','创建人','产品名称','产品编码','产品规格','产品单价','产品数量','产品合同金额'];
  529. return $this->saveExportData($return,$header);
  530. }
  531. public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
  532. if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
  533. $filename = $file_name . '.' . 'xlsx';
  534. $bool = Excel::store(new ExportOrder($data,$type,$headers),"/public/export/{$filename}", null, 'Xlsx', []);
  535. return $filename;
  536. }
  537. }