DwyController.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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'] = 300;
  614. $v['product_list'][$kk]['fake_qty'] = 300;
  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'] = 300;
  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. 14,15,2,3,9,12
  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 = [
  673. // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
  674. // 'list'=>[
  675. // [
  676. // 'title'=>'优选A7家具板ENF小标',
  677. // 'num'=>'20',
  678. // ],[
  679. // 'title'=>'植萃除醛圆标',
  680. // 'num'=>'10',
  681. // ],
  682. // ],
  683. // ];
  684. $token = $param['token'];
  685. $list = $param['list'];
  686. $mac = $param['mac'];
  687. // if($mac === 'cff4dc68c73115b'){
  688. //
  689. // return $this->test();
  690. // }
  691. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  692. $header = [
  693. 'Content-Type:application/json',
  694. 'Authorization: ' . $token,
  695. ];
  696. $data = $this->post_helper($url, '{"device_code":"'.$mac.'"}', $header);
  697. $data = json_decode($data, true);
  698. usort($data, function ($a,$b){
  699. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  700. });
  701. //做一个单独的校验,如果数量不够则返回失败
  702. $out_key_list = [];
  703. foreach ($list as $l){
  704. if(!isset($out_key_list[$l['title']])) $out_key_list[$l['title']] = 0;
  705. $out_key_list[$l['title']] += $l['num'];
  706. }
  707. $box_key_list = [];
  708. foreach ($data as $d){
  709. if (!isset($d['box_code_show']) || $d['box_code_show'] == '设备仓') {
  710. continue;
  711. }
  712. if(!isset($box_key_list[$d['material_code_show']])) $box_key_list[$d['material_code_show']] = 0;
  713. $box_key_list[$d['material_code_show']] += $d['qty'];
  714. }
  715. foreach ($out_key_list as $k=>$v){
  716. if(!isset($box_key_list[$k])){
  717. return ['status' => '201', 'data' => [],'msg'=>$k.'没有库存信息!'];
  718. }
  719. if($box_key_list[$k] < $v) {
  720. return ['status' => '201','data'=>[], 'msg' => $k.'库存数量不足信息!'];
  721. }
  722. }
  723. //end
  724. foreach ($data as $k => &$v) {
  725. if (!isset($v['product_list'])) $v['product_list'] = [];
  726. if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') {
  727. unset($data[$k]);
  728. continue;
  729. }
  730. if ($v['qty'] <= 0) {
  731. unset($data[$k]);
  732. continue;
  733. }
  734. $v['use_qty'] = $v['qty'];
  735. if (!isset($v['send_qty'])) $v['send_qty'] = 0;
  736. foreach ($list as $kk => $vv) {
  737. if ($vv['num'] == 0) continue;
  738. if ($v['material_code_show'] === $vv['title']) {
  739. $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0;
  740. if (($v['qty'] - $v['send_qty']) > $vv['num']) {
  741. $list[$kk]['num'] -= $vv['num'];
  742. $v['send_qty'] += $vv['num'];
  743. $p_total = $vv['num'];
  744. } else {
  745. $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']);
  746. $p_total = ($v['qty'] - $v['send_qty']);
  747. $v['send_qty'] += ($v['qty'] - $v['send_qty']);
  748. }
  749. //把产品相关参数进行封装
  750. ////产品编号
  751. //"product_code": "",
  752. ////产品名称
  753. //"product_code_show": "",
  754. ////工艺
  755. //"process_title": "",
  756. ////花色
  757. //"color": "",
  758. ////工艺2
  759. //"process_title_two": "",
  760. ////花色2
  761. //"color_two": "",
  762. if($p_total == 0) continue;
  763. $key_arr = [
  764. 'product_code' => $vv['product_code'] ?? '',
  765. 'product_code_show' => $vv['product_code_show'] ?? '',
  766. 'order_item_id' => $vv['order_item_id'] ?? '',
  767. 'order_item_id_show' => $vv['order_item_id_show'] ?? '',
  768. 'process_title' => $vv['craft_type_code_show'] ?? '',
  769. 'color' => $vv['decor_code_show'] ?? '',
  770. 'process_title_two' => $vv['craft_type_two_code_show'] ?? '',
  771. 'color_two' => $vv['decor_two_code_show'] ?? '',
  772. 'send_qty' => $p_total,
  773. 'fake_qty' => $p_total,
  774. // 'send_qty' => 0,
  775. 'restock_qty' => $vv['restock_qty'] ?? 0,
  776. ];
  777. if($vv['restock_qty'] > 0) $list[$kk]['restock_qty'] = 0;
  778. $v['product_list'][] = $key_arr;
  779. }
  780. // var_dump($key_arr);
  781. // var_dump($key_arr);
  782. }
  783. }
  784. usort($data, function ($a,$b){
  785. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  786. });
  787. // list($status,$msg) = DwyService::getInstance()->setLimitForBoxOut($param);
  788. // if(! $status) return ['status' => '201', 'data' => [],'msg'=> $msg];
  789. return ['status' => '200', 'data' => $data];
  790. }
  791. public function zjlb(Request $request)
  792. {
  793. $param = $request->all();
  794. file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8);
  795. // $param = [
  796. // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
  797. // 'list'=>[
  798. // [
  799. // 'title'=>'优选A7家具板ENF小标',
  800. // 'num'=>'20',
  801. // ],[
  802. // 'title'=>'植萃除醛圆标',
  803. // 'num'=>'10',
  804. // ],
  805. // ],
  806. // ];
  807. // dd(json_encode($param));
  808. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  809. $url = 'https://tm.dwycloud.com/jbl/api/module-data/box_inventory_dtl_qr/page';
  810. $header = [
  811. 'Content-Type:application/json',
  812. 'Authorization: ' . $request->header('Authorization'),
  813. ];
  814. $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}';
  815. $data = $this->post_helper($url, $param, $header);
  816. // $data = $this->post_helper($url, json_encode($param), $header);
  817. $data = json_decode($data, true);
  818. $data = $data['content'] ?? [];
  819. foreach ($data as $k => &$v) {
  820. $v['material_code_show'] = $v['box_inventory']['material_code_show'];
  821. $v['qty'] = $v['roll_qty'];
  822. $v['use_qty'] = 0;
  823. }
  824. sort($data);
  825. return json_encode($data);
  826. }
  827. public function boxOut(Request $request)
  828. {
  829. $param = $request->all();
  830. file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
  831. //商标绑定
  832. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  833. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  834. $header = [
  835. 'Content-Type:application/json',
  836. 'Authorization: ' . $request->header('Authorization'),
  837. ];
  838. $lead_bind = $param['lead_bind'];
  839. $this->post_helper($url, json_encode($lead_bind), $header);
  840. //商标出库
  841. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  842. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  843. $lead_bind = $param['lead_out'];
  844. $this->post_helper($url, json_encode($lead_bind), $header);
  845. return ['status'=>200,'msg'=>'success'];
  846. }
  847. public function post_helper($url, $data, $header)
  848. {
  849. $ch = curl_init();
  850. curl_setopt($ch, CURLOPT_POST, 1);
  851. curl_setopt($ch, CURLOPT_URL, $url);
  852. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  853. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  854. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  855. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  856. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  857. $r = curl_exec($ch);
  858. curl_close($ch);
  859. file_put_contents('33.txt',$r.PHP_EOL,8);
  860. return $r;
  861. }
  862. public function setTbData(Request $request){
  863. $data = $request->all();
  864. if(empty($data['id']) && empty($data['data'])) return [201, ''];
  865. BigKingTbj::updateOrCreate(
  866. ['id' => $data['id']], //查询条件
  867. [
  868. "id" => $data['id'],
  869. "data" => json_encode($data['data'])
  870. ] //添加或者修改的数据
  871. );
  872. return [200, ''];
  873. }
  874. public function getTbData(Request $request){
  875. $data = $request->all();
  876. if(empty($data['id'])) return [201, ''];
  877. $result = BigKingTbj::where('id',$data['id'])->first();
  878. if(empty($result)) return [200,'data' => []];
  879. $result = $result->toArray();
  880. return [200, 'data' => json_decode($result['data'],true)];
  881. }
  882. public function setBoxTrademark(Request $request){
  883. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list';
  884. $header = [
  885. 'Content-Type:application/json',
  886. 'Authorization: ' .'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2MzM1NTJ9.CC69s4dpUdd9UqQlpeK5UF3DwY5Zenn-YHv8Iy1ai0cCXgere7r7jskWU9ARmKotys2tCGYRlO-Idtxdwdsefg',
  887. ];
  888. $data = [
  889. 'roll_qr_code_list' => [
  890. '171368443563212'
  891. ]
  892. ];
  893. $a = $this->post_helper($url, json_encode($data), $header);
  894. var_dump($a);die;
  895. $a = json_decode($a,true);
  896. $detail = [];
  897. foreach ($a['data'] as $v){
  898. $code = $v['brand_qr_code'];
  899. $detail[] = $code;
  900. }
  901. file_put_contents('1.txt',json_encode($detail));
  902. var_dump($a);die;
  903. }
  904. public function getBoxTrademark(Request $request){
  905. $data = $request->all();
  906. if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []];
  907. $box_nos = $data['box_nos'];
  908. $dv = $data['mac'];
  909. $detail = [];
  910. //测试写入文件
  911. // foreach ($box_nos as $v) {
  912. // $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt");
  913. // if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade');
  914. // file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2']));
  915. // }
  916. //读取文件
  917. foreach ($box_nos as $v) {
  918. // $filePath = public_path($file_path . "{$dv}_{$v}.txt");
  919. $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt");
  920. if(file_exists($filePath)){
  921. if (($content = file_get_contents($filePath)) === false) continue;
  922. $decodedContent = json_decode($content, true);
  923. if (json_last_error() !== JSON_ERROR_NONE) continue;
  924. $detail[] = [
  925. 'detail'=>$decodedContent,
  926. 'code'=>$v,
  927. ];
  928. }
  929. }
  930. return ['status' => 200, 'data' => $detail];
  931. }
  932. }