Commit 80cad87e authored by luhongguang's avatar luhongguang

update:goods tcc 提示修改

parent 8fc82418
......@@ -58,5 +58,10 @@ class GoodsException extends BaseException
39 => '结算价不能大于售价',
40 => '结算价不符合标准',
41 => '商品id非法',
42 => 'TCC 参数错误',
43 => 'TCC 商品非上架状态',
44 => 'TCC 事务commit失败',
45 => 'TCC 还没有try,就去执行confirm',
46 => 'TCC 已经执行过cancel',
];
}
\ No newline at end of file
......@@ -24,13 +24,13 @@ class Tcc2Service
{
$goodsInfoList = json_decode($keys, true);
if (empty($goodsInfoList)) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
$isPindan = false;
foreach ($goodsInfoList as $item) {
if (empty($item["goods_sku_id"]) || empty($item["num"])) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
if (!empty($item["marketing_id"]) && !empty($item["marketing_type"]) && $item["marketing_type"] == Marketing::MARKETING_TYPE_PINDAN) {
$isPindan = true;
......@@ -84,7 +84,7 @@ class Tcc2Service
}
} else {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 43]);
}
}
Tcc::save([
......@@ -95,7 +95,7 @@ class Tcc2Service
if (!GoodsSku::commit()) {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......@@ -131,7 +131,7 @@ class Tcc2Service
}
} else {
PindanGoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 43]);
}
}
Tcc::save([
......@@ -142,7 +142,7 @@ class Tcc2Service
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......@@ -161,13 +161,13 @@ class Tcc2Service
{
$goodsInfoList = json_decode($keys, true);
if (empty($goodsInfoList)) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
$isPindan = false;
foreach ($goodsInfoList as $item) {
if (empty($item["goods_sku_id"]) || empty($item["num"])) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
if (!empty($item["marketing_id"]) && !empty($item["marketing_type"]) && $item["marketing_type"] == Marketing::MARKETING_TYPE_PINDAN) {
$isPindan = true;
......@@ -181,12 +181,12 @@ class Tcc2Service
}
//在confirm时候必须已经有try,如果没有就直接返回fail
if (!empty($tccInfo["status"]) && !in_array($tccInfo["status"], [Tcc::STATUS_T_SUCCESS])) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 45]);
}
//如果已经 cancel 成功, 则失败
if (!empty($tccInfo["status"]) && in_array($tccInfo["status"], [Tcc::STATUS_C2_SUCCESS])) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 46]);
}
if ($isPindan) {
......@@ -226,14 +226,14 @@ class Tcc2Service
}
} else {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 43]);
}
}
Tcc::save(["status" => Tcc::STATUS_C1_SUCCESS,], ["tid" => $tid]);
if (!GoodsSku::commit()) {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......@@ -258,7 +258,6 @@ class Tcc2Service
, ["goods_sku_id", "inventory_rest", "total_amount_order", "inventory_lock", "online_status"]);
if (!empty($sku["inventory_lock"]) && $sku["online_status"] == PindanGoodsSku::ONLINE_STATUS_ONLINE) {
//条件加上乐观锁
$rowCount = PindanGoodsSku::save([
"inventory_lock" => $sku["inventory_lock"] - $num,
......@@ -270,14 +269,14 @@ class Tcc2Service
}
} else {
PindanGoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 43]);
}
}
Tcc::save(["status" => Tcc::STATUS_C1_SUCCESS,], ["tid" => $tid]);
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......@@ -295,13 +294,13 @@ class Tcc2Service
{
$goodsInfoList = json_decode($keys, true);
if (empty($goodsInfoList)) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
$isPindan = false;
foreach ($goodsInfoList as $item) {
if (empty($item["goods_sku_id"]) || empty($item["num"])) {
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 42]);
}
if (!empty($item["marketing_id"]) && !empty($item["marketing_type"]) && $item["marketing_type"] == Marketing::MARKETING_TYPE_PINDAN) {
$isPindan = true;
......@@ -379,7 +378,7 @@ class Tcc2Service
if (!GoodsSku::commit()) {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......@@ -433,7 +432,7 @@ class Tcc2Service
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
return self::TCC_RESULT_FAIL;
throw new GoodsException(["cus" => 44]);
}
}
......
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