shish před 3 roky
rodič
revize
ccf5d7ae10

+ 44 - 4
app-ghs/controllers/RefundController.php

@@ -18,10 +18,50 @@ class RefundController extends BaseController
     //退款之后报损 ssh 20230409
     public function actionRefundWaste()
     {
-        //product: [{"productId":"25842","bigNum":1,"smallNum":0,"classId":"3173","itemId":"1007","ratio":"20"}]
-        //remark:
-        $data = [];
-        //$return = StockWastageOrderClass::addOrder($data);
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能报损');
+        }
+        $post = Yii::$app->request->post();
+        $post['shopId'] = $this->shopId;
+        $post['sjId'] = $this->sjId;
+        $post['mainId'] = $this->mainId;
+        $post['shopAdminId'] = $this->shopAdminId;
+        $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);
+            $post['product'] = $productList;
+            $return = StockWastageOrderClass::addOrder($post);
+            $transaction->commit();
+            util::success($return);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("报损失败原因:" . $e->getMessage());
+            util::fail('报损失败');
+        }
     }
 
     //列表

+ 4 - 1
app-ghs/controllers/WastageController.php

@@ -59,9 +59,12 @@ class WastageController extends BaseController
         foreach ($productList as $v) {
             $bigNum = $v['bigNum'] ?? 0;
             $smallNum = $v['smallNum'] ?? 0;
-            if ($bigNum <= 0 && $smallNum <= 0) {
+            if ($bigNum <= 0) {
                 util::fail('花材数量不能为0');
             }
+            if($smallNum > 0){
+                util::fail('小单位不能报损');
+            }
         }
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();