<?php
namespace app\store\controller\store;
use app\store\controller\Controller;
use app\store\model\store\Role as RoleModel;
use app\store\model\store\Access as AccessModel;
class Role extends Controller
{
public function index()
{
$model = new RoleModel;
$list = $model->getList();
return $this->fetch('index', compact('list'));
}
public function add()
{
$model = new RoleModel;
if (!$this->request->isAjax()) {
$accessList = (new AccessModel)->getJsTree();
$roleList = $model->getList();
return $this->fetch('add', compact('accessList', 'roleList'));
}
if ($model->add($this->postData('role'))) {
return $this->renderSuccess('添加成功', url('store.role/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
public function edit($role_id)
{
$model = RoleModel::detail($role_id);
if (!$this->request->isAjax()) {
$accessList = (new AccessModel)->getJsTree($model['role_id']);
$roleList = $model->getList();
return $this->fetch('edit', compact('model', 'accessList', 'roleList'));
}
if ($model->edit($this->postData('role'))) {
return $this->renderSuccess('更新成功', url('store.role/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function delete($role_id)
{
$model = RoleModel::detail($role_id);
if (!$model->remove()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}