Exemplo n.º 1
0
 public function listProducts($data)
 {
     if (is_array($data)) {
         $promotions = new Promotions();
         $product_ids = implode(",", array_keys($data));
         $query = $this->sql("SELECT products.id, products.name as product_name, products.photo as product_photo, price, categories.name as category_name, category_id FROM products JOIN categories ON categories.id = products.category_id WHERE products.id IN ({$product_ids})")->fetchAllAssoc();
         foreach ($query as $key => $item) {
             $discount = $promotions->getProductPromotion($item['id']);
             if ($discount) {
                 $query[$key]['discount'] = $discount;
             }
         }
         return $query;
     }
 }
Exemplo n.º 2
0
 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;
     */
 }
 /**
  * @param $id
  * @param Products $products
  * @param Reviews $reviews
  * @param Categories $categories
  * @param Promotions $promotions
  * @throws \Exception
  */
 public function getProduct($id, Products $products, Reviews $reviews, Categories $categories, Promotions $promotions)
 {
     $cart = $this->session->getSession()->cart ?: [''];
     $this->view->appendToLayout('body', "products.product");
     $this->view->display('layouts.main', ['product' => $products->get($id), 'cart' => $cart, 'promotion' => $promotions->getProductPromotion($id) ?: null, 'reviews' => $reviews->getForProduct($id), 'current_user_review' => $reviews->getForUser($this->auth->user()->id, $id), 'categories' => $categories->listAllNames()]);
 }
Exemplo n.º 4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $promotion = Promotions::find($id);
     if ($promotion != NULL) {
         $promotion->delete();
     }
     return redirect('promoter/promotion');
 }