cqpCow vor 1 Jahr
Ursprung
Commit
b960a8f7d3

+ 38 - 0
app/Http/Controllers/Api/JRFIDController.php

@@ -0,0 +1,38 @@
+<?php
+namespace App\Http\Controllers\Api;
+
+use App\Service\JRFIDServerService;
+use Illuminate\Http\Request;
+
+class JRFIDController extends BaseController
+{
+    public function getSite(Request $request){
+        list($bool, $data) = (new JRFIDServerService())->getSite($request->all(),$request->common_param);
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function getFlowByProduce(Request $request){
+        list($bool, $data) = (new JRFIDServerService())->getFlowByProduce($request->all(),$request->common_param);
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function getProduceByContract(Request $request){
+        list($bool, $data) = (new JRFIDServerService())->getProduceByContract($request->all(),$request->common_param);
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 8 - 11
app/Http/Controllers/Api/LoginController.php

@@ -1,22 +1,19 @@
 <?php
 namespace App\Http\Controllers\Api;
 
-use App\Service\EmployeeService;
-use App\Service\TokenService;
+use App\Service\JRFIDServerService;
 use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Log;
 
 //登录
 class LoginController extends BaseController
 {
     public function login(Request $request){
-        $data = $request->only("account","password");
-
-        //登录
-        $result = (new EmployeeService())->loginRule($data);
-        list($bool, $return) = $result;
-        if(! $bool) return $this->json_return(201,'',$return);
-
-        return $this->json_return(200,'', ['token' => $jwtToken]);
+        $data = $request->only("name","password","rememberMe");
+        list($bool, $msg) = (new JRFIDServerService())->loginRule($data);
+        if($bool){
+            return $this->json_return(200,'',$msg);
+        }else{
+            return $this->json_return(201,$msg);
+        }
     }
 }

+ 1 - 0
app/Http/Kernel.php

@@ -64,6 +64,7 @@ class Kernel extends HttpKernel
         'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
         'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
         'checkLogin' => \App\Http\Middleware\CheckLogin::class,
+        'CheckJRFIDLogin' => \App\Http\Middleware\CheckJRFIDLogin::class,
     ];
 
     /**

+ 28 - 0
app/Http/Middleware/CheckJRFIDLogin.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use App\Service\EmployeeService;
+use Closure;
+
+class CheckJRFIDLogin
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        $token = $request->header('Authorization');
+        if (! isset($token)) return response()->json(['code'=>201,'msg'=>'缺少token','data'=>null]);
+        if(strpos($token, "Bearer ") === false) $token = "Bearer " . $token;
+        $data['token'] = $token;
+        $data['header'] = ["Authorization: {$token}",'Content-Type:application/json'];
+
+        $request->common_param = $data;
+        return $next($request);
+    }
+}

+ 107 - 373
app/Service/JRFIDServerService.php

@@ -3,409 +3,103 @@
 namespace App\Service;
 
 use Illuminate\Support\Facades\Config;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 
 class JRFIDServerService extends Service
 {
-    public static function getToken(){
-        $token_key = config("j_rfid.LoginRedisTopic");
-        $token = Redis::get($token_key);
-        if(! $token){
-            $url = config('ip.zs');
-            $post = array("name" => "admin","password"=>"admin","rememberMe"=>true);
-            $header = ['Content-Type:application/json'];
-            $curl = curl_init();
-            curl_setopt_array($curl, array(
-                CURLOPT_URL => $url . 'jbl/api/mes/login',
-                CURLOPT_RETURNTRANSFER => true,
-                CURLOPT_ENCODING => '',
-                CURLOPT_MAXREDIRS => 10,
-                CURLOPT_TIMEOUT => 0,
-                CURLOPT_FOLLOWLOCATION => true,
-                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
-                CURLOPT_CUSTOMREQUEST => 'POST',
-                CURLOPT_POSTFIELDS => json_encode($post),
-                CURLOPT_HTTPHEADER =>  $header,
-            ));
-            $response = curl_exec($curl);
-            curl_close($curl);
-            $result = json_decode($response,true);
-            if(empty($result['token'])) {
-                file_put_contents('big_king_token_error.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL,8);
-                return [false,''];
-            }else{
-                $token = $result['token'];
-                $expire_time = 1728000; //20天
-                Redis::set($token_key,$token);
-                Redis::expire($token_key, $expire_time);
-                return [true,$token];
-            }
-        }
-
-        return [true,$token];
-    }
-
-    //销售订单(合同)保存
-    public function U8SaleOrderSave($data,$cmaker = ""){
-        if(! is_array($data)) $data = [$data];
-        $id = $data;
+    public function loginRule($data){
+        if(empty($data['name'])) return [false, '请输入账号!'];
+        if(empty($data['password'])) return [false, '请输入密码!'];
 
-        //映射ip是否通畅
-        $bool = $this->isDomainAvailable($this->u8['domain']);
-        if(! $bool) {
-            $msg = 'U8程序外部域名不可达';
-            $this->finalSettle($id, U8Job::two, $msg);
-            return;
-        }
-
-        //获取数据
-        $result = $this->getSaleOrderData($id);
-        if(empty($result)) {
-            $msg = "同步数据获取失败";
-            $this->finalSettle($id, U8Job::two, $msg);
-            return;
-        }
+        list($status, $msg) = $this->getToken($data);
+        if(! $status) return [false, $msg];
 
-        //u8接口参数组织
-        $post = $this->post_common;
-        $post['entity'] = "U8SaleOrderSave";
-
-        $time = date("Y-m-d");
-        $time1 = date("Y-m-d H:i:s");
-        foreach ($result as $value){
-            $bodys = [];
+        return [true, ['token' => $msg]];
+    }
 
-//            $cdefine31 = "";
-//            if(! empty($value['cstname']) && $value['cstname'] == "线下销售") $cdefine31 = $value['cstname'];
-            foreach ($value['product'] as $son){
-                //子表数据
-                $bodys[] = [
-                    "cinvcode"=>$son['code'], //存货编码
-                    "iquantity"=>$son['number'], //数量
-                    "inum"=>$son['number'], //件数
-                    "itaxrate"=>$son['itaxrate'], //税率
-                    "iunitprice"=>$son['iunitprice'],//原币单价
-                    "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
-                    "isum"=>$son['isum'], //原币价税合计
-                    "imoney"=>$son['imoney'], //原币无税金额
-                    "itax"=>$son['itax'],//原币税额
-                    "cbmemo"=>$son['mark'], //表体备注
-//                    "iappids"=>"", //子表id
-//                    "cinvcode"=>$son['code'], //存货编码
-//                    "iquantity"=>$son['number'], //数量
-//                    "inum"=>$son['number'], //件数
-//                    "ipertaxrate"=>$son['ipertaxrate'], //税率
-//                    "iunitprice"=>$son['iunitprice'], //原币单价
-//                    "itaxprice"=>$son['itaxprice'], //原币含税单价
-//                    "isum"=>$son['isum'], //原币价税合计
-//                    "imoney"=>$son['imoney'], //原币无税金额
-//                    "itax"=>$son['itax'],//原币税额
-//                    "cbmemo"=>$son['mark'], //表体备注
-                    "cdefine22"=>$son['cdefine22'], //手机号码
-                    "cdefine23"=>"",
-                    "cdefine24"=>"",
-                    "cdefine25"=>$son['cdefine25'], //平台类型
-                    "cdefine26"=>"",
-                    "cdefine27"=>"",
-                    "cdefine28"=>$son['cdefine28'], //平台单号
-                    "cdefine29"=>$son['cdefine29'], //分社施工
-                    "cdefine30"=>$son['cdefine30'], //业务员
-                    "cdefine31"=>$son['cdefine31'], //客户名称
-                    "cdefine32"=>$son['cdefine32'], //直播销售
-                    "cdefine33"=>"",
-                    "cdefine34"=>"",
-                    "cdefine35"=>"",
-                    "cdefine36"=>"",
-                    "cdefine37"=>"",
-                    "cfree1"=>"",
-                    "cfree2"=>"",
-                    "cfree3"=>"",
-                    "cfree4"=>"",
-                    "cfree5"=>"",
-                    "cfree6"=>"",
-                    "cfree7"=>"",
-                    "cfree8"=>"",
-                    "cfree9"=>"",
-                    "cfree10"=>""
-                ];
-            }
+    public function getToken($data){
+        $account = $data['name'];
+        $password = $data['password'];
+        $token_key = config("j_rfid.login_redis_topic");
+        $token_key = $token_key . $account . $password;
+        $token = Redis::get($token_key);
 
-            //最终数据
-            $post['data'] = [
-                "csocode"=>'',
-                "ddate"=> $time,
-                "cmaker"=>$cmaker ?? 'admin',
-                "dcreatesystime"=>$time1,
-                "cstcode"=>"",
-                "cbustype" => $value['cbustype'], //业务类型
-                "cstname"=>$value['cstname'], //销售类型
-                "ccuscode"=>"",
-                "ccusabbname"=>$value['ccusabbname'], //客户简称
-                "cdepcode"=>"",
-                "cdepname"=>"", // 部门名称 $value['cdepname']
-                "cpersoncode"=>"", //业务员编码 暂时不要
-                "jobnumber"=>$value['jobnumber'],//业务员工号
-                "itaxrate"=>"0",
-                "cmemo"=>$value['mark'],//"T9销售订单:". $value['order_number']
-                "cdefine1"=>"",
-                "cdefine2"=>"",
-                "cdefine3"=>"",
-                "cdefine4"=>"",
-                "cdefine5"=>"",
-                "cdefine6"=>"",
-                "cdefine7"=>"",
-                "cdefine8"=>"",
-                "cdefine9"=>"",
-                "cdefine10"=>"",
-                "cdefine11"=>"",
-                "cdefine12"=>"",
-                "cdefine13"=>"",
-                "cdefine14"=>"",
-                "cdefine15"=>"",
-                "cdefine16"=>"",
-                "bodys"=>$bodys
+        if(! $token){
+            $url = config("j_rfid.login");
+            $expire_time = config("j_rfid.login_expire_time");
+            $post = [
+                "name" => $account,
+                "password" => $password,
+                "rememberMe" => true
             ];
+            $header = ['Content-Type:application/json'];
+            list($status, $result) = $this->post_helper($url,json_encode($post), $header);
+            if(! $status) return [false, $result];
 
-            file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
-            $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
-            file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
+            //登录失败
+            if(! empty($result['errorMessage'])) return [false, $result['errorMessage']];
 
-            //剔除数据
-            $id = array_diff($id, [$value['id']]);
+            //登录成功
+            $token = $result['token'];
+            Redis::set($token_key,$token);
+            Redis::expire($token_key, $expire_time);
 
-            if(empty($return)) {
-                $msg = '异常错误,请确认请求接口地址或地址不可达';
-                $this->finalSettle($value['id'],U8Job::two, $msg);
-            }else{
-                if( ! empty($return['flag'])){
-                    $this->finalSettle($value['id'],U8Job::two);
-                }else{
-                    $this->finalSettle($value['id'], U8Job::two, $return['msg']);
-                }
-            }
+            return [true, $token];
         }
 
-        if(! empty($id)){
-            $msg = "未找到同步数据";
-            $this->finalSettle($id,U8Job::two, $msg);
-        }
+        return [true, $token];
     }
 
-    //最终处理
-    public function finalSettle($data,$data_type, $msg = ''){
-        if(! is_array($data)) $data = [$data];
-        $time = time();
-        $insert = [];
+    public function getSite($data, $param){
+        $url = config("j_rfid.site");
+        $token = $param['token'];
+        $header = ["Authorization: {$token}"];
+        list($status,$result) = $this->get_helper($url,$header);
+        if(! $status) return [false, $result];
 
-        U8Job::where('del_time',0)
-            ->where('data_type',$data_type)
-            ->whereIn('data',$data)
-            ->update(['del_time' => $time]);
-        foreach ($data as $value){
-            if(empty($msg)){
-                $insert[] = [
-                    'data' => $value,
-                    'data_type' => $data_type,
-                    'crt_time' => $time,
-                    'state' => U8Job::success,
-                ];
-            }else{
-                $insert[] = [
-                    'data' => $value,
-                    'data_type' => $data_type,
-                    'crt_time' => $time,
-                    'state' => U8Job::failed,
-                    'msg' => $msg
-                ];
-            }
-        }
+        if(! empty($result['errorMessage'])) return [false, $result['errorMessage']];
 
-        U8Job::insert($insert);
+        return [true, $result];
     }
 
-    public function getPurchaseData($id){
-        $main = PurchaseOrder::whereIn('id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        if(empty($main)) return [];
-        $supplier = Supplier::whereIn('id',array_unique(array_column($main,'supplier')))
-            ->pluck('title','id')
-            ->toArray();
-//        $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
-//            ->pluck('title','id')
-//            ->toArray();
-        $emp = Employee::whereIn('id',array_unique(array_column($main,'purchase_id')))
-            ->pluck('number','id')
-            ->toArray();
-        $code_map = BasicType::whereIn('id',array_unique(array_column($main,'purchase_type')))
-            ->pluck('title','id')
-            ->toArray();
-
-        $sub = PurchaseOrderInfo::whereIn('purchase_order_id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
-            ->get()->toArray();
-        $product_map = array_column($product,null,'id');
-
-        $sub_map = [];
-        foreach ($sub as $value){
-            $product_tmp = $product_map[$value['product_id']] ?? [];
-            $value['code'] = $product_tmp['code'];
+    public function getFlowByProduce($data,$param){
+        if(empty($data['produce_no'])) return [false, '订单号不能为空'];
+        if(empty($data['site'])) return [false, '站点不能为空'];
 
-            //计算金额
-            if($value['rate'] > 0){
-//                    ipertaxrate 税率
-//                    iunitprice 原币单价
-//                    itaxprice 原币含税单价
-//                    isum 原币价税合计
-//                    imoney 原币无税金额
-//                    itax 原币税额
-                $value['ipertaxrate'] = $value['rate'];
-                $rate = round($value['rate'] / 100,2);
-                $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
-                $value['itaxprice'] = $value['price'];
-                $value['isum'] = round($value['price'] * $value['number'],2);
-                $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
-                $value['itax'] = round($value['isum'] - $value['imoney'],2);
-            }else{
-                $value['ipertaxrate'] = 0;
-                $value['iunitprice'] = $value['price'];
-                $value['itaxprice'] = $value['price'];
-                $value['isum'] = $value['price'] * $value['number'];
-                $value['imoney'] = $value['isum'];
-                $value['itax'] = 0;
-            }
+        $url = config("j_rfid.get_flow_by_produce");
+        $post = [
+            'produce_no' => $data['produce_no'],
+            'site' => $data['site'],
+        ];
+        $header = $param['header'];
+        list($status,$result) = $this->post_helper($url,json_encode($post),$header);
+        if(! $status) return [false, $result];
 
-            $sub_map[$value['purchase_order_id']][] = $value;
-        }
-        foreach ($main as $key => $value){
-            $main[$key]['cptname'] = $code_map[$value['purchase_type']] ?? "";
-            $main[$key]['cvenname'] = $supplier[$value['supplier']] ?? "";
-//            $main[$key]['cdepname'] = $depart[$value['depart_id']] ?? "";
-//            $main[$key]['cpersoncode'] = $emp[$value['purchase_id']] ?? "";
-            $main[$key]['jobnumber'] = $emp[$value['purchase_id']] ?? "";
-            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
-        }
+        if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']];
 
-        return $main;
+        return [true, $result];
     }
 
-    public function getSaleOrderData($id){
-        $main = SalesOrder::whereIn('id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        if(empty($main)) return [];
-        $main_map = array_column($main,null,'id');
-        $sub = SalesOrderProductInfo::whereIn('sales_order_id',$id)
-            ->where('del_time',0)
-            ->get()->toArray();
-        $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
-            ->get()->toArray();
-        $product_map = array_column($product,null,'id');
-        $code_id = array_filter(array_unique(array_merge_recursive(array_column($main,'sale_type'),array_column($main,'plat_type'),array_column($main,'install_position'),array_column($main,'customer_short_name'))));
-        $code_map = BasicType::whereIn('id',$code_id)
-            ->pluck('title','id')
-            ->toArray();
-        $customer_map = Customer::whereIn('id',array_unique(array_column($main,'customer_id')))
-            ->pluck('title','id')
-            ->toArray();
-//        $depart = Depart::where('parent_id',0)
-//            ->pluck('title','id')
-//            ->toArray();
-        $empList = Employee::whereIn('id',array_unique(array_column($main,'crt_id')))
-            ->select('number','id','emp_name')
-            ->get()
-            ->toArray();
-        $emp = array_column($empList,'number','id');
-        $emp2 = array_column($empList,'emp_name','id');
-//        $see = SeeRange::where('del_time',0)
-//            ->whereIn('data_id',array_column($main,'id'))
-//            ->where('data_type',SeeRange::type_seven)
-//            ->where('type',SeeRange::data_three)
-//            ->pluck('param_id','data_id')->toArray();//指派的分社
-
-        $sub_map = [];
-        foreach ($sub as $value){
-            $product_tmp = $product_map[$value['product_id']] ?? [];
-            $main_tmp = $main_map[$value['sales_order_id']] ?? [];
-            $position = $code_map[$main_tmp['install_position']] ?? "";
-
-            if($main_tmp['model_type'] == SalesOrder::Model_type_four){
-                //线上订单
-                $cdefine28 = $main_tmp['plat_order'] ?? "";
-            }else{
-                $cdefine28 = $main_tmp['order_number'] ?? "";
-            }
-//            "itaxrate"=>$son['itaxrate'], //税率
-//            "iunitprice"=>$son['iunitprice'],//原币单价
-//            "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
-//            "isum"=>$son['isum'], //原币价税合计
-//            "imoney"=>$son['imoney'], //原币无税金额
-//            "itax"=>$son['itax'],//原币税额
-            //计算金额
-            //比如这4个产品合同金额是300.11,那么价税合计就是300.11,
-            //含税单价就是300.11/4,目前加了税率的没有计算规则。税率不进入计算
-
-            $value['itaxrate'] = 0;//税率
-            $value['iunitprice'] = $value['price'];
-            $value['itaxunitprice'] = $value['price'];
-            $value['isum'] = $value['final_amount']; //原币价税合计
-            $value['imoney'] = $value['isum']; //原币无税金额
-            $value['itax'] = 0;
+    public function getProduceByContract($data,$param){
+        if(empty($data['contract_no'])) return [false, '合同不能为空'];
+        if(empty($data['site'])) return [false, '站点不能为空'];
 
-//            if($value['rate'] > 0){
-//                $value['itaxrate'] = $value['rate'];
-//                $rate = round($value['rate'] / 100,2);
-//                $value['iunitprice'] = round($value['final_amount'] / (1 + $rate),2);
-//                $value['itaxunitprice'] = $value['final_amount'];
-//                $value['isum'] = round($value['final_amount'] * $value['number'],2);
-//                $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
-//                $value['itax'] = round($value['isum'] - $value['imoney'],2);
-//            }else{
-//                $value['itaxrate'] = 0;
-//                $value['iunitprice'] = $value['final_amount'];
-//                $value['itaxunitprice'] = $value['final_amount'];
-//                $value['isum'] = $value['final_amount'] * $value['number'];
-//                $value['imoney'] = $value['isum'];
-//                $value['itax'] = 0;
-//            }
-            $value['cdefine25'] = $code_map[$main_tmp['plat_type']] ?? ""; //平台类型
-            $value['cdefine28'] = $cdefine28; //平台单号
-//            $top_depart_id = $see[$value['sales_order_id']] ?? 0;
-            $value['cdefine29'] = $position ?? "";//安装地点
-            $value['cdefine32'] = "";//直播销售 暂时没有
-            $value['cdefine31'] = $customer_map[$main_tmp['customer_id']] ?? "";//客户名称
-            $value['cdefine22'] = $main_tmp['customer_contact'] ?? "";//手机号码
-//            $value['cdefine31'] = "";//客户名称(线上的时候就是空  线下的话就是表头的客户简称)
-//            $value['cdefine22'] = "";//手机号码 暂时没有
-            $value['cdefine30'] = $emp2[$main_tmp['crt_id']] ?? "";//业务员
-            $value['code'] = $product_tmp['code'];//存货编码
+        $url = config("j_rfid.get_produce_by_contract");
+        $post = [
+            'produce_no' => $data['contract_no'],
+            'site' => $data['site'],
+        ];
+        $header = $param['header'];
+        list($status,$result) = $this->post_helper($url,json_encode($post),$header);
+        if(! $status) return [false, $result];
 
-            $sub_map[$value['sales_order_id']][] = $value;
-        }
-        foreach ($main as $key => $value){
-            $customer_short_name = $code_map[$value['customer_short_name']] ?? "";
-//            if($plat_type == "营销部"){
-//                $ccusabbname = "营销部客户";
-//            }else{
-//                $ccusabbname = $customer_map[$value['customer_id']] ?? "";
-//            }
-            $main[$key]['cbustype'] = "普通销售"; //业务类型(本身就是中文)
-            $main[$key]['cstname'] = SalesOrder::$model_type_title[$value['model_type']] ?? ""; //销售类型
-            $main[$key]['ccusabbname'] = $customer_short_name;//客户简称
-//            $main[$key]['cdepname'] = $depart[$value['top_depart_id']] ?? "";//部门名称
-//            $main[$key]['cpersoncode'] = $emp[$value['crt_id']] ?? "";//业务员
-            $main[$key]['jobnumber'] = $emp[$value['crt_id']] ?? "";
-            $main[$key]['product'] = $sub_map[$value['id']] ?? [];
-        }
+        if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']];
 
-        return $main;
+        return [true, $result];
     }
 
     public function post_helper($url, $data, $header = [], $timeout = 20){
+        file_put_contents('jrfid_record.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL . "请求头部:" . json_encode($header) . PHP_EOL,8);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
@@ -415,9 +109,49 @@ class JRFIDServerService extends Service
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+
         if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         $r = curl_exec($ch);
+
+        if ($r === false) {
+            // 获取错误号
+            $errorNumber = curl_errno($ch);
+            // 获取错误信息
+            $errorMessage = curl_error($ch);
+            return [false, "cURL Error #{$errorNumber}: {$errorMessage}"];
+        }
+        curl_close($ch);
+
+        file_put_contents('jrfid_record.txt',date('Y-m-d H:i:s') . "返回结果:" . $r . PHP_EOL,8);
+        return [true, json_decode($r, true)];
+    }
+
+    public function get_helper($url,$header=[],$timeout = 20){
+        $ch = curl_init();
+        curl_setopt_array($ch, array(
+            CURLOPT_URL => $url,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_ENCODING => '',
+            CURLOPT_MAXREDIRS => 10,
+            CURLOPT_TIMEOUT => $timeout,
+            CURLOPT_FOLLOWLOCATION => true,
+            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+            CURLOPT_CUSTOMREQUEST => 'GET',
+            CURLOPT_SSL_VERIFYPEER => false,
+            CURLOPT_HTTPHEADER => $header,
+        ));
+        $r = curl_exec($ch);
+
+        if ($r === false) {
+            // 获取错误号
+            $errorNumber = curl_errno($ch);
+            // 获取错误信息
+            $errorMessage = curl_error($ch);
+            return [false, "cURL Error #{$errorNumber}: {$errorMessage}"];
+        }
+
         curl_close($ch);
-        return json_decode($r, true);
+        file_put_contents('jrfid_record.txt',date('Y-m-d H:i:s') . "GET返回结果:" . $r . PHP_EOL,8);
+        return [true, json_decode($r, true)];
     }
 }

+ 7 - 1
config/j_rfid.php

@@ -2,9 +2,15 @@
 //状态码
 return [
     //登录标识
-    'LoginRedisTopic' => 'JRFIDLOGIN',
+    'login_redis_topic' => 'JRFIDLOGIN',
+    //登录过期时间
+    'login_expire_time' => 2591900, // 2592000
     //登录
     'login' => 'https://gzy.qingyaokeji.com/jbl/api/mes/login',
     //站点获取
     'site' => 'https://gzy.qingyaokeji.com/jbl/api/site/all/ignore-action?_allow_anonymous=true',
+    //工艺流程单查询
+    'get_flow_by_produce' => 'https://gzy.qingyaokeji.com/api/module-data/process_flow/process_flow/diy/get_flow_by_produce',
+    //生产订单查询接口
+    'get_produce_by_contract' => 'https://gzy.qingyaokeji.com/api/module-data/produce_order/produce_order/diy/get_produce_by_contract',
 ];

+ 7 - 1
routes/api.php

@@ -19,5 +19,11 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 
 Route::any('login', 'Api\LoginController@login');
 
-Route::group(['middleware'=> []],function ($route){
+Route::group(['middleware'=> ['CheckJRFIDLogin']],function ($route){
+    //站点获取
+    $route->any('getSite', 'Api\JRFIDController@getSite');
+    //工艺流程单
+    $route->any('getFlowByProduce', 'Api\JRFIDController@getFlowByProduce');
+    //生产订单
+    $route->any('getProduceByContract', 'Api\JRFIDController@getProduceByContract');
 });