Commit 523222ef authored by luhongguang's avatar luhongguang

update:tcc cancel逻辑调整

parent c37e14a6
<?php
namespace Validate;
/**
* Class GoodsTccCancelValidate
*
* @package Validate
*/
class GoodsTccCancelValidate extends BaseValidate
{
protected $rule = [
'tid' => 'require',
'keys' => 'require',
'type' => 'require',
];
protected $message = [
"tid" => "tcc事务id不能为空",
"keys" => "商品信息不能为空",
"type" => "类型字段不能为空",
];
}
\ No newline at end of file
...@@ -4,6 +4,7 @@ use App\Base\Base; ...@@ -4,6 +4,7 @@ use App\Base\Base;
use App\Exception\custom\GoodsException; use App\Exception\custom\GoodsException;
use \Validate\GoodsTccValidate; use \Validate\GoodsTccValidate;
use \Validate\GoodsTccIsFinishValidate; use \Validate\GoodsTccIsFinishValidate;
use \Validate\GoodsTccCancelValidate;
use \App\Services\tcc\TccService; use \App\Services\tcc\TccService;
...@@ -84,9 +85,9 @@ class TccController extends Base ...@@ -84,9 +85,9 @@ class TccController extends Base
*/ */
public function cancel_order_confirmAction() public function cancel_order_confirmAction()
{ {
(new GoodsTccValidate())->validate(); (new GoodsTccCancelValidate())->validate();
$res = TccService::cancelOrderConfirm($this->params["keys"], $this->params["tid"]); $res = TccService::cancelOrderConfirm($this->params["keys"], $this->params["tid"], $this->params["type"]);
if ($res) { if ($res) {
$this->success(); $this->success();
} else { } else {
......
...@@ -14,6 +14,9 @@ class TccService ...@@ -14,6 +14,9 @@ class TccService
const TCC_RESULT_FAIL = false; const TCC_RESULT_FAIL = false;
const TCC_RESULT_SUCCESS = true; const TCC_RESULT_SUCCESS = true;
const TYPE_CANCEL_ORDER = 1;
const TYPE_BACK_ORDER = 2;
/** /**
* 下单 商品tcc try * 下单 商品tcc try
* @param $keys * @param $keys
...@@ -482,9 +485,10 @@ class TccService ...@@ -482,9 +485,10 @@ class TccService
* 取消订单单 商品tcc confirm * 取消订单单 商品tcc confirm
* @param $keys * @param $keys
* @param $tid * @param $tid
* @param $type
* @return int * @return int
*/ */
public static function cancelOrderConfirm($keys, $tid) public static function cancelOrderConfirm($keys, $tid, $type)
{ {
$goodsInfoList = json_decode($keys, true); $goodsInfoList = json_decode($keys, true);
if (empty($goodsInfoList)) { if (empty($goodsInfoList)) {
...@@ -546,7 +550,7 @@ class TccService ...@@ -546,7 +550,7 @@ class TccService
} }
$skus = GoodsSku::getRecords(["goods_sku_id" => $goodsSkuIds] $skus = GoodsSku::getRecords(["goods_sku_id" => $goodsSkuIds]
, ["goods_sku_id", "inventory_rest", "inventory_lock", "online_status"]); , ["goods_sku_id", "total_amount_sold", "inventory_rest", "inventory_lock", "online_status"]);
if (!empty($skus)) { if (!empty($skus)) {
GoodsSku::beginTransaction(); GoodsSku::beginTransaction();
foreach ($skus as $sku) { foreach ($skus as $sku) {
...@@ -563,10 +567,25 @@ class TccService ...@@ -563,10 +567,25 @@ class TccService
return self::TCC_RESULT_FAIL; return self::TCC_RESULT_FAIL;
} }
GoodsSku::save([ if ($type == self::TYPE_CANCEL_ORDER) {
"inventory_lock" => $sku["inventory_lock"] - $num, $params = [
"inventory_rest" => $sku["inventory_rest"] + $num, "inventory_lock" => $sku["inventory_lock"] - $num,
], ["goods_sku_id" => $goodsSkuId]); "inventory_rest" => $sku["inventory_rest"] + $num,
];
}
if ($type == self::TYPE_BACK_ORDER) {
if ($sku["total_amount_sold"] < $num) {
GoodsSku::rollback();
return self::TCC_RESULT_FAIL;
}
$params = [
"inventory_lock" => $sku["inventory_lock"] - $num,
"inventory_rest" => $sku["inventory_rest"] + $num,
"total_amount_sold" => $sku["total_amount_sold"] - $num,
];
}
GoodsSku::save($params, ["goods_sku_id" => $goodsSkuId]);
Tcc::save([ Tcc::save([
"tid" => $tid, "tid" => $tid,
......
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