奖励/忠诚度计划向所有人发放免费资金

the rewards / loyalty program is dishing out free money to everybody

我的应用程序通过每 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';
    }