Commit aa0ce40f authored by luhongguang's avatar luhongguang

update: 商品取消库存退回

parent 0412d525
...@@ -67,6 +67,8 @@ class TccController extends Base ...@@ -67,6 +67,8 @@ class TccController extends Base
$res = Tcc2Service::cancelConfirm($this->params["keys"]); $res = Tcc2Service::cancelConfirm($this->params["keys"]);
if ($res) { if ($res) {
$this->success(); $this->success();
} else {
throw new GoodsException(["cus" => 27]);
} }
} }
} }
\ No newline at end of file
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
namespace App\Services\tcc; namespace App\Services\tcc;
use Api\PhpUtils\Common\GoodsSkuId;
use App\Exception\custom\GoodsException; use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\GoodsSku; use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\PindanGoodsSku; use App\Models\goods\mysql\PindanGoodsSku;
use App\Models\goods\mysql\Tcc; use App\Models\goods\mysql\Tcc;
use App\Models\marketing\mysql\Marketing; use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingPindan; use App\Models\marketing\mysql\MarketingPindan;
use App\Services\goods\MarketingPindanGoodsService;
class Tcc2Service class Tcc2Service
{ {
...@@ -478,25 +480,42 @@ class Tcc2Service ...@@ -478,25 +480,42 @@ class Tcc2Service
return self::TCC_RESULT_FAIL; return self::TCC_RESULT_FAIL;
} }
$goodsSkuIds = $numList = []; $isPindan = false;
foreach ($goodsInfoList as $item) { foreach ($goodsInfoList as $item) {
if (empty($item["goods_sku_id"]) || empty($item["num"])) { if (empty($item["goods_sku_id"]) || empty($item["num"])) {
return self::TCC_RESULT_FAIL; return self::TCC_RESULT_FAIL;
} }
$goodsSkuIds[] = $item["goods_sku_id"]; $goodsSukParams = GoodsSkuId::getGoodsSkuIdParams($item["goods_sku_id"]);
$numList[$item["goods_sku_id"]] = $item["num"]; if (!empty($goodsSukParams)) {
if (isset($goodsSukParams["table_tag"]) && ($goodsSukParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN)) {
$isPindan = true;
}
}
} }
$skus = GoodsSku::getRecords(["goods_sku_id" => $goodsSkuIds] if ($isPindan) {
, ["goods_sku_id", "total_amount_order", "inventory_rest", "inventory_lock", "online_status"]); return self::pindanCancelConfirm($goodsInfoList);
if (!empty($skus)) { } else {
return self::generalCancelConfirm($goodsInfoList);
}
}
/**
* 普通订单退库存
* @param $goodsInfoList
* @return bool
* @throws GoodsException
*/
private static function generalCancelConfirm($goodsInfoList)
{
if (!empty($goodsInfoList)) {
GoodsSku::beginTransaction(); GoodsSku::beginTransaction();
foreach ($skus as $sku) { foreach ($goodsInfoList as $item) {
$goodsSkuId = $sku["goods_sku_id"]; $goodsSkuId = $item["goods_sku_id"];
if (empty($numList[$goodsSkuId])) { $num = $item["num"];
return self::TCC_RESULT_FAIL;
} $sku = GoodsSku::getRecord(["goods_sku_id" => $goodsSkuId]
$num = $numList[$goodsSkuId]; , ["goods_sku_id", "total_amount_order", "inventory_rest", "inventory_lock", "online_status"]);
$params = [ $params = [
"inventory_rest" => $sku["inventory_rest"] + $num, "inventory_rest" => $sku["inventory_rest"] + $num,
"total_amount_order" => $sku["total_amount_order"] - $num, "total_amount_order" => $sku["total_amount_order"] - $num,
...@@ -515,6 +534,41 @@ class Tcc2Service ...@@ -515,6 +534,41 @@ class Tcc2Service
return self::TCC_RESULT_SUCCESS; return self::TCC_RESULT_SUCCESS;
} }
/**
* 拼单活动取消订单退库存
* @param $goodsInfoList
* @return bool
* @throws GoodsException
*/
private static function pindanCancelConfirm($goodsInfoList)
{
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,
];
$rowCount = PindanGoodsSku::save($params, ["goods_sku_id" => $goodsSkuId, "total_amount_order[>=]" => $num]);
if ($rowCount <= 0) {
PindanGoodsSku::rollback();
throw new GoodsException(["cus" => 32]);
}
}
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
}
}
return self::TCC_RESULT_SUCCESS;
}
/** /**
* 获取 tcc 数据记录 * 获取 tcc 数据记录
* @param $tid * @param $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