|
@@ -17,9 +17,9 @@ use app\admin\model\Admin;
|
|
|
*/
|
|
|
class Staff extends Base {
|
|
|
|
|
|
- public function _initialize() {
|
|
|
- parent::_initialize();
|
|
|
- $this->model = new StaffModel();
|
|
|
+ public function _initialize() {
|
|
|
+ parent::_initialize();
|
|
|
+ $this->model = new StaffModel();
|
|
|
|
|
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
|
|
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
|
|
@@ -27,14 +27,14 @@ class Staff extends Base {
|
|
|
//角色组
|
|
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
|
|
|
Tree::instance()->init($groupList);
|
|
|
- $groupdata = [];
|
|
|
+ $groupdata = ['' => '请选择'];
|
|
|
if ($this->auth->isSuperAdmin()) {
|
|
|
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
|
|
|
foreach ($result as $k => $v) {
|
|
|
$groupdata[$v['id']] = $v['name'];
|
|
|
}
|
|
|
} else {
|
|
|
- $result = [];
|
|
|
+ $result = ['' => '请选择'];
|
|
|
$groups = $this->auth->getGroups();
|
|
|
foreach ($groups as $m => $n) {
|
|
|
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
|
|
@@ -48,36 +48,37 @@ class Staff extends Base {
|
|
|
}
|
|
|
$this->view->assign('groupdata', $groupdata);
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 员工列表
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function index() {
|
|
|
- $this->request->filter(['strip_tags']);
|
|
|
- if ($this->request->isAjax()) {
|
|
|
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
+ public function index() {
|
|
|
+ $this->request->filter(['strip_tags']);
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
- $list = $this->model->with(['parent','admin','staffrole'])
|
|
|
+ $list = $this->model->with(['parent','admin','staffrole'])
|
|
|
+ ->where(['id' => ['!=', 1]])
|
|
|
->where($where)->order($sort, $order)->paginate($limit);
|
|
|
- $row = $list->items();
|
|
|
+ $row = $list->items();
|
|
|
|
|
|
- $result = array("total" => $list->total(), "rows" => $row);
|
|
|
+ $result = array("total" => $list->total(), "rows" => $row);
|
|
|
|
|
|
- return json($result);
|
|
|
- }
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 添加员工
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function add() {
|
|
|
+ public function add() {
|
|
|
if ($this->request->isAjax()) {
|
|
|
$data = $this->request->post('row/a');
|
|
|
$mobile = $data['mobile'];
|
|
@@ -117,15 +118,26 @@ class Staff extends Base {
|
|
|
$this->success('提交成功');
|
|
|
}
|
|
|
|
|
|
- $staffname = StaffModel::where([])->column('id,name');
|
|
|
- $staffs = ['' => '无'];
|
|
|
- foreach ($staffname as $id => $name) {
|
|
|
- $staffs[$id] = $name;
|
|
|
- }
|
|
|
- $this->view->assign('roles',StaffRole::where([])->column('name','id'));
|
|
|
- $this->view->assign('staffs', $staffs);
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
+ $staffname = StaffModel::column('id,name');
|
|
|
+ $staffs = ['' => '请选择'];
|
|
|
+ foreach ($staffname as $id => $name) {
|
|
|
+ $staffs[$id] = $name;
|
|
|
+ }
|
|
|
+ $this->view->assign('staffs', $staffs);
|
|
|
+
|
|
|
+ $staffname = StaffModel::column('id,name');
|
|
|
+ $staffs = ['' => '无'];
|
|
|
+ foreach ($staffname as $id => $name) {
|
|
|
+ $staffs[$id] = $name;
|
|
|
+ }
|
|
|
+ $role_list = ['' => '请选择'];
|
|
|
+ $staff_role = StaffRole::column('name','id');
|
|
|
+ foreach ($staff_role as $key => $value) {
|
|
|
+ $role_list[$key] = $value;
|
|
|
+ }
|
|
|
+ $this->view->assign('roles', $role_list);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -133,21 +145,21 @@ class Staff extends Base {
|
|
|
* @param null $ids
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function edit($ids = null) {
|
|
|
- $map['id'] = $ids;
|
|
|
- if ($this->request->isAjax()) {
|
|
|
- $data = $this->request->post('row/a');
|
|
|
-
|
|
|
+ public function edit($ids = null) {
|
|
|
+ $map['id'] = $ids;
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ $row = StaffModel::where($map)->find();
|
|
|
|
|
|
- if($data['password']){
|
|
|
+ $data = $this->request->post('row/a');
|
|
|
+ if ($data['password']) {
|
|
|
$newSalt = substr(md5(uniqid(true)), 0, 6);
|
|
|
$newPassword = md5(md5($data['password']) . $newSalt);
|
|
|
$data['salt'] = $newSalt;
|
|
|
$data['password'] = $newPassword;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
unset($data['password']);
|
|
|
}
|
|
|
- $mobile=$data['mobile'];
|
|
|
+ $mobile = $data['mobile'];
|
|
|
$count = StaffModel::where(['mobile'=>$mobile,'id'=>['neq',$ids]])->count();
|
|
|
if($count > 0){
|
|
|
$this->error('员工手机号已存在');
|
|
@@ -157,89 +169,119 @@ class Staff extends Base {
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $group = $this->request->post("group/a",[]);
|
|
|
- //过滤不允许的组别,避免越权
|
|
|
- $group = array_intersect($this->childrenGroupIds, $group);
|
|
|
- if (!$group) {
|
|
|
- exception(__('The parent group exceeds permission limit'));
|
|
|
+ if ($row['id'] != 15) {
|
|
|
+ // 先移除所有权限
|
|
|
+ model('AuthGroupAccess')->where('uid', $row->admin_id)->delete();
|
|
|
+
|
|
|
+ $group = $this->request->post("group/a",[]);
|
|
|
+ //过滤不允许的组别,避免越权
|
|
|
+ $group = array_intersect($this->childrenGroupIds, $group);
|
|
|
+ if (!$group) {
|
|
|
+ exception(__('The parent group exceeds permission limit'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $dataset = [];
|
|
|
+ foreach ($group as $value) {
|
|
|
+ $dataset[] = ['uid' => $row->admin_id, 'group_id' => $value];
|
|
|
+ }
|
|
|
+ model('AuthGroupAccess')->saveAll($dataset);
|
|
|
+
|
|
|
+ $data['group_ids'] = implode(',', $group);
|
|
|
}
|
|
|
- $data['group_ids']=implode(',',$group);
|
|
|
- $data['id']=$map['id'];
|
|
|
- $result=$this->model->save($data,$map);
|
|
|
+ $data['id'] = $map['id'];
|
|
|
+ $result = $this->model->save($data, $map);
|
|
|
Db::commit();
|
|
|
}catch (Exception $e){
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
|
|
|
- if (!$result) {
|
|
|
- $this->error('修改失败');
|
|
|
- }
|
|
|
- $this->success('修改成功');
|
|
|
- }
|
|
|
- $data = StaffModel::where($map)->find();
|
|
|
- $this->view->assign("row", $data);
|
|
|
-
|
|
|
- $staffname = StaffModel::where([])->column('id,name');
|
|
|
- $staffs = ['' => '无'];
|
|
|
- foreach ($staffname as $id => $name) {
|
|
|
- $staffs[$id] = $name;
|
|
|
- }
|
|
|
- $this->view->assign('roles',StaffRole::where([])->column('name','id'));
|
|
|
- $this->view->assign('staffs', $staffs);
|
|
|
-
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
+ if (!$result) {
|
|
|
+ $this->error('修改失败');
|
|
|
+ }
|
|
|
+ $this->success('修改成功');
|
|
|
+ }
|
|
|
+ $data = StaffModel::where($map)->find();
|
|
|
+ $this->view->assign("row", $data);
|
|
|
+
|
|
|
+ $staffname = StaffModel::where([])->column('id,name');
|
|
|
+ $staffs = ['' => '请选择'];
|
|
|
+ foreach ($staffname as $id => $name) {
|
|
|
+ $staffs[$id] = $name;
|
|
|
+ }
|
|
|
+ $this->view->assign('staffs', $staffs);
|
|
|
+
|
|
|
+ $role_list = ['' => '请选择'];
|
|
|
+ $staff_role = StaffRole::column('name','id');
|
|
|
+ foreach ($staff_role as $key => $value) {
|
|
|
+ $role_list[$key] = $value;
|
|
|
+ }
|
|
|
+ $this->view->assign('roles',$role_list);
|
|
|
+
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 删除员工
|
|
|
*/
|
|
|
- public function del($ids = null) {
|
|
|
- if ($this->request->isAjax()) {
|
|
|
- $map['id'] = array('in', $ids);
|
|
|
+ public function del($ids = null) {
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ $map['id'] = array('in', $ids);
|
|
|
$findinfo = StaffModel::where($map)->select();
|
|
|
foreach($findinfo as $k=>$v){
|
|
|
- if($v['admin_id'] ==1){
|
|
|
+ if($v['admin_id'] ==1 || $v['id'] == 15){
|
|
|
$this->error('管理员不可删除');
|
|
|
}
|
|
|
}
|
|
|
- $result = StaffModel::destroy($map);
|
|
|
+ $result = StaffModel::destroy($map);
|
|
|
|
|
|
- if (!$result) {
|
|
|
- $this->error('删除失败');
|
|
|
- }
|
|
|
+ if (!$result) {
|
|
|
+ $this->error('删除失败');
|
|
|
+ }
|
|
|
// $cids = Customer::where(['owner_staff_id' => $ids])->column('id');
|
|
|
- try {
|
|
|
+ try {
|
|
|
// foreach ($cids as $id) {
|
|
|
// Customer::moveSeas($id);
|
|
|
// }
|
|
|
- } catch (Exception $e) {
|
|
|
+ } catch (Exception $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- $this->success('删除成功');
|
|
|
- }
|
|
|
+ $this->success('删除成功');
|
|
|
+ }
|
|
|
|
|
|
- return $this->view->fetch();
|
|
|
- }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新状态禁用账号
|
|
|
*/
|
|
|
- public function update_status() {
|
|
|
- $id = input('ids');
|
|
|
- $status = input('status', 2, 'intval');
|
|
|
-
|
|
|
- $staff = $this->model->where(['id' => $id])->find();
|
|
|
- if (empty($staff)) {
|
|
|
- $this->error('员工不存在');
|
|
|
- }
|
|
|
- if ($this->model->isUpdate(true)->save(['id' => $id, 'status' => $status])) {
|
|
|
- $this->success('操作成功');
|
|
|
- }
|
|
|
- $this->error('操作失败');
|
|
|
- }
|
|
|
+ public function update_status() {
|
|
|
+ $id = input('ids');
|
|
|
+ $status = input('status', 2, 'intval');
|
|
|
+
|
|
|
+ $staff = $this->model->where(['id' => $id])->find();
|
|
|
+ if (empty($staff)) {
|
|
|
+ $this->error('员工不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 把对应管理员表状态改为禁用
|
|
|
+ $admin = Admin::where(['id' => $staff['admin_id']])->find();
|
|
|
+ if ($admin) {
|
|
|
+ if ($status == 2) {
|
|
|
+ $admin->status = 'hidden';
|
|
|
+ } else {
|
|
|
+ $admin->status = 'normal';
|
|
|
+ }
|
|
|
+ $admin->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->model->isUpdate(true)->save(['id' => $id, 'status' => $status])) {
|
|
|
+ $this->success('操作成功');
|
|
|
+ }
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取员工角色
|