xxxrrrdddd il y a 3 ans
Parent
commit
23e69f920c

+ 20 - 0
application/common/service/MobileOrderExport.php

@@ -0,0 +1,20 @@
+<?php
+namespace app\common\service;
+
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
+class MobileOrderExport{
+    public static function export($list){
+        $excel=new Spreadsheet();
+        $sheet=$excel->getActiveSheet();
+        $sheet->setCellValue("A1",'订购商品');
+        $sheet->setCellValue("A2",'订单号');
+        $sheet->getColumnDimension('A')->setAutoSize(true);
+        $xlsx=new Xlsx($excel);
+        $xlsx->save('php://output');
+        return response()
+            ->data('')
+            ->contentType('application/vnd.ms-excel');
+    }
+}

+ 16 - 2
application/sub/controller/Order.php

@@ -7,6 +7,7 @@ use app\common\library\MobileConstant;
 use app\common\model\Attachment;
 use app\common\model\Mobile;
 use app\common\model\MobileOrder;
+use app\common\service\MobileOrderExport;
 use app\common\service\Refund;
 use app\common\service\SmsSend;
 use app\common\validate\RefundValidate;
@@ -48,13 +49,26 @@ class Order extends SubCommon
     }
     public function index(){
         $data=input();
+        $page=input('page',1);
+        $limit=input('limit',15);
+        $export=input('export');
         $model=new MobileOrder();
 
+        if(!empty($data['order_no'])){
+            $model->where('order_no',$data['order_no']);
+        }
+
         $list=$model
             ->with(['info'])
             ->where('s_id',$this->auth->id)
-            ->order('id','desc')
-            ->paginate();
+            ->order('id','desc');
+
+        $list=$list->paginate($limit,false);
+
+        if($export){
+            return MobileOrderExport::export($list);
+        }
+
         $this->assign('list',$list);
         $this->assign('pay_type',$model::$payTypes);
         $this->assign('status',$model::$status);

+ 12 - 0
application/sub/view/order/index.html

@@ -6,8 +6,15 @@
 <blockquote class="layui-elem-quote news_search">
     <form method="get" action="">
         <div class="layui-inline">
+            <label>订单号</label>
+            <div class="layui-input-inline">
+                <input type="text" class="layui-input" placeholder="订单号" name="order_no" value="{:input('order_no')}"/>
+            </div>
+        </div>
+        <div class="layui-inline">
             <button class="layui-btn search_btn">查询</button>
             <button class="layui-btn reset-btn" type="button">重置</button>
+            <button class="layui-btn layui-btn-primary export-btn" type="button">导出</button>
         </div>
     </form>
 </blockquote>
@@ -65,6 +72,7 @@
         {/foreach}
         </tbody>
     </table>
+    <form id="exportForm" target="_blank"><input type="hidden" name="export" value="1"></form>
 </div>
 <div id="page">
     <span style="float: left">共 {$list->total()} 条记录</span>
@@ -123,6 +131,10 @@
         $('.reset-btn').click(function (){
             location.replace(location.pathname)
         })
+        $('.export-btn').click(()=>{
+            $('#exportForm').attr('action',location.href)
+            $('#exportForm').submit()
+        })
     })
 
 </script>