'price/<id:\d+>-<slug:[a-z0-9_-]+>' => 'price/view'
<?php
namespace app\telegram_logger;
use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\httpclient\Client;
/**
* Telegram Bot
*
* @author Ali Irani <ali@irani.im>
*/
class TelegramBot extends Component
{
const API_BASE_URL = 'https://api.telegram.org/bot';
/**
* Bot api token secret key
* @var string
*/
public $token;
private $_client;
/**
* Check required property
*/
public function init()
{
parent::init();
if ($this->token === null) {
throw new InvalidConfigException(self::className() . '::$token property must be set');
}
}
/**
* @return Client
*/
public function getClient()
{
if ($this->_client) {
return $this->_client;
}
return new Client(['baseUrl' => self::API_BASE_URL . $this->token]);
}
/**
* Send message to the telegram chat or channel
* @param int|string $chat_id
* @param string $text
* @param string $parse_mode
* @param bool $disable_web_page_preview
* @param bool $disable_notification
* @param int $reply_to_message_id
* @param null $reply_markup
* @link https://core.telegram.org/bots/api#sendmessage
* return array
*/
public function sendMessage($chat_id, $text, $parse_mode = null, $disable_web_page_preview = null, $disable_notification = null, $reply_to_message_id = null, $reply_markup = null)
{
$response = $this->getClient()
->post('sendMessage', compact('chat_id', 'text', 'parse_mode', 'disable_web_page_preview', 'disable_notification', 'reply_to_message_id', 'reply_markup'))
->send();
return $response->data;
}
public function getUpdates($offset, $timeout = 30)
{
$response = $this->getClient()
->post('getUpdates', ['offset'=>$offset, 'timeout'=>$timeout])
->send();
return $response->data;
}
}
<?php
namespace app\console;
use Yii;
use app\telegram_logger\TelegramBot;
set_time_limit(0);
ini_set('memory_limit', '512M');
class TelegramController extends \yii\console\Controller
{
const UPDATE_INFO_FILE = '@runtime/last_telegram_update_id.txt';
public function actionIndex()
{
echo "Start waiting for messages\n";
$bot = new TelegramBot(['token' => Yii::$app->params['telegram']['botToken']]);
if (file_exists(Yii::getAlias(self::UPDATE_INFO_FILE))) {
$last_update_id = Yii::getAlias(self::UPDATE_INFO_FILE);
} else {
$last_update_id = 1;
}
while (true) {
echo "Requesting updates\n";
$data = $bot->getUpdates($last_update_id, 5);
if (empty($data)) {
echo "Empty response\n";
} else {
if ($data['ok'] == 1) {
if (is_array($data['result'])) {
foreach ($data['result'] as $update) {
if (!empty($update['message']['text']) && $update['message']['text'] == '/getid') {
$bot->sendMessage($update['message']['chat']['id'], 'Ваш ID: '.$update['message']['chat']['id']);
}
$last_update_id = $update['update_id'] + 1;
}
file_put_contents(Yii::getAlias(self::UPDATE_INFO_FILE), $last_update_id);
} else {
echo "Result is not array\n";
}
} else {
echo 'Error '.$data['error_code'].': '.$data['description']."\n";
}
}
}
echo "Finished\n";
}
}
['attribute'=>'status',
'label'=>'Статус',
'value'=>function($model) {
return $model->status; //тут доработайте вывод
},
//searchModel - может иметь другое, ваше название
'filter' => Html::activeDropDownList($searchModel, 'status', [
''=>'Все',
'new'=>'Новый',
'delivered'=>'Доставленный',
'cancelled'=>'Отказанные']),
],
<?php
namespace app\helpers;
class ArraySum
{
public static function getSum($array)
{
$sumArray=[];
foreach ($array as $k=>$subArray) {
foreach ($subArray as $id=>$value) {
$value = floatval($value);
if(isset($sumArray[$id])) {
$sumArray[$id]+=$value;
} else {
$sumArray[$id]=$value;
}
}
}
return $sumArray;
}
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showFooter'=>true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'date',
'operator_count'=>[
'attribute'=>'operator_count',
'footer' => $total_statistic['operator_count']
],
'operator_count2',
'operator_count4',
'operator_count4',
],
]); ?>