客服列表加角色

pull/30/head
taoshihan1991 4 years ago
parent d0ac4647b1
commit 8c700f0d8a

@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"strconv"
)
func GetKefuInfo(c *gin.Context){
@ -34,9 +35,19 @@ func PostKefuInfo(c *gin.Context){
password:=c.PostForm("password")
avator:=c.PostForm("avator")
nickname:=c.PostForm("nickname")
roleId:=c.PostForm("role_id")
if roleId==""{
c.JSON(200, gin.H{
"code": 400,
"msg": "请选择角色!",
})
return
}
//插入新用户
if id==""{
models.CreateUser(name,tools.Md5(password),avator,nickname)
uid:=models.CreateUser(name,tools.Md5(password),avator,nickname)
roleIdInt,_:=strconv.Atoi(roleId)
models.CreateUserRole(uid,uint(roleIdInt))
}else{
//更新用户
if password!=""{

@ -1,4 +1,9 @@
package models
import (
"strconv"
)
type User_role struct{
UserId string `json:"user_id"`
RoleId uint `json:"role_id"`
@ -7,4 +12,11 @@ func FindRoleByUserId(userId interface{})User_role{
var uRole User_role
DB.Where("user_id = ?", userId).First(&uRole)
return uRole
}
func CreateUserRole(userId uint,roleId uint){
uRole:=&User_role{
UserId:strconv.Itoa(int(userId)),
RoleId: roleId,
}
DB.Create(uRole)
}

@ -11,14 +11,14 @@ type User struct {
Avator string `json:"avator"`
RoleName string `json:"role_name"`
}
func CreateUser(name string,password string,avator string,nickname string){
func CreateUser(name string,password string,avator string,nickname string)uint{
user:=&User{
Name:name,
Password: password,
Avator:avator,
Nickname: nickname,
}
DB.Create(user)
return DB.Create(user).Value.(*User).ID
}
func UpdateUser(id string,name string,password string,avator string,nickname string){
user:=&User{
@ -46,7 +46,7 @@ func DeleteUserById(id string){
}
func FindUsers()[]User{
var users []User
DB.Order("id desc").Find(&users)
DB.Select("user.*,role.name role_name").Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").Order("user.id desc").Find(&users)
return users
}
func FindUserRole(query interface{},id interface{})User{

@ -27,6 +27,8 @@
![Image text](https://img2020.cnblogs.com/blog/726254/202009/726254-20200902141707515-1201702349.jpg)
![Image text](https://img2020.cnblogs.com/blog/726254/202009/726254-20200902141723679-927777888.png)
![Image text](https://img2020.cnblogs.com/blog/726254/202009/726254-20200902141736713-1155907367.jpg)
![Image text](https://img2020.cnblogs.com/blog/726254/202009/726254-20200902141745935-1312775469.jpg)

@ -60,10 +60,15 @@
password:"",
avator:"",
nickname:"",
role_name:"",
},
roleList:[],
roleDialog:false,
noticeList:[],
welcomeDialog:false,
welcomeForm: {
content: "",
},
roleForm:{
id:"",
name:"",
@ -146,6 +151,10 @@
showClose:true,
});
},
addWelcome(){
this.welcomeForm.content="";
this.welcomeDialog=true;
},
//初始化数据
initInfo(){
let _this=this;
@ -162,6 +171,9 @@
this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
this.sendAjax("/roles","get",{},function(result){
_this.roleList=result;
});
}
if(ACTION=="roles_list"){
this.sendAjax("/roles","get",{},function(result){

@ -25,6 +25,10 @@
prop="nickname"
label="客服昵称">
</el-table-column>
<el-table-column
prop="role_name"
label="角色">
</el-table-column>
<el-table-column
prop="created_at"
label="添加时间">
@ -63,6 +67,12 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item label="角色" prop="avator">
<el-select v-model="kefuForm.role_id" placeholder="请选择角色">
<el-option :label="item.role_name" :value="item.role_id" v-for="item in roleList" v-bind:key="item.role_id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="kefuDialog = false">取 消</el-button>

@ -7,7 +7,7 @@
<el-main class="mainMain">
<el-button style="margin-bottom: 10px;" @click="addWelcome" type="primary" size="small">添加欢迎</el-button>
<el-table
:data="notices"
:data="noticeList"
border
style="width: 100%">
<el-table-column
@ -30,6 +30,21 @@
</el-main>
</el-container>
<el-dialog
title="欢迎"
:visible.sync="welcomeDialog"
width="30%"
>
<el-form ref="welcomeForm" :model="welcomeForm" :rules="rules" label-width="70px">
<el-form-item label="内容" prop="content">
<el-input v-model="welcomeForm.content"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="welcomeDialog = false">取 消</el-button>
<el-button type="primary" @click="submitWelcomeForm('welcomeForm')">确 定</el-button>
</span>
</el-dialog>
</template>
</div>

Loading…
Cancel
Save