From 622bc5781204cf3a63d26fb87ab17a9b33f4f322 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 28 Jan 2025 10:56:09 +0300 Subject: [PATCH] =?utf8?q?ERP-282=20=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20?= =?utf8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20=D0=B8=D0=BD=D1=82?= =?utf8?q?=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20=D0=BD=D0=B0=D1=81=D1=82?= =?utf8?q?=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?utf8?q?=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/records/CityStoreParams.php | 53 ++++++++++++++++++------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/erp24/records/CityStoreParams.php b/erp24/records/CityStoreParams.php index 25502245..adc9150f 100644 --- a/erp24/records/CityStoreParams.php +++ b/erp24/records/CityStoreParams.php @@ -99,60 +99,69 @@ class CityStoreParams extends ActiveRecord public function afterSave($insert, $changedAttributes) { - if (isset($changedAttributes->address_region)) { - CityStore::update(['region' => $changedAttributes->address_region], ['id' => $changedAttributes->store_id]); - } - - if (isset($changedAttributes->address_city)) { - CityStore::update(['city' => $changedAttributes->address_city], ['id' => $changedAttributes->store_id]); - } + $fields = [ + 'address_region' => 'region', + 'address_city' => 'city', + 'address_district' => 'district', + 'store_type' => 'type' + ]; - if (isset($changedAttributes->address_district)) { - CityStore::update(['district' => $changedAttributes->address_district], ['id' => $changedAttributes->store_id]); - } + foreach ($fields as $attribute => $field) { + $value = $insert ? $this->$attribute : ($changedAttributes[$attribute] ?? null); - if (isset($changedAttributes->address_type)) { - CityStore::update(['type' => $changedAttributes->address_type], ['id' => $changedAttributes->store_id]); + if (!empty($value)) { + CityStore::updateAll([$field => $value], ['id' => $this->store_id]); + } } } - public function getStore() { + public function getStore() + { return $this->hasOne(CityStore::class, ['id' => 'store_id']); } - public function getUpdatedBy() { + public function getUpdatedBy() + { return $this->hasOne(Admin::class, ['id' => 'updated_by']); } - public function getCreatedBy() { + public function getCreatedBy() + { return $this->hasOne(Admin::class, ['id' => 'created_by']); } - public function getTerritorialManager() { + public function getTerritorialManager() + { return $this->hasOne(Admin::class, ['id' => 'territorial_manager']); } - public function getBushChefFlorist() { + public function getBushChefFlorist() + { return $this->hasOne(Admin::class, ['id' => 'bush_chef_florist']); } - public function getMatrixType() { + public function getMatrixType() + { return $this->hasOne(MatrixType::class, ['id' => 'matrix_type']); } - public function getStoreType() { + public function getStoreType() + { return $this->hasOne(StoreType::class, ['id' => 'store_type']); } - public function getAddressRegion() { + public function getAddressRegion() + { return $this->hasOne(StoreCityList::class, ['id' => 'address_region']); } - public function getAddressDistrict() { + public function getAddressDistrict() + { return $this->hasOne(StoreCityList::class, ['id' => 'address_district']); } - public function getAddressCity() { + public function getAddressCity() + { return $this->hasOne(StoreCityList::class, ['id' => 'address_city']); } } -- 2.39.5