我的应用程序通过每 15 个订单在收据/感谢页面上打印优惠券代码来奖励忠诚度。优惠券价值等于前 15 个订单之一的总价,随机拉动。
这已经工作了一段时间,但现在由于某种原因,每个新用户都在他们的第一笔订单上收到优惠券代码:
$count = dbFuncs::countRewardsProgress($_SESSION['user_id'])['count'];
$displayRewardsCode = dbFuncs::displayRewardsCode()['rewardsCode'];
if ( $count > 0 ) {
$remainder = $count % 15;
}
if($remainder == 0) {
echo "Congratulations, You've earned a $$previousOrderValueRoulette coupon code! We thank you for your continued business.";
echo "<br />";
echo "<br />";
echo 'Coupon code: ';
echo $displayRewardsCode;
dbFuncs::assignRewardsCode($previousOrderValueRoulette, $_SESSION['user_id'], $displayRewardsCode);
} else {
echo 'rewards progress: ';
echo $count;
echo '/15 orders completed';
}
如何确保客户每 15 个订单只收到一张优惠券?
因为如果$count
为 0,则 $reminder
未初始化,因此在下一个条件下它等于 0。
要解决,请更改第二个条件以检查$count
是否大于 0
if ( $count > 0 ) {
$remainder = $count % 15;
}
if($count > 0 && $remainder == 0) {
echo "Congratulations, You've earned a $$previousOrderValueRoulette coupon code! We thank you for your continued business.";
echo "<br />";
echo "<br />";
echo 'Coupon code: ';
echo $displayRewardsCode;
dbFuncs::assignRewardsCode($previousOrderValueRoulette, $_SESSION['user_id'], $displayRewardsCode);
} else {
echo 'rewards progress: ';
echo $count;
echo '/15 orders completed';
}