diff --git a/backend/app/Platform/Shopee/ShopeeOrderParser.php b/backend/app/Platform/Shopee/ShopeeOrderParser.php new file mode 100644 index 0000000..d1c2a69 --- /dev/null +++ b/backend/app/Platform/Shopee/ShopeeOrderParser.php @@ -0,0 +1,160 @@ +where('platform_store_id', '=', $platform_store_id) + ->first(); + + if (!$store) { + throw new InvalidArgumentException("Platform shopee store id {$shopee_platform_id} not found"); + } + + return $store; + } + + /** + * 实体数据映射 + * + * 将原始数据映射为可供 Model 使用的数组集合 + * + * @param array $rawData 原始数据数组,通常来自 $data['raw_data'] + * @return LazyCollection 返回 LazyCollection,每个元素为可供 Model::fill() 使用的数组 + */ + public function entityMap(array $rawData): LazyCollection + { + // 使用 LazyCollection 进行延迟处理,提高性能 + return LazyCollection::make(function () use ($rawData) { + // 如果 rawData 是单个记录,转换为数组 + $records = isset($rawData[0]) ? $rawData : [$rawData]; + + foreach ($records as $record) { + + // 映射每条原始数据到 Order Model 可用的数组格式 + // @attention 此处业务决定了 电商平台数据 和 数据仓库 之间的映射关系 + + // "company_id" int4 NOT NULL, + // "platform_id" int4 NOT NULL, + // "store_id" int4 NOT NULL, + // "order_status_id" int4 NOT NULL, + // "platform_order_id" text COLLATE "pg_catalog"."default" NOT NULL, + // "payment_method_id" int4 NOT NULL DEFAULT 1, + // "presale" bool NOT NULL DEFAULT false, + // "total_amount" float8 NOT NULL DEFAULT '0'::double precision, + // "total_paid" float8 NOT NULL DEFAULT '0'::double precision, + // "total_discount" float8 NOT NULL DEFAULT '0'::double precision, + // "total_received" float8 NOT NULL DEFAULT '0'::double precision, + // "freight_fee" float8 NOT NULL DEFAULT '0'::double precision, + // "tax_fee" float8 NOT NULL DEFAULT '0'::double precision, + // "discount_fee" float8 NOT NULL DEFAULT '0'::double precision, + // "commission_fee" float8 NOT NULL DEFAULT '0'::double precision, + // "coupon_amount" float8 NOT NULL DEFAULT '0'::double precision, + // "voucher_amount" float8 NOT NULL DEFAULT '0'::double precision, + // "order_type_id" int4 NOT NULL DEFAULT 1, + // "created_date" timestamptz(0) NOT NULL, + // "updated_date" timestamptz(0), + // "paid_date" timestamptz(0), + // "shipping_date" timestamptz(0), + // "zipcode" text COLLATE "pg_catalog"."default", + // "city" text COLLATE "pg_catalog"."default", + // "province" text COLLATE "pg_catalog"."default", + // "country" text COLLATE "pg_catalog"."default", + // "raw" jsonb, + // "ext" jsonb, + // "created_at" timestamptz(0), + // "updated_at" timestamptz(0), + + yield [ + 'company_id' => $this->getCompany()->id, + 'platform_id' => 25, + 'store_id' => $this->getStore()->id, + 'unique_id' => $record['unique_id'] ?? $this->getData()['unique_id'] ?? null, + 'raw_data' => json_encode($record['raw']), + // 根据实际业务需求映射其他字段 + // 例如: + // 'order_id' => $record['order_id'] ?? null, + // 'order_status' => $record['order_status'] ?? null, + // 'order_amount' => $record['order_amount'] ?? 0, + // ... + ]; + } + }); + } + + private function orderItemParse( array $order_items) : array { + return []; + } + + /** + * 可选:覆盖唯一标识符提取逻辑 + * + * 如果使用默认的 unique_id 提取逻辑,则无需覆盖此方法 + */ + // public function entityUniqueIdentifierExtract(array $metadata): string|int + // { + // return $metadata['custom_id_field'] ?? throw new InvalidArgumentException('custom_id_field not found'); + // } +}