1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
notification.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\Marketplace;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Config\Option;
8use Bitrix\Main\SystemException;
9use Bitrix\Main\Type\Date;
10use Bitrix\Rest\AppTable;
11use Bitrix\Rest\Engine\Access;
12use Bitrix\Rest\Integration\Bitrix24\Bitrix24;
13
14Loc::loadMessages(__FILE__);
15
21{
22 private const MODULE_ID = 'rest';
23 private const OPTION_ACCESS_NOTIFICATION = 'rest_access_notification';
24 private const OPTION_LAST_CHECK_ACCESS_NOTIFICATION = 'last_check_rest_access_notify';
25 private const OPTION_LAST_CHECK_NOTIFICATION = 'last_check_rest_notify';
26 private const OPTION_NOTIFICATION_URL = 'rest_notify_url';
27 private const CODE_CHECK_BY_AGENT = [
28 'REST_BUY',
29 'SUBSCRIPTION_MARKET_DEMO_END',
30 'SUBSCRIPTION_MARKET_TARIFF_MARKET',
31 'SUBSCRIPTION_MARKET_TRIAL_END',
32 ];
33 private static $timestampNotifyDays = 259200; // 3 * 86400
34 private static $codeToNotification = [
35 'rest_buy' => 'REST_BUY',
36 'limit_subscription_market_demomarket_end' => 'SUBSCRIPTION_MARKET_DEMO_END',
37 'limit_subscription_market_tarifwithmarket' => 'SUBSCRIPTION_MARKET_TARIFF_MARKET',
38 'plus_need_trial' => 'SUBSCRIPTION_MARKET_TRIAL_END',
39 ];
40
44 public static function get()
45 {
46 $result = false;
47 $option = Option::get(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, '');
48
49 if (isset(static::$codeToNotification[$option]) && static::$codeToNotification[$option])
50 {
51 $option = static::$codeToNotification[$option];
52 }
53
54 if ($option !== '')
55 {
56 $url = Option::get(static::MODULE_ID, static::OPTION_NOTIFICATION_URL, '');
57 if ($url === '')
58 {
59 $url = Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_URL');
60 if ($option === 'REST_BUY' && Loader::includeModule('bitrix24'))
61 {
62 $prefix = \CBitrix24::getLicensePrefix();
63 if ($prefix === 'by')
64 {
65 $url = 'https://goodbye-2020.bitrix24.site/';
66 }
67 elseif ($prefix === 'kz')
68 {
69 $url = 'https://goodbye2020.bitrix24.site/';
70 }
71 elseif ($prefix === 'ua')
72 {
73 $url = 'https://skilky-mozhna.bitrix24site.ua/';
74 }
75 elseif ($prefix === 'ru')
76 {
77 $url = 'https://goodbye2020.bitrix24.tech/';
78 }
79 elseif ($prefix === 'en')
80 {
81 $url = 'https://www.bitrix24.com/promo/sales/holiday-sale/';
82 }
83 elseif ($prefix === 'jp')
84 {
85 $url = 'https://www.bitrix24.jp/promo/sales/holiday-sale/';
86 }
87 elseif ($prefix === 'pl')
88 {
89 $url = 'https://www.bitrix24.pl/promo/sales/holiday-sale/';
90 }
91 elseif ($prefix === 'it')
92 {
93 $url = 'https://www.bitrix24.it/promo/sales/holiday-sale/';
94 }
95 elseif ($prefix === 'br')
96 {
97 $url = 'https://www.bitrix24.com.br/promo/sales/holiday-sale/';
98 }
99 elseif ($prefix === 'fr')
100 {
101 $url = 'https://www.bitrix24.fr/promo/sales/holiday-sale/';
102 }
103 elseif ($prefix === 'de')
104 {
105 $url = 'https://www.bitrix24.de/promo/sales/holiday-sale/';
106 }
107 elseif ($prefix === 'in')
108 {
109 $url = 'https://www.bitrix24.in/promo/sales/holiday-sale/';
110 }
111 elseif ($prefix === 'eu')
112 {
113 $url = 'https://www.bitrix24.eu/promo/sales/holiday-sale/';
114 }
115 elseif ($prefix === 'es' || $prefix === 'la')
116 {
117 $url = 'https://www.bitrix24.es/promo/sales/holiday-sale/';
118 }
119 }
120
121 if ($option === 'SUBSCRIPTION_MARKET_TRIAL_END')
122 {
124 }
125 }
126
127 if (
128 $option === 'SUBSCRIPTION_MARKET_DEMO_END'
129 && Bitrix24::getInstance()->isAvailableForRuRegion()
130 )
131 {
132 return self::getNotificationAboutDemoEnd($option);
133 }
134
135 $message = Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_MESS_MSGVER_1');
136
137 if (!empty($message))
138 {
139 $result = [
140 'BUTTON_TEXT' => $url !== '' ? Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_BTN') : null,
141 'PANEL_LINK' => $url ?? null,
142 'PANEL_MESSAGE' => $message
143 ];
144 }
145 else
146 {
147 \Bitrix\Main\Application::getInstance()->getExceptionHandler()->writeToLog(
148 new SystemException("Notification message for code '$option' not found.")
149 );
150 static::reset();
151 }
152 }
153
154 return $result;
155 }
156
157 private static function getNotificationAboutDemoEnd(string $option): array
158 {
159 return [
160 'BUTTON_TEXT' => Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_BTN_MSGVER_1'),
161 'PANEL_LINK' => Bitrix24::getInstance()->getBuyPath(),
162 'PANEL_MESSAGE' => Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_MESS_MSGVER_2')
163 ];
164 }
165
166 public static function setLastCheckTimestamp($timestamp)
167 {
168 Option::set(static::MODULE_ID, static::OPTION_LAST_CHECK_NOTIFICATION, $timestamp);
169 return true;
170 }
171
172 public static function getLastCheckTimestamp()
173 {
174 $result = false;
175 $option = (int) Option::get(static::MODULE_ID, static::OPTION_LAST_CHECK_NOTIFICATION, 0);
176 if ($option > 0)
177 {
178 $result = $option + static::$timestampNotifyDays;
179 }
180
181 return $result;
182 }
183
192 public static function set(string $code, string $url = '') : bool
193 {
194 Option::set(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, $code);
195 Option::set(static::MODULE_ID, static::OPTION_LAST_CHECK_ACCESS_NOTIFICATION, time());
196 Option::set(static::MODULE_ID, static::OPTION_NOTIFICATION_URL, $url);
197
198 return true;
199 }
200
206 public static function reset()
207 {
208 Option::delete(static::MODULE_ID, ['name' => static::OPTION_ACCESS_NOTIFICATION]);
209 Option::delete(static::MODULE_ID, ['name' => static::OPTION_LAST_CHECK_ACCESS_NOTIFICATION]);
210 Option::delete(static::MODULE_ID, ['name' => static::OPTION_NOTIFICATION_URL]);
211
212 return true;
213 }
214
218 public static function checkAgent()
219 {
220 if (Loader::includeModule('bitrix24'))
221 {
222 $code = '';
223 if (Access::isActiveRules() && Client::isSubscriptionAccess())
224 {
225 $dateFinish = Client::getSubscriptionFinalDate();
226 $entity = Access::getActiveEntity();
227 $maxCount = Access::getAvailableCount();
228 $isSubscriptionFinish = $dateFinish
229 && $dateFinish < (new Date())
230 && (time() - static::$timestampNotifyDays) < $dateFinish->getTimestamp();
231 if (!Access::isAvailable())
232 {
233 if (
234 $maxCount >= 0
235 && (
236 $entity[Access::ENTITY_COUNT] > $maxCount
237 || $entity[Access::ENTITY_TYPE_APP_STATUS][AppTable::STATUS_PAID] > 0
238 || $entity[Access::ENTITY_TYPE_APP_STATUS][AppTable::STATUS_SUBSCRIPTION] > 0
239 )
240 && static::getLastCheckTimestamp() > time()
241 )
242 {
243 $code = 'SUBSCRIPTION_MARKET_TARIFF_MARKET';
244 }
245 elseif ($isSubscriptionFinish)
246 {
247 $code = 'SUBSCRIPTION_MARKET_DEMO_END';
248 }
249 }
250 elseif (Access::isFeatureEnabled() && $isSubscriptionFinish)
251 {
252 $code = 'SUBSCRIPTION_MARKET_TRIAL_END';
253 }
254 }
255
256 if ($code !== '')
257 {
258 static::set($code);
259 }
260 else
261 {
262 $lastCode = Option::get(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, null);
263 if (!is_null($lastCode) && in_array($lastCode, static::CODE_CHECK_BY_AGENT))
264 {
265 static::reset();
266 }
267 }
268 }
269
270 return '\Bitrix\Rest\Marketplace\Notification::checkAgent();';
271 }
272}
static getInstance()
Определения application.php:98
Определения date.php:9
const STATUS_PAID
Определения app.php:86
const STATUS_SUBSCRIPTION
Определения app.php:89
static getSubscriptionFinalDate()
Определения client.php:594
static isSubscriptionAccess()
Определения client.php:650
static setLastCheckTimestamp($timestamp)
Определения notification.php:166
static getLastCheckTimestamp()
Определения notification.php:172
static getSubscriptionBuyUrl()
Определения url.php:562
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$maxCount
Определения options.php:1622
$result
Определения get_property_values.php:14
$entity
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$option
Определения options.php:1711
$url
Определения iframe.php:7