12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Model\BigKingTbj;
- use App\Service\DwyService;
- use App\Service\EmployeeService;
- use App\Service\SysMenuService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Redis;
- use Illuminate\Support\Str;
- use Obs\ObsClient;
- use Carbon\Carbon;
- class DwyController extends BaseController
- {
- public function advertisement(Request $request)
- {
- $data = $request->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(!isset($vv['restock_qty'])) $vv['restock_qty'] = 0;
- if ($vv['num'] == 0 && $vv['restock_qty'] == 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 && $vv['restock_qty'] <= 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);
- }
- }
- // dd($data);die;
- foreach ($data as $k=>$d){
- if(empty($d['product_list'])) 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];
- $this->unusualRestock($data,$mac,$token);
- if(empty($data)) return ['status' => '201', 'data' => $data,'msg'=>'无商标需要申领'];
- return ['status' => '200', 'data' => $data];
- }
- //单独的没有出标数据但是需要保存补领
- public function unusualRestock($data,$mac,$token){
- $send_status = true;
- $send_data = [];
- //2024-06-19T21:01:51.948Z,赖的写,直接拼
- $iso8601Time = date('Y-m-d').'T'.date('H:i:s').'.'.rand(100,999).'Z';
- foreach ($data as $v){
- if($v['send_qty'] > 0) $send_status = false;
- $send_product = [];
- //创建异常数据
- $box_data = [
- 'in_out_type_code' => 'CK00004',
- 'in_out_type_code_show' => '商标仓正常领标出库',
- 'send_box_code' => $v['box_code'],
- 'send_box_code_show' => $v['box_code_show'],
- 'device_code' => $mac,
- 'get_brand_source_dk' => 'SALE_ORDER',
- 'abnormal_flag' => false,
- 'abnormal_date' => $iso8601Time,
- ];
- foreach ($v['product_list'] as $kk=>$vv){
- $send_product[] = [
- 'item_no' => 10+$kk*10,
- 'brand_qr_code_list' => '',
- 'material_code' => $v['material_code'],
- 'material_code_show' => $v['material_code_show'],
- 'unit_code' => $v['unit_code'],
- 'unit_code_show' => $v['unit_code_show'],
- 'restock_qty' => $vv['restock_qty'],
- 'qty' => 0,
- 'fake_qty' => 0,
- 'bus_type_dk' => 'SALE_ORDER',
- 'bus_type_dk_show' => '销售订单',
- 'bus_no' => $vv['order_item_id'],
- 'bus_no_show' => $vv['order_item_id_show'],
- 'product_code' => $vv['product_code'],
- 'product_code_show' => $vv['product_code_show'],
- 'process_title' => $vv['process_title'],
- 'color' => $vv['color'],
- 'process_title_two' => $vv['process_title_two'],
- 'color_two' => $vv['color_two'],
- ];
- }
- $box_data['brand_out_stock_dtl'] =$send_product;
- $send_data[] = $box_data;
- }
- $param = [
- 'brand_out_stock_list' => $send_data
- ];
- if($send_status){
- $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
- $header = [
- 'Content-Type:application/json',
- 'Authorization: ' . $token,
- ];
- $res = $this->post_helper($url, json_encode($param), $header);
- file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($header) . PHP_EOL, 8);
- file_put_contents('dwy1.txt', date('Y-m-d H:i:s').json_encode($param) . PHP_EOL, 8);
- file_put_contents('dwy1.txt', date('Y-m-d H:i:s').$res . PHP_EOL, 8);
- }
- }
- 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['data'])) return [201, ''];
- BigKingTbj::updateOrCreate(
- ['id' => $data['id']], //查询条件
- [
- "id" => $data['id'],
- "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'])->first();
- if(empty($result)) return [200,'data' => []];
- return [200, 'data' => json_decode($result['data'],true)];
- }
- 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];
- }
- }
|