| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 | 
							- <?php
 
- namespace App\Service;
 
- /**
 
-  * dwy相关
 
-  * @package App\Models
 
-  */
 
- class DwyService extends Service
 
- {
 
-     private $url = 'https://tm.dwycloud.com';
 
-     protected $num = 0;
 
-     protected static $instance;
 
-     public static function getInstance(): self
 
-     {
 
-         if (self::$instance == null) {
 
-             self::$instance = new DwyService();
 
-         }
 
-         return self::$instance;
 
-     }
 
-     public function setBoxData($token,$dv,$data,$box_list,$old_data){
 
-         //
 
-         $this->num = 0;
 
- //        $token = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NjYxNTc5MjMwMDUzNzAzNjgiLCJhdXRoIjoiUk9MRV9CUkFORF9TVVBQTElFUixST0xFX1VTRV9CUkFORF9TVVBQTElFUixST0xFX0lOTkVSX1VTRVIsUk9MRV9JTlRFUkZBQ0UsUk9MRV9TRU5EX0JSQU5EX1NVUFBMSUVSIiwidG9rZW5JZCI6IjQiLCJleHAiOjE3MTk2NzI1OTN9.VKDLhTILWHe6MIAlzNvxCk4pBQaV-Et1UFYb12xTxl-QcVWpYaWLZnk6_QJ2bDXMplp75DuIKADmjuHDjDFSWQ';
 
- //        $dv = 'DV00001';
 
- //        $box_list = [
 
- //            'CK00007',
 
- //            'CK00004',
 
- //        ];
 
- //
 
- //        $data = [
 
- //            'CK00007'=>[
 
- //                'fake_qty' => '6',
 
- //                'detail' => ['K45SGTLA5HMM7YL1SPMM','R0FWCC4OG0BJFGY5D6BW','7I1V5NXUB8HO68TQT6F3','8EDJPMJQ3K0RCQ0DW45R'],
 
- //            ],
 
- //            'CK00004'=>[
 
- //                'fake_qty' => '7',
 
- //                'detail' => ['WO17UD8SJ5CMF8X4RCNF','IKUOBRFEDM2QI2KQ15TI','GB0C22CDHO4WMWCVO5GL','OHYL6X2RYCBQ2M6FYTDI','8IVEAK4UXO6HY9YN4MTI','B9MCUXN8CB25750R1U41'],
 
- //            ]
 
- //        ];
 
-         //请求获取仓位卷码信息
 
-         $box_roll_list = $this->getBoxData($dv,$token,$box_list);
 
-         $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;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
- //        var_dump($new_data);die;
 
-         //补全数据
 
-         $data = $this->setBoxFake($new_data);
 
-         //把数据拼回去
 
-         list($lind_bind,$lead_out) = $this->setNewData($old_data,$data);
 
-         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['brand_qr_code_list'] = $this->getValues( $code_key_data[$l['material_code']],$l['fake_qty']);
 
-         }
 
-         $lead_out = $old_data['brand_out_stock_list'];
 
-         foreach ($lead_out as &$ll){
 
-             unset($ll['brand_qr_code_list']);
 
-             $ll['brand_qr_code_list'] = $data[$ll['send_box_code']];
 
-         }
 
-         return [$lind_bind,$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(!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;
 
-     }
 
- }
 
 
  |