]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-323] region_id in prices and prices_dynamic
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 14 Feb 2025 10:30:49 +0000 (13:30 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 14 Feb 2025 10:30:49 +0000 (13:30 +0300)
erp24/api2/controllers/DataController.php
erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php [new file with mode: 0755]
erp24/records/Prices.php
erp24/records/PricesDynamic.php

index 7db1e3141b5e5cf6f43ec3f3955dc58dcd95bf4a..f72026ac9499000099b1d65274606d2d1492b79a 100644 (file)
@@ -1897,22 +1897,21 @@ class DataController extends BaseController
                         &&
                         in_array(
                             $type_price,
-                            [
-                                "Розничная цена",
-                                "Розничная Маг на Московск",
-                            ]
+                            array_keys(Prices::REGION_TYPE_PRICES)
                         )
                     ) {
-                        Prices::deleteAll(['product_id' => $idp]);
+                        $region_id = Prices::REGION_TYPE_PRICES[$type_price];
+                        Prices::deleteAll(['product_id' => $idp, 'region_id' => $region_id]);
                         $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));
                         }
                         try {
-                            $pricesDynamic = PricesDynamic::find()->where(['product_id' => $idp])->andWhere(['active' => '1'])->orderBy(['id' => SORT_DESC])->one();
+                            $pricesDynamic = PricesDynamic::find()->where(['product_id' => $idp, 'region_id' => $region_id])->andWhere(['active' => '1'])->orderBy(['id' => SORT_DESC])->one();
                             $price = round($price, 2);
                             // если нет записи или цена изменилась то вносим запись в БД
                             if ($pricesDynamic and $pricesDynamic->price != $price) {
@@ -1923,13 +1922,14 @@ class DataController extends BaseController
                                     LogService::apiErrorLog(json_encode(["error_id" => 28, "error" => $pricesDynamic->getErrors()], JSON_UNESCAPED_UNICODE));
                                 }
                             }
-                            if (!$pricesDynamic or ($pricesDynamic and $pricesDynamic->price != $price)) {
+                            if (!$pricesDynamic or ($pricesDynamic and ($pricesDynamic->price != $price || $pricesDynamic->region_id != $region_id))) {
                                 $pricesDynamic2 = new PricesDynamic;
                                 $pricesDynamic2->product_id = $idp;
                                 $pricesDynamic2->price = $price;
                                 $pricesDynamic2->date_from = date('Y-m-d H:i:s');
                                 $pricesDynamic2->date_to = '2100-01-01 00:00:00';
                                 $pricesDynamic2->active = 1;
+                                $pricesDynamic2->region_id = $region_id;
                                 $pricesDynamic2->save();
                                 if ($pricesDynamic2->getErrors()) {
                                     LogService::apiErrorLog(json_encode(["error_id" => 29, "error" => $pricesDynamic2->getErrors()], JSON_UNESCAPED_UNICODE));
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
new file mode 100755 (executable)
index 0000000..1a1d0bb
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id
+ */
+class m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id extends Migration
+{
+    const TABLE_NAME = 'erp24.prices';
+    const TABLE_NAME2 = 'erp24.prices_dynamic';
+    /**
+     * {@inheritdoc}
+     */
+    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('Регион'));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropColumn(self::TABLE_NAME2, 'region_id');
+        $this->dropColumn(self::TABLE_NAME, 'region_id');
+    }
+}
index e9980583f8dd1432f6f235c19fd50652898dd20d..8ceaab4e27e874452ad485f42fa58e8b2477f361 100644 (file)
@@ -9,9 +9,15 @@ use Yii;
  *
  * @property string $product_id
  * @property float $price
+ * @property int|null $region_id
  */
 class Prices extends \yii\db\ActiveRecord
 {
+    public const REGION_TYPE_PRICES = [
+        "Розничная цена" => 52,
+        "Розничная Маг на Московск" => 77,
+    ];
+
     /**
      * {@inheritdoc}
      */
@@ -27,7 +33,7 @@ class Prices extends \yii\db\ActiveRecord
     {
         return [
             [['product_id', 'price'], 'required'],
-            [['price'], 'number'],
+            [['price', 'region_id'], 'number'],
             [['product_id'], 'string', 'max' => 36],
             [['product_id'], 'unique'],
         ];
@@ -41,6 +47,7 @@ class Prices extends \yii\db\ActiveRecord
         return [
             'product_id' => 'Product ID',
             'price' => 'Price',
+            'region_id' => 'Регион'
         ];
     }
 }
index 45874daa9a97f91d632ef43571708c4ae6b46175..5a684c60af7d381e5669db2498244bd3c725526a 100755 (executable)
@@ -13,6 +13,7 @@ use Yii;
  * @property string $date_from
  * @property string|null $date_to
  * @property int $active
+ * @property int|null $region_id
  */
 class PricesDynamic extends \yii\db\ActiveRecord
 {
@@ -31,7 +32,7 @@ class PricesDynamic extends \yii\db\ActiveRecord
     {
         return [
             [['product_id', 'price'], 'required'],
-            [['price'], 'number'],
+            [['price', 'region_id'], 'number'],
             [['date_from', 'date_to'], 'safe'],
             [['active'], 'integer'],
             [['product_id'], 'string', 'max' => 36],
@@ -50,6 +51,7 @@ class PricesDynamic extends \yii\db\ActiveRecord
             'date_from' => 'Date From',
             'date_to' => 'Date To',
             'active' => 'Active',
+            'region_id' => 'Регион'
         ];
     }
 }