use yii\console\Controller;
use yii\console\ExitCode;
use yii\db\Expression;
+use yii\helpers\ArrayHelper;
use yii\helpers\BaseConsole;
use yii\helpers\Json;
use yii_app\helpers\ClientHelper;
use yii_app\helpers\DataHelper;
use yii_app\records\BonusLevels;
use yii_app\records\EqualizationRemains;
+use yii_app\records\KogortStopList;
use yii_app\records\LPTrackerApi;
use yii_app\records\Product1cReplacement;
use yii_app\records\Products1c;
->asArray()
->all();
- $phonesArray = array_diff(array_column($telegramUsers, 'phone'), $sentStatusKogort);
+ $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all();
+ $phonesArray = array_diff(
+ array_diff(
+ array_column($telegramUsers, 'phone'),
+ $sentStatusKogort
+ ),
+ array_column($kogortStopListPhones, 'phone')
+ );
$chatIdsArray = array_column($telegramUsers, 'chat_id');
$countTelegramPhones = count($phonesArray);
->select(['phone', 'chat_id'])
->asArray()
->all();
- $phonesArray = array_diff(array_column($telegramUsers, 'phone'), $sentStatusKogort);
+
+ $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all();
+ $phonesArray = array_diff(
+ array_diff(
+ array_column($telegramUsers, 'phone'),
+ $sentStatusKogort
+ ),
+ array_column($kogortStopListPhones, 'phone')
+ );
+
+
$chatIdsArray = array_column($telegramUsers, 'chat_id');
$countTelegramPhones = count($phonesArray);
$this->stdout(
->replaceShortcodes($messagesSettings->offer_whatsapp, $targetDate);
$phonesSentArray = [];
- foreach ($kogortPhones as $index => $phone) {
+ $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all();
+ $phonesArray = array_diff(
+ $kogortPhones,
+ array_column($kogortStopListPhones, 'phone')
+ );
+
+ foreach ($phonesArray as $index => $phone) {
if ($index >= $limit) {
break;
}
}
try {
- $numbers = SentKogort::findAll(['kogort_number' => SentKogort::CALL, 'kogort_date' => date('Y-m-d'), 'status' => SentKogort::READY_TO_UPLOAD_LPTRACKER_STATUS]);
+ $numbers = SentKogort::findAll(
+ ['kogort_number' => SentKogort::CALL,
+ 'kogort_date' => date('Y-m-d'),
+ 'status' => SentKogort::READY_TO_UPLOAD_LPTRACKER_STATUS]
+ );
+ $kogortPhones = ArrayHelper::getColumn(ArrayHelper::toArray($numbers), 'phone');
if (!empty($messagesSettings->test_phones_list)) {
$testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list));
&&
$messagesSettings->test_phones_active == 1
) {
- $numbers = $testPhones;
+ $kogortPhones = $testPhones;
}
}
$this->stdout(
"Отправка лидов в LPTrackerApi.\n",
BaseConsole::FG_RED
);
- foreach ($numbers as $number) {
+
+ $kogortStopListPhones = KogortStopList::find()->select('phone')->asArray()->all();
+ $phonesArray = array_diff(
+ $kogortPhones,
+ array_column($kogortStopListPhones, 'phone')
+ );
+ foreach ($phonesArray as $phone) {
$api = new LPTrackerApi();
$response = $api->post('lead', [
'contact' => [
'project_id' => LPTrackerApi::SERVICE,
- 'name' => $number->user?->name,
+ 'name' => Users::find()->where(['phone' => $phone])->name ?? 'Клиент',
'details' => [
[
'type' => 'phone',
- 'data' => $number->phone,
+ 'data' => $phone,
]
]
],
? SentKogort::SUCCESS_UPLOAD_TO_LPTRACKER_STATUS
: SentKogort::ERROR_UPLOAD_TO_LPTRACKER_STATUS;
+ $matches = array_filter($numbers, function($item) use ($phone) {
+ return $item->phone === $phone;
+ });
+
+ $number = reset($matches);
SentKogort::updateAll(['status' => $status], ['id' => $number->id]);
if ($status === SentKogort::ERROR_UPLOAD_TO_LPTRACKER_STATUS) {