chengwl 4 年之前
父节点
当前提交
470c1fa966
共有 2 个文件被更改,包括 109 次插入3 次删除
  1. 87 2
      controllers/SiteController.php
  2. 22 1
      views/site/index.php

+ 87 - 2
controllers/SiteController.php

@@ -150,10 +150,9 @@ class SiteController extends Controller
             $i++;
         }
         $spreadsheet->setActiveSheetIndex(0)->getStyle('B1:B'.$i)->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
-        
         // Rename worksheet
         $spreadsheet->getActiveSheet()->setTitle('Simple');
-        
+        // 
         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
         $spreadsheet->setActiveSheetIndex(0);
         $filename=($shop==1 ? "美国仓":"亚马逊")."退货订单".date("Ymd").".xlsx";
@@ -180,6 +179,92 @@ class SiteController extends Controller
 
 
 
+    }
+    public function actionOrderExport(){
+        $request = Yii::$app->request;
+        $id = $request->post('id'); 
+        if(!is_array($id)){
+            throw new \yii\base\ErrorException('参数异常');
+        }
+        $ids=implode(',',$id);
+        $orders=Orderreturn::find()
+        ->select(['*'])
+        ->where('id in (' . $ids . ')')
+        ->asArray()
+        ->all();
+
+        $spreadsheet = new Spreadsheet();
+        //表头
+        $spreadsheet->setActiveSheetIndex(0)->mergeCells('A1:L1');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1','美国店退货收货详情统计表');
+
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('A2','序号');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('B2','收货日期');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('C2','退回货运');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('D2','收到单号');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('E2','网站');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('F2','订单号');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('G2','订单编号');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('H2','客户名');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('I2','原订单货物详情');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('J2','货品详情');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('K2','完好程度/使用情况');
+        $spreadsheet->setActiveSheetIndex(0)->setCellValue('L2','备注');
+        $i=1;
+        $usageType=['1' => "可用-请加库存",'2'=>'不可用-退回工厂','3'=>'精打理-退回国内','4'=>'精打理-留美仓','5'=>'泡发-发回国内'];
+        $deliveryType=['1' =>'USPS','2'=>'UPS','3'=>'FedEx','4'=>'客人到店退货','5'=>'DHL' ];
+        foreach($orders as $item){
+            // if(isset($usageType[$item['usage']])){
+                $delivery=isset($deliveryType[$item['delivery']])?$deliveryType[$item['delivery']]:$item['delivery'];
+                $usage=isset($usageType[$item['usage']])?$usageType[$item['usage']]:$item['usage'];
+                
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('A'.($i+2),$i);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('B'.($i+2),date('Y-m-d',$item['receiptdate']));
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('C'.($i+2),$delivery);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('D'.($i+2),$item['deliveryid']);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('E'.($i+2),$item['website']);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('F'.($i+2),'');
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('G'.($i+2),'');
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('H'.($i+2),$item['customer']);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('I'.($i+2),$item['origin_goodsinfo']);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('J'.($i+2),$item['goodsinfo']);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('K'.($i+2),$usage);
+                $spreadsheet->setActiveSheetIndex(0)->setCellValue('L'.($i+2),$item['mark']);
+            // }
+            $i++;
+        }
+
+       
+        $spreadsheet->getActiveSheet()->setTitle('美国店退货');
+        // 
+        // Set active sheet index to the first sheet, so Excel opens this as the first sheet
+        $spreadsheet->setActiveSheetIndex(0);
+        $filename=($shop==1 ? "美国仓":"亚马逊")."退货订单".date("Ymd").".xlsx";
+        // Redirect output to a client’s web browser (Xlsx)
+        // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        // header('Content-Disposition: attachment;filename="'.$filename.'"');
+        // header('Cache-Control: max-age=0');
+        // // If you're serving to IE 9, then the following may be needed
+        // header('Cache-Control: max-age=1');
+        
+        // // If you're serving to IE over SSL, then the following may be needed
+        // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
+        // header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
+        // header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
+        // header('Pragma: public'); // HTTP/1.0
+        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
+        ob_start();
+       $writer->save('php://output');
+       $xlsData = ob_get_contents();
+        ob_end_clean();
+        $response =  array(
+            'op' => 'ok',
+            'file' => "data:application/vnd.ms-excel;base64,".base64_encode($xlsData)
+        );
+    
+    die(json_encode($response));
+
+
     }
 
     /**

+ 22 - 1
views/site/index.php

@@ -67,7 +67,8 @@ $this->params['breadcrumbs'][] = $this->title;
                 'class'=>CheckboxColumn::className(),
                 'name'=>'id',
                 'headerOptions' => ['width'=>'30'],
-                'footer' => '<button href="#" class="btn btn-default btn-xs btn-delete" url="'. Url::toRoute('site/delete-all') .'">批量删除</button>',
+                'footer' => '<button href="#" class="btn btn-default btn-xs btn-delete" url="'. Url::toRoute('site/delete-all') .'">批量删除</button>
+                <button href="#" class="btn btn-default btn-xs btn-export" style="margin: 0px 20px;"  url="'. Url::toRoute('site/order-export') .'">批量导出</button>',
                 'footerOptions' => ['colspan' => 5],
             ],
             ['attribute' => 'id', 'footerOptions' => ['class'=>'hide']],
@@ -111,6 +112,7 @@ $this->params['breadcrumbs'][] = $this->title;
 
 
 </div>
+
 <?php
 $script = <<< js
     $(".btn-delete").on("click", function(){
@@ -126,6 +128,25 @@ $script = <<< js
            }
         });
     });
+    $(".btn-export").on("click", function(){
+        var ids = $("#grid").yiiGridView("getSelectedRows");
+        var self = $(this);
+        if(ids.length == 0) return false;
+        $.ajax({
+           url:self.attr("url"),
+           type:"post",
+           data:{id:ids},
+           dataType:'json',
+           success:function(res){
+                var a = document.createElement("a");
+                a.href = res.file; 
+                a.download = '美国店退货订单.xlsx';
+                document.body.appendChild(a);
+                a.click();
+                a.remove();
+           }
+        });
+    });
 js;
 
 $this->registerJs($script);