all(); file_put_contents('dwy1.txt', json_encode(['data'=>$data,'header']) . PHP_EOL, 8); if(!isset($data['mac'])||$data['mac'] == 'a6a672c3e458bed2'){ return ['status' => 200, 'data' => [ 'video' => ['https://clouddevice.qingyaokeji.com/1.mp4', 'https://clouddevice.qingyaokeji.com/2.mp4'], 'img' => [ 'https://clouddevice.qingyaokeji.com/3.jpeg', 'https://clouddevice.qingyaokeji.com/3.jpeg', ], 'limit_time' => 10 ]]; } $url = 'https://tm.dwycloud.com/jbl/api/module-data/poster/poster/diy/device_code'; $token = $data['token']; $param = ['device_code'=>$data['mac']]; $header = [ 'Content-Type:application/json', 'Authorization: ' . $token, ]; $box_data = $this->post_helper($url, json_encode($param), $header); $box_data = json_decode($box_data, true); if(isset($box_data)&&$box_data['status'] === 'success'){ $return = [ 'video' => [], 'img' => [], 'limit_time' => 1 ]; foreach ($box_data['data'] as $v){ if(isset($v['poster_attachment']['picture_attachment']['attachFile'])){ foreach ($v['poster_attachment']['picture_attachment']['attachFile'] as $vv){ // var_dump($vv); $return['img'][] = $this->getObsUrl($vv['path']); } } if(isset($v['poster_attachment']['attachment']['attachFile'])){ foreach ($v['poster_attachment']['attachment']['attachFile'] as $vv){ // var_dump($vv); $return['video'][] = $this->getObsUrl($vv['path']); } } } }else{ $return = [ 'video' => ['https://clouddevice.qingyaokeji.com/1.mp4', 'https://clouddevice.qingyaokeji.com/2.mp4'], 'img' => [ 'https://clouddevice.qingyaokeji.com/3.jpeg', 'https://clouddevice.qingyaokeji.com/3.jpeg', ], 'limit_time' => 15 ]; } return ['status' => 200, 'data' => $return]; } public function getObsUrl($key){ //https://shangbiaoji-test.obs.cn-east-2.myhuaweicloud.com/shangbiaoji/20240621/E1F5AF36B011AEBAACB7246DD15F5E1E //https://shangbiaoji-test.obs.cn-east-2.myhuaweicloud.com/shangbiaoji/20240621/1718928008131.jpg $obsClient = new ObsClient([ 'key' => '0LLP17PIAGNVS5SFLMZL', 'secret' => 'A5dANNHaTelCzdLuhq9Gyrw13QZF3aNpZkKoySWF', 'endpoint' => 'https://obs.cn-east-2.myhuaweicloud.com' ]); // 设置桶名和对象名 $bucketName = 'shangbiaoji-test'; $objectKey = $key; // 例如:path/to/video.mp4 // 设置过期时间(以秒为单位) $expires = 86400; // URL的有效期为1小时 // 生成预签名URL $response = $obsClient->createSignedUrl([ 'Method' => 'GET', // 请求方法 'Bucket' => $bucketName, 'Key' => $objectKey, 'Expires' => $expires ]); // 获取预签名URL $signedUrl = $response['SignedUrl']; $obsClient->close(); return $signedUrl; } public function openCommand(Request $request) { $data = $request->all(); file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8); $device_id = $data['device_code']; $box_code = $data['box_code']; $key = $data['type']; $limit = 60; if ($key === 'UP') { $num = Redis::get($device_id . 'status_num'); if (empty($num)) $num = 0; $num++; if ($num === 1) { Redis::set($device_id . 'status_num', $num); Redis::expire($device_id . 'status_num', $limit); Redis::set($device_id . 'status', 201); Redis::expire($device_id . 'status', $limit); Redis::set($device_id, json_encode([$box_code])); Redis::expire($device_id, $limit); } else { $old = Redis::get($device_id); if (empty($old)) $old = []; else $old = json_decode($old, true); $data = array_merge($old, [$box_code]); Redis::set($device_id, json_encode($data)); Redis::expire($device_id, $limit); Redis::del($device_id . 'status'); Redis::del($device_id . 'status_num'); } } else { Redis::set($device_id, json_encode([$box_code])); Redis::expire($device_id, $limit); } return ['status' => 200]; } public function openDoor(Request $request) { $data = $s = $request->all(); file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8); $data = $data['device_code']; $code = Redis::get($data); Redis::del($data); // return ['data'=>['CK00001','CK00018'],'status'=>200]; if (empty($code)) return ['data' => [], 'status' => 201]; $status = Redis::get($data . 'status'); if (empty($status)) $status = 200; if(isset($s['again'])&&$s['again']===true) $status = 201; return ['data' => json_decode($code, true), 'status' => $status]; } public function maintenance(Request $request) { $data = [ [ 'code' => 'CK00001', 'title' => '设备仓' ],[ 'code' => 'CK00003', 'title' => '维修仓' ],[ 'code' => 'CK00004', 'title' => '商标一号仓' ],[ 'code' => 'CK00005', 'title' => '商标二号仓' ],[ 'code' => 'CK00006', 'title' => '商标三号仓' ],[ 'code' => 'CK00007', 'title' => '商标四号仓' ],[ 'code' => 'CK00008', 'title' => '商标五号仓' ],[ 'code' => 'CK00009', 'title' => '商标六号仓' ],[ 'code' => 'CK00010', 'title' => '商标七号仓' ],[ 'code' => 'CK00011', 'title' => '商标八号仓' ],[ 'code' => 'CK00012', 'title' => '商标九号仓' ],[ 'code' => 'CK00013', 'title' => '商标十号仓' ],[ 'code' => 'CK00014', 'title' => '商标十一号仓' ],[ 'code' => 'CK00015', 'title' => '商标十二号仓' ],[ 'code' => 'CK00016', 'title' => '商标十三号仓' ],[ 'code' => 'CK00017', 'title' => '商标十四号仓' ],[ 'code' => 'CK00018', 'title' => '商标十五号仓' ],[ 'code' => 'CK00019', 'title' => '商标十六号仓' ] ]; return ['data' => $data, 'status' => 200]; } public function getOpenCommand(Request $request) { $data = $request->all(); file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8); $device_id = $data['device_code']; $box_code = $data['box_code']; $key = $device_id . '_' . $box_code; $return = 201; $status = Redis::get($key); if ($status) { $return = 200; Redis::del($key); } return ['status' => $return]; } public function boxList(Request $request) { $param = $request->all(); $token = $param['token']; $device_code = $param['device_code']; //商标仓列表 $url = 'https://tm.dwycloud.com/jbl/api/module-data/device/device/diy/device_code'; $header = [ 'Content-Type:application/json', 'Authorization: ' . $token, ]; $box_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header); $box_data = json_decode($box_data, true); if (isset($box_data['status']) && $box_data['status'] === 'success') { //库存查询 $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory'; $stock_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header); $stock_data = json_decode($stock_data, true); if ($stock_data) { $list = []; $material_list = []; foreach ($box_data['data'] as $v) { $list[$v['box_code']] = [ 'material_code' => $v['material_code'], 'material_code_show' => $v['material_code_show'], 'box_code' => $v['box_code'], 'box_code_show' => $v['box_code_show'], 'min_stock_qty' => $v['min_stock_qty'] ?? 0, 'safe_stock_qty' => $v['safe_stock_qty'] ?? 0, 'status' => 1, //0设备仓中没有对应库存,1有对应库存,2对应商标仓中还有数量不允许上标 'qty' => 0, 'device_title' => $v['device']['name'] ?? '', ]; $material_list[$v['material_code']][] = $v['box_code']; } $return = []; foreach ($stock_data as $v) { if (isset($material_list[$v['material_code']]) && $v['box_code'] == 'CK00001' && $v['qty'] > 0) { foreach ($material_list[$v['material_code']] as $vv) { $list[$vv]['status'] = 1; } } if (isset($list[$v['box_code']]) && $v['qty'] > 0) { $list[$v['box_code']]['qty'] = $v['qty']; } } foreach ($list as $v) { if ($v['qty'] > 0) { $v['status'] = 2; } $return[] = $v; } return ['status' => 'success', 'data' => $return]; } } return $box_data; } public function test(){ $a = json_decode('{ "status": 200, "data": [ { "created_date_lt": "2024-06-08T08:30:15.000Z", "created_date": "2024-06-08T08:30:15.086Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010127000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "587196751249805312", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "587196751312719872", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-08T08:30:15.000Z", "material_code_show": "尊贵免漆板ENF小标", "qty": 4040, "specs": null, "box_code": "CK00005", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-08T08:30:15.095Z", "box_code_show": "商标二号仓", "in_stock_qty": 5000, "use_qty": 4040, "product_list": [ { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211289030656", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "120", "fake_qty": "120", "restock_qty": 0 }, { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211242893312", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "30", "fake_qty": "30", "restock_qty": 0 }, { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211221921792", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "160", "fake_qty": "160", "restock_qty": 0 } ], "send_qty": 310, "restore_qty": 0 }, { "created_date_lt": "2024-06-06T10:34:14.000Z", "created_date": "2024-06-06T10:34:14.502Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010232000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586503178690891776", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586503178758000640", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-06T10:34:14.000Z", "material_code_show": "优选A6森芯板E0小标", "qty": 4519, "specs": null, "box_code": "CK00007", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-06T10:34:14.512Z", "box_code_show": "商标四号仓", "in_stock_qty": 4652, "use_qty": 4519, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-08T05:59:10.000Z", "created_date": "2024-06-08T05:59:10.127Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010504000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "587158730056011776", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "587158730123120640", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-08T05:59:10.000Z", "material_code_show": "ENF圆标", "qty": 2909, "specs": null, "box_code": "CK00010", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-08T05:59:10.136Z", "box_code_show": "商标七号仓", "in_stock_qty": 5000, "use_qty": 2909, "safe_stock_qty": 400, "min_stock_qty": 100, "product_list": [ { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211289030656", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "120", "fake_qty": "120", "restock_qty": 0 }, { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211242893312", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "30", "fake_qty": "30", "restock_qty": 0 }, { "product_code": "BC450108000001", "product_code_show": "大王椰1700尊贵型ENF机拼香杉木-智能生态免漆板W", "order_item_id": "581029211221921792", "order_item_id_show": "SO202405200171", "process_title": "", "color": "", "process_title_two": "", "color_two": "", "send_qty": "160", "fake_qty": "160", "restock_qty": 0 } ], "send_qty": 310, "restore_qty": 0 }, { "created_date_lt": "2024-06-06T07:05:12.000Z", "created_date": "2024-06-06T07:05:12.783Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010102000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586450574908723200", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586450574980026368", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-06T07:05:12.000Z", "material_code_show": "尊贵免漆背板E0小标", "qty": 5001, "specs": null, "box_code": "CK00011", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-06T07:05:12.793Z", "box_code_show": "商标八号仓", "in_stock_qty": 5001, "use_qty": 5001, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-06T07:37:23.000Z", "created_date": "2024-06-06T07:37:23.194Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010134000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586458671639302144", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586458671702216704", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-06T07:37:23.000Z", "material_code_show": "优选免漆板ENF小标", "qty": 3345, "specs": null, "box_code": "CK00014", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-06T07:37:23.203Z", "box_code_show": "商标十一号仓", "in_stock_qty": 3345, "use_qty": 3345, "safe_stock_qty": 400, "min_stock_qty": 300, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-07T08:37:02.000Z", "created_date": "2024-06-07T08:37:02.353Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010101000999", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586836071590006784", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586836071657115648", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-07T08:37:02.000Z", "material_code_show": "E0批零免漆(测试白标)", "qty": 1234, "specs": null, "box_code": "CK00015", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-07T08:37:02.364Z", "box_code_show": "商标十二号仓", "in_stock_qty": 1518, "use_qty": 1234, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-08T02:08:40.000Z", "created_date": "2024-06-08T02:08:40.233Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010504000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "587100723276288000", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "587100723347591168", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-08T02:08:40.000Z", "material_code_show": "ENF圆标", "qty": 4467, "specs": null, "box_code": "CK00016", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-08T02:08:40.243Z", "box_code_show": "商标十三号仓", "in_stock_qty": 5000, "use_qty": 4467, "safe_stock_qty": 400, "min_stock_qty": 100, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-07T08:12:36.000Z", "created_date": "2024-06-07T08:12:36.275Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010501000999", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586829922408992768", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586829922471907328", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-07T08:12:36.000Z", "material_code_show": "银盾抗菌圆标(测试白标)", "qty": 1236, "specs": null, "box_code": "CK00017", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-07T08:12:36.284Z", "box_code_show": "商标十四号仓", "in_stock_qty": 1510, "use_qty": 1236, "product_list": [], "send_qty": 0 }, { "created_date_lt": "2024-06-06T07:35:54.000Z", "created_date": "2024-06-06T07:35:54.496Z", "last_modified_by_show": "余丽娴", "device_code": "a6a672c3e458bed2", "material_code": "40010504000001", "last_modified_by": "553395510115962882", "unit_code_show": "张", "bus_type_dk": "SUPPLIER", "created_by": "553395510115962882", "unit_code": "ST", "dynamic_form_value_id": "586458299612925952", "supplier_code_show": "嘉善大王椰整体橱柜有限公司", "device_code_show": "天凝工厂1号机", "belong_org": "0102", "bus_type_dk_show": "工厂", "created_by_show": "余丽娴", "id": "586458299675840512", "supplier_code": "0102", "main_table_id": null, "last_modified_date_lt": "2024-06-06T07:35:54.000Z", "material_code_show": "ENF圆标", "qty": 32, "specs": null, "box_code": "CK00018", "request_id": null, "detail_table_id": null, "last_modified_date": "2024-06-06T07:35:54.505Z", "box_code_show": "商标十五号仓", "in_stock_qty": 1540, "use_qty": 32, "safe_stock_qty": 400, "min_stock_qty": 100, "product_list": [], "send_qty": 0 } ] }',true); foreach ($a['data'] as $k=>$v){ if($v['box_code'] == 'CK00005') { foreach ($v['product_list'] as $kk=>$vv){ if($kk > 0 ){ unset($v['product_list'][$kk]); continue; } $v['product_list'][$kk]['send_qty'] = 200; $v['product_list'][$kk]['fake_qty'] = 200; } // $a['data'][$k]['box_code'] = 'CK00006'; // $a['data'][$k]['box_code_show'] = '商标三号仓'; $aa = $v; // $aa['box_code'] = 'CK00019'; // $aa['box_code_show'] = '商标十六号'; $aa['send_qty'] = 200; // // $bb = $v; // $bb['box_code'] = 'CK00013'; // $bb['box_code_show'] = '商标十号'; // $bb['send_qty'] = '15'; // // $cc = $v; // $cc['box_code'] = 'CK00014'; // $cc['box_code_show'] = '商标十一号'; // $cc['send_qty'] = '15'; // // $dd = $v; // $dd['box_code'] = 'CK00015'; // $dd['box_code_show'] = '商标十二号'; // $dd['send_qty'] = '15'; // // $gg = $v; // $gg['box_code'] = 'CK00018'; // $gg['box_code_show'] = '商标十五号'; // $gg['send_qty'] = '15'; } 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') { unset($a['data'][$k]); continue; } } $box_list = [ 1,2 ]; foreach ($box_list as $v){ $v = $v+3; if($v<10) $n = '0'.$v; else $n = $v; $aa['box_code'] = 'CK000'.$n; $aa['box_code_show'] = '商标'.($n-3).'号'; $a['data'][] = $aa; } // $a['data'][] = $bb; // $a['data'][] = $cc; // $a['data'][] = $dd; // $a['data'][] = $gg; usort( $a['data'], function ($jj,$kk){ return str_replace('CK','',$jj['box_code']) - str_replace('CK','',$kk['box_code']); }); return $a; } public function setLb(Request $request) { $param = $request->all(); file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8); // $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); $token = $param['token']; $list = $param['list']; $mac = $param['mac']; // if($mac === '28f1e65c8cfd496f'){ //// // return $this->test(); // } $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory'; $header = [ 'Content-Type:application/json', 'Authorization: ' . $token, ]; $data = $this->post_helper($url, '{"device_code":"'.$mac.'"}', $header); $data = json_decode($data, true); if($mac == 'a6a672c3e458bed2'||$mac == 'DV00001'){ usort($data, function ($a,$b){ return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']); }); }else{ usort($data, function($a, $b) { return $b['qty'] < $a['qty']; }); } //做一个单独的校验,如果数量不够则返回失败 $out_key_list = []; foreach ($list as $l){ if(!isset($out_key_list[$l['title']])) $out_key_list[$l['title']] = 0; $out_key_list[$l['title']] += $l['num']; } $box_key_list = []; foreach ($data as $d){ if (!isset($d['box_code_show']) || $d['box_code_show'] == '设备仓') { continue; } if(!isset($box_key_list[$d['material_code_show']])) $box_key_list[$d['material_code_show']] = 0; $box_key_list[$d['material_code_show']] += $d['qty']; } foreach ($out_key_list as $k=>$v){ if(!isset($box_key_list[$k])){ return ['status' => '201', 'data' => [],'msg'=>$k.'没有库存信息!']; } if($box_key_list[$k] < $v) { return ['status' => '201','data'=>[], 'msg' => $k.'库存数量不足信息!']; } } //end foreach ($data as $k => &$v) { if (!isset($v['product_list'])) $v['product_list'] = []; if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') { unset($data[$k]); continue; } if ($v['qty'] <= 0) { unset($data[$k]); continue; } $v['use_qty'] = $v['qty']; if (!isset($v['send_qty'])) $v['send_qty'] = 0; foreach ($list as $kk => $vv) { if ($vv['num'] == 0) continue; if ($v['material_code_show'] === $vv['title']) { $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0; if (($v['qty'] - $v['send_qty']) > $vv['num']) { $list[$kk]['num'] -= $vv['num']; $v['send_qty'] += $vv['num']; $p_total = $vv['num']; } else { $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']); $p_total = ($v['qty'] - $v['send_qty']); $v['send_qty'] += ($v['qty'] - $v['send_qty']); } //把产品相关参数进行封装 ////产品编号 //"product_code": "", ////产品名称 //"product_code_show": "", ////工艺 //"process_title": "", ////花色 //"color": "", ////工艺2 //"process_title_two": "", ////花色2 //"color_two": "", if($p_total == 0) continue; $key_arr = [ 'product_code' => $vv['product_code'] ?? '', 'product_code_show' => $vv['product_code_show'] ?? '', 'order_item_id' => $vv['order_item_id'] ?? '', 'order_item_id_show' => $vv['order_item_id_show'] ?? '', 'process_title' => $vv['craft_type_code_show'] ?? '', 'color' => $vv['decor_code_show'] ?? '', 'process_title_two' => $vv['craft_type_two_code_show'] ?? '', 'color_two' => $vv['decor_two_code_show'] ?? '', 'send_qty' => $p_total, 'fake_qty' => $p_total, // 'send_qty' => 0, 'restock_qty' => $vv['restock_qty'] ?? 0, ]; if($vv['restock_qty'] > 0) $list[$kk]['restock_qty'] = 0; $v['product_list'][] = $key_arr; } // var_dump($key_arr); // var_dump($key_arr); } } foreach ($data as $k=>$d){ if($d['send_qty'] <= 0) unset($data[$k]); } usort($data, function ($a,$b){ return str_replace('CK','',$a['box_code']) - str_replace('CK','',$b['box_code']); }); // list($status,$msg) = DwyService::getInstance()->setLimitForBoxOut($param); // if(! $status) return ['status' => '201', 'data' => [],'msg'=> $msg]; return ['status' => '200', 'data' => $data]; } public function zjlb(Request $request) { $param = $request->all(); file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8); // $param = [ // 'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg', // 'list'=>[ // [ // 'title'=>'优选A7家具板ENF小标', // 'num'=>'20', // ],[ // 'title'=>'植萃除醛圆标', // 'num'=>'10', // ], // ], // ]; // dd(json_encode($param)); // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory'; $url = 'https://tm.dwycloud.com/jbl/api/module-data/box_inventory_dtl_qr/page'; $header = [ 'Content-Type:application/json', 'Authorization: ' . $request->header('Authorization'), ]; $param = '{"direction":"DESC","property":"id","fromClientType":"pc","number":0,"sorts":[],"rules":[{"field":"box_inventory.device_code","option":"LIKE_ANYWHERE","values":["'.$param['device_code'].'"]}],"size":15,"specialConditions":[],"workflowSearchBean":{},"dynamicFormCode":"box_inventory","developmentSystemId":null,"debugFlag":true}'; $data = $this->post_helper($url, $param, $header); // $data = $this->post_helper($url, json_encode($param), $header); $data = json_decode($data, true); $data = $data['content'] ?? []; foreach ($data as $k => &$v) { $v['material_code_show'] = $v['box_inventory']['material_code_show']; $v['qty'] = $v['roll_qty']; $v['use_qty'] = 0; } sort($data); return json_encode($data); } public function boxOut(Request $request) { $param = $request->all(); file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8); //商标绑定 $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1'; // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind'; $header = [ 'Content-Type:application/json', 'Authorization: ' . $request->header('Authorization'), ]; $lead_bind = $param['lead_bind']; $this->post_helper($url, json_encode($lead_bind), $header); //商标出库 // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock'; $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11'; $lead_bind = $param['lead_out']; $this->post_helper($url, json_encode($lead_bind), $header); return ['status'=>200,'msg'=>'success']; } public function post_helper($url, $data, $header) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $r = curl_exec($ch); curl_close($ch); file_put_contents('33.txt',$r.PHP_EOL,8); return $r; } public function setTbData(Request $request){ $data = $request->all(); if(empty($data['id']) && empty($data['mac']) && empty($data['data'])) return [201, '']; BigKingTbj::updateOrCreate( ['id' => $data['id'], 'mac' => $data['mac']], //查询条件 [ "id" => $data['id'], "mac" => $data['mac'], "data" => json_encode($data['data']) ] //添加或者修改的数据 ); return [200, '']; } public function getTbData(Request $request){ $data = $request->all(); if(empty($data['id'])) return [201, '']; $result = BigKingTbj::where('id',$data['id'])->get()->toArray(); if(empty($result)) return [200,'data' => []]; $return = []; foreach ($result as $value){ $return[] = [ 'mac' => $value['mac'], 'data' => json_decode($value['data'],true), ]; } return [200, 'data' => $return]; } public function setBoxTrademark(Request $request){ $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list'; $header = [ 'Content-Type:application/json', 'Authorization: ' .'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfU1VQUExJRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9VU0VfQlJBTkRfU1VQUExJRVIsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2MzM1NTJ9.CC69s4dpUdd9UqQlpeK5UF3DwY5Zenn-YHv8Iy1ai0cCXgere7r7jskWU9ARmKotys2tCGYRlO-Idtxdwdsefg', ]; $data = [ 'roll_qr_code_list' => [ '171368443563212' ] ]; $a = $this->post_helper($url, json_encode($data), $header); var_dump($a);die; $a = json_decode($a,true); $detail = []; foreach ($a['data'] as $v){ $code = $v['brand_qr_code']; $detail[] = $code; } file_put_contents('1.txt',json_encode($detail)); var_dump($a);die; } public function getBoxTrademark(Request $request){ $data = $request->all(); if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []]; $box_nos = $data['box_nos']; $dv = $data['mac']; $detail = []; //测试写入文件 // foreach ($box_nos as $v) { // $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt"); // if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade'); // file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2'])); // } //读取文件 foreach ($box_nos as $v) { // $filePath = public_path($file_path . "{$dv}_{$v}.txt"); $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt"); if(file_exists($filePath)){ if (($content = file_get_contents($filePath)) === false) continue; $decodedContent = json_decode($content, true); if (json_last_error() !== JSON_ERROR_NONE) continue; $detail[] = [ 'detail'=>$decodedContent, 'code'=>$v, ]; } } return ['status' => 200, 'data' => $detail]; } }