From: Alexander Smirnov Date: Fri, 14 Feb 2025 10:30:49 +0000 (+0300) Subject: [ERP-323] region_id in prices and prices_dynamic X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ee8f7163c2523a0d90a66078eb1a4fdb3ae7662d;p=erp24_rep%2Fyii-erp24%2F.git [ERP-323] region_id in prices and prices_dynamic --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 7db1e314..f72026ac 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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 index 00000000..1a1d0bb8 --- /dev/null +++ b/erp24/migrations/m250214_095219_alter_table_prices_and_prices_dynamic_add_column_region_id.php @@ -0,0 +1,29 @@ +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'); + } +} diff --git a/erp24/records/Prices.php b/erp24/records/Prices.php index e9980583..8ceaab4e 100644 --- a/erp24/records/Prices.php +++ b/erp24/records/Prices.php @@ -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' => 'Регион' ]; } } diff --git a/erp24/records/PricesDynamic.php b/erp24/records/PricesDynamic.php index 45874daa..5a684c60 100755 --- a/erp24/records/PricesDynamic.php +++ b/erp24/records/PricesDynamic.php @@ -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' => 'Регион' ]; } }