Commit cd528437 by chenxianqi

update

parent f0eec77b
......@@ -35,8 +35,8 @@ func (c *AdminController) Finish() {}
// GetMeInfo get me info
func (c *AdminController) GetMeInfo() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil {
c.JSON(configs.ResponseFail, "fail,用户不存在!", nil)
......@@ -48,8 +48,8 @@ func (c *AdminController) GetMeInfo() {
// Get admin
func (c *AdminController) Get() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil {
c.JSON(configs.ResponseFail, "fail,用户不存在!", nil)
......@@ -72,8 +72,8 @@ func (c *AdminController) Get() {
// Put update admin
func (c *AdminController) Put() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// get request
admin := models.Admin{}
......@@ -127,8 +127,8 @@ func (c *AdminController) Put() {
// Post add new admin
func (c *AdminController) Post() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil {
......@@ -185,8 +185,8 @@ func (c *AdminController) Post() {
// Delete remove admin
func (c *AdminController) Delete() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
......@@ -235,8 +235,8 @@ func (c *AdminController) UpdatePassword() {
c.JSON(configs.ResponseFail, "参数有误,请检查!", err.Error())
}
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// oldAdmin
oldAdmin := c.AdminRepository.GetAdmin(auth.UID)
......@@ -299,8 +299,8 @@ func (c *AdminController) UpdatePassword() {
// ChangeCurrentUser current connect user
func (c *AdminController) ChangeCurrentUser() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// admin
admin := c.AdminRepository.GetAdmin(auth.UID)
......@@ -328,8 +328,8 @@ func (c *AdminController) Online() {
online = 0
}
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil {
......
......@@ -95,7 +95,7 @@ func (c *AuthController) Login() {
// create token
newToken := utils.GenerateToken(models.JwtKeyDto{ID: queryAdmin.ID, UserName: queryAdmin.UserName, AuthType: authType.ID})
auth := c.AuthsRepository.GetAuthInfoWithTypeAndUID(request.AuthType, queryAdmin.ID)
auth := c.AuthsRepository.GetAdminAuthInfoWithTypeAndUID(request.AuthType, queryAdmin.ID)
if auth == nil {
newAuth := models.Auths{
......@@ -129,8 +129,8 @@ func (c *AuthController) Login() {
// Logout admin logout
func (c *AuthController) Logout() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if count := c.AuthsRepository.GetAdminOnlineCount(auth.UID); count <= 1 {
......
......@@ -13,7 +13,8 @@ import (
type BaseControllerInterface interface {
JSON()
Prepare()
GetAuthInfo() *models.Auths
GetAdminAuthInfo() *models.Auths
GetUserInfo() *models.User
}
// BaseController Base class
......@@ -40,14 +41,25 @@ func (c *BaseController) JSON(status configs.ResponseStatusType, message string,
c.StopRun()
}
// GetAuthInfo get current anth user that AuthInfo
func (c *BaseController) GetAuthInfo() *models.Auths {
// GetAdminAuthInfo get current anth admin that AuthInfo
func (c *BaseController) GetAdminAuthInfo() *models.Auths {
token := c.Ctx.Input.Header("Authorization")
var authsRepository = services.GetAuthsRepositoryInstance()
auth := authsRepository.GetAuthInfo(token)
auth := authsRepository.GetAdminAuthInfo(token)
if auth == nil {
logs.Warn("GetAuthInfo fun error------------登录已失效!")
logs.Warn("GetAdminAuthInfo fun error------------登录已失效!")
c.JSON(configs.ResponseFail, "登录已失效!", nil)
}
return auth
}
// GetUserInfo get current user info
func (c *BaseController) GetUserInfo() *models.User {
token := c.Ctx.Input.Header("Token")
var userRepository = services.GetUserRepositoryInstance()
user := userRepository.GetUserWithToken(token)
if user == nil {
logs.Warn("GetAdminAuthInfo fun error------------登录已失效!")
}
return user
}
......@@ -37,8 +37,8 @@ func (c *ContactController) Finish() {}
// GetContacts get all Contacts
func (c *ContactController) GetContacts() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
contactDto, err := c.ContactRepository.GetContacts(auth.UID)
......@@ -57,8 +57,8 @@ func (c *ContactController) Delete() {
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// delete
rows, err := c.ContactRepository.Delete(id, auth.UID)
......@@ -73,8 +73,8 @@ func (c *ContactController) Delete() {
// DeleteAll all
func (c *ContactController) DeleteAll() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// delete
rows, err := c.ContactRepository.DeleteAll(auth.UID)
......@@ -88,8 +88,8 @@ func (c *ContactController) DeleteAll() {
// Transfer transfer admin to admin
func (c *ContactController) Transfer() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
adminRepository := services.GetAdminRepositoryInstance()
admin := adminRepository.GetAdmin(auth.UID)
......
......@@ -36,8 +36,8 @@ func (c *MessageController) List() {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
messagePaginationDto.Service = auth.UID
// Timestamp == 0
......
......@@ -44,8 +44,8 @@ func (c *PlatformController) Get() {
// Put update admin
func (c *PlatformController) Put() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
// is admin root ?
......@@ -99,8 +99,8 @@ func (c *PlatformController) Put() {
// Post add new platform
func (c *PlatformController) Post() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin.Root != 1 {
......@@ -149,8 +149,8 @@ func (c *PlatformController) Post() {
// Delete delete remove admin
func (c *PlatformController) Delete() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin.Root != 1 {
......
package controllers
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
"kefu_server/configs"
"kefu_server/models"
......@@ -95,21 +97,34 @@ func (c *PublicController) Register() {
}
// Addr for this request IP
currentRemoteAddr := c.Ctx.Input.IP()
/// old user
if user != nil {
// The last login address is inconsistent with this time and the token is not empty
if user.Token != "" && user.RemoteAddr != "" && currentRemoteAddr != user.RemoteAddr {
c.JSON(configs.ResponseFail, "注册失败,请稍等重试!", "")
}
// fetchResult
fetchResult, fetchError = utils.CreateMiMcToken(strconv.FormatInt(user.ID, 10))
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", err.Error())
}
// MD5 user token
m5 := md5.New()
m5.Write([]byte(imTokenDto.Data.Token))
_md5Token := hex.EncodeToString(m5.Sum(nil))
// update userinfo
c.UserRepository.Update(user.ID, orm.Params{
"Online": 1,
"Address": sessionRequestDto.Address,
"Platform": sessionRequestDto.Platform,
"LastActivity": time.Now().Unix(),
"Token": imTokenDto.Data.Token,
"Token": _md5Token,
})
user.Token = imTokenDto.Data.Token
......@@ -120,6 +135,7 @@ func (c *PublicController) Register() {
user.CreateAt = time.Now().Unix()
user.ID = 0
user.Online = 1
user.RemoteAddr = currentRemoteAddr
user.LastActivity = time.Now().Unix()
user.Address = sessionRequestDto.Address
......@@ -129,10 +145,14 @@ func (c *PublicController) Register() {
if err := json.Unmarshal([]byte(fetchResult), &imTokenDto); err != nil {
c.JSON(configs.ResponseFail, "注册失败!", err.Error())
}
// MD5 user token
m5 := md5.New()
m5.Write([]byte(imTokenDto.Data.Token))
_md5Token := hex.EncodeToString(m5.Sum(nil))
// update userinfo
c.UserRepository.Update(user.ID, orm.Params{
"Token": imTokenDto.Data.Token,
"Token": _md5Token,
"NickName": "访客" + strconv.FormatInt(accountID, 10),
})
......@@ -143,8 +163,8 @@ func (c *PublicController) Register() {
} else {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin = c.AdminRepository.GetAdmin(auth.UID)
// fetchResult
......@@ -180,6 +200,12 @@ func (c *PublicController) Register() {
// Read get user read count
func (c *PublicController) Read() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "查询成功!", "")
}
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
readCount, err := c.MessageRepository.GetReadCount(id)
if err == nil {
......@@ -192,6 +218,12 @@ func (c *PublicController) Read() {
// Window set user window
func (c *PublicController) Window() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "更新成功!", "")
}
type WindowType struct {
Window int `json:"window"`
}
......@@ -200,16 +232,8 @@ func (c *PublicController) Window() {
c.JSON(configs.ResponseFail, "更新失败!", nil)
}
// get user info
uid, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
user := c.UserRepository.GetUser(uid)
if user == nil {
c.JSON(configs.ResponseFail, "更新失败,用户不存在!", nil)
}
// update
_, err := c.UserRepository.Update(uid, orm.Params{
_, err := c.UserRepository.Update(user.UID, orm.Params{
"IsWindow": wType.Window,
})
if err != nil {
......@@ -221,15 +245,15 @@ func (c *PublicController) Window() {
// CleanRead clean user read
func (c *PublicController) CleanRead() {
uid, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
// Can't just clear customer service
if admin := c.AdminRepository.GetAdmin(uid); admin != nil {
c.JSON(configs.ResponseFail, "清除成功!", nil)
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "清除成功!", "")
}
// clear
if _, err := c.MessageRepository.ClearRead(uid); err != nil {
if _, err := c.MessageRepository.ClearRead(user.UID); err != nil {
c.JSON(configs.ResponseFail, "清除失败!", err.Error())
}
......@@ -313,12 +337,11 @@ func (c *PublicController) UploadSecret() {
// LastActivity change last Activity
func (c *PublicController) LastActivity() {
// uid id if exist current request is user, else admin
uid, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
// get user
user := c.GetUserInfo()
// user
if uid > 0 {
_, err := c.UserRepository.Update(uid, orm.Params{
if user != nil {
_, err := c.UserRepository.Update(user.ID, orm.Params{
"LastActivity": time.Now().Unix(),
})
if err != nil {
......@@ -327,9 +350,8 @@ func (c *PublicController) LastActivity() {
c.JSON(configs.ResponseSucess, "上报成功!", nil)
}
// admin
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
_, err := c.AdminRepository.Update(auth.UID, orm.Params{
"LastActivity": time.Now().Unix(),
})
......@@ -466,11 +488,6 @@ func (c *PublicController) GetMessageHistoryList() {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
token := c.Ctx.Input.Header("token")
if token == "" {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// validation
valid := validation.Validation{}
valid.Required(messagePaginationDto.Account, "account").Message("account不能为空!")
......@@ -489,6 +506,10 @@ func (c *PublicController) GetMessageHistoryList() {
}
/// validation TOKEN
token := c.Ctx.Input.Header("token")
if token == "" {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
if token != user.Token {
c.JSON(configs.ResponseFail, "fail,用户不存在!", nil)
}
......@@ -507,3 +528,44 @@ func (c *PublicController) GetMessageHistoryList() {
c.JSON(configs.ResponseSucess, "success", &returnMessagePaginationDto)
}
// CreateWorkOrder send word order
func (c *PublicController) CreateWorkOrder() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseFail, "工单创建失败!", "")
}
workOrder := models.WorkOrder{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &workOrder); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// validation
valid := validation.Validation{}
valid.Required(workOrder.TID, "tid").Message("tid不能为空!")
valid.Required(workOrder.UID, "uid").Message("account不能为空!")
valid.Required(workOrder.Phone, "phone").Message("page_size不能为空!")
valid.Email(workOrder.Email, "email").Message("email格式不正确!")
valid.Required(workOrder.Content, "content").Message("content不能为空!")
if valid.HasErrors() {
for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, nil)
}
}
workOrder.CreateAt = time.Now().Unix()
workOrderRepository := services.GetWorkOrderRepositoryInstance()
wid, err := workOrderRepository.Add(workOrder)
if err != nil {
c.JSON(configs.ResponseFail, "fail", err.Error())
}
c.JSON(configs.ResponseSucess, "工单创建成功!", wid)
}
// ReplyWorkOrder send word order
func (c *PublicController) ReplyWorkOrder() {
}
......@@ -35,8 +35,8 @@ func (c *QiniuController) Finish() {}
// Get get qiniu config info
func (c *QiniuController) Get() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限获取配置!", nil)
......@@ -60,8 +60,8 @@ func (c *QiniuController) Put() {
c.JSON(configs.ResponseFail, "fail", nil)
}
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限获取配置!", nil)
......
......@@ -55,8 +55,8 @@ func (c *RobotController) Get() {
// Delete delete robot
func (c *RobotController) Delete() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限删除机器人!", nil)
......@@ -86,8 +86,8 @@ func (c *RobotController) Delete() {
// Post add robot
func (c *RobotController) Post() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限添加机器人!", nil)
......@@ -138,8 +138,8 @@ func (c *RobotController) Post() {
// Put update robot
func (c *RobotController) Put() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := c.AdminRepository.GetAdmin(auth.UID)
if admin == nil || admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限修改机器人!", nil)
......
......@@ -31,8 +31,8 @@ func (c *ShortcutController) Finish() {}
// Get get shortcut
func (c *ShortcutController) Get() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
shortcut := c.ShortcutRepository.GetShortcut(id)
if shortcut == nil || auth.UID != shortcut.UID {
......@@ -45,8 +45,8 @@ func (c *ShortcutController) Get() {
// Put update shortcut
func (c *ShortcutController) Put() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// request body
shortcut := models.Shortcut{}
......@@ -84,8 +84,8 @@ func (c *ShortcutController) Put() {
// Post add new shortcut
func (c *ShortcutController) Post() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// request body
var shortcut models.Shortcut
......@@ -118,8 +118,8 @@ func (c *ShortcutController) Post() {
// Delete delete remove shortcut
func (c *ShortcutController) Delete() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
if row, err := c.ShortcutRepository.Delete(id, auth.UID); err != nil || row == 0 {
c.JSON(configs.ResponseFail, "删除失败!", err.Error())
......@@ -130,8 +130,8 @@ func (c *ShortcutController) Delete() {
// List get shortcut all
func (c *ShortcutController) List() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
// query
shortcuts := c.ShortcutRepository.GetShortcuts(auth.UID)
......
......@@ -47,8 +47,8 @@ func (c *SystemController) Put() {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
// is root ?
if admin.Root != 1 {
......
......@@ -91,8 +91,8 @@ func (c *UserController) Delete() {
// uid
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin.Root != 1 {
c.JSON(configs.ResponseFail, "您没有权限删除用户!", nil)
......
......@@ -38,8 +38,8 @@ func (c *WorkOrderController) Finish() {}
// PostWorkType add work order type
func (c *WorkOrderController) PostWorkType() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin != nil && admin.Root != 1 {
c.JSON(configs.ResponseFail, "没有权限!", nil)
......@@ -71,8 +71,8 @@ func (c *WorkOrderController) PostWorkType() {
// UpdateWorkType update work order type
func (c *WorkOrderController) UpdateWorkType() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin != nil && admin.Root != 1 {
c.JSON(configs.ResponseFail, "没有权限!", nil)
......@@ -101,8 +101,8 @@ func (c *WorkOrderController) UpdateWorkType() {
// DeleteWorkType delete work order type
func (c *WorkOrderController) DeleteWorkType() {
// GetAuthInfo
auth := c.GetAuthInfo()
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
admin := services.GetAdminRepositoryInstance().GetAdmin(auth.UID)
if admin != nil && admin.Root != 1 {
c.JSON(configs.ResponseFail, "没有权限!", nil)
......
......@@ -4,14 +4,15 @@ package models
type User struct {
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // 用户ID
UID int64 `orm:"type(bigint);column(uid)" json:"uid"` // 对应业务平台的用户ID(保留字段)
UserToken string `orm:"type(text);null;column(user_token)" json:"user_token"` // 对应业务平台的用户的user_token(保留字段)
Avatar string `orm:"type(char);null;column(avatar)" json:"avatar"` // 用户头像
Address string `orm:"type(char);null;column(address)" json:"address"` // 用户所在地
NickName string `orm:"type(char);null;column(nickname)" json:"nickname"` // 用户昵称
Token string `orm:"type(text);null;column(token)" json:"token"` // im token
UserToken string `orm:"type(text);null;column(user_token)" json:"user_token"` // 对应业务平台的用户的user_token(保留字段)
Phone string `orm:"type(char);null;column(phone)" json:"phone"` // 用户联系电话
Platform int64 `orm:"type(bigint);column(platform)" json:"platform"` // 用户所在渠道(平台)
Online int `orm:"default(0);column(online)" json:"online"` // 用户是否在线
RemoteAddr string `orm:"type(char);null;column(remote_addr)" json:"remote_addr"` // 用户当次登录地址
IsWindow int `orm:"default(0);column(is_window)" json:"is_window"` // 是否在聊天窗口
UpdateAt int64 `orm:"type(bigint);column(update_at)" json:"update_at"` // 用户资料被更新时间
Remarks string `orm:"type(char);null;column(remarks)" json:"remarks"` // 备注
......
......@@ -2,15 +2,16 @@ package models
// WorkOrder model
type WorkOrder struct {
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID
UID int64 `orm:"type(bigint);column(uid)" json:"uid"` // 用户ID
AID int64 `orm:"type(bigint);column(aid))" json:"aid"` // 客服ID
TID int64 `orm:"type(bigint);column(tid))" json:"tid"` // 工单类型ID
Phone string `orm:"type(char);null;column(phone)" json:"phone"` // 用户联系电话
Email string `orm:"type(varchar);null;column(email)" json:"email"` // 邮箱(可用于客服回复后发提醒邮件给客户)
Status int `orm:"default(0);column(status)" json:"status"` // 当前状态 ( 0=待处理 | 1=客服已回复 | 2=客户已回复 | 3=已结单 )
CID int64 `orm:"type(bigint);column(cid))" json:"cid"` // 结单客服ID
CloseAt int64 `orm:"type(bigint);column(close_at)" json:"close_at"` // 结单时间
Comment int64 `orm:"type(bigint);column(comment)" json:"comment"` // 结单原因
CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID
UID int64 `orm:"type(bigint);column(uid)" json:"uid"` // 用户ID
TID int64 `orm:"type(bigint);column(tid))" json:"tid"` // 工单类型ID
Phone string `orm:"type(char);null;column(phone)" json:"phone"` // 用户联系电话
Email string `orm:"type(varchar);null;column(email)" json:"email"` // 邮箱(可用于客服回复后发提醒邮件给客户)
Status int `orm:"default(0);column(status)" json:"status"` // 当前状态 ( 0=待处理 | 1=客服已回复 | 2=客户已回复 | 3=已结单 )
LastReply int64 `orm:"type(bigint);column(last_reply))" json:"last_reply"` // 最后回复的客服ID
CID int64 `orm:"type(bigint);column(cid))" json:"cid"` // 结单客服ID
CloseAt int64 `orm:"type(bigint);column(close_at)" json:"close_at"` // 结单时间
Comment string `orm:"type(text);column(comment)" json:"comment"` // 结单原因
Content string // 内容(不实际存储)
CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间
}
......@@ -3,6 +3,7 @@ package models
// WorkOrderComment model
type WorkOrderComment struct {
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID
AID int64 `orm:"type(bigint);column(aid))" json:"aid"` // 客服ID
WID int64 `orm:"type(bigint);column(wid)" json:"wid"` // 关联(WorkOrder ID)
Content string `orm:"type(text);null;column(content)" json:"content"` // 内容
CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间
......
......@@ -37,17 +37,19 @@ func init() {
beego.NSNamespace("/public",
beego.NSRouter("/register", &controllers.PublicController{}, "post:Register"),
beego.NSRouter("/robot/:platform", &controllers.PublicController{}, "get:Robot"),
beego.NSRouter("/read/:id", &controllers.PublicController{}, "get:Read"),
beego.NSRouter("/read", &controllers.PublicController{}, "get:Read"),
beego.NSRouter("/secret", &controllers.PublicController{}, "get:UploadSecret"),
beego.NSRouter("/activity/?:id", &controllers.PublicController{}, "get:LastActivity"),
beego.NSRouter("/company", &controllers.PublicController{}, "get:GetCompanyInfo"),
beego.NSRouter("/robot_info/:id", &controllers.PublicController{}, "get:RobotInfo"),
beego.NSRouter("/clean_read/:id", &controllers.PublicController{}, "get:CleanRead"),
beego.NSRouter("/window/:id", &controllers.PublicController{}, "put:Window"),
beego.NSRouter("/clean_read", &controllers.PublicController{}, "get:CleanRead"),
beego.NSRouter("/window", &controllers.PublicController{}, "put:Window"),
beego.NSRouter("/upload", &controllers.PublicController{}, "post:Upload"),
beego.NSRouter("/messages", &controllers.PublicController{}, "post:GetMessageHistoryList"),
beego.NSRouter("/message/push", &controllers.PublicController{}, "post:PushMessage"),
beego.NSRouter("/message/cancel", &controllers.PublicController{}, "post:CancelMessage"),
beego.NSRouter("/workorder/create", &controllers.PublicController{}, "post:CreateWorkOrder"),
beego.NSRouter("/workorder/reply", &controllers.PublicController{}, "post:ReplyWorkOrder"),
),
// knowledge_base
......
......@@ -9,8 +9,8 @@ import (
// AuthsRepositoryInterface interface
type AuthsRepositoryInterface interface {
GetAuthInfo(token string) *models.Auths
GetAuthInfoWithTypeAndUID(authType int64, uid int64) *models.Auths
GetAdminAuthInfo(token string) *models.Auths
GetAdminAuthInfoWithTypeAndUID(authType int64, uid int64) *models.Auths
GetAdminOnlineCount(uid int64) int64
Delete(id int64) (int64, error)
Add(id *models.Auths) (int64, error)
......@@ -29,21 +29,21 @@ func GetAuthsRepositoryInstance() *AuthsRepository {
return instance
}
// GetAuthInfo get a auth info
func (r *AuthsRepository) GetAuthInfo(token string) *models.Auths {
// GetAdminAuthInfo get a auth info
func (r *AuthsRepository) GetAdminAuthInfo(token string) *models.Auths {
var auth models.Auths
if err := r.q.Filter("token", token).One(&auth); err != nil {
logs.Warn("GetAuthInfo get a auth info------------", err)
logs.Warn("GetAdminAuthInfo get a auth info------------", err)
return nil
}
return &auth
}
// GetAuthInfoWithTypeAndUID get a auth info with type and uid
func (r *AuthsRepository) GetAuthInfoWithTypeAndUID(authType int64, uid int64) *models.Auths {
// GetAdminAuthInfoWithTypeAndUID get a auth info with type and uid
func (r *AuthsRepository) GetAdminAuthInfoWithTypeAndUID(authType int64, uid int64) *models.Auths {
var auth models.Auths
if err := r.q.Filter("auth_type", authType).Filter("uid", uid).One(&auth); err != nil {
logs.Warn("GetAuthInfoWithTypeAndUID get a auth info with type and uid------------", err)
logs.Warn("GetAdminAuthInfoWithTypeAndUID get a auth info with type and uid------------", err)
return nil
}
return &auth
......
......@@ -14,6 +14,7 @@ type UserRepositoryInterface interface {
GetUser(id int64) *models.User
GetUsers(usersPaginationDto *models.UsersPaginationDto) (*models.UsersPaginationDto, error)
GetUserWithUID(uid int64) *models.User
GetUserWithToken(token string) *models.User
Update(id int64, params *orm.Params) (int64, error)
Delete(id int64) (int64, error)
GetOnlineCount() (int64, error)
......@@ -35,8 +36,10 @@ func GetUserRepositoryInstance() *UserRepository {
// CheckUsersLoginTimeOutAndSetOffline Check if user login timeout
func (r *UserRepository) CheckUsersLoginTimeOutAndSetOffline(lastMessageUnixTimer int64) int64 {
count, err := r.q.Filter("online__in", 1, 2).Filter("last_activity__lte", lastMessageUnixTimer).Update(orm.Params{
"online": 0,
"is_window": 0,
"online": 0,
"remote_addr": "",
"token": "",
"is_window": 0,
})
if err != nil {
logs.Warn("CheckUsersLoginTimeOutAndSetOffline Check if user login timeout------------", err)
......@@ -122,6 +125,16 @@ func (r *UserRepository) GetUserWithUID(uid int64) *models.User {
return &user
}
// GetUserWithToken get one User with uid
func (r *UserRepository) GetUserWithToken(token string) *models.User {
var user models.User
if err := r.q.Filter("token", token).One(&user); err != nil {
logs.Warn("GetUserWithToken get one User with uid------------", err)
return nil
}
return &user
}
// Update user
func (r *UserRepository) Update(id int64, params orm.Params) (int64, error) {
index, err := r.q.Filter("id", id).Update(params)
......
......@@ -10,6 +10,7 @@ import (
type WorkOrderCommentRepositoryInterface interface {
GetWorkOrder() *models.WorkOrderComment
DeleteAll(wid int64) (int64, error)
Add(workOrderComment models.WorkOrderComment) (int64, error)
}
// WorkOrderCommentRepository struct
......@@ -24,8 +25,17 @@ func GetWorkOrderCommentRepositoryInstance() *WorkOrderCommentRepository {
return instance
}
// Add add WorkOrderComment
func (r *WorkOrderCommentRepository) Add(workOrderComment models.WorkOrderComment) (int64, error) {
index, err := r.o.Insert(workOrderComment)
if err != nil {
logs.Warn(" Add add WorkOrderComment------------", err)
}
return index, err
}
// DeleteAll delete all WorkOrderComment
func (r *WorkOrderRepository) DeleteAll(wid int64) (int64, error) {
func (r *WorkOrderCommentRepository) DeleteAll(wid int64) (int64, error) {
index, err := r.q.Filter("wid", wid).Delete()
if err != nil {
logs.Warn(" DeleteAll delete all WorkOrderComment------------", err)
......
......@@ -2,6 +2,7 @@ package services
import (
"kefu_server/models"
"time"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
......@@ -18,14 +19,14 @@ type WorkOrderRepositoryInterface interface {
// WorkOrderRepository struct
type WorkOrderRepository struct {
BaseRepository
CommentRepository *WorkOrderCommentRepository
WorkOrderCommentRepository *WorkOrderCommentRepository
}
// GetWorkOrderRepositoryInstance get instance
func GetWorkOrderRepositoryInstance() *WorkOrderRepository {
instance := new(WorkOrderRepository)
instance.Init(new(models.WorkOrder))
instance.CommentRepository = GetWorkOrderCommentRepositoryInstance()
instance.WorkOrderCommentRepository = GetWorkOrderCommentRepositoryInstance()
return instance
}
......@@ -36,18 +37,30 @@ func (r *WorkOrderRepository) Delete(id int64) (int64, error) {
logs.Warn("Delete delete WorkOrder------------", err)
}
if index > 0 {
GetWorkOrderCommentRepositoryInstance()
_, err := r.WorkOrderCommentRepository.DeleteAll(id)
if err != nil {
logs.Warn("Delete delete WorkOrder child------------", err)
}
}
return index, err
}
// Add add WorkOrder
func (r *WorkOrderRepository) Add(workOrder models.WorkOrder) (int64, error) {
index, err := r.o.Insert(workOrder)
createAt := time.Now().Unix()
workOrder.CreateAt = createAt
wid, err := r.o.Insert(workOrder)
if err != nil {
logs.Warn("Add add WorkOrder------------", err)
}
return index, err
if wid > 0 {
r.WorkOrderCommentRepository.Add(models.WorkOrderComment{
WID: wid,
Content: workOrder.Content,
CreateAt: createAt,
})
}
return wid, err
}
// Update WorkOrder Info
......
......@@ -4337,6 +4337,11 @@
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
},
"blueimp-md5": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.12.0.tgz",
"integrity": "sha512-zo+HIdIhzojv6F1siQPqPFROyVy7C50KzHv/k/Iz+BtvtVzSHXiMXOpq2wCfNkeBqdCv+V8XOV96tsEt2W/3rQ=="
},
"bn.js": {
"version": "4.11.8",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
......
......@@ -10,6 +10,7 @@
"dependencies": {
"axios": "^0.19.0",
"better-scroll": "^1.15.2",
"blueimp-md5": "^2.12.0",
"core-js": "^2.6.5",
"mint-ui": "^2.2.13",
"moment": "^2.24.0",
......
import axios from "axios";
import { Toast } from 'mint-ui';
var md5 = require('blueimp-md5')
var MimcPlugin = {};
MimcPlugin.install = function (Vue, options) {
......@@ -35,6 +36,7 @@ MimcPlugin.install = function (Vue, options) {
.then(response => {
this.fetchMIMCTokenResult = response.data.data.token
localStorage.setItem("miniImAppUser_" + response.data.data.user.id, JSON.stringify(response.data.data.user))
localStorage.setItem("Token", md5(response.data.data.user.token))
console.log("MIMC初始化成功")
if(callback) callback(response.data.data.user)
})
......
......@@ -349,7 +349,7 @@ export default {
},
beforeDestroy(){
this.toggleWindow(this.userAccount, 0)
this.toggleWindow(0)
},
methods: {
// run
......@@ -423,7 +423,7 @@ export default {
// 清除未读消息
this.cleanRead(user.id)
// 更换toggle
this.toggleWindow(user.id, 1)
this.toggleWindow(1)
// 登录完成发送一条握手消息给机器人
IM.login(() => {
setTimeout(()=> {
......@@ -475,8 +475,8 @@ export default {
axios.get('/public/clean_read/' + id)
},
// 用户是否在当前聊天页面
toggleWindow(id, window){
axios.put('/public/window/' + id,{window: window})
toggleWindow(window){
axios.put('/public/window/',{window: window})
},
// query 转json
queryToJson(str){
......@@ -885,16 +885,11 @@ export default {
getMessageRecord(){
const pageSize = 20
let uid = this.userInfo.id
let token = this.userInfo.token
let timestamp = this.messages.length == 0 ? parseInt((new Date().getTime() + " ").substr(0, 10)) : this.messages[0].timestamp
axios.post('/public/messages',{
"timestamp": timestamp,
"page_size": pageSize,
"account": uid
},{
"headers": {
'token': token
}
})
.then(response => {
let messages = response.data.data.list || []
......
......@@ -14,6 +14,19 @@ import axios from 'axios'
axios.defaults.baseURL = '/v1'
// axios添加请求拦截器
axios.interceptors.request.use(function (config) {
const token = localStorage.getItem('Token') || ""
config.headers = Object.assign({}, {
'Token': token,
}, config.headers)
return config;
}, function (error) {
// eslint-disable-next-line no-console
console.log(error)
return Promise.reject(error);
});
var options={
clickToCloseNonZoomable: false,
fullscreenEl:false, //关闭全屏按钮
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment