-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAdminController.php
executable file
·281 lines (242 loc) · 8.54 KB
/
AdminController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
namespace App\Http\Controllers;
use App\Admin;
use App\BuyMoney;
use App\ExchangeMoney;
use App\Provider;
use App\SellMoney;
use App\Trx;
use App\User;
use Illuminate\Http\Request;
use Auth;
use App\GeneralSettings;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Hash;
use File;
use Image;
class AdminController extends Controller
{
public function __construct(){
$Gset = GeneralSettings::first();
$this->sitename = $Gset->sitename;
$this->middleware('auth:admin');
}
public function exchangeLog()
{
$data['exchange'] = ExchangeMoney::where('status', '!=',0)->latest()->paginate(20);
$data['page_title'] = 'Manage Exchange Log';
return view('admin.currency.exchange-list', $data);
}
public function exchangeInfo($id)
{
$get = ExchangeMoney::where('id',$id)->where('status','!=',0)->first();
if($get)
{
$data['exchange'] = $get;
$data['page_title'] = ' Exchange Log Details';
return view('admin.currency.exchange-info', $data);
}
abort(404);
}
public function exchangeAction(Request $request)
{
$request->validate([
'button' => 'required',
'id' => 'required',
]);
$data = ExchangeMoney::find($request->id);
if($request->button == "approve")
{
$data->status= 2;
}else{
$data->status= -2;
}
$data->save();
$notification = array('message' => 'Saved Successfully !!', 'alert-type' => 'success');
return back()->with($notification);
}
public function buyLog()
{
$data['exchange'] = BuyMoney::where('status', '!=',0)->latest()->paginate(20);
$data['page_title'] = 'Manage Buy Log';
return view('admin.currency.buy-list', $data);
}
public function buyInfo($id)
{
$get = BuyMoney::where('id',$id)->where('status','!=',0)->first();
if($get)
{
$data['exchange'] = $get;
$data['page_title'] = ' Buy Log Details';
return view('admin.currency.buy-info', $data);
}
abort(404);
}
public function buyAction(Request $request)
{
$request->validate([
'button' => 'required',
'id' => 'required',
]);
$data = BuyMoney::find($request->id);
$basic = GeneralSettings::first();
if($request->button == "approve")
{
$data->status= 2;
}else{
if($data->type == 0)
{
$user = User::find($data->user_id);
$user->balance += $data->enter_amount;
$user->save();
Trx::create([
'user_id' => $user->id,
'amount' => $data->enter_amount,
'main_amo' => round($user->balance, $basic->decimal),
'charge' => 0,
'type' => '+',
'title' => ' Buy Amount return ' . $data->enter_amount . ' ' . $basic->currency,
'trx' => rand(000000, 999999) . rand(000000, 999999)
]);
$msg = ' Buy Amount return ' . $data->enter_amount . ' ' . $basic->currency;
send_email($user->email, $user->username, 'Buy Amount return ', $msg);
}
$data->status= -2;
}
$data->save();
$notification = array('message' => 'Saved Successfully !!', 'alert-type' => 'success');
return back()->with($notification);
}
public function sellLog()
{
$data['exchange'] = SellMoney::where('status', '!=',0)->latest()->paginate(20);
$data['page_title'] = 'Manage Sell Log';
return view('admin.currency.sell-list', $data);
}
public function sellInfo($id)
{
$get = SellMoney::where('id',$id)->where('status','!=',0)->first();
if($get)
{
$data['exchange'] = $get;
$data['page_title'] = ' Sell Log Details';
return view('admin.currency.sell-info', $data);
}
abort(404);
}
public function sellAction(Request $request)
{
$request->validate([
'button' => 'required',
'id' => 'required',
]);
$data = SellMoney::find($request->id);
$basic = GeneralSettings::first();
if($request->button == "approve")
{
$data->status= 2;
if($data->type == 0)
{
$user = User::find($data->user_id);
$user->balance += $data->get_amount;
$user->save();
Trx::create([
'user_id' => $user->id,
'amount' => $data->get_amount,
'main_amo' => round($user->balance, $basic->decimal),
'charge' => 0,
'type' => '+',
'title' => ' Sell Amount ' . $data->get_amount . ' ' . $basic->currency,
'trx' => rand(000000, 999999) . rand(000000, 999999)
]);
$msg = ' Sell Amount ' . $data->get_amount . ' ' . $basic->currency;
send_email($user->email, $user->username, 'Sell Amount ', $msg);
}
}else{
$data->status= -2;
}
$data->save();
$notification = array('message' => 'Saved Successfully !!', 'alert-type' => 'success');
return back()->with($notification);
}
public function socialLogin()
{
$data['page_title'] = 'Manage Social Login';
$data['providers'] = Provider::all();
return view('admin.social-login.index', $data);
}
public function socialLoginUpd(Request $request)
{
$data = Provider::find($request->id);
$data->client_id = $request->name;
$data->client_secret = $request->account;
$data->save();
$notification = array('message' => 'Updated Successfully !!', 'alert-type' => 'success');
return back()->with($notification);
}
public function dashboard()
{
$data['page_title'] = 'DashBoard';
return view('admin.dashboard', $data);
}
public function changePassword()
{
$data['page_title'] = "Change Password";
return view('admin.change_password',$data);
}
public function updatePassword(Request $request)
{
$request->validate([
'old_password' => 'required',
'new_password' => 'required|min:5',
'password_confirmation' => 'required|same:new_password',
]);
$user = Auth::guard('admin')->user();
$oldPassword = $request->old_password;
$password = $request->new_password;
$passwordConf = $request->password_confirmation;
if (!Hash::check($oldPassword, $user->password) || $password != $passwordConf) {
$notification = array('message' => 'Password Do not match !!', 'alert-type' => 'error');
return back()->with($notification);
}elseif (Hash::check($oldPassword, $user->password) && $password == $passwordConf)
{
$user->password = bcrypt($password);
$user->save();
$notification = array('message' => 'Password Changed Successfully !!', 'alert-type' => 'success');
return back()->with($notification);
}
}
public function profile()
{
$data['admin'] = Auth::user();
$data['page_title'] = "Profile Settings";
return view('admin.profile',$data);
}
public function updateProfile(Request $request)
{
$data = Admin::find($request->id);
$request->validate([
'name' => 'required|max:20',
'email' => 'required|max:50|unique:admins,email,'.$data->id,
'mobile' => 'required|regex:/(01)[0-9]{9}/',
]);
$in = Input::except('_method','_token');
if($request->hasFile('image')){
$image = $request->file('image');
$filename = 'admin_'.time().'.jpg';
$location = 'assets/admin/img/' . $filename;
Image::make($image)->resize(300,300)->save($location);
$path = './assets/admin/img/';
File::delete($path.$data->image);
$in['image'] = $filename;
}
$data->fill($in)->save();
$notification = array('message' => 'Profile Update Successfully', 'alert-type' => 'success');
return back()->with($notification);
}
public function logout() {
Auth::guard('admin')->logout();
session()->flash('message', 'Just Logged Out!');
return redirect('/admin');
}
}