77 lines
3.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Services\Business\KuaiTuanTuan;
2022-08-10 16:39:25 +08:00
use App\Listeners\UpdateBusinessGoodsStock;
use App\Models\BusinessOrder;
2022-08-09 16:56:52 +08:00
use App\Models\BusinessOrderItem;
class Order
{
/**
* 根据成交时间拉取订单列表
*/
2022-08-09 16:56:52 +08:00
public static function downloadOrders($beginTime, $endTime, $page = 1)
{
$type = 'pdd.ktt.order.list';
$appendParams = [
'confirm_at_begin' => $beginTime, // 成交启始时间, 必填,毫秒时间戳
'confirm_at_end' => $endTime, // 成交结束时间,必填, 毫秒时间戳,成交结束时间 - 成交启始时间 <= 24h
2022-08-09 16:56:52 +08:00
'page_number' => $page, // 页码, 必填
2022-08-10 16:39:25 +08:00
'page_size' => 100, // 数量, 必填, 1100
// 非必填
2022-08-09 10:34:36 +08:00
// 'activity_no' => $activityNo, // 团号
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消
// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货
// 'verification_status' => '', // 核销状态, 可选 0-未核销 1-已核销 2-部分核销
];
return [$type, $appendParams];
}
/**
* 快团团增量查订单
*/
2022-08-09 16:56:52 +08:00
public static function downloadIncrementOrders($beginTime, $endTime, $page = 1)
{
$type = 'pdd.ktt.increment.order.query';
$appendParams = [
'start_updated_at' => $beginTime, // 更新起始时间
'end_updated_at' => $endTime, // 更新结束时间
2022-08-09 16:56:52 +08:00
'page_number' => $page, // 页码
'page_size' => 100, // 数量
// 非必填
2022-08-09 10:34:36 +08:00
// 'activity_no' => $activityNo, // 团号
'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭
'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消
// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货
// 'verification_status' => '', // 核销状态, 可选 0-未核销 1-已核销 2-部分核销
];
return [$type, $appendParams];
}
// 下载订单事件之后去统计 然后更新库存
public static function saveOrders(array $orders, $shopId)
{
2022-08-10 16:39:25 +08:00
$updateOrders = [];
foreach ($orders as $order) {
2022-08-09 16:56:52 +08:00
unset($order['custom_item_list'], $order['logistics_list'], $order['gift_order_list']);
$orderRecord = BusinessOrder::updateOrCreate(
['shop_id' => $shopId, 'order_sn' => $order['order_sn']],
$order
);
2022-08-10 16:39:25 +08:00
$updateOrders[] = $order['order_sn'];
foreach ($order['sub_order_list'] as $item) {
2022-08-09 16:56:52 +08:00
BusinessOrderItem::updateOrCreate(
['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']],
$item
);
}
}
2022-08-10 16:39:25 +08:00
event(new UpdateBusinessGoodsStock($shopId, $updateOrders));
}
}