xieruidong 2 years ago
parent
commit
9f1c5a0a7c

+ 2 - 1
application/admin/controller/Orders.php

@@ -61,7 +61,7 @@ class Orders extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
             $filter=json_decode(input('filter'));
             $list = $this->model
-                ->with(['user','logistics','voucher','admin'])
+                ->with(['user','logistics','voucher','admin','info'])
                     ->where($where)
                 ->where(function (Query $query){
                     if($this->admin('is_seller')){
@@ -76,6 +76,7 @@ class Orders extends Backend
             }*/
 
             $result = array("total" => $list->total(), "rows" => $list->items(),'filter'=>$filter);
+            $result['link']=$this->request->url().'&export=1';
 
             return json($result);
         }

+ 2 - 1
application/admin/view/orders/index.html

@@ -16,7 +16,8 @@
                 <div class="widget-body no-padding">
                     <div id="toolbar" class="toolbar">
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
-<!--                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('orders/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+<!--                        <a href="javascript:;" target="_blank" class="btn btn-success btn-export {:$auth->check('orders/index')?'':'hide'}" title="{:__('导出')}" ><i class="fa fa-exchange"></i> {:__('导出')}</a>
+&lt;!&ndash;                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('orders/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
                         <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('orders/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
                         <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('orders/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
                         <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('orders/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>

+ 79 - 0
application/common/service/OrderExport.php

@@ -0,0 +1,79 @@
+<?php
+namespace app\common\service;
+
+use app\common\model\Orders;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
+class OrderExport{
+    public static function export($list){
+        $excel=new Spreadsheet();
+        $header=[
+            [
+                'name'=>'ID',
+                'value'=>function($model){
+                    return $model['id'];
+                },
+            ],
+            [
+                'name'=>'订单号',
+                'value'=>function($model){
+                    return $model['order_no'];
+                },
+            ],
+            [
+                'name'=>'状态',
+                'value'=>function($model){
+                    return Orders::getStatus()[$model['status']];
+                },
+            ],
+            [
+                'name'=>'下单用户',
+                'value'=>function($model){
+                    return $model['user']['nickname'];
+                },
+            ],
+            [
+                'name'=>'商品信息',
+                'value'=>function($model){
+                    $goods=[];
+                    foreach ($model['info'] as $info){
+                        $goods[]="商品:{$info['goods_name']},规格:{$info['sku_name']},数量:{$info['num']},安装量:{$info['num_install']},金额:{$info['amount_pay']}";
+                    }
+                    return implode("\n",$goods);
+                },
+            ],
+        ];
+        $headers=[];
+        foreach ($header as $value){
+            if(is_callable($value['value']) && self::visible($value)){
+                $headers[]=$value;
+            }
+        }
+        $sheet=$excel->getActiveSheet();
+        $headerPoint='A';
+        foreach ($headers as $key=>$value){
+            $sheet->setCellValue(sprintf("%s%d",$headerPoint,1),$value['name']);
+            $vk=2;
+            foreach ($list as $_key=>$_value){
+                $val=$value['value']($_value);
+                $sheet->setCellValueExplicit(sprintf("%s%d", $headerPoint, $vk), $val,DataType::TYPE_STRING);
+                $vk++;
+            }
+            $headerPoint++;
+        }
+
+        $sheet->getColumnDimension('A')->setAutoSize(true);
+        $xlsx=new Xlsx($excel);
+        header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
+        $xlsx->save('php://output');
+        return response()
+            ->data('')
+            ->contentType('application/vnd.ms-excel');
+    }
+
+    protected static function visible($item){
+        return empty($item['hidden']) || !$item['hidden'];
+    }
+}

+ 14 - 1
public/assets/js/backend/orders.js

@@ -36,6 +36,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             return Table.api.formatter.status.call(this,status,order,index)
                         },searchList:status},
                         {field: 'user.nickname', title: __('下单用户')},
+                        {field: 'info', title: __('商品信息'),operate: false,formatter(info, order, index) {
+                                let a=[];
+                                info.forEach(item=>{
+                                    a.push(`<div class="">商品:${item.goods_name},规格:${item.sku_name},数量:${item.num},安装量:${item.num_install},金额:${item.amount_pay}</div>`)
+                                })
+                                return Table.api.formatter.content.call(this,a.join('<br/>'),order,index)
+                            }},
                         {field: 'amount_total', title: __('Amount_total'), operate:'BETWEEN'},
                         {field: 'amount_pay', title: __('Amount_pay'), operate:'BETWEEN'},
                       /*  {field: 'amount_install', title: __('Amount_install'), operate:'BETWEEN'},
@@ -137,9 +144,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 },
                             ]}
                     ]
-                ]
+                ],
+                onLoadSuccess(a) {
+                    $('.btn-export').attr('href',a.link)
+                }
             });
 
+            $('.btn-export').click(function (){
+
+            })
             // 为表格绑定事件
             Table.api.bindevent(table);
         },