From ffbb8e0c18238750d4ac0ffbee082043492ff021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=84=E6=A2=A6=E5=AE=81?= Date: Tue, 6 Oct 2020 17:07:17 +0800 Subject: [PATCH] checkredis --- .../admin/controller/unishop/market/FlashSale.php | 65 +++++++++++++++++++++ application/admin/view/user/user/index.html | 1 + .../assets/js/backend/unishop/market/flash_sale.js | 11 ++++ public/assets/js/backend/unishop/order.js | 62 +++++++++++--------- public/uploads/file/员工账号导入模板.xls | Bin 0 -> 17920 bytes 5 files changed, 110 insertions(+), 29 deletions(-) create mode 100644 public/uploads/file/员工账号导入模板.xls diff --git a/application/admin/controller/unishop/market/FlashSale.php b/application/admin/controller/unishop/market/FlashSale.php index 5fe4df4..37c027d 100644 --- a/application/admin/controller/unishop/market/FlashSale.php +++ b/application/admin/controller/unishop/market/FlashSale.php @@ -500,4 +500,69 @@ class FlashSale extends Backend } $this->error(__('Parameter %s can not be empty', 'ids')); } + + public function export(){ + $id=input("id"); + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $title1=["商品名称","件数","单价","总价"]; + $product=new \app\admin\model\unishop\OrderProduct(); + $product_list = $product->alias("p") + ->join("unishop_order","p.order_id = unishop_order.id") + ->where([ + 'p.flash_id'=>$id + ]) + ->field(' + p.title, + SUM(p.number) num, + p.price, + SUM(p.number)*p.price as total, + p.product_id') + ->group("p.id") + ->select(); + $product_list = collection($product_list)->toArray(); + $product_arr=[]; + foreach ($product_list as $tmp_product){ + if (isset($product_arr[$tmp_product['product_id']])){ + $product_arr[$tmp_product['product_id']]["num"]+=$tmp_product['num']; + $product_arr[$tmp_product['product_id']]["total"]+=$tmp_product['total']; + }else{ + $product_arr[$tmp_product['product_id']]=$tmp_product; + } + } + + foreach ($title1 as $key => $value) { + // 单元格内容写入 + $sheet->setCellValueByColumnAndRow($key + 1, 1, $value); + } + $row=2; + foreach ($product_arr as $item) { + unset($item['product_id']); + $column = 1; + foreach ($item as $value) { + // 单元格内容写入 + $sheet->setCellValueByColumnAndRow($column, $row, $value); + $column++; + } + $row++; + } + + $file_name="导出活动统计.xlsx"; + // Redirect output to a client’s web browser (Xlsx) + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename='.$file_name); + 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 = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer->save('php://output'); + exit; + } } diff --git a/application/admin/view/user/user/index.html b/application/admin/view/user/user/index.html index c63e4a6..7dae879 100644 --- a/application/admin/view/user/user/index.html +++ b/application/admin/view/user/user/index.html @@ -7,6 +7,7 @@
{:build_toolbar('refresh,edit,del,import')} + {:__('下载')}