update tmall order parse
This commit is contained in:
@@ -37,12 +37,12 @@ class Order extends EntityParse
|
||||
throw new InvalidArgumentException('company_id is required in metadata');
|
||||
}
|
||||
|
||||
$companyId = $metadata['company_id'];
|
||||
$company_id = $metadata['company_id'];
|
||||
|
||||
$company = Company::find($companyId);
|
||||
$company = Company::find($company_id);
|
||||
|
||||
if (!$company) {
|
||||
throw new InvalidArgumentException("Company with ID {$companyId} not found");
|
||||
throw new InvalidArgumentException("Company with ID {$company_id} not found");
|
||||
}
|
||||
|
||||
return $company;
|
||||
@@ -64,12 +64,12 @@ class Order extends EntityParse
|
||||
throw new InvalidArgumentException('store_id is required in metadata');
|
||||
}
|
||||
|
||||
$storeId = $metadata['store_id'];
|
||||
$store_id = $metadata['store_id'];
|
||||
|
||||
$store = Store::find($storeId);
|
||||
$store = Store::find($store_id);
|
||||
|
||||
if (!$store) {
|
||||
throw new InvalidArgumentException("Store with ID {$storeId} not found");
|
||||
throw new InvalidArgumentException("Store with ID {$store_id} not found");
|
||||
}
|
||||
|
||||
return $store;
|
||||
@@ -80,15 +80,15 @@ class Order extends EntityParse
|
||||
*
|
||||
* 将原始数据映射为可供 Model 使用的数组集合
|
||||
*
|
||||
* @param array $rawData 原始数据数组,通常来自 $data['raw_data']
|
||||
* @param array $raw_data 原始数据数组,通常来自 $data['raw_data']
|
||||
* @return LazyCollection 返回 LazyCollection,每个元素为可供 Model::fill() 使用的数组
|
||||
*/
|
||||
public function entityMap(array $rawData): LazyCollection
|
||||
public function entityMap(array $raw_data): LazyCollection
|
||||
{
|
||||
// 使用 LazyCollection 进行延迟处理,提高性能
|
||||
return LazyCollection::make(function () use ($rawData) {
|
||||
// 如果 rawData 是单个记录,转换为数组
|
||||
$records = isset($rawData[0]) ? $rawData : [$rawData];
|
||||
return LazyCollection::make(function () use ($raw_data) {
|
||||
// 如果 raw_data 是单个记录,转换为数组
|
||||
$records = isset($raw_data[0]) ? $raw_data : [$raw_data];
|
||||
|
||||
foreach ($records as $record) {
|
||||
|
||||
@@ -208,14 +208,14 @@ class Order extends EntityParse
|
||||
/**
|
||||
* 根据淘宝订单状态确定对应的 Tools 订单状态
|
||||
*
|
||||
* @param string $platformOrderStatus 淘宝平台订单状态
|
||||
* @param string $platform_order_status 淘宝平台订单状态
|
||||
* @return int Tools 订单状态 ID
|
||||
*/
|
||||
public function getOrderStatusId(string $platformOrderStatus): int
|
||||
public function getOrderStatusId(string $platform_order_status): int
|
||||
{
|
||||
$statusMap = $this->orderStatusMap();
|
||||
$status_map = $this->orderStatusMap();
|
||||
|
||||
return $statusMap[$platformOrderStatus] ?? OrderStatus::PAYMENT_COMPLETE->value;
|
||||
return $status_map[$platform_order_status] ?? OrderStatus::PAYMENT_COMPLETE->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,24 +266,19 @@ class Order extends EntityParse
|
||||
*
|
||||
* orderItems 的输出结果为 \App\Model\OrderItem::fill() 可以直接使用的数据格式
|
||||
*
|
||||
* @param array $rawData
|
||||
* @param array $raw_data
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public function formatOrderItemsFromRaw(array $rawData, 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
|
||||
{
|
||||
// 由于 $rawData 是批量数据,包含多条订单结果,因此订单子项需要从集合中提取
|
||||
// 由于 $raw_data 是批量数据,包含多条订单结果,因此订单子项需要从集合中提取
|
||||
// Tmall 平台响应体的数据格式为: collection->payload->orders
|
||||
// $platform_orders_id_to_local_db_order_id_map 内部元素数据格式为 [platform_order_id => local db order id]
|
||||
|
||||
if(empty($rawData['orders'])){
|
||||
return [];
|
||||
}
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($rawData as $raw_orders) {
|
||||
foreach ($raw_orders['orders'] as $raw_order_item){
|
||||
foreach ($raw_data as $raw_orders) {
|
||||
foreach ($raw_orders['orders'] as $raw_order_item) {
|
||||
// 数据库中父订单 id
|
||||
$db_order_id = $platform_orders_id_to_local_db_order_id_map[$raw_orders['tid']];
|
||||
$items[] = $this->tmallOrderItemMap($raw_order_item, $raw_orders['tid'], $db_order_id, $raw_orders['created']);
|
||||
@@ -312,8 +307,10 @@ class Order extends EntityParse
|
||||
'sub_order_type_id' => '',
|
||||
'product_id' => '',
|
||||
'platform_product_id' =>$item['num_iid'],
|
||||
'product_sku' => $item['outer_sku_id'],
|
||||
'product_barcode' => '',
|
||||
// @attention @TODO 需要对 运营侧的产品维护做进一步规范
|
||||
'product_sku' => $item['outer_sku_id'] ?? null,
|
||||
// @attention @TODO 需要对 运营侧的产品维护做进一步规范
|
||||
'product_barcode' => null,
|
||||
'unit_price' => $item['price'],
|
||||
'quantity' => $item['num'],
|
||||
'discount' => $item['discount_fee'],
|
||||
|
||||
Reference in New Issue
Block a user