getToken($data); if(! $status) return [false, $msg]; return [true, ['data' => $msg]]; } public function getToken($data){ $account = $data['name']; $password = $data['password']; $url = config("j_rfid.login"); $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]; //登录失败 if(! empty($result['errorMessage'])) return [false, $result['errorMessage']]; return [true, $result]; } public function getSite($data){ $url = config("j_rfid.site"); list($status,$result) = $this->get_helper($url); if(! $status) return [false, $result]; if(! empty($result['errorMessage'])) return [false, $result['errorMessage']]; return [true, $result]; } public function getFlowByProduce($data,$param){ if(empty($data['produce_no'])) return [false, '订单号不能为空']; if(empty($data['site'])) return [false, '站点不能为空']; $url = config("j_rfid.get_flow_by_produce"); $post = [ 'produce_no' => $data['produce_no'], 'site' => $data['site'], ]; list($status,$result) = $this->post_helper($url,json_encode($post),$param['header']); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']]; return [true, $result]; } public function getProduceByContract($data,$param){ if(empty($data['contract_no'])) return [false, '合同不能为空']; if(empty($data['site'])) return [false, '站点不能为空']; $url = config("j_rfid.get_produce_by_contract"); $post = [ 'contract_no' => $data['contract_no'], 'site' => $data['site'], ]; list($status,$result) = $this->post_helper($url,json_encode($post),$param['header']); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']]; return [true, $result]; } public function getPrintData($data){ if(empty($data['id'])) return [false, '数据ID不能为空']; if(empty($data['type'])) return [false, '打印数据类型不能为空']; $rsaService = new RsaEncryptionService(); $dataToEncrypt = [ 'id' => $data['id'], 'type' => $data['type'], ]; $encryptedData = $rsaService->encrypt(json_encode($dataToEncrypt)); $url = config("j_rfid.get_print_data"); $post = [ 'body' => $encryptedData, ]; list($status,$result) = $this->post_helper($url,json_encode($post),['Content-Type:application/json'],62); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['message']]; if(! empty($result['type']) && $result['type'] == 'errorVm') return [false, $result['message']]; // $return = $this->clearPrintData($data, $result); return [true, $result]; } public function clearPrintData($data,$result){ //分页参数 $size = $data['size'] ?? 10; $number = $data['number'] ?? 1; if(empty($result['furn_pro_flow_dt_a'])) return []; $furn_pro_flow_dt_a = $result['furn_pro_flow_dt_a']; //排序 usort($furn_pro_flow_dt_a, function($a, $b) { return $b['id'] - $a['id']; }); //总数 $total = count($furn_pro_flow_dt_a); // 计算总页数 $totalPages = ceil($total / $size); // 确保请求的页码在有效范围内 $page = $number; // 计算当前页的起始索引 $offset = ($page - 1) * $size; //切片数据以获取当前页的数据 $currentPageData = array_slice($furn_pro_flow_dt_a, $offset, $size); if(empty($currentPageData)) return []; unset($result['furn_pro_flow_dt_a']); foreach ($furn_pro_flow_dt_a as $key => $value){ foreach ($result['furn_pro_flow_dt_assem'] as $v1){ if($v1['main_table_id'] == $value['id']){ foreach ($result['furn_pro_flow_dt_comp'] as $v2){ if($v2['main_table_id'] == $v1['id']) {dd(22); $v1['furn_pro_flow_dt_comp'][] = $v2; } } $furn_pro_flow_dt_a[$key]['furn_pro_flow_dt_assem'][] = $v1; } } } dd($furn_pro_flow_dt_a, 1); } public function getTeam($data,$param){ if(empty($data['site'])) return [false, '站点不能为空']; $url = config("j_rfid.get_team"); $post['rules'] = [ [ 'field' => 'site', 'option' => 'LIKE_ANYWHERE', 'values' => [$data['site']] ], [ 'field' => 'is_used', 'option' => 'IN', 'values' => ['1'] ] ]; $post['size'] = $data['size'] ?? 6; $post['number'] = ($data['number'] ?? 1) - 1; list($status,$result) = $this->post_helper($url,json_encode($post),$param['header']); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']]; return [true, $result]; } public function completionOrders($data,$param){ if(empty($data['exe_pro_flow_dtl_sub_c'])) return [false, '数据不能为空']; $url = config("j_rfid.completion_orders"); $post['data'] = [ 'exe_pro_flow_dtl_sub_c' => $data['exe_pro_flow_dtl_sub_c'], ]; list($status,$result) = $this->post_helper($url,json_encode($post), $param['header']); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['message']]; return [true, $result]; } public function qualityOrders($data,$param){ if(empty($data['exe_pro_flow_dtl_sub_c'])) return [false, '数据不能为空']; $url = config("j_rfid.quality_orders"); $post['data'] = [ 'exe_pro_flow_dtl_sub_c' => $data['exe_pro_flow_dtl_sub_c'], ]; list($status,$result) = $this->post_helper($url,json_encode($post), $param['header']); if(! $status) return [false, $result]; if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['message']]; 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') . PHP_EOL. "请求API:" . $url . PHP_EOL . "请求参数:" . $data . PHP_EOL . "请求头部:" . json_encode($header) . PHP_EOL,8); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 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') . PHP_EOL . "返回结果:" . $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); file_put_contents('jrfid_record.txt',date('Y-m-d H:i:s') . PHP_EOL . "GET返回结果:" . $r . PHP_EOL,8); return [true, json_decode($r, true)]; } }