+++ /dev/null
-<?php
-
-namespace app\controllers;
-
-use app\records\LPTrackerApi;
-
-class LPTrackerController extends BaseController
-{
- public function actionGetProjects()
- {
- $api = new LPTrackerApi();
-
- $response = $api->get('/projects');
- var_dump($response);
- }
-
- public function actionGetFunnels()
- {
-// $api = new LPTrackerApi();
-// //GET contact/search?project_id=[project_id]&phone=[phone]&email=[email]
-// $response = $api->get("/contact/search?project_id=117605&phone=79036571587&email=");
-//
-// echo '<pre>';
-// var_dump($response);
-// echo '</pre>';
- }
-
- public function actionTest()
- {
-// $api = new LPTrackerApi();
-
-// var_dump($response);
-// die();
-
- }
-
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
-namespace 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';
-
- 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
namespace yii_app\commands;
-use app\jobs\SendTelegramMessageDBJob;
use app\jobs\SendTelegramMessageJob;
+use app\records\LPTrackerApi;
use DateTime;
use DateTimeZone;
use Yii;
use yii\console\ExitCode;
use yii\db\Expression;
use yii\helpers\BaseConsole;
-use yii\helpers\Console;
use yii_app\helpers\ClientHelper;
use yii_app\records\BonusLevels;
-use yii_app\records\EqualizationRemains;
-use yii_app\records\Product1cReplacement;
-use yii_app\records\Products1c;
-use yii_app\records\ReplacementInvoice;
-use yii_app\records\ReplacementInvoiceProducts;
use yii_app\records\Sales;
use yii_app\records\SentKogort;
use yii_app\records\Users;
return ExitCode::OK;
}
-
public function actionSendSecondTelegramMessage()
{
$messagesSettings = UsersMessageManagement::find()->one();
return ExitCode::OK;
}
+ /**
+ * ERP-355
+ * Отправка контактов для обзвона в LPTracker
+ */
+ public function actionSendContactsToLptracker()
+ {
+ try {
+
+ $numbers = SentKogort::findAll(['kogort_number' => SentKogort::CALL, 'kogort_date' => date('Y-m-d'), 'status' => SentKogort::READY_TO_UPLOAD_LPTRACKER_STATUS]);
+
+ 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,
+ ]
+ ]
+ ],
+ //признак того что звонок должен поступать сразу после загрузки лида
+ //поставить true при согласовании с маркетингом
+ //также добавить признак повод звонка при необходимости
+ 'callback' => false,
+ 'funnel' => LPTrackerApi::SERVICE,
+ 'lead_date' => date('d.m.Y H:i'),
+ 'deal_date' => date('d.m.Y H:i'),
+ 'owner' => 0,
+ 'payments' => [
+ ],
+ ]);
+ if ($response['status'] == LPTrackerApi::SUCCESS_STATUS) {
+ SentKogort::updateAll(['status' => SentKogort::SUCCESS_UPLOAD_TO_LPTRACKER_STATUS], ['id' => $number->id]);
+ } else {
+ SentKogort::updateAll(['status' => SentKogort::ERROR_UPLOAD_TO_LPTRACKER_STATUS], ['id' => $number->id]);
+ throw new \Exception("ОШИБКА С LPTRACKER\n" . implode('. ', array_map(fn($error) => $error['message'], $response['errors'])));
+ }
+ }
+ } catch (\Exception $exception) {
+ throw new \Exception($exception);
+ }
+ }
+
public function options($actionID)
{
$options = parent::options($actionID);
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
+ [
+ 'class' => 'app\log\TelegramTarget',
+ 'levels' => ['error', 'warning'],
+ // 'categories' => ['api.error', 'js.error', 'command.error'],
+ ],
],
],
'db' => require dirname(__DIR__) . '/config/db.php',
--- /dev/null
+<?php
+
+namespace 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';
+
+ 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
class SentKogort extends \yii\db\ActiveRecord
{
public const CALL = 3;
- public const SUCCESS_UPLOAD_TO_LPTRACKER_STATUS = 1;
- public const ERROR_UPLOAD_TO_LPTRACKER_STATUS = 2;
+ public const READY_TO_UPLOAD_LPTRACKER_STATUS = 1;
+ public const SUCCESS_UPLOAD_TO_LPTRACKER_STATUS = 11;
+ public const ERROR_UPLOAD_TO_LPTRACKER_STATUS = 22;
public const KOGORT_NUMBERS = [
'target' => 1,