use yii_app\helpers\ClientHelper;
use yii_app\helpers\DataHelper;
use yii_app\records\BonusLevels;
+use yii_app\records\EqualizationRemains;
+use yii_app\records\LPTrackerApi;
+use yii_app\records\Product1cReplacement;
+use yii_app\records\Products1c;
+use yii_app\records\ReplacementInvoice;
+use yii_app\records\ReplacementInvoiceProducts;
use yii_app\records\MarketplaceOrder1cStatuses;
use yii_app\records\Sales;
use yii_app\records\SentKogort;
// 'export-catalog' => \app\actions\cron\ExportCatalogAction::class,
// 'cloudpayments-region' => \app\actions\cron\CloudpaymentsRegionAction::class,
// 'bonus-users-sale-update' => \app\actions\cron\BonusUsersSaleUpdateAction::class,
- // '1c-check-1day' => \app\actions\cron\OneCCheckOneDayAction::class,
+ // '1c-check-1day' => \app\actions\cron\OneCCheckOneDayAction::class,
];
}
//cron/one-c
- public function actionOneC() {
+ public function actionOneC()
+ {
$req_id = time();
$json_post = '{"request_id": "' . $req_id . '" ,"incomings":{"start_time":"' . date("Y-m-d", time() - 86400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},"checks":{"start_time":"' . date("Y-m-d", time() - 24400) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"},
"write_offs":{"start_time":"' . date("Y-m-d", time() - 86400 * 7) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
}
//cron/one-c-check-one-day
- public function actionOneCCheckOneDay() {
- $req_id=time();
- $json_post='{"request_id": "'.$req_id.'" ,"checks":{"start_time":"'.date("Y-m-d",time()-86400).' 00:00:00","end_time":"'.date("Y-m-d H:i:s",time()).'"}}';
+ public function actionOneCCheckOneDay()
+ {
+ $req_id = time();
+ $json_post = '{"request_id": "' . $req_id . '" ,"checks":{"start_time":"' . date("Y-m-d", time() - 86400) . ' 00:00:00","end_time":"' . date("Y-m-d H:i:s", time()) . '"}}';
$this->setApiCron($req_id, $json_post);
}
//cron/one-c-sellers
- public function actionOneCSellers() {
- $req_id=time();
- $json_post='{"request_id": "'.$req_id.'","nomenclature":true,"sellers":true, "prices":{"type_price":"Розничная цена"}, "balances":true, "payment_types":true}';
+ public function actionOneCSellers()
+ {
+ $req_id = time();
+ $json_post = '{"request_id": "' . $req_id . '","nomenclature":true,"sellers":true, "prices":{"type_price":"Розничная цена"}, "balances":true, "payment_types":true}';
$this->setApiCron($req_id, $json_post);
}
//cron/one-c-price-msk
- public function actionOneCPriceMsk() {
- $req_id=time();
- $json_post='{"request_id": "'.$req_id.'","nomenclature":true,"sellers":true, "prices":{"type_price":"Розничная Маг на Московск"}, "balances":true, "payment_types":true}';
+ public function actionOneCPriceMsk()
+ {
+ $req_id = time();
+ $json_post = '{"request_id": "' . $req_id . '","nomenclature":true,"sellers":true, "prices":{"type_price":"Розничная Маг на Московск"}, "balances":true, "payment_types":true}';
$this->setApiCron($req_id, $json_post);
}
//cron/custom-one-c-cron
- public function actionCustomOneCCron() {
- $req_id=time();
+ public function actionCustomOneCCron()
+ {
+ $req_id = time();
//чеки за 7 дней назад прогружаем
- $json_post='{"request_id": "'.$req_id.'", "checks":{"start_time":"'.date("Y-m-d",time()-86400*7).' 00:00:00","end_time":"'.date("Y-m-d",time()).' 23:59:59"}}';
+ $json_post = '{"request_id": "' . $req_id . '", "checks":{"start_time":"' . date("Y-m-d", time() - 86400 * 7) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
$this->setApiCron($req_id, $json_post);
}
//cron/one-c-cron-self-cost-day
- public function actionOneCCronSelfCostDay() {
- $req_id=time();
+ public function actionOneCCronSelfCostDay()
+ {
+ $req_id = time();
//себестоимость за текущий день
- $json_post='{"request_id": "'.$req_id.'", "self_cost":{"start_time":"'.date("Y-m-d",time()).' 00:00:00","end_time":"'.date("Y-m-d",time()).' 23:59:59"}}';
+ $json_post = '{"request_id": "' . $req_id . '", "self_cost":{"start_time":"' . date("Y-m-d", time()) . ' 00:00:00","end_time":"' . date("Y-m-d", time()) . ' 23:59:59"}}';
$this->setApiCron($req_id, $json_post);
// }
- public function actionBalanceHistory() {
+ public function actionBalanceHistory()
+ {
$data = Yii::$app->db->createCommand("SELECT * FROM balances")->queryAll();
$command = Yii::$app->db->createCommand()->batchInsert('balances_history',
$command->execute();
}
- private function setApiCron($req_id, $json_post) {
+ private function setApiCron($req_id, $json_post)
+ {
Yii::$app->db->createCommand()->insert('api_cron', [
'date' => new Expression('NOW()'),
'date_up' => new Expression('NOW()'),
],
[
- 'kogort_date' => $kogortDate,
- 'target_date' => $targetDate,
+ 'kogort_date' => $kogortDate,
+ 'target_date' => $targetDate,
'kogort_number' => SentKogort::KOGORT_NUMBERS['target'],
- 'phone' => $phonesArray,
+ 'phone' => $phonesArray,
]
);
$ip = "tst";
$tip_sale = "target";
$name = "Начисление бонусов на дату {$kogortDate}";
- $daysToEnd = $step1 + 1;
+ $daysToEnd = $step1 + 1;
$userBonusExist = UsersBonus::find()
->select(['phone'])
->where(['phone' => $kogortPhones])
return ExitCode::OK;
}
-
public function actionSendSecondTelegramMessage()
{
$messagesSettings = UsersMessageManagement::find()->one();
);
if (!empty($telegramUsers)) {
- $messageText = $messagesSettings
- ->replaceShortcodes($messagesSettings->offer_2, $targetDate);
+ $messageText = $messagesSettings
+ ->replaceShortcodes($messagesSettings->offer_2, $targetDate);
foreach ($telegramUsers as $telegramUser) {
if (!in_array($telegramUser['phone'], $sentStatusKogort)) {
$messageData = [];
$this->stdout("Некорректный формат времени\n", BaseConsole::FG_RED);
return ExitCode::DATAERR;
}
- $currentDate = $this->time ? date('Y-m-d', (int)$this->time) : date('Y-m-d');
+ $currentDate = $this->time ? date('Y-m-d', (int)$this->time) : date('Y-m-d');
$stepsBack = $this->stepsBack ?? 0;
$step3 = $messagesSettings ? $messagesSettings->day_before_step3 : 2;
$testActive = $messagesSettings ? (bool)($messagesSettings->test_phones_active) : false;
return ExitCode::OK;
}
+ /**
+ * ERP-355
+ * Отправка контактов для обзвона в LPTracker
+ */
+ public function actionSendContactsToLptracker()
+ {
+ $messagesSettings = UsersMessageManagement::find()->one();
+ if (!$messagesSettings) {
+ $this->stdout(
+ "Рассылка неактивна (не найдена настройка). Отправка сообщений прервана.\n",
+ BaseConsole::FG_RED
+ );
+ return ExitCode::UNAVAILABLE;
+ }
+ if (!$messagesSettings->active) {
+ $this->stdout(
+ "Рассылка неактивна (поле active = 0). Отправка сообщений прервана.\n",
+ BaseConsole::FG_RED
+ );
+ return ExitCode::UNAVAILABLE;
+ }
+ try {
+
+ $numbers = SentKogort::findAll(['kogort_number' => SentKogort::CALL, 'kogort_date' => date('Y-m-d'), 'status' => SentKogort::READY_TO_UPLOAD_LPTRACKER_STATUS]);
+
+ if (!empty($messagesSettings->test_phones_list)) {
+ $testPhones = array_map('trim', explode(',', $messagesSettings->test_phones_list));
+ if (
+ isset($messagesSettings->test_phones_active)
+ &&
+ $messagesSettings->test_phones_active == 1
+ ) {
+ $numbers = $testPhones;
+ }
+ }
+ $this->stdout(
+ "Отправка лидов в LPTrackerApi.\n",
+ BaseConsole::FG_RED
+ );
+ foreach ($numbers as $number) {
+ $api = new LPTrackerApi();
+ $response = $api->post('lead', [
+ 'contact' => [
+ 'project_id' => LPTrackerApi::SERVICE,
+ 'name' => $number->user?->name,
+ 'details' => [
+ [
+ 'type' => 'phone',
+ 'data' => $number->phone,
+ ]
+ ]
+ ],
+ 'custom' => [
+ LPTrackerApi::REASON_FOR_THE_CALL => LPTrackerApi::PURCHASE_EARLIER,
+ ],
+ //признак того что звонок должен поступать сразу после загрузки лида
+ //поставить true при согласовании с маркетингом
+ //также добавить признак повод звонка при необходимости
+ 'callback' => false,
+ 'funnel' => LPTrackerApi::NEW_LEAD,
+ 'lead_date' => date('d.m.Y H:i'),
+ 'owner' => 0,
+ 'payments' => [
+ ],
+ ]);
+
+ $status = $response['status'] == LPTrackerApi::SUCCESS_STATUS
+ ? SentKogort::SUCCESS_UPLOAD_TO_LPTRACKER_STATUS
+ : SentKogort::ERROR_UPLOAD_TO_LPTRACKER_STATUS;
+
+ SentKogort::updateAll(['status' => $status], ['id' => $number->id]);
+
+ if ($status === SentKogort::ERROR_UPLOAD_TO_LPTRACKER_STATUS) {
+ throw new \Exception(
+ "ОШИБКА С LPTRACKER\n" . implode('. ', array_column($response['errors'], 'message'))
+ );
+ } else {
+ $this->stdout(
+ "Лид с номером {$number->phone} успешно создан.\n",
+ BaseConsole::FG_RED
+ );
+ }
+ }
+ } catch (\Exception $exception) {
+ throw new \Exception($exception);
+ }
+ }
+
public function options($actionID)
{
$options = parent::options($actionID);
$batchSize = 500;
$offset = 0;
- // $csvFilePath = Yii::getAlias('@data/missing_users.csv');
- // $fileHandle = fopen($csvFilePath, 'w');
- // fputcsv($fileHandle, ['phone', 'username', 'chat_id', 'is-blocked', 'is_registered', 'reason'], ';');
+ // $csvFilePath = Yii::getAlias('@data/missing_users.csv');
+ // $fileHandle = fopen($csvFilePath, 'w');
+ // fputcsv($fileHandle, ['phone', 'username', 'chat_id', 'is-blocked', 'is_registered', 'reason'], ';');
while (true) {
$chatbotUsers = $remoteDb
->createCommand('SELECT * FROM chatbot_telegram_users LIMIT :limit OFFSET :offset', [
- ':limit' => $batchSize,
- ':offset' => $offset,
- ])->queryAll();
+ ':limit' => $batchSize,
+ ':offset' => $offset,
+ ])->queryAll();
if (empty($chatbotUsers)) {
break;
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Exception;
+use GuzzleHttp\Client;
+
+class LPTrackerApi
+{
+
+ private const LOGIN = 'Zakaz-bazacvetov24@yandex.ru1';
+ private const PASSWORD = 'B8-YY7d3K2ekNdK';
+ public const SERVICE = 117605;
+ private const TIMEOUT = 10;
+
+ public const SUCCESS_STATUS = 'success';
+ public const ERROR_STATUS = 'error';
+
+ public const NEW_LEAD = 2086013;
+ public const TO_CALL = 2140957;
+ public const REASON_FOR_THE_CALL = 2391182;
+
+
+ public const MEMORABLE_DATE = 'Памятная дата';
+ public const PURCHASE_EARLIER = 'Покупал ранее';
+
+ private $token;
+ public $client;
+
+ public const BASE_URI = 'https://direct.lptracker.ru';
+
+ public function __construct()
+ {
+ try {
+ $this->client = new Client([
+ 'base_uri' => self::BASE_URI,
+ 'timeout' => self::TIMEOUT,
+ ]);
+
+ if (empty($this->token)) {
+ $this->auth();
+ }
+ } catch (Exception $exception) {
+ throw new Exception($exception);
+ }
+ }
+
+
+ private function auth()
+ {
+ $response = $this->post('/login', [
+ 'login' => self::LOGIN,
+ 'password' => self::PASSWORD,
+ 'service' => self::SERVICE,
+ 'version' => '1.0'
+ ]);
+
+ if (!empty($response) && $response['status'] == self::SUCCESS_STATUS && $response['result']['token']) {
+ $this->token = $response['result']['token'];
+ } else {
+ throw new Exception('Не удалось получить токен!');
+ }
+ }
+
+ public function get($endpoint)
+ {
+ $response = $this->client->get($endpoint, [
+ 'headers' => [
+ 'token' => $this->token,
+ 'Content-type' => 'application/json',
+ ]
+ ]);
+
+ return json_decode($response->getBody(), true);
+ }
+
+ public function post($endpoint, array $data = [])
+ {
+ $response = $this->client->post($endpoint, [
+ 'json' => $data,
+ 'headers' => [
+ 'token' => $this->token,
+ 'Content-Type' => 'application/json',
+ ]
+ ]);
+
+ return json_decode($response->getBody(), true);
+ }
+
+}
\ No newline at end of file