Ejemplo n.º 1
0
 public static function checkDeactivateTariffUsers()
 {
     $activePaids = UsersTariffPlans::model()->findAll('date_end <= NOW() AND status=' . UsersTariffPlans::STATUS_ACTIVE);
     if ($activePaids) {
         $users = array();
         foreach ($activePaids as $paid) {
             $allow = true;
             $tariffInfo = TariffPlans::getFullTariffInfoById($paid->tariff_id);
             if ($tariffInfo && $tariffInfo['duration'] <= 0 && !$paid->setByAdmin) {
                 $allow = false;
             }
             if ($allow) {
                 $paid->status = UsersTariffPlans::STATUS_NO_ACTIVE;
                 if (!$paid->update(array('status'))) {
                     //deb($paid->getErrors());
                 }
                 $users[$paid->user_id] = $paid->user_id;
             }
         }
         if ($users) {
             TariffPlans::deactivateUserAdsByTariffPlan($users);
         }
     }
 }