Browse Source

开启预订

shish 2 năm trước cách đây
mục cha
commit
cc20290343

+ 20 - 22
app-ghs/controllers/StatBookController.php

@@ -3,7 +3,7 @@
 namespace ghs\controllers;
 
 use biz\shop\classes\ShopExtClass;
-use biz\stat\classes\StatBookClass;
+use bizGhs\book\classes\BookItemClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\dateUtil;
 use common\components\printUtil;
@@ -18,15 +18,9 @@ class StatBookController extends BaseController
         $get = Yii::$app->request->get();
         $where = [];
         $where['mainId'] = $this->mainId;
-        $searchTime = $get['searchTime'] ?? 'today';
-        if (!empty($searchTime)) {
-            $startTime = $get['startTime'] ?? '';
-            $endTime = $get['endTime'] ?? '';
-            $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
-            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
-        }
+        $bookSn = $get['bookSn'] ?? '';
         $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock', 'id', true);
-        $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
+        $list = BookItemClass::getAllByCondition($where, 'time DESC', '*');
         $table = [];
         if (!empty($list)) {
             foreach ($list as $key => $val) {
@@ -65,23 +59,26 @@ class StatBookController extends BaseController
         $get = Yii::$app->request->get();
         $where = [];
         $where['mainId'] = $this->mainId;
-        $searchTime = $get['searchTime'] ?? 'today';
-        if (!empty($searchTime)) {
-            $startTime = $get['startTime'] ?? '';
-            $endTime = $get['endTime'] ?? '';
-            $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
-            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
+        $bookSn = $get['bookSn'] ?? '';
+        if (empty($bookSn)) {
+            $shop = $this->shop;
+            $bookSn = $shop->bookSn ?? 0;
+            if (empty($bookSn)) {
+                util::fail('请选择预订活动');
+            }
         }
-        $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock', 'id', true);
-        $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
+        $where['bookSn'] = $bookSn;
+        $list = BookItemClass::getAllByCondition($where, 'addTime DESC', '*');
         if (!empty($list)) {
+            $ids = array_column($list, 'itemId');
+            $itemList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,stock', 'id', true);
             foreach ($list as $key => $val) {
                 $productId = $val['itemId'] ?? 0;
-                $stock = 0;
-                if (isset($itemList[$productId])) {
-                    $product = $itemList[$productId];
-                    $stock = $product->stock;
+                $product = $itemList[$productId] ?? null;
+                if (empty($product)) {
+                    util::fail('没有花材信息,ID:' . $productId);
                 }
+                $stock = $product->stock;
                 $list[$key]['stock'] = floatval($stock);
                 $time = $val['time'];
                 $shortTime = substr($time, 4, 4);
@@ -104,7 +101,7 @@ class StatBookController extends BaseController
             $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
         }
 
-        $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
+        $list = BookItemClass::getAllByCondition($where, 'time DESC', '*');
         if (empty($list)) {
             util::fail('没有花材需要打印');
         }
@@ -126,6 +123,7 @@ class StatBookController extends BaseController
 
     public static function printOrder($list, $shop, $order = 0)
     {
+        util::fail('开发中');
         $content = "<CB>预订汇总</CB><BR><BR>";
         if ($order > 0) {
             $content .= "<CB>第{$order}页</CB><BR><BR>";

+ 65 - 42
biz-ghs/book/classes/BookItemClass.php

@@ -3,6 +3,7 @@
 namespace bizGhs\book\classes;
 
 use bizGhs\base\classes\BaseClass;
+use bizGhs\product\classes\ProductClass;
 use bizGhs\shop\classes\ShopClass;
 use common\components\noticeUtil;
 use common\components\util;
@@ -13,7 +14,8 @@ class BookItemClass extends BaseClass
 
     public static $baseFile = '\bizGhs\book\models\BookItem';
 
-    public static function addItem($data, $order)
+    //数据结构 [['productId' => $productId,'num' => $num]]
+    public static function addBatchItem($batchData, $order)
     {
         $shopId = $order->shopId ?? 0;
         $shop = ShopClass::getById($shopId, true);
@@ -32,50 +34,71 @@ class BookItemClass extends BaseClass
             }
         }
         $mainId = $order->mainId ?? 0;
-        $itemId = $data['productId'] ?? 0;
-        $ptItemId = $data['ptItemId'] ?? 0;
-        //预订单只会有大单位
-        $num = $data['num'] ?? 0;
-        $name = $data['name'] ?? '';
-        $py = $data['py'] ?? '';
-        $cgStaffId = $data['cgStaffId'] ?? 0;
-        if (empty($cgStaffId)) {
-            if ($pfLevel == 1) {
-                util::fail($name . '没有设置采购人');
+        $customId = $order->customId ?? 0;
+        $customName = $order->customName ?? '';
+        $customNamePy = $order->customNamePy ?? '';
+
+        $ids = array_column($batchData, 'productId');
+        $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
+        foreach ($batchData as $data) {
+            $itemId = $data['productId'] ?? 0;
+            $product = $infoList[$itemId] ?? null;
+            if (empty($product)) {
+                util::fail('没有找到产品,ID:' . $itemId);
             }
-        }
-        $cgStaffName = $data['cgStaffName'] ?? '';
-        $stat = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
-        if (empty($stat)) {
-            $statData = ['mainId' => $mainId, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'name' => $name, 'bookSn' => $bookSn, 'py' => $py, 'cgStaffId' => $cgStaffId, 'cgStaffName' => $cgStaffName];
-            $stat = self::add($statData, true);
-        }
-        $id = $stat->id;
-        $unique = self::getLockById($id);
-        $currentNum = bcadd($unique->bookNum, $num);
-        $unique->bookNum = $currentNum;
-        $unique->save();
+            $ptItemId = $product->itemId ?? 0;
+            $num = $data['num'] ?? 0;
+            $name = $product->name ?? '';
+            $py = $product->py ?? '';
+            $cgStaffName = $product->cgStaffName ?? '';
+            $cgStaffId = $product->cgStaffId ?? 0;
+            if (empty($cgStaffId)) {
+                if ($pfLevel == 1) {
+                    util::fail($name . '没有设置采购人');
+                }
+            }
+            $stat = self::getByCondition(['mainId' => $mainId, 'bookSn' => $bookSn, 'itemId' => $itemId,], true);
+            if (empty($stat)) {
+                $statData = [
+                    'mainId' => $mainId,
+                    'itemId' => $itemId,
+                    'ptItemId' => $ptItemId,
+                    'name' => $name,
+                    'bookSn' => $bookSn,
+                    'py' => $py,
+                    'cgStaffId' => $cgStaffId,
+                    'cgStaffName' => $cgStaffName
+                ];
+                $stat = self::add($statData, true);
+            }
+            $id = $stat->id;
+            $unique = self::getLockById($id);
+            $currentNum = bcadd($unique->bookNum, $num);
+            $unique->bookNum = $currentNum;
+            $unique->save();
 
-        $customId = $order->customId ?? 0;
-        $has = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'customId' => $customId,], true);
-        if (empty($has)) {
-            $customName = $order->customName ?? '';
-            $customNamePy = $order->customNamePy ?? '';
-            $currentData = [
-                'mainId' => $mainId,
-                'itemId' => $itemId,
-                'customId' => $customId,
-                'customName' => $customName,
-                'customNamePy' => $customNamePy,
-                'cgStaffId' => $cgStaffId,
-                'cgStaffName' => $cgStaffName
-            ];
-            $has = BookItemCustomClass::add($currentData, true);
+            $has = BookItemCustomClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'customId' => $customId,], true);
+            if (empty($has)) {
+                $currentData = [
+                    'name' => $name,
+                    'py' => $py,
+                    'mainId' => $mainId,
+                    'itemId' => $itemId,
+                    'ptItemId' => $ptItemId,
+                    'customId' => $customId,
+                    'customName' => $customName,
+                    'customNamePy' => $customNamePy,
+                    'cgStaffId' => $cgStaffId,
+                    'cgStaffName' => $cgStaffName,
+                    'bookSn' => $bookSn,
+                ];
+                $has = BookItemCustomClass::add($currentData, true);
+            }
+            $hasId = $has->id ?? 0;
+            $has = BookItemCustomClass::getLockById($hasId);
+            $has->bookNum = bcadd($has->bookNum, $num);
+            $has->save();
         }
-        $hasId = $has->id ?? 0;
-        $has = BookItemCustomClass::getLockById($hasId);
-        $has->bookNum = bcadd($has->bookNum, $num);
-        $has->save();
     }
 
 }

+ 4 - 11
biz-ghs/order/classes/OrderItemClass.php

@@ -73,6 +73,7 @@ class OrderItemClass extends BaseClass
             util::fail('没有花材');
         }
         $productList = [];
+        $thisBookData = [];
         foreach ($itemList as $item) {
             $num = $item['num'] ?? 0;
             $price = $item['price'] ?? 0;
@@ -119,17 +120,6 @@ class OrderItemClass extends BaseClass
             $current['belongCost'] = $belongCost;
             self::add($current);
 
-            $thisData = [
-                'productId' => $productId,
-                'ptItemId' => $ptItemId,
-                'num' => $num,
-                'name' => $info['name'] ?? '',
-                'py' => $info['py'] ?? '',
-                'cgStaffId' => $info['cgStaffId'] ?? 0,
-                'cgStaffName' => $info['cgStaffName'] ?? '',
-            ];
-            BookItemClass::addItem($thisData, $order);
-
             $productList[] = [
                 'productId' => $productId,
                 'num' => $num,
@@ -139,7 +129,10 @@ class OrderItemClass extends BaseClass
                 'itemId' => $ptItemId,
                 'userPrice' => 0,
             ];
+
+            $thisBookData[] = ['productId' => $productId,'num' => $num,];
         }
+        BookItemClass::addBatchItem($thisBookData, $order);
         $cgId = $order->purchaseId ?? 0;
         $cg = PurchaseClass::getById($cgId, true);
         if (empty($cg)) {

+ 4 - 8
biz-ghs/order/services/OrderService.php

@@ -759,18 +759,14 @@ class OrderService extends BaseService
             //预订单统计数量增加
             $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
             if (!empty($itemList)) {
+                $bookData = [];
                 foreach ($itemList as $currentItem) {
-                    $thisData = [
+                    $bookData[] = [
                         'productId' => $currentItem->productId,
-                        'ptItemId' => $currentItem->itemId,
-                        'num' => $currentItem->xhNum,
-                        'name' => $currentItem->name,
-                        'py' => $currentItem->py,
-                        'cgStaffId' => $currentItem->cgStaffId ?? 0,
-                        'cgStaffName' => $currentItem->cgStaffName ?? '',
+                        'num' => $currentItem->xhNum ?? 0,
                     ];
-                    BookItemClass::addItem($thisData, $order);
                 }
+                BookItemClass::addBatchItem($bookData, $order);
             }
         } else {
             $main->finishOrder += 1;