Commit b7d99b6f authored by pengfei's avatar pengfei

Merge branch 'feature_optimize_order_create_refund' of...

Merge branch 'feature_optimize_order_create_refund' of https://git.yidian-inc.com:8021/bp/goods into feature_optimize_order_create_refund
parents dc0dc70b 7d245881
......@@ -19,6 +19,7 @@ class GoodsException extends BaseException
const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54;
const PRINTER_SN_ERROR = 55;
const PARAMS_NULL_ERROR = 56;
protected $cus = [
0 => '商品创建失败,请稍后重试',
......@@ -77,5 +78,6 @@ class GoodsException extends BaseException
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定',
self::PRINTER_BIND_ERROR => '打印机绑定失败:%s',
self::PRINTER_SN_ERROR => '打印机sn号码有误',
self:: PARAMS_NULL_ERROR => '参数不能为空',
];
}
\ No newline at end of file
......@@ -314,7 +314,7 @@ class GoodsController extends Base
*/
public function refundAction()
{
(new RefundGoodsValidate())->validate();
//(new RefundGoodsValidate())->validate();
$params = $this->params;
$res = GoodsService::refundGoods($params);
$this->success(["result" => $res]);
......
......@@ -1936,18 +1936,26 @@ class GoodsService
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
public static function refundGoods($dataJson)
{
$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);
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
foreach ($dataJson as $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")) {
$refundGoodsData[] = $params;
}
} else {
throw new GoodsException(["cus" => 41]);
}
} else {
throw new GoodsException(["cus" => 41]);
}
return true;
if (empty($refundGoodsData)){
return true;
}
return MarketingPindanGoodsService::refundGoods($refundGoodsData);
}
/**
......
......@@ -471,55 +471,55 @@ class MarketingPindanGoodsService
}
/**
* 退款拼单商品,库存调整
* 退款拼单商品,库存调整 (批量退库存)
* @param $params
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
public static function refundGoods($dataJson)
{
$sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]);
if (empty($sku)) {
throw new GoodsException(["cus" => 15]);
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
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([
foreach ($dataJson as $params){
$sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]);
if (empty($sku)) {
throw new GoodsException(["cus" => 15]);
}
$records = GoodsRefundRecord::getRecordMaster([
"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[-]" => $params["num"],
"total_amount_order[-]" => $params["num"],
"inventory_rest[+]" => $params["num"],
], ["goods_sku_id" => $sku["goods_sku_id"], "total_amount_sold[>=]" => $params["num"], "total_amount_order[>=]" => $params["num"]]);
FileLog::info('goods_refund_log', 'json decode error raw:' . json_encode($params));
if ($row < 1){
PindanGoodsSku::rollback();
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_FAILURE
"operator_result" => GoodsRefundRecord::OPERATOR_RESULT_SUCCESS
]);
throw new GoodsException(["cus" => 0]);
$row = PindanGoodsSku::save([
"total_amount_sold[-]" => $params["num"],
"total_amount_order[-]" => $params["num"],
"inventory_rest[+]" => $params["num"],
], ["goods_sku_id" => $sku["goods_sku_id"], "total_amount_sold[>=]" => $params["num"], "total_amount_order[>=]" => $params["num"]]);
FileLog::info('goods_refund_log', 'json decode error raw:' . json_encode($params));
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]);
......
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