]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-355 Автоматизация звонков роботом из когорт
authormarina <m.zozirova@gmail.com>
Fri, 7 Mar 2025 12:34:24 +0000 (15:34 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 7 Mar 2025 12:34:24 +0000 (15:34 +0300)
erp24/api2/controllers/LPTrackerController.php [deleted file]
erp24/api2/records/LPTrackerApi.php [deleted file]
erp24/commands/CronController.php
erp24/config/console.php
erp24/records/LPTrackerApi.php [new file with mode: 0644]
erp24/records/SentKogort.php

diff --git a/erp24/api2/controllers/LPTrackerController.php b/erp24/api2/controllers/LPTrackerController.php
deleted file mode 100644 (file)
index b458cab..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?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
diff --git a/erp24/api2/records/LPTrackerApi.php b/erp24/api2/records/LPTrackerApi.php
deleted file mode 100644 (file)
index 1dc04bd..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-<?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
index 45e98faf88a4e369cfd23533eb429d048bcd0c9f..99488f6011f4c8b6abd48dbe0449d600028be722 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace yii_app\commands;
 
-use app\jobs\SendTelegramMessageDBJob;
 use app\jobs\SendTelegramMessageJob;
+use app\records\LPTrackerApi;
 use DateTime;
 use DateTimeZone;
 use Yii;
@@ -11,14 +11,8 @@ use yii\console\Controller;
 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;
@@ -584,7 +578,6 @@ class CronController extends Controller
         return ExitCode::OK;
     }
 
-
     public function actionSendSecondTelegramMessage()
     {
         $messagesSettings = UsersMessageManagement::find()->one();
@@ -792,6 +785,52 @@ class CronController extends Controller
         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);
index b15ac017a2cd04f1ef56e3dd34573df2688c4470..abb400af9214b1a1bdad5872fb33188f7894a76d 100755 (executable)
@@ -62,6 +62,11 @@ $config = [
                     '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',
diff --git a/erp24/records/LPTrackerApi.php b/erp24/records/LPTrackerApi.php
new file mode 100644 (file)
index 0000000..1dc04bd
--- /dev/null
@@ -0,0 +1,82 @@
+<?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
index c0de3a42f8e8e3314b9048d593524cf5c3b238d2..8accdc520351bf22f2d169ddde7a2179f8d0d6ff 100644 (file)
@@ -21,8 +21,9 @@ use Yii;
 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,