PHP Code:
<?php
// hour minute second month day year
require 'connections.php';
$sunrises = (30 * 24 * 60 * 60); //days x hours x minutes x seconds
$now = time();
$issue_rewards = array();
$query = mysql_query("SELECT * FROM orders_total WHERE class ='ot_subtotal'");
$cID = '';
$date = '';
while($row = mysql_fetch_assoc($query)){
$updates = array();
$query2 = mysql_query("SELECT * FROM orders_status_history WHERE orders_id ='$row[orders_id]'");
while($row2 = mysql_fetch_assoc($query2)){
$updates[] = $row2['orders_status_id'];
}
if(in_array('3', $updates) && !in_array('5', $updates) && !in_array('6', $updates) && !in_array('111', $updates) && !in_array('107', $updates) && !in_array('109', $updates)){
$round_val = round($row['value'], PHP_ROUND_HALF_DOWN);
//2008-01-18 18:16:51
$o_get_date_time = mysql_query("SELECT * FROM orders WHERE orders_id ='$row[orders_id]'");
while($this_date_time = mysql_fetch_assoc($o_get_date_time)){
$dt_parts = explode(' ', $this_date_time['date_purchased']);
$dt_date = $dt_parts[0];
$dt_time = $dt_parts[1];
$cID = $this_date_time['customers_id'];
$date = $this_date_time['date_purchased'];
}
$d_parts = explode('-', $dt_date);
$mo = $d_parts[1]; $da = $d_parts[2]; $yr = $d_parts[0];
$t_parts = explode(':', $dt_time);
$hr = $t_parts[0]; $mn = $t_parts[1]; $se = $t_parts[2];
$odate_secs = mktime($hr, $mn, $se, $mo, $da, $yr);
//$recompile = $yr.'-'.$mo.'-'.$da.' '. $hr.':'.$mn.':'.$se;//testing here
$date_math = $now - $odate_secs;
if($date_math < $sunrises){
//insert these points as pending
echo $count . ": OK! Order ID: " . $row['orders_id'] . ' Will Get: ' . $round_val . ' ' . $recompile . ' PENDING<br />';
mysql_query("INSERT INTO reward_status_track (rewards_id,customers_id,orders_id,date,reward_points,status) VALUES ('',$cID,$row[orders_id],'$date',$round_val,'0')") or die(mysql_error());
$exisitng_check = mysql_query("SELECT * FROM reward_customer_points WHERE customers_id ='$cID'") or die(mysql_error());
$exis_chk_nums = mysql_num_rows($exisitng_check);
if($exis_chk_nums < 1){
mysql_query("INSERT INTO reward_customer_points (customers_id,reward_points,pending_points) VALUES ($cID,'0',$round_val)") or die(mysql_error());
}else{
while($existing_record = mysql_fetch_assoc($exisitng_check)){
//$existing_rp = $existing_record['reward_points'];
$existing_pp = $existing_record['pending_points'];
}
//$new_rp = $existing_rp + $round_val;
$new_pp = $existing_pp + $round_val;
mysql_query("UPDATE reward_customer_points SET pending_points=$new_pp WHERE customers_id=$cID") or die(mysql_error());
}
}else{
//insert these points as earned
echo $count . ": OK! Order ID: " . $row['orders_id'] . ' Will Get: ' . $round_val . ' ' . $recompile . ' EARNED!<br />';
mysql_query("INSERT INTO reward_status_track (rewards_id,customers_id,orders_id,date,reward_points,status) VALUES ('',$cID,$row[orders_id],'$date',$round_val,'1')") or die(mysql_error());
$exisitng_check = mysql_query("SELECT * FROM reward_customer_points WHERE customers_id ='$cID'") or die(mysql_error());
$exis_chk_nums = mysql_num_rows($exisitng_check);
if($exis_chk_nums < 1){
mysql_query("INSERT INTO reward_customer_points (customers_id,reward_points,pending_points) VALUES ($cID,$round_val,'0')") or die(mysql_error());
}else{
while($existing_record = mysql_fetch_assoc($exisitng_check)){
$existing_rp = $existing_record['reward_points'];
//$existing_pp = $existing_record['pending_points'];
}
$new_rp = $existing_rp + $round_val;
//$new_pp = $existing_pp + $round_val;
mysql_query("UPDATE reward_customer_points SET reward_points=$new_rp WHERE customers_id=$cID") or die(mysql_error());
}
}
}
}
?>
Bookmarks