public function home() { $catagory = Catagory::all(); $subcatagory = Subcatagory::all(); $product = Product::orderBy('created_at', 'desc')->paginate(9); // Check if any users have got any amount by their referals if (Auth::user()) { $amount = Amount::where("user_id", Auth::user()->id)->where('status', 0); if ($amount->count() > 0) { $amount->update(['status' => 1]); // Check the user's referal is an admin or not $my_referal = User::find(Auth::user()->referal_id); if (Auth::user()->referal_id != 0) { if ($my_referal->type == 'admin') { $distributed_amount = 600; } else { $distributed_amount = 300; } Amount::create(['user_id' => Auth::user()->referal_id, 'amount' => $distributed_amount]); } } } return View::make('Main.Home.Index', array('catagories' => $catagory, 'subcatagories' => $subcatagory, 'products' => $product)); }
public function recharge() { $v = Validator::make(Input::all(), ["code" => "required|size:22"], ["required" => "<span class='glyphicon glyphicon-exclamation-sign'></span> Please typr the code.", "size" => "<span class='glyphicon glyphicon-exclamation-sign'></span> Invalid code"]); if ($v->fails()) { return Redirect::back()->withErrors($v)->withInput(); } $find = Product::where("code", Input::get("code")); if ($find->count() > 0) { // Give the point associated with the code $point = $find->get()->first()->point; $p = new Point(); $p->user_id = Auth::user()->id; $p->point = $point; $p->product_id = $find->get()->first()->id; $p->save(); // Set user's designation $active_member = User::find(Auth::user()->id); $active_member->designation = "Active member"; $active_member->save(); // Remove the code from product. So that any user can't use the same code twice. $find->update(["code" => ""]); // If the user has 1000 points then add amount 500 $how_many_points = Point::where('user_id', Auth::user()->id)->sum('point'); if ($how_many_points >= 1000) { // Set the user's designation to Model member $model_member = User::find(Auth::user()->id); $model_member->designation = "Model member"; $model_member->save(); // Check the user's referal is an admin or not $my_referal = User::find(Auth::user()->referal_id); if ($my_referal->type == 'admin') { $distributed_amount = 600; } else { $distributed_amount = 300; } Amount::create(['user_id' => Auth::user()->id, 'amount' => 500, 'status' => 1]); Amount::create(['user_id' => Auth::user()->referal_id, 'amount' => $distributed_amount]); Point::where('user_id', Auth::user()->id)->delete(); } return Redirect::back()->with("event", "<p class='alert alert-success'><span class='glyphicon glyphicon-ok'></span> Congratulation! You got " . $point . " points.</p>"); } return Redirect::back()->with("event", "<p class='alert alert-danger'><span class='glyphicon glyphicon-exclamation-sign'></span> Invalid code.</p>"); }