]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление поля и проверка статусов и изменение названия метода origin/feature_fomichev_erp-20250910_add_field_created_at_marketplace_orders_status_types
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 10 Sep 2025 13:24:36 +0000 (16:24 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 10 Sep 2025 13:24:36 +0000 (16:24 +0300)
erp24/migrations/m250910_130353_add_created_at_field_to_marketplace_order_status_types_table.php [new file with mode: 0644]
erp24/records/MarketplaceOrderStatusTypes.php
erp24/services/MarketplaceService.php

diff --git a/erp24/migrations/m250910_130353_add_created_at_field_to_marketplace_order_status_types_table.php b/erp24/migrations/m250910_130353_add_created_at_field_to_marketplace_order_status_types_table.php
new file mode 100644 (file)
index 0000000..e768527
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+use yii\db\Migration;
+
+class m250910_130353_add_created_at_field_to_marketplace_order_status_types_table extends Migration
+{
+    const TABLE_NAME = 'erp24.marketplace_order_status_types';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+        if ($table === null) {
+            return;
+        }
+
+        if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('created_at')) {
+            $this->addColumn(
+                self::TABLE_NAME,
+                'created_at',
+                $this->dateTime()->notNull()->defaultExpression('NOW()'),
+            );
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('created_at')) {
+            $this->dropColumn(self::TABLE_NAME, 'created_at');
+        }
+    }
+
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m250910_130353_add_created_at_field_to_marketplace_order_status_types_table cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}
index 63a2b84d046d91fa83ea8b3c559b129e145cc66b..4a34061cfc3efb1a8532c5c8e0d15f250ae6efce 100644 (file)
@@ -3,6 +3,8 @@
 namespace yii_app\records;
 
 use Yii;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
 
 /**
  * This is the model class for table "marketplace_order_status_types".
@@ -11,11 +13,24 @@ use Yii;
  * @property string $code Код статуса
  * @property string|null $name Название статуса
  * @property string|null $description Описание статуса
+ * @property string|null $created_at Время создания
  */
 class MarketplaceOrderStatusTypes extends \yii\db\ActiveRecord
 {
     const CANSELLED_CODE = 'CANCELLED';
     const READY_CODE = 'READY_TO_SHIP';
+
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'value' => new Expression('NOW()'),
+            ],
+        ];
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -31,6 +46,7 @@ class MarketplaceOrderStatusTypes extends \yii\db\ActiveRecord
     {
         return [
             [['name', 'description'], 'default', 'value' => null],
+            [['created_at'], 'safe'],
             [['code'], 'required'],
             [['code'], 'string', 'max' => 64],
             [['name', 'description'], 'string', 'max' => 255],
@@ -48,6 +64,7 @@ class MarketplaceOrderStatusTypes extends \yii\db\ActiveRecord
             'code' => 'Код статуса',
             'name' => 'Название статуса',
             'description' => 'Описание статуса',
+            'created_at' => 'Время создания'
         ];
     }
 }
index 85479c3f21ae6bc6c2550aa3aae5e2600fddef04..fcade407a70cad9f14d1874af17ca8b7d2549df1 100644 (file)
@@ -2071,6 +2071,9 @@ class MarketplaceService
             ->indexBy('code')
             ->asArray()
             ->all();
+        if (empty($statuses)) {
+            return 0;
+        }
         $statuses = ArrayHelper::map($statuses, 'code', 'id');
         $statusCodes = array_unique(array_keys($statuses));
         $newOrdersCount = 0;
@@ -2087,7 +2090,7 @@ class MarketplaceService
 
         if (!$marketplaceOrder) {
             if ($index == self::SUBJECT_INDEX[self::SUBJECT_NEW]) {
-                $marketplaceOrder = self::createOrder($orderDetails, $campaignId, $statusId, $substatusId);
+                $marketplaceOrder = self::createOrderFlowwow($orderDetails, $campaignId, $statusId, $substatusId);
                 if ($marketplaceOrder->save()) {
                     self::sendMessageToTelegram($marketplaceOrder->guid, "Новый  заказ Флаувау");
                      $newOrdersCount += 1;
@@ -2197,7 +2200,7 @@ class MarketplaceService
         return $statuses[$statusCode];
     }
 
-    private static function createOrder($order, $campaignId, $statusId, $substatusId)
+    private static function createOrderFlowwow($order, $campaignId, $statusId, $substatusId)
     {
         $store = MarketplaceStore::find()
             ->where(['warehouse_guid' => (string)$campaignId])