Prechádzať zdrojové kódy

到处已预报的订单

zhangdehua 10 mesiacov pred
rodič
commit
15284b930b

+ 90 - 3
app/store/service/order/Export.php

@@ -75,7 +75,44 @@ class Export extends BaseService
         $orderListArr = $orderList->toArray();
         $orderForExcelArr = [];
         foreach ($orderListArr as $item) {
-            $orderForExcelArr[] = [
+            foreach ($item['goods'] as $key => &$goods){
+                $goodsFlavors = json_decode($goods['remark_for_one'],true);
+                $str = '';
+                foreach ($goodsFlavors as $k => $flavor){
+                    if ($flavor > 0){
+                        $str .= ($k .'×'. $flavor. ',');
+                    }
+                }
+                if ($key == 0){
+                    $orderForExcelArr[] = [
+                        $item['order_no'],
+                        $item['express_no'],
+                        $item['address']['region']['code'],
+                        $item['address']['city'],
+                        $item['address']['zip_code'],
+                        $item['address']['name'] . ' ' . $item['address']['last_name'],
+                        $item['address']['phone'],
+                        $item['address']['detail'],
+                        $str,
+                        $goods['total_num'],
+                    ];
+                }else{
+                    $orderForExcelArr[] = [
+                        '',
+                        '',
+                        '',
+                        '',
+                        '',
+                        $item['address']['name'] . ' ' . $item['address']['last_name'],
+                        $item['address']['phone'],
+                        $item['address']['detail'],
+                        $str,
+                        $goods['total_num'],
+                    ];
+                }
+            }
+
+/*            $orderForExcelArr[] = [
                 '专线',
                 'YH1049',
                 $item['order_no'],
@@ -100,7 +137,7 @@ class Export extends BaseService
                 $item['total_price'],
                 $item['total_price'],
                 $item['express_no'],
-            ];
+            ];*/
         }
         // 格式化生成表格数据
 /*        $columns = [
@@ -132,7 +169,8 @@ class Export extends BaseService
         // 获取导出的记录列名集
         //$columns = $this->getColumns($param['columns']);
         // 输出并写入到excel文件
-        $filePath = $this->outputDeliveryExcel($orderForExcelArr);
+        //$filePath = $this->outputDeliveryExcel($orderForExcelArr);
+        $filePath = $this->outputDeliveryExcelSimple($orderForExcelArr);
         // 新增订单导出记录
         $this->record($param, $filePath);
         return true;
@@ -278,6 +316,55 @@ class Export extends BaseService
     }
 
     /**
+     * 输出并写入到excel文件
+     * @param array $excelList 表格内容
+     * @return string
+     * @throws BaseException
+     */
+    private function outputDeliveryExcelSimple(array $excelList): string
+    {
+        $reader = IOFactory::createReader('Xlsx');
+        $reader->setReadDataOnly(TRUE);
+        $templateFile = public_path('template');
+        $spreadsheet = $reader->load($templateFile . 'OnePackagePreOrdersSimple.xlsx'); //载入excel表格
+
+        $sheet = $spreadsheet->getActiveSheet();
+
+        // 列宽
+        $sheet->getDefaultColumnDimension()->setWidth(24);
+        // 默认行高
+        $sheet->getDefaultRowDimension()->setRowHeight(20);
+        // 字体加粗(第一行)
+        $sheet->getStyle('1')->getFont()->setBold(true);
+
+        // 写入内容数据
+        foreach ($excelList as $key => $item) {
+            $row = $key + 2;
+            $sheet->setCellValueByColumnAndRow(1, $row, $item[0]);
+            $sheet->setCellValueByColumnAndRow(2, $row, $item[1]);
+            $sheet->setCellValueByColumnAndRow(3, $row, $item[2]);
+            $sheet->setCellValueByColumnAndRow(4, $row, $item[3]);
+            $sheet->setCellValueByColumnAndRow(5, $row, $item[4]);
+            $sheet->setCellValueByColumnAndRow(6, $row, $item[5]);
+            $sheet->setCellValueByColumnAndRow(7, $row, $item[6]);
+            $sheet->setCellValueByColumnAndRow(8, $row, $item[7]);
+            $sheet->setCellValueByColumnAndRow(9, $row, $item[8]);
+            $sheet->setCellValueByColumnAndRow(10, $row, $item[9]);
+        }
+        // 生成文件路径
+        $fileName = 'order-' . time() . '.xlsx';
+        $filePath = $this->getExportPath();
+        // 保存到文件
+        try {
+            $writer = new Xlsx($spreadsheet);
+            $writer->save(public_path() . $filePath . $fileName);
+        } catch (\PhpOffice\PhpSpreadsheet\Writer\Exception $e) {
+            throwError($e->getMessage());
+        }
+        return $filePath . $fileName;
+    }
+
+    /**
      * 获取导出的文件夹路径
      * @return string
      */

BIN
public/template/OnePackagePreOrdersSimple.xlsx