导出修改
This commit is contained in:
parent
b4c2c91557
commit
28cfc0384f
@ -2,13 +2,18 @@
|
||||
|
||||
namespace App\Domains\Virtual\Exports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Core\AbstractExport;
|
||||
use Dipper\Excel\Concerns\WithRows;
|
||||
use Dipper\Excel\Concerns\FromQuery;
|
||||
use Dipper\Excel\Concerns\WithHeadings;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
use Dipper\Excel\Concerns\WithColumnFormatting;
|
||||
use App\Domains\Virtual\Services\CompanyService;
|
||||
use App\Domains\Virtual\Services\PackageService;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
use App\Dicts;
|
||||
|
||||
class OrderCardExport extends AbstractExport implements FromQuery, WithHeadings, WithRows, WithColumnFormatting
|
||||
{
|
||||
@ -22,19 +27,36 @@ class OrderCardExport extends AbstractExport implements FromQuery, WithHeadings,
|
||||
|
||||
public function query()
|
||||
{
|
||||
$builder = app(OrderCardPartitionRepository::class)->forceNoReset()->select(['sim', 'counts', 'refunded_at'])
|
||||
->withConditions($this->conditions)->orderBy('sim');
|
||||
$builder = app(OrderCardPartitionRepository::class)->with('order')->forceNoReset()->select(['sim', 'order_id', 'counts', 'refunded_at'])
|
||||
->withConditions($this->conditions)->orderBy('order_id');
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
$headings = [
|
||||
'订单编号',
|
||||
'企业名称',
|
||||
'运营商',
|
||||
'套餐名称',
|
||||
'套餐单价',
|
||||
'支付方式',
|
||||
'支付流水号',
|
||||
'订单时间',
|
||||
'SIM',
|
||||
'数量',
|
||||
'退货',
|
||||
];
|
||||
|
||||
if ($this->conditions['type'] == 0) {
|
||||
array_splice($headings, 6, 0, [
|
||||
'订单状态',
|
||||
// '收款状态',
|
||||
]);
|
||||
}
|
||||
|
||||
return $headings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,12 +68,35 @@ class OrderCardExport extends AbstractExport implements FromQuery, WithHeadings,
|
||||
{
|
||||
$array = [];
|
||||
|
||||
$carrierOperators = app(Dicts::class)->get('carrier_operator');
|
||||
$orderStatues = app(Dicts::class)->get('order_status');
|
||||
$transactionStatuses = app(Dicts::class)->get('transaction_status');
|
||||
|
||||
foreach ($rows as $item) {
|
||||
$array[] = [
|
||||
$item['sim'],
|
||||
$carrier_operator = PackageService::load($item['order']['package_id'])['carrier_operator'];
|
||||
|
||||
$data = [
|
||||
"{$item['order']['sn']}\t",
|
||||
CompanyService::load($item['order']['company_id'])['name'] ?? '',
|
||||
$carrierOperators[$carrier_operator],
|
||||
PackageService::load($item['order']['package_id'])['name'] ?? '',
|
||||
sprintf('%.02f', $item['order']['unit_price']/100),
|
||||
CommonService::namePayChannel($item['order']['pay_channel']),
|
||||
"{$item['order']['transaction_no']}\t",
|
||||
Carbon::parse($item['order']['order_at'])->format('Y-m-d'),
|
||||
"{$item['sim']}\t",
|
||||
$item['counts'],
|
||||
$item['refunded_at'] ? '是' : '',
|
||||
];
|
||||
|
||||
if ($this->conditions['type'] == 0) {
|
||||
array_splice($data, 6, 0, [
|
||||
$orderStatues[$item['order']['order_status']],
|
||||
// $transactionStatuses[$item['order']['transaction_status']],
|
||||
]);
|
||||
}
|
||||
|
||||
$array[] = $data;
|
||||
}
|
||||
|
||||
return $array;
|
||||
@ -63,8 +108,7 @@ class OrderCardExport extends AbstractExport implements FromQuery, WithHeadings,
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'A' => NumberFormat::FORMAT_NUMBER,
|
||||
'B' => NumberFormat::FORMAT_NUMBER,
|
||||
'E' => NumberFormat::FORMAT_NUMBER_00,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Domains\Virtual\Exports;
|
||||
|
||||
use App\Dicts;
|
||||
use Carbon\Carbon;
|
||||
use App\Core\AbstractExport;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Dipper\Excel\Concerns\WithRows;
|
||||
use Dipper\Excel\Concerns\FromQuery;
|
||||
use Dipper\Excel\Concerns\WithHeadings;
|
||||
@ -12,8 +14,8 @@ use Dipper\Excel\Concerns\WithColumnFormatting;
|
||||
use App\Domains\Virtual\Services\CompanyService;
|
||||
use App\Domains\Virtual\Services\PackageService;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use App\Domains\Virtual\Repositories\OrderRepository;
|
||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||
use App\Dicts;
|
||||
|
||||
class OrderExport extends AbstractExport implements FromQuery, WithHeadings, WithRows, WithColumnFormatting
|
||||
{
|
||||
@ -21,14 +23,17 @@ class OrderExport extends AbstractExport implements FromQuery, WithHeadings, Wit
|
||||
|
||||
public function __construct(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['sim'])) {
|
||||
$conditions['sim'] = array_map('intval', array_map('trim', str_to_array($conditions['sim'], "\n")));
|
||||
}
|
||||
|
||||
$this->conditions = $conditions;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
$builder = app(OrderCardPartitionRepository::class)->with('order')->forceNoReset()->select(['sim', 'order_id', 'counts', 'refunded_at'])
|
||||
->withConditions($this->conditions)->orderBy('order_id');
|
||||
$builder = app(OrderRepository::class)->forceNoReset()->withConditions($this->conditions)->applyConditions()->orderBy('order_at', 'desc');
|
||||
|
||||
return $builder;
|
||||
}
|
||||
@ -43,19 +48,21 @@ class OrderExport extends AbstractExport implements FromQuery, WithHeadings, Wit
|
||||
'套餐单价',
|
||||
'支付方式',
|
||||
'支付流水号',
|
||||
'订单量',
|
||||
'订单金额',
|
||||
'订单时间',
|
||||
'SIM',
|
||||
'数量',
|
||||
'退货',
|
||||
];
|
||||
|
||||
if ($this->conditions['type'] == 0) {
|
||||
array_splice($headings, 6, 0, [
|
||||
array_splice($headings, 8, 0, [
|
||||
'发货量',
|
||||
'退货量',
|
||||
'订单状态',
|
||||
'收款状态',
|
||||
// '收款状态',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return $headings;
|
||||
}
|
||||
|
||||
@ -68,31 +75,41 @@ class OrderExport extends AbstractExport implements FromQuery, WithHeadings, Wit
|
||||
{
|
||||
$array = [];
|
||||
|
||||
$carrierOperators = app(Dicts::class)->get('carrier_operator');
|
||||
$orderStatues = app(Dicts::class)->get('order_status');
|
||||
$transactionStatuses = app(Dicts::class)->get('transaction_status');
|
||||
$orderShipments = app(OrderCardPartitionRepository::class)->select([
|
||||
'order_id',
|
||||
DB::raw('SUM(counts) as counts'),
|
||||
DB::raw('SUM(CASE WHEN refunded_at IS NULL THEN 0 ELSE 1 END) as refunds')
|
||||
])->withConditions([
|
||||
'order_id' => array_pluck($rows, 'id'),
|
||||
])->groupBy('order_id')->get()->keyBy('order_id')->toArray();
|
||||
|
||||
$dicts = app(Dicts::class);
|
||||
$carrierOperators = $dicts->get('carrier_operator');
|
||||
$orderStatues = $dicts->get('order_status');
|
||||
$transactionStatuses = $dicts->get('transaction_status');
|
||||
|
||||
foreach ($rows as $item) {
|
||||
$carrier_operator = PackageService::load($item['order']['package_id'])['carrier_operator'];
|
||||
$carrier_operator = PackageService::load($item['package_id'])['carrier_operator'];
|
||||
|
||||
$data = [
|
||||
"{$item['order']['sn']}\t",
|
||||
CompanyService::load($item['order']['company_id'])['name'] ?? '',
|
||||
"{$item['sn']}\t",
|
||||
CompanyService::load($item['company_id'])['name'] ?? '',
|
||||
$carrierOperators[$carrier_operator],
|
||||
PackageService::load($item['order']['package_id'])['name'] ?? '',
|
||||
sprintf('%.02f', $item['order']['unit_price']/100),
|
||||
CommonService::namePayChannel($item['order']['pay_channel']),
|
||||
"{$item['order']['transaction_no']}\t",
|
||||
Carbon::parse($item['order']['order_at'])->format('Y-m-d'),
|
||||
"{$item['sim']}\t",
|
||||
PackageService::load($item['package_id'])['name'] ?? '',
|
||||
sprintf('%.02f', $item['unit_price']/100),
|
||||
CommonService::namePayChannel($item['pay_channel']),
|
||||
"{$item['transaction_no']}\t",
|
||||
$item['counts'],
|
||||
$item['refunded_at'] ? '是' : '',
|
||||
sprintf('%.02f', $item['custom_price']/100),
|
||||
Carbon::parse($item['order']['order_at'])->format('Y-m-d'),
|
||||
];
|
||||
|
||||
if ($this->conditions['type'] == 0) {
|
||||
array_splice($data, 6, 0, [
|
||||
$orderStatues[$item['order']['order_status']],
|
||||
$transactionStatuses[$item['order']['transaction_status']],
|
||||
array_splice($data, 8, 0, [
|
||||
sprintf('%d', $orderShipments[$item['id']]['counts'] ?? 0),
|
||||
sprintf('%d', $orderShipments[$item['id']]['refunds'] ?? 0),
|
||||
$orderStatues[$item['order_status']],
|
||||
// $transactionStatuses[$item['order']['transaction_status']],
|
||||
]);
|
||||
}
|
||||
|
||||
@ -109,6 +126,10 @@ class OrderExport extends AbstractExport implements FromQuery, WithHeadings, Wit
|
||||
{
|
||||
return [
|
||||
'E' => NumberFormat::FORMAT_NUMBER_00,
|
||||
'H' => NumberFormat::FORMAT_NUMBER,
|
||||
'I' => NumberFormat::FORMAT_NUMBER,
|
||||
'J' => NumberFormat::FORMAT_NUMBER,
|
||||
'L' => NumberFormat::FORMAT_NUMBER_00,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,38 @@ class OrderController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出订单.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
|
||||
if (isset($conditions['sim'])) {
|
||||
$conditions['sim'] = array_map('intval', array_map('trim', str_to_array($conditions['sim'], "\n")));
|
||||
}
|
||||
|
||||
try {
|
||||
$total = app(OrderRepository::class)->withConditions($conditions)->count();
|
||||
|
||||
if ($total > 200000) {
|
||||
throw new NotAllowedException('数据量过大,请筛选后再进行导出');
|
||||
}
|
||||
|
||||
$queue = $total > 30000;
|
||||
|
||||
$export = new OrderExport($conditions);
|
||||
$url = ExportService::store($export, 'public', $queue);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return res($url, '导出成功', 201);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*/
|
||||
@ -195,37 +227,6 @@ class OrderController extends Controller
|
||||
return res(true, '重置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出订单.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
|
||||
if (isset($conditions['sim'])) {
|
||||
$conditions['sim'] = array_map('intval', array_map('trim', str_to_array($conditions['sim'], "\n")));
|
||||
}
|
||||
|
||||
try {
|
||||
$total = app(OrderCardPartitionRepository::class)->withConditions($conditions)->count();
|
||||
|
||||
if ($total > 200000) {
|
||||
throw new NotAllowedException('数据量过大,请筛选后再进行导出');
|
||||
}
|
||||
|
||||
$queue = $total > 30000;
|
||||
|
||||
$export = new OrderExport($conditions);
|
||||
$url = ExportService::store($export, 'public', $queue);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return res($url, '导出成功', 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡清单.
|
||||
*
|
||||
@ -249,9 +250,21 @@ class OrderController extends Controller
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
|
||||
if (isset($conditions['sim'])) {
|
||||
$conditions['sim'] = array_map('intval', array_map('trim', str_to_array($conditions['sim'], "\n")));
|
||||
}
|
||||
|
||||
try {
|
||||
$total = app(OrderCardPartitionRepository::class)->withConditions($conditions)->count();
|
||||
|
||||
if ($total > 200000) {
|
||||
throw new NotAllowedException('数据量过大,请筛选后再进行导出');
|
||||
}
|
||||
|
||||
$queue = $total > 30000;
|
||||
|
||||
$export = new OrderCardExport($conditions);
|
||||
$url = ExportService::store($export, 'public');
|
||||
$url = ExportService::store($export, 'public', $queue);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
@ -140,7 +140,10 @@
|
||||
<Button @click="resetSearch" ghost type="warning">重置搜索</Button>
|
||||
</div>
|
||||
<div class="handle-item" v-has="'output'">
|
||||
<Button @click="exportOrders" type="warning">导出卡表</Button>
|
||||
<Button @click="exportOrders" type="warning">导出订单</Button>
|
||||
</div>
|
||||
<div class="handle-item" v-has="'output'">
|
||||
<Button @click="exportOrderCards" type="warning">导出清单</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -644,6 +644,28 @@ export default {
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
},
|
||||
exportOrderCards() {
|
||||
this.isShowLoading(true);
|
||||
let params = this.parseParams(this.params);
|
||||
params.type = Number(this.$route.params.type);
|
||||
|
||||
API.cardsExport(params).then(res => {
|
||||
this.isShowLoading(false);
|
||||
|
||||
if (res.code === 0) {
|
||||
if (res.data) {
|
||||
this.downloadFile(res.data);
|
||||
} else {
|
||||
this.$Modal.success({
|
||||
title: '提示',
|
||||
content: '当前导出数据量大,已进入后台队列导出模式,请稍后至导出列表查看下载。'
|
||||
});
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* [openEdit 打开编辑弹窗]
|
||||
|
2
public/css/chunk-25e2723d.f18e4df8.css
Normal file
2
public/css/chunk-25e2723d.f18e4df8.css
Normal file
File diff suppressed because one or more lines are too long
2
public/js/app.0a9cab31.js
Normal file
2
public/js/app.0a9cab31.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.0a9cab31.js.map
Normal file
1
public/js/app.0a9cab31.js.map
Normal file
File diff suppressed because one or more lines are too long
2
public/js/chunk-25e2723d.ce806521.js
Normal file
2
public/js/chunk-25e2723d.ce806521.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-25e2723d.ce806521.js.map
Normal file
1
public/js/chunk-25e2723d.ce806521.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-7a0075e3.b9f7c25b.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-7a0075e3.b3690026.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.5a483cca.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.5a483cca.js></script></body></html>
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-25e2723d.f18e4df8.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-25e2723d.ce806521.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.0a9cab31.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.0a9cab31.js></script></body></html>
|
Loading…
x
Reference in New Issue
Block a user