| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?phpnamespace App\Service;use App\Model\BigKingCbj;use Illuminate\Support\Facades\Log;class LabelDealService extends Service{    protected static $instance;    public static function getInstance(): self    {        if (self::$instance == null) self::$instance = new LabelDealService();        return self::$instance;    }    public function clearData($data,&$return,&$box_list){        if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;        foreach ($data['lead_out']['brand_out_stock_list'] as $value){            $box_list[] = $value['send_box_code'];            foreach ($value['brand_out_stock_dtl'] as $tmp){                if(! isset($return[$value['send_box_code']])){                    $return[$value['send_box_code']] = [                        'fake_qty' => 0,                        'detail' => [],                    ];                }                $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'] ?? 0;                $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));            }        }    }    public function boxOut($lead_bind,$lead_out,$token,$id)    {        //商标出库        $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';        $return_out = $this->post_helper($url, $lead_out, $token);        $return_out = json_decode($return_out, true);        Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);        sleep(3);        //商标绑定//        $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';        $return_bind = $this->post_helper($url, $lead_bind, $token);        $return_bind = json_decode($return_bind, true);        Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);        if(isset($return_bind['status']) && $return_bind['status'] == 'success' && isset($return_out['status']) && $return_out['status'] == 'success') BigKingCbj::where('id',$id)->update(['is_successful' => 1]);    }    public function boxOut1($lead_bind,$lead_out,$token,$id)    {        //商标出库        $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';        $return_out = $this->post_helper($url, $lead_out, $token);        $return_out = json_decode($return_out, true);        Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);        sleep(3);        //商标绑定//        $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';        $return_bind = $this->post_helper($url, $lead_bind, $token);        $return_bind = json_decode($return_bind, true);        Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);        if(isset($return_bind['status']) && $return_bind['status'] == 'success' && isset($return_out['status']) && $return_out['status'] == 'success') BigKingCbj::where('id',$id)->update(['is_successful' => 1]);    }    public function post_helper($url, $data, $auth)    {        Log::channel('apiLog')->info('商标(请求参数)', ["param" => $data]);        $data = json_encode($data);        $header = [            'Content-Type:application/json',            'Authorization: ' . $auth,        ];        $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;    }}
 |