This commit is contained in:
yan.y 2024-05-20 09:32:12 +08:00
parent ae34bf5f26
commit b8fb0c8ee8
9 changed files with 208 additions and 80 deletions

View File

@ -25,7 +25,7 @@ type LoginResponse struct {
Uid int64 `json:"uid"` Uid int64 `json:"uid"`
NickName string `json:"nickName"` NickName string `json:"nickName"`
HeadImgUrl string `json:"headImgUrl"` HeadImgUrl string `json:"headImgUrl"`
Amount int `json:"amount"` Amount float64 `json:"amount"`
Discount float32 `json:"discount"` Discount float32 `json:"discount"`
Role int `json:"role"` Role int `json:"role"`
UserPets []UserPetInfo `json:"userPets"` UserPets []UserPetInfo `json:"userPets"`
@ -33,7 +33,7 @@ type LoginResponse struct {
} }
var defaultNickName = "微信用户" 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 { func (p DefParty) login() web_iris.Party {
@ -91,7 +91,7 @@ func (p DefParty) login() web_iris.Party {
Uid: userInfo.Id, Uid: userInfo.Id,
NickName: userInfo.NickName, NickName: userInfo.NickName,
HeadImgUrl: userInfo.HeadImgUrl, HeadImgUrl: userInfo.HeadImgUrl,
Amount: userInfo.Amount, Amount: float64(userInfo.Amount) / 10.0,
Role: userInfo.Role, Role: userInfo.Role,
Discount: float32(userInfo.Discount) / 100, Discount: float32(userInfo.Discount) / 100,
} }
@ -146,7 +146,7 @@ func (p DefParty) updateUserInfo() web_iris.Party {
Uid: userInfo.Id, Uid: userInfo.Id,
NickName: userInfo.NickName, NickName: userInfo.NickName,
HeadImgUrl: userInfo.HeadImgUrl, HeadImgUrl: userInfo.HeadImgUrl,
Amount: userInfo.Amount, Amount: float64(userInfo.Amount) / 10.0,
Role: userInfo.Role, Role: userInfo.Role,
UserPets: GetUserPets(userInfo.Id), UserPets: GetUserPets(userInfo.Id),
} }
@ -160,7 +160,7 @@ type GetUserInfoResponse struct {
NickName string `json:"nickName"` NickName string `json:"nickName"`
HeadImgUrl string `json:"headImgUrl"` HeadImgUrl string `json:"headImgUrl"`
Discount float64 `json:"discount"` Discount float64 `json:"discount"`
Amount int `json:"amount"` Amount float64 `json:"amount"`
Role int `json:"role"` Role int `json:"role"`
UserPets []UserPetInfo `json:"userPets"` UserPets []UserPetInfo `json:"userPets"`
Car models.ServiceCar `json:"car"` Car models.ServiceCar `json:"car"`
@ -181,7 +181,7 @@ func (p DefParty) getUserInfo() web_iris.Party {
Uid: userInfo.Id, Uid: userInfo.Id,
NickName: userInfo.NickName, NickName: userInfo.NickName,
HeadImgUrl: userInfo.HeadImgUrl, HeadImgUrl: userInfo.HeadImgUrl,
Amount: userInfo.Amount, Amount: float64(userInfo.Amount) / 10.0,
Discount: float64(userInfo.Discount) / 100, Discount: float64(userInfo.Discount) / 100,
Role: userInfo.Role, Role: userInfo.Role,
UserPets: GetUserPets(userInfo.Id), UserPets: GetUserPets(userInfo.Id),

View File

@ -115,7 +115,7 @@ func (p DefParty) carServiceProcess() web_iris.Party {
return return
} }
if carServiceProcessRequest.PayAmount > 0 { if carServiceProcessRequest.PayAmount > 0 {
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount subOrderInfo.TotalAmount = carServiceProcessRequest.PayAmount
subOrderInfo.PayTime = time.Now() subOrderInfo.PayTime = time.Now()
subOrderInfo.PayStatus = 1 subOrderInfo.PayStatus = 1
} }
@ -132,7 +132,7 @@ func (p DefParty) carServiceProcess() web_iris.Party {
subOrderInfo.PayStatus = 1 subOrderInfo.PayStatus = 1
subOrderInfo.PayTime = time.Now() subOrderInfo.PayTime = time.Now()
if carServiceProcessRequest.PayAmount > 0 { if carServiceProcessRequest.PayAmount > 0 {
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount subOrderInfo.TotalAmount = carServiceProcessRequest.PayAmount
} }
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
database.Instance().Save(&subOrderInfo) database.Instance().Save(&subOrderInfo)
@ -150,6 +150,12 @@ func (p DefParty) carServiceProcess() web_iris.Party {
mainOrder.OrderStatus = 3 mainOrder.OrderStatus = 3
database.Instance().Save(&mainOrder) 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 { } else if carServiceProcessRequest.Type == 3 {
subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark subOrderInfo.PayRemark = carServiceProcessRequest.PayRemark
database.Instance().Save(&subOrderInfo) database.Instance().Save(&subOrderInfo)

View File

@ -130,18 +130,20 @@ func DataInit() {
//--------------------------------------------------宠物基础信息数据--------------------------------------------------------- //--------------------------------------------------宠物基础信息数据---------------------------------------------------------
var petBastInfoList []models.PetBaseInfo var petBastInfoList []models.PetBaseInfo
database.Instance().Model(&models.PetBaseInfo{}).Find(&petBastInfoList) database.Instance().Model(&models.PetBaseInfo{}).Find(&petBastInfoList)
PetBaseInfoMap = make(map[int]models.PetBaseInfo) var PetBaseInfoMapC1 = make(map[int]models.PetBaseInfo)
for _, value := range petBastInfoList { for _, value := range petBastInfoList {
PetBaseInfoMap[value.Id] = value PetBaseInfoMapC1[value.Id] = value
} }
PetBaseInfoMap = PetBaseInfoMapC1
zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap)) zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
//--------------------------------------------------服务地址数据--------------------------------------------------------- //--------------------------------------------------服务地址数据---------------------------------------------------------
var serviceAddrList []models.ServiceAddr var serviceAddrList []models.ServiceAddr
database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList) database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList)
ServiceAddrMap = make(map[int64]models.ServiceAddr) var ServiceAddrMapC1 = make(map[int64]models.ServiceAddr)
for _, value := range serviceAddrList { for _, value := range serviceAddrList {
ServiceAddrMap[value.Id] = value ServiceAddrMapC1[value.Id] = value
} }
ServiceAddrMap := ServiceAddrMapC1
zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap)) zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap))
//--------------------------------------------------宠物商品关联数据--------------------------------------------------------- //--------------------------------------------------宠物商品关联数据---------------------------------------------------------
var petGoodsList []models.PetGoods var petGoodsList []models.PetGoods
@ -168,24 +170,27 @@ func DataInit() {
zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap)) zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
var carList []models.ServiceCar var carList []models.ServiceCar
database.Instance().Model(&models.ServiceCar{}).Find(&carList) database.Instance().Model(&models.ServiceCar{}).Find(&carList)
CarMap = make(map[int]models.ServiceCar) var CarMapC1 = make(map[int]models.ServiceCar)
for _, value := range carList { for _, value := range carList {
CarMap[value.Id] = value CarMapC1[value.Id] = value
} }
CarMap = CarMapC1
zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap)) zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap))
var timesList []models.ReserveTimeFilter var timesList []models.ReserveTimeFilter
database.Instance().Model(&models.ReserveTimeFilter{}).Find(&timesList) database.Instance().Model(&models.ReserveTimeFilter{}).Find(&timesList)
ReserveMap = make(map[string]models.ReserveTimeFilter) var ReserveMapC1 = make(map[string]models.ReserveTimeFilter)
for _, value := range timesList { 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 var serviceTimesList []models.AddrServiceTime
database.Instance().Model(&models.AddrServiceTime{}).Find(&serviceTimesList) database.Instance().Model(&models.AddrServiceTime{}).Find(&serviceTimesList)
AddrServiceMap = make(map[int64]models.AddrServiceTime) var AddrServiceMapC1 = make(map[int64]models.AddrServiceTime)
for _, value := range serviceTimesList { for _, value := range serviceTimesList {
AddrServiceMap[value.ServiceAddrId] = value AddrServiceMapC1[value.ServiceAddrId] = value
} }
AddrServiceMap = AddrServiceMapC1
zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap)) zap_server.ZAPLOG.Info("dataInit AddrServiceMap : ", zap.Any("AddrServiceMap", AddrServiceMap))
} }

View File

@ -31,6 +31,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
p.orderGoodsUpdate(), p.orderGoodsUpdate(),
p.orderPay(), p.orderPay(),
p.orderCancel(), p.orderCancel(),
p.orderCreatePreCheck(),
//宠物 //宠物
p.petList(), p.petList(),
p.petInfo(), p.petInfo(),

View File

@ -4,7 +4,6 @@ import (
"github.com/kataras/iris/v12" "github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context" "github.com/kataras/iris/v12/context"
"go.uber.org/zap" "go.uber.org/zap"
"pet-house.com/business/models"
"pet-house.com/business/utils" "pet-house.com/business/utils"
"pet-house.com/core/server/database" "pet-house.com/core/server/database"
"pet-house.com/core/server/web/web_iris" "pet-house.com/core/server/web/web_iris"
@ -26,25 +25,25 @@ var frontExcludes = [...]string{
func ModuleInit() { func ModuleInit() {
utils.WechatInit() utils.WechatInit()
_ = database.Instance().AutoMigrate( _ = database.Instance().AutoMigrate(
&models.User{}, //&models.User{},
&models.Pet{}, //&models.Pet{},
&models.PetBaseInfo{}, //&models.PetBaseInfo{},
&models.ServiceAddr{}, //&models.ServiceAddr{},
&models.UserServiceAddr{}, //&models.UserServiceAddr{},
&models.Goods{}, //&models.Goods{},
&models.PetGoods{}, //&models.PetGoods{},
&models.SystemConfig{}, //&models.SystemConfig{},
&models.OrderMain{}, //&models.OrderMain{},
&models.OrderSub{}, //&models.OrderSub{},
&models.OrderDetail{}, //&models.OrderDetail{},
&models.ServiceCar{}, //&models.ServiceCar{},
&models.CarOrder{}, //&models.CarOrder{},
&models.ServiceCarUser{}, //&models.ServiceCarUser{},
&models.ServiceUserMark{}, //&models.ServiceUserMark{},
&models.ServiceUserMarkRecord{}, //&models.ServiceUserMarkRecord{},
&models.ReserveTimeFilter{}, //&models.ReserveTimeFilter{},
&models.OrderServiceRecord{}, //&models.OrderServiceRecord{},
&models.AddrServiceTime{}, //&models.AddrServiceTime{},
) )
DataInit() DataInit()
DataCacheJob() DataCacheJob()

View File

@ -8,7 +8,6 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"io" "io"
"math"
"pet-house.com/business/models" "pet-house.com/business/models"
"pet-house.com/business/utils" "pet-house.com/business/utils"
"pet-house.com/core/server/database" "pet-house.com/core/server/database"
@ -35,6 +34,49 @@ type OrderCreateResponse struct {
OrderDetail OrderDetail `json:"orderDetail"` 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 var orderLock sync.Mutex
// 创建 // 创建
@ -142,17 +184,20 @@ func (p DefParty) orderCreate() web_iris.Party {
orderMain.ProjectionServiceTime = projectionServiceTimeAll orderMain.ProjectionServiceTime = projectionServiceTimeAll
var userInfo *models.User var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo) database.Instance().Model(&models.User{}).Where("id = ?", headerBaseInfo.Uid).Find(&userInfo)
var discountAmount = orderTotalAmount
if userInfo.Discount > 0 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) 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() tx := database.Instance().Begin()
var db4 *gorm.DB var db4 *gorm.DB
if userInfo.Amount >= orderTotalAmount { if userInfo.Amount >= discountAmount {
var currAmount = userInfo.Amount var currAmount = userInfo.Amount
orderMain.PayStatus = 1 orderMain.PayStatus = 1
orderMain.PayTotalAmount = orderTotalAmount orderMain.PayTotalAmount = discountAmount
userInfo.Amount = userInfo.Amount - orderTotalAmount userInfo.Amount = userInfo.Amount - discountAmount
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"Amount": userInfo.Amount, "Amount": userInfo.Amount,
} }
@ -162,7 +207,13 @@ func (p DefParty) orderCreate() web_iris.Party {
for index := range orderSubList { for index := range orderSubList {
orderSubList[index].PayType = 3 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 var findUserServiceAddr models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", orderCreateRequest.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr) 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"), CreateTime: orderMain.CreateTime.Format("2006-01-02 15:04:05"),
PayStatus: orderMain.PayStatus, PayStatus: orderMain.PayStatus,
DispatchStatus: orderMain.DispatchStatus, 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 subOrderList []SubOrder
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
@ -214,15 +271,25 @@ func GetOrderDetail(orderId string) OrderDetail {
good := GoodsMap[orderDetail.GoodsId] good := GoodsMap[orderDetail.GoodsId]
goods = append(goods, good) goods = append(goods, good)
} }
orderSub := SubOrder{ orderSubR1 := SubOrder{
OrderId: orderSub.OrderId, OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus, Status: orderSub.OrderStatus,
UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId), UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId),
TotalAmount: orderSub.TotalAmount, TotalAmount: orderSub.TotalAmount,
PayAmount: orderSub.PayAmount, PayAmount: strconv.Itoa(int(orderSub.PayAmount)),
Discount: float64(orderSub.Discount),
Goods: goods, 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 var carOrder models.CarOrder
database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder) database.Instance().Model(&models.CarOrder{}).Where("order_id = ?", orderMain.OrderId).Find(&carOrder)
@ -259,12 +326,14 @@ type OrderListRequest struct {
} }
type SubOrder struct { type SubOrder struct {
OrderId string `json:"orderId"` //子订单ID OrderId string `json:"orderId"` //子订单ID
Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消 Status int `json:"status"` //子订单状态 0待派单 1待服务 2服务中 3已完成 4已取消
UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息 UserPetInfo UserPetInfo `json:"userPetInfo"` //用户宠物信息
TotalAmount int32 `json:"totalAmount"` //总金额 单位:分 TotalAmount int32 `json:"totalAmount"` //总金额
PayAmount int32 `json:"payAmount"` //实际支付金额 单位:分 PayAmount string `json:"payAmount"` //实际支付金额
Goods []models.Goods `json:"goods"` //商品信息 DiscountAmount string `json:"discountAmount"` //折扣金额
Discount float64 `json:"discount"` //用户折扣
Goods []models.Goods `json:"goods"` //商品信息
} }
type OrderDetail struct { type OrderDetail struct {
@ -278,6 +347,9 @@ type OrderDetail struct {
ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有派单状态未1的时候才会存在 ServiceCar *models.ServiceCar `json:"serviceCar"` //服务车辆 只有派单状态未1的时候才会存在
PayStatus int `json:"payStatus"` //支付状态 0未支付 1已支付 PayStatus int `json:"payStatus"` //支付状态 0未支付 1已支付
DispatchStatus int `json:"dispatchStatus"` //派单状态 0未派单 1已派单 DispatchStatus int `json:"dispatchStatus"` //派单状态 0未派单 1已派单
Discount float64 `json:"discount"` //用户折扣
TotalAmount int `json:"totalAmount"` //总金额
DiscountAmount string `json:"discountAmount"` //折扣金额
} }
type OrderListResponse struct { type OrderListResponse struct {
@ -308,7 +380,7 @@ func (p DefParty) orderList() web_iris.Party {
for _, value := range orderList { for _, value := range orderList {
var findUserServiceAddr models.UserServiceAddr var findUserServiceAddr models.UserServiceAddr
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", value.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr) database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", value.ServiceAddrId, headerBaseInfo.Uid).Find(&findUserServiceAddr)
orderListResponse := OrderDetail{ orderDetail := OrderDetail{
OrderId: value.OrderId, OrderId: value.OrderId,
Status: value.OrderStatus, Status: value.OrderStatus,
ServiceTime: value.ServiceTime, ServiceTime: value.ServiceTime,
@ -317,6 +389,9 @@ func (p DefParty) orderList() web_iris.Party {
CreateTime: value.CreateTime.Format("2006-01-02 15:04:05"), CreateTime: value.CreateTime.Format("2006-01-02 15:04:05"),
PayStatus: value.PayStatus, PayStatus: value.PayStatus,
DispatchStatus: value.DispatchStatus, 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 subOrderList []SubOrder
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
@ -332,15 +407,22 @@ func (p DefParty) orderList() web_iris.Party {
orderSub := SubOrder{ orderSub := SubOrder{
OrderId: orderSub.OrderId, OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus, Status: orderSub.OrderStatus,
UserPetInfo: GetUserPet(headerBaseInfo.Uid, orderSub.PetId), UserPetInfo: GetUserPet(value.Uid, orderSub.PetId),
TotalAmount: orderSub.TotalAmount, TotalAmount: orderSub.TotalAmount,
PayAmount: orderSub.PayAmount, Discount: float64(orderSub.Discount / 100.0),
Goods: goods, 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) subOrderList = append(subOrderList, orderSub)
} }
orderListResponse.SubOrderList = subOrderList orderDetail.SubOrderList = subOrderList
orderDetails = append(orderDetails, orderListResponse) orderDetails = append(orderDetails, orderDetail)
} }
var orderListResponse = OrderListResponse{ var orderListResponse = OrderListResponse{
OrderDetails: orderDetails, OrderDetails: orderDetails,
@ -581,29 +663,32 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
//已支付 //已支付
if orderMain.PayStatus == 1 { if orderMain.PayStatus == 1 {
var userInfo *models.User if orderMain.PayType == 3 {
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo) var userInfo *models.User
//先退还 database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount //先退还
userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount
if userInfo.Discount > 0 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) discount := float64(userInfo.Discount)
newAmount = int(math.Round(float64(newAmount) * (discount / 100.0))) 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{}) 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.TotalAmount = int32(totalAmount)
orderSub.PayAmount = int32(newAmount)
orderSub.ProjectionServiceTime = projectionServiceTime orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount, "TotalAmount": orderSub.TotalAmount,
"PayAmount": orderSub.PayAmount,
"ProjectionServiceTime": orderSub.ProjectionServiceTime, "ProjectionServiceTime": orderSub.ProjectionServiceTime,
} }
orderMain.ProjectionServiceTime = allProjectionServiceTime orderMain.ProjectionServiceTime = allProjectionServiceTime

View File

@ -131,6 +131,7 @@ type OrderMain struct {
PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付 PayStatus int `gorm:"default:0" json:"payStatus"` //支付状态 0未支付 1已支付
DispatchStatus int `gorm:"default:0" json:"dispatchStatus"` //派单状态 0未派单 1已派单 DispatchStatus int `gorm:"default:0" json:"dispatchStatus"` //派单状态 0未派单 1已派单
PayTotalAmount int `json:"payTotalAmount"` //支付总金额 PayTotalAmount int `json:"payTotalAmount"` //支付总金额
TotalAmount int `json:"totalAmount"` //总金额
PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣 PayDiscount int `gorm:"default:0" json:"payDiscount"` //支付折扣
PayType int `gorm:"default:1" json:"payType"` //支付方式 1线下 2线上 3会员余额 PayType int `gorm:"default:1" json:"payType"` //支付方式 1线下 2线上 3会员余额
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"github.com/kataras/iris/v12/context" "github.com/kataras/iris/v12/context"
"io" "io"
"math"
"pet-house.com/business/models" "pet-house.com/business/models"
"time" "time"
) )
@ -112,3 +113,7 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
} }
return dayHoursMap return dayHoursMap
} }
func RoundToOneDecimalPlace(value float64) float64 {
return math.Round(value*10) / 10
}

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"math" "math"
"pet-house.com/business/models" "pet-house.com/business/models"
"strconv"
"testing" "testing"
) )
@ -30,3 +31,26 @@ func TestCalc1(t *testing.T) {
i := float64(85) / 100 i := float64(85) / 100
fmt.Println(i) 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)
}