update tmall refund parse

This commit is contained in:
2026-02-11 10:10:21 +08:00
parent c1939fd9bb
commit 7d8204cdab
@@ -69,49 +69,14 @@ class Refund extends EntityParse
/**
* 实体数据映射 - 映射到 refunds 表
*
* Tmall 每个售后单映射为一条 refunds 记录
* Tmall 不存在父退款订单,因此此方法返回空值
*
* @param array $raw_data 原始数据数组
* @return LazyCollection 每个元素为可供 Refund Model::fill() 使用的数组
*/
public function entityMap(array $raw_data): LazyCollection
{
return LazyCollection::make(function () use ($raw_data) {
$records = isset($raw_data[0]) ? $raw_data : [$raw_data];
foreach ($records as $record) {
$raw = \json_encode($record);
$tz = $this->getStore()->getTimezoneString();
$refund_fee = (float) ($record['refund_fee'] ?? 0);
yield [
'company_id' => $this->getCompany()->id,
'platform_id' => $this->getPlatform()->id,
'store_id' => $this->getStore()->id,
'order_id' => null,
'platform_order_id' => strval($record['tid']),
'platform_refund_id' => strval($record['refund_id']),
'refund_status_id' => $this->getRefundStatusId($record['status']),
'refund_type_id' => $this->getRefundTypeId($record),
'reason' => $record['reason'] ?? null,
'refund_amount' => $refund_fee,
'freight_refund' => 0,
'refund_total' => $refund_fee,
'currency' => 'CNY',
'buyer_user_id' => $record['buyer_open_uid'] ?? null,
'order_created_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'order_paid_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'created_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'updated_date' => isset($record['modified']) ? Carbon::parse($record['modified'], $tz)->format('Y-m-d H:i:sP') : null,
'completed_date' => isset($record['end_time']) ? Carbon::parse($record['end_time'], $tz)->format('Y-m-d H:i:sP') : null,
'raw' => $raw,
'ext' => null,
'hash' => \md5($raw),
'created_at' => Carbon::now()->format('Y-m-d H:i:sP'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:sP'),
];
}
});
return LazyCollection::make();
}
/**
@@ -149,6 +114,15 @@ class Refund extends EntityParse
];
}
/**
* Tmall 没有父级退款单
* @return bool
*/
public function hasParentRefund(): bool
{
return false;
}
/**
* 格式化退款子项数据 - 映射到 refund_items 表
*
@@ -159,14 +133,13 @@ class Refund extends EntityParse
* @param array $platform_refund_id_to_local_refund_id_map [platform_refund_id => local db refund id]
* @return array
*/
public function formatRefundItemsFromRaw(array $raw_data, array $platform_refund_id_to_local_refund_id_map): array
public function formatRefundItemsFromRaw(array $raw_data, array| null $platform_refund_id_to_local_refund_id_map = null): array
{
$records = isset($raw_data[0]) ? $raw_data : [$raw_data];
$items = [];
foreach ($records as $record) {
$platform_refund_id = strval($record['refund_id']);
$refund_id = $platform_refund_id_to_local_refund_id_map[$platform_refund_id] ?? 0;
$tz = $this->getStore()->getTimezoneString();
$raw = \json_encode($record);
@@ -174,7 +147,7 @@ class Refund extends EntityParse
'company_id' => $this->getCompany()->id,
'platform_id' => $this->getPlatform()->id,
'store_id' => $this->getStore()->id,
'refund_id' => $refund_id,
'refund_id' => 0,
'platform_parent_refund_id' => '',
'platform_refund_id' => $platform_refund_id,
'refund_status_id' => $this->getRefundStatusId($record['status']),
@@ -187,8 +160,8 @@ class Refund extends EntityParse
'platform_product_id' => isset($record['num_iid']) ? strval($record['num_iid']) : null,
'quantity' => $record['num'] ?? 0,
'refund_amount' => (float) ($record['refund_fee'] ?? 0),
'order_created_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'order_paid_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'order_created_date' => null, // @attention 暂时设置为 null 后续会批量更新
'order_paid_date' => null, // @attention 暂时设置为 null 后续会批量更新
'created_date' => Carbon::parse($record['created'], $tz)->format('Y-m-d H:i:sP'),
'updated_date' => isset($record['modified']) ? Carbon::parse($record['modified'], $tz)->format('Y-m-d H:i:sP') : null,
'completed_date' => isset($record['end_time']) ? Carbon::parse($record['end_time'], $tz)->format('Y-m-d H:i:sP') : null,