Files
crm.clientright.ru/modules/Contacts/tasks/SubscriptionDates.service

44 lines
1.9 KiB
Desktop File
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once 'modules/Users/Users.php';
require_once 'includes/Loader.php';
vimport ('includes.runtime.Globals');
vimport ('includes.runtime.BaseModel');
vimport ('includes.runtime.LanguageHandler');
global $adb;
// Поднимаем всех подписчиков, у кого была куплена подписка в бот
$query = 'select tg_id, date_buy_sub, date_sub_over from all_users_tg';
$result = $adb->pquery($query);
if ($adb->num_rows($result) > 0) {
for ($i == 0; $i < $adb->num_rows($result); $i++) {
$tgid = $adb->query_result($result, $i, "tg_id"); //tgid подписчика
$buy = $adb->query_result($result, $i, "date_buy_sub"); // Дата покупки подписки
$over = $adb->query_result($result, $i, "date_sub_over"); // Дата истечения подписки
if (!empty($buy) or !empty($over)) {
// Если даты заполнены - значит клиент в подписке
$subscribed = '1';
} else {
// Или нет
$subscribed = '0';
}
// Найдем Контакта по его tgid, который у нас хранится почему-то в поле phone
$getquery = 'select c.contactid
from vtiger_contactdetails c
left join vtiger_crmentity e on e.crmid = c.contactid
where e.deleted = 0 and c.phone = ?';
$getresult = $adb->pquery($getquery, array($tgid));
if ($adb->num_rows($getresult) > 0) {
// Если нашелся - выкупим его id
$contactid = $adb->query_result($getresult, 0, "contactid");
// И обновим у него в доп.полях даты покупки и истечения подписки, а так же признак подписки
$updquery = 'update vtiger_contactscf set cf_1873 = ?, cf_1875 = ?, cf_1877 = ? where contactid = ?';
$updresult = $adb->pquery($updquery, array($subscribed, $buy, $over, $contactid));
}
}
}