From c7bead15b2f4ee1c1c7dc78f3b218e66724b05a0 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Wed, 10 Dec 2025 12:57:32 +0800 Subject: [PATCH] update order entity parse --- .../app/Platform/Shopee/EntityParse/Order.php | 72 ++++++++----------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/backend/app/Platform/Shopee/EntityParse/Order.php b/backend/app/Platform/Shopee/EntityParse/Order.php index 4a8180d..4dd4bc7 100644 --- a/backend/app/Platform/Shopee/EntityParse/Order.php +++ b/backend/app/Platform/Shopee/EntityParse/Order.php @@ -10,6 +10,7 @@ use App\Model\Store; use App\Entity\Parse\EntityParse; use App\Platform\Shopee\Constants\OrderStatus; use App\Platform\Shopee\Constants\PaymentMethod; +use Carbon\Carbon; use Hyperf\Collection\LazyCollection; use Hyperf\Context\ApplicationContext; use Psr\Log\LoggerInterface; @@ -96,56 +97,43 @@ class Order extends EntityParse $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, 'order_status_id'=> OrderStatus::{$record['order_status']}->value, 'platform_order_id' => $record['order_sn'], - 'payment_method_id' => $this->parsePaymentMethod($record['payment_method'] ?? ''), - 'presale' => false, - 'raw_data' => json_encode($record['raw']), - // 根据实际业务需求映射其他字段 - // 例如: - // 'order_id' => $record['order_id'] ?? null, - // 'order_status' => $record['order_status'] ?? null, - // 'order_amount' => $record['order_amount'] ?? 0, - // ... + 'payment_method_id' => $this->parsePaymentMethod($record['payment_method']), + 'buyer_user_id' => $record['buyer_user_id'] ?? null, + 'presale' => false, // shopee 平台暂不存类型为 presales 的订单 + 'total_amount' => $record['total_amount'] ?? 0, + // @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1 + // shopee 定义 $record['total_amount'] 为买家付款金额字段 + // The total amount paid by the buyer for the order. This amount includes the total sale price of items, + // shipping cost beared by buyer; and offset by Shopee promotions if applicable. This value + // will only return after the buyer has completed payment for the order. + 'total_paid' => $record['total_amount'] ?? 0, + 'total_discount' => 0, + 'total_received' => 0, + // @link https://open.shopee.com/documents/v2/v2.order.get_order_detail?module=94&type=1 + // $record['actual_shipping_fee'] - The actual shipping fee of the order if available from external logistics partners. + 'freight_fee' => $record['actual_shipping_fee'] ?? 0, + 'tax_fee' => 0, + 'discount_fee' => 0, + 'commission_fee' => 0, + 'coupon_amount' => 0, + 'voucher_amount' => 0, + 'order_type_id' => 0, + 'created_date' => Carbon::createFromTimestamp($record['create_time'], $this->getStore()->getTimezoneString()), // 订单的创建时间 + 'updated_date' => Carbon::createFromTimestamp($record['update_time'], $this->getStore()->getTimezoneString()), // 最近的一次订单更新时间 + 'paid_date' => $record['pay_time'] ? Carbon::createFromTimestamp($record['pay_time'], $this->getStore()->getTimezoneString()) : null, + 'shipping_date' => $record['pickup_done_time'] > 0 ? Carbon::createFromTimestamp($record['pickup_done_time'], $this->getStore()->getTimezoneString()) : null, + 'country' => $record['region'], // address 等地理位置信息因 shopee 数据保护协议已被隐藏, 目前仅提供 ISO 格式国家代码 + 'raw' => json_encode($record['raw']), ]; } });