update shopee order parse
This commit is contained in:
@@ -107,7 +107,9 @@ class Order extends AbstractOrderParse
|
|||||||
|
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
|
|
||||||
$_origin_order_item = $record['order_list']; // 'order_list' 为来自 shopee 原始数据的 订单子项信息
|
dump($record);
|
||||||
|
|
||||||
|
$_origin_order_item = $record['item_list']; // 'item_list' 为来自 shopee 原始数据的 订单子项信息
|
||||||
|
|
||||||
// 解析订单子项数据,传入 platform_order_id(实现 OrderContract 契约方法)
|
// 解析订单子项数据,传入 platform_order_id(实现 OrderContract 契约方法)
|
||||||
$order_items = $this->parseOrderItems($_origin_order_item, $record['order_sn']);
|
$order_items = $this->parseOrderItems($_origin_order_item, $record['order_sn']);
|
||||||
@@ -117,42 +119,45 @@ class Order extends AbstractOrderParse
|
|||||||
// @attention 此处业务决定了 电商平台数据 和 数据仓库 之间的映射关系
|
// @attention 此处业务决定了 电商平台数据 和 数据仓库 之间的映射关系
|
||||||
|
|
||||||
// 返回包含订单数据和子项数据的结构
|
// 返回包含订单数据和子项数据的结构
|
||||||
|
$raw = \json_encode($record);
|
||||||
|
|
||||||
yield [
|
yield [
|
||||||
'order' => [
|
'company_id' => $this->getCompany()->id,
|
||||||
'company_id' => $this->getCompany()->id,
|
'platform_id' => $this->platform->id,
|
||||||
'platform_id' => 25,
|
'store_id' => $this->getStore()->id,
|
||||||
'store_id' => $this->getStore()->id,
|
'order_status_id'=> OrderStatus::{$record['order_status']}->value,
|
||||||
'order_status_id'=> OrderStatus::{$record['order_status']}->value,
|
'platform_order_id' => $record['order_sn'],
|
||||||
'platform_order_id' => $record['order_sn'],
|
'payment_method_id' => $this->getPaymentMethodId(),
|
||||||
'payment_method_id' => $this->getPaymentMethodId(),
|
'buyer_user_id' => $record['buyer_user_id'] ?? null,
|
||||||
'buyer_user_id' => $record['buyer_user_id'] ?? null,
|
'presale' => false, // shopee 平台暂不存类型为 presales 的订单
|
||||||
'presale' => false, // shopee 平台暂不存类型为 presales 的订单
|
'total_amount' => $record['total_amount'] ?? 0,
|
||||||
'total_amount' => $record['total_amount'] ?? 0,
|
// @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1
|
||||||
// @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1
|
// shopee 定义 $record['total_amount'] 为买家付款金额字段
|
||||||
// shopee 定义 $record['total_amount'] 为买家付款金额字段
|
// The total amount paid by the buyer for the order. This amount includes the total sale price of items,
|
||||||
// The total amount paid by the buyer for the order. This amount includes the total sale price of items,
|
// shipping cost beared by buyer; and offset by Shopee promotions if applicable. This value
|
||||||
// shipping cost beared by buyer; and offset by Shopee promotions if applicable. This value
|
// will only return after the buyer has completed payment for the order.
|
||||||
// will only return after the buyer has completed payment for the order.
|
'total_paid' => $record['total_amount'] ?? 0,
|
||||||
'total_paid' => $record['total_amount'] ?? 0,
|
'total_discount' => 0,
|
||||||
'total_discount' => 0,
|
'total_received' => 0,
|
||||||
'total_received' => 0,
|
// @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1
|
||||||
// @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1
|
// $record['actual_shipping_fee'] - The actual shipping fee of the order if available from external logistics partners.
|
||||||
// $record['actual_shipping_fee'] - The actual shipping fee of the order if available from external logistics partners.
|
'freight_fee' => $record['actual_shipping_fee'] ?? 0,
|
||||||
'freight_fee' => $record['actual_shipping_fee'] ?? 0,
|
'tax_fee' => 0,
|
||||||
'tax_fee' => 0,
|
'discount_fee' => 0,
|
||||||
'discount_fee' => 0,
|
'commission_fee' => 0,
|
||||||
'commission_fee' => 0,
|
'coupon_amount' => 0,
|
||||||
'coupon_amount' => 0,
|
'voucher_amount' => 0,
|
||||||
'voucher_amount' => 0,
|
'order_type_id' => 0,
|
||||||
'order_type_id' => 0,
|
'created_date' => Carbon::createFromTimestamp($record['create_time'], $this->getStore()->getTimezoneString()), // 订单的创建时间
|
||||||
'created_date' => Carbon::createFromTimestamp($record['create_time'], $this->getStore()->getTimezoneString()), // 订单的创建时间
|
'updated_date' => Carbon::createFromTimestamp($record['update_time'], $this->getStore()->getTimezoneString()), // 最近的一次订单更新时间
|
||||||
'updated_date' => Carbon::createFromTimestamp($record['update_time'], $this->getStore()->getTimezoneString()), // 最近的一次订单更新时间
|
'paid_date' => $record['pay_time'] ? Carbon::createFromTimestamp($record['pay_time'], $this->getStore()->getTimezoneString()) : null,
|
||||||
'paid_date' => $record['pay_time'] ? Carbon::createFromTimestamp($record['pay_time'], $this->getStore()->getTimezoneString()) : null,
|
'shipping_date' => $record['pickup_done_time'] > 0 ? Carbon::createFromTimestamp($record['pickup_done_time'], $this->getStore()->getTimezoneString()) : null,
|
||||||
'shipping_date' => $record['pickup_done_time'] > 0 ? Carbon::createFromTimestamp($record['pickup_done_time'], $this->getStore()->getTimezoneString()) : null,
|
'country' => $record['region'], // address 等地理位置信息因 shopee 数据保护协议已被隐藏, 目前仅提供 ISO 格式国家代码
|
||||||
'country' => $record['region'], // address 等地理位置信息因 shopee 数据保护协议已被隐藏, 目前仅提供 ISO 格式国家代码
|
'raw' => $raw,
|
||||||
'raw' => json_encode($record['raw']),
|
'ext' => null,
|
||||||
],
|
'hash' => \md5($raw),
|
||||||
'items' => $order_items,
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -212,7 +217,8 @@ class Order extends AbstractOrderParse
|
|||||||
*/
|
*/
|
||||||
public function getUniqueBy(): array
|
public function getUniqueBy(): array
|
||||||
{
|
{
|
||||||
return ['store_id', 'platform_order_id'];
|
// @attention create_date 为数据库强制要求,必需携带
|
||||||
|
return ['store_id', 'platform_order_id', 'created_date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,7 +256,8 @@ class Order extends AbstractOrderParse
|
|||||||
'country',
|
'country',
|
||||||
'raw',
|
'raw',
|
||||||
'ext',
|
'ext',
|
||||||
'updated_at',
|
'hash',
|
||||||
|
'updated_at', // 更新时刷新,created_at 不包含以保留原始创建时间
|
||||||
];
|
];
|
||||||
|
|
||||||
// 动态计算方案(如果表字段经常变化,可以使用):
|
// 动态计算方案(如果表字段经常变化,可以使用):
|
||||||
@@ -355,7 +362,7 @@ class Order extends AbstractOrderParse
|
|||||||
*/
|
*/
|
||||||
public function formatOrderItemsFromRaw(array $raw_data, array $platform_orders_id_to_local_db_order_id_map): array
|
public function formatOrderItemsFromRaw(array $raw_data, array $platform_orders_id_to_local_db_order_id_map): array
|
||||||
{
|
{
|
||||||
// 1. 从 $rawData 中提取订单子项信息(Shopee 的 order_list 字段)
|
// 1. 从 $rawData 中提取订单子项信息(Shopee 的 item_list 字段)
|
||||||
// 2. 使用 $platformOrderIdToLocalDbOrderIdMap 获取本地 order_id
|
// 2. 使用 $platformOrderIdToLocalDbOrderIdMap 获取本地 order_id
|
||||||
// 3. 调用 shopeeOrderItemMap() 进行单个子项的映射转换
|
// 3. 调用 shopeeOrderItemMap() 进行单个子项的映射转换
|
||||||
// 4. 返回可供 OrderItem::fill() 使用的数组
|
// 4. 返回可供 OrderItem::fill() 使用的数组
|
||||||
@@ -367,10 +374,12 @@ class Order extends AbstractOrderParse
|
|||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
foreach ($raw_data as $raw_orders) {
|
foreach ($raw_data as $raw_orders) {
|
||||||
foreach ($raw_orders['order_list'] as $raw_order_item) {
|
$parent_order_created_date = Carbon::createFromTimestamp($raw_orders['create_time'], $this->getStore()->getTimezoneString());
|
||||||
|
foreach ($raw_orders['item_list'] as $raw_order_item) {
|
||||||
// 数据库中父订单 id
|
// 数据库中父订单 id
|
||||||
$db_order_id = $platform_orders_id_to_local_db_order_id_map[$raw_orders['tid']];
|
|
||||||
$items[] = $this->shopeeOrderItemMap($raw_order_item, $raw_orders['tid'], $db_order_id, $raw_orders['created']);
|
$db_order_id = $platform_orders_id_to_local_db_order_id_map[$raw_orders['order_sn']];
|
||||||
|
$items[] = $this->shopeeOrderItemMap($raw_order_item, $raw_orders['order_sn'], $db_order_id, $parent_order_created_date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user