express_number)->first(); $data['belong_user_nickname']=''; $data['belong_user_mobile']=''; $data['address_name']=''; if ($datas){ $order=OrderTest::with(['get_good_user','get_address_user'])->find($data->order_id); if (!$order->get_good_user->isEmpty()){ $data['belong_user_nickname']=$order->get_good_user->nickname; $data['belong_user_mobile']=$order->get_good_user->mobile; } if (!$order->get_address_user->isEmpty()){ $data['address_name']=$order->get_address_user->username; } }else{ $datas=Express::where('express_number',"'".$request->express_number)->first(); $data['belong_user_nickname']=''; $data['belong_user_mobile']=''; $data['address_name']=''; if ($datas){ $order=OrderTest::with(['get_good_user','get_address_user'])->find($data->order_id); if (!$order->get_good_user->isEmpty()){ $data['belong_user_nickname']=$order->get_good_user->nickname; $data['belong_user_mobile']=$order->get_good_user->mobile; } if (!$order->get_address_user->isEmpty()){ $data['address_name']=$order->get_address_user->username; } } } return $this->success($data); } /*四种商品的选择**/ public function get_good(){ $re=GoodSelect::select('id','good_name')->get(); return $this->success($re); } /****/ /**公司发货**/ public function send_goods(Request $request){ $input=$request->all(); $user=User::where('id',$request->id)->first(); $re=Select::where('code',$input['code'])->first(); if ($re){ DB::beginTransaction(); try{ //小码发货 if ($re->is_lowest==1){ $re->user_id=$user->id; $re->com_binding=0; $re->track_status=2; $re->com_binding=0; $re->good_select_id=$request->good_select_id; $num=$this->update_full($re->pid); if ($num==300){ return $this->error(50021,'','修改状态出错'); } $data=[ 'op_name'=>'公司', 'op_phone'=>'', 'op_id'=>'', 'accept_name'=>$user->nickname, 'accept_phone'=>$user->mobile, 'accept_id'=>$user->id, 'type'=>1, 'select_id'=>$re->id ]; event(new SendGoodLogEvent($data)); }else{//中码或者大码发货 $num=$this->is_full($input['code']); if ($num==300){ return $this->error(50026,'','小码已经部分发货,不能扫描中码或者大码进行发货'); } $this->send_child_good($re->sort,$user->id,$request->good_select_id); $re->user_id=$user->id; $re->com_binding=0; $re->track_status=2; $re->com_binding=0; $re->good_select_id=$request->good_select_id; } $re->save(); DB::commit(); return $this->success([]); }catch (\Exception $exception){ DB::rollBack(); return $this->error(40023,'','发货失败,请重新尝试'); } }else{ return $this->error(40023,'','没有查到二维码对应的信息,请重试'); } } /**子码同时发货**/ public function send_child_good($id,$user_id,$good_select_id){ DB::beginTransaction(); try{ //查找下一级 $data=Select::where('pid',$id)->get(); //当前货物信息 $re=Select::where('sort','=',$id)->first(); //中码发货时 if ($re->level!=1){ //修改中码所属大码的状态 $num=$this->update_full($re->pid); if ($num==300){ throw new \Exception(1); } } foreach ($data as $k=>$v){ if ($v->is_lowest!=1){ $num=$this->send_child_good($v->id,$user_id,$good_select_id); if ($num==300){ throw new \Exception(1); } } $se=Select::find($v->id); $se->track_status=2; $se->com_binding=0; $se->user_id=$user_id; $se->good_select_id=$good_select_id; if (!$se->save()){ throw new \Exception('1'); } $user_s=User::find($user_id); $data=[ 'op_name'=>'公司', 'op_phone'=>'', 'op_id'=>'', 'accept_name'=>$user_s->nickname, 'accept_phone'=>$user_s->mobile, 'accept_id'=>$user_s->id, 'type'=>1, 'select_id'=>$v->id ]; event(new SendGoodLogEvent($data)); } DB::commit(); return 200; }catch (\Exception $exception){ DB::rollBack(); return 300; } } /**代理发货**/ public function user_send_good(Request $request){ DB::beginTransaction(); try{ $user=Auth::user(); $users=User::find($user->id); $re=Select::where('code',$request->code)->first(); if ($re->user_id!=$user->id){ return $this->error(50021,'','当前货物不是您的货物,不能使用此码进行发货'); } //先判断当前二维码能否进行发货 if ($re->is_full==1){ return $this->error(50021,'','当前二维码中的部分货物已经发货,不能使用此码进行发货'); } if ($request->id==$user->id){ return $this->error(50021,'','不能对自己进行发货操作'); } //判断当前二维码的是不是最低级 if ($re->is_lowest==1){ $re->track_status=2; $re->user_id=$request->id; if (!$re->save()){ throw new \Exception('1'); } $user_s=User::find($request->id); $data=[ 'op_name'=>$users->nickname, 'op_phone'=>$users->mobile, 'op_id'=>$users->id, 'accept_name'=>$user_s->nickname, 'accept_phone'=>$user_s->mobile, 'accept_id'=>$user_s->id, 'type'=>0, 'select_id'=>$re->id ]; event(new SendGoodLogEvent($data)); $num=$this->update_full($re->pid); if ($num==300){ return $this->error(50021,'','子码更改信息失败,请重新尝试发货'); } }else{ //中码或者大码进行发货 if ($users->level!=3){//只有代理公司能够进行扫码中码或者大码进行发货 return $this->error(50021,'','当前等级只能使用小码进行发货'); } //子码跟着更改代理信息 $num=$this->user_send_goods($re->sort,$request->id,$user->id); if ($num==300){ throw new \Exception('1'); } } DB::commit(); return $this->success([]); }catch (\Exception $exception){ DB::rollBack(); return $this->error(50024,'','发货失败,请重新尝试'.$exception); } } /**代理发货子码跟着发货**/ public function user_send_goods($pid,$user_id,$id,$type=0){ DB::beginTransaction(); try{ //查找下一级 $data=Select::where('pid',$pid)->get(); //当前货物信息 $re=Select::where('sort','=',$pid)->first(); //中码发货时 if ($type==0){ if ($re->level!=1){ //修改中码所属大码的状态 $num=$this->update_full($re->pid); if ($num==300){ throw new \Exception(1); } } } foreach ($data as $k=>$v){ if ($v->is_lowest!=1){ $num=$this->user_send_goods($v->sort,$user_id,$id); if ($num==300){ throw new \Exception(1); } } $se=Select::find($v->id); $se->track_status=2; $se->user_id=$user_id; if (!$se->save()){ Log::error('走了这里(所属者的改变)'); throw new \Exception('1'); } $users=User::find($id); $user_s=User::find($user_id); $data=[ 'op_name'=>$users->nickname, 'op_phone'=>$users->mobile, 'op_id'=>$users->id, 'accept_name'=>$user_s->nickname, 'accept_phone'=>$user_s->mobile, 'accept_id'=>$user_s->id, 'type'=>0, 'select_id'=>$v->id ]; event(new SendGoodLogEvent($data)); } DB::commit(); return 200; }catch (\Exception $exception){ DB::rollBack(); Log::error($exception); return 300; } } /**小码发货时更改中码和大码**/ public function update_full($pid){ DB::beginTransaction(); try{ $re=Select::where('sort','=',$pid)->first(); $re->is_full=1; if (!$re->save()){ throw new \Exception('1'); } if ($re->level!=1){ $this->update_full($re->pid); } DB::commit(); return 200; }catch (\Exception $exception){ DB::rollBack(); Log::error($exception); return 300; } } /**查询**/ public function get_lower_user(Request $request){ return $this->success_list([]); } /**检查是够已经发货**/ public function is_full($code){ $re=Select::where('code',$code)->first(); if ($re->is_full==1){ return 300; } return 200; } /**代理退货**/ public function user_return_good(Request $request){ $user=Auth::user(); $re=Select::where('code',$request->code)->first(); if ($re){ $res=$this->check_user_level($user->id,$re->user_id); if ($res['code']==200){ return $this->success([]); } } } /**检查用户**/ public function check_user_level($id,$user_id){ if ($id==$user_id){ return ['code'=>50026,'message'=>'你不能对自己的货物进行退货操作']; } return ['code'=>200]; } public function new_send_good(Request $request){ if ($request->id){ return $this->error(50026,'','请选择代理进行发货'); } DB::beginTransaction(); try{ }catch (\Exception $exception){ } } }