shish 1 год назад
Родитель
Сommit
49a390e901
1 измененных файлов с 37 добавлено и 4 удалено
  1. 37 4
      biz-ghs/live/classes/LiveOrderClass.php

+ 37 - 4
biz-ghs/live/classes/LiveOrderClass.php

@@ -95,6 +95,24 @@ class LiveOrderClass extends BaseClass
             }
         }
         $customName = $custom->name ?? '';
+        $seatSn = $custom->seatSn ?? 0;
+        //分配货位
+        if (empty($seatSn)) {
+            $mainId = $live->mainId ?? 0;
+            $seatRes = LiveSeatClass::getByCondition(['mainId' => $mainId, 'no' => 0], true);
+            if (empty($seatRes)) {
+                util::fail('没有货位可分配');
+            }
+            $seatResId = $seatRes->id ?? 0;
+            $seatRes = LiveSeatClass::getLockById($seatResId);
+            $newSeatSn = $seatRes->no;
+            $custom->seatSn = $newSeatSn;
+            $custom->visitTime = date("Y-m-d H:i:s");
+            $custom->save();
+            $seatRes->customId = $custom->id;
+            $seatRes->save();
+        }
+
         $num = $params['num'] ?? 0;
         $unitPrice = $params['price'] ?? 0;
         $price = bcmul($unitPrice, $num, 2);
@@ -171,8 +189,7 @@ class LiveOrderClass extends BaseClass
         ];
         self::add($liveData, true);
         $ids = array_column($customList, 'customId');
-        $infoList = CustomClass::getByIds($ids, null, 'id');
-
+        $infoList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
         foreach ($customList as $it) {
             $customId = $it['customId'] ?? 0;
             $num = $it['num'] ?? 0;
@@ -181,14 +198,30 @@ class LiveOrderClass extends BaseClass
             $unitName = $product->bigUnit ?? '扎';
             $unitPrice = $it['price'] ?? 0;
             $price = bcmul($num, $unitPrice, 2);
-            $customInfo = $infoList[$customId] ?? [];
+            $customInfo = $infoList[$customId] ?? null;
             if (empty($customInfo)) {
                 util::fail('客户信息缺失');
             }
-            $customName = $customInfo['name'] ?? '';
+            $customName = $customInfo->name ?? '';
             if ($currentMainId == $ownMainId) {
                 util::fail($customName . ' 是自己的店');
             }
+            $seatSn = $customInfo->seatSn ?? 0;
+            //分配货位
+            if (empty($seatSn)) {
+                $seatRes = LiveSeatClass::getByCondition(['mainId' => $mainId, 'no' => 0], true);
+                if (empty($seatRes)) {
+                    util::fail('没有货位可分配');
+                }
+                $seatResId = $seatRes->id ?? 0;
+                $seatRes = LiveSeatClass::getLockById($seatResId);
+                $newSeatSn = $seatRes->no;
+                $customInfo->seatSn = $newSeatSn;
+                $customInfo->visitTime = date("Y-m-d H:i:s");
+                $customInfo->save();
+                $seatRes->customId = $customInfo->id;
+                $seatRes->save();
+            }
             $customData = [
                 'mainId' => $mainId,
                 'orderSn' => $orderSn,