update entity parse batch insert

This commit is contained in:
2025-12-12 11:12:52 +08:00
parent b8e3b12316
commit c726020c8c
3 changed files with 172 additions and 32 deletions
@@ -210,12 +210,66 @@ class Order extends EntityParse
}
/**
* 可选:覆盖唯一标识符提取逻辑
* 获取唯一键字段(对应数据库唯一索引)
*
* 如果使用默认的 unique_id 提取逻辑,则无需覆盖此方法
* 对应数据库约束:
* UNIQUE INDEX orders_store_platform_order_unique (store_id, platform_order_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'];
}
/**
* 获取可更新字段列表
*
* 排除:主键、唯一键、创建时间、关联 ID
*
* @return array
*/
public function getUpdateFields(): array
{
// 手动指定(推荐:明确且高效,无数据库查询开销)
return [
'order_status_id',
'payment_method_id',
'buyer_user_id',
'presale',
'total_amount',
'total_paid',
'total_discount',
'total_received',
'freight_fee',
'tax_fee',
'discount_fee',
'commission_fee',
'coupon_amount',
'voucher_amount',
'order_type_id',
'updated_date',
'paid_date',
'shipping_date',
'zipcode',
'city',
'province',
'country',
'raw',
'ext',
'updated_at',
];
// 动态计算方案(如果表字段经常变化,可以使用):
// $entity = $this->entityMatch([
// 'company_id' => $this->getCompany()->id,
// 'platform_id' => $this->getPlatform()->id,
// 'store_id' => $this->getStore()->id,
// ]);
// $excludeFields = array_merge(
// ['id', 'created_at', 'created_date', 'company_id', 'platform_id'],
// $this->getUniqueBy()
// );
// return $this->getTableColumnsExcept($entity, $excludeFields);
}
}