| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace addons\StarChain\common\models;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_star_chain_setting_log}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property string|null $before_setting 更新前配置
- * @property int|null $created_at 创建时间
- */
- class SettingLog extends BaseModel
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_star_chain_setting_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'created_at'], 'integer'],
- [['before_setting'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'before_setting' => 'Before Setting',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * 添加setting修改日志
- *
- * @param Setting $setting
- * @return boolean
- */
- public static function addSettingLog(Setting $setting)
- {
- // 修改前设置
- $old_setting = $setting->oldAttributes;
-
- // 新增为空时不操作
- if (empty($old_setting)) return true;
-
- // before_setting
- $before_setting = [
- 'app_key' => $old_setting['app_key'],
- 'app_secret' => $old_setting['app_secret'],
- 'auto_update' => Json::decode($old_setting['auto_update']),
- 'sell' => Json::decode($old_setting['sell']),
- 'cost' => Json::decode($old_setting['cost']),
- 'original' => Json::decode($old_setting['original']),
- ];
- $data = [
- 'mall_id' => $old_setting['mall_id'],
- 'before_setting' => Json::encode($before_setting),
- ];
- $model = new self();
- return ($model->load($data, '') && $model->save());
- }
- }
|