DwyController.php 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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. $data = json_decode($data, true);
  925. // if($mac == 'a6a672c3e458bed2'||$mac == 'DV00001'){
  926. // usort($data, function ($a,$b){
  927. // return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  928. // });
  929. // }else{
  930. //
  931. // }
  932. usort($data, function($a, $b) {
  933. return $b['qty'] < $a['qty'];
  934. });
  935. //做一个单独的校验,如果数量不够则返回失败
  936. $out_key_list = [];
  937. foreach ($list as $l){
  938. if(!isset($out_key_list[$l['title']])) $out_key_list[$l['title']] = 0;
  939. $out_key_list[$l['title']] += $l['num'];
  940. }
  941. $box_key_list = [];
  942. foreach ($data as $d){
  943. if (!isset($d['box_code_show']) || $d['box_code_show'] == '设备仓') {
  944. continue;
  945. }
  946. if(!isset($box_key_list[$d['material_code_show']])) $box_key_list[$d['material_code_show']] = 0;
  947. $box_key_list[$d['material_code_show']] += $d['qty'];
  948. }
  949. foreach ($out_key_list as $k=>$v){
  950. if(!isset($box_key_list[$k])){
  951. return ['status' => '201', 'data' => [],'msg'=>$k.'没有库存信息!'];
  952. }
  953. if($box_key_list[$k] < $v) {
  954. return ['status' => '201','data'=>[], 'msg' => $k.'库存数量不足信息!'];
  955. }
  956. }
  957. //end
  958. foreach ($data as $k => &$v) {
  959. if (!isset($v['product_list'])) $v['product_list'] = [];
  960. if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') {
  961. unset($data[$k]);
  962. continue;
  963. }
  964. if(isset($v['box_code'])&&in_array($v['box_code'],$un_box)) continue;
  965. if ($v['qty'] <= 0) {
  966. unset($data[$k]);
  967. continue;
  968. }
  969. $v['use_qty'] = $v['qty'];
  970. if (!isset($v['send_qty'])) $v['send_qty'] = 0;
  971. foreach ($list as $kk => $vv) {
  972. if(!isset($vv['restock_qty'])) $vv['restock_qty'] = 0;
  973. if($vv['restock_qty'] > 0) return ['status' => '201','data'=>[], 'msg' => '不允许超出可领数量'];
  974. if ($vv['num'] == 0 && $vv['restock_qty'] == 0) continue;
  975. if ($v['material_code_show'] === $vv['title']) {
  976. $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0;
  977. if (($v['qty'] - $v['send_qty']) > $vv['num']) {
  978. $list[$kk]['num'] -= $vv['num'];
  979. $v['send_qty'] += $vv['num'];
  980. $p_total = $vv['num'];
  981. } else {
  982. $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']);
  983. $p_total = ($v['qty'] - $v['send_qty']);
  984. $v['send_qty'] += ($v['qty'] - $v['send_qty']);
  985. }
  986. //把产品相关参数进行封装
  987. ////产品编号
  988. //"product_code": "",
  989. ////产品名称
  990. //"product_code_show": "",
  991. ////工艺
  992. //"process_title": "",
  993. ////花色
  994. //"color": "",
  995. ////工艺2
  996. //"process_title_two": "",
  997. ////花色2
  998. //"color_two": "",
  999. if($p_total == 0 && $vv['restock_qty'] <= 0) continue;
  1000. $key_arr = [
  1001. 'product_code' => $vv['product_code'] ?? '',
  1002. 'product_code_show' => $vv['product_code_show'] ?? '',
  1003. 'order_item_id' => $vv['order_item_id'] ?? '',
  1004. 'order_item_id_show' => $vv['order_item_id_show'] ?? '',
  1005. 'process_title' => $vv['craft_type_code_show'] ?? '',
  1006. 'color' => $vv['decor_code_show'] ?? '',
  1007. 'process_title_two' => $vv['craft_type_two_code_show'] ?? '',
  1008. 'color_two' => $vv['decor_two_code_show'] ?? '',
  1009. 'send_qty' => $p_total,
  1010. 'fake_qty' => $p_total,
  1011. // 'send_qty' => 0,
  1012. 'restock_qty' => $vv['restock_qty'] ?? 0,
  1013. 'mat_material_a' => $vv['mat_material_a'] ?? []
  1014. ];
  1015. if($vv['restock_qty'] > 0) $list[$kk]['restock_qty'] = 0;
  1016. $v['product_list'][] = $key_arr;
  1017. }
  1018. // var_dump($key_arr);
  1019. // var_dump($key_arr);
  1020. }
  1021. }
  1022. // dd($data);die;
  1023. foreach ($data as $k=>$d){
  1024. if(empty($d['product_list'])) unset($data[$k]);
  1025. }
  1026. usort($data, function ($a,$b){
  1027. return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']);
  1028. });
  1029. // list($status,$msg) = DwyService::getInstance()->setLimitForBoxOut($param);
  1030. // if(! $status) return ['status' => '201', 'data' => [],'msg'=> $msg];
  1031. $this->unusualRestock1($data,$mac,$token);
  1032. if(empty($data)) return ['status' => '201', 'data' => $data,'msg'=>'无商标需要申领'];
  1033. return ['status' => '200', 'data' => $data];
  1034. }
  1035. //单独的没有出标数据但是需要保存补领
  1036. public function unusualRestock($data,$mac,$token){
  1037. $send_status = true;
  1038. $send_data = [];
  1039. //2024-06-19T21:01:51.948Z,赖的写,直接拼
  1040. $iso8601Time = date('Y-m-d').'T'.date('H:i:s').'.'.rand(100,999).'Z';
  1041. foreach ($data as $v){
  1042. if($v['send_qty'] > 0) $send_status = false;
  1043. $send_product = [];
  1044. //创建异常数据
  1045. $box_data = [
  1046. 'in_out_type_code' => 'CK00004',
  1047. 'in_out_type_code_show' => '商标仓正常领标出库',
  1048. 'send_box_code' => $v['box_code'],
  1049. 'send_box_code_show' => $v['box_code_show'],
  1050. 'device_code' => $mac,
  1051. 'get_brand_source_dk' => 'SALE_ORDER',
  1052. 'abnormal_flag' => false,
  1053. 'abnormal_date' => $iso8601Time,
  1054. ];
  1055. foreach ($v['product_list'] as $kk=>$vv){
  1056. $send_product[] = [
  1057. 'item_no' => 10+$kk*10,
  1058. 'brand_qr_code_list' => '',
  1059. 'material_code' => $v['material_code'],
  1060. 'material_code_show' => $v['material_code_show'],
  1061. 'unit_code' => $v['unit_code'],
  1062. 'unit_code_show' => $v['unit_code_show'],
  1063. 'restock_qty' => $vv['restock_qty'],
  1064. 'qty' => 0,
  1065. 'fake_qty' => 0,
  1066. 'bus_type_dk' => 'SALE_ORDER',
  1067. 'bus_type_dk_show' => '销售订单',
  1068. 'bus_no' => $vv['order_item_id'],
  1069. 'bus_no_show' => $vv['order_item_id_show'],
  1070. 'product_code' => $vv['product_code'],
  1071. 'product_code_show' => $vv['product_code_show'],
  1072. 'process_title' => $vv['process_title'],
  1073. 'color' => $vv['color'],
  1074. 'process_title_two' => $vv['process_title_two'],
  1075. 'color_two' => $vv['color_two'],
  1076. ];
  1077. }
  1078. $box_data['brand_out_stock_dtl'] =$send_product;
  1079. $send_data[] = $box_data;
  1080. }
  1081. $param = [
  1082. 'brand_out_stock_list' => $send_data
  1083. ];
  1084. if($send_status){
  1085. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  1086. $header = [
  1087. 'Content-Type:application/json',
  1088. 'Authorization: ' . $token,
  1089. ];
  1090. $res = $this->post_helper($url, json_encode($param), $header);
  1091. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($header) . PHP_EOL, 8);
  1092. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($param) . PHP_EOL, 8);
  1093. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').$res . PHP_EOL, 8);
  1094. }
  1095. }
  1096. public function unusualRestock1($data,$mac,$token){
  1097. $send_status = true;
  1098. $send_data = [];
  1099. //2024-06-19T21:01:51.948Z,赖的写,直接拼
  1100. $iso8601Time = date('Y-m-d').'T'.date('H:i:s').'.'.rand(100,999).'Z';
  1101. foreach ($data as $v){
  1102. if($v['send_qty'] > 0) $send_status = false;
  1103. $send_product = [];
  1104. //创建异常数据
  1105. $box_data = [
  1106. 'in_out_type_code' => 'CK00004',
  1107. 'in_out_type_code_show' => '商标仓正常领标出库',
  1108. 'send_box_code' => $v['box_code'],
  1109. 'send_box_code_show' => $v['box_code_show'],
  1110. 'device_code' => $mac,
  1111. 'get_brand_source_dk' => 'SALE_ORDER',
  1112. 'abnormal_flag' => false,
  1113. 'abnormal_date' => $iso8601Time,
  1114. ];
  1115. foreach ($v['product_list'] as $kk=>$vv){
  1116. $send_product[] = [
  1117. 'item_no' => 10+$kk*10,
  1118. 'brand_qr_code_list' => '',
  1119. 'material_code' => $v['material_code'],
  1120. 'material_code_show' => $v['material_code_show'],
  1121. 'unit_code' => $v['unit_code'],
  1122. 'unit_code_show' => $v['unit_code_show'],
  1123. 'restock_qty' => $vv['restock_qty'],
  1124. 'qty' => 0,
  1125. 'fake_qty' => 0,
  1126. 'bus_type_dk' => 'SALE_ORDER',
  1127. 'bus_type_dk_show' => '销售订单',
  1128. 'bus_no' => $vv['order_item_id'],
  1129. 'bus_no_show' => $vv['order_item_id_show'],
  1130. 'product_code' => $vv['product_code'],
  1131. 'product_code_show' => $vv['product_code_show'],
  1132. 'process_title' => $vv['process_title'],
  1133. 'color' => $vv['color'],
  1134. 'process_title_two' => $vv['process_title_two'],
  1135. 'color_two' => $vv['color_two'],
  1136. ];
  1137. }
  1138. $box_data['brand_out_stock_dtl'] =$send_product;
  1139. $send_data[] = $box_data;
  1140. }
  1141. $param = [
  1142. 'brand_out_stock_list' => $send_data
  1143. ];
  1144. if($send_status){
  1145. $url = 'http://122.112.196.99:7774/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  1146. $header = [
  1147. 'Content-Type:application/json',
  1148. 'Authorization: ' . $token,
  1149. ];
  1150. $res = $this->post_helper($url, json_encode($param), $header);
  1151. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($header) . PHP_EOL, 8);
  1152. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($param) . PHP_EOL, 8);
  1153. file_put_contents('dwy1.txt', date('Y-m-d H:i:s').$res . PHP_EOL, 8);
  1154. }
  1155. }
  1156. public function zjlb(Request $request)
  1157. {
  1158. $param = $request->all();
  1159. file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8);
  1160. // $param = [
  1161. // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
  1162. // 'list'=>[
  1163. // [
  1164. // 'title'=>'优选A7家具板ENF小标',
  1165. // 'num'=>'20',
  1166. // ],[
  1167. // 'title'=>'植萃除醛圆标',
  1168. // 'num'=>'10',
  1169. // ],
  1170. // ],
  1171. // ];
  1172. // dd(json_encode($param));
  1173. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
  1174. $url = 'https://tm.dwycloud.com/jbl/api/module-data/box_inventory_dtl_qr/page';
  1175. $header = [
  1176. 'Content-Type:application/json',
  1177. 'Authorization: ' . $request->header('Authorization'),
  1178. ];
  1179. $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}';
  1180. $data = $this->post_helper($url, $param, $header);
  1181. // $data = $this->post_helper($url, json_encode($param), $header);
  1182. $data = json_decode($data, true);
  1183. // var_dump($data);die;
  1184. $data = $data['content'] ?? [];
  1185. foreach ($data as $k => &$v) {
  1186. $v['material_code_show'] = $v['box_inventory']['material_code_show'];
  1187. $v['qty'] = $v['roll_qty'];
  1188. $v['bus_date'] = $v['bus_date'] ? strtotime($v['bus_date']) : '1722441600';
  1189. $v['use_qty'] = 0;
  1190. }
  1191. sort($data);
  1192. return json_encode($data);
  1193. }
  1194. public function boxOut(Request $request)
  1195. {
  1196. $param = $request->all();
  1197. file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
  1198. //商标绑定
  1199. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  1200. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  1201. $header = [
  1202. 'Content-Type:application/json',
  1203. 'Authorization: ' . $request->header('Authorization'),
  1204. ];
  1205. $lead_bind = $param['lead_bind'];
  1206. $this->post_helper($url, json_encode($lead_bind), $header);
  1207. //商标出库
  1208. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  1209. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  1210. $lead_bind = $param['lead_out'];
  1211. $this->post_helper($url, json_encode($lead_bind), $header);
  1212. return ['status'=>200,'msg'=>'success'];
  1213. }
  1214. public function post_helper($url, $data, $header)
  1215. {
  1216. $ch = curl_init();
  1217. curl_setopt($ch, CURLOPT_POST, 1);
  1218. curl_setopt($ch, CURLOPT_URL, $url);
  1219. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1220. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1221. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1222. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  1223. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1224. $r = curl_exec($ch);
  1225. curl_close($ch);
  1226. file_put_contents('33.txt',$r.PHP_EOL,8);
  1227. return $r;
  1228. }
  1229. public function setTbData(Request $request){
  1230. $data = $request->all();
  1231. if(empty($data['id']) && empty($data['data'])) return [201, ''];
  1232. BigKingTbj::updateOrCreate(
  1233. ['id' => $data['id']], //查询条件
  1234. [
  1235. "id" => $data['id'],
  1236. "data" => json_encode($data['data'])
  1237. ] //添加或者修改的数据
  1238. );
  1239. return [200, ''];
  1240. }
  1241. public function getTbData(Request $request){
  1242. $data = $request->all();
  1243. if(empty($data['id'])) return [201, ''];
  1244. $result = BigKingTbj::where('id',$data['id'])->first();
  1245. if(empty($result)) return [200,'data' => []];
  1246. return [200, 'data' => json_decode($result['data'],true)];
  1247. }
  1248. public function setBoxTrademark(Request $request){
  1249. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list';
  1250. $header = [
  1251. 'Content-Type:application/json',
  1252. 'Authorization: ' .'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2MzM1NTJ9.CC69s4dpUdd9UqQlpeK5UF3DwY5Zenn-YHv8Iy1ai0cCXgere7r7jskWU9ARmKotys2tCGYRlO-Idtxdwdsefg',
  1253. ];
  1254. $data = [
  1255. 'roll_qr_code_list' => [
  1256. '171368443563212'
  1257. ]
  1258. ];
  1259. $a = $this->post_helper($url, json_encode($data), $header);
  1260. var_dump($a);die;
  1261. $a = json_decode($a,true);
  1262. $detail = [];
  1263. foreach ($a['data'] as $v){
  1264. $code = $v['brand_qr_code'];
  1265. $detail[] = $code;
  1266. }
  1267. file_put_contents('1.txt',json_encode($detail));
  1268. var_dump($a);die;
  1269. }
  1270. public function getBoxTrademark(Request $request){
  1271. $data = $request->all();
  1272. if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []];
  1273. $box_nos = $data['box_nos'];
  1274. $dv = $data['mac'];
  1275. $detail = [];
  1276. //测试写入文件
  1277. // foreach ($box_nos as $v) {
  1278. // $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt");
  1279. // if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade');
  1280. // file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2']));
  1281. // }
  1282. //读取文件
  1283. foreach ($box_nos as $v) {
  1284. // $filePath = public_path($file_path . "{$dv}_{$v}.txt");
  1285. $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt");
  1286. if(file_exists($filePath)){
  1287. if (($content = file_get_contents($filePath)) === false) continue;
  1288. $decodedContent = json_decode($content, true);
  1289. if (json_last_error() !== JSON_ERROR_NONE) continue;
  1290. $detail[] = [
  1291. 'detail'=>$decodedContent,
  1292. 'code'=>$v,
  1293. ];
  1294. }
  1295. }
  1296. return ['status' => 200, 'data' => $detail];
  1297. }
  1298. public function andriodLog(Request $request){
  1299. // $data = $request->all();
  1300. $data = file_get_contents('php://input');
  1301. $path = date('Ymd');
  1302. $file = 'dwyAndriod.txt';
  1303. if (!is_dir($path)) {
  1304. // 创建目录,第三个参数 true 表示递归创建目录
  1305. mkdir($path, 0755, true);
  1306. }
  1307. $param = json_decode($data,true);
  1308. if(isset($param['type'])&&isset($param['content'])){
  1309. $file = $path.'/'.$param['type'].'_'.$file;
  1310. file_put_contents($file,$param['content'].PHP_EOL,8);
  1311. }else{
  1312. file_put_contents($file,$data.PHP_EOL,8);
  1313. }
  1314. return ['status' => 200, 'data' => []];
  1315. }
  1316. public function andriodDownload(Request $request){
  1317. $data = file_get_contents('andriodList.txt');
  1318. $data = json_decode($data,true);
  1319. $param = $request->all();
  1320. if(isset($param['type'])){
  1321. $type = $param['type'];
  1322. $return = [];
  1323. foreach ($data as $v){
  1324. if($v['type'] == $type) $return[] = $v;
  1325. }
  1326. $data = $return;
  1327. }
  1328. return ['status'=>200,'data'=> $data];
  1329. }
  1330. public function setAndriodDownload(Request $request){
  1331. // $data = file_get_contents('andriodList.txt');
  1332. // if(empty($data)) $data = [];
  1333. // else $data = json_decode($data,true);
  1334. $param = $request->all();
  1335. file_put_contents('andriodList.txt',json_encode($param));
  1336. return ['status'=>200,'msg'=>'ok','data'=>[]];
  1337. }
  1338. }