DwyController.php 43 KB

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