--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250303_095855_add_column_status_telegram_to_marketplace_orders_table
+ */
+class m250303_095855_add_column_status_telegram_to_marketplace_orders_table extends Migration
+{
+ const TABLE_NAME = 'erp24.marketplace_orders';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->addColumn(self::TABLE_NAME, 'status_telegram', $this->tinyInteger()->notNull()
+ ->defaultValue(0)->comment('0 - не отправлено, 1 - готово к отправке, 2 - отправлено'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, 'status_telegram');
+ }
+}
* @property string|null $raw_data Полный сырой ответ API
* @property string|null $guid GUID заказа в 1С
* @property int|null $status_1c Статус заказа в 1С
+ * @property int|null $status_telegram Статус отсылки заказа в телеграм
*/
class MarketplaceOrders extends \yii\db\ActiveRecord
{
+ const STATUS_TELEGRAM_NOT_SENT = 0;
+ const STATUS_TELEGRAM_PREPARED_TO_SEND = 1;
+ const STATUS_TELEGRAM_SENT = 2;
+
const STATUSES_1C = [
1 => 'Создан в ЕРП'
];
{
return [
[['store_id', 'warehouse_guid', 'returned_at', 'return_data', 'raw_data', 'guid'], 'default', 'value' => null],
- [['cancel_requested'], 'default', 'value' => 0],
+ [['cancel_requested', 'status_telegram'], 'default', 'value' => 0],
[['status_1c'], 'default', 'value' => 1],
[['marketplace_order_id', 'status_id', 'substatus_id', 'creation_date', 'updated_at', 'total', 'delivery_total', 'buyer_total_before_discount', 'tax_system', 'payment_type', 'payment_method'], 'required'],
[['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c'], 'default', 'value' => null],
[[ 'fake'], 'default', 'value' => 0],
- [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c'], 'integer'],
+ [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_telegram'], 'integer'],
[['creation_date', 'updated_at', 'returned_at'], 'safe'],
[['return_data', 'raw_data'], 'string'],
[['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
'raw_data' => 'Полный сырой ответ API',
'guid' => 'GUID заказа в 1С',
'status_1c' => 'Статус заказа в 1С',
+ 'status_telegram' => 'Статус отправки в телеграм',
];
}
use yii_app\records\SchedulerTaskLog;
use \yii_app\records\Meeting;
use yii_app\services\TelegramService;
+use yii_app\records\MarketplaceOrders;
ini_set('max_execution_time', (string)(60 * 60 * 1)); // 1 час
ini_set('display_errors', 'on');
$schedulerTaskLog->save();
}
////////////////////////////////////////////////////////////////////////
- Meeting::updateAll(['location' => 2], ['location' => 1]);
- $meeting = Meeting::find()->where(['location' => 2])->one();
- if ($meeting) {
- Meeting::updateAll(['location' => 3], ['location' => 2]);
+ MarketplaceOrders::updateAll(['status_telegram' => MarketplaceOrders::STATUS_TELEGRAM_PREPARED_TO_SEND],
+ ['status_telegram' => MarketplaceOrders::STATUS_TELEGRAM_NOT_SENT]);
+ $marketplaceOrders = MarketplaceOrders::find()->where(['status_telegram' => MarketplaceOrders::STATUS_TELEGRAM_PREPARED_TO_SEND])->one();
+ if ($marketplaceOrders) {
+ MarketplaceOrders::updateAll(['status_telegram' => MarketplaceOrders::STATUS_TELEGRAM_SENT],
+ ['status_telegram' => MarketplaceOrders::STATUS_TELEGRAM_PREPARED_TO_SEND]);
$botToken = TelegramService::TELEGRAM_BOT_DEV;
$apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";