num = 0; // 测试 // $token = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9CUkFORF9TVVBQTElFUixST0xFX1VTRV9CUkFORF9TVVBQTElFUixST0xFX0lOTkVSX1VTRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2NzI1OTN9.VKDLhTILWHe6MIAlzNvxCk4pBQaV-Et1UFYb12xTxl-QcVWpYaWLZnk6_QJ2bDXMplp75DuIKADmjuHDjDFSWQ'; // $dv = 'DV00001'; // $box_list = [ // 'CK00007', // 'CK00008', // ]; // // $data = [ // 'CK00007'=>[ // 'fake_qty' => '3', // 'detail' => [ // "WJY98V5BJRHDEA3IQT4R", // "ULW9TDTIV092DGYD81SU" // // // ], // ], // 'CK00008'=>[ // 'fake_qty' => '3', // 'detail' => [ // "20A70CCRQ96EDM7X6C07", // "4V6GUEDJSLVAS89JJ557" // // ], // ] // ]; // $old_data = json_decode('{ // "key": "DV00001", // "lead_bind": { // "device_code": "DV00001", // "material_list": [ // { // "product_code": "BC020202000999", // "product_code_show": "\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728", // "order_item_id": "581719319017431040", // "order_item_id_show": "SO202405240088", // "material_code": "40010501000999", // "material_code_show": "\u94f6\u76fe\u6297\u83cc\u5706\u6807\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "process_title": null, // "process_title_two": null, // "color": null, // "fake_qty": 3, // "color_two": null, // "brand_qr_code_list": [ // "WJY98V5BJRHDEA3IQT4R", // "ULW9TDTIV092DGYD81SU" // ], // "order_no_list": "SO202405240088" // }, // { // "product_code": "BC020202000999", // "product_code_show": "\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728", // "order_item_id": "581719319017431040", // "order_item_id_show": "SO202405240088", // "material_code": "40010101000999", // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "process_title": null, // "process_title_two": null, // "color": null, // "fake_qty": 3, // "color_two": null, // "brand_qr_code_list": [ // "20A70CCRQ96EDM7X6C07", // "4V6GUEDJSLVAS89JJ557" // ], // "order_no_list": "SO202405240088" // } // ] // }, // "lead_out": { // "brand_out_stock_list": [ // { // "in_out_type_code": "CK00004", // "in_out_type_code_show": "\u5546\u6807\u4ed3\u6b63\u5e38\u9886\u6807\u51fa\u5e93", // "send_box_code": "CK00007", // "send_box_code_show": "\u5546\u6807\u56db\u53f7\u4ed3", // "device_code": "DV00001", // "get_brand_source_dk": "SALE_ORDER", // "brand_out_stock_dtl": [ // { // "item_no": 10, // "brand_qr_code_list": "WJY98V5BJRHDEA3IQT4R,ULW9TDTIV092DGYD81SU", // "material_code": "40010501000999", // "restock_qty": 0, // "material_code_show": "\u94f6\u76fe\u6297\u83cc\u5706\u6807\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "unit_code": "ST", // "unit_code_show": "\u5f20", // "qty": "3", // "fake_qty": 3, // "bus_type_dk": "SALE_ORDER", // "bus_type_dk_show": "\u9500\u552e\u8ba2\u5355", // "bus_no": "581719319017431040", // "bus_no_show": "SO202405240088" // } // ] // }, // { // "in_out_type_code": "CK00004", // "in_out_type_code_show": "\u5546\u6807\u4ed3\u6b63\u5e38\u9886\u6807\u51fa\u5e93", // "send_box_code": "CK00008", // "send_box_code_show": "\u5546\u6807\u4e94\u53f7\u4ed3", // "device_code": "DV00001", // "get_brand_source_dk": "SALE_ORDER", // "brand_out_stock_dtl": [ // { // "item_no": 10, // "brand_qr_code_list": "20A70CCRQ96EDM7X6C07,4V6GUEDJSLVAS89JJ557", // "material_code": "40010101000999", // "restock_qty": 0, // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "unit_code": "ST", // "unit_code_show": "\u5f20", // "qty": "3", // "fake_qty": 3, // "bus_type_dk": "SALE_ORDER", // "bus_type_dk_show": "\u9500\u552e\u8ba2\u5355", // "bus_no": "581719319017431040", // "bus_no_show": "SO202405240088" // } // ] // } // ] // } //}',true); //请求获取仓位卷码信息 $box_roll_list = $this->getBoxData($dv,$token,$box_list); // var_dump($box_roll_list);die; $new_data = []; foreach ($data as $k=>$box_detail){ foreach ($box_detail['detail'] as $v){ foreach ($box_roll_list as $roll_number=>$roll_detail){ if(in_array($v,$roll_detail['detail'])){ if(!isset($new_data[$roll_detail['box_code']])) $new_data[$roll_detail['box_code']] = [ 'detail' => [], 'fake_qty' => $data[$roll_detail['box_code']]['fake_qty'], 'material_code' => $roll_detail['material_code'], 'roll_number' => $roll_number ]; $new_data[$roll_detail['box_code']]['detail'][] = $v; break; } } } } //补全数据 $data = $this->setBoxFake($new_data); // var_dump($data); //把数据拼回去 list($lind_bind,$lead_out) = $this->setNewData($old_data,$data); // var_dump(json_encode($lind_bind)); // var_dump(json_encode($lead_out));die; return [$lind_bind,$lead_out]; } // 获取指定数量的值,并从原数组中删除这些值 function getValues(&$array, $count) { // 获取前$count个值 $result = array_slice($array, 0, $count); // 从原数组中删除这些值 $array = array_slice($array, $count); return $result; } private function setNewData($old_data,$data){ $code_key_data = []; foreach ($data as $v){ if(!isset($code_key_data[$v['material_code']])) $code_key_data[$v['material_code']] = []; $code_key_data[$v['material_code']] = array_merge($code_key_data[$v['material_code']],$v['detail']); } $lind_bind = $old_data['lead_bind']; foreach ($lind_bind['material_list'] as &$l){ unset($l['brand_qr_code_list']); // $l['qty'] = $l['fake_qty']; $l['brand_qr_code_list'] = $this->getValues( $code_key_data[$l['material_code']],$l['fake_qty']); unset($l['fake_qty']); } $lead_out = $old_data['lead_out']['brand_out_stock_list']; foreach ($lead_out as &$ll){ unset($ll['brand_out_stock_dtl'][0]['brand_qr_code_list']); $ll['brand_out_stock_dtl'][0]['qty'] = $ll['brand_out_stock_dtl'][0]['fake_qty']; unset($ll['brand_out_stock_dtl'][0]['fake_qty']); // var_dump($data[$ll['send_box_code']]); $ll['brand_out_stock_dtl'][0]['brand_qr_code_list'] = implode(',',$data[$ll['send_box_code']]['detail']); } file_put_contents('1.txt',json_encode(['lind_bind'=>$lind_bind,'lead_out'=>$lead_out])); // var_dump($lind_bind); // var_dump($lead_out);die; return [$lind_bind,['brand_out_stock_list'=>$lead_out]]; //{ // "key": "DV00001", // "lead_bind": { // "device_code": "DV00001", // "material_list": [ // { // "product_code": "BC020202000999", // "product_code_show": "\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728", // "order_item_id": "581732116677795840", // "order_item_id_show": "SO202405240088", // "material_code": "40010101000999", // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "process_title": null, // "process_title_two": null, // "color": null, // "fake_qty": 20, // "color_two": null, // "brand_qr_code_list": [ // "DN2EYGAT3XJJRGMHJ5CL", // ], // "order_no_list": "SO202405240088" // }, // { // "product_code": "BC020202000999", // "product_code_show": "\u4fe1\u606f\u90e8\u6d4b\u8bd51800\u9999\u6749\u6728", // "order_item_id": "581732116677795840", // "order_item_id_show": "SO202405240088", // "material_code": "40010101000999", // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "process_title": null, // "process_title_two": null, // "color": null, // "fake_qty": 10, // "color_two": null, // "brand_qr_code_list": [ // "13NMKBBM8O8JBRWDJHW3", // ], // "order_no_list": "SO202405240088" // } // ] // }, // "lead_out": { // "brand_out_stock_list": [ // { // "in_out_type_code": "CK00004", // "in_out_type_code_show": "\u5546\u6807\u4ed3\u6b63\u5e38\u9886\u6807\u51fa\u5e93", // "send_box_code": "CK00014", // "send_box_code_show": "\u5546\u6807\u5341\u4e00\u53f7\u4ed3", // "device_code": "DV00001", // "get_brand_source_dk": "SALE_ORDER", // "brand_out_stock_dtl": [ // { // "item_no": 10, // "brand_qr_code_list": "", // "material_code": "40010101000999", // "restock_qty": 0, // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "unit_code": "ST", // "unit_code_show": "\u5f20", // "qty": "24", // "bus_type_dk": "SALE_ORDER", // "bus_type_dk_show": "\u9500\u552e\u8ba2\u5355", // "bus_no": "581732116677795840", // "bus_no_show": "SO202405240088" // } // ] // }, // { // "in_out_type_code": "CK00004", // "in_out_type_code_show": "\u5546\u6807\u4ed3\u6b63\u5e38\u9886\u6807\u51fa\u5e93", // "send_box_code": "CK00012", // "send_box_code_show": "\u5546\u6807\u4e5d\u53f7\u4ed3", // "device_code": "DV00001", // "get_brand_source_dk": "SALE_ORDER", // "brand_out_stock_dtl": [ // { // "item_no": 10, // "brand_qr_code_list": "13NMKBBM8O8JBRWDJHW3", // "material_code": "40010101000999", // "restock_qty": 0, // "material_code_show": "E0\u6279\u96f6\u514d\u6f06\uff08\u6d4b\u8bd5\u767d\u6807\uff09", // "unit_code": "ST", // "unit_code_show": "\u5f20", // "qty": "5", // "bus_type_dk": "SALE_ORDER", // "bus_type_dk_show": "\u9500\u552e\u8ba2\u5355", // "bus_no": "581732116677795840", // "bus_no_show": "SO202405240088" // } // ] // } // ] // } //} } private function setBoxFake($data){ foreach ($data as $k=>$v){ if($v['fake_qty'] > count($v['detail'])){ $diff = $v['fake_qty'] - count($v['detail']); var_dump($diff); $return = $this->fakeData($v['roll_number'],$diff); $data[$k]['detail'] = array_merge($v['detail'],$return); } } return $data; } private function fakeData($number,$diff){ $return = []; for ($i=0;$i < $diff;$i++){ $this->num++; $return[] = 'f'.$number.'a'.$this->num.rand(10,99); } return $return; } private function getBoxData($dv,$token,$box_list){ //为了取商标卷码 $res = $this->post_helper($this->url.'/jbl/api/module-data/device/device/diy/device_code',['device_code'=>$dv],$token); $res = json_decode($res,true); $detail = []; $qr_codes = []; if(isset($res['data'])){ foreach ($res['data'] as $v){ if(in_array($v['box_code'],$box_list)){ $detail[$v['roll_qr_code']] = $v['box_code']; $qr_codes[] = $v['roll_qr_code']; } } }else{ return [false,'']; }; //为了取仓对应卷码进行获取 $res = $this->post_helper($this->url.'/jbl/api/module-data/brand_sale_order/brand_sale_order/diy/find_roll_qr_code_list',['roll_qr_code_list'=>$qr_codes],$token); $res = json_decode($res,true); $qr_roll_list = []; if(isset($res['data'])){ foreach ($res['data'] as $v){ if(!empty($v['out_brand_qr_code'])) continue; if(!isset($qr_roll_list[$v['roll_qr_code']]['material_code'])) { $qr_roll_list[$v['roll_qr_code']]['material_code'] = $v['material_code']; $qr_roll_list[$v['roll_qr_code']]['box_code'] = $detail[$v['roll_qr_code']]; } $qr_roll_list[$v['roll_qr_code']]['detail'][] = $v['brand_qr_code']; } } return $qr_roll_list; } public function post_helper($url, $data, $auth) { $header = [ 'Content-Type: application/json', 'Authorization: ' . $auth, ]; $data = json_encode($data); // var_dump($url);die; $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); return $r; } }