&&
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) {
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));
--- /dev/null
+<?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');
+ }
+}
*
* @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}
*/
{
return [
[['product_id', 'price'], 'required'],
- [['price'], 'number'],
+ [['price', 'region_id'], 'number'],
[['product_id'], 'string', 'max' => 36],
[['product_id'], 'unique'],
];
return [
'product_id' => 'Product ID',
'price' => 'Price',
+ 'region_id' => 'Регион'
];
}
}
* @property string $date_from
* @property string|null $date_to
* @property int $active
+ * @property int|null $region_id
*/
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],
'date_from' => 'Date From',
'date_to' => 'Date To',
'active' => 'Active',
+ 'region_id' => 'Регион'
];
}
}