芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/bit-alphas-ltd.com/user/project/app/Http/Controllers/Admin/UserController.php
middleware('auth:admin'); } public function datatables() { $datas = User::orderBy('id','desc'); return Datatables::of($datas) ->addColumn('action', function(User $data) { return '
'.'Actions' .'
'.__("Details").'
'.__("Edit").'
'.__("Send").'
'.__("Delete").'
'; }) ->addColumn('status', function(User $data) { $status = $data->is_banned == 1 ? __('Block') : __('Unblock'); $status_sign = $data->is_banned == 1 ? 'danger' : 'success'; return '
'.$status .'
'.__("Unblock").'
'.__("Block").'
'; }) ->rawColumns(['action','status']) ->toJson(); } public function index() { return view('admin.user.index'); } public function image() { return view('admin.generalsetting.user_image'); } public function show($id) { $data = User::findOrFail($id); $data['data'] = $data; return view('admin.user.show',$data); } public function ban($id1,$id2) { $user = User::findOrFail($id1); $user->is_banned = $id2; $user->update(); $msg = 'Data Updated Successfully.'; return response()->json($msg); } public function edit($id) { $data = User::findOrFail($id); return view('admin.user.edit',compact('data')); } public function update(Request $request, $id) { $rules = [ 'photo' => 'mimes:jpeg,jpg,png,svg', ]; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return response()->json(array('errors' => $validator->getMessageBag()->toArray())); } $user = User::findOrFail($id); $data = $request->all(); if ($file = $request->file('photo')) { $name = Str::random(8).time().'.'.$file->getClientOriginalExtension(); $file->move('assets/images',$name); if($user->photo != null) { if (file_exists(public_path().'/assets/images/'.$user->photo)) { unlink(public_path().'/assets/images/'.$user->photo); } } $data['photo'] = $name; } $user->update($data); $msg = 'Customer Information Updated Successfully.'; return response()->json($msg); } public function adddeduct(Request $request){ $user = User::whereId($request->user_id)->first(); if($user){ if($request->type == 'add'){ $user->increment('balance',$request->amount); return redirect()->back()->with('message','User balance added'); }else{ if($user->balance>=$request->amount){ $user->decrement('balance',$request->amount); return redirect()->back()->with('message','User balance deduct!'); }else{ return redirect()->back()->with('warning','User don,t have sufficient balance!'); } } }else{ return redirect()->back()->with('warning','User not found!'); } } public function withdraws(){ return view('admin.user.withdraws'); } public function withdrawdatatables() { $datas = Withdraw::orderBy('id','desc'); return Datatables::of($datas) ->addColumn('email', function(Withdraw $data) { $email = $data->user->email; return $email; }) ->addColumn('phone', function(Withdraw $data) { $phone = $data->user->phone; return $phone; }) ->editColumn('status', function(Withdraw $data) { $status = ucfirst($data->status); return $status; }) ->editColumn('amount', function(Withdraw $data) { $amount = $data->amount; return '$' . $amount; }) ->editColumn('created_at', function(Withdraw $data) { $date = $data->created_at->diffForHumans(); return $date; }) ->addColumn('action', function(Withdraw $data) { if($data->status == "pending") { $action = '
'.__("Accept").'
'.__("Reject").'
'; }else{ $action = ''; } return '
'.'Actions' .'
'.__("Details").'
'.$action.'
'; }) ->rawColumns(['name','email','amount','action']) ->toJson(); } public function withdrawdetails($id) { $withdraw = Withdraw::findOrFail($id); return view('admin.user.withdraw-details',compact('withdraw')); } public function accept($id) { $gs = Generalsetting::first(); $admin = Admin::first(); $withdraw = Withdraw::findOrFail($id); $user = User::findOrFail($withdraw->user->id); $data['status'] = "completed"; $withdraw->update($data); if($gs->is_smtp == 1) { $data = [ 'to' => $user->email, 'type' => "Withdraw", 'cname' => $user->name, 'oamount' => $withdraw->amount + $withdraw->fee, 'aname' => $admin->name, 'aemail' => $admin->email, 'wtitle' => "", ]; $mailer = new GeniusMailer(); $mailer->sendAutoMail($data); } else { $to = $user->email; $subject = " You have invested successfully."; $msg = "Hello ".$user->name."!\nYou have invested successfully.\nThank you."; $headers = "From: ".$gs->from_name."<".$gs->from_email.">"; mail($to,$subject,$msg,$headers); } $msg = __('Withdraw Accepted Successfully.'); return response()->json($msg); } public function reject($id) { $gs = Generalsetting::first(); $admin = Admin::first(); $withdraw = Withdraw::findOrFail($id); $user = User::findOrFail($withdraw->user->id); $user->balance = $user->balance + $withdraw->amount + $withdraw->fee; $trans = new Transaction(); $trans->email = $user->email; $trans->amount = $withdraw->amount + $withdraw->fee; $trans->type = "Payout Rejected"; $trans->profit = "plus"; $trans->txnid = Str::random(12); $trans->user_id = $user->id; $trans->save(); $user->update(); $data['status'] = "rejected"; $withdraw->update($data); if($gs->is_smtp == 1) { $data = [ 'to' => $user->email, 'type' => "Withdraw", 'cname' => $user->name, 'oamount' => $withdraw->amount + $withdraw->fee, 'aname' => $admin->name, 'aemail' => $admin->email, 'wtitle' => "", ]; $mailer = new GeniusMailer(); $mailer->sendAutoMail($data); } else { $to = $user->email; $subject = " You have invested successfully."; $msg = "Hello ".$user->name."!\nYou have invested successfully.\nThank you."; $headers = "From: ".$gs->from_name."<".$gs->from_email.">"; mail($to,$subject,$msg,$headers); } $msg = __('Withdraw Rejected Successfully.'); return response()->json($msg); } public function destroy($id) { $user = User::findOrFail($id); if($user->transactions->count() > 0) { foreach ($user->transactions as $transaction) { $transaction->delete(); } } if($user->withdraws->count() > 0) { foreach ($user->withdraws as $withdraw) { $withdraw->delete(); } } if($user->deposits->count() > 0) { foreach ($user->deposits as $deposit) { $deposit->delete(); } } if($user->balanceTransfers->count() > 0) { foreach ($user->balanceTransfers as $balanceTransfer) { $balanceTransfer->delete(); } } @unlink('/assets/images/'.$user->photo); $user->delete(); $msg = 'Data Deleted Successfully.'; return response()->json($msg); } }