From 9b79eb1a4e53d812622a387b8fc8c99910149fd4 Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 21 Apr 2025 14:37:50 +0300 Subject: [PATCH] =?utf8?q?=D0=A2=D0=B5=D1=81=D1=82=20=D1=81=D1=82=D0=BE?= =?utf8?q?=D0=BF=20=D0=BB=D0=B8=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../crud/KogortStopListController.php | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/erp24/controllers/crud/KogortStopListController.php b/erp24/controllers/crud/KogortStopListController.php index ba2576ca..e5eb865e 100644 --- a/erp24/controllers/crud/KogortStopListController.php +++ b/erp24/controllers/crud/KogortStopListController.php @@ -2,11 +2,19 @@ namespace yii_app\controllers\crud; +use Yii; +use yii\console\ExitCode; +use yii\helpers\ArrayHelper; +use yii\helpers\BaseConsole; use yii_app\records\KogortStopList; use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use yii_app\records\SentKogort; +use yii_app\records\Users; +use yii_app\records\UsersMessageManagement; +use yii_app\records\UsersTelegram; /** * KogortStopListController implements the CRUD actions for KogortStopList model. @@ -141,4 +149,157 @@ class KogortStopListController extends Controller throw new NotFoundHttpException('The requested page does not exist.'); } + + public function actionTestStopListTelegram() + { + $response = Yii::$app->response; + $response->format = \yii\web\Response::FORMAT_JSON; + $messagesSettings = UsersMessageManagement::find()->one(); + + $testResult = []; + $step1 = $messagesSettings ? $messagesSettings->day_before_step1 : 10; + + // Генерация для текущей даты + $kogortDate = '2025-04-19'; + $targetDate = date('Y-m-d', strtotime("+$step1 days", strtotime($kogortDate))); + $testResult['kogortDate'] = $kogortDate; + $kogortPhones = SentKogort::find() + ->select('phone') + ->where(['kogort_date' => $kogortDate]) + ->andWhere(['kogort_number' => 1]) + ->andWhere(['target_date' => $targetDate]) + ->andWhere(['status' => 1]) + ->column(); + $testResult['kogortPhones'] = count($kogortPhones); + $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list)); + $countTestPhones = count($testPhones); + $testResult['testPhones'] = $countTestPhones; + if (!empty($messagesSettings->test_phones_list)) { + if ( + isset($messagesSettings->test_phones_active) + && + $messagesSettings->test_phones_active == 1 + ) { + $kogortPhones = $testPhones; + } + } + + if (!empty($kogortPhones)) { + + $sentStatusKogort = SentKogort::find() + ->select('phone') + ->where(['kogort_date' => $kogortDate]) + ->andWhere(['kogort_number' => 1]) + ->andWhere(['target_date' => $targetDate]) + ->andWhere(['status' => 2]) + ->column(); + $testResult['sentPhones'] = count($sentStatusKogort); + // Выбираем номера для отправки через бота + $telegramUsers = UsersTelegram::find() + ->where(['is_blocked' => 0, 'is_registered' => 1]) + ->andWhere(['phone' => $kogortPhones]) + ->select(['phone', 'chat_id']) + ->asArray() + ->all(); + $testResult['telegramPhones'] = count($telegramUsers); + $toSend = Users::filterTelegramUsersForSending($telegramUsers, $sentStatusKogort); + $testResult['tosendPhones'] = count($toSend); + $testResult['tosendArray'] = $toSend; + } + return $testResult; + } + + public function actionTestStopListWhatsapp() + { + $response = Yii::$app->response; + $response->format = \yii\web\Response::FORMAT_JSON; + $messagesSettings = UsersMessageManagement::find()->one(); + + $testResult = []; + $step2 = $messagesSettings ? $messagesSettings->day_before_step2 : 4; + $limit = $messagesSettings ? $messagesSettings->channel_limit : 250; + $cascadeId = $messagesSettings ? $messagesSettings->cascade_id : 5686; + + $kogortDate = '2025-04-12'; + $testResult['kogortDate'] = $kogortDate; + $targetDate = date('Y-m-d', strtotime("+$step2 days", strtotime($kogortDate))); + + $kogortPhones = SentKogort::find() + ->select('phone') + ->andWhere(['kogort_number' => SentKogort::KOGORT_NUMBERS['whatsapp']]) + ->andWhere(['target_date' => $targetDate]) + ->andWhere(['purchase' => 0]) + ->andWhere(['status' => SentKogort::STATUSES['created']]) + ->column(); + $testResult['kogortPhones'] = count($kogortPhones); + if (!empty($messagesSettings->test_phones_list)) { + $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list)); + $countTestPhones = count($testPhones); + $testResult['testPhones'] = $countTestPhones; + if ( + isset($messagesSettings->test_phones_active) + && + $messagesSettings->test_phones_active == 1 + ) { + $kogortPhones = $testPhones; + } + } + + if (!empty($kogortPhones)) { + $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all(); + + $phonesArray = array_diff( + $kogortPhones, + array_column($kogortStopListPhones, 'phone') + ); + $testResult['stoplistPhones'] = count($kogortStopListPhones); + $testResult['toSendPhones'] = count($phonesArray); + $testResult['toSendPhonesArray'] = $phonesArray; + } + return $testResult; + } + + public function actionTestStopListLp() + { + $response = Yii::$app->response; + $response->format = \yii\web\Response::FORMAT_JSON; + $messagesSettings = UsersMessageManagement::find()->one(); + + $testResult = []; + $kogortDate = '2025-04-09'; + $numbers = SentKogort::findAll( + ['kogort_number' => SentKogort::CALL, + 'kogort_date' => $kogortDate, + 'status' => SentKogort::READY_TO_UPLOAD_LPTRACKER_STATUS] + ); + + $testResult['kogortDate'] = $kogortDate; + $testResult['numbers'] = count($numbers); + $kogortPhones = ArrayHelper::getColumn(ArrayHelper::toArray($numbers), 'phone'); + $testResult['kogortPhones'] = count($kogortPhones); + if (!empty($messagesSettings->test_phones_list)) { + $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list)); + $testResult['testPhones'] = count($testPhones); + + if ( + isset($messagesSettings->test_phones_active) + && + $messagesSettings->test_phones_active == 1 + ) { + $kogortPhones = $testPhones; + } + } + + $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all(); + $phonesArray = array_diff( + $kogortPhones, + array_column($kogortStopListPhones, 'phone') + ); + $testResult['stoplistPhones'] = count($kogortStopListPhones); + $testResult['toSendPhones'] = count($phonesArray); + $testResult['toSendPhonesArray'] = $phonesArray; + + return $testResult; + } + } -- 2.39.5