You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.2 KiB
129 lines
3.2 KiB
1 year ago
|
<?php
|
||
|
|
||
|
namespace app\admin\controller\user;
|
||
|
|
||
|
use app\common\controller\Backend;
|
||
|
use app\common\library\Auth;
|
||
|
|
||
|
/**
|
||
|
* 会员管理
|
||
|
*
|
||
|
* @icon fa fa-user
|
||
|
*/
|
||
|
class User extends Backend
|
||
|
{
|
||
|
|
||
|
protected $relationSearch = true;
|
||
|
protected $searchFields = 'id,username,nickname';
|
||
|
protected $selectpageFields = ['id','nickname','avatar','username','mobile'];
|
||
|
|
||
|
/**
|
||
|
* @var \app\admin\model\User
|
||
|
*/
|
||
|
protected $model = null;
|
||
|
|
||
|
public function _initialize()
|
||
|
{
|
||
|
parent::_initialize();
|
||
|
$this->model = model('User');
|
||
|
$this->view->assign('statusList', $this->model->getStatusList());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 查看
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
//设置过滤方法
|
||
|
$this->request->filter(['strip_tags', 'trim']);
|
||
|
if ($this->request->isAjax()) {
|
||
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
|
if ($this->request->request('keyField')) {
|
||
|
return $this->selectpage();
|
||
|
}
|
||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
|
$list = $this->model
|
||
|
->with('user1')
|
||
|
->where($where)
|
||
|
->order($sort, $order)
|
||
|
->paginate($limit);
|
||
|
foreach ($list as $k => $v) {
|
||
|
$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
|
||
|
$v->hidden(['password', 'salt']);
|
||
|
}
|
||
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
|
|
||
|
return json($result);
|
||
|
}
|
||
|
return $this->view->fetch();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 添加
|
||
|
*/
|
||
|
public function add()
|
||
|
{
|
||
|
if ($this->request->isPost()) {
|
||
|
$this->token();
|
||
|
}
|
||
|
return parent::add();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑
|
||
|
*/
|
||
|
public function edit($ids = null)
|
||
|
{
|
||
|
$row = $this->model->get($ids);
|
||
|
|
||
|
if (!$row)
|
||
|
$this->error(__('No Results were found'));
|
||
|
if ($this->request->isPost()){
|
||
|
$params = $this->request->post("row/a");
|
||
|
$params['updatetime'] = time();
|
||
|
$params['deadline'] = strtotime($params['deadline']) < 0 ? 0 : strtotime($params['deadline']);
|
||
|
// var_dump($params);
|
||
|
// exit();
|
||
|
$ret = $this->model->update($params, ['id'=>$ids]);
|
||
|
if(!$ret){
|
||
|
$this->error(__('Operation failed'));
|
||
|
}
|
||
|
|
||
|
return $this->success();
|
||
|
}
|
||
|
$arr = $row->toArray();
|
||
|
|
||
|
$this->view->assign("row", $arr);
|
||
|
return $this->view->fetch();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除
|
||
|
*/
|
||
|
public function del($ids = "")
|
||
|
{
|
||
|
if (!$this->request->isPost()) {
|
||
|
$this->error(__("Invalid parameters"));
|
||
|
}
|
||
|
$ids = $ids ? $ids : $this->request->post("ids");
|
||
|
$row = $this->model->get($ids);
|
||
|
$this->modelValidate = true;
|
||
|
if (!$row) {
|
||
|
$this->error(__('No Results were found'));
|
||
|
}
|
||
|
Auth::instance()->delete($row['id']);
|
||
|
$this->success();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Selectpage搜索
|
||
|
*
|
||
|
* @internal
|
||
|
*/
|
||
|
public function selectpage()
|
||
|
{
|
||
|
return parent::selectpage();
|
||
|
}
|
||
|
|
||
|
}
|