You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.6 KiB
82 lines
1.6 KiB
|
2 months ago
|
// 账号相关的接口实现
|
||
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/customer/app"
|
||
|
|
"server/modules/customer/bdb"
|
||
|
|
"server/modules/customer/values"
|
||
|
|
"server/util"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Login(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.LoginReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
one := &values.User{Account: req.Account, Password: req.Pass}
|
||
|
|
if err := bdb.BackDB.Get(one); err != nil {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "账号不存在"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
token := util.GetSimpleRandomString(6)
|
||
|
|
err := db.Redis().SetJsonData(common.GetBackendTokenKey(token), one, values.RedisTokenEx)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
a.Data = values.LoginResp{Role: one.Role, Token: token, Power: one.Power, Id: int(one.ID)}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 操作 1上线 2下线
|
||
|
|
type OnlineReq struct {
|
||
|
|
Opt int
|
||
|
|
}
|
||
|
|
|
||
|
|
func Online(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
// if a.User.Role != values.UserRole2 {
|
||
|
|
// return
|
||
|
|
// }
|
||
|
|
req := new(OnlineReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
str := "上线"
|
||
|
|
opt := 1
|
||
|
|
if req.Opt == 2 {
|
||
|
|
str = "下线"
|
||
|
|
opt = 0
|
||
|
|
}
|
||
|
|
bdb.BackDB.Update(&values.User{ID: a.User.ID}, map[string]interface{}{"online": opt})
|
||
|
|
a.RecordEdit(values.PowerGM, fmt.Sprintf("客服%s", str))
|
||
|
|
}
|
||
|
|
|
||
|
|
type OnlineResp struct {
|
||
|
|
Status int
|
||
|
|
}
|
||
|
|
|
||
|
|
func OnlineStatus(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
user := &values.User{ID: a.User.ID}
|
||
|
|
bdb.BackDB.Get(user)
|
||
|
|
resp := OnlineResp{Status: user.Online}
|
||
|
|
a.Data = resp
|
||
|
|
}
|