cqp 5 päivää sitten
vanhempi
commit
23242fd3f0
3 muutettua tiedostoa jossa 133 lisäystä ja 0 poistoa
  1. 20 0
      app/Http/Controllers/Api/TestController.php
  2. 110 0
      app/Service/TestService.php
  3. 3 0
      routes/api.php

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

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

+ 110 - 0
app/Service/TestService.php

@@ -70,6 +70,46 @@ class TestService extends Service
         return [$status, $msg];
     }
 
+    public function getSnList($data){
+        list($status, $msg) = $this->rule();
+        if(! $status) return [false, 'IP未入白名单'];
+        if(empty($data['urlFromT9']) || $data['urlFromT9'] != "getSnList") return [false,'API请求参数不能为空'];
+        if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空'];
+
+        list($status, $msg) = $this->connectYy();
+        if(! $status) return [false, $msg];
+
+        //数据库
+        $db = $msg[0];
+        $u8 = $msg[1];
+        if($data['sn_type'] == 1){
+            list($status, $msg) = $this->getSnListFormU8One($db, $u8,$data);
+        }else{
+            //发货出库单 sn码
+            list($status, $msg) = $this->getSnListFormU8Two($db, $u8,$data);
+        }
+
+        return [$status, $msg];
+    }
+
+    public function getSnforMap($data){
+        list($status, $msg) = $this->rule();
+//        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, '产品编码不能为空'];
+
+        list($status, $msg) = $this->connectYy();
+        if(! $status) return [false, $msg];
+
+        //数据库
+        $db = $msg[0];
+        $u8 = $msg[1];
+        list($status, $msg) = $this->getSnListFormU8ForMap($db, $u8,$data);
+
+        return [$status, $msg];
+    }
+
     public function rule(){
         // 获取用户的IP地址
         $userIP = $_SERVER['REMOTE_ADDR'];
@@ -173,6 +213,76 @@ class TestService extends Service
         return [true, $return];
     }
 
+    public function getSnListFormU8One($db, $u8, $data){
+        if(empty($data['code'])) return [false, '存货不能为空'];
+        $sn = $data['sn'] ?? "";
+        $warehouse = [
+            '001',
+            '003',
+            '010',
+        ];
+
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($u8['domain']);
+        if(! $bool) return [false, 'U8程序外部域名不可达'];
+
+        //检索条件 在库的
+        $model = $db->table('ST_SNState')
+            ->select('cinvCode as code','cInvSN as sn')
+            ->whereIn("cWhCode", $warehouse)
+            ->where("cInvCode", $data['code'])
+            ->where("iSNState", 2)
+            ->when(! empty($sn), function ($query) use ($sn) {
+                return $query->where('cInvSN', 'LIKE', '%'.$sn.'%');
+            });
+
+        $list = $this->limit($model, '', $data);
+
+        return [true, $list];
+    }
+
+    public function getSnListFormU8Two($db, $u8, $data){
+        if(empty($data['code']) || empty($data['depart_title'])) return [false, '存货以及门店信息不能为空'];
+        $sn = $data['sn'] ?? "";
+
+        //映射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')
+            ->whereNotNull('a.cHandler')
+            ->where("b.cInvCode", $data['code'])
+            ->where("b.iQuantity", '>', 0)
+            ->where("b.cDefine31", $data['depart_title'])
+            ->whereNotNull("c.cinvSN")
+            ->when(! empty($sn), function ($query) use ($sn) {
+                return $query->where('c.cInvSN', 'LIKE', '%'.$sn.'%');
+            })
+            ->orderBy('a.ID','desc');
+
+        $list = $this->limit($model, '', $data);
+
+        return [true, $list];
+    }
+
+    public function getSnListFormU8ForMap($db, $u8, $data){
+        //映射ip是否通畅
+        $bool = $this->isDomainAvailable($u8['domain']);
+        if(! $bool) return [false, 'U8程序外部域名不可达'];
+
+        $list = $db->table('ST_SNState')
+            ->select("cInvCode as code",'cinvSN as sn')
+            ->whereIn("cInvCode", $data['code'])
+            ->whereIn('cInvSN', $data['sn'])
+            ->get()->toArray();
+
+        return [true, $list];
+    }
+
     public function post_helper($url, $data, $header = [], $timeout = 20){
         Log::channel('apiLog')->info('朗峰POST', ["api" => $url , "param" => $data ,"header" => $header]);
 

+ 3 - 0
routes/api.php

@@ -37,6 +37,9 @@ Route::any('deviceStatisticsReportOEEChart', 'Api\ReportFormsController@deviceSt
 
 //更新t9总社库存
 Route::any('updateTopStock', 'Api\TestController@updateTopStock');
+//更新t9获取sn
+Route::any('getSnList', 'Api\TestController@getSnList');
+Route::any('getSnforMap', 'Api\TestController@getSnforMap');
 Route::group(['middleware'=> ['CheckJRFIDLogin']],function ($route){
     //站点获取登录后
     $route->any('getSiteByLogin', 'Api\JRFIDController@getSite2');