DwyController.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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'])||$data['mac'] == 'a6a672c3e458bed2'){
  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. // $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);
  747. $token = $param['token'];
  748. $list = $param['list'];
  749. $mac = $param['mac'];
  750. // if($mac === '28f1e65c8cfd496f'){
  751. ////
  752. // return $this->test();
  753. // }
  754. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  755. $header = [
  756. 'Content-Type:application/json',
  757. 'Authorization: ' . $token,
  758. ];
  759. $data = $this->post_helper($url, '{"device_code":"'.$mac.'"}', $header);
  760. $data = json_decode($data, true);
  761. if($mac == 'a6a672c3e458bed2'||$mac == 'DV00001'){
  762. usort($data, function ($a,$b){
  763. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  764. });
  765. }else{
  766. usort($data, function($a, $b) {
  767. return $b['qty'] < $a['qty'];
  768. });
  769. }
  770. //做一个单独的校验,如果数量不够则返回失败
  771. $out_key_list = [];
  772. foreach ($list as $l){
  773. if(!isset($out_key_list[$l['title']])) $out_key_list[$l['title']] = 0;
  774. $out_key_list[$l['title']] += $l['num'];
  775. }
  776. $box_key_list = [];
  777. foreach ($data as $d){
  778. if (!isset($d['box_code_show']) || $d['box_code_show'] == '设备仓') {
  779. continue;
  780. }
  781. if(!isset($box_key_list[$d['material_code_show']])) $box_key_list[$d['material_code_show']] = 0;
  782. $box_key_list[$d['material_code_show']] += $d['qty'];
  783. }
  784. foreach ($out_key_list as $k=>$v){
  785. if(!isset($box_key_list[$k])){
  786. return ['status' => '201', 'data' => [],'msg'=>$k.'没有库存信息!'];
  787. }
  788. if($box_key_list[$k] < $v) {
  789. return ['status' => '201','data'=>[], 'msg' => $k.'库存数量不足信息!'];
  790. }
  791. }
  792. //end
  793. foreach ($data as $k => &$v) {
  794. if (!isset($v['product_list'])) $v['product_list'] = [];
  795. if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') {
  796. unset($data[$k]);
  797. continue;
  798. }
  799. if ($v['qty'] <= 0) {
  800. unset($data[$k]);
  801. continue;
  802. }
  803. $v['use_qty'] = $v['qty'];
  804. if (!isset($v['send_qty'])) $v['send_qty'] = 0;
  805. foreach ($list as $kk => $vv) {
  806. if(!isset($vv['restock_qty'])) $vv['restock_qty'] = 0;
  807. if ($vv['num'] == 0 && $vv['restock_qty'] == 0) continue;
  808. if ($v['material_code_show'] === $vv['title']) {
  809. $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0;
  810. if (($v['qty'] - $v['send_qty']) > $vv['num']) {
  811. $list[$kk]['num'] -= $vv['num'];
  812. $v['send_qty'] += $vv['num'];
  813. $p_total = $vv['num'];
  814. } else {
  815. $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']);
  816. $p_total = ($v['qty'] - $v['send_qty']);
  817. $v['send_qty'] += ($v['qty'] - $v['send_qty']);
  818. }
  819. //把产品相关参数进行封装
  820. ////产品编号
  821. //"product_code": "",
  822. ////产品名称
  823. //"product_code_show": "",
  824. ////工艺
  825. //"process_title": "",
  826. ////花色
  827. //"color": "",
  828. ////工艺2
  829. //"process_title_two": "",
  830. ////花色2
  831. //"color_two": "",
  832. if($p_total == 0 && $vv['restock_qty'] <= 0) continue;
  833. $key_arr = [
  834. 'product_code' => $vv['product_code'] ?? '',
  835. 'product_code_show' => $vv['product_code_show'] ?? '',
  836. 'order_item_id' => $vv['order_item_id'] ?? '',
  837. 'order_item_id_show' => $vv['order_item_id_show'] ?? '',
  838. 'process_title' => $vv['craft_type_code_show'] ?? '',
  839. 'color' => $vv['decor_code_show'] ?? '',
  840. 'process_title_two' => $vv['craft_type_two_code_show'] ?? '',
  841. 'color_two' => $vv['decor_two_code_show'] ?? '',
  842. 'send_qty' => $p_total,
  843. 'fake_qty' => $p_total,
  844. // 'send_qty' => 0,
  845. 'restock_qty' => $vv['restock_qty'] ?? 0,
  846. ];
  847. if($vv['restock_qty'] > 0) $list[$kk]['restock_qty'] = 0;
  848. $v['product_list'][] = $key_arr;
  849. }
  850. // var_dump($key_arr);
  851. // var_dump($key_arr);
  852. }
  853. }
  854. // dd($data);die;
  855. foreach ($data as $k=>$d){
  856. if(empty($d['product_list'])) unset($data[$k]);
  857. }
  858. usort($data, function ($a,$b){
  859. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  860. });
  861. // list($status,$msg) = DwyService::getInstance()->setLimitForBoxOut($param);
  862. // if(! $status) return ['status' => '201', 'data' => [],'msg'=> $msg];
  863. $this->unusualRestock($data,$mac,$token);
  864. if(empty($data)) return ['status' => '201', 'data' => $data,'msg'=>'无商标需要申领'];
  865. return ['status' => '200', 'data' => $data];
  866. }
  867. //单独的没有出标数据但是需要保存补领
  868. public function unusualRestock($data,$mac,$token){
  869. $send_status = true;
  870. $send_data = [];
  871. //2024-06-19T21:01:51.948Z,赖的写,直接拼
  872. $iso8601Time = date('Y-m-d').'T'.date('H:i:s').'.'.rand(100,999).'Z';
  873. foreach ($data as $v){
  874. if($v['send_qty'] > 0) $send_status = false;
  875. $send_product = [];
  876. //创建异常数据
  877. $box_data = [
  878. 'in_out_type_code' => 'CK00004',
  879. 'in_out_type_code_show' => '商标仓正常领标出库',
  880. 'send_box_code' => $v['box_code'],
  881. 'send_box_code_show' => $v['box_code_show'],
  882. 'device_code' => $mac,
  883. 'get_brand_source_dk' => 'SALE_ORDER',
  884. 'abnormal_flag' => false,
  885. 'abnormal_date' => $iso8601Time,
  886. ];
  887. foreach ($v['product_list'] as $kk=>$vv){
  888. $send_product[] = [
  889. 'item_no' => 10+$kk*10,
  890. 'brand_qr_code_list' => '',
  891. 'material_code' => $v['material_code'],
  892. 'material_code_show' => $v['material_code_show'],
  893. 'unit_code' => $v['unit_code'],
  894. 'unit_code_show' => $v['unit_code_show'],
  895. 'restock_qty' => $vv['restock_qty'],
  896. 'qty' => 0,
  897. 'fake_qty' => 0,
  898. 'bus_type_dk' => 'SALE_ORDER',
  899. 'bus_type_dk_show' => '销售订单',
  900. 'bus_no' => $vv['order_item_id'],
  901. 'bus_no_show' => $vv['order_item_id_show'],
  902. 'product_code' => $vv['product_code'],
  903. 'product_code_show' => $vv['product_code_show'],
  904. 'process_title' => $vv['process_title'],
  905. 'color' => $vv['color'],
  906. 'process_title_two' => $vv['process_title_two'],
  907. 'color_two' => $vv['color_two'],
  908. ];
  909. }
  910. $box_data['brand_out_stock_dtl'] =$send_product;
  911. $send_data[] = $box_data;
  912. }
  913. $param = [
  914. 'brand_out_stock_list' => $send_data
  915. ];
  916. if($send_status){
  917. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  918. $header = [
  919. 'Content-Type:application/json',
  920. 'Authorization: ' . $token,
  921. ];
  922. $res = $this->post_helper($url, json_encode($param), $header);
  923. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($header) . PHP_EOL, 8);
  924. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($param) . PHP_EOL, 8);
  925. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').$res . PHP_EOL, 8);
  926. }
  927. }
  928. public function zjlb(Request $request)
  929. {
  930. $param = $request->all();
  931. file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8);
  932. // $param = [
  933. // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
  934. // 'list'=>[
  935. // [
  936. // 'title'=>'优选A7家具板ENF小标',
  937. // 'num'=>'20',
  938. // ],[
  939. // 'title'=>'植萃除醛圆标',
  940. // 'num'=>'10',
  941. // ],
  942. // ],
  943. // ];
  944. // dd(json_encode($param));
  945. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  946. $url = 'https://tm.dwycloud.com/jbl/api/module-data/box_inventory_dtl_qr/page';
  947. $header = [
  948. 'Content-Type:application/json',
  949. 'Authorization: ' . $request->header('Authorization'),
  950. ];
  951. $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}';
  952. $data = $this->post_helper($url, $param, $header);
  953. // $data = $this->post_helper($url, json_encode($param), $header);
  954. $data = json_decode($data, true);
  955. $data = $data['content'] ?? [];
  956. foreach ($data as $k => &$v) {
  957. $v['material_code_show'] = $v['box_inventory']['material_code_show'];
  958. $v['qty'] = $v['roll_qty'];
  959. $v['use_qty'] = 0;
  960. }
  961. sort($data);
  962. return json_encode($data);
  963. }
  964. public function boxOut(Request $request)
  965. {
  966. $param = $request->all();
  967. file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
  968. //商标绑定
  969. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  970. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  971. $header = [
  972. 'Content-Type:application/json',
  973. 'Authorization: ' . $request->header('Authorization'),
  974. ];
  975. $lead_bind = $param['lead_bind'];
  976. $this->post_helper($url, json_encode($lead_bind), $header);
  977. //商标出库
  978. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  979. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  980. $lead_bind = $param['lead_out'];
  981. $this->post_helper($url, json_encode($lead_bind), $header);
  982. return ['status'=>200,'msg'=>'success'];
  983. }
  984. public function post_helper($url, $data, $header)
  985. {
  986. $ch = curl_init();
  987. curl_setopt($ch, CURLOPT_POST, 1);
  988. curl_setopt($ch, CURLOPT_URL, $url);
  989. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  990. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  991. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  992. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  993. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  994. $r = curl_exec($ch);
  995. curl_close($ch);
  996. file_put_contents('33.txt',$r.PHP_EOL,8);
  997. return $r;
  998. }
  999. public function setTbData(Request $request){
  1000. $data = $request->all();
  1001. if(empty($data['id']) && empty($data['data'])) return [201, ''];
  1002. BigKingTbj::updateOrCreate(
  1003. ['id' => $data['id']], //查询条件
  1004. [
  1005. "id" => $data['id'],
  1006. "data" => json_encode($data['data'])
  1007. ] //添加或者修改的数据
  1008. );
  1009. return [200, ''];
  1010. }
  1011. public function getTbData(Request $request){
  1012. $data = $request->all();
  1013. if(empty($data['id'])) return [201, ''];
  1014. $result = BigKingTbj::where('id',$data['id'])->first();
  1015. if(empty($result)) return [200,'data' => []];
  1016. return [200, 'data' => json_decode($result['data'],true)];
  1017. }
  1018. public function setBoxTrademark(Request $request){
  1019. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list';
  1020. $header = [
  1021. 'Content-Type:application/json',
  1022. 'Authorization: ' .'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2MzM1NTJ9.CC69s4dpUdd9UqQlpeK5UF3DwY5Zenn-YHv8Iy1ai0cCXgere7r7jskWU9ARmKotys2tCGYRlO-Idtxdwdsefg',
  1023. ];
  1024. $data = [
  1025. 'roll_qr_code_list' => [
  1026. '171368443563212'
  1027. ]
  1028. ];
  1029. $a = $this->post_helper($url, json_encode($data), $header);
  1030. var_dump($a);die;
  1031. $a = json_decode($a,true);
  1032. $detail = [];
  1033. foreach ($a['data'] as $v){
  1034. $code = $v['brand_qr_code'];
  1035. $detail[] = $code;
  1036. }
  1037. file_put_contents('1.txt',json_encode($detail));
  1038. var_dump($a);die;
  1039. }
  1040. public function getBoxTrademark(Request $request){
  1041. $data = $request->all();
  1042. if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []];
  1043. $box_nos = $data['box_nos'];
  1044. $dv = $data['mac'];
  1045. $detail = [];
  1046. //测试写入文件
  1047. // foreach ($box_nos as $v) {
  1048. // $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt");
  1049. // if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade');
  1050. // file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2']));
  1051. // }
  1052. //读取文件
  1053. foreach ($box_nos as $v) {
  1054. // $filePath = public_path($file_path . "{$dv}_{$v}.txt");
  1055. $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt");
  1056. if(file_exists($filePath)){
  1057. if (($content = file_get_contents($filePath)) === false) continue;
  1058. $decodedContent = json_decode($content, true);
  1059. if (json_last_error() !== JSON_ERROR_NONE) continue;
  1060. $detail[] = [
  1061. 'detail'=>$decodedContent,
  1062. 'code'=>$v,
  1063. ];
  1064. }
  1065. }
  1066. return ['status' => 200, 'data' => $detail];
  1067. }
  1068. }