cqp 4 周之前
父节点
当前提交
b11bbb6c13
共有 3 个文件被更改,包括 58 次插入1 次删除
  1. 10 0
      app/Http/Controllers/Api/TestController.php
  2. 47 1
      app/Service/TestService.php
  3. 1 0
      routes/api.php

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

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

+ 47 - 1
app/Service/TestService.php

@@ -94,7 +94,7 @@ class TestService extends Service
 
     public function getSnforMap($data){
         list($status, $msg) = $this->rule();
-//        if(! $status) return [false, 'IP未入白名单'];
+        if(! $status) return [false, 'IP未入白名单'];
         if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnMap") return [false,'API请求参数不能为空'];
         if(empty($data['sn'])) return [false, 'sn码不能为空'];
         if(empty($data['code'])) return [false, '产品编码不能为空'];
@@ -110,6 +110,23 @@ class TestService extends Service
         return [$status, $msg];
     }
 
+    public function getSnForWarranty($data){
+        list($status, $msg) = $this->rule();
+        if(! $status) return [false, 'IP未入白名单'];
+        if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnForWarranty") return [false,'API请求参数不能为空'];
+        if(empty($data['sn'])) return [false, 'sn码不能为空'];
+
+        list($status, $msg) = $this->connectYy();
+        if(! $status) return [false, $msg];
+
+        //数据库
+        $db = $msg[0];
+        $u8 = $msg[1];
+        list($status, $msg) = $this->getSnForWarrantyData($db, $u8,$data);
+
+        return [$status, $msg];
+    }
+
     public function rule(){
         // 获取用户的IP地址
         $userIP = $_SERVER['REMOTE_ADDR'];
@@ -274,15 +291,44 @@ class TestService extends Service
         $bool = $this->isDomainAvailable($u8['domain']);
         if(! $bool) return [false, 'U8程序外部域名不可达'];
 
+        $warehouse = [
+            '001',
+            '003',
+            '010',
+        ];
+
         $list = $db->table('ST_SNState')
             ->select("cInvCode as code",'cinvSN as sn')
+            ->whereIn("cWhCode", $warehouse)
             ->whereIn("cInvCode", $data['code'])
             ->whereIn('cInvSN', $data['sn'])
+            ->where("iSNState", 2)
             ->get()->toArray();
 
         return [true, $list];
     }
 
+    public function getSnForWarrantyData($db, $u8, $data){
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($u8['domain']);
+        if(! $bool) return [false, 'U8程序外部域名不可达'];
+
+        $warehouse = [
+            '001',
+            '003',
+            '010',
+        ];
+
+        $list = $db->table('ST_SNState')
+            ->select("cInvCode as code",'cinvSN as sn')
+            ->whereIn("cWhCode", $warehouse)
+            ->where('cInvSN', $data['sn'])
+//            ->where("iSNState", 2)
+            ->first();
+
+        return [true, $list];
+    }
+
     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

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