get(); foreach ($data as $k=>$v){ $re[$k]['nickname']=$v->nickanme.'--'.$v->mobile; $re[$k]['id']=$v->id; } return $this->success_list($re); } /* * 充值 * */ public function add_money(Request $request){ $input=$request->all(); foreach ($input['mobile'] as $k=>$v){ $user=User::where('mobile',$v)->first(); if (!$user){ return $this->error(40013,'用户'.$v.'不存在'); } } DB::beginTransaction(); try{ foreach ($input['mobile'] as $k=>$v){ $user=User::where('mobile',$v)->first(); $user->money=$user->money+$input['money'][$k]; if (!$user->save()){ Log::error('充值失败'.$v); throw new \Exception('1'); } $userpay=new Userpay(); $userpay->pay_money=$input['money'][$k]; $userpay->type=0; $userpay->op_name=Auth::user()->name; $userpay->user_id=$user->id; $userpay->pay_num=$this->pay_num($user->id); if (!$userpay->save()){ throw new \Exception('3'); } DB::commit(); return $this->success([],'充值完成'); } }catch (\Exception $exception){ DB::rollBack(); return $this->error(40013,'充值失败,出错用户手机号为'.$v); } } /* * */ public function pay_num($id){ $num=date('Ymd',time()).'100000'.str_pad($id,6,0,STR_PAD_LEFT).rand(11111,99999); $count=UserPay::where('pay_num',$num)->count(); if ($count>0){ $num=$this->pay_num($id); return $num; } return $num; } /* * 搜索 * */ public function search(Request $request){ // if ($request->start==null || $request->end==null){ // $where_time=null; // }else{ //// $where_time= // } $user=User::where('mobile',$request->mobile)->first(); if ($user){ return $this->error(40013,'查无此人'); } $userpay=Userpay::where('user_id',$user->id)->orderByDesc('created_at')->paginate(15); return $this->success_list($userpay->items(),'',$userpay->total()); } /* * 代理账户金额 * */ public function user_account(Request $request){ $user=User::where('level',3)->paginate(15); return $this->success_list($user->items(),'',$user->total()); } /* * 详情 * */ public function user_pay_log(Request $request){ $userpay=Userpay::where('user_id',$request->id)->orderByDesc('created_at')->paginate(15); return $this->success_list($userpay->items(),'',$userpay->total()); } /** 作废**/ public function UserPayCancel(Request $request){ $id=$request->id; $ids=[$id]; $userPayLog=Userpay::find($id); $user_id=$userPayLog->user_id; $re=Userpay::where('user_id',$user_id)->where('id','<',$id)->orderByDesc('id')->limit(1)->first(); $user_money=$re->user_money; $user=User::where('id',$user_id)->first(); $pay_chongzhi=Userpay::where('user_id',$user_id)->where('id','>',$id)->whereIn('type',[0,2,3])->first(); if ($pay_chongzhi){ return $this->error(50241,'该记录后面存在充值(扣款、退回)记录,请联系开发人员'); // Log::error('该记录后面存在充值(扣款、退回)记录,请联系开发人员'); // exit(); } DB::beginTransaction(); try{ $orderPayLog=Userpay::where('user_id',$user_id)->where('id','>',$id)->where('type',1)->get(); foreach ($orderPayLog as $k=>$v){ $order=Ordertest::where('order_num',$v->order_num)->first(); $pay_money=$v->pay_money; if ($order->wait_back_money!=0){ return $this->error(50214,'订单编号为:'.$v->order_num.'有待退款'); // Log::error('订单编号为:'.$v->order_num.'有待退款'); // exit(); } $order->pay_money-=$pay_money; if ($order->pay_money>0){ $order->pay_status=1; }elseif ($order->pay_money==0){ $order->pay_status=0; }else{ return $this->error(50214,'订单编号为:'.$v->order_num.'金额出错'); // Log::error('订单编号为:'.$v->order_num.'金额出错'); // exit(); } $order->no_pay_money=$order->money-$order->pay_money; if (!$order->save()){ throw new \Exception(1); } $order->save(); array_push($ids,$v->id); } $user->money=$user_money; if (!$user->save()){ throw new \Exception(1); } Userpay::whereIn('id',$ids)->delete(); DB::commit(); return $this->success([]); }catch (\Exception $exception){ DB::rollBack(); return $this->error(500214,$exception->getMessage()); } } }