From: marina Date: Tue, 28 Jan 2025 07:56:09 +0000 (+0300) Subject: ERP-282 Нужно сделать интерфейс настройки магазина X-Git-Tag: 1.7~35^2~9 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=622bc5781204cf3a63d26fb87ab17a9b33f4f322;p=erp24_rep%2Fyii-erp24%2F.git ERP-282 Нужно сделать интерфейс настройки магазина --- 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']); } }