用户反馈农贸市场模块"挂单成交了,但是没产生订单",经过深入分析发现了两个关键问题。
问题:订单创建时没有冻结用户物品
MexOrderLogic::createSellOrder 只创建订单记录,未冻结物品transferFrozenItemsToWarehouse 期望物品已冻结根据文档要求:
问题:数据库表结构与模型配置不匹配
kku_mex_transactions 表只有 created_at 字段,没有 updated_at 字段created_at 和 updated_at 字段Unknown column 'updated_at' in 'field list'修改 app/Module/Mex/Logic/MexOrderLogic.php:
public static function createSellOrder(int $userId, int $itemId, int $quantity, float $price, ?FUND_CURRENCY_TYPE $currencyType = null): array
{
return DB::transaction(function () use ($userId, $itemId, $quantity, $price, $currencyType, $totalAmount) {
// 1. 验证用户是否有足够的物品
$checkResult = ItemService::checkItemQuantity($userId, $itemId, $quantity);
if (!$checkResult->success) {
return ['success' => false, 'message' => $checkResult->message];
}
// 2. 创建订单记录
$order = MexOrder::create([...]);
// 3. 冻结用户物品
$freezeResult = ItemService::freezeItem(
$userId,
$itemId,
null,
$quantity,
"农贸市场卖出订单冻结,订单ID:{$order->id}",
[
'reason_type' => FREEZE_REASON_TYPE::TRADE_ORDER->value,
'source_id' => $order->id,
'source_type' => 'mex_sell_order',
]
);
if (!$freezeResult['success']) {
throw new \Exception('冻结物品失败:' . $freezeResult['message']);
}
return ['success' => true, 'order_id' => $order->id, ...];
});
}
修改 app/Module/Mex/Models/MexTransaction.php:
class MexTransaction extends ModelCore
{
protected $table = 'mex_transactions';
// 禁用updated_at字段的自动管理,因为表中只有created_at字段
public const UPDATED_AT = null;
// ... 其他配置
}
$result = MexOrderService::createSellOrder(39068, 3, 50, 10.00000, FUND_CURRENCY_TYPE::ZUANSHI);
// 结果:成功创建订单64,物品正确冻结
php artisan mex:user-sell-item-match --item=3
撮合结果:
根据文档第26行和第150行:
MexMatchService 正确使用 DB::transaction() 包装撮合逻辑ItemService::consumeItem 需要在事务中执行(Helper::check_tr() 验证){
"id": 17,
"buy_order_id": null,
"sell_order_id": 64,
"buyer_id": 15,
"seller_id": 39068,
"item_id": 3,
"currency_type": 2,
"quantity": 50,
"price": "10.00000",
"total_amount": "500.00000",
"transaction_type": "USER_SELL",
"is_admin_operation": 0,
"created_at": "2025-06-19T10:20:10.000Z"
}
✅ 问题完全解决:
✅ 系统完整性:
现在农贸市场的挂单撮合功能完全正常,用户卖出订单能够正确成交并产生对应的成交记录。