1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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]);
}
}