YouChuKoffee/app/services/UserService.go

43 lines
1.2 KiB
Go
Raw Normal View History

2024-06-19 18:32:34 +08:00
package services
import (
"qteam/app/constants/common"
"qteam/app/constants/errorcode"
"qteam/app/http/entities/front"
"qteam/app/models/usersmodel"
"qteam/app/third/youchu"
"qteam/app/utils"
"qteam/config"
2024-06-25 10:12:48 +08:00
"strconv"
"time"
2024-06-19 18:32:34 +08:00
)
func YouChuLogin(req *front.UnionLoginRequest) (code int, login front.LoginResponse) {
client := youchu.NewYouChuClient(config.GetConf().YouChu)
2024-06-24 11:44:38 +08:00
Code, YouChuResponse := client.Login(req.Code)
if Code != errorcode.Success {
2024-06-25 10:12:48 +08:00
return errorcode.NotFound, login
2024-06-19 18:32:34 +08:00
}
if YouChuResponse.RespCode == "000000" {
// 获取用户信息
2024-06-25 13:51:22 +08:00
user := usersmodel.Users{}
has, _ := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Get(&user)
if !has && YouChuResponse.CustNo != "" {
2024-06-25 10:12:48 +08:00
user.CustNo = YouChuResponse.CustNo
user.Status = strconv.Itoa(common.STATUSABLED)
user.CreateTime = time.Now()
2024-06-25 13:51:22 +08:00
_, err := usersmodel.GetInstance().GetDb().Insert(&user)
2024-06-25 10:12:48 +08:00
if err != nil {
return errorcode.InsertUserFail, front.LoginResponse{}
}
}
2024-06-19 18:32:34 +08:00
login.Token = utils.GeneratorJwtToken(utils.User{
2024-06-25 13:51:22 +08:00
Id: user.Id,
CustNo: user.CustNo,
2024-06-19 18:32:34 +08:00
})
return errorcode.Success, login
2024-06-25 10:12:48 +08:00
} else {
return errorcode.YouChuCodeFail, login
2024-06-19 18:32:34 +08:00
}
}