|
@@ -0,0 +1,221 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Jobs;
|
|
|
+
|
|
|
+use App\Service\ClearDataService;
|
|
|
+use App\Service\InOutOptionService;
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
+use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+
|
|
|
+class DoorDeviceJob implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+
|
|
|
+ protected $data;
|
|
|
+ protected $type;
|
|
|
+ protected $site;
|
|
|
+ protected $device_id;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a new job instance
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __construct($data,$type,$site,$device_id)
|
|
|
+ {
|
|
|
+ $this->data = $data;
|
|
|
+ $this->type = $type;
|
|
|
+ $this->site = $site ?? '91451322MA5P9JNKXA';
|
|
|
+ $this->device_id = $device_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $epc = $this->data;
|
|
|
+ $type = $this->type;//1 入库 2 出库
|
|
|
+ $order_number = [];
|
|
|
+ foreach ($epc as $value){
|
|
|
+ $order_number[] = hex2bin($value); //十六进制字符串转回 原来字符串
|
|
|
+ }
|
|
|
+ file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time())."原数据:".json_encode($epc) . "解析后:" . json_encode($order_number) .PHP_EOL.'start'.PHP_EOL,8);
|
|
|
+ if(empty($order_number)) return;
|
|
|
+
|
|
|
+ //获取包装单产品
|
|
|
+ $dispatchList = $this->getDispatchList($order_number);
|
|
|
+ if(empty($dispatchList) || empty($dispatchList['data'])) return;
|
|
|
+ $this->completionOrders($dispatchList['data'],$type);
|
|
|
+
|
|
|
+ //输出信息 测试
|
|
|
+ $this->echoMessage(new ConsoleOutput());
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ file_put_contents('record_door_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::getTokenCs();
|
|
|
+ if(! $status) return [];
|
|
|
+
|
|
|
+ $site = $this->site;
|
|
|
+ $url = "http://121.36.142.167:7774/jbl/api/module-data/box_orders/box_orders/diy/defective_order_no_list";
|
|
|
+ $post = [
|
|
|
+ 'defective_order_no_list' => $data,
|
|
|
+ ];
|
|
|
+ $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
|
|
|
+ $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_door_result.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,$type){
|
|
|
+ list($status,$token) = ClearDataService::getTokenCs();
|
|
|
+ if(! $status) return;
|
|
|
+
|
|
|
+ $site = $this->site;
|
|
|
+ $device_id = $this->device_id;
|
|
|
+ //组织数据
|
|
|
+ $main_dtl = $orderNo = [];
|
|
|
+ if($type == 1){
|
|
|
+ $opt = InOutOptionService::OrderKeyQueueIn;
|
|
|
+ $url = 'http://121.36.142.167:7774/jbl/api/module-data/production_receipt/production_receipt';
|
|
|
+ $dynamicFormId = "473758926009479168";
|
|
|
+ $showModelId = "473761325902147584";
|
|
|
+ foreach ($data as $value){
|
|
|
+ if(empty($value['box_orders']['delivery_status'])){
|
|
|
+ $main_dtl[] = [
|
|
|
+ "product_code"=> $value['brand_code'],
|
|
|
+ "product_title"=> $value['product_title'],
|
|
|
+ "product_size"=> $value['product_size'],
|
|
|
+ "color"=> $value['color'],
|
|
|
+ "color_two"=> $value['color_two'],
|
|
|
+ "product_unit_title"=> $value['product_unit_title'],
|
|
|
+ "product_unit"=> $value['product_unit'],
|
|
|
+ "color_code"=> $value['color_code'],
|
|
|
+ "color_code_two"=> $value['color_code_two'],
|
|
|
+ "in_num"=> $value['box_num'],
|
|
|
+ ];
|
|
|
+ if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $datas = [
|
|
|
+ 'production_receipt' => [
|
|
|
+ 'production_receipt_no' => null,
|
|
|
+ 'in_out_type' => 'RK007',
|
|
|
+ 'box_title' => 'WH05001',
|
|
|
+ 'in_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
|
|
|
+ 'status' => "NOT_APPROVED",
|
|
|
+ ],
|
|
|
+ 'production_receipt_dtl' => $main_dtl
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $opt = InOutOptionService::OrderKeyQueueOut;
|
|
|
+ $url = 'http://121.36.142.167:7774/jbl/api/module-data/picking_out/picking_out';
|
|
|
+ $dynamicFormId = "473763313217908736";
|
|
|
+ $showModelId = "473771977253269504";
|
|
|
+ foreach ($data as $value){
|
|
|
+ if(empty($value['box_orders']['delivery_status'])){
|
|
|
+ $main_dtl[] = [
|
|
|
+ "product_code"=> $value['brand_code'],
|
|
|
+ "product_title"=> $value['product_title'],
|
|
|
+ "product_size"=> $value['product_size'],
|
|
|
+ "color"=> $value['color'],
|
|
|
+ "color_two"=> $value['color_two'],
|
|
|
+ "product_unit_title"=> $value['product_unit_title'],
|
|
|
+ "product_unit"=> $value['product_unit'],
|
|
|
+ "color_code"=> $value['color_code'],
|
|
|
+ "color_code_two"=> $value['color_code_two'],
|
|
|
+ "in_num"=> $value['box_num'],
|
|
|
+ ];
|
|
|
+ if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $datas = [
|
|
|
+ 'picking_out' => [
|
|
|
+ 'picking_out_no' => null,
|
|
|
+ 'in_out_type' => 'CK010',
|
|
|
+ 'box_title' => 'WH05001',
|
|
|
+ 'out_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
|
|
|
+ 'status' => "NOT_APPROVED",
|
|
|
+ ],
|
|
|
+ 'picking_out_product' => $main_dtl
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($main_dtl)){
|
|
|
+ //有产品
|
|
|
+ $post = [
|
|
|
+ "bizTypeEk" => "LOWCODE",
|
|
|
+ "bizId" => -1,
|
|
|
+ "data" => $datas,
|
|
|
+ "dynamicFormId" => $dynamicFormId,
|
|
|
+ "showModelId" => $showModelId
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //组织数据------
|
|
|
+ file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . json_encode($post) .PHP_EOL.'post'.PHP_EOL,8);
|
|
|
+
|
|
|
+ $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
+ $result = json_decode($response,true);
|
|
|
+ if(! empty($result['createdDate'])) {
|
|
|
+ $expire_time = 6;
|
|
|
+ $key = $device_id . $opt;
|
|
|
+ Redis::set($key, json_encode($orderNo));
|
|
|
+ Redis::expire($key, $expire_time);
|
|
|
+ }
|
|
|
+
|
|
|
+ file_put_contents('record_door_result.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);
|
|
|
+ }
|
|
|
+}
|