DwyController.php 61 KB

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