data = $data; $this->url = config('ip.zs'); } /** * Execute the job. * * @return void */ public function handle() { try{ $first = ltrim($this->data[0],'0');//取第一个值 $order_num = hex2bin($first); //十六进制字符串转回 原来字符串 file_put_contents('record_complete.txt',date("Y-m-d H:i:s",time())."原数据:$first" . "解析后:" . $order_num . PHP_EOL,8); if(! $order_num) return; // 使用Redis Facade设置键名为order_number的值,当键名不存在时才设置成功 if (Redis::setnx($order_num, $order_num)) { Redis::expire($order_num, 120); $dispatchList = $this->getDispatchList($order_num); if(empty($dispatchList) || empty($dispatchList['content'])) return; $this->completionOrders($dispatchList); file_put_contents('send_record.txt',date('Y-m-d H:i:s').$order_num . PHP_EOL,8); } //输出信息 测试 $this->echoMessage(new ConsoleOutput()); }catch (\Exception $exception){ file_put_contents('record_error.txt',date("Y-m-d H:i:s",time()).json_encode($this->data) . PHP_EOL.$exception->getMessage().PHP_EOL,8); } } public function getDispatchList($data){ if(empty($data)) return []; list($status,$token) = ClearDataService::getToken(); if(! $status) return; $url = $this->url . 'jbl/api/module-data/dispatch_orders/page'; $post = [ 'direction' => 'DESC', 'property' => 'id', 'fromClientType' => 'pc', 'number' => 0, 'sorts' => [], 'rules' => [['field' =>'dispatch_orders.dispatch_no','option' => 'LIKE_ANYWHERE', 'values' => [$data]]], "size"=> 15, "specialConditions" => [], "workflowSearchBean" => [], "dynamicFormCode" => "dispatch_orders", "dynamicFormTable" => null, "ignoreField" => true, "developmentSystemId" => null, "debugFlag" => true, ]; $header = ["Authorization: Bearer {$token}","Content-Type:application/json",'Site:91451322MA5P9JNKXA']; $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post)); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, 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, CURLOPT_HTTPHEADER => $header, )); $response = curl_exec($curl); curl_close($curl); file_put_contents('record_get_dispatch.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getlist'.PHP_EOL,8); return json_decode($response,true); } public function completionOrders($data){ list($status,$token) = ClearDataService::getToken(); if(! $status) return; //组织数据 $completion_orders_dtl = []; $first = $data['content'][0]['dispatch_orders']; foreach ($data['content'] as $value){ $completion_orders_dtl[] = [ "item_num" => $value['item_num'], "product_no" => $value['product_no'], "in_product_tile" => $value['in_product_tile'], "in_process_title" => $value['in_process_title'], "in_color" => $value['in_color'], "in_process_title_two" => $value['in_process_title_two'], "in_color_two" => $value['in_color_two'], "product_size" => $value['product_size'], "product_unit" => $value['product_unit'], "product_unit_title" => $value['product_unit_title'], "finished_num" => $value['dispatch_num'], "dispatch_num" => $value['dispatch_num'], "production_num" => $value['production_num'], "production_no" => $value['production_no'], "production_item_no" => $value['production_item_no'], "dispatch_order_no" => $first['dispatch_no'], // "dispatch_item_no" => $value['dispatch_item_no'], "order_no" => $value['order_no'], "order_item_no" => $value['order_item_no'], "customer_no" => $value['customer_no'], "customer_name" => $value['customer_name'], "dealer_no" => $value['dealer_no'], "dealer_name" => $value['dealer_name'], "product_title" => $value['product_title'], "process_title" => $value['process_title'], "color" => $value['color'], "process_title_two" => $value['process_title_two'], "color_two" => $value['color_two'], "color_code_two" => $value['color_code_two'], // "dispatch_item_id" => $value['dispatch_item_id'], "process_code_two" => $value['process_code_two'], "color_code" => $value['color_code'], "order_item_id" => $value['order_item_id'], "production_item_id" => $value['production_item_id'], "process_code" => $value['process_code'], "process_router_id" => $value['process_router_id'], "craft_type_dk" => $value['craft_type_dk'], "craft_type_dk_show" => $value['craft_type_dk_show'], "mat_type" => $value['mat_type'], "site" => null, // "not_finished_num" => $value['not_finished_num'], // "lineId" => $value['lineId'], // "mainKey" => $value['mainKey'] ]; } $completion_orders = [ "completion_order_no" => null, "completion_time" => gmdate("Y-m-d\TH:i:s.000\Z"), "process_id" => $first['process_id'], "team_id" => $first['team_id'], "equipment_id" => $first['equipment_id'], "employee_id" => $first['employee_id'], "remark" => $first['remark'], "site" => null, "created_by" => null, "created_date" => null, "last_modified_by" => null, "last_modified_date" => null, "process_id_show" => $first['process_id_show'], "team_id_show" => $first['team_id_show'], "equipment_id_show" => $first['equipment_id_show'], "employee_id_show" => $first['employee_id_show'] ]; $post = [ "bizTypeEk" => "LOWCODE", "bizId" => -1, "data" => [ "completion_orders_dtl" => $completion_orders_dtl, "completion_orders" => $completion_orders ], "dynamicFormId" => "474201923419320320", "showModelId" => "474382714828959744" ]; //组织数据------ $url = $this->url . 'jbl/api/module-data/completion_orders/completion_orders'; $header = ["Authorization: Bearer {$token}","Content-Type:application/json",'Site:91451322MA5P9JNKXA']; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, 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); file_put_contents('record_get_dispatch.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8); } protected function echoMessage(OutputInterface $output) { $output->writeln($this->data); } }