input('page_index',1); $page_size=$request->input('page_size',20); $num=($page_index-1)*$page_size; $search_name=$request->input('search_name'); $express_status=$request->input('express_status')??-1; $status=$request->input('status')??-1; $order_num=$request->input('order_num')??null; $express_num=$request->input('express_num')??null; $tab_num=$request->input('tab_num'); $re=Soap::query(); if (Auth::user()->role_id==23){ $warea_id=Warea::where('admin_id',Auth::user()->id)->value('id'); $re->where('warea_id',$warea_id); } if ($order_num){ $re->where('order_num','like','%'.$order_num.'%'); } if ($tab_num==1){ $re->where('is_pay',0)->where('order_end','>',Carbon::now()); }elseif ($tab_num==2){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',0); }elseif ($tab_num==3){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',1); }elseif ($tab_num==4){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',2); }elseif ($tab_num==5){ $re->where('is_pay',1)->where('is_refund',1); } // if ($express_status>0){ // $re->where('express_status',$express_status); // } if ($express_num){ $re->where('express_num',$express_num); } if($status>0){ $re->where('status',$status); } if ($search_name){ $user_ids=User::where('mobile','like','%'.$search_name.'%')->orwhere('nickname','like',"%$search_name%") ->orwhere('realname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$user_ids); } $count=$re->count(); $data=$re->where('is_deleted',0)->with(['user:mobile,id,nickname,level'])->with(['warea'])->orderByDesc('id')->take($page_size)->skip($num)->get(); return $this->success_list($data,'',$count); } /**导出订单信息***/ public function ExportSoapInfo(Request $request){ $search_name=$request->input('search_name'); $express_status=$request->input('express_status')??-1; $order_num=$request->input('order_num')??null; $express_num=$request->input('express_num')??null; $tab_num=$request->input('tab_num')??null; $id_all=$request->input('id_arr',[]); $re=Soap::query(); if (Auth::user()->role_id==23){ $warea_id=Warea::where('admin_id',Auth::user()->id)->value('id'); $re->where('warea_id',$warea_id); } if ($id_all){ $data=$re->whereIn('id',$id_all)->with(['user:mobile,id,nickname,level'])->orderByDesc('id')->get(); return $this->success($data); } if ($order_num){ $re->where('order_num','like','%'.$order_num.'%'); } if ($tab_num==1){ $re->where('is_pay',0)->whereNull('is_refund')->where('order_end','>',Carbon::now()); }elseif ($tab_num==2){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',0); }elseif ($tab_num==3){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',1); }elseif ($tab_num==4){ $re->where('is_pay',1)->whereNull('is_refund')->where('express_status',2); } // if ($express_status>0){ // $re->where('express_status',$express_status); // } if ($express_num){ $re->where('express_num',$express_num); } if ($search_name){ $user_ids=User::where('mobile','like','%'.$search_name.'%')->orwhere('nickname','like',"%$search_name%") ->orwhere('realname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$user_ids); } $data=$re->where('status',1)->where('is_deleted',0)->with(['user:mobile,id,nickname,level'])->orderByDesc('id')->get(); return $this->success($data); } /**政委审核*/ public function UpdateStatus(Request $request){ $status=$request->input('status'); if ($status==0){ $id=[$request->input('id')]; }else{ $id=$request->input('id'); } $re=Soap::whereIn('id',$id)->update(['status'=>$request->input('status')]); return $this->success([]); } public function UpdateAllStatus(Request $request){ Soap::where('is_pay',1)->update(['status'=>1]); return $this->success([]); } /* * 修改信息 * ***/ public function UpdateInfo(Request $request){ $re=Soap::find($request->input('id')); $re->province=$request->input('province'); $re->city=$request->input('city'); $re->area=$request->input('area'); $re->address=$request->input('address'); $re->user_name=$request->input('user_name'); $re->mobile=$request->input('mobile'); $re->save(); return $this->success([]); } /* *快递公司简称 */ public function GetExpressInfo(){ $express_name=['顺丰速运', '百世快递', '中通快递', '申通快递', '圆通速递', '韵达速递', '邮政快递包裹', 'EMS', '京东快递', '优速快递', '德邦快递', '极兔速递', '众邮快递', '宅急送']; $express_code=['SF', 'HTKY', 'ZTO', 'STO', 'YTO', 'YD', 'YZPY', 'EMS', 'JD', 'UC', 'DBL', 'JTSD', 'ZYE', 'ZJS']; $data=[]; foreach ($express_name as $k=>$v){ $data[$express_code[$k]]=$v; } return $this->success($data); } /**上传单个物流信息**/ public function Express(Request $request){ $re=Soap::find($request->input('id')); $re->express_num=$request->input('express_num'); $re->express_status=1; $re->express_company=$request->input('express_company'); $re->express_code=$request->input('express_code'); $data=[ 'mobile'=>$re->mobile, 'express_com'=>$re->express_company, 'express_num'=>$re->express_num, 'status'=>0 ]; event(new SoapSendSmsEvent($data)); $re->save(); return $this->success([]); } /**上传物流**/ public function UploadExpress(Request $request){ $file = $request->file('file'); if ( !$file->isValid()) { //判断文件是否有效 return redirect() ->back() ->withErrors('文件上传失败,请重新上传'); } $array = Excel::toArray(new ExpressImport, request()->file('file')); if(count($array)>5001){ return $this->error('450001',"单次最多导入5000条数据"); } $one = array_shift($array[0]); $express_num_keys=array_search('快递单号',$one); if(!$express_num_keys && !is_numeric($express_num_keys)){ return $this->error('450001',"表头无'快递单号'字段"); } $order_num_keys=array_search('订单号',$one); if(!$order_num_keys && !is_numeric($order_num_keys)){ return $this->error('450001',"表头无'快递单号'字段"); } $express_com_keys=array_search('快递公司',$one); if(!$express_com_keys){ return $this->error('450001',"表头无'快递公司'字段"); } $express_code_keys=array_search('快递公司代码',$one); if(!$express_code_keys){ return $this->error('450001',"表头无'快递公司代码'字段"); } $arr=$array[0]; $express_nums=array_column($arr,$express_num_keys); $unique_express_nums=array_unique($express_nums); $que_express_nums=array_diff_assoc($express_nums,$unique_express_nums); if(count($que_express_nums)>0){ $que_express_str=implode(',',$que_express_nums); return $this->error('450001','快递单号'.$que_express_str.'重复出现'); } $new_arr=[]; $new_arrs=[]; $z=0; foreach ($array[0] as $k=>$v){ $st=''; if ($v[$express_com_keys]=='中通快递'){ $patterns = "/\d+/"; preg_match_all($patterns,$v[$express_num_keys],$aa); foreach ($aa[0] as $kee=>$vaa){ $st.=$vaa; } $new_arr[$z]=$st; }else{ $new_arr[$z]=$v[$express_num_keys]; } $new_arrs[$z]=$v[$order_num_keys]; $z++; } $res=Soap::whereIn('express_num',$new_arr)->pluck('express_num')->toArray(); if (count($res)>0){ $ar_r=array_intersect($new_arr,$res); $que_express_str=implode(',',$ar_r); return $this->error('450001','快递单号:'.$que_express_str.'已经上传',$ar_r); } $order_arr=Soap::whereIn('order_num',$new_arrs)->whereNotNull('express_num')->pluck('order_num')->toArray(); if ($order_arr){ return $this->error(500214,implode(',',$order_arr).'已经上传过快递单号,请核实数据'); } DB::beginTransaction(); try { foreach ($arr as $k=>$v){ $order_num=$v[$order_num_keys]; $order_info=Soap::where('order_num',$order_num)->first(); if (!$order_info){ return $this->error(20014,'申请单号:'.$order_num.'不存在'); } $st=''; if ($v[$express_com_keys]=='中通快递'){ $patterns = "/\d+/"; preg_match_all($patterns,$v[$express_num_keys],$aa); foreach ($aa[0] as $kee=>$vaa){ $st.=$vaa; } $order_info->express_num=$st; }else{ $order_info->express_num=$v[$express_num_keys]; } $order_info->express_company=$v[$express_com_keys]; $order_info->express_code=$v[$express_code_keys]; $order_info->express_time=Carbon::now(); $order_info->express_status=1; if (!$order_info->save()){ throw new \Exception(1); } } DB::commit(); /**发送 快递信息*/ foreach ($arr as $k=>$v){ $apply_info=Soap::where('order_num',$v[$order_num_keys])->first(); $data=[ 'mobile'=>$apply_info->mobile, 'express_com'=>$apply_info->express_company, 'express_num'=>$apply_info->express_num, 'status'=>0 ]; event(new SoapSendSmsEvent($data)); } return $this->success([]); }catch (\Exception $exception){ DB::rollBack(); return $this->error(500214,$exception->getMessage()); } } /**获取物流轨迹**/ public function ExpressSearch(Request $request,ExpressHandler $expressHandler){ $express=Soap::find($request->id); if (!$express){ return $this->error(40011,'','该物流订单不存在'); } if ($express->express_status==2){ return $this->success(json_decode($express->express_info)); }else{ $re=$expressHandler->search($express->express_num,$express->express_code); $re=(array)$re; if ($re['State']==3){ DB::beginTransaction(); try{ $express->express_info=json_encode($re); $express->express_status=2; $express->save(); DB::commit(); }catch (\Exception $exception){ Log::error('-------物流信息保存出错--------'.$exception); DB::rollBack(); } } return $this->success($re); } } /* * 获取各个数量 * **/ public function GetTabNum(){ $total=Soap::where('is_deleted',0)->count(); $total_1=Soap::where('is_deleted',0)->whereNull('is_refund')->where('is_pay',0)->where('order_end','>',Carbon::now())->count(); $total_2=Soap::where('is_deleted',0)->whereNull('is_refund')->where('is_pay',1)->where('express_status',0)->count(); $total_3=Soap::where('is_deleted',0)->where('is_pay',1)->whereNull('is_refund')->where('express_status',1)->count(); $total_4=Soap::where('is_deleted',0)->where('is_pay',1)->whereNull('is_refund')->where('express_status',2)->count(); return $this->success(['all'=>$total,'no_pay'=>$total_1,'no_send'=>$total_2,'no_complete'=>$total_3,'end'=>$total_4]); } /**修改物流**/ public function UpdateSoapExpressInfo(Request $request){ $file = $request->file('file'); if ( !$file->isValid()) { //判断文件是否有效 return redirect() ->back() ->withErrors('文件上传失败,请重新上传'); } $array = Excel::toArray(new ExpressImport, request()->file('file')); if(count($array)>5001){ return $this->error('450001',"单次最多导入5000条数据"); } $one = array_shift($array[0]); $express_num_keys=array_search('旧快递单号',$one); if(!$express_num_keys && !is_numeric($express_num_keys)){ return $this->error('450001',"表头无'旧快递单号'字段"); } $new_express_num_keys=array_search('新快递单号',$one); if(!$express_num_keys && !is_numeric($express_num_keys)){ return $this->error('450001',"表头无'新快递单号'字段"); } $express_com_keys=array_search('快递公司',$one); if(!$express_com_keys){ return $this->error('450001',"表头无'快递公司'字段"); } $express_code_keys=array_search('快递公司代码',$one); if(!$express_code_keys){ return $this->error('450001',"表头无'快递公司代码'字段"); } $arr=$array[0]; $express_nums=array_column($arr,$express_num_keys); $unique_express_nums=array_unique($express_nums); $que_express_nums=array_diff_assoc($express_nums,$unique_express_nums); if(count($que_express_nums)>0){ $que_express_str=implode(',',$que_express_nums); return $this->error('450001','快递单号'.$que_express_str.'重复出现'); } DB::beginTransaction(); try { foreach ($arr as $k=>$v){ $apply_info=Soap::where('express_num',$v[$express_num_keys])->first(); if (!$apply_info){ return $this->error(20014,'申请单号:'.$v[$express_num_keys].'不存在'); } $st=''; if ($v[$express_com_keys]=='中通快递'){ $patterns = "/\d+/"; preg_match_all($patterns,$v[$new_express_num_keys],$aa); foreach ($aa[0] as $kee=>$vaa){ $st.=$vaa; } $apply_info->express_num=$st; }else{ $apply_info->express_num=$v[$new_express_num_keys]; } $apply_info->express_company=$v[$express_com_keys]; $apply_info->express_code=$v[$express_code_keys]; $apply_info->express_time=Carbon::now(); $apply_info->express_status=1; if (!$apply_info->save()){ throw new \Exception(1); } } DB::commit(); // /**发送 快递信息*/ // foreach ($arr as $k=>$v){ // $apply_info=Soap::where('express_num',$v[$new_express_num_keys])->first(); // $data=[ // 'mobile'=>$apply_info->customer_phone, // 'express_com'=>$apply_info->express_com, // 'express_num'=>$apply_info->express_num, // 'status'=>1, // 'old_express_num'=>$v[$express_num_keys] // ]; // try { // event(new CustomerSendSmsEvent($data)); // }catch (\Exception $exception){ // // } // } return $this->success([]); }catch (\Exception $exception){ DB::rollBack(); return $this->error(500214,$exception->getMessage()); } } /* * 点击退款 * **/ public function Refund(Request $request){ $re=Soap::find($request->input('id')); if ($re){ $options=$this->options(); $payment=Factory::payment($options); $number=time().$re->user_id.random_int(11111,99999); // 参数分别为:商户订单号、商户退款单号、订单金额、退款金额、其他参数 $result = $payment->refund->byOutTradeNumber($re->enroll_no, $number, $re->cost*100, $re->cost*100, [ // 可在此处传入其他参数,详细参数见微信支付文档 'refund_desc' => $request->input('refund_desc'), 'notify_url'=>'https://api.admin.app.jiuweiyun.cn/api/soap/RefoundMessage' ]); $re->refund_cause=$request->input('refund_desc'); $re->op_name=Auth::user()->name; $re->is_refund=1; $re->save(); } return $this->success([]); } public function RefundMessage(Request $request){ $options = $this->options(); $payment = Factory::payment($options); $response = $payment->handleRefundedNotify(function ($message, $reqInfo, $fail){ $out_trade_no = $reqInfo['out_trade_no']; // 商户订单号 $out_refund_no = $reqInfo['out_refund_no']; // 微信支付退款订单号 $order = Soap::where('enroll_no', '=', $out_trade_no)->first(); if (empty($order)) { return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了 } if ($message['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态 // 用户是否支付成功 if ($reqInfo['refund_status'] === 'SUCCESS') { $enroll = Soap::where('enroll_no', '=', $out_trade_no)->first(); $enroll->is_refund = 1; $enroll->refund_num = $out_refund_no; $enroll->refund_time = Carbon::now()->toDateTimeString(); $enroll->save(); } } else { return $fail('通信失败,请稍后再通知我'); } return true; }); return $response; } protected function options(){ return [ 'app_id' => config('wechat.payment.daweiboshi.app_id'),//config('wechat.payment.default.app_id'), 'mch_id' => config('wechat.payment.daweiboshi.mch_id'), 'sub_mch_id' => '', 'key' => config('wechat.payment.daweiboshi.key'), 'notify_url' =>'', // 'notify_url' =>url('api/pay/message'), 'cert_path' =>config('wechat.payment.daweiboshi.cert_path'), 'key_path' =>config('wechat.payment.daweiboshi.key_path'), ]; } }