update order and order_item
This commit is contained in:
+41
-8
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Platform\Tmall;
|
||||
namespace App\Platform\Tmall\EntityParse;
|
||||
|
||||
use App\Model\Company;
|
||||
use App\Model\Model as Entity;
|
||||
@@ -16,7 +16,7 @@ use InvalidArgumentException;
|
||||
*
|
||||
* 展示如何继承 EntityParse 实现自定义解析逻辑
|
||||
*/
|
||||
class TmallOrderParser extends EntityParse
|
||||
class Order extends EntityParse
|
||||
{
|
||||
/**
|
||||
* 公司作用域匹配
|
||||
@@ -107,12 +107,45 @@ class TmallOrderParser extends EntityParse
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选:覆盖唯一标识符提取逻辑
|
||||
* 获取实体的唯一键字段(用于 upsert 的 uniqueBy 参数)
|
||||
*
|
||||
* 如果使用默认的 unique_id 提取逻辑,则无需覆盖此方法
|
||||
* 定义订单的唯一约束字段组合
|
||||
*
|
||||
* @return array 唯一键字段名数组
|
||||
*/
|
||||
// public function entityUniqueIdentifierExtract(array $metadata): string|int
|
||||
// {
|
||||
// return $metadata['custom_id_field'] ?? throw new InvalidArgumentException('custom_id_field not found');
|
||||
// }
|
||||
public function getUniqueBy(): array
|
||||
{
|
||||
// 天猫订单的唯一性由店铺 + 平台订单号确定
|
||||
return ['store_id', 'platform_order_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可更新的字段列表(用于 upsert 的 update 参数)
|
||||
*
|
||||
* 明确定义哪些字段在更新时可以被修改
|
||||
* 排除:主键、唯一键、创建时间、关联 ID 等不应变更的字段
|
||||
*
|
||||
* @return array 可更新字段名数组
|
||||
*/
|
||||
public function getUpdateFields(): array
|
||||
{
|
||||
// 方案1:手动指定可更新字段(推荐,最明确)
|
||||
return [
|
||||
'order_status_id',
|
||||
'payment_method_id',
|
||||
'buyer_user_id',
|
||||
'total_amount',
|
||||
'updated_date',
|
||||
'raw',
|
||||
// 根据实际业务需求添加其他可更新字段
|
||||
];
|
||||
|
||||
// 方案2:动态计算(如果字段较多且经常变动)
|
||||
// $entity = $this->entityMatch($this->getData());
|
||||
// $excludeFields = array_merge(
|
||||
// ['id', 'created_at', 'created_date', 'company_id', 'platform_id'],
|
||||
// $this->getUniqueBy()
|
||||
// );
|
||||
// return $this->getTableColumnsExcept($entity, $excludeFields);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user