|
|
@@ -3,6 +3,7 @@
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
use bizGhs\notify\classes\NotifyClass;
|
|
|
+use bizGhs\order\classes\CheckOrderClass;
|
|
|
use bizGhs\order\classes\RefundOrderItemClass;
|
|
|
use bizGhs\order\services\RefundOrderService;
|
|
|
use bizGhs\shop\classes\ShopClass;
|
|
|
@@ -289,27 +290,81 @@ class RefundController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //退款之后报损 ssh 20230409
|
|
|
- public function actionRefundWaste()
|
|
|
+ //售后之后减少库存 ssh 20250912
|
|
|
+ public function actionReduceStock()
|
|
|
{
|
|
|
$shopAdmin = $this->shopAdmin;
|
|
|
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
|
|
|
- util::fail('超管才能报损');
|
|
|
+ if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
|
|
|
+ util::fail('管理员才能报损');
|
|
|
}
|
|
|
$post = Yii::$app->request->post();
|
|
|
$refundItemId = $post['refundItemId'] ?? 0;
|
|
|
- $wasteProductId = $post['wasteProductId'] ?? 0;
|
|
|
- $wasteNum = $post['wasteNum'] ?? 0;
|
|
|
- unset($post['refundId']);
|
|
|
- unset($post['wasteNum']);
|
|
|
- unset($post['wasteProductId']);
|
|
|
- $productInfo = ProductClass::getById($wasteProductId, true);
|
|
|
+ $refundItem = RefundOrderItemClass::getById($refundItemId, true);
|
|
|
+ if (empty($refundItem)) {
|
|
|
+ util::fail('没有找到退货信息');
|
|
|
+ }
|
|
|
+ if ($refundItem->mainId != $this->mainId) {
|
|
|
+ util::fail('不是您的退款信息');
|
|
|
+ }
|
|
|
+ $reduceProductId = $refundItem->productId ?? 0;
|
|
|
+ $reduceNum = $post['reduceNum'] ?? 0;
|
|
|
+ $productInfo = ProductClass::getById($reduceProductId, true);
|
|
|
if (empty($productInfo)) {
|
|
|
util::fail('没有找到花材');
|
|
|
}
|
|
|
- $ptItemId = $productInfo->itemId ?? 0;
|
|
|
- $ratio = $productInfo->ratio ?? 20;
|
|
|
+ if ($productInfo->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的花材');
|
|
|
+ }
|
|
|
+ $unitType = $refundItem->xhUnitType ?? 0;
|
|
|
+ if ($unitType == 1) {
|
|
|
+ util::fail('小单位,无法减库存');
|
|
|
+ }
|
|
|
+ $refundNum = $refundItem->xhNum ?? 0;
|
|
|
+ $hasReduceNum = $refundItem->xhReduceNum ?? 0;
|
|
|
+ $remainNum = bcsub($refundNum, $hasReduceNum);
|
|
|
+ if ($reduceNum > $remainNum) {
|
|
|
+ util::fail('剩余可减数量 ' . $remainNum);
|
|
|
+ }
|
|
|
+ $stock = $productInfo->stock ?? 0;
|
|
|
+ if ($reduceNum > $stock) {
|
|
|
+ util::fail('库存不足了');
|
|
|
+ }
|
|
|
+ $orderSn = $refundItem->orderSn ?? '';
|
|
|
+ $bigNum = bcsub($stock, $reduceNum);
|
|
|
+
|
|
|
+ $refundItem->xhReduceNum = bcadd($refundItem->xhReduceNum, $reduceNum);
|
|
|
+ $refundItem->save();
|
|
|
|
|
|
+ $shop = $this->shop;
|
|
|
+ $sjId = $shop->sjId ?? 0;
|
|
|
+ $shopId = $shop->id ?? 0;
|
|
|
+ $mainId = $shop->mainId ?? 0;
|
|
|
+ $adminId = $this->adminId;
|
|
|
+ $staff = $this->shopAdmin;
|
|
|
+ $staffName = $staff->name ?? '';
|
|
|
+ $params = [
|
|
|
+ 'pdType' => '',
|
|
|
+ 'itemInfo' => [['productId' => $reduceProductId, 'bigNum' => $bigNum, 'smallNum' => '']],
|
|
|
+ 'remark' => '售后' . $orderSn . '直接减少库存',
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'adminId' => $adminId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ ];
|
|
|
+ CheckOrderClass::opOrder($params);
|
|
|
+ util::complete('操作成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //退款之后报损 ssh 20230409
|
|
|
+ public function actionRefundWaste()
|
|
|
+ {
|
|
|
+ $shopAdmin = $this->shopAdmin;
|
|
|
+ if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
|
|
|
+ util::fail('管理员才能报损');
|
|
|
+ }
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $refundItemId = $post['refundItemId'] ?? 0;
|
|
|
$refundItem = RefundOrderItemClass::getById($refundItemId, true);
|
|
|
if (empty($refundItem)) {
|
|
|
util::fail('没有找到退货信息');
|
|
|
@@ -319,8 +374,21 @@ class RefundController extends BaseController
|
|
|
}
|
|
|
$unitType = $refundItem->xhUnitType ?? 0;
|
|
|
if ($unitType == 1) {
|
|
|
- util::fail('无法报损');
|
|
|
+ util::fail('小单位,无法报损');
|
|
|
}
|
|
|
+
|
|
|
+ $wasteProductId = $refundItem->productId ?? 0;
|
|
|
+ $wasteNum = $post['wasteNum'] ?? 0;
|
|
|
+ unset($post['refundItemId']);
|
|
|
+ unset($post['wasteNum']);
|
|
|
+ unset($post['wasteProductId']);
|
|
|
+ $productInfo = ProductClass::getById($wasteProductId, true);
|
|
|
+ if (empty($productInfo)) {
|
|
|
+ util::fail('没有找到花材');
|
|
|
+ }
|
|
|
+ $ptItemId = $productInfo->itemId ?? 0;
|
|
|
+ $ratio = $productInfo->ratio ?? 20;
|
|
|
+
|
|
|
$refundNum = $refundItem->xhNum ?? 0;
|
|
|
$hasWasteNum = $refundItem->xhWasteNum ?? 0;
|
|
|
$remainNum = bcsub($refundNum, $hasWasteNum);
|
|
|
@@ -334,7 +402,6 @@ class RefundController extends BaseController
|
|
|
$post['sjId'] = $this->sjId;
|
|
|
$post['mainId'] = $this->mainId;
|
|
|
$post['shopAdminId'] = $this->shopAdminId;
|
|
|
- $shopAdmin = $this->shopAdmin;
|
|
|
$adminName = $shopAdmin['name'] ?? '';
|
|
|
$post['shopAdminName'] = $adminName;
|
|
|
//属于售后报损
|