diff --git a/backend/app/Platform/AbstractProductParse.php b/backend/app/Platform/AbstractProductParse.php index 866adb3..6203a9e 100644 --- a/backend/app/Platform/AbstractProductParse.php +++ b/backend/app/Platform/AbstractProductParse.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Platform; use App\Entity\Parse\EntityParse; -use InvalidArgumentException; /** * 产品解析器抽象基类 @@ -15,5 +14,8 @@ use InvalidArgumentException; */ abstract class AbstractProductParse extends EntityParse implements ProductContract { - + /** + * 获取产品状态 ID(抽象方法,由子类实现) + */ + abstract public function getProductStatusId(string $platform_status): int; } \ No newline at end of file diff --git a/backend/app/Platform/AbstractRefundParse.php b/backend/app/Platform/AbstractRefundParse.php new file mode 100644 index 0000000..ee108cc --- /dev/null +++ b/backend/app/Platform/AbstractRefundParse.php @@ -0,0 +1,48 @@ +parseValidate($parse); - $meta = $data['meta'] ?? []; $metadata = [ 'company_id' => $meta['company_id'] ?? null, @@ -299,22 +295,4 @@ class RefundConsumer extends ConsumerMessage dump("Refund items processing completed"); } - protected function parseValidate(EntityParseInterface $parse): void - { - if (!method_exists($parse, 'hasParentRefund')) { - throw new Exception('hasParentRefund method must be implemented in ' . $parse::class); - } - - if (!method_exists($parse, 'formatRefundItemsFromRaw')) { - throw new Exception('formatRefundItemsFromRaw method must be implemented in ' . $parse::class); - } - - if (!method_exists($parse, 'getRefundStatusId')) { - throw new Exception('getRefundStatusId method must be implemented in ' . $parse::class); - } - - if (!method_exists($parse, 'getRefundTypeId')) { - throw new Exception('getRefundTypeId method must be implemented in ' . $parse::class); - } - } } diff --git a/backend/app/Platform/RefundContract.php b/backend/app/Platform/RefundContract.php new file mode 100644 index 0000000..ac5602e --- /dev/null +++ b/backend/app/Platform/RefundContract.php @@ -0,0 +1,53 @@ + 本地数据库退款 ID 映射 + * @return array 解析后的退款子项数据数组 + */ + public function formatRefundItemsFromRaw(array $raw_data, ?array $platform_refund_id_to_local_refund_id_map): array; +} diff --git a/backend/app/Platform/Shopee/EntityParse/Refund.php b/backend/app/Platform/Shopee/EntityParse/Refund.php index 46536e3..3244afe 100644 --- a/backend/app/Platform/Shopee/EntityParse/Refund.php +++ b/backend/app/Platform/Shopee/EntityParse/Refund.php @@ -10,7 +10,7 @@ use App\Platform\Shopee\Constants\ReturnStatus as ShopeeReturnStatus; use App\Model\Company; use App\Model\Order; use App\Model\Store; -use App\Entity\Parse\EntityParse; +use App\Platform\AbstractRefundParse; use Carbon\Carbon; use Hyperf\Collection\LazyCollection; use InvalidArgumentException; @@ -21,7 +21,7 @@ use InvalidArgumentException; * Shopee 具有完整的父子退款结构:一个 return 包含多个 item。 * 每个 return 同时写入 refunds(主记录)和 refund_items(明细)两张表。 */ -class Refund extends EntityParse +class Refund extends AbstractRefundParse { /** * 缓存 entityMap 中查询到的订单日期映射,供 formatRefundItemsFromRaw 复用 @@ -178,7 +178,7 @@ class Refund extends EntityParse * @param array $platform_refund_id_to_local_refund_id_map [platform_refund_id => local db refund id] * @return array */ - public function formatRefundItemsFromRaw(array $raw_data, array $platform_refund_id_to_local_refund_id_map): array + public function formatRefundItemsFromRaw(array $raw_data, ?array $platform_refund_id_to_local_refund_id_map): array { $records = isset($raw_data[0]) ? $raw_data : [$raw_data]; $items = []; diff --git a/backend/app/Platform/Tmall/EntityParse/Product.php b/backend/app/Platform/Tmall/EntityParse/Product.php index 0d7c467..b261b7c 100644 --- a/backend/app/Platform/Tmall/EntityParse/Product.php +++ b/backend/app/Platform/Tmall/EntityParse/Product.php @@ -7,7 +7,7 @@ namespace App\Platform\Tmall\EntityParse; use App\Constants\ProductStatus; use App\Model\Company; use App\Model\Store; -use App\Entity\Parse\EntityParse; +use App\Platform\AbstractProductParse; use App\Platform\Tmall\Constants\ItemStatus; use Carbon\Carbon; use Hyperf\Collection\LazyCollection; @@ -18,7 +18,7 @@ use InvalidArgumentException; * * 将 Tmall 产品原始数据解析为本地 Product 模型格式 */ -class Product extends EntityParse +class Product extends AbstractProductParse { /** * 公司作用域匹配 diff --git a/backend/app/Platform/Tmall/EntityParse/Refund.php b/backend/app/Platform/Tmall/EntityParse/Refund.php index cd0c034..20d15c7 100644 --- a/backend/app/Platform/Tmall/EntityParse/Refund.php +++ b/backend/app/Platform/Tmall/EntityParse/Refund.php @@ -15,7 +15,7 @@ use App\Model\Order; use App\Model\OrderItem; use App\Model\RefundItem; use App\Model\Store; -use App\Entity\Parse\EntityParse; +use App\Platform\AbstractRefundParse; use Carbon\Carbon; use Hyperf\Collection\LazyCollection; use Hyperf\DbConnection\Db; @@ -27,7 +27,7 @@ use InvalidArgumentException; * Tmall 没有主退款和子退款的概念,每个售后单对应一个订单子项。 * 每个售后单同时写入 refunds(主记录)和 refund_items(明细)两张表。 */ -class Refund extends EntityParse +class Refund extends AbstractRefundParse { /** * 公司作用域匹配 @@ -140,7 +140,7 @@ class Refund extends EntityParse * @param array $platform_refund_id_to_local_refund_id_map [platform_refund_id => local db refund id] * @return array */ - public function formatRefundItemsFromRaw(array $raw_data, array| null $platform_refund_id_to_local_refund_id_map = null): array + public function formatRefundItemsFromRaw(array $raw_data, ?array $platform_refund_id_to_local_refund_id_map): array { $records = isset($raw_data[0]) ? $raw_data : [$raw_data]; $items = [];