YouChuKoffee/app/services/UserService.go

44 lines
1.2 KiB
Go

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"
"strconv"
"time"
)
func YouChuLogin(req *front.UnionLoginRequest) (code int, login front.LoginResponse) {
client := youchu.NewYouChuClient(config.GetConf().YouChu)
Code, YouChuResponse := client.Login(req.Code)
if Code != errorcode.Success {
return errorcode.NotFound, login
}
if YouChuResponse.RespCode == "000000" {
// 获取用户信息
var user usersmodel.Users
err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Where("custNo = ?", YouChuResponse.CustNo).Find(&user)
code = handErr(err)
if user.Id == "" {
user.CustNo = YouChuResponse.CustNo
user.Status = strconv.Itoa(common.STATUSABLED)
user.CreateTime = time.Now()
_, err := usersmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).Insert(&user)
if err != nil {
return errorcode.InsertUserFail, front.LoginResponse{}
}
}
login.Token = utils.GeneratorJwtToken(utils.User{
Id: user.Id,
Phone: user.CustNo,
})
return errorcode.Success, login
} else {
return errorcode.YouChuCodeFail, login
}
}