This commit is contained in:
yan.y 2024-04-28 14:59:29 +08:00
parent e5090dbc31
commit 889a56b046
4 changed files with 73 additions and 2 deletions

View File

@ -30,7 +30,7 @@ type LoginResponse struct {
}
var defaultNickName = "微信用户"
var defaultHeadImgUrl = "http://" + web.CONFIG.System.Addr + "/static/img/20240327152925.jpg"
var defaultHeadImgUrl = web.CONFIG.System.Domain + "/static/img/20240327152925.jpg"
// 登录
func (p DefParty) login() web_iris.Party {
@ -100,6 +100,50 @@ func (p DefParty) login() web_iris.Party {
}
}
type UpdateUserInfoRequest struct {
NickName string `json:"nickName"`
HeadImgUrl string `json:"headImgUrl"`
}
// 更新用户信息
func (p DefParty) updateUserInfo() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(AuthBase+"/updateUserInfo", func(ctx *context.Context) {
headerInfo := GetHeaderBaseInfo(ctx)
var updateUserInfoRequest UpdateUserInfoRequest
body, _ := io.ReadAll(ctx.Request().Body)
json.Unmarshal(body, &updateUserInfoRequest)
var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerInfo.Uid).Find(&userInfo)
if userInfo == nil || userInfo.Id == 0 {
UserNotExistError.Fail(ctx, nil)
return
}
if len(updateUserInfoRequest.NickName) > 0 {
userInfo.NickName = updateUserInfoRequest.NickName
}
if len(updateUserInfoRequest.HeadImgUrl) > 0 {
userInfo.HeadImgUrl = updateUserInfoRequest.HeadImgUrl
}
updateValues := map[string]interface{}{
"NickName": userInfo.NickName,
"HeadImgUrl": userInfo.HeadImgUrl,
}
database.Instance().Model(&userInfo).Updates(&updateValues)
getUserInfoResponse := GetUserInfoResponse{
Uid: userInfo.Id,
NickName: userInfo.NickName,
HeadImgUrl: userInfo.HeadImgUrl,
Amount: userInfo.Amount,
Role: userInfo.Role,
UserPets: GetUserPets(userInfo.Id),
}
Success(ctx, headerInfo, getUserInfoResponse)
})
}}
}
type GetUserInfoResponse struct {
Uid int64 `json:"uid"`
NickName string `json:"nickName"`

View File

@ -13,10 +13,12 @@ var System = "/system"
func (p DefParty) RegisterList() []web_iris.Party {
ps := []web_iris.Party{
p.index(),
//用户
p.login(),
p.getUserInfo(),
p.userUploadFile(),
p.updateUserInfo(),
//商品
p.goodsList(),
p.goodsDetail(),

View File

@ -10,6 +10,23 @@ import (
"pet-house.com/core/server/web/web_iris"
)
var CatWeightMap = map[int]string{
1: "0-1.5kg",
2: "1.5-3kg",
3: "3-5kg",
4: "5-8kg",
5: "8kg以上",
}
var DogWeightMap = map[int]string{
1: "0-3kg",
2: "3-6kg",
3: "6-9kg",
4: "9-13kg",
5: "13-18kg",
6: "18-22kg",
7: "22-30kg",
}
type UserPetInfo struct {
PetInfo models.Pet `json:"petInfo"`
PetBaseInfo models.PetBaseInfo `json:"petBaseInfo"`
@ -77,6 +94,7 @@ type PetAddOrEditRequest struct {
HeadImgType int //头像类型 0远程头像 1本地头像
HeadImgUrl string //宠物头像
Desc string //宠物描述
Weight int //宠物体重
Precaution string //注意事项
Gender int //性别 0男 1女
Birthday string //生日
@ -106,6 +124,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
HeadImgType: petAddOrEditRequest.HeadImgType,
HeadImgUrl: petAddOrEditRequest.HeadImgUrl,
Desc: petAddOrEditRequest.Desc,
Weight: petAddOrEditRequest.Weight,
Precaution: petAddOrEditRequest.Precaution,
Gender: petAddOrEditRequest.Gender,
Birthday: petAddOrEditRequest.Birthday,
@ -127,6 +146,7 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
"HeadImgType": pet.HeadImgType,
"HeadImgUrl": pet.HeadImgUrl,
"Desc": pet.Desc,
"Weight": pet.Weight,
"Precaution": pet.Precaution,
"Gender": pet.Gender,
"Birthday": pet.Birthday,
@ -143,6 +163,8 @@ func (p DefParty) petAddOrEdit() web_iris.Party {
type PetTypeListResponse struct {
PetBaseInfoList []models.PetBaseInfo `json:"petBaseInfoList"`
CatWeights map[int]string `json:"catWeights"`
DogWeights map[int]string `json:"dogWeights"`
}
// 宠物基础信息列表
@ -153,7 +175,8 @@ func (p DefParty) petTypeList() web_iris.Party {
for _, petBaseInfo := range PetBaseInfoMap {
petBaseInfoList = append(petBaseInfoList, petBaseInfo)
}
Success(ctx, nil, PetTypeListResponse{petBaseInfoList})
Success(ctx, nil, PetTypeListResponse{petBaseInfoList, CatWeightMap, DogWeightMap})
})
}}
}

View File

@ -28,6 +28,7 @@ type Pet struct {
HeadImgType int `json:"headImgType"` //用户头像类型 0远程头像 1本地头像
HeadImgUrl string `json:"headImgUrl"` //宠物头像
Desc string `json:"desc"` //宠物描述
Weight int `json:"weight"` //宠物体重
Precaution string `json:"precaution"` //注意事项
Gender int `json:"gender"` //性别 0男 1女
Birthday string `json:"birthday"` //生日
@ -90,6 +91,7 @@ type PetGoods struct {
Assortment int `gorm:"not null" json:"assortment"` //品种Id 优先用品种查询 如不存在 则用类型及大小查询
PetType int `gorm:"not null" json:"petType"` //类型 1猫 2狗
Size int `gorm:"not null" json:"size"` //大小 1大 2中 3小
Weight int `gorm:"not null" json:"weight"` //体重
GoodsId int64 `gorm:"not null" json:"goodsId"` //商品ID
Sort int `gorm:"not null" json:"sort"` //排序
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间