DoorDeviceJob.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. }
  51. file_put_contents('record_door_data.txt',date("Y-m-d H:i:s",time())."原数据:".json_encode($epc) . "解析后:" . json_encode($order_number) .PHP_EOL.'start'.PHP_EOL,8);
  52. if(empty($order_number)) return;
  53. $this->zs($type,$order_number);
  54. //输出信息 测试
  55. $this->echoMessage(new ConsoleOutput());
  56. }catch (\Exception $exception){
  57. file_put_contents('record_door_error.txt',date("Y-m-d H:i:s",time()).json_encode($this->data) . PHP_EOL.$exception->getMessage()."line" . $exception->getLine().PHP_EOL,8);
  58. }
  59. }
  60. //测试--------------------------------------
  61. public function getDeviceStateCs($data){
  62. if(empty($data)) return [];
  63. list($status,$token) = ClearDataService::getTokenCs();
  64. if(! $status) return [];
  65. $site = $this->site;
  66. $url = "http://121.36.142.167:7774/jbl/api/module-data/device/device/diy/machine_code_list";
  67. $post = [
  68. 'machine_code_list' => $data,
  69. ];
  70. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  71. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  72. $curl = curl_init();
  73. curl_setopt_array($curl, array(
  74. CURLOPT_URL => $url,
  75. CURLOPT_RETURNTRANSFER => true,
  76. CURLOPT_ENCODING => '',
  77. CURLOPT_MAXREDIRS => 10,
  78. CURLOPT_TIMEOUT => 0,
  79. CURLOPT_FOLLOWLOCATION => true,
  80. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  81. CURLOPT_CUSTOMREQUEST => 'POST',
  82. CURLOPT_POSTFIELDS => $json,
  83. CURLOPT_HTTPHEADER => $header,
  84. ));
  85. $response = curl_exec($curl);
  86. curl_close($curl);
  87. file_put_contents('record_door_result_cs.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getDoorState'.PHP_EOL,8);
  88. $result = json_decode($response,true);
  89. if(empty($result)) return false;
  90. $first = $result[0];
  91. return $first['status'];
  92. }
  93. public function productionReceiptCs($data){
  94. list($status,$token) = ClearDataService::getTokenCs();
  95. if(! $status) return;
  96. $site = $this->site;
  97. $url = "http://121.36.142.167:7774/jbl/api/module-data/box_orders/box_orders/diy/production_receipt";
  98. $post = [
  99. 'defective_order_no_list' => $data,
  100. ];
  101. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  102. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  103. $curl = curl_init();
  104. curl_setopt_array($curl, array(
  105. CURLOPT_URL => $url,
  106. CURLOPT_RETURNTRANSFER => true,
  107. CURLOPT_ENCODING => '',
  108. CURLOPT_MAXREDIRS => 10,
  109. CURLOPT_TIMEOUT => 0,
  110. CURLOPT_FOLLOWLOCATION => true,
  111. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  112. CURLOPT_CUSTOMREQUEST => 'POST',
  113. CURLOPT_POSTFIELDS => $json,
  114. CURLOPT_HTTPHEADER => $header,
  115. ));
  116. $response = curl_exec($curl);
  117. curl_close($curl);
  118. file_put_contents('record_door_result_cs.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'in_opt'.PHP_EOL,8);
  119. $return = json_decode($response,true);
  120. if(! empty($return['data'])){
  121. $expire_time = 10;
  122. $key = $this->device_id . InOutOptionService::OrderKeyQueueIn;
  123. Redis::set($key, json_encode($return['data']));
  124. Redis::expire($key, $expire_time);
  125. }
  126. }
  127. public function getDispatchListCs($data){
  128. if(empty($data)) return [];
  129. list($status,$token) = ClearDataService::getTokenCs();
  130. if(! $status) return [];
  131. $site = $this->site;
  132. $url = "http://121.36.142.167:7774/jbl/api/module-data/box_orders/box_orders/diy/defective_order_no_list";
  133. $post = [
  134. 'defective_order_no_list' => $data,
  135. ];
  136. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  137. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  138. $curl = curl_init();
  139. curl_setopt_array($curl, array(
  140. CURLOPT_URL => $url,
  141. CURLOPT_RETURNTRANSFER => true,
  142. CURLOPT_ENCODING => '',
  143. CURLOPT_MAXREDIRS => 10,
  144. CURLOPT_TIMEOUT => 0,
  145. CURLOPT_FOLLOWLOCATION => true,
  146. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  147. CURLOPT_CUSTOMREQUEST => 'POST',
  148. CURLOPT_POSTFIELDS => $json,
  149. CURLOPT_HTTPHEADER => $header,
  150. ));
  151. $response = curl_exec($curl);
  152. curl_close($curl);
  153. file_put_contents('record_door_result_cs.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getlist'.PHP_EOL,8);
  154. return json_decode($response,true);
  155. }
  156. public function completionOrdersCs($data,$type){
  157. list($status,$token) = ClearDataService::getTokenCs();
  158. if(! $status) return;
  159. $site = $this->site;
  160. $device_id = $this->device_id;
  161. //组织数据
  162. $main_dtl = $orderNo = [];
  163. if($type == 1){
  164. $opt = InOutOptionService::OrderKeyQueueIn;
  165. $url = 'http://121.36.142.167:7774/jbl/api/module-data/production_receipt/production_receipt';
  166. $dynamicFormId = "473758926009479168";
  167. $showModelId = "473761325902147584";
  168. foreach ($data as $value){
  169. if(empty($value['box_orders']['delivery_status'])){
  170. $main_dtl[] = [
  171. "product_code"=> $value['brand_code'],
  172. "product_title"=> $value['product_title'],
  173. "product_size"=> $value['product_size'],
  174. "color"=> $value['color'],
  175. "color_two"=> $value['color_two'],
  176. "product_unit_title"=> $value['product_unit_title'],
  177. "product_unit"=> $value['product_unit'],
  178. "color_code"=> $value['color_code'],
  179. "color_code_two"=> $value['color_code_two'],
  180. "in_num"=> $value['box_num'],
  181. ];
  182. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  183. }
  184. }
  185. $datas = [
  186. 'production_receipt' => [
  187. 'production_receipt_no' => null,
  188. 'in_out_type' => 'RK007',
  189. 'box_title' => 'WH05001',
  190. 'in_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  191. 'status' => "NOT_APPROVED",
  192. ],
  193. 'production_receipt_dtl' => $main_dtl
  194. ];
  195. }else{
  196. $opt = InOutOptionService::OrderKeyQueueOut;
  197. $url = 'http://121.36.142.167:7774/jbl/api/module-data/picking_out/picking_out';
  198. $dynamicFormId = "473763313217908736";
  199. $showModelId = "473771977253269504";
  200. $item = 0;
  201. $site_b = $site_b_show = "";
  202. foreach ($data as $value){
  203. if(empty($value['box_orders']['delivery_status'])){
  204. $item = $item + 1;
  205. if(empty($site_b)) $site_b = $value['site'];
  206. if(empty($site_b_show)) $site_b_show = $value['site_show'];
  207. $main_dtl[] = [
  208. "product_code"=> $value['brand_code'],
  209. "product_title"=> $value['product_title'],
  210. "product_size"=> $value['product_size'],
  211. "color"=> $value['color'],
  212. "color_two"=> $value['color_two'],
  213. "product_unit_title"=> $value['product_unit_title'],
  214. "product_unit"=> $value['product_unit'],
  215. "color_code"=> $value['color_code'],
  216. "color_code_two"=> $value['color_code_two'],
  217. "in_num"=> $value['box_num'],
  218. "bus_type" => "BOX",
  219. "bus_type_show" => "包装明细",
  220. "bus_id" => $value['box_orders']['id'],
  221. "bus_no" => $value['box_orders']['defective_order_no'],
  222. "item_num" => $item,
  223. "bus_item_no" => $value['item_num'],
  224. "bus_item_id" => $value['id'],
  225. "order_no" => $value['order_no'],
  226. "customer_no" => $value['customer_no'],
  227. "customer_name" => $value['customer_name'],
  228. "dealer_no" => $value['dealer_no'],
  229. "dealer_name" => $value['dealer_name'],
  230. "site" => $value['site'],
  231. "site_show" => $value['site_show'],
  232. ];
  233. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  234. }
  235. }
  236. $datas = [
  237. 'picking_out' => [
  238. 'picking_out_no' => null,
  239. 'in_out_type' => 'CK010',
  240. 'box_title' => 'WH05001',
  241. 'out_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  242. 'status' => "NOT_APPROVED",
  243. 'in_out_type_show' => "通道门成品出库",
  244. 'box_title_show' => "成品仓",
  245. "site" => $site_b,
  246. "site_show" => $site_b_show
  247. ],
  248. 'picking_out_product' => $main_dtl
  249. ];
  250. }
  251. if(! empty($main_dtl)){
  252. //有产品
  253. $post = [
  254. "bizTypeEk" => "LOWCODE",
  255. "bizId" => -1,
  256. "data" => $datas,
  257. "dynamicFormId" => $dynamicFormId,
  258. "showModelId" => $showModelId
  259. ];
  260. }
  261. //组织数据------
  262. file_put_contents('record_door_result_cs.txt',date('Y-m-d H:i:s'). PHP_EOL . json_encode($post) .PHP_EOL.'post'.PHP_EOL,8);
  263. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  264. $curl = curl_init();
  265. curl_setopt_array($curl, array(
  266. CURLOPT_URL => $url,
  267. CURLOPT_RETURNTRANSFER => true,
  268. CURLOPT_ENCODING => '',
  269. CURLOPT_MAXREDIRS => 10,
  270. CURLOPT_TIMEOUT => 0,
  271. CURLOPT_FOLLOWLOCATION => true,
  272. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  273. CURLOPT_CUSTOMREQUEST => 'POST',
  274. CURLOPT_POSTFIELDS => json_encode($post),
  275. CURLOPT_HTTPHEADER => $header,
  276. ));
  277. $response = curl_exec($curl);
  278. curl_close($curl);
  279. $result = json_decode($response,true);
  280. if(! empty($result['createdDate'])) {
  281. $expire_time = 10;
  282. $key = $device_id . $opt;
  283. Redis::set($key, json_encode($orderNo));
  284. Redis::expire($key, $expire_time);
  285. }
  286. file_put_contents('record_door_result_cs.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8);
  287. }
  288. public function cs($type,$order_number){
  289. //获取是否开启通道门
  290. $bool = $this->getDeviceStateCs([$this->device_id]);
  291. if(! $bool) {
  292. file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time()).'door_not_open'.PHP_EOL,8);
  293. return;
  294. }
  295. if($type == 1){
  296. //入库
  297. $this->productionReceiptCs($order_number);
  298. }else{
  299. //出库
  300. //获取包装单产品
  301. $dispatchList = $this->getDispatchListCs($order_number);
  302. if(empty($dispatchList) || empty($dispatchList['data'])) {
  303. file_put_contents('record_door_result_cs.txt',date("Y-m-d H:i:s",time()).'getlist_end'.PHP_EOL,8);
  304. return;
  305. }
  306. $this->completionOrdersCs($dispatchList['data'],$type);
  307. }
  308. }
  309. //测试--------------------------------------
  310. //正式--------------------------------------
  311. public function getDeviceState($data){
  312. if(empty($data)) return [];
  313. list($status,$token) = ClearDataService::getToken();
  314. if(! $status) return [];
  315. $site = $this->site;
  316. $url = "http://122.112.250.253:7774/jbl/api/module-data/device/device/diy/machine_code_list";
  317. $post = [
  318. 'machine_code_list' => $data,
  319. ];
  320. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  321. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  322. $curl = curl_init();
  323. curl_setopt_array($curl, array(
  324. CURLOPT_URL => $url,
  325. CURLOPT_RETURNTRANSFER => true,
  326. CURLOPT_ENCODING => '',
  327. CURLOPT_MAXREDIRS => 10,
  328. CURLOPT_TIMEOUT => 0,
  329. CURLOPT_FOLLOWLOCATION => true,
  330. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  331. CURLOPT_CUSTOMREQUEST => 'POST',
  332. CURLOPT_POSTFIELDS => $json,
  333. CURLOPT_HTTPHEADER => $header,
  334. ));
  335. $response = curl_exec($curl);
  336. curl_close($curl);
  337. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getDoorState'.PHP_EOL,8);
  338. $result = json_decode($response,true);
  339. if(empty($result)) return false;
  340. $first = $result[0];
  341. return $first['status'];
  342. }
  343. public function productionReceipt($data){
  344. list($status,$token) = ClearDataService::getToken();
  345. if(! $status) return;
  346. $site = $this->site;
  347. $url = "http://122.112.250.253:7774/jbl/api/module-data/box_orders/box_orders/diy/production_receipt";
  348. $post = [
  349. 'defective_order_no_list' => $data,
  350. ];
  351. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  352. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  353. $curl = curl_init();
  354. curl_setopt_array($curl, array(
  355. CURLOPT_URL => $url,
  356. CURLOPT_RETURNTRANSFER => true,
  357. CURLOPT_ENCODING => '',
  358. CURLOPT_MAXREDIRS => 10,
  359. CURLOPT_TIMEOUT => 0,
  360. CURLOPT_FOLLOWLOCATION => true,
  361. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  362. CURLOPT_CUSTOMREQUEST => 'POST',
  363. CURLOPT_POSTFIELDS => $json,
  364. CURLOPT_HTTPHEADER => $header,
  365. ));
  366. $response = curl_exec($curl);
  367. curl_close($curl);
  368. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'in_opt'.PHP_EOL,8);
  369. $return = json_decode($response,true);
  370. if(! empty($return['data'])){
  371. $expire_time = 10;
  372. $key = $this->device_id . InOutOptionService::OrderKeyQueueIn;
  373. Redis::set($key, json_encode($return['data']));
  374. Redis::expire($key, $expire_time);
  375. }
  376. }
  377. public function getDispatchList($data){
  378. if(empty($data)) return [];
  379. list($status,$token) = ClearDataService::getToken();
  380. if(! $status) return [];
  381. $site = $this->site;
  382. $url = "http://122.112.250.253:7774/jbl/api/module-data/box_orders/box_orders/diy/defective_order_no_list";
  383. $post = [
  384. 'defective_order_no_list' => $data,
  385. ];
  386. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  387. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  388. $curl = curl_init();
  389. curl_setopt_array($curl, array(
  390. CURLOPT_URL => $url,
  391. CURLOPT_RETURNTRANSFER => true,
  392. CURLOPT_ENCODING => '',
  393. CURLOPT_MAXREDIRS => 10,
  394. CURLOPT_TIMEOUT => 0,
  395. CURLOPT_FOLLOWLOCATION => true,
  396. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  397. CURLOPT_CUSTOMREQUEST => 'POST',
  398. CURLOPT_POSTFIELDS => $json,
  399. CURLOPT_HTTPHEADER => $header,
  400. ));
  401. $response = curl_exec($curl);
  402. curl_close($curl);
  403. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'getlist'.PHP_EOL,8);
  404. return json_decode($response,true);
  405. }
  406. public function completionOrders($data,$type){
  407. list($status,$token) = ClearDataService::getToken();
  408. if(! $status) return;
  409. $site = $this->site;
  410. $device_id = $this->device_id;
  411. //组织数据
  412. $main_dtl = $orderNo = [];
  413. if($type == 1){
  414. $opt = InOutOptionService::OrderKeyQueueIn;
  415. $url = 'http://122.112.250.253:7774/jbl/api/module-data/production_receipt/production_receipt';
  416. $dynamicFormId = "473758926009479168";
  417. $showModelId = "473761325902147584";
  418. foreach ($data as $value){
  419. if(empty($value['box_orders']['delivery_status'])){
  420. $main_dtl[] = [
  421. "product_code"=> $value['brand_code'],
  422. "product_title"=> $value['product_title'],
  423. "product_size"=> $value['product_size'],
  424. "color"=> $value['color'],
  425. "color_two"=> $value['color_two'],
  426. "product_unit_title"=> $value['product_unit_title'],
  427. "product_unit"=> $value['product_unit'],
  428. "color_code"=> $value['color_code'],
  429. "color_code_two"=> $value['color_code_two'],
  430. "in_num"=> $value['box_num'],
  431. ];
  432. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  433. }
  434. }
  435. $datas = [
  436. 'production_receipt' => [
  437. 'production_receipt_no' => null,
  438. 'in_out_type' => 'RK007',
  439. 'box_title' => 'WH05001',
  440. 'in_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  441. 'status' => "NOT_APPROVED",
  442. ],
  443. 'production_receipt_dtl' => $main_dtl
  444. ];
  445. }else{
  446. $opt = InOutOptionService::OrderKeyQueueOut;
  447. $url = 'http://122.112.250.253:7774/jbl/api/module-data/picking_out/picking_out';
  448. $dynamicFormId = "473763313217908736";
  449. $showModelId = "473771977253269504";
  450. $item = 0;
  451. $site_b = $site_b_show = "";
  452. foreach ($data as $value){
  453. if(empty($value['box_orders']['delivery_status'])){
  454. $item = $item + 1;
  455. if(empty($site_b)) $site_b = $value['site'];
  456. if(empty($site_b_show)) $site_b_show = $value['site_show'];
  457. $main_dtl[] = [
  458. "product_code"=> $value['brand_code'],
  459. "product_title"=> $value['product_title'],
  460. "product_size"=> $value['product_size'],
  461. "color"=> $value['color'],
  462. "color_two"=> $value['color_two'],
  463. "product_unit_title"=> $value['product_unit_title'],
  464. "product_unit"=> $value['product_unit'],
  465. "color_code"=> $value['color_code'],
  466. "color_code_two"=> $value['color_code_two'],
  467. "in_num"=> $value['box_num'],
  468. "bus_type" => "BOX",
  469. "bus_type_show" => "包装明细",
  470. "bus_id" => $value['box_orders']['id'],
  471. "bus_no" => $value['box_orders']['defective_order_no'],
  472. "item_num" => $item,
  473. "bus_item_no" => $value['item_num'],
  474. "bus_item_id" => $value['id'],
  475. "order_no" => $value['order_no'],
  476. "customer_no" => $value['customer_no'],
  477. "customer_name" => $value['customer_name'],
  478. "dealer_no" => $value['dealer_no'],
  479. "dealer_name" => $value['dealer_name'],
  480. "site" => $value['site'],
  481. "site_show" => $value['site_show'],
  482. ];
  483. if(! in_array($value['box_orders']['defective_order_no'], $orderNo)) $orderNo[] = $value['box_orders']['defective_order_no'];
  484. }
  485. }
  486. $datas = [
  487. 'picking_out' => [
  488. 'picking_out_no' => null,
  489. 'in_out_type' => 'CK010',
  490. 'box_title' => 'WH05001',
  491. 'out_time' => gmdate("Y-m-d\TH:i:s.000\Z"),
  492. 'status' => "NOT_APPROVED",
  493. 'in_out_type_show' => "通道门成品出库",
  494. 'box_title_show' => "成品仓",
  495. "site" => $site_b,
  496. "site_show" => $site_b_show
  497. ],
  498. 'picking_out_product' => $main_dtl
  499. ];
  500. }
  501. if(! empty($main_dtl)){
  502. //有产品
  503. $post = [
  504. "bizTypeEk" => "LOWCODE",
  505. "bizId" => -1,
  506. "data" => $datas,
  507. "dynamicFormId" => $dynamicFormId,
  508. "showModelId" => $showModelId
  509. ];
  510. }else{
  511. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . "no_products" .PHP_EOL.'post'.PHP_EOL,8);
  512. return;
  513. }
  514. //组织数据------
  515. 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);
  516. $header = ["Authorization: Bearer {$token}","Content-Type:application/json","Site:{$site}"];
  517. $curl = curl_init();
  518. curl_setopt_array($curl, array(
  519. CURLOPT_URL => $url,
  520. CURLOPT_RETURNTRANSFER => true,
  521. CURLOPT_ENCODING => '',
  522. CURLOPT_MAXREDIRS => 10,
  523. CURLOPT_TIMEOUT => 0,
  524. CURLOPT_FOLLOWLOCATION => true,
  525. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  526. CURLOPT_CUSTOMREQUEST => 'POST',
  527. CURLOPT_POSTFIELDS => json_encode($post),
  528. CURLOPT_HTTPHEADER => $header,
  529. ));
  530. $response = curl_exec($curl);
  531. curl_close($curl);
  532. $result = json_decode($response,true);
  533. if(! empty($result['createdDate'])) {
  534. $expire_time = 10;
  535. $key = $device_id . $opt;
  536. Redis::set($key, json_encode($orderNo));
  537. Redis::expire($key, $expire_time);
  538. }
  539. file_put_contents('record_door_result.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8);
  540. }
  541. public function zs($type,$order_number){
  542. //获取是否开启通道门
  543. $bool = $this->getDeviceState([$this->device_id]);
  544. if(! $bool) {
  545. file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time()).'door_not_open'.PHP_EOL,8);
  546. return;
  547. }
  548. if($type == 1){
  549. //入库
  550. $this->productionReceipt($order_number);
  551. }else{
  552. //出库
  553. //获取包装单产品
  554. $dispatchList = $this->getDispatchList($order_number);
  555. if(empty($dispatchList) || empty($dispatchList['data'])) {
  556. file_put_contents('record_door_result.txt',date("Y-m-d H:i:s",time()).'getlist_end'.PHP_EOL,8);
  557. return;
  558. }
  559. $this->completionOrders($dispatchList['data'],$type);
  560. }
  561. }
  562. //正式--------------------------------------
  563. protected function echoMessage(OutputInterface $output)
  564. {
  565. $output->writeln($this->data);
  566. }
  567. }