1 Star 2 Fork 2

brookscoder/awesome-mall-go

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
userInfo.go 1.76 KB
Copy Edit Raw Blame History
Soul authored 2021-08-18 20:05 +08:00 . Api - 登录注册接口完成(含Base64加密)
package sqlx
import (
"context"
"gitee.com/brookscoder/awesome-mall-go/common/log"
"gitee.com/brookscoder/awesome-mall-go/model"
"go.uber.org/zap"
)
//---------- CRUD Public Method ----------
/*往user_info表添加一条新的记录*/
func AddNewUser(u model.User) bool {
sqlStr := "insert into user_info(phone, password) values (?,?)"
ret, err := Db.Exec(sqlStr, u.MobilePhone, u.Password)
if err != nil {
log.Warning(context.Background(), "创建新用户数据失败", zap.Error(err))
return false
}
theID, err := ret.LastInsertId() // 新插入数据的id
if err != nil {
log.Warning(context.Background(), "获取创建新用户数据失败", zap.Error(err))
return false
}
log.Info(context.Background(), "创建新用户数据成功", zap.Any("用户信息", theID))
return true
}
func QueryUserInfo(phoneNum string) model.User {
sqlStr := "select id, first_name, last_name, age, phone, password from user_info where phone=?"
var u model.User
err := Db.Get(&u, sqlStr, phoneNum)
if err != nil {
log.Warning(context.Background(), "查询用户信息失败", zap.Error(err))
} else {
log.Info(context.Background(), "查询用户信息成功", zap.Any("用户信息", u))
}
return u
}
func AddUserInfo(phoneNum string, passwd string) bool {
sqlStr := "insert into user_info(phone, password) values (?,?)"
ret, err := Db.Exec(sqlStr, phoneNum, passwd)
if err != nil {
log.Warning(context.Background(), "新增用户信息失败", zap.Error(err))
return false
}
theID, err := ret.LastInsertId() // 新插入数据的id
if err != nil {
log.Warning(context.Background(), "获取最后插入用户信息失败", zap.Error(err))
return false
}
log.Info(context.Background(), "新增用户信息成功", zap.Any("用户信息", theID))
return true
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/brookscoder/awesome-mall-go.git
git@gitee.com:brookscoder/awesome-mall-go.git
brookscoder
awesome-mall-go
awesome-mall-go
9a786c4eb39b

Search