Fix bug update basket / cron / stat on panier
This commit is contained in:
parent
34feeb3179
commit
ec3ddace4e
3 changed files with 52 additions and 22 deletions
|
|
@ -120,27 +120,35 @@ class Kernel extends ConsoleKernel
|
|||
$coupons = $campagne->coupons()->get();
|
||||
foreach ($coupons as $coupon) {
|
||||
if ($campagne->camp_type == 0 || $campagne->camp_type == 2) { //Calcul des BR consommé pour les murs
|
||||
$count = Mur::where(['mur_couponId' => $coupon->coupon_id, 'mur_campid' => $campagne->camp_id])->whereBetween('mur_createdate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')])->count();
|
||||
} else { //Calcul des BR consommé pour les paniers
|
||||
$count = 0;
|
||||
$paniers = Panier::where('panier_campId', $campagne->camp_id)->where(function($query) use ($dateStart){
|
||||
$query->whereBetween('panier_createdate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')])
|
||||
->orWhereBetween('panier_updatedate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')]);
|
||||
})->get();
|
||||
foreach ($paniers as $panier) {
|
||||
$panierContentCount = $panier->panierContents()->where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_printed');
|
||||
$count = $count + $panierContentCount;
|
||||
}
|
||||
}
|
||||
// ---- Insertion en base de stats
|
||||
if($count > 0){
|
||||
$stat = new Statistique();
|
||||
$stat->stat_campId = $campagne->camp_id;
|
||||
$stat->stat_couponId = $coupon->coupon_id;
|
||||
$stat->stat_couponPrinted = $count;
|
||||
|
||||
$counts = Mur::selectRaw('count(*) as count, DATE_FORMAT(mur_createdate, "%Y-%m-%d") as date')
|
||||
->where(['mur_couponId' => $coupon->coupon_id, 'mur_campid' => $campagne->camp_id])
|
||||
->whereBetween('mur_createdate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')])
|
||||
->groupBy(DB::raw("DATE_FORMAT(mur_createdate, '%Y-%m-%d')"))
|
||||
->pluck('count', 'date');
|
||||
|
||||
$stat->save();
|
||||
}
|
||||
foreach($counts as $date => $count){
|
||||
$stat = new Statistique();
|
||||
$stat->stat_campId = $campagne->camp_id;
|
||||
$stat->stat_couponId = $coupon->coupon_id;
|
||||
$stat->stat_couponPrinted = $count;
|
||||
$stat->created_at = $date;
|
||||
$stat->save();
|
||||
}
|
||||
|
||||
}
|
||||
// else { //Calcul des BR consommé pour les paniers
|
||||
// $count = 0;
|
||||
// $paniers = Panier::where('panier_campId', $campagne->camp_id)->where(function($query) use ($dateStart){
|
||||
// $query->whereBetween('panier_createdate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')])
|
||||
// ->orWhereBetween('panier_updatedate', [$dateStart, Carbon::now()->setTime(23,59,59)->format('Y-m-d H:i:s')]);
|
||||
// })->get();
|
||||
// foreach ($paniers as $panier) {
|
||||
// $panierContentCount = $panier->panierContents()->where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_printed');
|
||||
// $count = $count + $panierContentCount;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
})->everyFifteenMinutes();
|
||||
|
|
|
|||
|
|
@ -168,6 +168,14 @@ class AjaxController extends Controller
|
|||
$newQtyAvailable = 0;
|
||||
$newQtyPrinted = $panierContent->panier_content_quantity + $panierContent->panier_content_printed;
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => $panierContent->panier_content_quantity]);
|
||||
|
||||
//Sauvegarde de stat
|
||||
$stat = new Statistique();
|
||||
$stat->stat_campId = $campagne->camp_id;
|
||||
$stat->stat_couponId = $cp->coupon_id;
|
||||
$stat->stat_couponPrinted = $panierContent->panier_content_quantity;
|
||||
$stat->save();
|
||||
|
||||
}else{
|
||||
if($panierContent->panier_content_quantity > 0){
|
||||
$coupons .= '<img src="'.$imgCoupon.'" border="0" style="display:block;width:165mm;"/>';
|
||||
|
|
@ -176,6 +184,13 @@ class AjaxController extends Controller
|
|||
$newQtyAvailable = $panierContent->panier_content_quantity-1;
|
||||
$newQtyPrinted = $panierContent->panier_content_printed+1;
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
|
||||
//Sauvegarde de stat
|
||||
$stat = new Statistique();
|
||||
$stat->stat_campId = $campagne->camp_id;
|
||||
$stat->stat_couponId = $cp->coupon_id;
|
||||
$stat->stat_couponPrinted = 1;
|
||||
$stat->save();
|
||||
}
|
||||
}
|
||||
// ---- Mémorise l'impression
|
||||
|
|
@ -230,6 +245,13 @@ class AjaxController extends Controller
|
|||
if($nbCoupon % 3 == 0) $coupons .= '</div><div>';
|
||||
$newQtyAvailable = $panierContent->panier_content_quantity-1;
|
||||
$newQtyPrinted = $panierContent->panier_content_printed+1;
|
||||
|
||||
//Sauvegarde de stat
|
||||
$stat = new Statistique();
|
||||
$stat->stat_campId = $campagne->camp_id;
|
||||
$stat->stat_couponId = $cp->coupon_id;
|
||||
$stat->stat_couponPrinted = 1;
|
||||
$stat->save();
|
||||
}
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
// ---- Mémorise l'impression
|
||||
|
|
|
|||
|
|
@ -300,11 +300,11 @@ class PanierController extends Controller
|
|||
if(isset($request->refcamp) && $request->refcamp != ""){
|
||||
$refcamp = $request->refcamp;
|
||||
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
||||
if(!$campagne || $campagne->camp_published == 0 ){
|
||||
if(!$campagne || $campagne->camp_published == 0 || $campagne->camp_type != 1 || $campagne->camp_type != 3){
|
||||
|
||||
$log->log_params = json_encode(['refcamp' => $refcamp]);
|
||||
$log->log_statut = 'NOK';
|
||||
$log->log_message = "La campagne n'existe pas";
|
||||
$log->log_message = "La campagne n'existe pas ou n'est pas un panier";
|
||||
$log->save();
|
||||
|
||||
return Response::json([
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue