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;
)
) {
$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);
*/
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('Регион'));
}
public function safeDown()
{
$this->dropColumn(self::TABLE_NAME2, 'region_id');
- $this->dropColumn(self::TABLE_NAME, 'region_id');
}
}
*/
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('Цена'),
+ ]);
}
/**
*/
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);
}
}
*
* @property string $product_id
* @property float $price
- * @property int|null $region_id
*/
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'],
];
}
return [
'product_id' => 'Product ID',
'price' => 'Price',
- 'region_id' => 'Регион'
];
}
}
--- /dev/null
+<?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',
+ ];
+ }
+}