From: fomichev Date: Wed, 5 Mar 2025 15:03:15 +0000 (+0300) Subject: Тестирование отправки из когорт X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7d2160f528de643ade58e1c6c5d458be83bfbb69;p=erp24_rep%2Fyii-erp24%2F.git Тестирование отправки из когорт --- diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 09f52b9d..7f1c12db 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -29,6 +29,7 @@ use yii_app\records\UsersMessageManagement; use yii_app\records\UsersTelegram; use yii_app\records\UsersTelegramLog; use yii_app\services\TelegramService; +use yii_app\services\WhatsAppService; class CronController extends Controller { @@ -765,14 +766,39 @@ class CronController extends Controller BaseConsole::FG_GREEN ); - $channel = self::getChannelByName('WABA'); + $channel = WhatsAppService::getChannelByName('WABA'); $limit = $channel['messagingLimit'] ?? 250; - if (!empty($phonesArray)) { + $salesData = Sales::find() + ->select([ + 'phone', + 'dealsCount' => 'COUNT(*)' + ]) + ->where(['phone' => $phonesArray]) + ->groupBy('phone') + ->asArray() + ->indexBy('phone') + ->all(); + + $phoneSales = []; + foreach ($phonesArray as $phone) { + $phoneSales[$phone] = $salesData[$phone]['dealsCount'] ?? 0; + } + arsort($phoneSales); + $sortedPhones = array_keys($phoneSales); + + $phonesToSend = null; + if ($countWhatsappPhones > $limit) { + $phonesToSend = $sortedPhones; + } else { + $phonesToSend = $phonesArray; + } + + if (!empty($phonesToSend)) { $messageText = $messagesSettings ->replaceShortcodes($messagesSettings->offer_whatsapp, $targetDate); $phonesSentArray = []; - foreach ($phonesArray as $index => $phone) { + foreach ($phonesToSend as $index => $phone) { if ($index >= $limit) { break; } diff --git a/erp24/records/Users.php b/erp24/records/Users.php index ac38ea25..00b8faf8 100755 --- a/erp24/records/Users.php +++ b/erp24/records/Users.php @@ -561,9 +561,27 @@ class Users extends \yii\db\ActiveRecord } $whatsappPhones = array_diff(array_diff($targetPhones, $excludeRegistered), $excludeSalesPhone); + if (!empty($messagesSettings->test_phones_list)) { + if ( + isset($messagesSettings->test_phones_active) + && + $messagesSettings->test_phones_active == 0 + ) { + $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list)); + $whatsappKogortData = array_merge($whatsappPhones, $testPhones); + } else { + $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list)); + $whatsappKogortData = $testPhones; + } + } else { + if ($messagesSettings->test_phones_active == 1) { + $whatsappKogortData = []; + } + } + $secondTarget = array_diff($excludeRegistered, $excludeSalesPhone); - return ['whatsapp' => $whatsappPhones, 'secondTarget' => $secondTarget]; + return ['whatsapp' => $whatsappKogortData, 'secondTarget' => $secondTarget]; } /**