--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+class m250307_084838_add_columns_marketplace_name_to_marketplace_orders_table 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('marketplace_name') === null) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'marketplace_name',
+ $this->string()->null()->comment('Наименование маркетплейса')
+ );
+ }
+ if ($table->getColumn('marketplace_id') === null) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'marketplace_id',
+ $this->integer()->null()->comment('ID маркетплейса')
+ );
+ }
+
+ $this->execute("
+ UPDATE " . self::TABLE_NAME . " AS o
+ SET marketplace_id = (
+ SELECT s.warehouse_id
+ FROM erp24.marketplace_store s
+ WHERE s.warehouse_guid::TEXT = o.warehouse_guid::TEXT
+ LIMIT 1
+ )
+ WHERE o.warehouse_guid IS NOT NULL;
+ ");
+
+ $this->execute("
+ UPDATE " . self::TABLE_NAME . "
+ SET marketplace_name = CASE
+ WHEN marketplace_id = 1 THEN 'ФлауВау'
+ WHEN marketplace_id = 2 THEN 'ЯндексМаркет'
+ ELSE marketplace_name
+ END;
+ ");
+ $this->alterColumn(
+ self::TABLE_NAME,
+ 'marketplace_id',
+ $this->integer()->notNull()->comment('ID маркетплейса')
+ );
+ $this->alterColumn(
+ self::TABLE_NAME,
+ 'marketplace_name',
+ $this->string()->notNull()->comment('Наименование маркетплейса')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME) === null) {
+ return;
+ }
+
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME)->getColumn('marketplace_name') !== null) {
+ $this->dropColumn(self::TABLE_NAME, 'marketplace_name');
+ $this->dropColumn(self::TABLE_NAME, 'marketplace_id');
+ }
+ }
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m250307_084838_add_columns_marketplace_name_to_marketplace_orders_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
* @property string|null $raw_data Полный сырой ответ API
* @property string|null $guid GUID заказа в 1С
* @property int|null $status_1c Статус заказа в 1С
+ * @property int|null $marketplace_name Наименование маркетплейса 'ФлауВау' 'ЯндексМаркет'
+ * @property int|null $marketplace_id ID маркетплейса: 1 - Flowwow, 2 - YandexMarket
*/
class MarketplaceOrders extends \yii\db\ActiveRecord
{
[['store_id', 'warehouse_guid', 'returned_at', 'return_data', 'raw_data', 'guid'], 'default', 'value' => null],
[['cancel_requested'], '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'],
+ [['marketplace_order_id', 'marketplace_id', 'marketplace_name', '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', 'marketplace_id'], 'integer'],
[['creation_date', 'updated_at', 'returned_at'], 'safe'],
- [['return_data', 'raw_data'], 'string'],
+ [['return_data', 'raw_data', 'marketplace_name'], 'string'],
[['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
[['marketplace_order_id'], 'string', 'max' => 64],
[['warehouse_guid', 'guid'], 'string', 'max' => 36],
'raw_data' => 'Полный сырой ответ API',
'guid' => 'GUID заказа в 1С',
'status_1c' => 'Статус заказа в 1С',
+ 'marketplace_name' => 'Наименование маркетплейса',
+ 'marketplace_id' => 'ID маркетплейса: 1 - Flowwow, 2 - YandexMarket',
];
}