Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace App\Http\Controllers; use App\Models\Admin; use App\Models\AdminNot..
Decoded Output download
<?php
namespace App\Http\Controllers;
use App\Models\Admin;
use App\Models\AdminNotification;
use App\Models\Bid;
use App\Models\BidTransaction;
use App\Models\Category;
use App\Models\GeneralSetting;
use App\Models\Merchant;
use App\Models\PackageRendend;
use App\Models\Product;
use App\Models\Review;
use App\Models\Transaction;
use App\Models\User;
use DB;
use Illuminate\Http\Request;
use Response;
class ProductController extends Controller
{
public function __construct()
{
$this->activeTemplate = activeTemplate();
}
public function products()
{
$pageTitle = request()->search_key?'Search Products':'All Products';
$emptyMessage = 'No product found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->orderBy("expired_at",'DESC')
->where("auction_type",'2')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
// $products = $products->where('name', 'like', '%'.request()->search_key.'%')->with('category');
$allProducts = clone $products->get();
if(request()->category_id){
$products = $products->where('category_id', request()->category_id);
}
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
// $product->setAttribute('current_leadrer_name',$current_leadrer_name['firstname']);
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
// $product->setAttribute('current_leadrer_name','');
}
// unset($current_leadrer);
}
return view($this->activeTemplate.'sections.product.list', compact('pageTitle', 'emptyMessage', 'products', 'allProducts', 'categories'));
}
public function dailyAuctions()
{
$pageTitle = request()->search_key ?'Daily Auctions':'All Daily Auctions';
$emptyMessage = 'No Auctions found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->where("auction_type",'1')
->orderBy("expired_at",'DESC')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
}
}
return view($this->activeTemplate.'sections.product.daily_auctions', compact('pageTitle', 'emptyMessage', 'products', 'categories'));
}
public function auctions()
{
$pageTitle = request()->search_key ?' Auctions ':'Auctions';
$emptyMessage = 'No Auctions found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->where("auction_type",'2')
->orderBy("expired_at",'DESC')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
}
}
return view($this->activeTemplate.'sections.product.auctions', compact('pageTitle', 'emptyMessage', 'products', 'categories'));
}
public function winner()
{
$pageTitle = request()->search_key? 'Search Winner':'All winner';
$emptyMessage = 'No product found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::with('winner')->orderBy("expired_at",'DESC')->where('expired_at','<',date('Y-m-d H:i:s'))->whereHas("winner")->get();
// $products = $products->where('name', 'like', '%'.request()->search_key.'%')->with('category');
// $allProducts = clone $products->get();
// if(request()->category_id){
// $products = $products->where('category_id', request()->category_id);
// }
// $products = $products->paginate(getPaginate(18));
return view($this->activeTemplate.'sections.product.winner_list', compact('pageTitle', 'emptyMessage', 'products'));
}
public function filter(Request $request)
{
$pageTitle = 'Search Products';
$emptyMessage = 'No product found';
$products = Product::live()->where('name', 'like', '%'.$request->search_key.'%');
if($request->sorting){
$products->orderBy($request->sorting, 'ASC');
}
if($request->categories){
$products->whereIn('category_id', $request->categories);
}
if($request->minPrice){
$products->where('price', '>=', $request->minPrice);
}
if($request->maxPrice){
$products->where('price', '<=', $request->maxPrice);
}
$products = $products->paginate(getPaginate(18));
return view($this->activeTemplate.'product.filtered', compact('pageTitle', 'emptyMessage', 'products'));
}
public function productDetails($id)
{
$pageTitle = 'Auction Details';
$product = Product::with('reviews', 'merchant', 'reviews.user')->where('status', '!=', 0)->findOrFail($id);
$relatedProducts = Product::live()->where('category_id', $product->category_id)->where('id', '!=', $id)->limit(10)->get();
$imageData = imagePath()['product'];
$seoContents = getSeoContents($product, $imageData, 'image');
return view($this->activeTemplate.'sections.product.details', compact('pageTitle', 'product', 'relatedProducts', 'seoContents'));
}
public function loadMore(Request $request)
{
$reviews = Review::where('product_id', $request->pid)->with('user')->latest()->paginate(5);
return view($this->activeTemplate . 'partials.product_review', compact('reviews'));
}
public function bid(Request $request)
{
$request->validate([
'amount' => 'required|numeric|gt:0',
'product_id' => 'required|integer|gt:0'
]);
$product = Product::live()->with('merchant', 'admin')->findOrFail($request->product_id);
$user = auth()->user();
if($product->price > $request->amount){
$notify[] = ['error', 'Bid amount must be greater than product price'];
return back()->withNotify($notify);
}
if($request->amount > $user->balance){
$notify[] = ['error', 'Insufficient Balance'];
return back()->withNotify($notify);
}
$bid = Bid::where('product_id', $request->product_id)->where('user_id', $user->id)->exists();
if($bid){
$notify[] = ['error', 'You already bidden on this product'];
return back()->withNotify($notify);
}
$bid = new Bid();
$bid->product_id = $product->id;
$bid->user_id = $user->id;
$bid->amount = $request->amount;
$bid->save();
$product->total_bid += 1;
$product->save();
$user->balance -= $request->amount;
$user->save();
$general = GeneralSetting::first();
$trx = getTrx();
$transaction = new Transaction();
$transaction->user_id = $user->id;
$transaction->amount = $request->amount;
$transaction->post_balance = $user->balance;
$transaction->trx_type = '-';
$transaction->details = 'Subtracted for a new bid';
$transaction->trx = $trx;
$transaction->save();
if($product->admin){
$adminNotification = new AdminNotification();
$adminNotification->user_id = auth()->user()->id;
$adminNotification->title = 'An user has been bidden on your product';
$adminNotification->click_url = urlPath('admin.product.bids',$product->id);
$adminNotification->save();
$notify[] = ['success', 'Bidden successfully'];
return back()->withNotify($notify);
}
$product->merchant->balance += $request->amount;
$product->merchant->save();
$transaction = new Transaction();
$transaction->merchant_id = $product->merchant_id;
$transaction->amount = $request->amount;
$transaction->post_balance = $product->merchant->balance;
$transaction->trx_type = '+';
$transaction->details = showAmount($request->amount) . ' ' . $general->cur_text . ' Added for Bid';
$transaction->trx = $trx;
$transaction->save();
notify($product->merchant, 'BID_COMPLETE', [
'trx' => $trx,
'amount' => showAmount($request->amount),
'currency' => $general->cur_text,
'product' => $product->name,
'product_price' => showAmount($product->price),
'post_balance' => showAmount($product->merchant->balance),
], 'merchant');
$notify[] = ['success', 'Bidden successfully'];
return back()->withNotify($notify);
}
public function saveProductReview(Request $request)
{
$request->validate([
'rating' => 'required|integer|between:1,5',
'product_id' => 'required|integer'
]);
Bid::where('user_id', auth()->id())->where('product_id', $request->product_id)->firstOrFail();
$review = Review::where('user_id', auth()->id())->where('product_id', $request->product_id)->first();
$product = Product::find($request->product_id);
if(!$review){
$review = new Review();
$product->total_rating += $request->rating;
$product->review_count += 1;
$notify[] = ['success', 'Review given successfully'];
}else{
$product->total_rating = $product->total_rating - $review->rating + $request->rating;
$notify[] = ['success', 'Review updated successfully'];
}
$product->avg_rating = $product->total_rating / $product->review_count;
$product->save();
$review->rating = $request->rating;
$review->description = $request->description;
$review->user_id = auth()->id();
$review->product_id = $request->product_id;
$review->save();
return back()->withNotify($notify);
}
public function saveMerchantReview(Request $request)
{
$request->validate([
'rating' => 'required|integer|between:1,5',
'merchant_id' => 'required|integer'
]);
$merchant = Merchant::with('bids')->whereHas('bids', function($bid){
$bid->where('user_id', auth()->id());
})
->findOrFail($request->merchant_id);
$review = Review::where('user_id', auth()->id())->where('merchant_id', $request->merchant_id)->first();
if(!$review){
$review = new Review();
$merchant->total_rating += $request->rating;
$merchant->review_count += 1;
$notify[] = ['success', 'Review given successfully'];
}else{
$merchant->total_rating = $merchant->total_rating - $review->rating + $request->rating;
$notify[] = ['success', 'Review updated successfully'];
}
$merchant->avg_rating = $merchant->total_rating / $merchant->review_count;
$merchant->save();
$review->rating = $request->rating;
$review->description = $request->description;
$review->user_id = auth()->id();
$review->merchant_id = $request->merchant_id;
$review->save();
return back()->withNotify($notify);
}
public function biddingForm(Request $request){
if(auth()->user()){
$current_user_id = auth()->user()->id;
}else{
$current_user_id=1;
}
$bidder_leader_list =Bid::with(['user'])->select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$request->product_id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(3)
->get()->toArray();
$last_bidder=Bid::with(['user'])->where(['product_id'=>$request->product_id])->orderBy('id','desc')->take(10)->get();
$current_user_bid=Bid::where(['product_id'=>$request->product_id])->orderBy('id','desc')->where(['user_id'=>$current_user_id])->take(10)->select('amount','remaining_bidding','message')->get()->toArray();
$productDetail = Product::with(['winner','all_package_rendend'])
->withCount(['all_package_rendend as count_package_rendend' => function($query) {
$query->select(DB::raw('SUM(total)'));
}])->find($request->product_id);
// dd($productDetail);
$pageTitle ="Bidding Form";
return view('frontend.productBidding',compact('pageTitle','bidder_leader_list','productDetail','last_bidder','current_user_bid'));
}
public function singelBid(Request $request)
{
// dd($request->all());
$status =1;
$message = '';
$user_id=auth()->user();
if($user_id){
$user_id=auth()->user()->id;
}else{
$status = 0;
$message = "unauthorized";
}
$total_bid = getTotalBid($request->product_id);
$productDetail = Product::with('winner')->find($request->product_id);
if (isExpire($productDetail->expired_at)) {
return [
"error"=>"Product is expire",
"result"=>true,
];
}
if($status == 1 && $productDetail->winner && $productDetail->winner->confirmed){
$status = 0;
$message = "No More Bidding Allowed";
}
elseif($status== 1 && $total_bid == 0){
$status = 0;
$message = "You need to buy bid";
}
if($status == 1){
$bid_amount = $request->amount;
$already_same_amount_bid_by_you = Bid::where('product_id',$request->product_id)
->where(['user_id'=>$user_id])
->where('amount',$request->amount)
->first();
if($already_same_amount_bid_by_you){
$message = "You can not quote same value again";
return Response::json([
"message"=>$message,
"total_bid"=>$total_bid,
"status"=>true,
]);
}
/*same amount bid by anoter user so cancale a bid and update message*/
$is_same_amount = Bid::where(['product_id'=>$request->product_id])
->where('amount',$bid_amount)
->where('user_id','!=',$user_id)
->first();
if ($is_same_amount) {
$message = Product::NOT_UNIQUE;
$is_same_amount->message = $message;
$is_same_amount->save();
$status = 0;
}
/*Close*/
if ($status == 1) {
$max_amount = Bid::where('product_id',$request->product_id)->max('amount');
if($max_amount > $request->amount){
$message = Product::UNIQUE_BUT_NOT_HIGHEST;
}
else if($max_amount < $request->amount){
$message = Product::HIGHEST_UNIQUE_BID;
$bid_s = Bid::where('product_id',$request->product_id)
->where('message', $message)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
}
}
$total_bid = ($total_bid-1);
$checkInsert = Bid::insertGetId([
'product_id'=>$request->product_id,
'user_id'=>$user_id,
'amount'=>$request->amount,
'remaining_bidding'=>$total_bid,
"message"=>$message
]);
if($request->product_id) updateUsersBid($request->product_id,$total_bid);
$higest_unique_value = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->orderBy('amount','DESC')
->first();
if ($higest_unique_value) {
Bid::where(['product_id'=>$request->product_id])
->where('id','!=',$higest_unique_value->id)
->where('message','!=',Product::NOT_UNIQUE)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
$higest_unique_value->message = Product::HIGHEST_UNIQUE_BID;
$higest_unique_value->save();
}
// if ($higest_unique_value) {
// add_Winner($productDetail->id,$higest_unique_value->id,$higest_unique_value->amount);
// }
}
return [
"message"=>$message,
"total_bit"=>getTotalBid($request->product_id),
"status"=>true,
];
}
public function bulkbid(Request $request){
// dd($request->all());
$status =1;
$message = '';
$count = 1;
$total_bid = getTotalBid($request->product_id);
$ret_msg = '';
$user_id=auth()->user();
if($user_id){
$user_id=auth()->user()->id;
}else{
$status = 0;
$message = "unauthorized";
}
$productDetail = Product::with('winner')->find($request->product_id);
if (isExpire($productDetail->expired_at)) {
return [
"error"=>"Product is expire",
"result"=>true,
];
}
if($productDetail->winner && $productDetail->winner->confirmed){
$status = 0;
$message = "No More Bidding Allowed";
}
elseif($total_bid == 0){
$status = 0;
$message = "You need to buy bid";
}
if($status == 1){
if($request->filled('min_amount')){
$bid_amount=$request->min_amount;
$max_bid = 1;
$range = range($request->min_amount,$request->max_amount,0.01);
foreach($range as $i){
$total_bid = ($total_bid-1);
$message = '';
if ($total_bid >= 0) {
$bid_amount = $i;
if ($bid_amount > $request->max_amount) {
$total_bid = ($total_bid+1);
break;
}
$already_same_amount_bid_by_you = Bid::where(['product_id'=>$request->product_id])
->where('user_id',$user_id)
->where('amount',$bid_amount)
->first();
if ($already_same_amount_bid_by_you) {
$total_bid = ($total_bid+1);
$message = "You can not quote same value again";
continue;
}
$is_same_amount = Bid::where(['product_id'=>$request->product_id])
->where('amount',$bid_amount)
->where('user_id','!=',$user_id)
->first();
if ($is_same_amount) {
$message = Product::NOT_UNIQUE;
$is_same_amount->message = $message;
$is_same_amount->save();
$status = 0;
}
if ($status == 1) {
$max_amount = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->max('amount');
if($max_amount > $bid_amount){
$message = Product::UNIQUE_BUT_NOT_HIGHEST;
}
else if($max_amount < $bid_amount){
$message = Product::HIGHEST_UNIQUE_BID;
}
}
$checkInsert = Bid::insertGetId([
'product_id'=>$request->product_id,
'user_id'=>$user_id,
'amount'=>$bid_amount,
'remaining_bidding'=>$total_bid,
"message"=>$message
]);
$higest_unique_value = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->orderBy('amount','DESC')
->first();
if ($higest_unique_value) {
Bid::where(['product_id'=>$request->product_id])
->where('id','!=',$higest_unique_value->id)
->where('message','!=',Product::NOT_UNIQUE)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
$higest_unique_value->message = Product::HIGHEST_UNIQUE_BID;
$higest_unique_value->save();
}
// if ($higest_unique_value) {
// add_Winner($productDetail->id,$higest_unique_value->id,$higest_unique_value->amount);
// }
if($message) {$ret_msg = $message;}
}
// $insert_status[]=$checkInsert;
if ($total_bid <= 0 || $max_bid >= 100) {
break;
}
$max_bid++;
}
}
if($request->product_id) updateUsersBid($request->product_id,$total_bid);
}
return [
"message"=>$ret_msg,
"total_bit"=>getTotalBid($request->product_id),
"status"=>true,
"i"=>$i,
"range"=>$range,
];
}
public function storeBiddingForm(Request $request){
if($request->filled('min_amount') && $request->filled('max_amount')){
return $this->bulkbid($request);
}
if($request->filled('amount')){
return $this->singelBid($request);
}
return [];
}
public function autoFetch(Request $request){
$is_expire = false;
$bidder_leader_list_html = view("partials.bidder_leader_list_html",["product_id"=>$request->product_id])->render();
$last_bidders_html = view("partials.last_bidders_html",["product_id"=>$request->product_id])->render();
$current_user_bid_html = view("partials.current_user_bid_html",["product_id"=>$request->product_id])->render();
$leader_user_info = view("partials.leader_user_info",["product_id"=>$request->product_id])->render();
$productDetail = Product::find($request->product_id);
if (isExpire($productDetail->expired_at)) {
$is_expire = true;
}else{
$is_expire = false;
}
return ([
'bidder_leader_list'=>$bidder_leader_list_html,
'last_bidders_html'=>$last_bidders_html,
'current_user_bid_html'=>$current_user_bid_html,
// 'leader_img'=>$leader_img,
// 'leader_name'=>$leader_name,
// 'statue'=>'1',
'leader_user_info'=>$leader_user_info,
'is_expire'=>$is_expire,
]);
}
public function addPackage(Request $request)
{
$package = BidTransaction::where('product_id',$request->product_id)
->where('user_id',\Auth::user()->id)
->where('type',$request->type)
->first();
if($package){
return Response::json(["message"=>"already addes","status"=>false]);
}
$package_rendend = new BidTransaction();
$package_rendend->product_id = $request->product_id;
$package_rendend->user_id = \Auth::user()->id;
$package_rendend->type = $request->type;
$package_rendend->amount = $request->price;
$package_rendend->total = $request->total_bit;
$package_rendend->save();
// $total_bit = BidTransaction::where('product_id',$request->product_id)
// ->where('user_id',\Auth::user()->id)
// ->select("total")
// ->sum("total");
if (\Auth::check()) {
// $user = \Auth::user();
// $user->total_bid = (int)$user->total_bit + (int)$package_rendend->total;
// $user->save();
increaseBid($request->product_id,$request->total_bit);
}
$total_bit =getTotalBid($request->product_id);
return Response::json(["message"=>"successfully added","status"=>true,"total_bit"=>$total_bit]);
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace App\Http\Controllers;
use App\Models\Admin;
use App\Models\AdminNotification;
use App\Models\Bid;
use App\Models\BidTransaction;
use App\Models\Category;
use App\Models\GeneralSetting;
use App\Models\Merchant;
use App\Models\PackageRendend;
use App\Models\Product;
use App\Models\Review;
use App\Models\Transaction;
use App\Models\User;
use DB;
use Illuminate\Http\Request;
use Response;
class ProductController extends Controller
{
public function __construct()
{
$this->activeTemplate = activeTemplate();
}
public function products()
{
$pageTitle = request()->search_key?'Search Products':'All Products';
$emptyMessage = 'No product found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->orderBy("expired_at",'DESC')
->where("auction_type",'2')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
// $products = $products->where('name', 'like', '%'.request()->search_key.'%')->with('category');
$allProducts = clone $products->get();
if(request()->category_id){
$products = $products->where('category_id', request()->category_id);
}
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
// $product->setAttribute('current_leadrer_name',$current_leadrer_name['firstname']);
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
// $product->setAttribute('current_leadrer_name','');
}
// unset($current_leadrer);
}
return view($this->activeTemplate.'sections.product.list', compact('pageTitle', 'emptyMessage', 'products', 'allProducts', 'categories'));
}
public function dailyAuctions()
{
$pageTitle = request()->search_key ?'Daily Auctions':'All Daily Auctions';
$emptyMessage = 'No Auctions found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->where("auction_type",'1')
->orderBy("expired_at",'DESC')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
}
}
return view($this->activeTemplate.'sections.product.daily_auctions', compact('pageTitle', 'emptyMessage', 'products', 'categories'));
}
public function auctions()
{
$pageTitle = request()->search_key ?' Auctions ':'Auctions';
$emptyMessage = 'No Auctions found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::where(['status'=>'1'])
->where("auction_type",'2')
->orderBy("expired_at",'DESC')
// ->where('started_at','>',0)
->where('expired_at','>=',date('Y-m-d H:i:s'));
$products = $products->paginate(getPaginate(18));
foreach($products as $la_key=>&$product){
$current_leadrer=Bid::select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$product->id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(1)
->get()->toArray();
if($current_leadrer){
$current_leadrer_user=User::find($current_leadrer[0]['user_id']);
$product->current_leadrer_name = $current_leadrer_user['firstname'].' '.$current_leadrer_user['lastname'];
$product->current_leadrer_image = getImage(imagePath()['profile']['user']['path'] . '/' . $current_leadrer_user['image'], imagePath()['profile']['user']['size'],true) ;
}else{
$product->current_leadrer_name='N/A';
$product->current_leadrer_image = getImage('', 0,true) ;
}
}
return view($this->activeTemplate.'sections.product.auctions', compact('pageTitle', 'emptyMessage', 'products', 'categories'));
}
public function winner()
{
$pageTitle = request()->search_key? 'Search Winner':'All winner';
$emptyMessage = 'No product found';
$categories = Category::with('products')->where('status', 1)->get();
$products = Product::with('winner')->orderBy("expired_at",'DESC')->where('expired_at','<',date('Y-m-d H:i:s'))->whereHas("winner")->get();
// $products = $products->where('name', 'like', '%'.request()->search_key.'%')->with('category');
// $allProducts = clone $products->get();
// if(request()->category_id){
// $products = $products->where('category_id', request()->category_id);
// }
// $products = $products->paginate(getPaginate(18));
return view($this->activeTemplate.'sections.product.winner_list', compact('pageTitle', 'emptyMessage', 'products'));
}
public function filter(Request $request)
{
$pageTitle = 'Search Products';
$emptyMessage = 'No product found';
$products = Product::live()->where('name', 'like', '%'.$request->search_key.'%');
if($request->sorting){
$products->orderBy($request->sorting, 'ASC');
}
if($request->categories){
$products->whereIn('category_id', $request->categories);
}
if($request->minPrice){
$products->where('price', '>=', $request->minPrice);
}
if($request->maxPrice){
$products->where('price', '<=', $request->maxPrice);
}
$products = $products->paginate(getPaginate(18));
return view($this->activeTemplate.'product.filtered', compact('pageTitle', 'emptyMessage', 'products'));
}
public function productDetails($id)
{
$pageTitle = 'Auction Details';
$product = Product::with('reviews', 'merchant', 'reviews.user')->where('status', '!=', 0)->findOrFail($id);
$relatedProducts = Product::live()->where('category_id', $product->category_id)->where('id', '!=', $id)->limit(10)->get();
$imageData = imagePath()['product'];
$seoContents = getSeoContents($product, $imageData, 'image');
return view($this->activeTemplate.'sections.product.details', compact('pageTitle', 'product', 'relatedProducts', 'seoContents'));
}
public function loadMore(Request $request)
{
$reviews = Review::where('product_id', $request->pid)->with('user')->latest()->paginate(5);
return view($this->activeTemplate . 'partials.product_review', compact('reviews'));
}
public function bid(Request $request)
{
$request->validate([
'amount' => 'required|numeric|gt:0',
'product_id' => 'required|integer|gt:0'
]);
$product = Product::live()->with('merchant', 'admin')->findOrFail($request->product_id);
$user = auth()->user();
if($product->price > $request->amount){
$notify[] = ['error', 'Bid amount must be greater than product price'];
return back()->withNotify($notify);
}
if($request->amount > $user->balance){
$notify[] = ['error', 'Insufficient Balance'];
return back()->withNotify($notify);
}
$bid = Bid::where('product_id', $request->product_id)->where('user_id', $user->id)->exists();
if($bid){
$notify[] = ['error', 'You already bidden on this product'];
return back()->withNotify($notify);
}
$bid = new Bid();
$bid->product_id = $product->id;
$bid->user_id = $user->id;
$bid->amount = $request->amount;
$bid->save();
$product->total_bid += 1;
$product->save();
$user->balance -= $request->amount;
$user->save();
$general = GeneralSetting::first();
$trx = getTrx();
$transaction = new Transaction();
$transaction->user_id = $user->id;
$transaction->amount = $request->amount;
$transaction->post_balance = $user->balance;
$transaction->trx_type = '-';
$transaction->details = 'Subtracted for a new bid';
$transaction->trx = $trx;
$transaction->save();
if($product->admin){
$adminNotification = new AdminNotification();
$adminNotification->user_id = auth()->user()->id;
$adminNotification->title = 'An user has been bidden on your product';
$adminNotification->click_url = urlPath('admin.product.bids',$product->id);
$adminNotification->save();
$notify[] = ['success', 'Bidden successfully'];
return back()->withNotify($notify);
}
$product->merchant->balance += $request->amount;
$product->merchant->save();
$transaction = new Transaction();
$transaction->merchant_id = $product->merchant_id;
$transaction->amount = $request->amount;
$transaction->post_balance = $product->merchant->balance;
$transaction->trx_type = '+';
$transaction->details = showAmount($request->amount) . ' ' . $general->cur_text . ' Added for Bid';
$transaction->trx = $trx;
$transaction->save();
notify($product->merchant, 'BID_COMPLETE', [
'trx' => $trx,
'amount' => showAmount($request->amount),
'currency' => $general->cur_text,
'product' => $product->name,
'product_price' => showAmount($product->price),
'post_balance' => showAmount($product->merchant->balance),
], 'merchant');
$notify[] = ['success', 'Bidden successfully'];
return back()->withNotify($notify);
}
public function saveProductReview(Request $request)
{
$request->validate([
'rating' => 'required|integer|between:1,5',
'product_id' => 'required|integer'
]);
Bid::where('user_id', auth()->id())->where('product_id', $request->product_id)->firstOrFail();
$review = Review::where('user_id', auth()->id())->where('product_id', $request->product_id)->first();
$product = Product::find($request->product_id);
if(!$review){
$review = new Review();
$product->total_rating += $request->rating;
$product->review_count += 1;
$notify[] = ['success', 'Review given successfully'];
}else{
$product->total_rating = $product->total_rating - $review->rating + $request->rating;
$notify[] = ['success', 'Review updated successfully'];
}
$product->avg_rating = $product->total_rating / $product->review_count;
$product->save();
$review->rating = $request->rating;
$review->description = $request->description;
$review->user_id = auth()->id();
$review->product_id = $request->product_id;
$review->save();
return back()->withNotify($notify);
}
public function saveMerchantReview(Request $request)
{
$request->validate([
'rating' => 'required|integer|between:1,5',
'merchant_id' => 'required|integer'
]);
$merchant = Merchant::with('bids')->whereHas('bids', function($bid){
$bid->where('user_id', auth()->id());
})
->findOrFail($request->merchant_id);
$review = Review::where('user_id', auth()->id())->where('merchant_id', $request->merchant_id)->first();
if(!$review){
$review = new Review();
$merchant->total_rating += $request->rating;
$merchant->review_count += 1;
$notify[] = ['success', 'Review given successfully'];
}else{
$merchant->total_rating = $merchant->total_rating - $review->rating + $request->rating;
$notify[] = ['success', 'Review updated successfully'];
}
$merchant->avg_rating = $merchant->total_rating / $merchant->review_count;
$merchant->save();
$review->rating = $request->rating;
$review->description = $request->description;
$review->user_id = auth()->id();
$review->merchant_id = $request->merchant_id;
$review->save();
return back()->withNotify($notify);
}
public function biddingForm(Request $request){
if(auth()->user()){
$current_user_id = auth()->user()->id;
}else{
$current_user_id=1;
}
$bidder_leader_list =Bid::with(['user'])->select("amount",'user_id', DB::raw("count('amount') as totalCount"))
->where(['product_id'=>$request->product_id])
->groupBy("amount")
->having('totalCount',1)
->orderBy('amount','desc')
->limit(3)
->get()->toArray();
$last_bidder=Bid::with(['user'])->where(['product_id'=>$request->product_id])->orderBy('id','desc')->take(10)->get();
$current_user_bid=Bid::where(['product_id'=>$request->product_id])->orderBy('id','desc')->where(['user_id'=>$current_user_id])->take(10)->select('amount','remaining_bidding','message')->get()->toArray();
$productDetail = Product::with(['winner','all_package_rendend'])
->withCount(['all_package_rendend as count_package_rendend' => function($query) {
$query->select(DB::raw('SUM(total)'));
}])->find($request->product_id);
// dd($productDetail);
$pageTitle ="Bidding Form";
return view('frontend.productBidding',compact('pageTitle','bidder_leader_list','productDetail','last_bidder','current_user_bid'));
}
public function singelBid(Request $request)
{
// dd($request->all());
$status =1;
$message = '';
$user_id=auth()->user();
if($user_id){
$user_id=auth()->user()->id;
}else{
$status = 0;
$message = "unauthorized";
}
$total_bid = getTotalBid($request->product_id);
$productDetail = Product::with('winner')->find($request->product_id);
if (isExpire($productDetail->expired_at)) {
return [
"error"=>"Product is expire",
"result"=>true,
];
}
if($status == 1 && $productDetail->winner && $productDetail->winner->confirmed){
$status = 0;
$message = "No More Bidding Allowed";
}
elseif($status== 1 && $total_bid == 0){
$status = 0;
$message = "You need to buy bid";
}
if($status == 1){
$bid_amount = $request->amount;
$already_same_amount_bid_by_you = Bid::where('product_id',$request->product_id)
->where(['user_id'=>$user_id])
->where('amount',$request->amount)
->first();
if($already_same_amount_bid_by_you){
$message = "You can not quote same value again";
return Response::json([
"message"=>$message,
"total_bid"=>$total_bid,
"status"=>true,
]);
}
/*same amount bid by anoter user so cancale a bid and update message*/
$is_same_amount = Bid::where(['product_id'=>$request->product_id])
->where('amount',$bid_amount)
->where('user_id','!=',$user_id)
->first();
if ($is_same_amount) {
$message = Product::NOT_UNIQUE;
$is_same_amount->message = $message;
$is_same_amount->save();
$status = 0;
}
/*Close*/
if ($status == 1) {
$max_amount = Bid::where('product_id',$request->product_id)->max('amount');
if($max_amount > $request->amount){
$message = Product::UNIQUE_BUT_NOT_HIGHEST;
}
else if($max_amount < $request->amount){
$message = Product::HIGHEST_UNIQUE_BID;
$bid_s = Bid::where('product_id',$request->product_id)
->where('message', $message)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
}
}
$total_bid = ($total_bid-1);
$checkInsert = Bid::insertGetId([
'product_id'=>$request->product_id,
'user_id'=>$user_id,
'amount'=>$request->amount,
'remaining_bidding'=>$total_bid,
"message"=>$message
]);
if($request->product_id) updateUsersBid($request->product_id,$total_bid);
$higest_unique_value = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->orderBy('amount','DESC')
->first();
if ($higest_unique_value) {
Bid::where(['product_id'=>$request->product_id])
->where('id','!=',$higest_unique_value->id)
->where('message','!=',Product::NOT_UNIQUE)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
$higest_unique_value->message = Product::HIGHEST_UNIQUE_BID;
$higest_unique_value->save();
}
// if ($higest_unique_value) {
// add_Winner($productDetail->id,$higest_unique_value->id,$higest_unique_value->amount);
// }
}
return [
"message"=>$message,
"total_bit"=>getTotalBid($request->product_id),
"status"=>true,
];
}
public function bulkbid(Request $request){
// dd($request->all());
$status =1;
$message = '';
$count = 1;
$total_bid = getTotalBid($request->product_id);
$ret_msg = '';
$user_id=auth()->user();
if($user_id){
$user_id=auth()->user()->id;
}else{
$status = 0;
$message = "unauthorized";
}
$productDetail = Product::with('winner')->find($request->product_id);
if (isExpire($productDetail->expired_at)) {
return [
"error"=>"Product is expire",
"result"=>true,
];
}
if($productDetail->winner && $productDetail->winner->confirmed){
$status = 0;
$message = "No More Bidding Allowed";
}
elseif($total_bid == 0){
$status = 0;
$message = "You need to buy bid";
}
if($status == 1){
if($request->filled('min_amount')){
$bid_amount=$request->min_amount;
$max_bid = 1;
$range = range($request->min_amount,$request->max_amount,0.01);
foreach($range as $i){
$total_bid = ($total_bid-1);
$message = '';
if ($total_bid >= 0) {
$bid_amount = $i;
if ($bid_amount > $request->max_amount) {
$total_bid = ($total_bid+1);
break;
}
$already_same_amount_bid_by_you = Bid::where(['product_id'=>$request->product_id])
->where('user_id',$user_id)
->where('amount',$bid_amount)
->first();
if ($already_same_amount_bid_by_you) {
$total_bid = ($total_bid+1);
$message = "You can not quote same value again";
continue;
}
$is_same_amount = Bid::where(['product_id'=>$request->product_id])
->where('amount',$bid_amount)
->where('user_id','!=',$user_id)
->first();
if ($is_same_amount) {
$message = Product::NOT_UNIQUE;
$is_same_amount->message = $message;
$is_same_amount->save();
$status = 0;
}
if ($status == 1) {
$max_amount = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->max('amount');
if($max_amount > $bid_amount){
$message = Product::UNIQUE_BUT_NOT_HIGHEST;
}
else if($max_amount < $bid_amount){
$message = Product::HIGHEST_UNIQUE_BID;
}
}
$checkInsert = Bid::insertGetId([
'product_id'=>$request->product_id,
'user_id'=>$user_id,
'amount'=>$bid_amount,
'remaining_bidding'=>$total_bid,
"message"=>$message
]);
$higest_unique_value = Bid::where(['product_id'=>$request->product_id])
->where('message','!=',Product::NOT_UNIQUE)
->orderBy('amount','DESC')
->first();
if ($higest_unique_value) {
Bid::where(['product_id'=>$request->product_id])
->where('id','!=',$higest_unique_value->id)
->where('message','!=',Product::NOT_UNIQUE)
->update(["message"=>Product::UNIQUE_BUT_NOT_HIGHEST]);
$higest_unique_value->message = Product::HIGHEST_UNIQUE_BID;
$higest_unique_value->save();
}
// if ($higest_unique_value) {
// add_Winner($productDetail->id,$higest_unique_value->id,$higest_unique_value->amount);
// }
if($message) {$ret_msg = $message;}
}
// $insert_status[]=$checkInsert;
if ($total_bid <= 0 || $max_bid >= 100) {
break;
}
$max_bid++;
}
}
if($request->product_id) updateUsersBid($request->product_id,$total_bid);
}
return [
"message"=>$ret_msg,
"total_bit"=>getTotalBid($request->product_id),
"status"=>true,
"i"=>$i,
"range"=>$range,
];
}
public function storeBiddingForm(Request $request){
if($request->filled('min_amount') && $request->filled('max_amount')){
return $this->bulkbid($request);
}
if($request->filled('amount')){
return $this->singelBid($request);
}
return [];
}
public function autoFetch(Request $request){
$is_expire = false;
$bidder_leader_list_html = view("partials.bidder_leader_list_html",["product_id"=>$request->product_id])->render();
$last_bidders_html = view("partials.last_bidders_html",["product_id"=>$request->product_id])->render();
$current_user_bid_html = view("partials.current_user_bid_html",["product_id"=>$request->product_id])->render();
$leader_user_info = view("partials.leader_user_info",["product_id"=>$request->product_id])->render();
$productDetail = Product::find($request->product_id);
if (isExpire($productDetail->expired_at)) {
$is_expire = true;
}else{
$is_expire = false;
}
return ([
'bidder_leader_list'=>$bidder_leader_list_html,
'last_bidders_html'=>$last_bidders_html,
'current_user_bid_html'=>$current_user_bid_html,
// 'leader_img'=>$leader_img,
// 'leader_name'=>$leader_name,
// 'statue'=>'1',
'leader_user_info'=>$leader_user_info,
'is_expire'=>$is_expire,
]);
}
public function addPackage(Request $request)
{
$package = BidTransaction::where('product_id',$request->product_id)
->where('user_id',\Auth::user()->id)
->where('type',$request->type)
->first();
if($package){
return Response::json(["message"=>"already addes","status"=>false]);
}
$package_rendend = new BidTransaction();
$package_rendend->product_id = $request->product_id;
$package_rendend->user_id = \Auth::user()->id;
$package_rendend->type = $request->type;
$package_rendend->amount = $request->price;
$package_rendend->total = $request->total_bit;
$package_rendend->save();
// $total_bit = BidTransaction::where('product_id',$request->product_id)
// ->where('user_id',\Auth::user()->id)
// ->select("total")
// ->sum("total");
if (\Auth::check()) {
// $user = \Auth::user();
// $user->total_bid = (int)$user->total_bit + (int)$package_rendend->total;
// $user->save();
increaseBid($request->product_id,$request->total_bit);
}
$total_bit =getTotalBid($request->product_id);
return Response::json(["message"=>"successfully added","status"=>true,"total_bit"=>$total_bit]);
}
}
Function Calls
None |
Stats
MD5 | d58b378e81841eaee68277617534a63b |
Eval Count | 0 |
Decode Time | 65 ms |