DwyController.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Model\BigKingTbj;
  4. use App\Service\DwyService;
  5. use App\Service\EmployeeService;
  6. use App\Service\SysMenuService;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Redis;
  9. use Illuminate\Support\Str;
  10. class DwyController extends BaseController
  11. {
  12. public function advertisement()
  13. {
  14. return ['status' => 200, 'data' => [
  15. 'video' => ['https://clouddevice.qingyaokeji.com/1.mp4',
  16. 'https://clouddevice.qingyaokeji.com/2.mp4'],
  17. 'img' => [
  18. 'https://clouddevice.qingyaokeji.com/3.jpeg',
  19. 'https://clouddevice.qingyaokeji.com/3.jpeg',
  20. ],
  21. 'limit_time' => 10
  22. ]];
  23. }
  24. public function openCommand(Request $request)
  25. {
  26. $data = $request->all();
  27. file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
  28. $device_id = $data['device_code'];
  29. $box_code = $data['box_code'];
  30. $key = $data['type'];
  31. if ($key === 'UP') {
  32. $num = Redis::get($device_id . 'status_num');
  33. if (empty($num)) $num = 0;
  34. $num++;
  35. if ($num === 1) {
  36. Redis::set($device_id . 'status_num', $num);
  37. Redis::expire($device_id . 'status_num', 300);
  38. Redis::set($device_id . 'status', 201);
  39. Redis::expire($device_id . 'status', 300);
  40. Redis::set($device_id, json_encode([$box_code]));
  41. Redis::expire($device_id, 300);
  42. } else {
  43. $old = Redis::get($device_id);
  44. if (empty($old)) $old = [];
  45. else $old = json_decode($old, true);
  46. $data = array_merge($old, [$box_code]);
  47. Redis::set($device_id, json_encode($data));
  48. Redis::expire($device_id, 300);
  49. Redis::del($device_id . 'status');
  50. Redis::del($device_id . 'status_num');
  51. }
  52. } else {
  53. Redis::set($device_id, json_encode([$box_code]));
  54. Redis::expire($device_id, 300);
  55. }
  56. return ['status' => 200];
  57. }
  58. public function openDoor(Request $request)
  59. {
  60. $data = $s = $request->all();
  61. file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
  62. $data = $data['device_code'];
  63. $code = Redis::get($data);
  64. Redis::del($data);
  65. // return ['data'=>['CK00001','CK00018'],'status'=>200];
  66. if (empty($code)) return ['data' => [], 'status' => 201];
  67. $status = Redis::get($data . 'status');
  68. if (empty($status)) $status = 200;
  69. if(isset($s['again'])&&$s['again']===true) $status = 201;
  70. return ['data' => json_decode($code, true), 'status' => $status];
  71. }
  72. public function maintenance(Request $request)
  73. {
  74. $data = [
  75. [
  76. 'code' => 'CK00001',
  77. 'title' => '设备仓'
  78. ],[
  79. 'code' => 'CK00003',
  80. 'title' => '维修仓'
  81. ],[
  82. 'code' => 'CK00004',
  83. 'title' => '商标一号仓'
  84. ],[
  85. 'code' => 'CK00005',
  86. 'title' => '商标二号仓'
  87. ],[
  88. 'code' => 'CK00006',
  89. 'title' => '商标三号仓'
  90. ],[
  91. 'code' => 'CK00007',
  92. 'title' => '商标四号仓'
  93. ],[
  94. 'code' => 'CK00008',
  95. 'title' => '商标五号仓'
  96. ],[
  97. 'code' => 'CK00009',
  98. 'title' => '商标六号仓'
  99. ],[
  100. 'code' => 'CK00010',
  101. 'title' => '商标七号仓'
  102. ],[
  103. 'code' => 'CK00011',
  104. 'title' => '商标八号仓'
  105. ],[
  106. 'code' => 'CK00012',
  107. 'title' => '商标九号仓'
  108. ],[
  109. 'code' => 'CK00013',
  110. 'title' => '商标十号仓'
  111. ],[
  112. 'code' => 'CK00014',
  113. 'title' => '商标十一号仓'
  114. ],[
  115. 'code' => 'CK00015',
  116. 'title' => '商标十二号仓'
  117. ],[
  118. 'code' => 'CK00016',
  119. 'title' => '商标十三号仓'
  120. ],[
  121. 'code' => 'CK00017',
  122. 'title' => '商标十四号仓'
  123. ],[
  124. 'code' => 'CK00018',
  125. 'title' => '商标十五号仓'
  126. ],[
  127. 'code' => 'CK00019',
  128. 'title' => '商标十六号仓'
  129. ]
  130. ];
  131. return ['data' => $data, 'status' => 200];
  132. }
  133. public function getOpenCommand(Request $request)
  134. {
  135. $data = $request->all();
  136. file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
  137. $device_id = $data['device_code'];
  138. $box_code = $data['box_code'];
  139. $key = $device_id . '_' . $box_code;
  140. $return = 201;
  141. $status = Redis::get($key);
  142. if ($status) {
  143. $return = 200;
  144. Redis::del($key);
  145. }
  146. return ['status' => $return];
  147. }
  148. public function boxList(Request $request)
  149. {
  150. $param = $request->all();
  151. $token = $param['token'];
  152. $device_code = $param['device_code'];
  153. //商标仓列表
  154. $url = 'https://tm.dwycloud.com/jbl/api/module-data/device/device/diy/device_code';
  155. $header = [
  156. 'Content-Type:application/json',
  157. 'Authorization: ' . $token,
  158. ];
  159. $box_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header);
  160. $box_data = json_decode($box_data, true);
  161. if (isset($box_data['status']) && $box_data['status'] === 'success') {
  162. //库存查询
  163. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  164. $stock_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header);
  165. $stock_data = json_decode($stock_data, true);
  166. if ($stock_data) {
  167. $list = [];
  168. $material_list = [];
  169. foreach ($box_data['data'] as $v) {
  170. $list[$v['box_code']] = [
  171. 'material_code' => $v['material_code'],
  172. 'material_code_show' => $v['material_code_show'],
  173. 'box_code' => $v['box_code'],
  174. 'box_code_show' => $v['box_code_show'],
  175. 'min_stock_qty' => $v['min_stock_qty'] ?? 0,
  176. 'safe_stock_qty' => $v['safe_stock_qty'] ?? 0,
  177. 'status' => 1, //0设备仓中没有对应库存,1有对应库存,2对应商标仓中还有数量不允许上标
  178. 'qty' => 0,
  179. ];
  180. $material_list[$v['material_code']][] = $v['box_code'];
  181. }
  182. $return = [];
  183. foreach ($stock_data as $v) {
  184. if (isset($material_list[$v['material_code']]) && $v['box_code'] == 'CK00001' && $v['qty'] > 0) {
  185. foreach ($material_list[$v['material_code']] as $vv) {
  186. $list[$vv]['status'] = 1;
  187. }
  188. }
  189. if (isset($list[$v['box_code']]) && $v['qty'] > 0) {
  190. $list[$v['box_code']]['qty'] = $v['qty'];
  191. }
  192. }
  193. foreach ($list as $v) {
  194. if ($v['qty'] > 0) {
  195. $v['status'] = 2;
  196. }
  197. $return[] = $v;
  198. }
  199. return ['status' => 'success', 'data' => $return];
  200. }
  201. }
  202. return $box_data;
  203. }
  204. public function test(){
  205. $a = json_decode('{
  206. "status": 200,
  207. "data": [
  208. {
  209. "created_date_lt": "2024-06-08T08:30:15.000Z",
  210. "created_date": "2024-06-08T08:30:15.086Z",
  211. "last_modified_by_show": "余丽娴",
  212. "device_code": "a6a672c3e458bed2",
  213. "material_code": "40010127000001",
  214. "last_modified_by": "553395510115962882",
  215. "unit_code_show": "张",
  216. "bus_type_dk": "SUPPLIER",
  217. "created_by": "553395510115962882",
  218. "unit_code": "ST",
  219. "dynamic_form_value_id": "587196751249805312",
  220. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  221. "device_code_show": "天凝工厂1号机",
  222. "belong_org": "0102",
  223. "bus_type_dk_show": "工厂",
  224. "created_by_show": "余丽娴",
  225. "id": "587196751312719872",
  226. "supplier_code": "0102",
  227. "main_table_id": null,
  228. "last_modified_date_lt": "2024-06-08T08:30:15.000Z",
  229. "material_code_show": "尊贵免漆板ENF小标",
  230. "qty": 4040,
  231. "specs": null,
  232. "box_code": "CK00005",
  233. "request_id": null,
  234. "detail_table_id": null,
  235. "last_modified_date": "2024-06-08T08:30:15.095Z",
  236. "box_code_show": "商标二号仓",
  237. "in_stock_qty": 5000,
  238. "use_qty": 4040,
  239. "product_list": [
  240. {
  241. "product_code": "BC450108000001",
  242. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  243. "order_item_id": "581029211289030656",
  244. "order_item_id_show": "SO202405200171",
  245. "process_title": "",
  246. "color": "",
  247. "process_title_two": "",
  248. "color_two": "",
  249. "send_qty": "120",
  250. "fake_qty": "120",
  251. "restock_qty": 0
  252. },
  253. {
  254. "product_code": "BC450108000001",
  255. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  256. "order_item_id": "581029211242893312",
  257. "order_item_id_show": "SO202405200171",
  258. "process_title": "",
  259. "color": "",
  260. "process_title_two": "",
  261. "color_two": "",
  262. "send_qty": "30",
  263. "fake_qty": "30",
  264. "restock_qty": 0
  265. },
  266. {
  267. "product_code": "BC450108000001",
  268. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  269. "order_item_id": "581029211221921792",
  270. "order_item_id_show": "SO202405200171",
  271. "process_title": "",
  272. "color": "",
  273. "process_title_two": "",
  274. "color_two": "",
  275. "send_qty": "160",
  276. "fake_qty": "160",
  277. "restock_qty": 0
  278. }
  279. ],
  280. "send_qty": 310,
  281. "restore_qty": 0
  282. },
  283. {
  284. "created_date_lt": "2024-06-06T10:34:14.000Z",
  285. "created_date": "2024-06-06T10:34:14.502Z",
  286. "last_modified_by_show": "余丽娴",
  287. "device_code": "a6a672c3e458bed2",
  288. "material_code": "40010232000001",
  289. "last_modified_by": "553395510115962882",
  290. "unit_code_show": "张",
  291. "bus_type_dk": "SUPPLIER",
  292. "created_by": "553395510115962882",
  293. "unit_code": "ST",
  294. "dynamic_form_value_id": "586503178690891776",
  295. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  296. "device_code_show": "天凝工厂1号机",
  297. "belong_org": "0102",
  298. "bus_type_dk_show": "工厂",
  299. "created_by_show": "余丽娴",
  300. "id": "586503178758000640",
  301. "supplier_code": "0102",
  302. "main_table_id": null,
  303. "last_modified_date_lt": "2024-06-06T10:34:14.000Z",
  304. "material_code_show": "优选A6森芯板E0小标",
  305. "qty": 4519,
  306. "specs": null,
  307. "box_code": "CK00007",
  308. "request_id": null,
  309. "detail_table_id": null,
  310. "last_modified_date": "2024-06-06T10:34:14.512Z",
  311. "box_code_show": "商标四号仓",
  312. "in_stock_qty": 4652,
  313. "use_qty": 4519,
  314. "product_list": [],
  315. "send_qty": 0
  316. },
  317. {
  318. "created_date_lt": "2024-06-08T05:59:10.000Z",
  319. "created_date": "2024-06-08T05:59:10.127Z",
  320. "last_modified_by_show": "余丽娴",
  321. "device_code": "a6a672c3e458bed2",
  322. "material_code": "40010504000001",
  323. "last_modified_by": "553395510115962882",
  324. "unit_code_show": "张",
  325. "bus_type_dk": "SUPPLIER",
  326. "created_by": "553395510115962882",
  327. "unit_code": "ST",
  328. "dynamic_form_value_id": "587158730056011776",
  329. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  330. "device_code_show": "天凝工厂1号机",
  331. "belong_org": "0102",
  332. "bus_type_dk_show": "工厂",
  333. "created_by_show": "余丽娴",
  334. "id": "587158730123120640",
  335. "supplier_code": "0102",
  336. "main_table_id": null,
  337. "last_modified_date_lt": "2024-06-08T05:59:10.000Z",
  338. "material_code_show": "ENF圆标",
  339. "qty": 2909,
  340. "specs": null,
  341. "box_code": "CK00010",
  342. "request_id": null,
  343. "detail_table_id": null,
  344. "last_modified_date": "2024-06-08T05:59:10.136Z",
  345. "box_code_show": "商标七号仓",
  346. "in_stock_qty": 5000,
  347. "use_qty": 2909,
  348. "safe_stock_qty": 400,
  349. "min_stock_qty": 100,
  350. "product_list": [
  351. {
  352. "product_code": "BC450108000001",
  353. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  354. "order_item_id": "581029211289030656",
  355. "order_item_id_show": "SO202405200171",
  356. "process_title": "",
  357. "color": "",
  358. "process_title_two": "",
  359. "color_two": "",
  360. "send_qty": "120",
  361. "fake_qty": "120",
  362. "restock_qty": 0
  363. },
  364. {
  365. "product_code": "BC450108000001",
  366. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  367. "order_item_id": "581029211242893312",
  368. "order_item_id_show": "SO202405200171",
  369. "process_title": "",
  370. "color": "",
  371. "process_title_two": "",
  372. "color_two": "",
  373. "send_qty": "30",
  374. "fake_qty": "30",
  375. "restock_qty": 0
  376. },
  377. {
  378. "product_code": "BC450108000001",
  379. "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W",
  380. "order_item_id": "581029211221921792",
  381. "order_item_id_show": "SO202405200171",
  382. "process_title": "",
  383. "color": "",
  384. "process_title_two": "",
  385. "color_two": "",
  386. "send_qty": "160",
  387. "fake_qty": "160",
  388. "restock_qty": 0
  389. }
  390. ],
  391. "send_qty": 310,
  392. "restore_qty": 0
  393. },
  394. {
  395. "created_date_lt": "2024-06-06T07:05:12.000Z",
  396. "created_date": "2024-06-06T07:05:12.783Z",
  397. "last_modified_by_show": "余丽娴",
  398. "device_code": "a6a672c3e458bed2",
  399. "material_code": "40010102000001",
  400. "last_modified_by": "553395510115962882",
  401. "unit_code_show": "张",
  402. "bus_type_dk": "SUPPLIER",
  403. "created_by": "553395510115962882",
  404. "unit_code": "ST",
  405. "dynamic_form_value_id": "586450574908723200",
  406. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  407. "device_code_show": "天凝工厂1号机",
  408. "belong_org": "0102",
  409. "bus_type_dk_show": "工厂",
  410. "created_by_show": "余丽娴",
  411. "id": "586450574980026368",
  412. "supplier_code": "0102",
  413. "main_table_id": null,
  414. "last_modified_date_lt": "2024-06-06T07:05:12.000Z",
  415. "material_code_show": "尊贵免漆背板E0小标",
  416. "qty": 5001,
  417. "specs": null,
  418. "box_code": "CK00011",
  419. "request_id": null,
  420. "detail_table_id": null,
  421. "last_modified_date": "2024-06-06T07:05:12.793Z",
  422. "box_code_show": "商标八号仓",
  423. "in_stock_qty": 5001,
  424. "use_qty": 5001,
  425. "product_list": [],
  426. "send_qty": 0
  427. },
  428. {
  429. "created_date_lt": "2024-06-06T07:37:23.000Z",
  430. "created_date": "2024-06-06T07:37:23.194Z",
  431. "last_modified_by_show": "余丽娴",
  432. "device_code": "a6a672c3e458bed2",
  433. "material_code": "40010134000001",
  434. "last_modified_by": "553395510115962882",
  435. "unit_code_show": "张",
  436. "bus_type_dk": "SUPPLIER",
  437. "created_by": "553395510115962882",
  438. "unit_code": "ST",
  439. "dynamic_form_value_id": "586458671639302144",
  440. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  441. "device_code_show": "天凝工厂1号机",
  442. "belong_org": "0102",
  443. "bus_type_dk_show": "工厂",
  444. "created_by_show": "余丽娴",
  445. "id": "586458671702216704",
  446. "supplier_code": "0102",
  447. "main_table_id": null,
  448. "last_modified_date_lt": "2024-06-06T07:37:23.000Z",
  449. "material_code_show": "优选免漆板ENF小标",
  450. "qty": 3345,
  451. "specs": null,
  452. "box_code": "CK00014",
  453. "request_id": null,
  454. "detail_table_id": null,
  455. "last_modified_date": "2024-06-06T07:37:23.203Z",
  456. "box_code_show": "商标十一号仓",
  457. "in_stock_qty": 3345,
  458. "use_qty": 3345,
  459. "safe_stock_qty": 400,
  460. "min_stock_qty": 300,
  461. "product_list": [],
  462. "send_qty": 0
  463. },
  464. {
  465. "created_date_lt": "2024-06-07T08:37:02.000Z",
  466. "created_date": "2024-06-07T08:37:02.353Z",
  467. "last_modified_by_show": "余丽娴",
  468. "device_code": "a6a672c3e458bed2",
  469. "material_code": "40010101000999",
  470. "last_modified_by": "553395510115962882",
  471. "unit_code_show": "张",
  472. "bus_type_dk": "SUPPLIER",
  473. "created_by": "553395510115962882",
  474. "unit_code": "ST",
  475. "dynamic_form_value_id": "586836071590006784",
  476. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  477. "device_code_show": "天凝工厂1号机",
  478. "belong_org": "0102",
  479. "bus_type_dk_show": "工厂",
  480. "created_by_show": "余丽娴",
  481. "id": "586836071657115648",
  482. "supplier_code": "0102",
  483. "main_table_id": null,
  484. "last_modified_date_lt": "2024-06-07T08:37:02.000Z",
  485. "material_code_show": "E0批零免漆(测试白标)",
  486. "qty": 1234,
  487. "specs": null,
  488. "box_code": "CK00015",
  489. "request_id": null,
  490. "detail_table_id": null,
  491. "last_modified_date": "2024-06-07T08:37:02.364Z",
  492. "box_code_show": "商标十二号仓",
  493. "in_stock_qty": 1518,
  494. "use_qty": 1234,
  495. "product_list": [],
  496. "send_qty": 0
  497. },
  498. {
  499. "created_date_lt": "2024-06-08T02:08:40.000Z",
  500. "created_date": "2024-06-08T02:08:40.233Z",
  501. "last_modified_by_show": "余丽娴",
  502. "device_code": "a6a672c3e458bed2",
  503. "material_code": "40010504000001",
  504. "last_modified_by": "553395510115962882",
  505. "unit_code_show": "张",
  506. "bus_type_dk": "SUPPLIER",
  507. "created_by": "553395510115962882",
  508. "unit_code": "ST",
  509. "dynamic_form_value_id": "587100723276288000",
  510. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  511. "device_code_show": "天凝工厂1号机",
  512. "belong_org": "0102",
  513. "bus_type_dk_show": "工厂",
  514. "created_by_show": "余丽娴",
  515. "id": "587100723347591168",
  516. "supplier_code": "0102",
  517. "main_table_id": null,
  518. "last_modified_date_lt": "2024-06-08T02:08:40.000Z",
  519. "material_code_show": "ENF圆标",
  520. "qty": 4467,
  521. "specs": null,
  522. "box_code": "CK00016",
  523. "request_id": null,
  524. "detail_table_id": null,
  525. "last_modified_date": "2024-06-08T02:08:40.243Z",
  526. "box_code_show": "商标十三号仓",
  527. "in_stock_qty": 5000,
  528. "use_qty": 4467,
  529. "safe_stock_qty": 400,
  530. "min_stock_qty": 100,
  531. "product_list": [],
  532. "send_qty": 0
  533. },
  534. {
  535. "created_date_lt": "2024-06-07T08:12:36.000Z",
  536. "created_date": "2024-06-07T08:12:36.275Z",
  537. "last_modified_by_show": "余丽娴",
  538. "device_code": "a6a672c3e458bed2",
  539. "material_code": "40010501000999",
  540. "last_modified_by": "553395510115962882",
  541. "unit_code_show": "张",
  542. "bus_type_dk": "SUPPLIER",
  543. "created_by": "553395510115962882",
  544. "unit_code": "ST",
  545. "dynamic_form_value_id": "586829922408992768",
  546. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  547. "device_code_show": "天凝工厂1号机",
  548. "belong_org": "0102",
  549. "bus_type_dk_show": "工厂",
  550. "created_by_show": "余丽娴",
  551. "id": "586829922471907328",
  552. "supplier_code": "0102",
  553. "main_table_id": null,
  554. "last_modified_date_lt": "2024-06-07T08:12:36.000Z",
  555. "material_code_show": "银盾抗菌圆标(测试白标)",
  556. "qty": 1236,
  557. "specs": null,
  558. "box_code": "CK00017",
  559. "request_id": null,
  560. "detail_table_id": null,
  561. "last_modified_date": "2024-06-07T08:12:36.284Z",
  562. "box_code_show": "商标十四号仓",
  563. "in_stock_qty": 1510,
  564. "use_qty": 1236,
  565. "product_list": [],
  566. "send_qty": 0
  567. },
  568. {
  569. "created_date_lt": "2024-06-06T07:35:54.000Z",
  570. "created_date": "2024-06-06T07:35:54.496Z",
  571. "last_modified_by_show": "余丽娴",
  572. "device_code": "a6a672c3e458bed2",
  573. "material_code": "40010504000001",
  574. "last_modified_by": "553395510115962882",
  575. "unit_code_show": "张",
  576. "bus_type_dk": "SUPPLIER",
  577. "created_by": "553395510115962882",
  578. "unit_code": "ST",
  579. "dynamic_form_value_id": "586458299612925952",
  580. "supplier_code_show": "嘉善大王椰整体橱柜有限公司",
  581. "device_code_show": "天凝工厂1号机",
  582. "belong_org": "0102",
  583. "bus_type_dk_show": "工厂",
  584. "created_by_show": "余丽娴",
  585. "id": "586458299675840512",
  586. "supplier_code": "0102",
  587. "main_table_id": null,
  588. "last_modified_date_lt": "2024-06-06T07:35:54.000Z",
  589. "material_code_show": "ENF圆标",
  590. "qty": 32,
  591. "specs": null,
  592. "box_code": "CK00018",
  593. "request_id": null,
  594. "detail_table_id": null,
  595. "last_modified_date": "2024-06-06T07:35:54.505Z",
  596. "box_code_show": "商标十五号仓",
  597. "in_stock_qty": 1540,
  598. "use_qty": 32,
  599. "safe_stock_qty": 400,
  600. "min_stock_qty": 100,
  601. "product_list": [],
  602. "send_qty": 0
  603. }
  604. ]
  605. }',true);
  606. foreach ($a['data'] as $k=>$v){
  607. if($v['box_code'] == 'CK00005') {
  608. foreach ($v['product_list'] as $kk=>$vv){
  609. if($kk > 0 ){
  610. unset($v['product_list'][$kk]);
  611. continue;
  612. }
  613. $v['product_list'][$kk]['send_qty'] = 200;
  614. $v['product_list'][$kk]['fake_qty'] = 200;
  615. }
  616. // $a['data'][$k]['box_code'] = 'CK00006';
  617. // $a['data'][$k]['box_code_show'] = '商标三号仓';
  618. $aa = $v;
  619. // $aa['box_code'] = 'CK00019';
  620. // $aa['box_code_show'] = '商标十六号';
  621. $aa['send_qty'] = 200;
  622. //
  623. // $bb = $v;
  624. // $bb['box_code'] = 'CK00013';
  625. // $bb['box_code_show'] = '商标十号';
  626. // $bb['send_qty'] = '15';
  627. //
  628. // $cc = $v;
  629. // $cc['box_code'] = 'CK00014';
  630. // $cc['box_code_show'] = '商标十一号';
  631. // $cc['send_qty'] = '15';
  632. //
  633. // $dd = $v;
  634. // $dd['box_code'] = 'CK00015';
  635. // $dd['box_code_show'] = '商标十二号';
  636. // $dd['send_qty'] = '15';
  637. //
  638. // $gg = $v;
  639. // $gg['box_code'] = 'CK00018';
  640. // $gg['box_code_show'] = '商标十五号';
  641. // $gg['send_qty'] = '15';
  642. }
  643. if($v['box_code'] == 'CK00004'||$v['box_code'] == 'CK00005'||$v['box_code'] == 'CK00006'||$v['box_code'] == 'CK00007'||$v['box_code'] == 'CK00008'||$v['box_code'] == 'CK00009'||$v['box_code'] == 'CK00010'||$v['box_code'] == 'CK00011'||$v['box_code'] == 'CK00012'||$v['box_code'] == 'CK00013'||$v['box_code'] == 'CK00014'||$v['box_code'] == 'CK00015'||$v['box_code'] == 'CK00016'||$v['box_code'] == 'CK00017'||$v['box_code'] == 'CK00018'||$v['box_code'] == 'CK00019') {
  644. unset($a['data'][$k]);
  645. continue;
  646. }
  647. }
  648. $box_list = [
  649. 6,7
  650. ];
  651. foreach ($box_list as $v){
  652. $v = $v+3;
  653. if($v<10) $n = '0'.$v;
  654. else $n = $v;
  655. $aa['box_code'] = 'CK000'.$n;
  656. $aa['box_code_show'] = '商标'.($n-3).'号';
  657. $a['data'][] = $aa;
  658. }
  659. // $a['data'][] = $bb;
  660. // $a['data'][] = $cc;
  661. // $a['data'][] = $dd;
  662. // $a['data'][] = $gg;
  663. usort( $a['data'], function ($jj,$kk){
  664. return str_replace('CK','',$jj['box_code']) - str_replace('CK','',$kk['box_code']);
  665. });
  666. return $a;
  667. }
  668. public function setLb(Request $request)
  669. {
  670. $param = $request->all();
  671. file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
  672. // $param = json_decode('{"token":"Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1OTAwNDY0ODg5NDAzODQyNTYiLCJhdXRoIjoiUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9PVVRFUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTk5FUl9VU0VSLFJPTEVfSU5URVJGQUNFLFJPTEVfU0VORF9CUkFORF9TVVBQTElFUiIsInRva2VuSWQiOiIzIiwiZXhwIjoxNzIxMzU1NDczfQ.BMRYPq_8TXaSE4isig-2hn3I6J25IeFe8_Z9_-LZZt41yGVRE0OQUlSO9zl93a1Lv7fW9D0BB8V9ZoHxvRfWhA","list":[{"title":"E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09","num":"6500","restock_qty":0,"product_code":"BC020202000999","product_code_show":"\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728","order_item_id":"590882008738308096","order_item_id_show":"SO202406180173","decor_code_show":"\u6d4b\u8bd5\u82b1\u827201","craft_type_code_show":"\u5178\u96c5\u6c99\u8d1d","specs":"\u5178\u96c5\u6c99\u8d1d \u6d4b\u8bd5\u82b1\u827201 11345","material_name":"\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728"},{"title":"\u94f6\u76fe\u6297\u83cc\u5706\u6807\uff08\u6d4b\u8bd5\u767d\u6807\uff09","num":"500","restock_qty":0,"product_code":"BC020202000999","product_code_show":"\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728","order_item_id":"590882008738308096","order_item_id_show":"SO202406180173","decor_code_show":"\u6d4b\u8bd5\u82b1\u827201","craft_type_code_show":"\u5178\u96c5\u6c99\u8d1d","specs":"\u5178\u96c5\u6c99\u8d1d \u6d4b\u8bd5\u82b1\u827201 11345","material_name":"\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728"}],"mac":"28f1e65c8cfd496f"}',true);
  673. $token = $param['token'];
  674. $list = $param['list'];
  675. $mac = $param['mac'];
  676. // if($mac === '28f1e65c8cfd496f'){
  677. //
  678. // return $this->test();
  679. // }
  680. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  681. $header = [
  682. 'Content-Type:application/json',
  683. 'Authorization: ' . $token,
  684. ];
  685. $data = $this->post_helper($url, '{"device_code":"'.$mac.'"}', $header);
  686. $data = json_decode($data, true);
  687. usort($data, function ($a,$b){
  688. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  689. });
  690. //做一个单独的校验,如果数量不够则返回失败
  691. $out_key_list = [];
  692. foreach ($list as $l){
  693. if(!isset($out_key_list[$l['title']])) $out_key_list[$l['title']] = 0;
  694. $out_key_list[$l['title']] += $l['num'];
  695. }
  696. $box_key_list = [];
  697. foreach ($data as $d){
  698. if (!isset($d['box_code_show']) || $d['box_code_show'] == '设备仓') {
  699. continue;
  700. }
  701. if(!isset($box_key_list[$d['material_code_show']])) $box_key_list[$d['material_code_show']] = 0;
  702. $box_key_list[$d['material_code_show']] += $d['qty'];
  703. }
  704. foreach ($out_key_list as $k=>$v){
  705. if(!isset($box_key_list[$k])){
  706. return ['status' => '201', 'data' => [],'msg'=>$k.'没有库存信息!'];
  707. }
  708. if($box_key_list[$k] < $v) {
  709. return ['status' => '201','data'=>[], 'msg' => $k.'库存数量不足信息!'];
  710. }
  711. }
  712. //end
  713. foreach ($data as $k => &$v) {
  714. if (!isset($v['product_list'])) $v['product_list'] = [];
  715. if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') {
  716. unset($data[$k]);
  717. continue;
  718. }
  719. if ($v['qty'] <= 0) {
  720. unset($data[$k]);
  721. continue;
  722. }
  723. $v['use_qty'] = $v['qty'];
  724. if (!isset($v['send_qty'])) $v['send_qty'] = 0;
  725. foreach ($list as $kk => $vv) {
  726. if ($vv['num'] == 0) continue;
  727. if ($v['material_code_show'] === $vv['title']) {
  728. $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0;
  729. if (($v['qty'] - $v['send_qty']) > $vv['num']) {
  730. $list[$kk]['num'] -= $vv['num'];
  731. $v['send_qty'] += $vv['num'];
  732. $p_total = $vv['num'];
  733. } else {
  734. $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']);
  735. $p_total = ($v['qty'] - $v['send_qty']);
  736. $v['send_qty'] += ($v['qty'] - $v['send_qty']);
  737. }
  738. //把产品相关参数进行封装
  739. ////产品编号
  740. //"product_code": "",
  741. ////产品名称
  742. //"product_code_show": "",
  743. ////工艺
  744. //"process_title": "",
  745. ////花色
  746. //"color": "",
  747. ////工艺2
  748. //"process_title_two": "",
  749. ////花色2
  750. //"color_two": "",
  751. if($p_total == 0) continue;
  752. $key_arr = [
  753. 'product_code' => $vv['product_code'] ?? '',
  754. 'product_code_show' => $vv['product_code_show'] ?? '',
  755. 'order_item_id' => $vv['order_item_id'] ?? '',
  756. 'order_item_id_show' => $vv['order_item_id_show'] ?? '',
  757. 'process_title' => $vv['craft_type_code_show'] ?? '',
  758. 'color' => $vv['decor_code_show'] ?? '',
  759. 'process_title_two' => $vv['craft_type_two_code_show'] ?? '',
  760. 'color_two' => $vv['decor_two_code_show'] ?? '',
  761. 'send_qty' => $p_total,
  762. 'fake_qty' => $p_total,
  763. // 'send_qty' => 0,
  764. 'restock_qty' => $vv['restock_qty'] ?? 0,
  765. ];
  766. if($vv['restock_qty'] > 0) $list[$kk]['restock_qty'] = 0;
  767. $v['product_list'][] = $key_arr;
  768. }
  769. // var_dump($key_arr);
  770. // var_dump($key_arr);
  771. }
  772. }
  773. usort($data, function ($a,$b){
  774. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  775. });
  776. // list($status,$msg) = DwyService::getInstance()->setLimitForBoxOut($param);
  777. // if(! $status) return ['status' => '201', 'data' => [],'msg'=> $msg];
  778. return ['status' => '200', 'data' => $data];
  779. }
  780. public function zjlb(Request $request)
  781. {
  782. $param = $request->all();
  783. file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8);
  784. // $param = [
  785. // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
  786. // 'list'=>[
  787. // [
  788. // 'title'=>'优选A7家具板ENF小标',
  789. // 'num'=>'20',
  790. // ],[
  791. // 'title'=>'植萃除醛圆标',
  792. // 'num'=>'10',
  793. // ],
  794. // ],
  795. // ];
  796. // dd(json_encode($param));
  797. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  798. $url = 'https://tm.dwycloud.com/jbl/api/module-data/box_inventory_dtl_qr/page';
  799. $header = [
  800. 'Content-Type:application/json',
  801. 'Authorization: ' . $request->header('Authorization'),
  802. ];
  803. $param = '{"direction":"DESC","property":"id","fromClientType":"pc","number":0,"sorts":[],"rules":[{"field":"box_inventory.device_code","option":"LIKE_ANYWHERE","values":["'.$param['device_code'].'"]}],"size":15,"specialConditions":[],"workflowSearchBean":{},"dynamicFormCode":"box_inventory","developmentSystemId":null,"debugFlag":true}';
  804. $data = $this->post_helper($url, $param, $header);
  805. // $data = $this->post_helper($url, json_encode($param), $header);
  806. $data = json_decode($data, true);
  807. $data = $data['content'] ?? [];
  808. foreach ($data as $k => &$v) {
  809. $v['material_code_show'] = $v['box_inventory']['material_code_show'];
  810. $v['qty'] = $v['roll_qty'];
  811. $v['use_qty'] = 0;
  812. }
  813. sort($data);
  814. return json_encode($data);
  815. }
  816. public function boxOut(Request $request)
  817. {
  818. $param = $request->all();
  819. file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
  820. //商标绑定
  821. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  822. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  823. $header = [
  824. 'Content-Type:application/json',
  825. 'Authorization: ' . $request->header('Authorization'),
  826. ];
  827. $lead_bind = $param['lead_bind'];
  828. $this->post_helper($url, json_encode($lead_bind), $header);
  829. //商标出库
  830. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  831. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  832. $lead_bind = $param['lead_out'];
  833. $this->post_helper($url, json_encode($lead_bind), $header);
  834. return ['status'=>200,'msg'=>'success'];
  835. }
  836. public function post_helper($url, $data, $header)
  837. {
  838. $ch = curl_init();
  839. curl_setopt($ch, CURLOPT_POST, 1);
  840. curl_setopt($ch, CURLOPT_URL, $url);
  841. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  842. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  843. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  844. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  845. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  846. $r = curl_exec($ch);
  847. curl_close($ch);
  848. file_put_contents('33.txt',$r.PHP_EOL,8);
  849. return $r;
  850. }
  851. public function setTbData(Request $request){
  852. $data = $request->all();
  853. if(empty($data['id']) && empty($data['data'])) return [201, ''];
  854. BigKingTbj::updateOrCreate(
  855. ['id' => $data['id']], //查询条件
  856. [
  857. "id" => $data['id'],
  858. "data" => json_encode($data['data'])
  859. ] //添加或者修改的数据
  860. );
  861. return [200, ''];
  862. }
  863. public function getTbData(Request $request){
  864. $data = $request->all();
  865. if(empty($data['id'])) return [201, ''];
  866. $result = BigKingTbj::where('id',$data['id'])->first();
  867. if(empty($result)) return [200,'data' => []];
  868. $result = $result->toArray();
  869. return [200, 'data' => json_decode($result['data'],true)];
  870. }
  871. public function setBoxTrademark(Request $request){
  872. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list';
  873. $header = [
  874. 'Content-Type:application/json',
  875. 'Authorization: ' .'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2MzM1NTJ9.CC69s4dpUdd9UqQlpeK5UF3DwY5Zenn-YHv8Iy1ai0cCXgere7r7jskWU9ARmKotys2tCGYRlO-Idtxdwdsefg',
  876. ];
  877. $data = [
  878. 'roll_qr_code_list' => [
  879. '171368443563212'
  880. ]
  881. ];
  882. $a = $this->post_helper($url, json_encode($data), $header);
  883. var_dump($a);die;
  884. $a = json_decode($a,true);
  885. $detail = [];
  886. foreach ($a['data'] as $v){
  887. $code = $v['brand_qr_code'];
  888. $detail[] = $code;
  889. }
  890. file_put_contents('1.txt',json_encode($detail));
  891. var_dump($a);die;
  892. }
  893. public function getBoxTrademark(Request $request){
  894. $data = $request->all();
  895. if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []];
  896. $box_nos = $data['box_nos'];
  897. $dv = $data['mac'];
  898. $detail = [];
  899. //测试写入文件
  900. // foreach ($box_nos as $v) {
  901. // $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt");
  902. // if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade');
  903. // file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2']));
  904. // }
  905. //读取文件
  906. foreach ($box_nos as $v) {
  907. // $filePath = public_path($file_path . "{$dv}_{$v}.txt");
  908. $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt");
  909. if(file_exists($filePath)){
  910. if (($content = file_get_contents($filePath)) === false) continue;
  911. $decodedContent = json_decode($content, true);
  912. if (json_last_error() !== JSON_ERROR_NONE) continue;
  913. $detail[] = [
  914. 'detail'=>$decodedContent,
  915. 'code'=>$v,
  916. ];
  917. }
  918. }
  919. return ['status' => 200, 'data' => $detail];
  920. }
  921. }