DwyController.php 37 KB

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