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;
use App\Exception\custom\GoodsException;
use \Validate\GoodsTccValidate;
use \Validate\GoodsTccIsFinishValidate;
use \Validate\GoodsTccCancelValidate;
use \App\Services\tcc\TccService;
......@@ -84,9 +85,9 @@ class TccController extends Base
*/
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) {
$this->success();
} else {
......
......@@ -14,6 +14,9 @@ class TccService
const TCC_RESULT_FAIL = false;
const TCC_RESULT_SUCCESS = true;
const TYPE_CANCEL_ORDER = 1;
const TYPE_BACK_ORDER = 2;
/**
* 下单 商品tcc try
* @param $keys
......@@ -482,9 +485,10 @@ class TccService
* 取消订单单 商品tcc confirm
* @param $keys
* @param $tid
* @param $type
* @return int
*/
public static function cancelOrderConfirm($keys, $tid)
public static function cancelOrderConfirm($keys, $tid, $type)
{
$goodsInfoList = json_decode($keys, true);
if (empty($goodsInfoList)) {
......@@ -546,7 +550,7 @@ class TccService
}
$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)) {
GoodsSku::beginTransaction();
foreach ($skus as $sku) {
......@@ -563,10 +567,25 @@ class TccService
return self::TCC_RESULT_FAIL;
}
GoodsSku::save([
"inventory_lock" => $sku["inventory_lock"] - $num,
"inventory_rest" => $sku["inventory_rest"] + $num,
], ["goods_sku_id" => $goodsSkuId]);
if ($type == self::TYPE_CANCEL_ORDER) {
$params = [
"inventory_lock" => $sku["inventory_lock"] - $num,
"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([
"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