shish 3 年之前
父節點
當前提交
f3bf41fef5
共有 1 個文件被更改,包括 38 次插入20 次删除
  1. 38 20
      app-ghs/controllers/RefundController.php

+ 38 - 20
app-ghs/controllers/RefundController.php

@@ -23,6 +23,39 @@ class RefundController extends BaseController
             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);
+        if (empty($productInfo)) {
+            util::fail('没有找到花材');
+        }
+        $ptItemId = $productInfo->itemId ?? 0;
+        $ratio = $productInfo->ratio ?? 20;
+
+        $refundItem = RefundOrderItemClass::getById($refundItemId, true);
+        if (empty($refundItem)) {
+            util::fail('没有找到退货信息');
+        }
+        if ($refundItem->mainId != $this->mainId) {
+            util::fail('不是您的退款信息');
+        }
+        $unitType = $refundItem->xhUnitType ?? 0;
+        if ($unitType == 1) {
+            util::fail('无法报损');
+        }
+        $refundNum = $refundItem->xhNum ?? 0;
+        $hasWasteNum = $refundItem->xhWasteNum ?? 0;
+        $remainNum = bcsub($refundNum, $hasWasteNum);
+        if ($wasteNum > $remainNum) {
+            util::fail('退货剩余报损数量只有:' . $remainNum);
+        }
+
+        $productList = [['productId' => $wasteProductId, 'bigNum' => $wasteNum, 'smallNum' => 0, 'classId' => 0, 'itemId' => $ptItemId, 'ratio' => $ratio]];
+
         $post['shopId'] = $this->shopId;
         $post['sjId'] = $this->sjId;
         $post['mainId'] = $this->mainId;
@@ -30,29 +63,14 @@ class RefundController extends BaseController
         $shopAdmin = $this->shopAdmin;
         $adminName = $shopAdmin['name'] ?? '';
         $post['shopAdminName'] = $adminName;
-        $productJson = $post['product'] ?? '';
-        if (empty($productJson)) {
-            util::fail('请选择花材');
-        }
-        $productList = json_decode($productJson, true);
-        if (empty($productList)) {
-            util::fail('请选择花材');
-        }
-        foreach ($productList as $v) {
-            $bigNum = $v['bigNum'] ?? 0;
-            $smallNum = $v['smallNum'] ?? 0;
-            if ($bigNum <= 0) {
-                util::fail('花材数量不能为0');
-            }
-            if ($smallNum > 0) {
-                util::fail('小单位不能报损');
-            }
-        }
+
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-            //判断花材有效性
-            ProductClass::valid($productList, $this->mainId);
+
+            $refundItem->xhWasteNum = bcadd($refundItem->xhWasteNum, $wasteNum);
+            $refundItem->save();
+
             $post['product'] = $productList;
             $return = StockWastageOrderClass::addOrder($post);
             $transaction->commit();