
Originally Posted by
abcisme
I need points to expire 90 days after they are earned.
This code is a good start, but I can see a problem...
Say we want rewards to expire at 90 days.
Day 1: Customer places order. Earns 100 points.
Day 30: Customer places another order. Earns 100 points.
Day 90: Only 100 points should be removed, not all of their points, which is what this code would do.
Has anyone determined how to properly remove earned points after a certain time period?
Ok, I am not a programmer, so I am taking a stab in the dark at this.. but looking at the housekeeping function, if I create a subset for housekeeping which specifies earned points instead of pending points.. then switched the housekeeping function to reflect rewards_points instead of pending_points, it should work to remove any earned points instead of pending points. Right?
So pending points will switch to earned after the sunrise period, then be removed after the housekeeping period... Does this look correct?
Code:
function CleanupRewardPointHistory()
{
global $db,$messageStack;
$subset="IFNULL((SELECT SUM(rp.reward_points) FROM ".TABLE_REWARD_STATUS_TRACK." rp WHERE cp.customers_id=rp.customers_id AND rp.status='".STATUS_PENDING."' AND rp.date<NOW()-INTERVAL %s DAY),0)";
$subset2="IFNULL((SELECT SUM(rp.reward_points) FROM ".TABLE_REWARD_STATUS_TRACK." rp WHERE cp.customers_id=rp.customers_id AND rp.status='".STATUS_PROCESSED."' AND rp.date<NOW()-INTERVAL %s DAY),0)";
$sunrise_subset=sprintf($subset,REWARD_POINTS_SUNRISE_PERIOD);
$housekeeping_subset=sprintf($subset2,REWARD_POINTS_HOUSEKEEPING);
if(REWARD_POINTS_SUNRISE_PERIOD>0)
if($db->Execute("UPDATE ".TABLE_REWARD_CUSTOMER_POINTS." cp, ".TABLE_REWARD_STATUS_TRACK." rp SET cp.reward_points=cp.reward_points+".$sunrise_subset.",cp.pending_points=cp.pending_points-".$sunrise_subset." WHERE cp.customers_id=rp.customers_id;"))
$db->Execute("UPDATE ".TABLE_REWARD_STATUS_TRACK." SET status=".STATUS_PROCESSED." WHERE status=".STATUS_PENDING." AND date<NOW()-INTERVAL ".REWARD_POINTS_SUNRISE_PERIOD." DAY;");
if(REWARD_POINTS_HOUSEKEEPING>0)
if($db->Execute("UPDATE ".TABLE_REWARD_CUSTOMER_POINTS." cp, ".TABLE_REWARD_STATUS_TRACK." rp SET cp.reward_points=cp.reward_points-".$housekeeping_subset." WHERE cp.customers_id=rp.customers_id;"))
$db->Execute("DELETE FROM ".TABLE_REWARD_STATUS_TRACK." WHERE date<NOW()-INTERVAL ".(int)REWARD_POINTS_HOUSEKEEPING." DAY;");
}
Bookmarks