Bladeren bron

批量上架

shish 2 jaren geleden
bovenliggende
commit
6e034b0b74
2 gewijzigde bestanden met toevoegingen van 56 en 5 verwijderingen
  1. 49 2
      app-ghs/controllers/BookItemCustomController.php
  2. 7 3
      biz-ghs/book/classes/BookItemCustomClass.php

+ 49 - 2
app-ghs/controllers/BookItemCustomController.php

@@ -92,7 +92,7 @@ class BookItemCustomController extends BaseController
         $shop = $this->shop;
         $bookSn = $shop->bookSn ?? 0;
         if (empty($bookSn)) {
-            util::fail('预订没有开');
+            util::fail('预订没有开');
         }
         $book = BookItemCustomClass::getById($id, true);
         if (empty($book) || $book->bookSn != $bookSn) {
@@ -109,7 +109,54 @@ class BookItemCustomController extends BaseController
     //批量上齐 ssh 20240812
     public function actionBatchGoOn()
     {
-        util::complete();
+        $post = Yii::$app->request->post();
+        $ids = $post['ids']??'';
+
+        $staff = $this->shopAdmin;
+        if(isset($staff->identity) && $staff->identity == 2){
+            util::fail('不能操作');
+        }
+
+        $shop = $this->shop;
+        $bookSn = $shop->bookSn ?? 0;
+        if (empty($bookSn)) {
+            util::fail('预订没有开启');
+        }
+
+        if(empty($ids)){
+            util::fail('请选择要上齐的项');
+        }
+        $arr = json_decode($ids,true);
+        if(empty($arr)){
+            util::fail('请选择项');
+        }
+
+        $staff = $this->shopAdmin;
+        $staffId = $staff->id ?? 0;
+        $staffName = $staff->name ?? '';
+        $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            foreach($arr as $id){
+                $num = 0;
+                $book = BookItemCustomClass::getById($id, true);
+                if (empty($book)) {
+                    util::fail('有选择项没有找到');
+                }
+                if($book->bookSn != $bookSn){
+                    util::fail('有选择的项不是当前预订活动');
+                }
+                BookItemCustomClass::goOn($book, $shop, $params, $num);
+            }
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            Yii::info("操作失败原因:" . $e->getMessage());
+            $transaction->rollBack();
+            util::fail('操作失败');
+        }
     }
 
     //预订客户列表 ssh 20240616

+ 7 - 3
biz-ghs/book/classes/BookItemCustomClass.php

@@ -42,8 +42,8 @@ class BookItemCustomClass extends BaseClass
         $bookCustomRes = BookCustomClass::delOnNum($bookCustomRes, $needOffNum, 0, null, $shop, $product, $params);
     }
 
-    //上架
-    public static function goOn($bookItemCustomRes, $shop, $params, $num)
+    //上架 $onSkip true 表示上齐的直接跳过
+    public static function goOn($bookItemCustomRes, $shop, $params, $num, $onSkip=false)
     {
         $itemId = $bookItemCustomRes->itemId ?? 0;
         $product = ProductClass::getById($itemId, true);
@@ -53,7 +53,11 @@ class BookItemCustomClass extends BaseClass
         $bookNum = $bookItemCustomRes->bookNum ?? 0;
         $onNum = $bookItemCustomRes->onNum ?? 0;
         if ($onNum >= $bookNum) {
-            util::fail('已经上齐');
+            if($onSkip){
+                return true;
+            }else{
+                util::fail('已经上齐');
+            }
         }
 
         $bookSn = $shop->bookSn ?? 0;