DwyController.php 60 KB

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