From 01aa915c3003da8194dd9ebc323e8f5c46efeb79 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Fri, 18 Oct 2024 15:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AE=8C=E5=96=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E6=90=9C=E7=B4=A2=EF=BC=8C=E7=AE=97=E4=B8=80=E7=AE=97?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Question.go | 22 ++++++++++++++-------- api/dao/User.go | 28 +++++++++++++++++++--------- api/requests/User.go | 2 +- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/api/controller/Question.go b/api/controller/Question.go index 3d559de..781689e 100644 --- a/api/controller/Question.go +++ b/api/controller/Question.go @@ -10,6 +10,7 @@ import ( "hepa-calc-admin-api/api/service" "hepa-calc-admin-api/global" "hepa-calc-admin-api/utils" + "math" "strconv" "time" ) @@ -569,7 +570,7 @@ func (b *Question) GetQuestionPrice(c *gin.Context) { for _, question := range questions { // 总价 - price = price + question.Price + price = price + math.Round(question.Price*100)/100 // 处理折扣价格 if question.DiscountPrice != nil { @@ -580,19 +581,24 @@ func (b *Question) GetQuestionPrice(c *gin.Context) { continue } } - } - if discountPrice == nil { - discountPrice = question.DiscountPrice - } else { - d := *discountPrice + *question.DiscountPrice - discountPrice = &d + d := math.Round(*question.DiscountPrice * 100) + + if discountPrice == nil { + discountPrice = &d + } else { + d = d + *discountPrice + discountPrice = &d + } } } var g dto.QuestionPriceDto g.Price = price - g.DiscountPrice = discountPrice + if discountPrice != nil { + u := *discountPrice / 100 + g.DiscountPrice = &u + } responses.OkWithData(g, c) } diff --git a/api/dao/User.go b/api/dao/User.go index ebdd44a..a69b92a 100644 --- a/api/dao/User.go +++ b/api/dao/User.go @@ -184,15 +184,25 @@ func (r *UserDao) GetUserPageSearch(req requests.GetUserPage, page, pageSize int // 信息完善状态 if req.IsInfoComplete != nil { - subQuery := global.Db.Model(&model.UserInfo{}). - Where("user_info.user_id = user.user_id"). - Where("user_info.height != '' "). - Where("user_info.weight != '' "). - Where("user_info.is_family_history is not NULL"). - Where("user_info.province_id is not NULL"). - Select("1") - - query = query.Where("EXISTS (?)", subQuery) + if *req.IsInfoComplete == true { + subQuery := global.Db.Model(&model.UserInfo{}). + Where("user_info.user_id = user.user_id"). + Where("user_info.height != '' "). + Where("user_info.weight != '' "). + Where("user_info.is_family_history is not NULL"). + Where("user_info.province_id is not NULL"). + Select("1") + query = query.Where("EXISTS (?)", subQuery) + } else { + subQuery := global.Db.Model(&model.UserInfo{}). + Where("user_info.user_id = user.user_id"). + Or("user_info.height = '' "). + Or("user_info.weight = '' "). + Or("user_info.is_family_history is NULL"). + Or("user_info.province_id is NULL"). + Select("1") + query = query.Where("EXISTS (?)", subQuery) + } } // 排序 diff --git a/api/requests/User.go b/api/requests/User.go index 02b2ffd..5df0773 100644 --- a/api/requests/User.go +++ b/api/requests/User.go @@ -18,7 +18,7 @@ type GetUserPage struct { Sex *int `json:"sex" form:"sex" label:"性别"` IsMember *int `json:"is_member" form:"is_member" label:"是否会员"` MemberExpireDate string `json:"member_expire_date" form:"member_expire_date" label:"会员到期时间"` // 假设转换为可选字符串 - IsInfoComplete *int `json:"is_info_complete" form:"is_info_complete" label:"信息完善状态"` // 0:否 1:是 + IsInfoComplete *bool `json:"is_info_complete" form:"is_info_complete" label:"信息完善状态"` // 0:否 1:是 Order *GetUserPageOrder `json:"order" form:"order" label:"排序"` }