Beispiel #1
0
 /**
  * Если включили бесплатный канал, активируем для всех пользователей подписку.
  * 
  * @return object 
  */
 public static function OnBeforeUpdate(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $primary = $event->getParameter("id");
     $data = $event->getParameter("fields");
     $res = self::getById($primary);
     $arChannel = $res->fetch();
     $price = floatval($arChannel["UF_PRICE_H24"]);
     if ($data["UF_ACTIVE"] && !$arChannel["UF_ACTIVE"] && $price == 0) {
         //Найдем пользователей, для кого эта подписка была включена
         $userIds = array();
         $result = SubscribeTable::getList(array('filter' => array("=UF_CHANNEL_ID" => $data["ID"]), 'select' => array("ID", "UF_USER_ID")));
         while ($arSub = $result->fetch()) {
             $userIds[$arSub["UF_USER_ID"]] = $arSub["ID"];
         }
         $CSubscribe = new CSubscribe("CHANNEL");
         $dbUsers = \CUser::GetList($by = "EMAIL", $order = "desc", array("ACTIVE" => "Y"));
         while ($arUser = $dbUsers->Fetch()) {
             if (!array_key_exists($arUser["ID"], $userIds)) {
                 $CSubscribe->setUserSubscribe($data["ID"], $arUser["ID"]);
             } else {
                 $sub_id = $userIds[$arUser["ID"]];
                 $CSubscribe->updateUserSubscribe($sub_id, array("UF_ACTIVE" => 1));
             }
         }
     }
     return $result;
 }
Beispiel #2
0
 function OnBeforeUserDeleteHandler($user_id)
 {
     \CModule::IncludeModule("iblock");
     \CModule::IncludeModule("sale");
     //Привязки к соц. сетям
     $arrFilter = array("IBLOCK_ID" => USER_SOCIAL_IB, "PROPERTY_USER_ID" => $user_id);
     $arSelect = array("ID");
     $rsRes = \CIBlockElement::GetList($arOrder, $arrFilter, false, false, $arSelect);
     while ($arItem = $rsRes->GetNext()) {
         \CIBlockElement::Delete($arItem["ID"]);
     }
     //Удаляем записи
     $result = \Hawkart\Megatv\RecordTable::getList(array('filter' => array("UF_USER_ID" => $user_id), 'select' => array("ID")));
     while ($arRecord = $result->fetch()) {
         \CRecordEx::delete($arRecord["ID"]);
     }
     //Удаляем счет
     if ($arAccount = \CSaleUserAccount::GetByUserID($user_id, "RUR")) {
         \CSaleUserAccount::Delete($arAccount["ID"]);
     }
     //Удаляем заказы
     $arFilter = array("USER_ID" => $user_id);
     $db_sales = \CSaleOrder::GetList(array("DATE_INSERT" => "ASC"), $arFilter);
     while ($ar_sales = $db_sales->Fetch()) {
         \CSaleOrder::Delete($ar_sales["ID"]);
     }
     //Удаляем подписки
     $result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("=UF_USER_ID" => $user_id), 'select' => array("ID")));
     if ($arSub = $result->fetch()) {
         \Hawkart\Megatv\SubscribeTable::delete($arSub["ID"]);
     }
 }
Beispiel #3
0
 /**
  * Get subscribe active channels ids by city for authorized user
  *
  * @return array  
  */
 public static function getActiveIdByCityByUser()
 {
     global $USER;
     if ($USER->IsAuthorized()) {
         $arChannels = self::getActiveByCity();
         $selectedChannels = array();
         $arFilter = array("=UF_ACTIVE" => 1, "=UF_USER_ID" => $USER->GetID(), ">UF_CHANNEL_ID" => 0);
         $arSelect = array("UF_CHANNEL_ID");
         $result = SubscribeTable::getList(array('filter' => $arFilter, 'select' => $arSelect));
         while ($arSub = $result->fetch()) {
             $selectedChannels[] = $arSub["UF_CHANNEL_ID"];
         }
         $ids = array();
         foreach ($arChannels as $key => $arChannel) {
             if (in_array($arChannel["UF_CHANNEL_BASE_ID"], $selectedChannels)) {
                 $ids[] = $arChannel["ID"];
             }
         }
         unset($selectedChannels);
         unset($arChannels);
         return $ids;
     } else {
         return self::getActiveIdByCity();
     }
 }
Beispiel #4
0
 /**
  * Billing by all users at 3-30
  */
 public static function dailyAllUsers()
 {
     global $DB;
     $table = \Hawkart\Megatv\SubscribeTable::getTableName();
     $time_update = "03:30:00";
     $datetime = new \Bitrix\Main\Type\Datetime(date("Y-m-d " . $time_update), 'Y-m-d H:i:s');
     $datetime_next_date = new \Bitrix\Main\Type\Datetime(date('Y-m-d' . $time_update, strtotime('+1 day')), 'Y-m-d H:i:s');
     $datetime_from_db = date("d.m.Y " . $time_update);
     $datetime_to_db = date("d.m.Y " . $time_update, strtotime('+1 day'));
     /**
      * Get all users
      */
     $arUsers = array();
     $arFilter = array("ACTIVE" => "Y");
     $rsUsers = \CUser::GetList($by = "LAST_NAME", $order = "asc", $arFilter);
     while ($arUser = $rsUsers->GetNext()) {
         $arUsers[$arUser["ID"]] = $arUser;
     }
     /**
      * Get all priced subscribe for all users
      */
     $arSubscribeUsers = array();
     $result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("UF_ACTIVE" => 1, ">UF_CHANNEL_ID" => 0, ">UF_CHANNEL.UF_PRICE_H24" => 0, "<=UF_DATETIME_TO" => $datetime), 'select' => array("ID", "PRICE" => "UF_CHANNEL.UF_PRICE_H24", "UF_USER_ID")));
     while ($arSub = $result->fetch()) {
         $arSubscribeUsers[$arSub["UF_USER_ID"]][] = array("ID" => $arSub["ID"], "PRICE" => $arSub["PRICE"]);
     }
     $result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("UF_ACTIVE" => 1, ">UF_SERVICE_ID" => 0, ">UF_SERVICE.UF_PRICE" => 0), 'select' => array("ID", "PRICE" => "UF_SERVICE.UF_PRICE", "UF_USER_ID")));
     while ($arSub = $result->fetch()) {
         $arSubscribeUsers[$arSub["UF_USER_ID"]][] = array("ID" => $arSub["ID"], "PRICE" => $arSub["PRICE"]);
     }
     /**
      * Make transaction for 1 day for all users
      */
     foreach ($arSubscribeUsers as $user_id => $arSubscribes) {
         $daily_price = 0;
         foreach ($arSubscribes as $arSubscribe) {
             $daily_price += $arSubscribe["PRICE"];
         }
         $balance = \CUserEx::getBudget($user_id);
         if ($balance > 0 && $daily_price > 0) {
             \CSaleAccountEx::transaction(-1 * $daily_price, $user_id, "Оплата услуг за " . date('d.m.Y'));
             $strSql = "UPDATE " . $table . " SET UF_DATETIME_TO=curdate() + INTERVAL 1 DAY + INTERVAL 3 HOUR + INTERVAL 30 MINUTE WHERE UF_USER_ID=" . $user_id;
             $res = $DB->Query($strSql, false, $err_mess . __LINE__);
             //Send email to user to add money to budget for 3 days
             if ($balance < $daily_price * 2) {
                 \CEvent::SendImmediate("NOTIFICATION_PAY_AFTER_DAYS", SITE_ID, array("EMAIL_TO" => $arUsers[$user_id]["EMAIL"], "PRICE" => $daily_price * 5));
             }
         }
     }
 }
Beispiel #5
0
 public function updateUserSubscribe($ID, $arFields)
 {
     /*if($arFields["UF_ACTIVE"]=="Y")
           $arFields["UF_ACTIVE"] = 1;
           
       if($arFields["UF_ACTIVE"]=="N")
           $arFields["UF_ACTIVE"] = 0;*/
     $result = \Hawkart\Megatv\SubscribeTable::update($ID, $arFields);
     if ($result->isSuccess()) {
         return true;
     } else {
         return implode(', ', $result->getErrors());
     }
 }
 public function down()
 {
     global $APPLICATION;
     \Bitrix\Main\Loader::includeModule("highloadblock");
     $arHlblock = \Bitrix\Highloadblock\HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => \Hawkart\Megatv\SubscribeTable::getTableName())))->fetch();
     if ($arHlblock) {
         $arProps = array("UF_DATETIME_TO");
         foreach ($arProps as $prop_name) {
             $oUserTypeEntity = new \CUserTypeEntity();
             $resProperty = \CUserTypeEntity::GetList(array(), array('ENTITY_ID' => 'HLBLOCK_' . $arHlblock["ID"], 'FIELD_NAME' => $prop_name));
             if ($aUserHasField = $resProperty->Fetch()) {
                 $oUserTypeEntity->Delete($aUserHasField['ID']);
                 $this->outSuccess("Свойство 'Дата окончания подписки' удалено!");
             }
         }
     }
 }
Beispiel #7
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
global $USER;
CModule::IncludeModule("iblock");
$arResult["CHANNELS"] = array();
$selectedServices = array();
$arServices = array();
//get service subscribe list
$result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("UF_ACTIVE" => 1, "=UF_USER_ID" => $USER->GetID(), ">UF_SERVICE_ID" => 0), 'select' => array("UF_SERVICE_ID")));
while ($arSub = $result->fetch()) {
    $selectedServices[] = $arSub["UF_CHANNEL_ID"];
}
//get all services
$result = \Hawkart\Megatv\ServiceTable::getList(array('filter' => array("UF_ACTIVE" => 1), 'select' => array("ID", "UF_TITLE", "UF_TEXT", "UF_PRICE", "UF_DISK_TYPE", "UF_DESC")));
while ($arService = $result->fetch()) {
    if (in_array($arService["ID"], $selectedServices)) {
        $arService["SELECTED"] = true;
    }
    $arServices[] = $arService;
}
$arResult["SERVICES"] = $arServices;
$rsUser = CUser::GetByID($USER->GetID());
$arUser = $rsUser->Fetch();
$arResult["USER"] = $arUser;
if (floatval($arResult["USER"]["UF_CAPACITY_BUSY"]) == 0 || floatval($arResult["USER"]["UF_CAPACITY"]) == 0) {
    $arResult["DISK_SPACE_FILLED"] = 0;
} else {
    $arResult["DISK_SPACE_FILLED"] = round(floatval($arResult["USER"]["UF_CAPACITY_BUSY"]) / floatval($arResult["USER"]["UF_CAPACITY"]), 4);
Beispiel #8
0
<?php

define('STOP_STATISTICS', true);
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
$GLOBALS['APPLICATION']->RestartBuffer();
global $USER;
if (!is_object($USER)) {
    $USER = new CUser();
}
$result = array();
$channelID = intval($_REQUEST["channelID"]);
$status = htmlspecialcharsbx($_REQUEST["status"]);
//get subcribe channel list
$selectedChannels = array();
$result = \Hawkart\Megatv\SubscribeTable::getList(array('filter' => array("=UF_USER_ID" => $USER->GetID(), ">UF_CHANNEL_ID" => 0), 'select' => array("UF_CHANNEL_ID", "ID")));
while ($arSub = $result->fetch()) {
    $selectedChannels[$arSub["UF_CHANNEL_ID"]] = $arSub["ID"];
}
//check disable sub
$result = \Hawkart\Megatv\ChannelBaseTable::getList(array('filter' => array("=UF_FORBID_REC" => 1, "=ID" => $channelID), 'select' => array("ID")));
if ($arChannel = $result->fetch()) {
    exit(json_encode(array("status" => "disable", "error" => "Нельзя подписаться на канал")));
}
//update subsribes
$CSubscribe = new \Hawkart\Megatv\CSubscribe("CHANNEL");
if (!isset($selectedChannels[$channelID])) {
    $result = $CSubscribe->setUserSubscribe($channelID);
} else {
    if ($status == "enable") {
        $active = 1;
    } else {