From 9e77453330f8039c624abb8bd1f4f4e157834c95 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Wed, 10 Sep 2025 16:24:36 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=B8=20=D0=BF=D1=80?= =?utf8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D1=81=D1=82=D0=B0=D1=82?= =?utf8?q?=D1=83=D1=81=D0=BE=D0=B2=20=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0?= =?utf8?q?=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...o_marketplace_order_status_types_table.php | 52 +++++++++++++++++++ erp24/records/MarketplaceOrderStatusTypes.php | 17 ++++++ erp24/services/MarketplaceService.php | 7 ++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 erp24/migrations/m250910_130353_add_created_at_field_to_marketplace_order_status_types_table.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 index 00000000..e768527e --- /dev/null +++ b/erp24/migrations/m250910_130353_add_created_at_field_to_marketplace_order_status_types_table.php @@ -0,0 +1,52 @@ +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; + } + */ +} diff --git a/erp24/records/MarketplaceOrderStatusTypes.php b/erp24/records/MarketplaceOrderStatusTypes.php index 63a2b84d..4a34061c 100644 --- a/erp24/records/MarketplaceOrderStatusTypes.php +++ b/erp24/records/MarketplaceOrderStatusTypes.php @@ -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' => 'Время создания' ]; } } diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index 85479c3f..fcade407 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -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]) -- 2.39.5