]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Тест стоп листов
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 21 Apr 2025 11:37:50 +0000 (14:37 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 21 Apr 2025 11:37:50 +0000 (14:37 +0300)
erp24/controllers/crud/KogortStopListController.php

index ba2576cac600fd547edaae526ff87c56197695a7..e5eb865ea0d992cdb943852f9283ffcb94428952 100644 (file)
@@ -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;
+    }
+
 }