DwyController.php 49 KB

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