a订单导出
This commit is contained in:
parent
a5e82074a8
commit
67dd4ea4fb
65
app/Exports/BusinessAfterOrderExport.php
Normal file
65
app/Exports/BusinessAfterOrderExport.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\DailyReport;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Illuminate\Support\Collection;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class BusinessAfterOrderExport implements FromCollection, ShouldAutoSize
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($orders)
|
||||
{
|
||||
$this->data = $this->createData($orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return new Collection($this->data);
|
||||
}
|
||||
|
||||
|
||||
private function createData($orders)
|
||||
{
|
||||
$headTitle = [
|
||||
'父订单编号',
|
||||
'店铺名称',
|
||||
'退款金额',
|
||||
'用户申请退运费金额',
|
||||
'退款原因',
|
||||
'描述',
|
||||
'图片链接',
|
||||
'售后单状态',
|
||||
'售后单创建时间',
|
||||
];
|
||||
$bodyData = [];
|
||||
foreach ($orders as $order) {
|
||||
$productInfo = "";
|
||||
foreach ($order['items'] as $item) {
|
||||
$productInfo .= $item['goods_name'] . "|" . $item['goods_number'] . ",";
|
||||
}
|
||||
rtrim($productInfo, ",");
|
||||
$bodyData[] = [
|
||||
$order['order_sn'],
|
||||
$order['shop']['name'],
|
||||
bcdiv($order['refund_amount'],100,2),
|
||||
bcdiv($order['refund_shipping_amount'],100,2),
|
||||
$order['description'],
|
||||
implode(",",$order['image_list']),
|
||||
$order['cancel_status'],
|
||||
$order['after_sale_created_at']
|
||||
];
|
||||
}
|
||||
|
||||
return [$headTitle, $bodyData];
|
||||
}
|
||||
}
|
||||
68
app/Exports/BusinessOrderExport.php
Normal file
68
app/Exports/BusinessOrderExport.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\DailyReport;
|
||||
use App\Models\Shop;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Illuminate\Support\Collection;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class BusinessOrderExport implements FromCollection, ShouldAutoSize
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($orders)
|
||||
{
|
||||
$this->data = $this->createData($orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return new Collection($this->data);
|
||||
}
|
||||
|
||||
|
||||
private function createData($orders)
|
||||
{
|
||||
$headTitle = [
|
||||
'订单id/编号',
|
||||
'商品信息|个数',
|
||||
'店铺名称',
|
||||
'跟团号',
|
||||
'收件人',
|
||||
'收件地址',
|
||||
'下单时间',
|
||||
'发货状态',
|
||||
'订单状态',
|
||||
'售后状态',
|
||||
];
|
||||
$bodyData = [];
|
||||
foreach ($orders as $order) {
|
||||
$productInfo = "";
|
||||
foreach ($order['items'] as $item) {
|
||||
$productInfo .= $item['goods_name']. "|" . $item['goods_number'] . ",";
|
||||
}
|
||||
rtrim($productInfo, ",");
|
||||
$bodyData[] = [
|
||||
$order['id'] . "/" . $order['order_sn'],
|
||||
$productInfo,
|
||||
$order['shop']['name'],
|
||||
$order['is_supplier'].":".$order['participate_no'],
|
||||
$order['receiver_name'],
|
||||
$order['receiver_address_province']." ". $order['receiver_address_city']." ".$order['receiver_address_district']." ".$order['receiver_address_detail'],
|
||||
$order['confirm_at'],
|
||||
$order['shipping_status'],
|
||||
$order['cancel_status'],
|
||||
$order['after_sales_status']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
return [$headTitle, $bodyData];
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Business;
|
||||
|
||||
use App\Exports\BusinessOrderExport;
|
||||
use App\Exports\OrderBlankExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BusinessAfterSaleOrder;
|
||||
@ -32,9 +33,30 @@ class BusinessAfterSaleOrderController extends Controller
|
||||
$builder = $builder->whereBetween("after_sale_created_at"
|
||||
, [$request->created_at_start, $request->created_at_end]);
|
||||
}
|
||||
if ($request->get("is_export")) {
|
||||
$params = $request->validate([
|
||||
'created_at_start' => 'required',
|
||||
'created_at_end' => 'required',
|
||||
], [
|
||||
'created_at_start.required' => '请输入开始确认时间',
|
||||
'created_at_end.required' => '请输入结束确认时间',
|
||||
]);
|
||||
$startDate = Carbon::parse($params['created_at_start']);
|
||||
$endDate = Carbon::parse($params['created_at_end']);
|
||||
|
||||
if ($endDate->gt($startDate->copy()->addMonth())) {
|
||||
throw new \Exception("导出时间超出一个月");
|
||||
}
|
||||
|
||||
return Excel::download(new BusinessOrderExport($builder->get()->toArray())
|
||||
, $startDate . '~' . $endDate . "售后订单数据" . '.xlsx');
|
||||
}
|
||||
$businessOrders = $builder->orderByDesc('after_sale_created_at')
|
||||
->paginate($request->get('per_page'));
|
||||
$businessOrders->getCollection()->map(function ($v) {
|
||||
$v->refund_amount = bcdiv($v->refund_amount,100,2);
|
||||
$v->refund_shipping_amount = bcdiv($v->refund_shipping_amount,100,2);
|
||||
});
|
||||
|
||||
return JsonResource::collection($businessOrders);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Business;
|
||||
|
||||
use App\Exports\BusinessOrderExport;
|
||||
use App\Exports\OrderBlankExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BusinessOrder;
|
||||
@ -35,6 +36,24 @@ class BusinessOrderController extends Controller
|
||||
$ids = BusinessOrderItem::query()->whereIn('external_sku_id', $externalSkuIds)->pluck('business_order_id');
|
||||
$builder->whereIn('id', $ids);
|
||||
}
|
||||
|
||||
if($request->get("is_export")){
|
||||
$params = $request->validate([
|
||||
'confirm_at_start' => 'required',
|
||||
'confirm_at_end' => 'required',
|
||||
], [
|
||||
'confirm_at_start.required' => '请输入开始确认时间',
|
||||
'confirm_at_end.required' => '请输入结束确认时间',
|
||||
]);
|
||||
$startDate = Carbon::parse($params['confirm_at_start']);
|
||||
$endDate = Carbon::parse($params['confirm_at_end']);
|
||||
|
||||
if ($endDate->gt($startDate->copy()->addMonth())) {
|
||||
throw new \Exception("导出时间超出一个月");
|
||||
}
|
||||
|
||||
return Excel::download(new BusinessOrderExport($builder->get()->toArray()), $startDate . '~' . $endDate."订单数据" . '.xlsx');
|
||||
}
|
||||
$businessOrders = $builder->orderByDesc('confirm_at')
|
||||
->paginate($request->get('per_page'));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user