更新代码,完善功能
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\Client as ClientM;
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
@@ -15,71 +17,65 @@ use app\controller\Admin;
|
||||
*/
|
||||
class Client extends Admin {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->model = model('Client');
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 客户端列表
|
||||
*/
|
||||
public function index() {
|
||||
$list = $this->model->paginate(25, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
$data = array(
|
||||
$map = [];
|
||||
|
||||
$list = ClientM::where($map)->paginate($this->request->pageConfig);
|
||||
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('客户端列表');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加客户端
|
||||
*/
|
||||
public function add(\think\Request $request) {
|
||||
public function add() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $request->param();
|
||||
$result = $this->model->validate(true)->save($data);
|
||||
$data = $this->request->param();
|
||||
|
||||
$result = ClientM::create($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('成功添加', url('client/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$info['appid'] = rand_string(10, 1); //八位数字appid
|
||||
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
||||
$data = array(
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('添加客户端');
|
||||
return $this->fetch('add');
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑客户端
|
||||
*/
|
||||
public function edit(\think\Request $request) {
|
||||
public function edit() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $request->param();
|
||||
$result = $this->model->validate(true)->save($data, array('id' => $request->param('id')));
|
||||
$data = $this->request->param();
|
||||
|
||||
$result = ClientM::update($data, ['id' => $this->request->param('id')]);
|
||||
if (false !== $result) {
|
||||
return $this->success('修改添加', url('client/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
} else {
|
||||
$info = $this->model->where('id', $request->param('id'))->find();
|
||||
$data = array(
|
||||
$info = $ClientM::where('id', $request->param('id'))->find();
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('编辑客户端');
|
||||
return $this->fetch('add');
|
||||
return $this->fetch('admin/client/add');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user