cqp 3 days ago
parent
commit
e2e239619e
3 changed files with 103 additions and 7 deletions
  1. 10 0
      app/Http/Controllers/Api/TestController.php
  2. 92 7
      app/Service/TestService.php
  3. 1 0
      routes/api.php

+ 10 - 0
app/Http/Controllers/Api/TestController.php

@@ -76,4 +76,14 @@ class TestController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function saveSnUseData(Request $request){
+        list($bool, $data) = (new TestService())->saveSnUseData($request->all());
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 92 - 7
app/Service/TestService.php

@@ -233,6 +233,7 @@ class TestService extends Service
     public function getSnListFormU8One($db, $u8, $data){
         if(empty($data['code'])) return [false, '存货不能为空'];
         $sn = $data['sn'] ?? "";
+        $construction_id = $data['construction_id'] ?? 0;
         $warehouse = [
             '001',
             '003',
@@ -242,18 +243,31 @@ class TestService extends Service
         //映射ip是否通畅
         $bool = $this->isDomainAvailable($u8['domain']);
         if(! $bool) return [false, 'U8程序外部域名不可达'];
+//        $db->enableQueryLog();
 
         //检索条件 在库的
         $model = $db->table('ST_SNState')
-            ->select('cinvCode as code','cInvSN as sn')
+            ->select('cinvCode as code','cInvSN as sn','AutoID as auto_id')
             ->whereIn("cWhCode", $warehouse)
             ->where("cInvCode", $data['code'])
             ->where("iSNState", 2)
             ->when(! empty($sn), function ($query) use ($sn) {
                 return $query->where('cInvSN', 'LIKE', '%'.$sn.'%');
-            });
+            })
+//            ->when(! empty($construction_id), function ($query) use ($construction_id) {
+//                return $query->whereNull('cSNDefine1')->orWhere('cSNDefine1', '')->orWhere('cSNDefine1', $construction_id);
+//            })
+            ->when(empty($construction_id), function ($query) {
+                return $query->where(function ($q) {
+                    $q->whereNull('cSNDefine1')
+                        ->orWhere('cSNDefine1', '');
+                });
+            })
+            ->orderBy('cSNDefine1','desc')
+            ->orderBy('AutoID','asc');
 
         $list = $this->limit($model, '', $data);
+//        dd($db->getQueryLog());
 
         return [true, $list];
     }
@@ -261,16 +275,17 @@ class TestService extends Service
     public function getSnListFormU8Two($db, $u8, $data){
         if(empty($data['code']) || empty($data['depart_title'])) return [false, '存货以及门店信息不能为空'];
         $sn = $data['sn'] ?? "";
+        $construction_id = $data['construction_id'] ?? 0;
+//        $db->enableQueryLog();
 
         //映射ip是否通畅
         $bool = $this->isDomainAvailable($u8['domain']);
         if(! $bool) return [false, 'U8程序外部域名不可达'];
 
-
         $model = $db->table('rdrecord32 as a')
             ->leftJoin('rdrecords32 as b','b.ID','a.ID')
             ->leftJoin('ST_SNDetail_SaleOut as c','c.iVouchsID','b.AutoID')
-            ->select("c.cInvCode as code",'c.cinvSN as sn')
+            ->select("c.cInvCode as code",'c.cinvSN as sn','c.AutoID as auto_id') //,'c.cSNDefine1','a.ID'
             ->whereNotNull('a.cHandler')
             ->where("b.cInvCode", $data['code'])
             ->where("b.iQuantity", '>', 0)
@@ -279,9 +294,21 @@ class TestService extends Service
             ->when(! empty($sn), function ($query) use ($sn) {
                 return $query->where('c.cInvSN', 'LIKE', '%'.$sn.'%');
             })
-            ->orderBy('a.ID','desc');
+//            ->when(! empty($construction_id), function ($query) use ($construction_id) {
+//                return $query->whereNull('c.cSNDefine1')->orWhere('c.cSNDefine1', '')->orWhere('c.cSNDefine1', $construction_id);
+//            })
+            ->when(empty($construction_id), function ($query) {
+                return $query->where(function ($q) {
+                    $q->whereNull('c.cSNDefine1')
+                        ->orWhere('c.cSNDefine1', '');
+                });
+            })
+            ->orderBy('c.cSNDefine1','desc')
+            ->orderBy('a.ID','desc')
+            ->orderBy('c.AutoID','asc');
 
         $list = $this->limit($model, '', $data);
+//        $logs = $db->getQueryLog();dd($logs);
 
         return [true, $list];
     }
@@ -302,7 +329,7 @@ class TestService extends Service
             ->whereIn("cWhCode", $warehouse)
             ->whereIn("cInvCode", $data['code'])
             ->whereIn('cInvSN', $data['sn'])
-            ->where("iSNState", 2)
+//            ->where("iSNState", 2)
             ->get()->toArray();
 
         return [true, $list];
@@ -320,7 +347,7 @@ class TestService extends Service
         ];
 
         $list = $db->table('ST_SNState')
-            ->select("cInvCode as code",'cinvSN as sn')
+            ->select("cInvCode as code",'cinvSN as sn','AutoID as auto_id')
             ->whereIn("cWhCode", $warehouse)
             ->where('cInvSN', $data['sn'])
 //            ->where("iSNState", 2)
@@ -329,6 +356,64 @@ class TestService extends Service
         return [true, $list];
     }
 
+    public function saveSnUseData($data){
+        list($status, $msg) = $this->rule();
+        if(! $status) return [false, 'IP未入白名单'];
+        if(empty($data['urlFromT9']) || $data['urlFromT9'] != "saveSnUseData") return [false,'API请求参数不能为空'];
+        if(empty($data['sn_type'])) return [false,'sn码来源依据不能为空'];
+//        if(empty($data['sn_for_u8'])) return [false, 'sn码更新信息不能为空'];
+        if(empty($data['data_id'])) return [false, 'dataID信息不能为空'];
+
+        list($status, $msg) = $this->connectYy();
+        if(! $status) return [false, $msg];
+
+        //数据库
+        $db = $msg[0];
+        $u8 = $msg[1];
+        list($status, $msg) = $this->saveSnUseDataDetail($db, $u8,$data);
+
+        return [$status, $msg];
+    }
+
+    public function saveSnUseDataDetail($db, $u8, $data){
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($u8['domain']);
+        if(! $bool) return [false, 'U8程序外部域名不可达'];
+
+        $sn_for_u8 = $data['sn_for_u8'] ?? [];
+        try {
+            DB::beginTransaction();
+            if(empty($sn_for_u8)){//删除
+                if($data['sn_type'] == 1){
+                    $db->table('ST_SNState')
+                        ->where('cSNDefine1', $data['data_id'])
+                        ->update(['cSNDefine1' => ""]);
+                }else{
+                    $db->table('ST_SNDetail_SaleOut')
+                        ->where('cSNDefine1', $data['data_id'])
+                        ->update(['cSNDefine1' => ""]);
+                }
+            }else{//增加或更新
+                if($data['sn_type'] == 1){
+                    $db->table('ST_SNState')
+                        ->whereIn('AutoID', $sn_for_u8)
+                        ->update(['cSNDefine1' => $data['data_id']]);
+                }else{
+                    $db->table('ST_SNDetail_SaleOut')
+                        ->whereIn('AutoID', $sn_for_u8)
+                        ->update(['cSNDefine1' => $data['data_id']]);
+                }
+            }
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
     public function post_helper($url, $data, $header = [], $timeout = 20){
         Log::channel('apiLog')->info('朗峰POST', ["api" => $url , "param" => $data ,"header" => $header]);
 

+ 1 - 0
routes/api.php

@@ -41,6 +41,7 @@ Route::any('updateTopStock', 'Api\TestController@updateTopStock');
 Route::any('getSnList', 'Api\TestController@getSnList');
 Route::any('getSnforMap', 'Api\TestController@getSnforMap');
 Route::any('getSnForWarranty', 'Api\TestController@getSnForWarranty');
+Route::any('saveSnUseData', 'Api\TestController@saveSnUseData');
 Route::group(['middleware'=> ['CheckJRFIDLogin']],function ($route){
     //站点获取登录后
     $route->any('getSiteByLogin', 'Api\JRFIDController@getSite2');