Kaynağa Gözat

分配货位

shish 2 yıl önce
ebeveyn
işleme
64bc71930c

+ 83 - 19
app-ghs/controllers/PurchaseOrderController.php

@@ -21,7 +21,7 @@ use Yii;
 class PurchaseOrderController extends BaseController
 {
 
-    public $guestAccess = ['detail'];
+    public $guestAccess = ['detail', 'check-seat-update', 'assign-seat'];
 
     //打印多联 ssh 2024509
     public function actionPrintPaper()
@@ -500,7 +500,7 @@ class PurchaseOrderController extends BaseController
                 $noLock = util::lock($key);
                 if ($noLock) {
                     //没有锁定,即没有在分配货位,可以进行货位分配
-                    PurchaseOrderClass::assign($order, $bookSn);
+                    PurchaseOrderClass::assign($order);
                     util::unlock($key);
                 }
             }
@@ -523,29 +523,41 @@ class PurchaseOrderController extends BaseController
         if (empty($cg)) {
             util::fail('没有找到采购单');
         }
-        if (!empty($salt)) {
-            if ($cg->salt != $salt) {
-                util::fail('您不能访问的采购单');
+        //不是待入库状态不需要分配
+        if ($cg->status != 3) {
+            util::success(['hint' => 'cg is no wait for entry']);
+        }
+        $cgBookSn = $cg->bookSn ?? 0;
+        if (empty($cgBookSn)) {
+            util::success(['hint' => 'cg bookSn is empty']);
+        }
+        $adminId = $this->adminId;
+        if (!empty($adminId)) {
+            if ($cg->mainId != $this->mainId) {
+                util::success(['hint' => 'cg mainId != this mainId']);
+            }
+            $shop = $this->shop;
+            $bookSn = $shop->bookSn ?? 0;
+            if ($bookSn != $cgBookSn) {
+                util::success(['hint' => 'shop bookSn != cg bookSn']);
             }
         } else {
-            if ($cg->mainId != $this->mainId) {
-                util::fail('不是你的采购单呢');
+            if ($cg->salt != $salt) {
+                util::success(['hint' => 'cg salt != post salt']);
+            }
+            $shopId = $cg->shopId ?? 0;
+            $shop = ShopClass::getById($shopId, true);
+            if (empty($shop)) {
+                util::success(['hint' => 'shop empty']);
+            }
+            if ($shop->bookSn != $cgBookSn) {
+                util::success(['hint' => 'shop bookSn != cg bookSn o']);
             }
         }
-        $shop = $this->shop;
-        $bookSn = $shop->bookSn ?? 0;
-        if (empty($bookSn)) {
-            util::success([]);
-        }
-        //不是待入库状态不需要分配
-        if ($cg->status != 3) {
-            util::success([]);
-        }
-
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            PurchaseOrderClass::assign($cg, $bookSn);
+            PurchaseOrderClass::assign($cg);
             $transaction->commit();
             util::complete('货位获取成功');
         } catch (\Exception $e) {
@@ -585,7 +597,7 @@ class PurchaseOrderController extends BaseController
     //订单详情
     public function actionDetail()
     {
-        $get = Yii::$app->request->get('');
+        $get = Yii::$app->request->get();
         $orderSn = $get['orderSn'] ?? '';
         $salt = $get['salt'] ?? '';
         $adminId = $this->adminId ?? 0;
@@ -605,6 +617,58 @@ class PurchaseOrderController extends BaseController
         util::success($orderData);
     }
 
+    //采购页,定时检测货位有没更新 ssh 20240709
+    public function actionCheckSeatUpdate()
+    {
+        util::success(['need' => 1]);
+        $get = Yii::$app->request->get();
+        $orderSn = $get['orderSn'] ?? '';
+        $salt = $get['salt'] ?? '';
+        if (empty($orderSn)) {
+            util::success(['need' => 0, 'hint' => 'empty orderSn']);
+        }
+        $cg = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($cg)) {
+            util::success(['need' => 0, 'hint' => 'empty cg info']);
+        }
+        $adminId = $this->adminId ?? 0;
+        $cgId = $cg->id ?? 0;
+        $cgBookSn = $cg->bookSn ?? 0;
+        if (!empty($adminId)) {
+            if ($cg->mainId != $this->mainId) {
+                util::success(['need' => 0, 'hint' => 'cgMainId != thisMainId']);
+            }
+            $shop = $this->shop;
+            $shopBookSn = $shop->bookSn ?? 0;
+            if (empty($shopBookSn)) {
+                util::success(['need' => 0, 'hint' => 'empty shopBookSn']);
+            }
+            if ($shopBookSn != $cgBookSn) {
+                util::success(['need' => 0, 'hint' => 'shopBookSn!=cgBookSn']);
+            }
+            $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $cgBookSn;
+            $staff = $this->shopAdmin;
+            $staffId = $staff->id ?? 0;
+            $element = $cgId . '-' . $staffId;
+            $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $element]);
+            if (!empty($exists)) {
+                Yii::$app->redis->executeCommand('SREM', [$cacheKey, $element]);
+                util::success(['need' => 1]);
+            }
+        } else {
+            if ($cg->salt != $salt) {
+                util::success(['need' => 0, 'hint' => 'cg salt != post salt']);
+            }
+            $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $cgBookSn;
+            $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $cgId]);
+            if (!empty($exists)) {
+                Yii::$app->redis->executeCommand('SREM', [$cacheKey, $cgId]);
+                util::success(['need' => 1]);
+            }
+        }
+        util::success(['need' => 0, 'hint' => 'real no need']);
+    }
+
     //修改备注
     public function actionUpdateRemark()
     {

+ 12 - 2
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -69,8 +69,9 @@ class PurchaseOrderClass extends BaseClass
     const IN_TYPE_LATER = 0;
     const IN_TYPE_NOW = 1;
 
-    public static function assign($cg, $bookSn)
+    public static function assign($cg)
     {
+        $bookSn = $cg->bookSn ?? 0;
         $orderSn = $cg->orderSn ?? '';
         $cgId = $cg->id ?? 0;
         $mainId = $cg->mainId ?? 0;
@@ -495,7 +496,7 @@ class PurchaseOrderClass extends BaseClass
             $noLock = util::lock($key);
             if ($noLock) {
                 //可以获得锁,没有在分配货位,可以进行货位分配
-                self::assign($cg, $bookSn);
+                self::assign($cg);
                 util::unlock($key);
                 //分配货位后上架和入库
                 CgOrderItemClass::assignToPutOn($cg);
@@ -1246,6 +1247,15 @@ class PurchaseOrderClass extends BaseClass
         $totalCgCost = bcadd($totalCgCost, $localCharge, 2);
         $orderData['totalCgCost'] = $totalCgCost;
 
+        $shop = ShopClass::getById($shopId, true);
+        $shopBookSn = $shop->bookSn ?? 0;
+        $bookSn = $orderData['bookSn'] ?? 0;
+        //是否需要提醒更新货位
+        $needRemindUpdateSeat = 0;
+        if (!empty($shopBookSn) && $shopBookSn == $bookSn) {
+            $needRemindUpdateSeat = 1;
+        }
+        $orderData['needRemindUpdateSeat'] = $needRemindUpdateSeat;
         return $orderData;
     }