use Yii;
use yii\base\Action;
+use yii\helpers\Json;
use yii_app\services\TelegramService;
use GuzzleHttp\Client;
public function run() {
if (Yii::$app->request->isPost) {
- $botToken = TelegramService::TELEGRAM_BOT_DEV;
+ $botToken = TelegramService::TELEGRAM_BOT_DEV . 'asdf';
$apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
- $chats = ['337084327', '5489795686']; //Алексей
- $message = TelegramService::escapeMarkdown("Тестовое сообщение для https://tracker.yandex.ru/ERP-326");
+ $chats = [/*'337084327',*/ '5489795686']; //Алексей, Александр
+ $message = TelegramService::escapeMarkdown("Тестовое сообщение для https://tracker.yandex.ru/ERP-326 из test2");
$client = new Client();
foreach ($chats as $chatId) {
try {
- $client->post($apiURL, [
+ $r = $client->post($apiURL, [
'json' => [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'MarkdownV2',
],
]);
+ return Json::encode($r);
} catch (\Exception $e) {
Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+ $arr = preg_split("/response:/", $e->getMessage());
+ return $arr[count($arr) - 1];
}
}
Yii::error("Ошибка отправки сообщения в Telegram: " . Json::encode($marketplaceOrders->getErrors()), 'site');
}
- $botToken = TelegramService::TELEGRAM_BOT_DEV;
+ $botToken = TelegramService::TELEGRAM_BOT_DEV . 'ABCDCBA';
$apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
$chats = ['337084327', '5489795686']; //Алексей
$message = TelegramService::escapeMarkdown($message);
}
} catch (\Exception $e) {
Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+ $arr = preg_split("/response:/", $e->getMessage());
+ $marketplaceOrders->telegram_error = $arr[count($arr) - 1];
+ $marketplaceOrders->save();
+ if ($marketplaceOrders->getErrors()) {
+ Yii::error("Ошибка отправки сообщения в Telegram: " . Json::encode($marketplaceOrders->getErrors()), 'site');
+ }
}
}
}
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250321_143531_alter_table_marketplace_orders_add_column_telegram_error
+ */
+class m250321_143531_alter_table_marketplace_orders_add_column_telegram_error extends Migration
+{
+ const TABLE_NAME = 'erp24.marketplace_orders';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+ if ($table === null) {
+ return;
+ }
+
+ if ($table->getColumn('telegram_error') === null) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'telegram_error',
+ $this->text()->null()->comment('ошибка телеграмма')
+ );
+ }
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME) === null) {
+ return;
+ }
+
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME)->getColumn('telegram_error') !== null) {
+ $this->dropColumn(self::TABLE_NAME, 'telegram_error');
+ }
+ }
+}
* @property int|null $status_1c Статус заказа в 1С
* @property int|null $marketplace_name Наименование маркетплейса 'ФлауВау' 'ЯндексМаркет'
* @property int|null $marketplace_id ID маркетплейса: 1 - Flowwow, 2 - YandexMarket
+ * @property string|null $telegram_error ошибка телеграмма
*/
class MarketplaceOrders extends \yii\db\ActiveRecord
{
[[ 'fake'], 'default', 'value' => 0],
[['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id', 'status_telegram'], 'integer'],
[['creation_date', 'updated_at', 'returned_at'], 'safe'],
- [['return_data', 'raw_data', 'marketplace_name'], 'string'],
+ [['return_data', 'raw_data', 'marketplace_name', 'telegram_error'], 'string'],
[['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
[['marketplace_order_id'], 'string', 'max' => 64],
[['warehouse_guid', 'guid'], 'string', 'max' => 36],
'marketplace_name' => 'Наименование маркетплейса',
'marketplace_id' => 'ID маркетплейса: 1 - Flowwow, 2 - YandexMarket',
'status_telegram' => 'Статус отправки в телеграм',
+ 'telegram_error' => 'Ошибка телеграмма',
];
}