DoorDeviceJob.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. namespace App\Jobs;
  3. use App\Service\ClearDataService;
  4. use App\Service\InOutOptionService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Illuminate\Support\Facades\Redis;
  11. use Symfony\Component\Console\Output\ConsoleOutput;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class DoorDeviceJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. protected $data;
  17. protected $type;
  18. protected $site;
  19. protected $device_id;
  20. /**
  21. * Create a new job instance
  22. *
  23. * @return void
  24. */
  25. public function __construct($data,$type,$site,$device_id)
  26. {
  27. $this->data = $data;
  28. $this->type = $type;
  29. $this->site = $site ?? '91451322MA5P9JNKXA';
  30. $this->device_id = $device_id;
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. try{
  40. $epc = $this->data;
  41. $type = $this->type;//1 入库 2 出库
  42. $order_number = [];
  43. foreach ($epc as $value){
  44. $str = @hex2bin($value);
  45. $str = ltrim($str, "\x00");// 代0字符串
  46. $str = str_replace(chr(26), '', $str); //过滤CRTL-Z字符
  47. if(! empty($str) && substr($str, 0, 2) === "BZ"){
  48. if(! in_array($str, $order_number)) $order_number[] = $str; // 十六进制字符串转回原来字符串
  49. }
  50. // $order_number[] = hex2bin($value); //十六进制字符串转回 原来字符串
  51. }
  52. 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);
  53. if(empty($order_number)) {
  54. file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time()).'start_end'.PHP_EOL,8);
  55. return;
  56. }
  57. if($type == 1){
  58. //入库
  59. $this->productionReceipt($order_number);
  60. }else{
  61. //出库
  62. //获取包装单产品
  63. $dispatchList = $this->getDispatchList($order_number);
  64. if(empty($dispatchList) || empty($dispatchList['data'])) {
  65. file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time()).'getlist_end'.PHP_EOL,8);
  66. return;
  67. }
  68. $this->completionOrders($dispatchList['data'],$type);
  69. }
  70. //输出信息 测试
  71. $this->echoMessage(new ConsoleOutput());
  72. }catch (\Exception $exception){
  73. 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);
  74. }
  75. }
  76. public function productionReceiptCs($data){
  77. list($status,$token) = ClearDataService::getTokenCs();
  78. if(! $status) return;
  79. $site = $this->site;
  80. $url = "http://121.36.142.167:7774/jbl/api/module-data/box_orders/box_orders/diy/production_receipt";
  81. $post = [
  82. 'defective_order_no_list' => $data,
  83. ];
  84. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  85. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  86. $curl = curl_init();
  87. curl_setopt_array($curl, array(
  88. CURLOPT_URL => $url,
  89. CURLOPT_RETURNTRANSFER => true,
  90. CURLOPT_ENCODING => '',
  91. CURLOPT_MAXREDIRS => 10,
  92. CURLOPT_TIMEOUT => 0,
  93. CURLOPT_FOLLOWLOCATION => true,
  94. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  95. CURLOPT_CUSTOMREQUEST => 'POST',
  96. CURLOPT_POSTFIELDS => $json,
  97. CURLOPT_HTTPHEADER => $header,
  98. ));
  99. $response = curl_exec($curl);
  100. curl_close($curl);
  101. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'in_opt'.PHP_EOL,8);
  102. $return = json_decode($response,true);
  103. if(! empty($return['data'])){
  104. $expire_time = 10;
  105. $key = $this->device_id . InOutOptionService::OrderKeyQueueIn;
  106. Redis::set($key, json_encode($return['data']));
  107. Redis::expire($key, $expire_time);
  108. }
  109. }
  110. public function getDispatchListCs($data){
  111. if(empty($data)) return [];
  112. list($status,$token) = ClearDataService::getTokenCs();
  113. if(! $status) return [];
  114. $site = $this->site;
  115. $url = "http://121.36.142.167:7774/jbl/api/module-data/box_orders/box_orders/diy/defective_order_no_list";
  116. $post = [
  117. 'defective_order_no_list' => $data,
  118. ];
  119. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  120. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  121. $curl = curl_init();
  122. curl_setopt_array($curl, array(
  123. CURLOPT_URL => $url,
  124. CURLOPT_RETURNTRANSFER => true,
  125. CURLOPT_ENCODING => '',
  126. CURLOPT_MAXREDIRS => 10,
  127. CURLOPT_TIMEOUT => 0,
  128. CURLOPT_FOLLOWLOCATION => true,
  129. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  130. CURLOPT_CUSTOMREQUEST => 'POST',
  131. CURLOPT_POSTFIELDS => $json,
  132. CURLOPT_HTTPHEADER => $header,
  133. ));
  134. $response = curl_exec($curl);
  135. curl_close($curl);
  136. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getlist'.PHP_EOL,8);
  137. return json_decode($response,true);
  138. }
  139. public function completionOrdersCs($data,$type){
  140. list($status,$token) = ClearDataService::getTokenCs();
  141. if(! $status) return;
  142. $site = $this->site;
  143. $device_id = $this->device_id;
  144. //组织数据
  145. $main_dtl = $orderNo = [];
  146. if($type == 1){
  147. $opt = InOutOptionService::OrderKeyQueueIn;
  148. $url = 'http://121.36.142.167:7774/jbl/api/module-data/production_receipt/production_receipt';
  149. $dynamicFormId = "473758926009479168";
  150. $showModelId = "473761325902147584";
  151. foreach ($data as $value){
  152. if(empty($value['box_orders']['delivery_status'])){
  153. $main_dtl[] = [
  154. "product_code"=> $value['brand_code'],
  155. "product_title"=> $value['product_title'],
  156. "product_size"=> $value['product_size'],
  157. "color"=> $value['color'],
  158. "color_two"=> $value['color_two'],
  159. "product_unit_title"=> $value['product_unit_title'],
  160. "product_unit"=> $value['product_unit'],
  161. "color_code"=> $value['color_code'],
  162. "color_code_two"=> $value['color_code_two'],
  163. "in_num"=> $value['box_num'],
  164. ];
  165. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  166. }
  167. }
  168. $datas = [
  169. 'production_receipt' => [
  170. 'production_receipt_no' => null,
  171. 'in_out_type' => 'RK007',
  172. 'box_title' => 'WH05001',
  173. 'in_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  174. 'status' => "NOT_APPROVED",
  175. ],
  176. 'production_receipt_dtl' => $main_dtl
  177. ];
  178. }else{
  179. $opt = InOutOptionService::OrderKeyQueueOut;
  180. $url = 'http://121.36.142.167:7774/jbl/api/module-data/picking_out/picking_out';
  181. $dynamicFormId = "473763313217908736";
  182. $showModelId = "473771977253269504";
  183. foreach ($data as $value){
  184. if(empty($value['box_orders']['delivery_status'])){
  185. $main_dtl[] = [
  186. "product_code"=> $value['brand_code'],
  187. "product_title"=> $value['product_title'],
  188. "product_size"=> $value['product_size'],
  189. "color"=> $value['color'],
  190. "color_two"=> $value['color_two'],
  191. "product_unit_title"=> $value['product_unit_title'],
  192. "product_unit"=> $value['product_unit'],
  193. "color_code"=> $value['color_code'],
  194. "color_code_two"=> $value['color_code_two'],
  195. "in_num"=> $value['box_num'],
  196. ];
  197. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  198. }
  199. }
  200. $datas = [
  201. 'picking_out' => [
  202. 'picking_out_no' => null,
  203. 'in_out_type' => 'CK010',
  204. 'box_title' => 'WH05001',
  205. 'out_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  206. 'status' => "NOT_APPROVED",
  207. ],
  208. 'picking_out_product' => $main_dtl
  209. ];
  210. }
  211. if(! empty($main_dtl)){
  212. //有产品
  213. $post = [
  214. "bizTypeEk" => "LOWCODE",
  215. "bizId" => -1,
  216. "data" => $datas,
  217. "dynamicFormId" => $dynamicFormId,
  218. "showModelId" => $showModelId
  219. ];
  220. }
  221. //组织数据------
  222. 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);
  223. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  224. $curl = curl_init();
  225. curl_setopt_array($curl, array(
  226. CURLOPT_URL => $url,
  227. CURLOPT_RETURNTRANSFER => true,
  228. CURLOPT_ENCODING => '',
  229. CURLOPT_MAXREDIRS => 10,
  230. CURLOPT_TIMEOUT => 0,
  231. CURLOPT_FOLLOWLOCATION => true,
  232. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  233. CURLOPT_CUSTOMREQUEST => 'POST',
  234. CURLOPT_POSTFIELDS => json_encode($post),
  235. CURLOPT_HTTPHEADER => $header,
  236. ));
  237. $response = curl_exec($curl);
  238. curl_close($curl);
  239. $result = json_decode($response,true);
  240. if(! empty($result['createdDate'])) {
  241. $expire_time = 10;
  242. $key = $device_id . $opt;
  243. Redis::set($key, json_encode($orderNo));
  244. Redis::expire($key, $expire_time);
  245. }
  246. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8);
  247. }
  248. public function productionReceipt($data){
  249. list($status,$token) = ClearDataService::getToken();
  250. if(! $status) return;
  251. $site = $this->site;
  252. $url = "http://122.112.250.253:7774/jbl/api/module-data/box_orders/box_orders/diy/production_receipt";
  253. $post = [
  254. 'defective_order_no_list' => $data,
  255. ];
  256. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  257. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  258. $curl = curl_init();
  259. curl_setopt_array($curl, array(
  260. CURLOPT_URL => $url,
  261. CURLOPT_RETURNTRANSFER => true,
  262. CURLOPT_ENCODING => '',
  263. CURLOPT_MAXREDIRS => 10,
  264. CURLOPT_TIMEOUT => 0,
  265. CURLOPT_FOLLOWLOCATION => true,
  266. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  267. CURLOPT_CUSTOMREQUEST => 'POST',
  268. CURLOPT_POSTFIELDS => $json,
  269. CURLOPT_HTTPHEADER => $header,
  270. ));
  271. $response = curl_exec($curl);
  272. curl_close($curl);
  273. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'in_opt'.PHP_EOL,8);
  274. $return = json_decode($response,true);
  275. if(! empty($return['data'])){
  276. $expire_time = 10;
  277. $key = $this->device_id . InOutOptionService::OrderKeyQueueIn;
  278. Redis::set($key, json_encode($return['data']));
  279. Redis::expire($key, $expire_time);
  280. }
  281. }
  282. public function getDispatchList($data){
  283. if(empty($data)) return [];
  284. list($status,$token) = ClearDataService::getToken();
  285. if(! $status) return [];
  286. $site = $this->site;
  287. $url = "http://122.112.250.253:7774/jbl/api/module-data/box_orders/box_orders/diy/defective_order_no_list";
  288. $post = [
  289. 'defective_order_no_list' => $data,
  290. ];
  291. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  292. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  293. $curl = curl_init();
  294. curl_setopt_array($curl, array(
  295. CURLOPT_URL => $url,
  296. CURLOPT_RETURNTRANSFER => true,
  297. CURLOPT_ENCODING => '',
  298. CURLOPT_MAXREDIRS => 10,
  299. CURLOPT_TIMEOUT => 0,
  300. CURLOPT_FOLLOWLOCATION => true,
  301. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  302. CURLOPT_CUSTOMREQUEST => 'POST',
  303. CURLOPT_POSTFIELDS => $json,
  304. CURLOPT_HTTPHEADER => $header,
  305. ));
  306. $response = curl_exec($curl);
  307. curl_close($curl);
  308. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getlist'.PHP_EOL,8);
  309. return json_decode($response,true);
  310. }
  311. public function completionOrders($data,$type){
  312. list($status,$token) = ClearDataService::getToken();
  313. if(! $status) return;
  314. $site = $this->site;
  315. $device_id = $this->device_id;
  316. //组织数据
  317. $main_dtl = $orderNo = [];
  318. if($type == 1){
  319. $opt = InOutOptionService::OrderKeyQueueIn;
  320. $url = 'http://122.112.250.253:7774/jbl/api/module-data/production_receipt/production_receipt';
  321. $dynamicFormId = "473758926009479168";
  322. $showModelId = "473761325902147584";
  323. foreach ($data as $value){
  324. if(empty($value['box_orders']['delivery_status'])){
  325. $main_dtl[] = [
  326. "product_code"=> $value['brand_code'],
  327. "product_title"=> $value['product_title'],
  328. "product_size"=> $value['product_size'],
  329. "color"=> $value['color'],
  330. "color_two"=> $value['color_two'],
  331. "product_unit_title"=> $value['product_unit_title'],
  332. "product_unit"=> $value['product_unit'],
  333. "color_code"=> $value['color_code'],
  334. "color_code_two"=> $value['color_code_two'],
  335. "in_num"=> $value['box_num'],
  336. ];
  337. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  338. }
  339. }
  340. $datas = [
  341. 'production_receipt' => [
  342. 'production_receipt_no' => null,
  343. 'in_out_type' => 'RK007',
  344. 'box_title' => 'WH05001',
  345. 'in_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  346. 'status' => "NOT_APPROVED",
  347. ],
  348. 'production_receipt_dtl' => $main_dtl
  349. ];
  350. }else{
  351. $opt = InOutOptionService::OrderKeyQueueOut;
  352. $url = 'http://122.112.250.253:7774/jbl/api/module-data/picking_out/picking_out';
  353. $dynamicFormId = "473763313217908736";
  354. $showModelId = "473771977253269504";
  355. foreach ($data as $value){
  356. if(empty($value['box_orders']['delivery_status'])){
  357. $main_dtl[] = [
  358. "product_code"=> $value['brand_code'],
  359. "product_title"=> $value['product_title'],
  360. "product_size"=> $value['product_size'],
  361. "color"=> $value['color'],
  362. "color_two"=> $value['color_two'],
  363. "product_unit_title"=> $value['product_unit_title'],
  364. "product_unit"=> $value['product_unit'],
  365. "color_code"=> $value['color_code'],
  366. "color_code_two"=> $value['color_code_two'],
  367. "in_num"=> $value['box_num'],
  368. ];
  369. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  370. }
  371. }
  372. $datas = [
  373. 'picking_out' => [
  374. 'picking_out_no' => null,
  375. 'in_out_type' => 'CK010',
  376. 'box_title' => 'WH05001',
  377. 'out_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  378. 'status' => "NOT_APPROVED",
  379. ],
  380. 'picking_out_product' => $main_dtl
  381. ];
  382. }
  383. if(! empty($main_dtl)){
  384. //有产品
  385. $post = [
  386. "bizTypeEk" => "LOWCODE",
  387. "bizId" => -1,
  388. "data" => $datas,
  389. "dynamicFormId" => $dynamicFormId,
  390. "showModelId" => $showModelId
  391. ];
  392. }
  393. //组织数据------
  394. 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);
  395. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  396. $curl = curl_init();
  397. curl_setopt_array($curl, array(
  398. CURLOPT_URL => $url,
  399. CURLOPT_RETURNTRANSFER => true,
  400. CURLOPT_ENCODING => '',
  401. CURLOPT_MAXREDIRS => 10,
  402. CURLOPT_TIMEOUT => 0,
  403. CURLOPT_FOLLOWLOCATION => true,
  404. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  405. CURLOPT_CUSTOMREQUEST => 'POST',
  406. CURLOPT_POSTFIELDS => json_encode($post),
  407. CURLOPT_HTTPHEADER => $header,
  408. ));
  409. $response = curl_exec($curl);
  410. curl_close($curl);
  411. $result = json_decode($response,true);
  412. if(! empty($result['createdDate'])) {
  413. $expire_time = 10;
  414. $key = $device_id . $opt;
  415. Redis::set($key, json_encode($orderNo));
  416. Redis::expire($key, $expire_time);
  417. }
  418. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8);
  419. }
  420. protected function echoMessage(OutputInterface $output)
  421. {
  422. $output->writeln($this->data);
  423. }
  424. }