function calc_accts() { global $DB, $error_ar; echo "Billing accounts ...\n"; $start_time = microtime(1); //$n = 0; $account_result = $DB->make_select('Accounts'); //$account_result = $DB->make_select('Accounts', '', "`status`='Open'"); for ($n = 0; $account_row = $DB->row($account_result); $n++) { $status = $account_row['status']; $amount = $account_row['amount']; $bonustime = $account_row['bonustime']; //$statusinfo = $account_row['statusinfo']; $NOW = date('Y-m-d H:i:s'); $now = strtotime($NOW); //$now = time(); $addsql = array(); if ($status == 'Active') { $account = new Account(); $account->load($account_row); list($amount, $bonustime, $closetime) = $account->getBalance(); $ostperiod = $closetime - $now; $ostdays = round($ostperiod / iDAY, 0); $addsql['closetime'] = date('Y-m-d H:i:s', $closetime); if ($ostperiod + iDAY * $account->billing_opts['credit_days'] <= 0) { echo "Suspend account {$account->domain} (id={$account->id})\n"; if (ACTION) { if ($account->suspend(false)) { } $account->mail_send(3); } } elseif ($ostdays == 7 || $ostdays == 3 || $ostdays <= 1) { echo "Send mail to account {$account->domain} ({$account->contact->Email}) with '{$status}' status about close date in {$ostdays} days\n"; if (ACTION) { $account->mail_send(2); } } unset($account); $addsql['amount'] = $amount; $addsql['bonustime'] = $bonustime; } elseif ($status == 'Open') { $account = new Account(); $account->load($account_row); //$amount = 0; $bonustime = 0; $period_live = $now - strtotime($account_row['opentime']); $days_live = round($period_live / iDAY, 0); if ($days_live == 25) { if (ACTION) { $account->mail_send(2); } echo "Send mail to account {$account->domain} ({$account->contact->Email}) with '{$status}' status about close date in {$ostdays} days\n"; } elseif ($days_live >= 30) { echo "Close account {$account->domain} (id={$account->id})\n"; if (ACTION) { if ($account->suspend(false)) { } $account->mail_send(3); } } unset($account); //$addsql['amount'] = $amount; //$addsql['bonustime'] = $bonustime; } elseif ($status == 'Suspend') { $account = new Account(); $account->load($account_row); $period = $now - strtotime($account_row['closetime']); if ($period >= 60 * iDAY) { echo "Delete account {$account_row['domain']} (id={$account_row['AccountID']})\n"; if (ACTION) { log_event('delete account', 'notice', '', $account_row['AccountID'], $account_row['ResellerID']); $whm = new WhmAPI($account->ServerID); $result = $whm->killacct($account); if ($result) { //echo nl2br($whm->xml->rawout); } else { echo $whm->geterrmsg(); } } $addsql['status'] = 'Deleted'; //$addsql['statusinfo'] = "$statusinfo\nautomatic deleted $NOW"; } } elseif ($status == 'Deleted') { $addsql['lastproc'] = 0; // pack and archive account if closetime > 6 * iMON } elseif ($status == 'Staff') { // our accounts } else { $error_ar[] = "Unknown Status for account {$account_row['domain']} (id={$account_row['AccountID']})\n"; } if (ACTION) { $addsql['lastproc'] = $NOW; $result = $DB->make_update('Accounts', '`AccountID`=' . $account_row['AccountID'], $addsql); } //$n++; } echo "Finished Step. {$n} account calculated. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n"; }
public function unsuspend() { global $DB; log_event('unsuspend account', 'notice', '', $this->id, $this->reseller->id); $whm = new WhmAPI($this->ServerID); $result = $whm->unsuspend($this); if ($result) { $show = '<br />Аккаунт возобновлён <br />'; $show .= '<pre>' . $result . '</pre><br />'; $this->lastproc = iNOW_TEXT; $this->status = 'Active'; $DB->make_update('Accounts', '`AccountID`=' . $this->id, array('status' => $this->status, 'lastproc' => $this->lastproc)); if ($data = $DB->row($DB->make_select('Services', '*', "`AccountID`={$this->id} AND `name`='hosting'", 'opentime', 'DESC', 1))) { $serv = new Service_hosting(); $serv->load($data); $last = count($serv->mod) - 1; if ($serv->mod[$last]['time'] == 0) { // проблема, сервис открыт, а аккаунт в суспенде // так пусть так и будет } elseif (iNOW_UNIX - $serv->mod[$last]['opentime'] - $serv->mod[$last]['time'] > 3 * iDAY) { // Открываем новый сервис, если простой более 3х дней. TODO использовать billing_opts $serv->mod[] = $serv->mod[$last]; $serv->mod[$last + 1]['opentime'] = iNOW_UNIX; $serv->mod[$last + 1]['time'] = 0; } else { // если срок маленький, то пускай списывается прошлым сервисом $serv->mod[$last]['time'] = 0; } $serv->save(); } /* $result = $DB->make_select('Services', '*,UNIX_TIMESTAMP(opentime) as opentime,UNIX_TIMESTAMP(closetime) as closetime', "`AccountID`=$this->id AND `name`='hosting'", 'opentime', 'DESC', 1); if($data = $DB->row($result)) { if($data['closetime'] == 0) { // проблема, сервис открыт, а аккаунт в суспенде // так пусть так и будет }elseif(iNOW_UNIX - $data['closetime'] > 3*iDAY) { // Открываем новый сервис, если простой более 3х дней. TODO использовать billing_opts $serv = new Service_hosting(array('AccountID'=>$this->id, 'opentime'=>iNOW_TEXT, 'closetime'=>0, 'mod'=>$this->package->id)); $serv->add_service(); }else{ // если срок маленький, то пускай списывается прошлым сервисом Service::closeService($this->id, 'hosting', 0); } } */ } else { $show = $whm->geterrmsg(); } return $show; }