Commit 745702c5 authored by luhongguang's avatar luhongguang

update:退单商品库存处理

parent 453da3a2
<?php
namespace Validate;
/**
* Class RefundGoodsValidate
*
* @package Validate
*/
class RefundGoodsValidate extends BaseValidate
{
protected $rule = [
'goods_sku_id' => 'require',
'order_id' => 'require',
'order_item_id' => 'require',
'num' => 'require',
];
protected $message = [
"goods_sku_id" => "goods_sku_id 不能为空",
"order_id" => "order_id 不能为空",
"order_item_id" => "order_item_id 不能为空",
"num" => "num 不能为空",
];
}
\ No newline at end of file
<?php
namespace App\Models\goods\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
/**
* Class GoodsRefundRecord
* 商品退款记录
* @package App\Models\goods\mysql
*/
class GoodsRefundRecord extends MysqlBase
{
const TABLE_NAME = 'goods_refund_record';
const CONFIG_INDEX = 'goods';
const OPERATOR_RESULT_FAILURE = 0;
const OPERATOR_RESULT_SUCCESS = 1;
public static function getRecord($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::get($columns, $where);
}
public static function getRecordMaster($where, $columns = [])
{
if (empty($columns)) {
$columns = '*';
}
return self::selectMaster($columns, $where);
}
public static function save($data, $where = [])
{
if (empty($where)) {
return self::insert($data);
}
return self::update($data, $where);
}
public static function deleteRecord($where)
{
return self::delete($where);
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ use \Validate\GoodsInfoOpValidate;
use \Validate\GoodsInfoFeValidate;
use \Validate\GoodsListCValidate;
use \Validate\OrderGoodsValidate;
use \Validate\RefundGoodsValidate;
use \Validate\GoodsOnlineOfflineValidate;
use \Validate\PaySuccessGoodsCallbackValidate;
use \Validate\GoodsInitShopValidate;
......@@ -289,4 +290,16 @@ class GoodsController extends Base
$list = MarketingPindanGoodsService::getPindanGoodsList($params);
$this->success(["result" => $list]);
}
/**
* 拼单商品退款商品逻辑
* @throws Exception
*/
public function refundAction()
{
(new RefundGoodsValidate())->validate();
$params = $this->params;
$res = GoodsService::refundGoods($params);
$this->success(["result" => $res]);
}
}
\ No newline at end of file
......@@ -1689,4 +1689,24 @@ class GoodsService
return self::addShop($lifeAccount);
}
/**
* 退款拼单商品,库存调整
* @param $params
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
{
$goodsSukParams = GoodsSkuId::getGoodsSkuIdParams($params["goods_sku_id"]);
if (!empty($goodsSukParams)) {
if (isset($goodsSukParams["table_tag"]) && ($goodsSukParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN
|| $goodsSukParams["category_1_id"] == "00")) {
return MarketingPindanGoodsService::refundGoods($params);
}
} else {
throw new GoodsException(["cus" => 41]);
}
return true;
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ use Api\PhpUtils\Http\HttpUtil;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Category;
use App\Models\goods\mysql\GoodsOperationRecord;
use App\Models\goods\mysql\GoodsRefundRecord;
use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\GoodsSkuPicRecord;
use App\Models\goods\mysql\GoodsSkuSubShop;
......@@ -452,4 +453,59 @@ class MarketingPindanGoodsService
}
return $data;
}
/**
* 退款拼单商品,库存调整
* @param $params
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
{
$sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]);
if (empty($sku)) {
throw new GoodsException(["cus" => 15]);
}
PindanGoodsSku::beginTransaction();
$records = GoodsRefundRecord::getRecordMaster([
"goods_sku_id" => $params["goods_sku_id"],
"order_item_id" => $params["order_item_id"],
"operator_result" => GoodsRefundRecord::OPERATOR_RESULT_SUCCESS
]);
if (empty($records)) {
GoodsRefundRecord::save([
"goods_sku_id" => $params["goods_sku_id"],
"order_id" => $params["order_id"],
"order_item_id" => $params["order_item_id"],
"num" => $params["num"],
"operator_result" => GoodsRefundRecord::OPERATOR_RESULT_SUCCESS
]);
$row = PindanGoodsSku::save([
"total_amount_sold" => $sku["total_amount_sold"] - $params["num"],
"total_amount_order" => $sku["total_amount_order"] - $params["num"],
"inventory_rest" => $sku["inventory_rest"] + $params["num"],
], ["goods_sku_id" => $sku["goods_sku_id"], "total_amount_sold[>=]" => $params["num"], "total_amount_order[>=]" => $params["num"]]);
if ($row < 1){
PindanGoodsSku::rollback();
GoodsRefundRecord::save([
"goods_sku_id" => $params["goods_sku_id"],
"order_id" => $params["order_id"],
"order_item_id" => $params["order_item_id"],
"num" => $params["num"],
"operator_result" => GoodsRefundRecord::OPERATOR_RESULT_FAILURE
]);
throw new GoodsException(["cus" => 0]);
}
}
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
throw new GoodsException(["cus" => 0]);
}
return true;
}
}
\ No newline at end of file
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