From: Alexander Smirnov Date: Mon, 17 Feb 2025 13:52:21 +0000 (+0300) Subject: [ERP-323] удаление region_id из prices, добавления prices_region X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d98f5ab367211deb786f11a25c00fd002ffeee35;p=erp24_rep%2Fyii-erp24%2F.git [ERP-323] удаление region_id из prices, добавления prices_region --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index f72026ac..1e9086ff 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -28,6 +28,7 @@ use yii_app\records\OrdersAmo; use yii_app\records\PaymentTypes; use yii_app\records\Prices; use yii_app\records\PricesDynamic; +use yii_app\records\PricesRegion; use yii_app\records\PricesZakup; use yii_app\records\Products1cNomenclature; use yii_app\records\Products1cPropType; @@ -1901,15 +1902,23 @@ class DataController extends BaseController ) ) { $region_id = Prices::REGION_TYPE_PRICES[$type_price]; - Prices::deleteAll(['product_id' => $idp, 'region_id' => $region_id]); + Prices::deleteAll(['product_id' => $idp]); $price1 = new Prices; $price1->product_id = $idp; $price1->price = $price; - $price1->region_id = $region_id; $price1->save(); if ($price1->getErrors()) { LogService::apiErrorLog(json_encode(["error_id" => 27, "error" => $price1->getErrors()], JSON_UNESCAPED_UNICODE)); } + PricesRegion::deleteAll(['product_id' => $idp, 'region_Id' => $region_id]); + $priceRegion = new PricesRegion; + $priceRegion->product_id = $idp; + $priceRegion->region_id = $region_id; + $priceRegion->price = $price; + $priceRegion->save(); + if ($priceRegion->getErrors()) { + LogService::apiErrorLog(json_encode(["error_id" => 27.5, "error" => $priceRegion->getErrors()], JSON_UNESCAPED_UNICODE)); + } try { $pricesDynamic = PricesDynamic::find()->where(['product_id' => $idp, 'region_id' => $region_id])->andWhere(['active' => '1'])->orderBy(['id' => SORT_DESC])->one(); $price = round($price, 2); diff --git a/erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php b/erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php index 1a1d0bb8..c1d8c0cb 100755 --- a/erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php +++ b/erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php @@ -14,7 +14,6 @@ class m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id */ public function safeUp() { - $this->addColumn(self::TABLE_NAME, 'region_id', $this->integer()->null()->comment('Регион')); $this->addColumn(self::TABLE_NAME2, 'region_id', $this->integer()->null()->comment('Регион')); } @@ -24,6 +23,5 @@ class m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id public function safeDown() { $this->dropColumn(self::TABLE_NAME2, 'region_id'); - $this->dropColumn(self::TABLE_NAME, 'region_id'); } } diff --git a/erp24/migrations/m250214_113003_alter_table_drop_unique_product_id_in_prices.php b/erp24/migrations/m250214_113003_alter_table_drop_unique_product_id_in_prices.php index b41335e7..dc72abe1 100755 --- a/erp24/migrations/m250214_113003_alter_table_drop_unique_product_id_in_prices.php +++ b/erp24/migrations/m250214_113003_alter_table_drop_unique_product_id_in_prices.php @@ -7,16 +7,19 @@ use yii\db\Migration; */ class m250214_113003_alter_table_drop_unique_product_id_in_prices extends Migration { - const TABLE_NAME = 'erp24.prices'; + const TABLE_NAME = 'erp24.prices_region'; /** * {@inheritdoc} */ public function safeUp() { - - $this->dropIndex('idx_463248_primary', self::TABLE_NAME); - $this->dropIndex('idx_463248_product_id', self::TABLE_NAME); + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'product_id' => $this->string(36)->notNull()->comment('GUID товара из таблицы products_1c'), + 'region_id' => $this->integer()->notNull()->comment('Регион'), + 'price' => $this->float()->notNull()->comment('Цена'), + ]); } /** @@ -24,7 +27,6 @@ class m250214_113003_alter_table_drop_unique_product_id_in_prices extends Migrat */ public function safeDown() { - $this->createIndex('idx_463248_primary', self::TABLE_NAME, 'product_id'); - $this->createIndex('idx_463248_product_id', self::TABLE_NAME, 'product_id', true); + $this->dropTable(self::TABLE_NAME); } } diff --git a/erp24/records/Prices.php b/erp24/records/Prices.php index adce7702..b74efefc 100644 --- a/erp24/records/Prices.php +++ b/erp24/records/Prices.php @@ -9,7 +9,6 @@ use Yii; * * @property string $product_id * @property float $price - * @property int|null $region_id */ class Prices extends \yii\db\ActiveRecord { @@ -33,9 +32,9 @@ class Prices extends \yii\db\ActiveRecord { return [ [['product_id', 'price'], 'required'], - [['price', 'region_id'], 'number'], + [['price'], 'number'], [['product_id'], 'string', 'max' => 36], - //[['product_id'], 'unique'], + [['product_id'], 'unique'], ]; } @@ -47,7 +46,6 @@ class Prices extends \yii\db\ActiveRecord return [ 'product_id' => 'Product ID', 'price' => 'Price', - 'region_id' => 'Регион' ]; } } diff --git a/erp24/records/PricesRegion.php b/erp24/records/PricesRegion.php new file mode 100644 index 00000000..613db817 --- /dev/null +++ b/erp24/records/PricesRegion.php @@ -0,0 +1,51 @@ + null], + [['region_id'], 'integer'], + [['price'], 'number'], + [['product_id'], 'string', 'max' => 36], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'product_id' => 'Product ID', + 'region_id' => 'Region ID', + 'price' => 'Price', + ]; + } +}