Exemplo n.º 1
0
 /**
  * Lists all System models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new System();
     $postData = Yii::$app->request->post('System');
     if (count($postData)) {
         foreach ($postData as $key => $da) {
             if ($key == 'lowest_cash_amount') {
                 $da = $da * 100;
             }
             $system = System::findOne(['name' => $key]);
             if ($system && $system->id) {
                 $oldValue = $system->value;
                 $system->value = $da;
                 if ($system->save() && $da != $oldValue) {
                     Yii::$app->systemlog->add('管理员', '修改系统参数', '成功', $key . ': 从 (' . $oldValue . ')改为(' . $da . ')');
                 } else {
                     if ($da != $oldValue) {
                         Yii::$app->systemlog->add('管理员', '修改系统参数', '失败', $key . ': 从 (' . $oldValue . ')改为(' . $da . ')');
                     }
                 }
             } else {
                 $system = new System();
                 $system->name = $key;
                 $system->value = $da;
                 $system->save();
             }
             Yii::$app->session->setFlash('success', '保存成功.');
         }
         Yii::$app->cache->set('SYSTEM_CONFIG', null);
     }
     $data = System::loadConfig();
     if ($data && count($data)) {
         foreach ($data as $key => $da) {
             $model->{$key} = $da;
         }
     }
     return $this->render('index', ['model' => $model]);
 }