DwyController.php 37 KB

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