]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-323] удаление region_id из prices, добавления prices_region
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Feb 2025 13:52:21 +0000 (16:52 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Feb 2025 13:52:21 +0000 (16:52 +0300)
erp24/api2/controllers/DataController.php
erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php
erp24/migrations/m250214_113003_alter_table_drop_unique_product_id_in_prices.php
erp24/records/Prices.php
erp24/records/PricesRegion.php [new file with mode: 0644]

index f72026ac9499000099b1d65274606d2d1492b79a..1e9086ffa33a19f9a9ab0905c1043eb50f300e47 100644 (file)
@@ -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);
index 1a1d0bb8f48b1bf543fcee56b4029660d04ed527..c1d8c0cb41e2f133aab5710a04b9d218c543ea9e 100755 (executable)
@@ -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');
     }
 }
index b41335e7ceeb0850e9f7a3162713c6b19701e32c..dc72abe1a7d9e496d255ebd5f8d8310270ac0c88 100755 (executable)
@@ -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);
     }
 }
index adce77020ad4e5055996e0f5fe5d8837c1378088..b74efefc9b99187af928c0602ca274e6d1d3747a 100644 (file)
@@ -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 (file)
index 0000000..613db81
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "prices_region".
+ *
+ * @property int $id
+ * @property string $product_id GUID товара из таблицы products_1c
+ * @property int $region_id Регион
+ * @property float $price Цена
+ */
+class PricesRegion extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'prices_region';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['product_id', 'region_id', 'price'], 'required'],
+            [['region_id'], 'default', 'value' => 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',
+        ];
+    }
+}