use yii_app\services\ExportImportService;
use yii_app\services\SalesService;
use yii_app\services\StoreVisitorsService;
+use yii_app\services\TelegramService;
class TestAction extends Action
{
public function run() {
- $sales = Sales::find()->where(['operation' => Sales::OPERATION_SALE])
- ->andWhere(['>=', 'date', '2024-05-30 21:28:00'])
- ->andWhere(['<=', 'date', '2024-06-04 17:24:00'])->all();
- $salesIds = ArrayHelper::getColumn($sales, 'id');
- $returns = Sales::find()->select(['id', 'sales_check'])->where(['operation' => Sales::OPERATION_RETURN, 'sales_check' => $salesIds])->all();
- $returnsIds = ArrayHelper::getColumn($returns, 'sales_check');
- foreach ($sales as $sale) {
- /** @var $sale Sales */
- if (!in_array($sale->id, $returnsIds)) {
- if (ClientHelper::phoneVerify($sale->phone)) {
- $usersBonusMinus = UsersBonus::find()->where(['tip' => 'minus', 'check_id' => $sale->id])->one();
- if ($usersBonusMinus) {
- $usersBonusPlus = UsersBonus::find()->where(['tip' => 'plus', 'check_id' => $sale->id])->one();
- if (!$usersBonusPlus) {
- $userBonus = new UsersBonus;
- $userBonus->phone = "" . $sale->phone;
- $userBonus->name = "Возврат с покупки 10% " . $sale->number . " сумма чека " . $sale->summ;
- $userBonus->date = date('Y-m-d H:i:s');
- $userBonus->site_id = 1;
- $userBonus->setka_id = 1;
- $userBonus->tip = 'plus';
- $userBonus->tip_sale = 'sale';
- $userBonus->bonus = floor($sale->summ * 0.1);
- $userBonus->date_start = $userBonus->date;
- $userBonus->date_end = date('Y-m-d H:i:s', strtotime('+366 day', strtotime($userBonus->date)));
- $userBonus->save();
- }
- }
- }
- }
- }
+
+ $messageBonuses = "⚠️ Внимание! Тестовая рассылка для проверки кнопок!".
+
+ "\n\n" .
+ "📢 Проверьте данные!";
+
+ TelegramService::sendTargetStatToTelegramMessage($messageBonuses);
+
return 'ok';
}
}
\ No newline at end of file
const TARGET_PROD_URL = "erp.erp-flowers.ru";
const CHAT_CHANNEL_ID = "-1001861631125";
const CHAT_CHANNEL_ERP_ID = "-1002338329426";
+ const CHATBOT_SALT = "ASIUdgb762gIUOYASgd7a6iuydb";
public static function sendMessage($admin_id, $message, $reply_markup = null)
{
$client = new Client();
foreach ($chats as $chatId) {
try {
+ $buttons = self::getTgButtons($chatId);
$client->post($apiURL, [
'json' => [
'chat_id' => $chatId,
'text' => $message,
'parse_mode' => 'MarkdownV2',
+ 'reply_markup' => Json::encode([
+ "inline_keyboard" => $buttons
+ ]),
],
]);
$apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
$message = self::escapeMarkdown($message);
+ $buttons = self::getTgButtons($chatId);
$client = new Client();
try {
'text' => $message,
'parse_mode' => 'MarkdownV2',
'reply_markup' => Json::encode([
- "inline_keyboard" => [
- [
- ['text' => "Адреса магазинов", "web_app" => ['url' => 'https://chatbot.bazacvetov24.ru/bot/telegram?hash=$hash&start=store']],
- ['text' => "Заказ на сайте", "url" => "https://bazacvetov24.ru/"],
- ],
- [
- ['text' => "Забрать 1800 руб", "web_app" => ['url' => 'https://chatbot.bazacvetov24.ru/bot/telegram?hash=$hash&start=promo.1000']],
- ['text' => 'Списание бонусов', "web_app" => ['url' => 'https://chatbot.bazacvetov24.ru/bot/telegram?hash=$hash']]
- ]
- ]
+ "inline_keyboard" => $buttons
]),
],
]);
}
}
+ public static function getHashTG($chatId) : string
+ {
+ // Так можно создать hash для бота
+ $data = Json::encode([
+ 'platform' => 'telegram',
+ 'user_id' => $chatId
+ ]);
+
+ $sha1 = sha1(self::CHATBOT_SALT . ";" . $data);
+
+ return base64_encode($sha1 . "#" . $data);
+ }
+
+ public static function getTgButtons($chatId) : array
+ {
+ $hash = self::getHashTG($chatId);
+
+ $siteBc24Url = "https://bazacvetov24.ru/";
+ $chatBotBc24Url = 'https://chatbot.bazacvetov24.ru';
+
+ $linkAppStore = $chatBotBc24Url . "/bot/telegram?hash=$hash&start=store";
+ $linkAppEvents = $chatBotBc24Url . "/bot/telegram?hash=$hash&start=promo.1000";
+ $linkAppBalance = $chatBotBc24Url . "/bot/telegram?hash=$hash";
+
+ return [
+ [
+ ['text' => "Адреса магазинов", "web_app" => ['url' => $linkAppStore]],
+ ['text' => "Заказ на сайте", "url" => $siteBc24Url],
+ ],
+ [
+ ['text' => "Забрать 1800 руб", "web_app" => ['url' => $linkAppEvents]],
+ ['text' => 'Списание бонусов', "web_app" => ['url' => $linkAppBalance]]
+ ]
+ ];
+ }
+
// Метод для экранирования символов MarkdownV2 для файла
public static function escapeMarkdown($text)