|
@@ -944,6 +944,164 @@ class DwyController extends BaseController
|
|
|
if(empty($data)) return ['status' => '201', 'data' => $data,'msg'=>'无商标需要申领'];
|
|
|
return ['status' => '200', 'data' => $data];
|
|
|
}
|
|
|
+ public function setLb1(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/device/device/diy/device_code';
|
|
|
+ $token = $param['token'];
|
|
|
+ $json = ['device_code'=>$param['mac']];
|
|
|
+ $header = [
|
|
|
+ 'Content-Type:application/json',
|
|
|
+ 'Authorization: ' . $token,
|
|
|
+ ];
|
|
|
+ $box_data = $this->post_helper($url, json_encode($json), $header);
|
|
|
+ $box_data = json_decode($box_data, true);
|
|
|
+ $un_box = [];
|
|
|
+ if(isset($box_data['data'])){
|
|
|
+ foreach ($box_data['data'] as $d){
|
|
|
+ if(isset($d['status'])&&$d['status'] == 0){
|
|
|
+ $un_box[] = $d['box_code'] ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// $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(isset($v['box_code'])&&in_array($v['box_code'],$un_box)) 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['restock_qty'] > 0) return ['status' => '201','data'=>[], 'msg' => '不允许超出可领数量'];
|
|
|
+ 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){
|