Browse Source

总后台-订单列表-新增-导出

sunxbiao 1 year ago
parent
commit
be73ba4e76

+ 6 - 2
app/common/repositories/store/order/StoreOrderRepository.php

@@ -4998,7 +4998,7 @@ class StoreOrderRepository extends BaseRepository
4998 4998
      * @return array
4999 4999
      * @author Qinii
5000 5000
      */
5001
-    public function merchantGetList(array $where, $page, $limit)
5001
+    public function merchantGetList(array $where, $page, $limit, $is_excel = 0)
5002 5002
     {
5003 5003
         $status = $where['status'];
5004 5004
         unset($where['status']);
@@ -5028,7 +5028,11 @@ class StoreOrderRepository extends BaseRepository
5028 5028
 
5029 5029
 
5030 5030
         $count = $query->where('test_order', 0)->count();
5031
-        $list = $query->page($page, $limit)->order('order_id desc')->where('test_order', 0)->select();
5031
+        if ($is_excel) {
5032
+            $list = $query->order('order_id desc')->where('test_order', 0)->select();
5033
+        } else {
5034
+            $list = $query->page($page, $limit)->order('order_id desc')->where('test_order', 0)->select();
5035
+        }
5032 5036
 
5033 5037
         $productId = $query->where($this->getOrderType($status))->column('order_id');
5034 5038
         $make = app()->make(StoreRefundOrderRepository::class);

+ 78 - 1
app/controller/admin/order/Order.php

@@ -14,6 +14,7 @@ use crmeb\basic\BaseController;
14 14
 use app\common\repositories\store\ExcelRepository;
15 15
 use app\common\repositories\system\merchant\MerchantRepository;
16 16
 use app\common\repositories\store\order\StoreOrderRepository as repository;
17
+use crmeb\services\SpreadsheetExcelService;
17 18
 use think\App;
18 19
 use think\facade\Db;
19 20
 
@@ -73,9 +74,85 @@ class Order extends BaseController
73 74
             $where['mer_id']=496;
74 75
             $where['pay_type']=5;
75 76
         }
76
-        return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
77
+        // 导出
78
+        $is_excel = request()->param('is_excel', 0);
79
+
80
+        $result = $this->repository->merchantGetList($where, $page, $limit);
81
+
82
+        if ($is_excel == 1) {
83
+            $data = $result['list'];
84
+            $arr = [];
85
+            foreach ($data as $item) {
86
+                $arr[] = [
87
+                    $item['order_sn'], // 订单编号
88
+                    $item['order_type'] == 0 ? "普通订单" : "核销订单", // 订单类型
89
+                    $item['user']['nickname'] ?? '', // 用户昵称
90
+                    $item['user']['phone'] ?? '', // 用户手机号
91
+                    $item['real_name'], // 收货人
92
+                    $item['merchant']['mer_name'] ?? '', // 商户名称
93
+                    $item['orderProduct'][0]['cart_info']['product']['image'],
94
+                    $item['orderProduct'][0]['cart_info']['product']['store_name'] . ' | ' . $item['orderProduct'][0]['cart_info']['productAttr']['sku'],
95
+                    $item['orderProduct'][0]['cart_info']['productAttr']['price'],
96
+                    $item['orderProduct'][0]['product_num'],
97
+                    $item['pay_price'], // 订单金额
98
+                    $item['fzone_pay_note'], // 支付方式
99
+                    $item['paid'] == 0 ? "未支付" : "已支付", // 支付状态
100
+                    $item['is_del'] == 0 ? ($item['status'] == 5 ? '待付款' : ($item['status'] == 0 ? '待发货' : ($item['status'] == 1 ? '待收货' : ($item['status'] == 2 ? '待评价' : ($item['status'] == 3 ? '已完成' : ($item['status'] == 4 ? '已申请退款' : ($item['status'] == -1 ? '已退款' : ($item['status'] == 6 ? '已取消' : '')))))))) : '已删除', // 订单状态
101
+                    $item['create_time'], // 下单时间
102
+                ];
103
+            }
104
+            return app('json')->success($this->getStatisticsExcel([
105
+                '订单编号',
106
+                '订单类型',
107
+                '用户昵称',
108
+                '用户手机号',
109
+                '收货人',
110
+                '商户名称',
111
+                '商品图片',
112
+                '商品名称',
113
+                '商品单价',
114
+                '商品数量',
115
+                '订单金额',
116
+                '支付方式',
117
+                '支付状态',
118
+                '订单状态',
119
+                '下单时间'
120
+            ], $arr, '订单明细'));
121
+        }
122
+        return app('json')->success($result);
123
+    }
124
+    /**
125
+     * 获取统计导出
126
+     */
127
+    public function getStatisticsExcel($header,$arr,$title)
128
+    {
129
+        $filename = $title.'_'.date('YmdHis').'_'.rand(10000,99999);
130
+        $name = $filename;
131
+        $info = '生成时间:' . date('Y-m-d H:i:s',time());
132
+        $suffix='xlsx';
133
+        $path='extract';
134
+        unset($_instance);
135
+
136
+        $_instance = SpreadsheetExcelService::instance_xin();
137
+
138
+        $_path =$_instance
139
+            ->createOrActive()
140
+            ->setExcelHeader($header)
141
+            ->setExcelTile($title, $name, $info)
142
+            ->setExcelContent($arr)
143
+            ->excelSave($filename, $suffix, $path);
144
+
145
+        $domain = request()->domain();
146
+        $data= [
147
+            'name' => $filename.'.'.$suffix,
148
+            'status' => 1,
149
+            'path' => $domain.'/'.$_path
150
+        ];
151
+
152
+        return $data;
77 153
     }
78 154
 
155
+
79 156
     /**
80 157
      * TODO 自提订单列表
81 158
      * @return mixed