<?php /** * @author 河南鼎汉软件科技 * @copyright Copyright (c) 2017 HNDH Software Technology Co., Ltd. * createtime: 2017/9/21 10:53 */ namespace backend\modules\game\controllers; use backend\controllers\ControllerBase; use common\models\GameGoods; class GoodsController extends ControllerBase { /** * @return string */ public function actionIndex() { $query = GameGoods::find()->orderBy('updated_at desc'); return $this->render('index', ['query' => $query]); } /** * @param $id * @return string|\yii\web\Response */ public function actionUpdate($id) { $model = GameGoods::findOne($id); if ($model->load(\Yii::$app->request->post())) { // 格式化生长周期 $model->growth = json_encode($model->growth); if ($model->type != '1') { $model->growth = null; } if ($model->save()) { return $this->message('更新成功!', ['goods/index'], 'success'); } else { return $this->message('保存失败!' . current($model->getFirstErrors()), 'referer', 'error'); } } if (!empty($model->growth)) { $model->growth = json_decode($model->growth, true); } return $this->render('update', ['model' => $model]); } }