Quellcode durchsuchen

手持入库添加缓存校验

haozi vor 4 Jahren
Ursprung
Commit
80b027a713

+ 26 - 0
app/Http/Controllers/HandInStorageController.php

@@ -6,7 +6,10 @@ use App\Components\AsyncResponse;
 use App\OracleDOCASNHeader;
 use App\Services\HandInStorageService;
 use Carbon\Carbon;
+use Doctrine\DBAL\Exception;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 
 class HandInStorageController extends Controller
@@ -118,7 +121,16 @@ class HandInStorageController extends Controller
             if ($result===2)$this->error('需要维护该产品档案中的重量体积');
         }
         if ($info['customerid']=='JIANSHANG'&&$handInStorageService->checkForwardingLoc($info)===1)$this->error('请维护拣货位');
+        $key = $info['asnno'] . '_' . $info['sku'] . '_' . Auth::id();
+        $ttl = 10;
         try {
+            //缓存校验操作
+            if (Cache::has($key)){
+                $this->error('当前已操作');
+            }else{
+                Cache::put($key,true, $ttl);
+            }
+            //收货操作
             $resultIn = $handInStorageService->fluxHandIn($info);
             if ($resultIn===1)$this->error("超收");
             if ($resultIn){
@@ -127,6 +139,8 @@ class HandInStorageController extends Controller
             } else $this->error("收货失败");
         } catch (\Exception $e) {
             app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
+        } finally {
+            Cache::forget($key);
         }
     }
 
@@ -178,6 +192,7 @@ class HandInStorageController extends Controller
     {
         $this->gate("入库管理-手持入库-上架");
         $info=$request->input('info');
+        if (gettype($info['amount'])==='string')$info['amount']=(int)$info['amount'];
         if (!$info['location']||!$info['amount']||!$info['barCode'] || gettype($info['amount'])==='string') $this->error('参数错误');
         if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
         $checkData=$request->input('checkData')[0];
@@ -189,7 +204,16 @@ class HandInStorageController extends Controller
         if ($res===2)$this->error('库位:产品和批次不可混放');
         if ($res===3)$this->error('库位:不能混放批次');
         if ($res===4)$this->error('库位:产品不能混放');
+        $key = $info['location'] . '_' . $info['barCode'] . '_' . Auth::id();
+        $ttl = 10;
         try {
+            //缓存校验操作
+            if (Cache::has($key)){
+                $this->error('当前已操作');
+            }else{
+                Cache::put($key,true, $ttl);
+            }
+
             $result = $handInStorageService->fluxHandPa($info, $checkData);
             if ($result===true)$this->success("上架成功");
             if ($result===false) $this->error("上架失败");
@@ -197,6 +221,8 @@ class HandInStorageController extends Controller
         } catch (\Exception $e) {
             $this->error($e->getMessage());
             app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
+        }finally {
+            Cache::forget($key);
         }
     }
 

+ 1 - 1
app/Services/HandInStorageService.php

@@ -638,6 +638,7 @@ sql;
         $amount = (int) $info['amount'];                    // 当前收货数量
         $expectedQty = (int)$asnDetail['expectedqty'];     // 预期数量
 
+        if ($receivedQty+$amount>$expectedQty)return 1; //超收
         if ($receivedQty + $amount < $expectedQty) {
             // 已收货数量+当前收货数量 < 预期数量
             $db->update(DB::raw("UPDATE DOC_ASN_DETAILS SET receivedqty = receivedqty + ?,receivedqty_each = receivedqty_each + ?,linestatus = '30',holdrejectcode ='OK',
@@ -667,7 +668,6 @@ sql;
                     [$time, $who, $info['asnno']]);
             }
         }
-        if ($receivedQty+$amount>$expectedQty)return 1; //超收
         return true;
     }