Authored by wuxiao

Merge branch 'develop' into wuxiao

<?php
namespace backend\controllers;
use Yii;
use app\models\SysConfig;
/**
* Site controller
*/
class SystemController extends BaseController
{
public function actionServers()
{
$key = 'servers';
if (Yii::$app->request->isPost && trim(Yii::$app->request->post('content'))) {
$content = Yii::$app->request->post('content');
$ip_arr = explode(",",trim($content));
$ip_arr = array_map(function($v){return trim($v);},$ip_arr);
$model = SysConfig::findOne(['conf_key'=>$key]);
$model->conf_value = json_encode($ip_arr);
if($model->save()){
Yii::$app->session->setFlash('success', '保存成功。');
}else{
Yii::$app->session->setFlash('error', '保存失败。');
}
$this->redirect('/system/servers');
}else{
$model = SysConfig::find()->where(['conf_key' => $key])->one();
$ips = json_decode($model->conf_value, true);
return $this->render('servers', ['ips' => $ips]);
}
}
public function actionServAddr()
{
$key = 'serv_addr';
if( Yii::$app->request->isPost && trim(Yii::$app->request->post('content')) ){
$save_arr = [];
$content = Yii::$app->request->post('content');
$val_arr = explode(",",trim($content));
$val_arr = array_map(function($v){return trim($v);},$val_arr);
/*foreach($val_arr as $k=>$v){
list($host,$port) = explode(':',$v);
$save_arr[$k]['host']=$host;
$save_arr[$k]['port']=$port;
}*/
// var_dump($val_arr);exit;
$model = SysConfig::findOne(['conf_key'=>$key]);
$model->conf_value = json_encode($val_arr);
if($model->save()){
Yii::$app->session->setFlash('success', '保存成功。');
}else{
Yii::$app->session->setFlash('error', '保存失败。');
}
$this->redirect('/system/serv-addr');
}else{
$model = SysConfig::find()->where(['conf_key'=>$key])->one();
$data = json_decode($model->conf_value,true);
return $this->render('serv-addr',['data'=>$data]);
}
}
}
... ...
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%sys_config}}".
*
* @property integer $id
* @property string $conf_key
* @property string $conf_value
*/
class SysConfig extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%sys_config}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['conf_key'], 'required'],
[['conf_value'], 'string'],
[['conf_key'], 'string', 'max' => 50],
[['conf_key'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'conf_key' => 'Conf Key',
'conf_value' => 'Conf Value',
];
}
}
... ...
<?php
use yii\web\View;
$this->title = '管理后台首页';
?>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">弹幕服务器列表</h5>
</div>
<form class="form-inline" method="post" action="/system/serv-addr">
<div class="panel-body">
<div>
<div class="form-group">
<label class="col-sm-3 control-label">Textarea</label>
<div class="col-sm-9">
<textarea name="content" class="form-control" rows="10" cols="50"><?php echo $data ? implode(',',$data):''?></textarea>
</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-6">
</div>
\ No newline at end of file
... ...
<?php
use yii\web\View;
$this->title = '管理后台首页';
?>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">弹幕服务器列表</h5>
</div>
<form class="form-inline" method="post" action="/system/servers">
<div class="panel-body">
<div>
<div class="form-group">
<label class="col-sm-3 control-label">Textarea</label>
<div class="col-sm-9">
<textarea name="content" class="form-control" rows="10" cols="50"><?php echo $ips ? implode(',',$ips):''?></textarea>
</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<button class="btn btn-primary mr5" id="upload_button">保存</button>
<a href="<?=$_refer?>" class="btn btn-dark">取消</a>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-6">
</div>
\ No newline at end of file
... ...