Commit cd528437 by chenxianqi

update

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