feat: #10000 订单返回

This commit is contained in:
赵世界 2023-07-28 19:13:51 +08:00
parent e35114f842
commit 2ed22b91b5
2 changed files with 69 additions and 48 deletions

View File

@ -95,61 +95,21 @@ class BusinessOrderController extends Controller
public function exportOrderBlank(Request $request) public function exportOrderBlank(Request $request)
{ {
$shopId = $request->get('shop_id'); $orderIds = $request->get('order_ids');
$startNo = $request->get('start_no');
$endNo = $request->get('end_no');
$isSupplier = $request->get('is_supplier');
$field = 'participate_no';
if ($isSupplier) {
$field = 'supply_participate_no';
}
$startTime = BusinessOrder::query()
->where('shop_id', $shopId)
->where('is_supplier', $isSupplier)
->where($field, $startNo)
->orderByDesc('id')
->value('confirm_at');
if (empty($startTime)) {
exit('开始跟团号订单未查询到或正在同步中,请稍后再次获取');
}
$startTime = DateTimeUtils::getMicroTime($startTime);
$endTime = BusinessOrder::query()
->where('shop_id', $shopId)
->where('is_supplier', $isSupplier)
->where($field, $endNo)
->orderByDesc('id')
->value('confirm_at');
if (empty($endTime)) {
exit('结束跟团号订单未查询到或正在同步中,请稍后再次获取');
}
$endTime = DateTimeUtils::getMicroTime($endTime);
if ($startTime > $endTime) {
exit('开始跟团号订单 成交时间 大于 结束跟团号订单时间,请查验后再试!');
}
$orders = BusinessOrder::query() $orders = BusinessOrder::query()
->with([ ->with([
'items:id,business_order_id,external_sku_id,goods_number,goods_name,already_cancel_number', 'items:id,business_order_id,external_sku_id,goods_number,goods_name,already_cancel_number',
'items.goodsSkuLocation:id,external_sku_id,location,goods_name' 'items.goodsSkuLocation:id,external_sku_id,location,goods_name'
]) ])
->where('shop_id', $shopId) ->whereIn('id', $orderIds)
->where('confirm_at', '>=', $startTime) ->get(['id']);
->where('confirm_at', '<=', $endTime)
->where('after_sales_status', 0)
->where('cancel_status', 0)
->where('is_supplier', $isSupplier)
->orderByDesc('confirm_at')
->get(['id', $field]);
$distribution = []; $distribution = [];
$no = []; $no = [];
foreach ($orders as $key => $order) { foreach ($orders as $key => $order) {
$index = $key + 1; $index = $key + 1;
$no[] = 'P' . $index . '(' . $order->$field . ')'; $no[] = 'P' . $index;
foreach ($order->items as $item) { foreach ($order->items as $item) {
$item = $item->toArray();
$num = $item['goods_number'] - $item['already_cancel_number']; $num = $item['goods_number'] - $item['already_cancel_number'];
if (empty($item['external_sku_id']) || empty($num)) {
continue;
}
$local = $item['goods_sku_location'] ? $item['goods_sku_location']['location'] : '无'; $local = $item['goods_sku_location'] ? $item['goods_sku_location']['location'] : '无';
$index = $key + 1; $index = $key + 1;
$index = "P{$index}*{$num}"; $index = "P{$index}*{$num}";
@ -169,10 +129,10 @@ class BusinessOrderController extends Controller
} }
} }
} }
$shopName = Shop::query()->where('id', $shopId)->value('name'); $fileName = time();
ob_end_clean(); ob_end_clean();
return Excel::download(new OrderBlankExport($shopName, $no, $distribution), $shopName . date('Y-m-d H:i:s') . '.xlsx'); return Excel::download(new OrderBlankExport($fileName, $no, $distribution), $fileName . date('Y-m-d H:i:s') . '.xlsx');
} }
public function groupActivity(Request $request, $shopId) public function groupActivity(Request $request, $shopId)
@ -205,6 +165,17 @@ class BusinessOrderController extends Controller
$businessOrders = $builder->get(); $businessOrders = $builder->get();
$waybill = new WayBillService(); $waybill = new WayBillService();
$waybill->setOrders($businessOrders); $waybill->setOrders($businessOrders);
$waybill->get(); $contents = $waybill->getContents();
// 待打印数据
[$documents, $orderIds] = $waybill->getDocumentsAndOrderIds($contents);
// 只有订单商品种类2-5的需要配货单
if (2 !== $request->get('goods_sku_num')) {
$orderIds = [];
}
return response([
'documents' => $documents,
'order_ids' => $orderIds,
]);
} }
} }

View File

@ -13,9 +13,14 @@ class WayBillService
public $objectId; public $objectId;
public $templateUrl = 'https://file-link.pinduoduo.com/sf_one'; public $templateUrl = 'https://file-link.pinduoduo.com/sf_one';
public function get() public function getContents()
{ {
$contents = [];
foreach ($this->orders as $shopId => $order) { foreach ($this->orders as $shopId => $order) {
// 花落测试;
if ($shopId !== 6) {
continue;
}
// 订单取消的情况暂不处理 // 订单取消的情况暂不处理
$shop = $this->getShop($shopId); $shop = $this->getShop($shopId);
$faceSheet = new FaceSheet(); $faceSheet = new FaceSheet();
@ -34,9 +39,54 @@ class WayBillService
$waybill->ver = $printData['ver']; $waybill->ver = $printData['ver'];
$waybill->waybill_code = $data['waybill_code']; $waybill->waybill_code = $data['waybill_code'];
$waybill->save(); $waybill->save();
// 返回待打印内容
$contents[$waybill->id] = [
'addData' => [
'sender' => $sender,
],
'encryptedData' => $printData['encryptedData'],
'signature' => $printData['signature'],
'templateUrl' => $printData['templateUrl'],
'ver' => $printData['ver'],
'userid' => $waybill->user_id,
'items' => $item['items'],
'documentID' => $waybill->id,
'order_id' => $item['id']
];
return $contents; //测试
} }
} }
} }
return $contents;
}
public function getDocumentsAndOrderIds($contents)
{
// 打印单,根据商品排序
$items = [];
foreach ($contents as $docId => $content) {
foreach ($content['items'] as $item) {
if ($item['is_single']) {
$items[$item['external_sku_id']][] = $docId;
}
}
}
ksort($items);
$documents = $orderIds = $hasIds = [];
foreach ($items as $docIds) {
$docIds = array_unique($docIds);
$docIds = array_diff($docIds, $hasIds);
$hasIds = array_merge($hasIds, $docIds);
foreach ($docIds as $docId) {
$orderIds[] = $contents[$docId]['order_id'];
unset($contents[$docId]['items'], $contents[$docId]['order_id']);
$documents[] = $contents[$docId];
}
}
return [$documents, $orderIds];
} }
private function saveWayBill($order, $shop) private function saveWayBill($order, $shop)