作者 何书鹏

售后单导出

... ... @@ -2,6 +2,7 @@
namespace app\admin\controller\shopro\order;
use addons\shopro\library\Export;
use addons\shopro\model\OrderAftersaleLog;
use app\admin\model\shopro\order\Order;
use app\admin\model\shopro\order\OrderItem;
... ... @@ -398,7 +399,7 @@ class Aftersale extends Backend
}
// 申请时间
if ($createtime) {
if ($createtime && array_filter($createtime)) {
$sym = 'BETWEEN';
if ($createtime[0] === '') {
$sym = '<=';
... ... @@ -480,4 +481,71 @@ class Aftersale extends Backend
return $aftersales;
}
public function export()
{
$export = new Export();
$sort = $this->request->get("sort", !empty($this->model) && $this->model->getPk() ? $this->model->getPk() : 'id');
$order = $this->request->get("order", "DESC");
$offset = $this->request->get("offset", 0);
$limit = $this->request->get("limit", 0);
$search = $this->request->get("search", ''); // 关键字
$status = $this->request->get("status", 'all');
$list = $this->buildSearchOrder() // 返回的是 orderModel
->with(['aftersale' => function ($query) {
$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');
}])
->order($sort, $order)
->select();
// 经销商
$dealer = [];
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$dealer = \app\admin\model\dealer\Dealer::where('admin_id',$this->auth->id)->find();
}
$expCellName = [
'aftersale_id' => 'Id',
'order_sn' => '订单号',
'goods_title' => '商品名称',
'goods_sku_text' => '规格',
'activity_type_text' => '订单来源',
'user_info' => '用户信息',
'aftersale_sn' => '售后单号',
'refund_fee' => '退款金额',
'aftersale_status_text' => '处理状态',
'type_text' => '售后类型',
'createtime' => '申请时间',
];
$newList = [];
foreach ($list as $key => $order) {
foreach ($order['aftersale'] as $k => $after) {
$data = [
'aftersale_id' => $after['id'],
'order_sn' => $order['order_sn'],
'goods_title' => $after['goods_title'],
'goods_sku_text' => $after['goods_sku_text'],
'activity_type_text' => $after['activity_type_text'],
'user_info' => $after['user_nickname'] ? $after['user_nickname'] : '',
'aftersale_sn' => $after['aftersale_sn'],
'refund_fee' => $after['refund_fee'],
'aftersale_status_text' => $after['aftersale_status_text'],
'type_text' => $after['type_text'],
'createtime' => date('Y-m-d H:i:s',$after['createtime']),
];
$newList[] = $data;
}
}
// 增加合计
$newList[] = [
'aftersale_id' => "售后总数:" . count($newList) . ";退款总金额:¥" . array_sum(array_column($newList, 'refund_fee'))
];
$export->exportExcel('售后/退款列表-' . date('Y-m-d H:i:s'), $expCellName, $newList);
}
}
... ...
... ... @@ -258,6 +258,9 @@
text-align: center;
cursor: pointer;
}
.cursor-pointer {
cursor: pointer;
}
[v-cloak] {
display: none
... ... @@ -296,7 +299,7 @@
end-placeholder="结束日期" @change="reqOrderList(0,10)">
</el-date-picker>
</div>
<!-- <div class="common-btn cursor-pointer" @click="goExport">导出</div>-->
<div class="common-btn cursor-pointer" @click="goExport">导出</div>
</div>
<div class="custom-table-container">
<el-table :data="pageData" style="width: 100%" default-expand-all="true" border :span-method="arraySpanMethod">
... ...