add order item constraint to order parse
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Platform;
|
||||
|
||||
use App\Entity\Parse\EntityParse;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* 订单解析器抽象基类
|
||||
*
|
||||
* 继承 EntityParse 的通用能力,并实现 OrderContract 契约
|
||||
* 提供订单解析的通用方法和辅助函数
|
||||
*/
|
||||
abstract class AbstractOrderParse extends EntityParse implements OrderContract
|
||||
{
|
||||
/**
|
||||
* 解析订单子项数据(抽象方法,由子类实现)
|
||||
*
|
||||
* 每个平台有自己的订单子项数据结构,需要各自实现具体的解析逻辑
|
||||
*
|
||||
* @param array $orderItems 原始订单子项数组
|
||||
* @param string $platformOrderId 平台订单 ID
|
||||
* @return array 解析后的订单子项数据数组
|
||||
*/
|
||||
abstract public function parseOrderItems(array $orderItems, string $platformOrderId): array;
|
||||
|
||||
/**
|
||||
* 通用辅助方法:验证订单必需字段
|
||||
*
|
||||
* @param array $orderData 订单原始数据
|
||||
* @param array $requiredFields 必需字段列表
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function validateOrderFields(array $orderData, array $requiredFields = []): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用辅助方法:格式化货币金额
|
||||
*
|
||||
* @param float|int|string|null $amount 金额
|
||||
* @param int $decimals 小数位数,默认 2 位
|
||||
* @return float 格式化后的金额
|
||||
*/
|
||||
protected function formatAmount(float|int|string|null $amount, int $decimals = 2): float
|
||||
{
|
||||
return round((float)($amount ?? 0), $decimals);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user