Commit 898c4e52 authored by jianghaiming's avatar jianghaiming

update:修改批量退款退库存

parent 5d6b8571
...@@ -19,6 +19,7 @@ class GoodsException extends BaseException ...@@ -19,6 +19,7 @@ class GoodsException extends BaseException
const LABEL_PRINTER_ALREADY_EXIST = 53; const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54; const PRINTER_BIND_ERROR = 54;
const PRINTER_SN_ERROR = 55; const PRINTER_SN_ERROR = 55;
const PARAMS_NULL_ERROR = 56;
protected $cus = [ protected $cus = [
0 => '商品创建失败,请稍后重试', 0 => '商品创建失败,请稍后重试',
...@@ -77,5 +78,6 @@ class GoodsException extends BaseException ...@@ -77,5 +78,6 @@ class GoodsException extends BaseException
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定', self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定',
self::PRINTER_BIND_ERROR => '打印机绑定失败:%s', self::PRINTER_BIND_ERROR => '打印机绑定失败:%s',
self::PRINTER_SN_ERROR => '打印机sn号码有误', self::PRINTER_SN_ERROR => '打印机sn号码有误',
self:: PARAMS_NULL_ERROR => '参数不能为空',
]; ];
} }
\ No newline at end of file
...@@ -314,7 +314,7 @@ class GoodsController extends Base ...@@ -314,7 +314,7 @@ class GoodsController extends Base
*/ */
public function refundAction() public function refundAction()
{ {
(new RefundGoodsValidate())->validate(); //(new RefundGoodsValidate())->validate();
$params = $this->params; $params = $this->params;
$res = GoodsService::refundGoods($params); $res = GoodsService::refundGoods($params);
$this->success(["result" => $res]); $this->success(["result" => $res]);
......
...@@ -1936,19 +1936,27 @@ class GoodsService ...@@ -1936,19 +1936,27 @@ class GoodsService
* @return bool * @return bool
* @throws GoodsException * @throws GoodsException
*/ */
public static function refundGoods($params) public static function refundGoods($dataJson)
{ {
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
foreach ($dataJson as $params){
$goodsSukParams = GoodsSkuId::getGoodsSkuIdParams($params["goods_sku_id"]); $goodsSukParams = GoodsSkuId::getGoodsSkuIdParams($params["goods_sku_id"]);
if (!empty($goodsSukParams)) { if (!empty($goodsSukParams)) {
if (isset($goodsSukParams["table_tag"]) && ($goodsSukParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN if (isset($goodsSukParams["table_tag"]) && ($goodsSukParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN
|| $goodsSukParams["category_1_id"] == "00")) { || $goodsSukParams["category_1_id"] == "00")) {
return MarketingPindanGoodsService::refundGoods($params); $refundGoodsData[] = $params;
} }
} else { } else {
throw new GoodsException(["cus" => 41]); throw new GoodsException(["cus" => 41]);
} }
}
if (empty($refundGoodsData)){
return true; return true;
} }
return MarketingPindanGoodsService::refundGoods($refundGoodsData);
}
/** /**
* 通过goods_sku_id 获取 拼单商品的ota信息 * 通过goods_sku_id 获取 拼单商品的ota信息
......
...@@ -471,20 +471,22 @@ class MarketingPindanGoodsService ...@@ -471,20 +471,22 @@ class MarketingPindanGoodsService
} }
/** /**
* 退款拼单商品,库存调整 * 退款拼单商品,库存调整 (批量退库存)
* @param $params * @param $params
* @return bool * @return bool
* @throws GoodsException * @throws GoodsException
*/ */
public static function refundGoods($params) public static function refundGoods($dataJson)
{ {
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
PindanGoodsSku::beginTransaction();
foreach ($dataJson as $params){
$sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]); $sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]);
if (empty($sku)) { if (empty($sku)) {
throw new GoodsException(["cus" => 15]); throw new GoodsException(["cus" => 15]);
} }
PindanGoodsSku::beginTransaction();
$records = GoodsRefundRecord::getRecordMaster([ $records = GoodsRefundRecord::getRecordMaster([
"goods_sku_id" => $params["goods_sku_id"], "goods_sku_id" => $params["goods_sku_id"],
"order_item_id" => $params["order_item_id"], "order_item_id" => $params["order_item_id"],
...@@ -504,9 +506,7 @@ class MarketingPindanGoodsService ...@@ -504,9 +506,7 @@ class MarketingPindanGoodsService
"total_amount_order[-]" => $params["num"], "total_amount_order[-]" => $params["num"],
"inventory_rest[+]" => $params["num"], "inventory_rest[+]" => $params["num"],
], ["goods_sku_id" => $sku["goods_sku_id"], "total_amount_sold[>=]" => $params["num"], "total_amount_order[>=]" => $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)); FileLog::info('goods_refund_log', 'json decode error raw:' . json_encode($params));
if ($row < 1){ if ($row < 1){
PindanGoodsSku::rollback(); PindanGoodsSku::rollback();
GoodsRefundRecord::save([ GoodsRefundRecord::save([
...@@ -519,7 +519,7 @@ class MarketingPindanGoodsService ...@@ -519,7 +519,7 @@ class MarketingPindanGoodsService
throw new GoodsException(["cus" => 0]); throw new GoodsException(["cus" => 0]);
} }
} }
}
if (!PindanGoodsSku::commit()) { if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback(); PindanGoodsSku::rollback();
throw new GoodsException(["cus" => 0]); 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