作者 何书鹏

售后单导出

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace app\admin\controller\shopro\order; 3 namespace app\admin\controller\shopro\order;
4 4
  5 +use addons\shopro\library\Export;
5 use addons\shopro\model\OrderAftersaleLog; 6 use addons\shopro\model\OrderAftersaleLog;
6 use app\admin\model\shopro\order\Order; 7 use app\admin\model\shopro\order\Order;
7 use app\admin\model\shopro\order\OrderItem; 8 use app\admin\model\shopro\order\OrderItem;
@@ -398,7 +399,7 @@ class Aftersale extends Backend @@ -398,7 +399,7 @@ class Aftersale extends Backend
398 } 399 }
399 400
400 // 申请时间 401 // 申请时间
401 - if ($createtime) { 402 + if ($createtime && array_filter($createtime)) {
402 $sym = 'BETWEEN'; 403 $sym = 'BETWEEN';
403 if ($createtime[0] === '') { 404 if ($createtime[0] === '') {
404 $sym = '<='; 405 $sym = '<=';
@@ -480,4 +481,71 @@ class Aftersale extends Backend @@ -480,4 +481,71 @@ class Aftersale extends Backend
480 481
481 return $aftersales; 482 return $aftersales;
482 } 483 }
  484 +
  485 + public function export()
  486 + {
  487 + $export = new Export();
  488 +
  489 + $sort = $this->request->get("sort", !empty($this->model) && $this->model->getPk() ? $this->model->getPk() : 'id');
  490 + $order = $this->request->get("order", "DESC");
  491 + $offset = $this->request->get("offset", 0);
  492 + $limit = $this->request->get("limit", 0);
  493 + $search = $this->request->get("search", ''); // 关键字
  494 + $status = $this->request->get("status", 'all');
  495 +
  496 + $list = $this->buildSearchOrder() // 返回的是 orderModel
  497 + ->with(['aftersale' => function ($query) {
  498 + $query->removeOption('soft_delete')->alias('a')->field('a.*, u.nickname as user_nickname, u.mobile as user_mobile')->join('user u', 'u.id = a.user_id', 'LEFT');
  499 + }])
  500 + ->order($sort, $order)
  501 + ->select();
  502 +
  503 + // 经销商
  504 + $dealer = [];
  505 + $group_id_arr = array_column($this->auth->getGroups(), 'group_id');
  506 + if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
  507 + $dealer = \app\admin\model\dealer\Dealer::where('admin_id',$this->auth->id)->find();
  508 + }
  509 +
  510 + $expCellName = [
  511 + 'aftersale_id' => 'Id',
  512 + 'order_sn' => '订单号',
  513 + 'goods_title' => '商品名称',
  514 + 'goods_sku_text' => '规格',
  515 + 'activity_type_text' => '订单来源',
  516 + 'user_info' => '用户信息',
  517 + 'aftersale_sn' => '售后单号',
  518 + 'refund_fee' => '退款金额',
  519 + 'aftersale_status_text' => '处理状态',
  520 + 'type_text' => '售后类型',
  521 + 'createtime' => '申请时间',
  522 + ];
  523 +
  524 + $newList = [];
  525 + foreach ($list as $key => $order) {
  526 + foreach ($order['aftersale'] as $k => $after) {
  527 + $data = [
  528 + 'aftersale_id' => $after['id'],
  529 + 'order_sn' => $order['order_sn'],
  530 + 'goods_title' => $after['goods_title'],
  531 + 'goods_sku_text' => $after['goods_sku_text'],
  532 + 'activity_type_text' => $after['activity_type_text'],
  533 + 'user_info' => $after['user_nickname'] ? $after['user_nickname'] : '',
  534 + 'aftersale_sn' => $after['aftersale_sn'],
  535 + 'refund_fee' => $after['refund_fee'],
  536 + 'aftersale_status_text' => $after['aftersale_status_text'],
  537 + 'type_text' => $after['type_text'],
  538 + 'createtime' => date('Y-m-d H:i:s',$after['createtime']),
  539 + ];
  540 + $newList[] = $data;
  541 + }
  542 + }
  543 +
  544 + // 增加合计
  545 + $newList[] = [
  546 + 'aftersale_id' => "售后总数:" . count($newList) . ";退款总金额:¥" . array_sum(array_column($newList, 'refund_fee'))
  547 + ];
  548 +
  549 + $export->exportExcel('售后/退款列表-' . date('Y-m-d H:i:s'), $expCellName, $newList);
  550 + }
483 } 551 }
@@ -258,6 +258,9 @@ @@ -258,6 +258,9 @@
258 text-align: center; 258 text-align: center;
259 cursor: pointer; 259 cursor: pointer;
260 } 260 }
  261 + .cursor-pointer {
  262 + cursor: pointer;
  263 + }
261 264
262 [v-cloak] { 265 [v-cloak] {
263 display: none 266 display: none
@@ -296,7 +299,7 @@ @@ -296,7 +299,7 @@
296 end-placeholder="结束日期" @change="reqOrderList(0,10)"> 299 end-placeholder="结束日期" @change="reqOrderList(0,10)">
297 </el-date-picker> 300 </el-date-picker>
298 </div> 301 </div>
299 -<!-- <div class="common-btn cursor-pointer" @click="goExport">导出</div>--> 302 + <div class="common-btn cursor-pointer" @click="goExport">导出</div>
300 </div> 303 </div>
301 <div class="custom-table-container"> 304 <div class="custom-table-container">
302 <el-table :data="pageData" style="width: 100%" default-expand-all="true" border :span-method="arraySpanMethod"> 305 <el-table :data="pageData" style="width: 100%" default-expand-all="true" border :span-method="arraySpanMethod">