DwyController.php 65 KB

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