data=$data; } /** * Execute the job. * * @return void */ public function handle() { $data_info=$this->data; Log::error($data_info); $info=json_decode($data_info['data'],true); $url=mb_substr($info['Domain'],0,-1); $url_info=UrlList::where('url',$url)->first(); if ($url_info->time<(time()+30)){ $token=$this->getToekn($url,$url_info->id); }else{ $token=$url_info->token; } $type=$info['Type']; $order_arr=explode('-',$info['Code']); if (count($order_arr)>1){ Log::error($info['Code']); return null; } if ($type==3){ $order=Order::where('order_num',$info['Code'])->first(); if ($order){ if (!$order->is_deleted){ if ($order->pay_money>0){ $order->wait_back_money=$order->pay_money; $order->pay_status=3; } } $order->is_deleted=1; $order->save(); } return; } $json = '{"QueryType":"0","Code":"","BrandIDS":[],"StartDate":"","EndDate":"","StartMoney":"","EndMoney":"","WarehouseIDS":[],"AccountMethod":"","CurrencyIDS":[],"AddrName":"","AddrPhone":"","Addr":"","IsChina":"","AddrID":"","Remark":"","SourceName":"","SourcePhone":"","ProductName":"","ProductCode":"","SourceAuthorizationCode":"","SalesRemark":"","SelectOrderIDs":[],"TeamID":"","PageNo":1,"PageSize":10,"DeliveryType":"","IsCreateOrderSales":null,"Sort":"","IsAsc":false,"PackagesType":[],"BrandLevels":[],"SelfDeliveryStoreName":"","BusinessContactName":"","StateIDs":[],"TeamIDs":[],"ExpressAccountMethod":"","CustomerOrderCategoryID":0,"EMSCompany":"","DateType":"","EMSCode":"","AccuracyQueryKey":[],"NotLikeQueryKey":[],"GratisOrReachedToPay":""}'; $client=new Client(); $url = $url.'/api/Admin/CompanyCustomerOrderList/GetMyCustomerOrderList'; $data=json_decode($json,true); $data['Code']=$info['Code']; $data['AccuracyQueryKey']=['Code']; $re=$client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json', // 设置请求头 'Auth-AdminToken' => $token, // 如果需要身份验证令牌 ], 'json'=>$data ]); $res=$re->getBody()->getContents(); $order_info=json_decode($res,true); $arr=$order_info['data']['Models']; $this->DelOrder($arr,mb_substr($info['Domain'],0,-1)); } protected function getToekn($url,$id){ $client=new Client(); $re=$client->post($url.'/api/Admin/System/MainSubLogin',[ 'headers' => [ 'Content-Type' => 'application/json', // 设置请求头 // 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌 ], 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9'] ]); $res=$re->getBody()->getContents(); $info=json_decode($res,true); $urlinfo=UrlList::find($id); // Log::error($res); // Log::error($info); if (!$info['errcode']){ $token=$info['data']['accessToken']; $urlinfo->token=$token; $urlinfo->time=time()+9*60; $urlinfo->save(); return $token; }else{ Log::error($urlinfo->name.'生成token出错===='.$info['errcode']); return 0; } } protected function DelOrder($arr,$url){ if (!$arr){ return; } try { $activity_id=Activity::where('is_ing',1)->value('id'); foreach ($arr as $k=>$v){ //批发商 $Sourcemobile=$v['SourceCustomerModel']['Telephone']; $Sourcenickname=$v['SourceCustomerModel']['CustomerName']; $Sourcecode=$v['SourceCustomerModel']['AuthorizationCode']; $user=User::where('auth_code',$Sourcecode)->first(); Log::info($Sourcecode); if (!$user){ $user=new User(); $user->name=$Sourcenickname; $user->nickname=$Sourcenickname; $user->realname=$Sourcenickname; $user->remark_name=$Sourcenickname; $user->mobile=$Sourcemobile; $user->uuid=$Sourcemobile; $user->auth_code=$Sourcecode; $user->level=3; $user->url=$url; $user->save(); } $TopCode=$v['TopCustomerModel']['AuthorizationCode']; $belongUser=User::where('auth_code',$TopCode)->first(); if (!$belongUser){ //经销商 $belongUser=new User(); $belongUser->name=$v['TopCustomerModel']['CustomerName']; $belongUser->nickname=$v['TopCustomerModel']['CustomerName']; $belongUser->realname=$v['TopCustomerModel']['CustomerName']; $belongUser->remark_name=$v['TopCustomerModel']['CustomerName']; $belongUser->mobile=$v['TopCustomerModel']['Telephone']; $belongUser->uuid=$v['TopCustomerModel']['Telephone']; $belongUser->auth_code=$TopCode; $belongUser->level=2; $belongUser->url=$url; $belongUser->save(); } $order_num=$v['Code']; Log::info($order_num); $order=Order::where('order_num',$order_num)->first(); if ($order){ $address=Address::where('id',$order->address_id)->first(); $address->user_id=$user->id; $address->username=$v['AddressDetail']['Name']; $address->mobile=$v['AddressDetail']['Phone']; $address->province=$v['AddressDetail']['Province']; $address->city=$v['AddressDetail']['City']; $address->town=$v['AddressDetail']['District']; $address->address=$v['AddressDetail']['Address']; $address->type=0; $address->save(); if ($order->money!=$v['TotalCash']){ OrderDetail::where('order_id',$order->id)->delete(); } $order->money=$v['TotalCash']; if ($order->money==$order->pay_money){ $order->no_pay_money=0;//未支付变为0 $order->pay_status=2;//支付状态2,为全部支付 $order->wait_back_money=0;//待退回金额为0 }elseif ($order->money<$order->pay_money){//订单金额小于支付金额 $order->no_pay_money=0;//未支付金额变为0 $order->pay_status=3;//支付状态3,待退款状态 $order->wait_back_money=$order->pay_money-$order->money;//待退款金额为支付金额减去订单金额 }elseif ($order->money>$order->pay_money){//订单金额大于支付金额 if ($order->pay_money==0){//如果支付金额为0 $order->pay_status=0;//则支付状态0,未支付 }else{ $order->pay_status=1;//否则支付状态1,部分支付 } $order->no_pay_money=$order->money-$order->pay_money;//未支付金额等于订单金额减去支付金额 $order->wait_back_money=0;//待退款为0 } $order->total=$v['TotalQty']; $order->State=$v['State']; $order->save(); $detail=$v['OrderDetailOutput']; $activity_status=false; $orderdrtail_id=[]; foreach ($detail as $ke=>$va){ if ($va['IsGift']){ $activity_status=true; $gift_name=$va['ProductName']; $num=$va['Qty']; $gift=Gifts::where('name',$gift_name)->where('activity_id',$activity_id)->first(); $ordergift=OrderGift::where('order_id',$order->id) ->where('gift_id',$gift->id)->first(); if (!$ordergift){ $ordergift=new OrderGift(); } $order->total-=$num; $order->save(); $ordergift->gift_id=$gift->id; $ordergift->order_id=$order->id; $ordergift->activity_id=$activity_id; $ordergift->num=$num; $ordergift->limit_num=1; $ordergift->save(); }else{ // Log::error($va); $GroupID=$va['ProductGroupSKUID']; $num=$va['Qty']; $goods=Goods::where('groupID',$GroupID)->first(); if (!$goods){ Log::error('不存在商品'.$GroupID); } $orderDetail=OrderDetail::where('order_id',$order->id) ->where('goods_id',$goods->id)->first(); if (!$orderDetail){ $orderDetail=new OrderDetail(); } $orderDetail->order_id=$order->id; $orderDetail->goods_id=$goods->id; $orderDetail->num=$num; $orderDetail->goods_price=$va['Price']; $orderDetail->money=$num*$va['Price']; $orderDetail->goods_name=$goods->name; $orderDetail->goods_size=$goods->size; $orderDetail->goods_unit=$goods->unit; $orderDetail->goods_sku=$va['SKUCode']; $orderDetail->save(); $order_id[]=$orderDetail->id; } } }else{ $address=new Address(); $address->user_id=$user->id; $address->username=$v['AddressDetail']['Name']; $address->mobile=$v['AddressDetail']['Phone']; $address->province=$v['AddressDetail']['Province']; $address->city=$v['AddressDetail']['City']; $address->town=$v['AddressDetail']['District']; $address->address=$v['AddressDetail']['Address']; $address->type=0; $address->uid=$belongUser->id; $address->save(); $order=new Order(); $order->order_num=$order_num; $order->money=$v['TotalCash']; $order->no_pay_money=$v['TotalCash']; $order->user_id=$user->id; $order->total=$v['TotalQty']; $order->created_at=$v['CreateDate']; $order->ZDL_id=$v['CustomerOrderID']; $order->url=$url; $order->State=$v['State']; $order->address_id=$address->id; $order->good_user_id=$belongUser->id; if ($v['State']=='7'){ $order->is_deleted=1; } $order->save(); $detail=$v['OrderDetailOutput']; $activity_status=false; foreach ($detail as $ke=>$va){ if ($va['IsGift']){ $activity_status=true; $gift_name=$va['ProductName']; $num=$va['Qty']; $gift=Gifts::where('name',$gift_name)->where('activity_id',$activity_id)->first(); $ordergift=new OrderGift(); $ordergift->gift_id=$gift->id; $ordergift->order_id=$order->id; $ordergift->activity_id=$activity_id; $ordergift->num=$num; $ordergift->limit_num=1; $ordergift->save(); $order->total-=$num; $order->save(); }else{ $GroupID=$va['ProductGroupSKUID']; $num=$va['Qty']; $goods=Goods::where('groupID',$GroupID)->first(); if (!$goods){ Log::error('不存在该商品'.$GroupID); } $orderDetail=new OrderDetail(); $orderDetail->order_id=$order->id; $orderDetail->goods_id=$goods->id; $orderDetail->num=$num; $orderDetail->goods_price=$va['Price']; $orderDetail->money=$num*$va['Price']; $orderDetail->goods_name=$goods->name; $orderDetail->goods_size=$goods->size; $orderDetail->goods_unit=$goods->unit; $orderDetail->goods_sku=$va['SKUCode']; $orderDetail->save(); } } if ($activity_status){ $order->activity_id=$activity_id; $order->save(); } } } }catch (\Exception $exception){ // Log::error($arr); // DB::table('data_in') // ->insert(['uuid'=>$data_id]); Log::error($exception->getMessage()); } } }