From 889a56b046c289d33c9ddd2a105614678d5bb3ad Mon Sep 17 00:00:00 2001 From: "yan.y" Date: Sun, 28 Apr 2024 14:59:29 +0800 Subject: [PATCH] update --- business/api/auth.go | 46 +++++++++++++++++++++++++++++++++++- business/api/control.go | 2 ++ business/api/pet.go | 25 +++++++++++++++++++- business/models/dataModel.go | 2 ++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/business/api/auth.go b/business/api/auth.go index 11ec98b..a197a99 100644 --- a/business/api/auth.go +++ b/business/api/auth.go @@ -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"` diff --git a/business/api/control.go b/business/api/control.go index 09ec82a..6bbe376 100644 --- a/business/api/control.go +++ b/business/api/control.go @@ -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(), diff --git a/business/api/pet.go b/business/api/pet.go index 006b995..527c0ca 100644 --- a/business/api/pet.go +++ b/business/api/pet.go @@ -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}) }) }} } diff --git a/business/models/dataModel.go b/business/models/dataModel.go index 8ed45e3..7365121 100644 --- a/business/models/dataModel.go +++ b/business/models/dataModel.go @@ -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:"-"` //创建时间