|
|
@@ -4,6 +4,7 @@
|
|
|
* Date: 2017/10/23 13:33
|
|
|
* Email: 1902822973@qq.com
|
|
|
*/
|
|
|
+
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
class Groups extends Base
|
|
|
@@ -11,14 +12,14 @@ class Groups extends Base
|
|
|
// 分组列表
|
|
|
public function index()
|
|
|
{
|
|
|
- if(request()->isAjax()){
|
|
|
+ if (request()->isAjax()) {
|
|
|
|
|
|
$result = db('groups')->select();
|
|
|
- foreach($result as $key=>$vo){
|
|
|
+ foreach ($result as $key => $vo) {
|
|
|
// 优化显示状态
|
|
|
- if(1 == $vo['status']){
|
|
|
+ if (1 == $vo['status']) {
|
|
|
$result[$key]['status'] = '<span style="color: #2fbe1b">启用</span>';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$result[$key]['status'] = '<span style="color: red">禁用</span>';
|
|
|
}
|
|
|
|
|
|
@@ -52,18 +53,18 @@ class Groups extends Base
|
|
|
// 添加分组
|
|
|
public function addGroup()
|
|
|
{
|
|
|
- if(request()->isPost()){
|
|
|
+ if (request()->isPost()) {
|
|
|
|
|
|
$param = input('post.');
|
|
|
|
|
|
$has = db('groups')->field('id')->where('name', $param['name'])->find();
|
|
|
- if(!empty($has)){
|
|
|
+ if (!empty($has)) {
|
|
|
return json(['code' => -1, 'data' => '', 'msg' => '该分组已经存在']);
|
|
|
}
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
db('groups')->insert($param);
|
|
|
- }catch(\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
}
|
|
|
|
|
|
@@ -81,19 +82,19 @@ class Groups extends Base
|
|
|
// 编辑分组
|
|
|
public function editGroup()
|
|
|
{
|
|
|
- if(request()->isAjax()){
|
|
|
+ if (request()->isAjax()) {
|
|
|
|
|
|
$param = input('post.');
|
|
|
|
|
|
// 检测用户修改的用户名是否重复
|
|
|
$has = db('groups')->where('name', $param['name'])->where('id', '<>', $param['id'])->find();
|
|
|
- if(!empty($has)){
|
|
|
+ if (!empty($has)) {
|
|
|
return json(['code' => -1, 'data' => '', 'msg' => '该分组已经存在']);
|
|
|
}
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
db('groups')->where('id', $param['id'])->update($param);
|
|
|
- }catch(\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
}
|
|
|
|
|
|
@@ -114,18 +115,21 @@ class Groups extends Base
|
|
|
// 删除分组
|
|
|
public function delGroup()
|
|
|
{
|
|
|
- if(request()->isAjax()){
|
|
|
+ if (request()->isAjax()) {
|
|
|
$id = input('param.id/d');
|
|
|
+ if ($id == 99999) {
|
|
|
+ return json(['code' => -3, 'data' => '', 'msg' => '公共组,不可删除']);
|
|
|
+ }
|
|
|
|
|
|
// 查询该分组下是否有客服
|
|
|
$has = db('users')->where('group_id', $id)->count();
|
|
|
- if($has > 0){
|
|
|
+ if ($has > 0) {
|
|
|
return json(['code' => -2, 'data' => '', 'msg' => '该分组下有客服,不可删除']);
|
|
|
}
|
|
|
|
|
|
- try{
|
|
|
+ try {
|
|
|
db('groups')->where('id', $id)->delete();
|
|
|
- }catch(\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
|
|
|
}
|
|
|
|