public function main() { $yearmonth = date("Y-m", strtotime("last month")); $statuses = CommissionAPI::call("presenter/{$yearmonth}/statuses"); foreach ($statuses as $presenterId => $color) { $this->PresenterType->updateStatus($presenterId, $yearmonth, $color); // Let the commission engine know this happened . . . // However, since there is not real action to be taken on a white, there is no need to report it. if (strtolower($color) != 'white') { try { $result = CommissionAPI::write("presenter/" . $presenterId . "/recognizedstatus", array("status" => strtolower($color), "date" => date("c"), "timestamp" => date("c"))); } catch (Exception $e) { $this->out("Error updating [{$presenterId}] to status [{$color}] based on [{$yearmonth}]."); } } } }
public function main() { $db = ConnectionManager::getDataSource('default'); $result = $db->query("Select date_sub(now(), interval 2 second) as timestamp"); $twoSecondsAgo = $result[0][0]["timestamp"]; $since = $this->SystemSetting->getSystemSetting("commission_load", "0000-00-00"); $newPresenters = $this->Presenter->findChanges($twoSecondsAgo, $since); foreach ($newPresenters as $presenter) { $eligibleRaceToStart = $presenter['Presenter']['default_locale'] == 'es_US'; if ($eligibleRaceToStart) { $result = $this->AdminUserAudit->query("Select count(*) as changes\r\n from admin_user_audits\r\n Where reference_id = " . (int) $presenter['Presenter']['id'] . " and reference_name = 'presenters.default_locale' and notes = 'Admin3 sponsor default locale change' "); if ($result[0][0]['changes'] == 0) { $eligibleRaceToStart = true; } else { $eligibleRaceToStart = false; } } //getTypeId requires presenter_sequence_id $presenterRank = $this->PresenterType->getRecognizedStatus($presenter['Presenter']['id']); if ($presenterRank['id'] >= 8) { //To get on the Wall of Influence in USD, earn 83333.33 in one month. Alter for other markets $goalForWall = $this->Market->getPayPegRate($presenter['Presenter']['market_id']) * 83333.33; $wallInfluence = $this->RoyaltiesEarned->isWallInfluence($presenter['Presenter']['id'], $goalForWall); } else { $wallInfluence = false; } $result = CommissionAPI::write("presenter/" . $presenter['Presenter']['id'], array("parentId" => $presenter['Presenter']['id'] == 1 ? 0 : $presenter['Presenter']['sponsor_id'], "date" => date("c", strtotime($presenter['Presenter']['consent_to_agreements'])), "name" => $presenter['User']['first_name'] . " " . $presenter['User']['last_name'], "presenter_id" => $presenter['Presenter']['presenter_sequence_id'], "image" => $presenter['User']['largeimage'], "terminated_date" => $presenter['Presenter']['terminated_date'], "timestamp" => date("c", strtotime($presenter['Presenter']['_auditdate'])), "cat1" => $eligibleRaceToStart ? $presenter['Presenter']['default_locale'] : '', "wallInfluence" => $wallInfluence)); } $newOrders = $this->Order->findChanges($twoSecondsAgo, $since); foreach ($newOrders as $order) { $presenterId = $order['Order']['presenter_id']; if ($presenterId == 0) { continue; } $status = "rejected"; //if(in_array($order['Order']['order_status_id'], array(3,4,5,8))) { MIKEFIX if ($this->Order->isCommissionable($order['Order']['order_status_id'])) { $status = "accepted"; } $result = CommissionAPI::write("order/" . $order['Order']['id'], array("parentId" => $presenterId, "state" => $status, "date" => date("c", strtotime($order['Order']['date_completed'])), "retail" => Money::fromString($order['Order']['commissionable_total'])->intVal(), "wholesale" => Money::fromString($order['Order']['commissionable_total'])->times(0.75)->intVal(), "timestamp" => date("c", strtotime($order['Order']['_auditdate'])))); } $this->SystemSetting->saveSetting("commission_load", $twoSecondsAgo); print "Done"; }