From b8fb0c8ee84a3c7abdf141644ea6d6c817b79f41 Mon Sep 17 00:00:00 2001 From: "yan.y" Date: Mon, 20 May 2024 09:32:12 +0800 Subject: [PATCH] update --- business/api/auth.go | 12 +-- business/api/car.go | 10 +- business/api/common.go | 27 +++-- business/api/control.go | 1 + business/api/init.go | 39 ++++--- business/api/order.go | 169 ++++++++++++++++++++++-------- business/models/dataModel.go | 1 + business/utils/commonUtil.go | 5 + business/utils/commonUtil_test.go | 24 +++++ 9 files changed, 208 insertions(+), 80 deletions(-) diff --git a/business/api/auth.go b/business/api/auth.go index 79cb05f..aa45d37 100644 --- a/business/api/auth.go +++ b/business/api/auth.go @@ -25,7 +25,7 @@ type LoginResponse struct { Uid int64 `json:"uid"` NickName string `json:"nickName"` HeadImgUrl string `json:"headImgUrl"` - Amount int `json:"amount"` + Amount float64 `json:"amount"` Discount float32 `json:"discount"` Role int `json:"role"` UserPets []UserPetInfo `json:"userPets"` @@ -33,7 +33,7 @@ type LoginResponse struct { } var defaultNickName = "微信用户" -var defaultHeadImgUrl = web.CONFIG.System.Domain + "/static/img/20240327152925.jpg" +var defaultHeadImgUrl = web.CONFIG.System.Domain + "/static/img/default_head.jpg" // 登录 func (p DefParty) login() web_iris.Party { @@ -91,7 +91,7 @@ func (p DefParty) login() web_iris.Party { Uid: userInfo.Id, NickName: userInfo.NickName, HeadImgUrl: userInfo.HeadImgUrl, - Amount: userInfo.Amount, + Amount: float64(userInfo.Amount) / 10.0, Role: userInfo.Role, Discount: float32(userInfo.Discount) / 100, } @@ -146,7 +146,7 @@ func (p DefParty) updateUserInfo() web_iris.Party { Uid: userInfo.Id, NickName: userInfo.NickName, HeadImgUrl: userInfo.HeadImgUrl, - Amount: userInfo.Amount, + Amount: float64(userInfo.Amount) / 10.0, Role: userInfo.Role, UserPets: GetUserPets(userInfo.Id), } @@ -160,7 +160,7 @@ type GetUserInfoResponse struct { NickName string `json:"nickName"` HeadImgUrl string `json:"headImgUrl"` Discount float64 `json:"discount"` - Amount int `json:"amount"` + Amount float64 `json:"amount"` Role int `json:"role"` UserPets []UserPetInfo `json:"userPets"` Car models.ServiceCar `json:"car"` @@ -181,7 +181,7 @@ func (p DefParty) getUserInfo() web_iris.Party { Uid: userInfo.Id, NickName: userInfo.NickName, HeadImgUrl: userInfo.HeadImgUrl, - Amount: userInfo.Amount, + Amount: float64(userInfo.Amount) / 10.0, Discount: float64(userInfo.Discount) / 100, Role: userInfo.Role, UserPets: GetUserPets(userInfo.Id), diff --git a/business/api/car.go b/business/api/car.go index 441ccf5..f43837b 100644 --- a/business/api/car.go +++ b/business/api/car.go @@ -115,7 +115,7 @@ func (p DefParty) carServiceProcess() web_iris.Party { return } if carServiceProcessRequest.PayAmount > 0 { - subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount + subOrderInfo.TotalAmount = carServiceProcessRequest.PayAmount subOrderInfo.PayTime = time.Now() subOrderInfo.PayStatus = 1 } @@ -132,7 +132,7 @@ func (p DefParty) carServiceProcess() web_iris.Party { subOrderInfo.PayStatus = 1 subOrderInfo.PayTime = time.Now() if carServiceProcessRequest.PayAmount > 0 { - subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount + subOrderInfo.TotalAmount = carServiceProcessRequest.PayAmount } subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark database.Instance().Save(&subOrderInfo) @@ -150,6 +150,12 @@ func (p DefParty) carServiceProcess() web_iris.Party { mainOrder.OrderStatus = 3 database.Instance().Save(&mainOrder) } + pet := GetPet(subOrderInfo.PetId) + pet.PetInfo.LastServiceDate = time.Now().Format("2006-01-02 15:04:05") + updateValues := map[string]interface{}{ + "LastServiceDate": pet.PetInfo.LastServiceDate, + } + database.Instance().Model(&models.Pet{}).Updates(&updateValues) } else if carServiceProcessRequest.Type == 3 { subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark database.Instance().Save(&subOrderInfo) diff --git a/business/api/common.go b/business/api/common.go index 156a779..dbfde89 100644 --- a/business/api/common.go +++ b/business/api/common.go @@ -130,18 +130,20 @@ func DataInit() { //--------------------------------------------------宠物基础信息数据--------------------------------------------------------- var petBastInfoList []models.PetBaseInfo database.Instance().Model(&models.PetBaseInfo{}).Find(&petBastInfoList) - PetBaseInfoMap = make(map[int]models.PetBaseInfo) + var PetBaseInfoMapC1 = make(map[int]models.PetBaseInfo) for _, value := range petBastInfoList { - PetBaseInfoMap[value.Id] = value + PetBaseInfoMapC1[value.Id] = value } + PetBaseInfoMap = PetBaseInfoMapC1 zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap)) //--------------------------------------------------服务地址数据--------------------------------------------------------- var serviceAddrList []models.ServiceAddr database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList) - ServiceAddrMap = make(map[int64]models.ServiceAddr) + var ServiceAddrMapC1 = make(map[int64]models.ServiceAddr) for _, value := range serviceAddrList { - ServiceAddrMap[value.Id] = value + ServiceAddrMapC1[value.Id] = value } + ServiceAddrMap := ServiceAddrMapC1 zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap)) //--------------------------------------------------宠物商品关联数据--------------------------------------------------------- var petGoodsList []models.PetGoods @@ -168,24 +170,27 @@ func DataInit() { zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap)) var carList []models.ServiceCar database.Instance().Model(&models.ServiceCar{}).Find(&carList) - CarMap = make(map[int]models.ServiceCar) + var CarMapC1 = make(map[int]models.ServiceCar) for _, value := range carList { - CarMap[value.Id] = value + CarMapC1[value.Id] = value } + CarMap = CarMapC1 zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap)) var timesList []models.ReserveTimeFilter database.Instance().Model(&models.ReserveTimeFilter{}).Find(×List) - ReserveMap = make(map[string]models.ReserveTimeFilter) + var ReserveMapC1 = make(map[string]models.ReserveTimeFilter) for _, value := range timesList { - ReserveMap[value.Content] = value + ReserveMapC1[value.Content] = value } - zap_server.ZAPLOG.Info("dataInit ReserveMap : ", zap.Any("ReserveMap", CarMap)) + ReserveMap = ReserveMapC1 + zap_server.ZAPLOG.Info("dataInit ReserveMap : ", zap.Any("ReserveMap", ReserveMap)) var serviceTimesList []models.AddrServiceTime database.Instance().Model(&models.AddrServiceTime{}).Find(&serviceTimesList) - AddrServiceMap = make(map[int64]models.AddrServiceTime) + var AddrServiceMapC1 = make(map[int64]models.AddrServiceTime) for _, value := range serviceTimesList { - AddrServiceMap[value.ServiceAddrId] = value + AddrServiceMapC1[value.ServiceAddrId] = value } + AddrServiceMap = AddrServiceMapC1 zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap)) } diff --git a/business/api/control.go b/business/api/control.go index de6a5ac..cd69cb7 100644 --- a/business/api/control.go +++ b/business/api/control.go @@ -31,6 +31,7 @@ func (p DefParty) RegisterList() []web_iris.Party { p.orderGoodsUpdate(), p.orderPay(), p.orderCancel(), + p.orderCreatePreCheck(), //宠物 p.petList(), p.petInfo(), diff --git a/business/api/init.go b/business/api/init.go index e3209ba..40c6b6c 100644 --- a/business/api/init.go +++ b/business/api/init.go @@ -4,7 +4,6 @@ import ( "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/context" "go.uber.org/zap" - "pet-house.com/business/models" "pet-house.com/business/utils" "pet-house.com/core/server/database" "pet-house.com/core/server/web/web_iris" @@ -26,25 +25,25 @@ var frontExcludes = [...]string{ func ModuleInit() { utils.WechatInit() _ = database.Instance().AutoMigrate( - &models.User{}, - &models.Pet{}, - &models.PetBaseInfo{}, - &models.ServiceAddr{}, - &models.UserServiceAddr{}, - &models.Goods{}, - &models.PetGoods{}, - &models.SystemConfig{}, - &models.OrderMain{}, - &models.OrderSub{}, - &models.OrderDetail{}, - &models.ServiceCar{}, - &models.CarOrder{}, - &models.ServiceCarUser{}, - &models.ServiceUserMark{}, - &models.ServiceUserMarkRecord{}, - &models.ReserveTimeFilter{}, - &models.OrderServiceRecord{}, - &models.AddrServiceTime{}, + //&models.User{}, + //&models.Pet{}, + //&models.PetBaseInfo{}, + //&models.ServiceAddr{}, + //&models.UserServiceAddr{}, + //&models.Goods{}, + //&models.PetGoods{}, + //&models.SystemConfig{}, + //&models.OrderMain{}, + //&models.OrderSub{}, + //&models.OrderDetail{}, + //&models.ServiceCar{}, + //&models.CarOrder{}, + //&models.ServiceCarUser{}, + //&models.ServiceUserMark{}, + //&models.ServiceUserMarkRecord{}, + //&models.ReserveTimeFilter{}, + //&models.OrderServiceRecord{}, + //&models.AddrServiceTime{}, ) DataInit() DataCacheJob() diff --git a/business/api/order.go b/business/api/order.go index fef4ab6..5855a74 100644 --- a/business/api/order.go +++ b/business/api/order.go @@ -8,7 +8,6 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" "io" - "math" "pet-house.com/business/models" "pet-house.com/business/utils" "pet-house.com/core/server/database" @@ -35,6 +34,49 @@ type OrderCreateResponse struct { OrderDetail OrderDetail `json:"orderDetail"` } +type OrderCreatePreCheckResponse struct { + HasAlert bool `json:"hasAlert"` //是否弹窗提示 返回false直接下单,返回ture弹出确认框,确认框点击是之后调用下单接口 + AlertMsg string `json:"alertMsg"` //弹窗消息 +} + +func (p DefParty) orderCreatePreCheck() web_iris.Party { + return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) { + index.Post(OrderBase+"/orderCreatePreCheck", func(ctx *context.Context) { + headerBaseInfo := GetHeaderBaseInfo(ctx) + body, _ := io.ReadAll(ctx.Request().Body) + var orderCreateRequest OrderCreateRequest + json.Unmarshal(body, &orderCreateRequest) + if len(orderCreateRequest.PetGoodsInfos) == 0 { + ParamError.Fail(ctx, orderCreateRequest) + return + } + var userInfo *models.User + database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo) + var orderTotalAmount = 0 + for _, value := range orderCreateRequest.PetGoodsInfos { + for _, value := range value.GoodsIds { + goods := GoodsMap[value] + orderTotalAmount = orderTotalAmount + int(goods.Price) + } + } + orderCreatePreCheckResponse := OrderCreatePreCheckResponse{ + HasAlert: false, + } + var discountAmount = orderTotalAmount + if userInfo.Discount > 0 { + discount := float64(userInfo.Discount) + discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount)*(discount/100.0)) * 10) + if userInfo.Amount < discountAmount { + orderCreatePreCheckResponse.HasAlert = true + orderCreatePreCheckResponse.AlertMsg = "您的会员余额不够,需要进行线下支付,当前订单将不享受会员折扣优惠价格" + } + } + + Success(ctx, orderCreateRequest, orderCreatePreCheckResponse) + }) + }} +} + var orderLock sync.Mutex // 创建 @@ -142,17 +184,20 @@ func (p DefParty) orderCreate() web_iris.Party { orderMain.ProjectionServiceTime = projectionServiceTimeAll var userInfo *models.User database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo) + var discountAmount = orderTotalAmount if userInfo.Discount > 0 { discount := float64(userInfo.Discount) - orderTotalAmount = int(math.Round(float64(orderTotalAmount) * (discount / 100.0))) + discountAmount = int(utils.RoundToOneDecimalPlace(float64(orderTotalAmount)*(discount/100.0)) * 10) + //discountAmount = int(math.Round(float64(orderTotalAmount)*(discount/100.0)) * 10) } + orderMain.TotalAmount = orderTotalAmount tx := database.Instance().Begin() var db4 *gorm.DB - if userInfo.Amount >= orderTotalAmount { + if userInfo.Amount >= discountAmount { var currAmount = userInfo.Amount orderMain.PayStatus = 1 - orderMain.PayTotalAmount = orderTotalAmount - userInfo.Amount = userInfo.Amount - orderTotalAmount + orderMain.PayTotalAmount = discountAmount + userInfo.Amount = userInfo.Amount - discountAmount updateValues := map[string]interface{}{ "Amount": userInfo.Amount, } @@ -162,7 +207,13 @@ func (p DefParty) orderCreate() web_iris.Party { for index := range orderSubList { orderSubList[index].PayType = 3 } - zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("当前余额", currAmount), zap.Any("扣除余额", orderTotalAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount)) + zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("订单号", orderMain.OrderId), zap.Any("当前余额", currAmount), zap.Any("扣除余额", discountAmount), zap.Any("剩余余额", userInfo.Amount), zap.Any("折扣", userInfo.Discount)) + discount := float64(userInfo.Discount) + for index, _ := range orderSubList { + orderSubList[index].Discount = userInfo.Discount + //orderSubList[index].PayAmount = int32(math.Round(float64(orderSubList[index].TotalAmount) * (discount / 100.0))) + orderSubList[index].PayAmount = int32(utils.RoundToOneDecimalPlace(float64(orderSubList[index].TotalAmount)*(discount/100.0)) * 10) + } } var findUserServiceAddr models.UserServiceAddr database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr) @@ -202,6 +253,12 @@ func GetOrderDetail(orderId string) OrderDetail { CreateTime: orderMain.CreateTime.Format("2006-01-02 15:04:05"), PayStatus: orderMain.PayStatus, DispatchStatus: orderMain.DispatchStatus, + TotalAmount: orderMain.TotalAmount, + DiscountAmount: strconv.Itoa(orderMain.TotalAmount), + Discount: float64(orderMain.PayDiscount) / 100, + } + if orderMain.PayDiscount > 0 { + orderDetail.DiscountAmount = strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10.0, 'f', 1, 64) } var subOrderList []SubOrder var orderSubList []models.OrderSub @@ -214,15 +271,25 @@ func GetOrderDetail(orderId string) OrderDetail { good := GoodsMap[orderDetail.GoodsId] goods = append(goods, good) } - orderSub := SubOrder{ + orderSubR1 := SubOrder{ OrderId: orderSub.OrderId, Status: orderSub.OrderStatus, UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId), TotalAmount: orderSub.TotalAmount, - PayAmount: orderSub.PayAmount, + PayAmount: strconv.Itoa(int(orderSub.PayAmount)), + Discount: float64(orderSub.Discount), Goods: goods, } - subOrderList = append(subOrderList, orderSub) + if orderSubR1.Discount < 100 { + //orderSubR1.PayAmount = int32(math.Round(float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0))) + //x := float64(orderSubR1.TotalAmount) * (orderSubR1.Discount / 100.0) / 10 + x := float64(orderSub.PayAmount) / 10 + orderSubR1.PayAmount = strconv.FormatFloat(x, 'f', 1, 64) + orderSubR1.DiscountAmount = orderSubR1.PayAmount + } else { + orderSubR1.DiscountAmount = strconv.Itoa(int(orderSubR1.TotalAmount)) + } + subOrderList = append(subOrderList, orderSubR1) } var carOrder models.CarOrder database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder) @@ -259,12 +326,14 @@ type OrderListRequest struct { } type SubOrder struct { - OrderId string `json:"orderId"` //子订单ID - Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消 - UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息 - TotalAmount int32 `json:"totalAmount"` //总金额 单位:分 - PayAmount int32 `json:"payAmount"` //实际支付金额 单位:分 - Goods []models.Goods `json:"goods"` //商品信息 + OrderId string `json:"orderId"` //子订单ID + Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消 + UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息 + TotalAmount int32 `json:"totalAmount"` //总金额 + PayAmount string `json:"payAmount"` //实际支付金额 + DiscountAmount string `json:"discountAmount"` //折扣金额 + Discount float64 `json:"discount"` //用户折扣 + Goods []models.Goods `json:"goods"` //商品信息 } type OrderDetail struct { @@ -278,6 +347,9 @@ type OrderDetail struct { ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有派单状态未1的时候才会存在 PayStatus int `json:"payStatus"` //支付状态 0未支付 1已支付 DispatchStatus int `json:"dispatchStatus"` //派单状态 0未派单 1已派单 + Discount float64 `json:"discount"` //用户折扣 + TotalAmount int `json:"totalAmount"` //总金额 + DiscountAmount string `json:"discountAmount"` //折扣金额 } type OrderListResponse struct { @@ -308,7 +380,7 @@ func (p DefParty) orderList() web_iris.Party { for _, value := range orderList { var findUserServiceAddr models.UserServiceAddr database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", value.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr) - orderListResponse := OrderDetail{ + orderDetail := OrderDetail{ OrderId: value.OrderId, Status: value.OrderStatus, ServiceTime: value.ServiceTime, @@ -317,6 +389,9 @@ func (p DefParty) orderList() web_iris.Party { CreateTime: value.CreateTime.Format("2006-01-02 15:04:05"), PayStatus: value.PayStatus, DispatchStatus: value.DispatchStatus, + TotalAmount: value.TotalAmount, + DiscountAmount: strconv.FormatFloat(float64(value.PayTotalAmount)/10.0, 'f', 1, 64), + Discount: float64(value.PayDiscount / 100.0), } var subOrderList []SubOrder var orderSubList []models.OrderSub @@ -332,15 +407,22 @@ func (p DefParty) orderList() web_iris.Party { orderSub := SubOrder{ OrderId: orderSub.OrderId, Status: orderSub.OrderStatus, - UserPetInfo: GetUserPet(headerBaseInfo.Uid, orderSub.PetId), + UserPetInfo: GetUserPet(value.Uid, orderSub.PetId), TotalAmount: orderSub.TotalAmount, - PayAmount: orderSub.PayAmount, + Discount: float64(orderSub.Discount / 100.0), Goods: goods, } + if orderSub.Discount > 0 { + //orderSub.PayAmount = int32(math.Round(float64(orderSub.TotalAmount) * (orderSub.Discount / 100.0))) + //orderSub.DiscountAmount = orderSub.PayAmount + x := float64(orderSub.TotalAmount) * (orderSub.Discount / 100.0) / 10 + orderSub.PayAmount = strconv.FormatFloat(x, 'f', 1, 64) + orderSub.DiscountAmount = orderSub.PayAmount + } subOrderList = append(subOrderList, orderSub) } - orderListResponse.SubOrderList = subOrderList - orderDetails = append(orderDetails, orderListResponse) + orderDetail.SubOrderList = subOrderList + orderDetails = append(orderDetails, orderDetail) } var orderListResponse = OrderListResponse{ OrderDetails: orderDetails, @@ -581,29 +663,32 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { //已支付 if orderMain.PayStatus == 1 { - var userInfo *models.User - database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo) - //先退还 - userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount + if orderMain.PayType == 3 { + var userInfo *models.User + database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo) + //先退还 + userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount - if userInfo.Discount > 0 { - discount := float64(userInfo.Discount) - newAmount = int(math.Round(float64(newAmount) * (discount / 100.0))) + if userInfo.Discount > 0 { + discount := float64(userInfo.Discount) + newAmount = int(utils.RoundToOneDecimalPlace(float64(newAmount)*(discount/100.0)) * 10) + } + //余额不足 + if userInfo.Amount < newAmount { + OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(newAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付") + return + } + var originAmount = userInfo.Amount + var preAmount = orderMain.PayTotalAmount + userInfo.Amount = userInfo.Amount - newAmount + orderMain.PayTotalAmount = newAmount + updateValues := map[string]interface{}{ + "Amount": userInfo.Amount, + } + database.Instance().Model(&userInfo).Updates(&updateValues) + orderMain.PayDiscount = userInfo.Discount + zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("订单ID", orderMain.OrderId), zap.Any("用户修改之前余额", originAmount), zap.Any("当前余额", userInfo.Amount), zap.Any("商品修改之前金额", preAmount), zap.Any("商品修改之后金额", orderMain.PayTotalAmount), zap.Any("折扣", userInfo.Discount)) } - //余额不足 - if userInfo.Amount < newAmount { - OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.Itoa(orderMain.PayTotalAmount)+" 修改后订单金额:"+strconv.Itoa(newAmount)+";修改服务项目后余额不足,请充值后再修改") - return - } - var preAmount = orderMain.PayTotalAmount - orderMain.PayTotalAmount = newAmount - userInfo.Amount = userInfo.Amount - newAmount - updateValues := map[string]interface{}{ - "Amount": userInfo.Amount, - } - database.Instance().Model(&userInfo).Updates(&updateValues) - orderMain.PayDiscount = userInfo.Discount - zap_server.ZAPLOG.Info("会员金额扣除", zap.Any("用户ID", userInfo.Id), zap.Any("当前余额", userInfo.Amount), zap.Any("商品修改之前金额", preAmount), zap.Any("商品修改之后金额", orderMain.PayTotalAmount), zap.Any("折扣", userInfo.Discount)) } database.Instance().Where("sub_order_id = ?", orderGoodsUpdateRequest.OrderId).Delete(&models.OrderDetail{}) @@ -618,9 +703,11 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { } orderSub.TotalAmount = int32(totalAmount) + orderSub.PayAmount = int32(newAmount) orderSub.ProjectionServiceTime = projectionServiceTime updateValues := map[string]interface{}{ "TotalAmount": orderSub.TotalAmount, + "PayAmount": orderSub.PayAmount, "ProjectionServiceTime": orderSub.ProjectionServiceTime, } orderMain.ProjectionServiceTime = allProjectionServiceTime diff --git a/business/models/dataModel.go b/business/models/dataModel.go index f4d4a80..1a743c1 100644 --- a/business/models/dataModel.go +++ b/business/models/dataModel.go @@ -131,6 +131,7 @@ type OrderMain struct { PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付 DispatchStatus int `gorm:"default:0" json:"dispatchStatus"` //派单状态 0未派单 1已派单 PayTotalAmount int `json:"payTotalAmount"` //支付总金额 + TotalAmount int `json:"totalAmount"` //总金额 PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣 PayType int `gorm:"default:1" json:"payType"` //支付方式 1线下 2线上 3会员余额 } diff --git a/business/utils/commonUtil.go b/business/utils/commonUtil.go index bc45f18..9e79578 100644 --- a/business/utils/commonUtil.go +++ b/business/utils/commonUtil.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/kataras/iris/v12/context" "io" + "math" "pet-house.com/business/models" "time" ) @@ -112,3 +113,7 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil } return dayHoursMap } + +func RoundToOneDecimalPlace(value float64) float64 { + return math.Round(value*10) / 10 +} diff --git a/business/utils/commonUtil_test.go b/business/utils/commonUtil_test.go index 7376d52..308d446 100644 --- a/business/utils/commonUtil_test.go +++ b/business/utils/commonUtil_test.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "pet-house.com/business/models" + "strconv" "testing" ) @@ -30,3 +31,26 @@ func TestCalc1(t *testing.T) { i := float64(85) / 100 fmt.Println(i) } + +func roundToOneDecimalPlace(value float64) float64 { + return math.Round(value*10) / 10 +} + +func TestCalc3(t *testing.T) { + i := float64(348) * 0.95 + fmt.Println(i) +} +func TestCalc4(t *testing.T) { + value := 267.77 + roundedValue := roundToOneDecimalPlace(value) + fmt.Printf("%.1f\n", roundedValue) // 输出 3.1 +} +func TestCalc5(t *testing.T) { + var a = 1596 + float := strconv.FormatFloat(float64(a/10.0), 'f', 1, 64) + fmt.Printf(float) +} +func TestMath(t *testing.T) { + i := int(float64(256) * (85 / 100.0) * 10) + fmt.Println(i) +}