diff --git a/backend/app/Platform/Shopee/EntityParse/Product.php b/backend/app/Platform/Shopee/EntityParse/Product.php new file mode 100644 index 0000000..414fb8e --- /dev/null +++ b/backend/app/Platform/Shopee/EntityParse/Product.php @@ -0,0 +1,238 @@ +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 使用的数组集合 + * + * @attention 当前返回格式为 ['order' => [...], 'items' => [...]] + * 但 ProductConsumer 第 153-157 行期望直接返回订单数据数组(参考 Tmall 实现) + * 需要调整返回格式以兼容 ProductConsumer 的 upsert 操作 + * + * @TODO 调整返回格式: + * - 方案1:改为直接返回订单数据数组(与 Tmall 一致) + * - 方案2:修改 ProductConsumer 以支持当前的嵌套结构 + * + * @param array $raw_data 原始数据数组,通常来自 $data['raw_data'] + * @return LazyCollection 返回 LazyCollection,每个元素为可供 Model::fill() 使用的数组 + */ + public function entityMap(array $raw_data): LazyCollection + { + // 使用 LazyCollection 进行延迟处理,提高性能 + return LazyCollection::make(function () use ($raw_data) { + // 如果 raw_data 是单个记录,转换为数组 + $records = isset($raw_data[0]) ? $raw_data : [$raw_data]; + + foreach ($records as $record) { + dump($record); + } + }); + } + + + /** + * 获取唯一键字段(对应数据库唯一索引) + * + * 对应数据库约束: + * UNIQUE INDEX orders_store_platform_order_unique (store_id, platform_order_id) + * + * @return array + */ + public function getUniqueBy(): array + { + return ['store_id', 'platform_product_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); + } + + /** + * 根据 Shopee 产品状态确定对应的本地订单状态 + * + * @required ProductConsumer 要求实现此方法(第 130-132 行) + * @see \App\Constants\OrderStatus + * + * @param string $platform_order_status Shopee 平台订单状态 + * @return int 本地订单状态 ID + */ + public function getProductStatusId(string $platform_order_status): int + { + + } + + /** + * Shopee 产品状态到本地产品状态的映射表 + * + * @see \App\Platform\Shopee\Constants\ProductStatus Shopee 产品订单状态枚举 + * @see \App\Constants\OrderStatus 本地产品状态枚举 + * + * @return array + */ + private function ProducttatusMap(): array + { + return [ + // 未付款 -> 等待付款 + 'UNPAID' => \App\Constants\OrderStatus::PAYMENT_PENDING->value, + + // 可发货(已付款,等待卖家安排发货)-> 付款完成 + 'READY_TO_SHIP' => \App\Constants\OrderStatus::PAYMENT_COMPLETE->value, + + // 已处理(卖家已安排发货并获取物流单号)-> 等待发货 + 'PROCESSED' => \App\Constants\OrderStatus::AWAITING_SHIPMENT->value, + + // 重新发货(3PL 取件失败,需要重新安排发货)-> 等待发货 + 'RETRY_SHIP' => \App\Constants\OrderStatus::AWAITING_SHIPMENT->value, + + // 已发货(包裹已交给 3PL 或已被 3PL 取走)-> 已发货 + 'SHIPPED' => \App\Constants\OrderStatus::SHIPPED->value, + + // 待确认收货(买家已收到订单)-> 已发货 + 'TO_CONFIRM_RECEIVE' => \App\Constants\OrderStatus::SHIPPED->value, + + // 取消中(订单取消正在处理)-> 取消请求中 + 'IN_CANCEL' => \App\Constants\OrderStatus::CANCEL_REQUESTED->value, + + // 已取消 -> 取消确认 + 'CANCELLED' => \App\Constants\OrderStatus::CANCEL_CONFIRMED->value, + + // 退货中(买家请求退货,退货正在处理)-> 取消请求中 + 'TO_RETURN' => \App\Constants\OrderStatus::CANCEL_REQUESTED->value, + + // 已完成 -> 完成 + 'COMPLETED' => \App\Constants\OrderStatus::FINISHED->value, + ]; + } + +} diff --git a/backend/app/Platform/Tmall/Producer/TmallProductProducer.php b/backend/app/Platform/Tmall/Producer/TmallProductProducer.php new file mode 100644 index 0000000..866a048 --- /dev/null +++ b/backend/app/Platform/Tmall/Producer/TmallProductProducer.php @@ -0,0 +1,25 @@ + [ 'driver' => 'mysql', - 'host' => '127.0.0.1', - 'port' => 3380, - 'database' => 'wpic_task', - 'username' => 'tools', - 'password' => 'root', + // 'host' => '127.0.0.1', + // 'port' => 3380, + // 'database' => 'wpic_task', + // 'username' => 'tools', + // 'password' => 'root', + 'host' => '120.27.136.208', + 'port' => 3306, + 'database' => 'wpic', + 'username' => 'wpic', + 'password' => 'wpic#jsKk223', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '',