$this->getPlatform()->id, 'company_id' => $this->getCompany()->id, 'store_id' => $this->getStore()->id, 'unique_id' => $record['unique_id'] ?? $this->getData()['unique_id'] ?? null, 'raw_data' => json_encode($record), // 根据实际业务需求映射其他字段 // 例如: // 'order_id' => $record['order_id'] ?? null, // 'order_status' => $record['order_status'] ?? null, // 'order_amount' => $record['order_amount'] ?? 0, // ... ]; } }); } /** * 获取实体的唯一键字段(用于 upsert 的 uniqueBy 参数) * * 定义订单的唯一约束字段组合 * * @return array 唯一键字段名数组 */ 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); } }