Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/skyweb24.popuppro/lib/ |
Upload File : |
<? namespace Skyweb24\Popuppro; use Bitrix\Main\Mail\Event; use Bitrix\Main\Localization\Loc; class Reward extends \Skyweb24\Popuppro\Base { private $params; private $eventName; private $eventData; private $popup; private $settings; function __construct($popup, $params) { $this->popup = $popup; $this->params = $params; $this->settings = $this->popup->getSettings(); } public function get() { switch ($this->popup->getType()) { case "thimbles": return $this->thimbles(); case "roulette": return $this->roulette(); case "discount": return $this->discount(); case "coupon": return $this->coupon(); default: return false; } } private function coupon(){ // dev ... } private function discount(){ // dev ... } private function roulette(){ // dev ... } private function thimbles() { $this->eventName = "SKYWEB24_POPUPPRO_ROULETTE_SEND"; $arListRules = $this->settings['thimbles']['list_wins']; $arPrize = $this->getPrizeList(); $arRandomSector = []; $reward = []; foreach ($arListRules as $key => $value) { $chance = empty($value['chance']) ? 0 : $value['chance']; $chance = (string)$chance == 'NaN' ? 1 : ($chance * 10); if ($chance > 0) { $arRandomSector = array_pad($arRandomSector, count($arRandomSector) + $chance, $key); } } shuffle($arRandomSector); if (count($arRandomSector) > 0) { $probabilityIndex = $arRandomSector[array_rand($arRandomSector)]; $probability = $arListRules[$probabilityIndex]; } if(!empty($probability)){ foreach ($arPrize as $grPrize) { foreach($grPrize['items'] as $prize) { if ($prize['id'] == $probability['prizeId']) { $reward = $prize; if ($prize['type'] == "coupon") { $reward["value"] = $this->generateCoupon($prize['id']); } else { $reward["value"] = $prize['title']; } $this->params['text'] = $probability['text']; break; } } } } if(!empty($reward)) { if(!empty($reward['type'])) { $this->eventData['EMAIL'] = $this->params['email']; $this->eventData["COUPON"] = $reward['value']; $this->eventData["RESULT_TEXT"] = $this->params['text']; } return $reward; } $this->setError("Prize not found"); return false; } public static function getPrizeList() { $arPrize = [ "main" => [ "name" => Loc::getMessage("SKYWEB24_POPUPPRO_REWARD_GROUP_NAME_MAIN"), "items" => [ [ "id" => "0", "type" => "default", "title" => Loc::getMessage("SKYWEB24_POPUPPRO_WIN"), ], [ "id" => "1", "type" => false, "title" => Loc::getMessage("SKYWEB24_POPUPPRO_DEFEAT"), ] ] ] ]; if (\Bitrix\Main\Loader::IncludeModule('sale')) { $rsBasketRules = \Bitrix\Sale\Internals\DiscountTable::getList([ 'select' => ['ID', 'NAME'], 'filter' => ['=ACTIVE' => 'Y'] ]); $arPrize["coupon"] = [ "name" => Loc::getMessage("SKYWEB24_POPUPPRO_REWARD_GROUP_NAME_COUPON"), "items" => [] ]; while ($row = $rsBasketRules->fetch()) { $arPrize["coupon"]['items'][] = [ "id" => $row["ID"], "type" => "coupon", "title" => str_replace('"', "'", $row['NAME']), ]; } } return $arPrize; } public function generateCoupon($discountId) { $cTime = time(); $startTime = new \Bitrix\Main\Type\DateTime(ConvertTimeStamp($cTime, "FULL")); $endTime = AddToTimeStamp(['DD' => 30], $cTime); $endTime = new \Bitrix\Main\Type\DateTime(ConvertTimeStamp($endTime, "FULL")); $coupon = \Bitrix\Sale\Internals\DiscountCouponTable::generateCoupon(true); $fields = [ 'DISCOUNT_ID' => $discountId, 'ACTIVE' => 'Y', 'TYPE' => \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_ONE_ORDER, 'COUPON' => $coupon, 'DATE_APPLY' => false, 'ACTIVE_TO' => $endTime, 'ACTIVE_FROM' => $startTime, 'DESCRIPTION' => "description", "MAX_USE" => 1 ]; \Bitrix\Sale\Internals\DiscountCouponTable::add($fields); return $coupon; } public function send() { if(empty($this->eventData)) { return false; } if($emailTemplateId = $this->settings['view']['props']['MAIL_TEMPLATE']) { \Bitrix\Main\Mail\Event::send([ "EVENT_NAME" => $this->eventName, "LID" => SITE_ID, "C_FIELDS" => $this->eventData, 'MESSAGE_ID' => $emailTemplateId ]); } } }