
Originally Posted by
abcisme
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;");
}
So I guess I've messed up somewhere here. I'm hoping someone can help me figure this out.
I want to:
zen_reward_customer_points.reward_points - zen_reward_status_track.reward_points
WHEN
zen_reward_status_track date > 104 days ago
AND
zen_reward_status_track.customer_id = zen_reward_customer_points.customer_id
Then, I want to delete the record from zen_reward_status_track
Here's what I currently have:
Code:
$subset2="IFNULL((SELECT SUM(rp.reward_points) FROM ".TABLE_REWARD_STATUS_TRACK." rp WHERE cp.customers_id=rp.customers_id AND rp.status='1' AND rp.date<NOW()-INTERVAL 104 DAY),0)";
$housekeeping_subset=sprintf($subset2,REWARD_POINTS_HOUSEKEEPING);
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 104 DAY;");
}
This deletes the record from zen_reward_status_track, but doesn't delete the points from zen_reward_customer_points.reward_points
Can anyone help?
Bookmarks