|
|
@@ -266,15 +266,72 @@ class MexPriceConfigLogic
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量验证价格和数量
|
|
|
- *
|
|
|
+ * 挂单阶段参数验证(不验证价格和保护阈值)
|
|
|
+ * 根据文档要求:挂单阶段无价格验证,所有订单都可以挂单并冻结资金/物品
|
|
|
+ *
|
|
|
+ * @param int $itemId 商品ID
|
|
|
+ * @param string $price 价格(仅做基本格式验证)
|
|
|
+ * @param int $quantity 数量(不验证保护阈值)
|
|
|
+ * @param string $orderType 订单类型 (BUY/SELL)
|
|
|
+ * @return array 验证结果
|
|
|
+ */
|
|
|
+ public static function validateOrderParamsForPlacement(int $itemId, string $price, int $quantity, string $orderType): array
|
|
|
+ {
|
|
|
+ // 注意:$orderType 参数保留用于接口一致性,挂单阶段不区分买卖类型的验证
|
|
|
+ // 只验证价格配置是否存在,不验证价格范围
|
|
|
+ $config = self::getItemPriceConfig($itemId);
|
|
|
+
|
|
|
+ if (!$config) {
|
|
|
+ return [
|
|
|
+ 'valid' => false,
|
|
|
+ 'message' => '商品未配置价格信息',
|
|
|
+ 'error_code' => 'CONFIG_NOT_FOUND'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$config['is_enabled']) {
|
|
|
+ return [
|
|
|
+ 'valid' => false,
|
|
|
+ 'message' => '商品价格配置已禁用',
|
|
|
+ 'error_code' => 'CONFIG_DISABLED'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 基本的价格格式验证(确保是有效数字)
|
|
|
+ if (!is_numeric($price) || bccomp($price, '0', 5) <= 0) {
|
|
|
+ return [
|
|
|
+ 'valid' => false,
|
|
|
+ 'message' => '价格必须是大于0的数字',
|
|
|
+ 'error_code' => 'INVALID_PRICE_FORMAT'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 基本的数量验证(确保是正整数)
|
|
|
+ if (!is_int($quantity) || $quantity <= 0) {
|
|
|
+ return [
|
|
|
+ 'valid' => false,
|
|
|
+ 'message' => '数量必须是大于0的整数',
|
|
|
+ 'error_code' => 'INVALID_QUANTITY'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'valid' => true,
|
|
|
+ 'message' => '挂单参数验证通过',
|
|
|
+ 'config' => $config
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 撮合阶段价格和数量验证(用于撮合时的严格验证)
|
|
|
+ *
|
|
|
* @param int $itemId 商品ID
|
|
|
* @param string $price 价格
|
|
|
* @param int $quantity 数量
|
|
|
* @param string $orderType 订单类型 (BUY/SELL)
|
|
|
* @return array 验证结果
|
|
|
*/
|
|
|
- public static function validateOrderParams(int $itemId, string $price, int $quantity, string $orderType): array
|
|
|
+ public static function validateOrderParamsForMatching(int $itemId, string $price, int $quantity, string $orderType): array
|
|
|
{
|
|
|
// 验证价格
|
|
|
if ($orderType === 'SELL') {
|
|
|
@@ -287,7 +344,7 @@ class MexPriceConfigLogic
|
|
|
return $priceResult;
|
|
|
}
|
|
|
|
|
|
- // 验证数量(只对买入订单验证)
|
|
|
+ // 验证数量(只对买入订单验证保护阈值)
|
|
|
if ($orderType === 'BUY') {
|
|
|
$quantityResult = self::validateOrderQuantity($itemId, $quantity);
|
|
|
if (!$quantityResult['valid']) {
|
|
|
@@ -297,11 +354,27 @@ class MexPriceConfigLogic
|
|
|
|
|
|
return [
|
|
|
'valid' => true,
|
|
|
- 'message' => '参数验证通过',
|
|
|
+ 'message' => '撮合参数验证通过',
|
|
|
'config' => $priceResult['config']
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量验证价格和数量(已废弃,请使用validateOrderParamsForPlacement或validateOrderParamsForMatching)
|
|
|
+ *
|
|
|
+ * @deprecated 请根据使用场景选择validateOrderParamsForPlacement(挂单)或validateOrderParamsForMatching(撮合)
|
|
|
+ * @param int $itemId 商品ID
|
|
|
+ * @param string $price 价格
|
|
|
+ * @param int $quantity 数量
|
|
|
+ * @param string $orderType 订单类型 (BUY/SELL)
|
|
|
+ * @return array 验证结果
|
|
|
+ */
|
|
|
+ public static function validateOrderParams(int $itemId, string $price, int $quantity, string $orderType): array
|
|
|
+ {
|
|
|
+ // 为了向后兼容,默认使用挂单验证
|
|
|
+ return self::validateOrderParamsForPlacement($itemId, $price, $quantity, $orderType);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取商品价格建议
|
|
|
*
|