芝麻web文件管理V1.00
编辑当前文件:/home/unicorntechnolog/public_html/mt5-ctrader/app/Http/Controllers/admin/DashboardController.php
middleware('admin'); $this->currentcontroller = Route::currentRouteName(); View::share('title',ucfirst($this->currentcontroller)); } public function index() { if(Auth::guard('admin')->user()->isadmin == '0'){ $managerclientlist = ManagerClient::select('groupname')->where('managerid',Auth::guard('admin')->user()->id)->pluck('groupname')->toArray(); $allowuserid = Mt5UserList::select('userid')->WhereIn('groupname',$managerclientlist)->groupBy('userid')->pluck('userid')->toArray(); $totalclients = User::whereIn('id',$allowuserid)->where('type','1')->where('is_ib','!=','2')->count(); $totalib = User::whereIn('id',$allowuserid)->where('type','1')->where('is_ib','=','2')->count(); $pendingdocuments = Documents::select('userid')->whereIn('userid',$allowuserid)->where('status','0')->groupBy('userid')->pluck('userid')->toArray(); $pendingclients = User::where('type','1')->whereIn('id',$pendingdocuments)->count(); $pendingdeposit = Deposit::whereIn('userid',$allowuserid)->where('displaystatus','1')->where('status','0')->count(); $pendingwithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','0')->count(); $pendingibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','0')->count(); $pendingbankdetails = BankDetails::whereIn('userid',$allowuserid)->where('status','0')->count(); $pendingibrequest = User::whereIn('id',$allowuserid)->where('is_ib','1')->count(); $latestclients = User::whereIn('id',$allowuserid)->where('type','1')->orderBy('id','desc')->take(18)->get(); $from = date('Y-m-d',strtotime('-6 days')); $to = date('Y-m-d'); $dailydeposit = Deposit::whereIn('userid',$allowuserid)->where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklydeposit = Deposit::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at', [$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlydeposit = Deposit::whereIn('userid',$allowuserid)->where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totaldeposit = Deposit::whereIn('userid',$allowuserid)->where('status','1')->sum('amount'); $ftduserslistarry = Deposit::select('userid')->whereIn('userid',$allowuserid)->where('status','1')->groupBy('userid')->pluck('userid')->toArray(); $ftduserslist = count($ftduserslistarry); $nonftdusers = User::whereIn('id',$allowuserid)->whereNotIn('id',$ftduserslistarry)->count(); $dailywithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklywithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at',[$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlywithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totalwithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','1')->sum('amount'); $dailyibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklyibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at',[$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlyibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totalibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','1')->sum('amount'); $last7daydeposit = Deposit::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartdepositdata = array_map(function ($datePeriod) use ($last7daydeposit) { $date = $datePeriod->format('Y-m-d'); return $last7daydeposit->has($date) ? $last7daydeposit->get($date)->totalamount : 0; }, iterator_to_array($period)); $last7daywithdraw = Withdraw::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period1 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartwithdrawdata = array_map(function ($datePeriod1) use ($last7daywithdraw) { $date1 = $datePeriod1->format('Y-m-d'); return $last7daywithdraw->has($date1) ? $last7daywithdraw->get($date1)->totalamount : 0; }, iterator_to_array($period1)); $last7dayibwithdraw = Ibwithdraw::whereIn('userid',$allowuserid)->where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period2 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartibwithdrawdata = array_map(function ($datePeriod2) use ($last7dayibwithdraw) { $date2 = $datePeriod2->format('Y-m-d'); return $last7dayibwithdraw->has($date2) ? $last7dayibwithdraw->get($date2)->totalamount : 0; }, iterator_to_array($period2)); $last7dayclients = User::whereIn('id',$allowuserid)->where('type','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('count(*) as totalclients') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period3 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartclientsdata = array_map(function ($datePeriod3) use ($last7dayclients) { $date3 = $datePeriod3->format('Y-m-d'); return $last7dayclients->has($date3) ? $last7dayclients->get($date3)->totalclients : 0; }, iterator_to_array($period3)); $days = []; for ($i = 6; $i >= 0; $i--) { $days[] = now()->subDays($i)->format('Y-m-d'); } } else{ $totalclients = User::where('type','1')->where('is_ib','!=','2')->count(); $totalib = User::where('type','1')->where('is_ib','=','2')->count(); $pendingdocuments = Documents::select('userid')->where('status','0')->groupBy('userid')->pluck('userid')->toArray(); $pendingclients = User::where('type','1')->whereIn('id',$pendingdocuments)->count(); $pendingdeposit = Deposit::where('displaystatus','1')->where('status','0')->count(); $pendingwithdraw = Withdraw::where('status','0')->count(); $pendingibwithdraw = Ibwithdraw::where('status','0')->count(); $pendingbankdetails = BankDetails::where('status','0')->count(); $pendingibrequest = User::where('is_ib','1')->count(); $latestclients = User::where('type','1')->orderBy('id','desc')->take(18)->get(); $from = date('Y-m-d',strtotime('-6 days')); $to = date('Y-m-d'); $dailydeposit = Deposit::where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklydeposit = Deposit::where('status','1')->whereBetween('created_at', [$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlydeposit = Deposit::where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totaldeposit = Deposit::where('status','1')->sum('amount'); // dd($ftduserslist); $ftduserslistarry = Deposit::select('userid')->where('status','1')->groupBy('userid')->pluck('userid')->toArray(); $ftduserslist = count($ftduserslistarry); // dd($ftduserslistarry); $nonftdusers = User::whereNotIn('id',$ftduserslistarry)->count(); // dd($nonftdusers); $dailywithdraw = Withdraw::where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklywithdraw = Withdraw::where('status','1')->whereBetween('created_at',[$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlywithdraw = Withdraw::where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totalwithdraw = Withdraw::where('status','1')->sum('amount'); $dailyibwithdraw = Ibwithdraw::where('status','1')->whereDate('created_at',date('Y-m-d'))->sum('amount'); $weeklyibwithdraw = Ibwithdraw::where('status','1')->whereBetween('created_at',[$from, $to.' 23:59:59'])->whereMonth('created_at',date('m'))->sum('amount'); $monthlyibwithdraw = Ibwithdraw::where('status','1')->whereMonth('created_at',date('m'))->whereYear('created_at', date('Y'))->sum('amount'); $totalibwithdraw = Ibwithdraw::where('status','1')->sum('amount'); $last7daydeposit = Deposit::where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartdepositdata = array_map(function ($datePeriod) use ($last7daydeposit) { $date = $datePeriod->format('Y-m-d'); return $last7daydeposit->has($date) ? $last7daydeposit->get($date)->totalamount : 0; }, iterator_to_array($period)); $last7daywithdraw = Withdraw::where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period1 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartwithdrawdata = array_map(function ($datePeriod1) use ($last7daywithdraw) { $date1 = $datePeriod1->format('Y-m-d'); return $last7daywithdraw->has($date1) ? $last7daywithdraw->get($date1)->totalamount : 0; }, iterator_to_array($period1)); $last7dayibwithdraw = Ibwithdraw::where('status','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('sum(amount) as totalamount') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period2 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartibwithdrawdata = array_map(function ($datePeriod2) use ($last7dayibwithdraw) { $date2 = $datePeriod2->format('Y-m-d'); return $last7dayibwithdraw->has($date2) ? $last7dayibwithdraw->get($date2)->totalamount : 0; }, iterator_to_array($period2)); $last7dayclients = User::where('type','1')->whereBetween('created_at', [Carbon::now()->subDays(6)->format('Y-m-d')." 00:00:00", Carbon::now()->format('Y-m-d')." 23:59:59"]) ->groupBy('date')->orderBy('date') ->get([ DB::raw('DATE_FORMAT(created_at, "%Y-%m-%d") as date'), DB::raw('count(*) as totalclients') ])->keyBy('date') ->map(function ($item) { $item->date = Carbon::parse($item->date); return $item; }); $period3 = new DatePeriod(Carbon::now()->subDays(6), CarbonInterval::day(), Carbon::now()->addDay()); $chartclientsdata = array_map(function ($datePeriod3) use ($last7dayclients) { $date3 = $datePeriod3->format('Y-m-d'); return $last7dayclients->has($date3) ? $last7dayclients->get($date3)->totalclients : 0; }, iterator_to_array($period3)); $days = []; for ($i = 6; $i >= 0; $i--) { $days[] = now()->subDays($i)->format('Y-m-d'); } } $title = "Dashboard"; return view('admin.dashboard')->with(compact('title','pendingbankdetails','pendingibrequest','ftduserslist','nonftdusers','totalclients','totalib','pendingclients','pendingdeposit','pendingwithdraw','pendingibwithdraw','latestclients','dailydeposit','weeklydeposit','monthlydeposit','totaldeposit','dailywithdraw','weeklywithdraw','monthlywithdraw','totalwithdraw','dailyibwithdraw','weeklyibwithdraw','monthlyibwithdraw','totalibwithdraw','days','chartdepositdata','chartwithdrawdata','chartibwithdrawdata','chartclientsdata')); } public function readnotification($id) { Auth::guard('admin')->user() ->unreadNotifications ->where('id', $id) ->markAsRead(); return redirect()->back(); } public function readnotificationall() { foreach (Auth::guard('admin')->user()->unreadNotifications as $notification) { $notification->markAsRead(); } return redirect()->back(); } public function unreadnotificationlist() { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','unread_notification')->first(); if(empty($permissionlist)){ return abort(403); } else{ $notifications = Auth::guard('admin')->user()->unreadNotifications; $title = 'New Notification'; return view('admin.notification.unreadnotificationlist')->with(compact('title','notifications')); } } public function readnotificationlist() { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','read_notification')->first(); if(empty($permissionlist)){ return abort(403); } else{ $notifications = Auth::guard('admin')->user()->readNotifications; $title = 'New Notification'; return view('admin.notification.readnotificationlist')->with(compact('title','notifications')); } } public function changeadminpassword() { $title = 'Change Password'; return view('admin.changeadminpassword')->with(compact('title')); } public function changeadminpasswordstore(Request $request) { $messages = [ 'current_password.required' => 'The Current Password field is required.', 'new_password.required' => 'The New Password field is required.', 'new_password.min' => 'The New Password must be at least 6 characters.', 'new_password.confirmed' => 'The New Password and Confirm Password does not match.' ]; $request->validate([ 'current_password' => 'required', 'new_password' => 'required|min:6|confirmed', ],$messages); $admindata = Admin::find(Auth::guard('admin')->user()->id); if(!Hash::check($request->get('current_password'),$admindata->password)){ $request->session()->flash('alert-danger','Please enter valid current password.'); return redirect()->back(); } $serializeArray = array(); $serializeArray['id'] = $admindata->id; $serializeArray['name'] = $admindata->name; $serializeArray['email'] = $admindata->email; $serializeArray['mpassword'] = $admindata->mpassword; $admindata->password = Hash::make($request->get('new_password')); $admindata->mpassword = base64_encode($request->get('new_password')); if($admindata->save()){ AdminActivity::create([ 'type' => 'change_admin_password', 'data' => serialize($serializeArray), 'adminid' => Auth::guard('admin')->user()->id, 'ip_address' => \Illuminate\Support\Facades\Request::ip(), ]); $request->session()->flash('alert-success','Password changes successfully.'); } return redirect()->back(); } public function sendemail() { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','send_email')->first(); if(empty($permissionlist)){ return abort(403); } else{ $title = 'Send Email'; $grouplist = Group::get(); return view('admin.sendemail')->with(compact('title','grouplist')); } } public function sendemailstore(Request $request){ // dd($request->all()); $request->validate([ 'sentto' => 'required', 'selectedusers' => 'required_if:sentto,selectedusers', 'selectedgroups' => 'required_if:sentto,selectedgroups', 'subject' => 'required', 'body' => 'required', ]); $subject = $request->subject; $content = $request->body; if($request->sentto == 'all'){ if(Auth::guard('admin')->user()->isadmin == '0'){ $managerclientlist = ManagerClient::select('groupname')->where('managerid',Auth::guard('admin')->user()->id)->pluck('groupname')->toArray(); $allowuserid = Mt5UserList::select('userid')->WhereIn('groupname',$managerclientlist)->groupBy('userid')->pluck('userid')->toArray(); $emails = User::select('email')->whereIn('id',$allowuserid)->where('status','=','1')->pluck('email')->all(); } else{ $emails = User::where('type','1')->select('email')->where('status','=','1')->pluck('email')->all(); } }elseif($request->sentto == 'selectedusers'){ $emails = $request->selectedusers; } elseif($request->sentto == 'selectgroup'){ $checkmt5 = Mt5UserList::select('userid')->where('groupname',$request->selectedgroups)->groupBy('userid')->pluck('userid')->toArray(); $emails = User::select('email')->whereIn('id',$checkmt5)->where('status','=','1')->pluck('email')->all(); } \Mail::send('email.dynamictemplate', ['content' => $content], function ($message) use ($subject,$emails){ $message->from(env('FROM_MAIL'),env('APP_NAME')); $message->to(env('SHOW_MAIL')); $message->bcc($emails); $message->subject($subject); }); $request->session()->flash('alert-success', 'You have successfully sent an email'); return redirect()->back(); } public function newslist() { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','news_list')->first(); if(empty($permissionlist)){ return abort(403); } else{ $title = 'News'; $newslists = News::get(); return view('admin.news.newslist')->with(compact('title','newslists')); } } public function addnews() { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','add_news')->first(); if(empty($permissionlist)){ return abort(403); } else{ $title = 'Add News'; return view('admin.news.addnews')->with(compact('title')); } } public function newsstore(Request $request){ $request->validate([ 'title' => 'required|max:250', 'description' => 'required', 'short_description' => 'required|max:250', 'filename' => 'required|mimes:jpeg,png,jpg,JPEG,PNG,JPG', 'status' => 'required', 'trending' => 'required', ]); $allowed = array('jpeg','jpg','png','JPEG','JPG','PNG'); if(!empty($request->filename)){ $filename = $request->file('filename'); $extensionfilename = $filename->getClientOriginalExtension(); if(!in_array($extensionfilename,$allowed)){ return redirect()->back()->with('alert-danger','Only file type png, jpg, jpeg allowed'); } $filenameImg = time().'_1.'.$filename->getClientOriginalExtension(); $path = public_path() . '/images/news/'; File::makeDirectory($path, $mode = 0777, true, true); $filename->move($path, $filenameImg); } $mydata = array(); $mydata['title'] = $request->title; $mydata['description'] = $request->description; $mydata['short_description'] = $request->short_description; $mydata['status'] = $request->status; $mydata['trending'] = $request->trending; $mydata['filename'] = $filenameImg; $mydata['adminid'] = Auth::guard('admin')->user()->id; if(News::create($mydata)) { $request->session()->flash('alert-success', 'News created successfully.'); } return redirect('/admin/news/newslist'); } public function editnews($id) { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','edit_news')->first(); if(empty($permissionlist)){ return abort(403); } else{ $title = 'Edit News'; $newsdata = News::find($id); return view('admin.news.editnews')->with(compact('title','newsdata')); } } public function newsupdate(Request $request){ $request->validate([ 'title' => 'required|max:250', 'description' => 'required', 'short_description' => 'required|max:250', 'status' => 'required', 'trending' => 'required', ]); $newsdata = News::find($request['id']); $allowed = array('jpeg','jpg','png','JPEG','JPG','PNG'); if(!empty($request->filename)){ $filename = $request->file('filename'); $extensionfilename = $filename->getClientOriginalExtension(); if(!in_array($extensionfilename,$allowed)){ return redirect()->back()->with('alert-danger','Only file type png, jpg, jpeg allowed'); } $filenameImg = time().'_1.'.$filename->getClientOriginalExtension(); $path = public_path() . '/images/news/'; File::makeDirectory($path, $mode = 0777, true, true); $filename->move($path, $filenameImg); }else{ $filenameImg = $newsdata->filename; } $newsdata->title = $request['title']; $newsdata->description = $request['description']; $newsdata->short_description = $request['short_description']; $newsdata->status = $request['status']; $newsdata->trending = $request['trending']; $newsdata->filename = $filenameImg; $newsdata->adminid = Auth::guard('admin')->user()->id; if($newsdata->update()) { $request->session()->flash('alert-success', 'News update successfully.'); } return redirect('/admin/news/newslist'); } public function newsdelete(Request $request,$id) { $permissionlist = AdminPermission::where('adminid',Auth::guard('admin')->user()->id)->where('permissionname','delete_news')->first(); if(empty($permissionlist)){ return abort(403); } else{ $newsdata = News::find($id); if(empty($newsdata)) { $request->session()->flash('alert-danger', trans('Some problem occured in delete news details.')); return redirect()->back(); } News::where('id', $id)->delete(); $request->session()->flash('alert-success', trans('News deleted successfully.')); return redirect()->back(); } } public function darktheme() { Admin::where('id', Auth::guard('admin')->user()->id)->update(array( 'theme' => 'dark' )); return redirect()->back(); } public function lighttheme() { Admin::where('id', Auth::guard('admin')->user()->id)->update(array( 'theme' => 'light' )); return redirect()->back(); } public function managementreport(Request $request) { if(Auth::guard('admin')->user()->main == '1'){ $title = 'Management Report'; if($request->todate != null || $request->fromdate != null){ $todate = date('Y-m-d',strtotime($request->todate.' 23:59:59')); $fromdate = date('Y-m-d',strtotime($request->fromdate)); } else{ $todate = date('Y-m-d'); $fromdate = date('Y-m-d', strtotime($todate. '-7 days')); } if(!empty($request->country) || !empty($request->marketingid)){ if(!empty($request->country) && !empty($request->marketingid)){ $useridarray = User::select('id')->where('status','1')->where('country',$request->country)->where('marketingid',$request->marketingid)->pluck('id')->toArray(); $countryselected = $request->country; $marketingselected = $request->marketingid; } elseif(!empty($request->country)){ $useridarray = User::select('id')->where('status','1')->where('country',$request->country)->pluck('id')->toArray(); $countryselected = $request->country; $marketingselected = ''; } elseif(!empty($request->marketingid)){ $useridarray = User::select('id')->where('status','1')->where('marketingid',$request->marketingid)->pluck('id')->toArray(); $countryselected = ''; $marketingselected = $request->marketingid; } } else{ $countryselected = ''; $marketingselected = ''; $useridarray = User::select('id')->where('status','1')->pluck('id')->toArray(); } $countrylists = User::select('country')->where('status','1')->groupBy('country')->pluck('country')->toArray(); $marketinglists = Marketing::get(); $totaldeposit = Deposit::where('status','1')->whereIn('userid',$useridarray)->whereBetween('created_at', [$fromdate,$todate.' 23:59:59'])->sum('amount'); $totalwithdraw = Withdraw::where('status','1')->whereIn('userid',$useridarray)->whereBetween('created_at', [$fromdate,$todate.' 23:59:59'])->sum('amount'); $netdeposit = $totaldeposit - $totalwithdraw; $depositchart = User::select('users.country', DB::raw('SUM(deposit.amount) as total_deposit')) ->join('deposit', 'users.id', '=', 'deposit.userid') ->where('deposit.status','1') ->whereIn('users.id',$useridarray) ->whereBetween('deposit.created_at', [$fromdate,$todate.' 23:59:59']) ->groupBy('users.country') ->get(); $depositsum = Deposit::join('users','users.id','=','deposit.userid')->groupBy('users.marketingid')->where('deposit.status','1')->whereIn('deposit.userid',$useridarray)->whereBetween('deposit.created_at', [$fromdate,$todate.' 23:59:59'])->select("deposit.userid","users.marketingid", DB::raw('SUM(deposit.amount) AS totaldeposit')); $withdrawsum = Withdraw::join('users','users.id','=','withdraw.userid')->groupBy('users.marketingid')->where('withdraw.status','1')->whereIn('withdraw.userid',$useridarray)->whereBetween('withdraw.created_at', [$fromdate,$todate.' 23:59:59'])->select("withdraw.userid","users.marketingid", DB::raw('SUM(withdraw.amount) AS totalwithdraw')); $toptendepositlists = Marketing::leftjoin(DB::raw("({$depositsum->toSql()}) AS dAmount"), 'dAmount.marketingid', '=', 'marketing.id') ->leftjoin(DB::raw("({$withdrawsum->toSql()}) AS wAmount"), 'wAmount.marketingid', '=', 'marketing.id') ->mergeBindings($depositsum->getQuery()) ->mergeBindings($withdrawsum->getQuery()) ->select('marketing.id','marketing.name','marketing.email', 'totaldeposit','totalwithdraw') ->orderBy('totaldeposit','DESC') ->groupBy('marketing.id') ->limit(10) ->get(); $toptenuserdepositlists = DB::table('deposit') ->select('deposit.userid','users.marketingid','users.name','users.email', DB::raw('SUM(deposit.amount) as total_deposit')) ->join('users', 'users.id', '=', 'deposit.userid') ->where('deposit.status','1') ->whereIn('users.id',$useridarray) ->whereBetween('deposit.created_at', [$fromdate,$todate.' 23:59:59']) ->groupBy('users.id') ->orderByDesc('total_deposit') ->limit(10) ->get(); $toptenuserwithdrawlists = DB::table('withdraw') ->select('withdraw.userid','users.marketingid','users.name','users.email', DB::raw('SUM(withdraw.amount) as total_withdraw')) ->join('users', 'users.id', '=', 'withdraw.userid') ->where('withdraw.status','1') ->whereIn('users.id',$useridarray) ->whereBetween('withdraw.created_at', [$fromdate,$todate.' 23:59:59']) ->groupBy('users.id') ->orderByDesc('total_withdraw') ->limit(10) ->get(); $toptenuserprofitlists = DB::table('closedtrade') ->select('closedtrade.Login', 'mt5_userlist.mt5id', DB::raw('SUM(closedtrade.Profit) as total_profit'), DB::raw('SUM(closedtrade.Volume) as total_volume')) ->join('mt5_userlist', 'mt5_userlist.mt5id', '=', 'closedtrade.Login') ->whereIn('mt5_userlist.userid',$useridarray) ->whereBetween('closedtrade.Date', [$fromdate,$todate.' 23:59:59']) ->groupBy('mt5_userlist.mt5id') ->orderByDesc('total_profit') ->limit(10) ->get(); $toptenuserlosslists = DB::table('closedtrade') ->select('closedtrade.Login', 'mt5_userlist.mt5id', DB::raw('SUM(closedtrade.Profit) as total_profit'), DB::raw('SUM(closedtrade.Volume) as total_volume')) ->join('mt5_userlist', 'mt5_userlist.mt5id', '=', 'closedtrade.Login') ->whereIn('mt5_userlist.userid',$useridarray) ->whereBetween('closedtrade.Date', [$fromdate,$todate.' 23:59:59']) ->groupBy('mt5_userlist.mt5id') ->orderBy('total_profit','ASC') ->limit(10) ->get(); $totoallot = ClosedTrade::whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->sum('Volume'); $totoalibcommission = Dealsrecord::whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->sum('Commission'); $totoalpnl = ClosedTrade::whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->sum('Profit'); $totoalpositive = ClosedTrade::where('Profit','>','0')->whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->sum('Profit'); $totoalpositivecount = ClosedTrade::where('Profit','>','0')->whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->count(); $totoalnegative = ClosedTrade::where('Profit','<','0')->whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->sum('Profit'); $totoalnegativecount = ClosedTrade::where('Profit','<','0')->whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->count(); if($totoalpositivecount > 0){ $avgwinamount = $totoalpositive / $totoalpositivecount; } else{ $avgwinamount = '0'; } if($totoalnegativecount > 0){ $avglossamount = $totoalnegative / $totoalnegativecount; } else{ $avglossamount = '0'; } $totoaltrades = ClosedTrade::whereIn('userid',$useridarray)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->count(); return view('admin.managementreport',array('title' => $title,'totoalibcommission' => $totoalibcommission,'totoallot' => $totoallot,'avgwinamount' => $avgwinamount,'avglossamount' => $avglossamount,'totoaltrades' => $totoaltrades,'totoalpositive' => $totoalpositive,'totoalnegative' => $totoalnegative,'totoalpnl' => $totoalpnl,'todate' => $todate,'fromdate' => $fromdate,'marketinglists' => $marketinglists,'marketingselected' => $marketingselected,'countrylists' => $countrylists,'countryselected' => $countryselected,'totaldeposit' => $totaldeposit,'totalwithdraw' => $totalwithdraw,'netdeposit' => $netdeposit,'useridarray' => $useridarray,'depositchart' => $depositchart,'toptendepositlists' => $toptendepositlists,'toptenuserdepositlists' => $toptenuserdepositlists,'toptenuserwithdrawlists' => $toptenuserwithdrawlists,'toptenuserprofitlists' => $toptenuserprofitlists,'toptenuserlosslists' => $toptenuserlosslists)); } else{ return abort(403); } } public function getClosedTradeByAccount(Request $request) { $mt5id = $request->mt5id; $fromdate = $request->fromdate; $todate = $request->todate; $data = ClosedTrade::where('Login',$mt5id)->whereBetween('Date', [$fromdate,$todate.' 23:59:59'])->get(); return response()->json($data); } public function pammInvestorSubscriptionRequest(Request $request) { $title = "Investor PAMM Request"; if ($request->ajax()) { $subscriptionrequest = DB::table('subscribe_requests')->leftJoin("users", "subscribe_requests.userid", "=", "users.id")->select("users.name", "users.email", "subscribe_requests.*")->where("subscribe_requests.status", 0)->where("subscribe_requests.user_type", "investor")->where("subscribe_requests.service_type", "PAMM")->get(); return Datatables::of($subscriptionrequest)->addIndexColumn()->addColumn('action', function($row){ $btn = '
'; return $btn; }) ->addColumn('date', function($row) { return date('Y-m-d',strtotime($row->created_at)); }) ->rawColumns(['action']) ->make(true); } return view("admin.pamm_copier.investor_pamm_request", compact("title")); } public function pammMmSubscriptionRequest(Request $request) { $title = "MM PAMM Request"; if ($request->ajax()) { $subscriptionrequest = DB::table('subscribe_requests')->leftJoin("users", "subscribe_requests.userid", "=", "users.id")->select("users.name", "users.email", "subscribe_requests.*")->where("subscribe_requests.status", 0)->where("subscribe_requests.user_type", "mm")->where("subscribe_requests.service_type", "PAMM")->get(); return Datatables::of($subscriptionrequest)->addIndexColumn()->addColumn('action', function($row){ $btn = '
'; return $btn; }) ->addColumn('date', function($row) { return date('Y-m-d',strtotime($row->created_at)); }) ->addColumn('trade_type', function ($row) { if ($row->trade_type == "per_deal") { return "Per Deal"; } if ($row->trade_type == "per_lot") { return "Per Lot"; } return ""; }) ->addColumn("performance_fee", function($row) { return $row->performance_fee . "%"; }) ->addColumn("trade_fee", function($row) { return "$" . $row->trade_fee; }) ->addColumn("min_investment", function($row) { return "$" . $row->min_investment; }) ->rawColumns(['action']) ->make(true); } return view("admin.pamm_copier.mm_pamm_request", compact("title")); } public function copierSlaveSubscriptionRequest(Request $request) { $title = "Slave Copier Request"; if ($request->ajax()) { $subscriptionrequest = DB::table('subscribe_requests')->leftJoin("users", "subscribe_requests.userid", "=", "users.id")->select("users.name", "users.email", "subscribe_requests.*")->where("subscribe_requests.status", 0)->where("subscribe_requests.user_type", "slave")->where("subscribe_requests.service_type", "Copier")->get(); return Datatables::of($subscriptionrequest)->addIndexColumn()->addColumn('action', function($row){ $btn = '
'; return $btn; }) ->addColumn('date', function($row) { return date('Y-m-d',strtotime($row->created_at)); }) ->rawColumns(['action']) ->make(true); } return view("admin.pamm_copier.slave_copier_request", compact("title")); } public function copierMasterSubscriptionRequest(Request $request) { $title = "Master Copier Request"; if ($request->ajax()) { $subscriptionrequest = DB::table('subscribe_requests')->leftJoin("users", "subscribe_requests.userid", "=", "users.id")->select("users.name", "users.email", "subscribe_requests.*")->where("subscribe_requests.status", 0)->where("subscribe_requests.user_type", "master")->where("subscribe_requests.service_type", "Copier")->get(); return Datatables::of($subscriptionrequest)->addIndexColumn()->addColumn('action', function($row){ $btn = '
'; return $btn; }) ->addColumn('date', function($row) { return date('Y-m-d',strtotime($row->created_at)); }) ->rawColumns(['action']) ->make(true); } return view("admin.pamm_copier.master_copier_request", compact("title")); } }