我遇到了一个循环混乱,实际上,我正在尝试检查,
第一个条件:如果凭证类型是AMOUNT = AMOUNT
并且value > 0 and $totalRules <= 1
意味着这是用户第一次使用优惠券,然后让用户使用它。
第二个条件:我正在检查是否AMOUNT = AMOUNT
并且value > 0 and $totalRules >=1
意味着用户已经使用了优惠券。
第三条件:如果这一次用户选择了不同AMOUNT !=AMOUNT
的$totalRules >=1
优惠券,可能是 PERCENT 类型,那么我们不允许用户使用此优惠券。
现在,第一次,代码工作正常,但如果刷新页面,即使我使用了其他条件也变得真实break;
谁能帮我解决这个问题?我知道我需要改进该代码,我需要前辈的帮助。
$vDetail = array('AMOUNT', 'ONLY'); // For now check if the coupon type is AMOUNT (set from admin)
$voucherAllowed = 1; // Total number of voucher allowed, Global variable.
$totalRules = 1; // First tiem it'll be 0, then always adds 1 in that variable to check if user has already used any coupon.
$voucherTypeArray ['AMOUNT'] = 8.00;
$voucherTypeArray ['PERCENT'] = 0.00;
foreach($voucherTypeArray as $thisVoucher => $vValue )
{
echo "$vDetail[0] == $thisVoucher && $vValue>0 && $totalRules <= $voucherAllowed <br>";
if($vDetail[0]==$thisVoucher && $vValue>0 && (int)$totalRules <= $voucherAllowed)
{ $throwError = '0'; break; } // Continue to the next rule and add this one.
elseif($vDetail[0]==$thisVoucher && $vValue > 0 && (int)$totalRules >= $voucherAllowed)
{
$throwError = "Only $voucherAllowed voucher can be redeem at this time.";
break;
}
elseif($vDetail[0]!=$thisVoucher && (int)$totalRules >= $voucherAllowed)
{
$throwError = 'aYou cannot redeem this voucher at this time.';
break;
}
}