Commit e2af1318 authored by cuiweifeng's avatar cuiweifeng

update tcc goods rollback fix

parent 1f5ca56c
......@@ -63,5 +63,6 @@ class GoodsException extends BaseException
44 => '事务commit失败',
45 => '还没有try,就去执行confirm',
46 => '已经执行过cancel',
47 => 'sku rollback error',
];
}
\ No newline at end of file
......@@ -545,20 +545,15 @@ class Tcc2Service
if (!empty($goodsInfoList)) {
PindanGoodsSku::beginTransaction();
foreach ($goodsInfoList as $item) {
$goodsSkuId = $item["goods_sku_id"];
$num = $item["num"];
$sku = PindanGoodsSku::getRecord(["goods_sku_id" => $goodsSkuId]
, ["goods_sku_id", "total_amount_order", "inventory_rest", "inventory_lock", "online_status"]);
$params = [
"inventory_rest" => $sku["inventory_rest"] + $num,
"total_amount_order" => $sku["total_amount_order"] - $num,
"inventory_rest[+]" => $num,
"total_amount_order[-]" => $num,
];
$rowCount = PindanGoodsSku::save($params, ["goods_sku_id" => $goodsSkuId, "total_amount_order[>=]" => $num]);
$rowCount = PindanGoodsSku::save($params, ["goods_sku_id" => $item["goods_sku_id"]]);
if ($rowCount <= 0) {
PindanGoodsSku::rollback();
throw new GoodsException(["cus" => 32]);
throw new GoodsException(["cus" => 47]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment