public function getPromo(request $request) { $maxDiscount = 0; $bestPromo = null; if ($request['type_id'] == config('constants.credit')) { $promo_disc = Promotions::where('event_id', $request['event_id'])->where('access_id', 2)->where('startday', '<', Carbon::now())->where('endday', '>', Carbon::now())->get(); } else { if ($request['type_id'] == config('constants.cash')) { $promo_disc = Promotions::where('event_id', $request['event_id'])->where('access_id', 1)->where('startday', '<', Carbon::now())->where('endday', '>', Carbon::now())->get(); } else { $promos = null; return null; } } $promos = Promotions::where('event_id', $request['event_id'])->where('typePromotion', 2)->where('startday', '<', Carbon::now())->where('endday', '>', Carbon::now())->get(); $promos = $promos->merge($promo_disc); if ($promos) { foreach ($promos as $promo) { if ($promo->typePromotion == config('constants.discount')) { if ($promo->desc > $maxDiscount) { $pu = Zone::find($request['zone_id'])->price; $quantity = $request['quantity']; $pt = $pu * $quantity; $pd = $pt - $pt * $promo->desc / 100; $maxDiscount = $promo->desc; $bestPromo = ['id' => $promo->id, 'amount' => $pd]; } } else { if ($promo->zone_id == $request['zone_id']) { $pu = Zone::find($request['zone_id'])->price; $quantity = $request['quantity']; $pt = $pu * $quantity; $discTickets = $quantity / $promo->carry; $discTickets = floor($discTickets); $pd = $pt - $discTickets * $pu * ($promo->carry - $promo->pay); $desc = 100 - $pd / $pt * 100; if ($desc >= $maxDiscount) { $maxDiscount = $desc; $promo->desc = $desc; $bestPromo = ['id' => $promo->id, 'amount' => $pd]; } } } } } return $bestPromo; /* $maxDiscount = 0; $bestPromo = null; if($request['type_id']==config('constants.credit')){ $promo_disc = Promotions::where('event_id',$request['event_id'])->where('access_id',2)->where('startday','<',Carbon::now())->where('endday','>',Carbon::now())->get(); }else if($request['type_id']==config('constants.cash')){ $promo_disc = Promotions::where('event_id',$request['event_id'])->where('access_id',1)->where('startday','<',Carbon::now())->where('endday','>',Carbon::now())->get(); }else{ $promos = null; } $promos = Promotions::where('event_id',$request['event_id'])->where('typePromotion',2)->where('startday','<',Carbon::now())->where('endday','>',Carbon::now())->get(); $promos = $promos->merge($promo_disc); if($promos){ foreach ($promos as $promo) { if ($promo->typePromotion == config('constants.discount')){ if ($promo->desc > $maxDiscount){ $maxDiscount = $promo->desc; $bestPromo = $promo; } }else{ if($promo->zone_id == $request['zone_id']){ $pu = Zone::find($request['zone_id'])->price; $quantity = $request['quantity']; $pt = $pu * $quantity; $discTickets = $quantity / $promo->carry; $discTickets = floor($discTickets); $pd = $pt - $discTickets*$pu; $desc = 100 - ($pd/$pt)*100; if ($desc >= $maxDiscount){ $maxDiscount = $desc; $promo->desc = $desc; $bestPromo = $promo; } } } } } return $bestPromo; */ }
public function promotion() { $promotions = Promotions::where('user_id', Auth::user()->id)->get(); return view('internal.promoter.promotions', ['promotions' => $promotions]); }