diff --git a/business/api/auth.go b/business/api/auth.go index aa45d37..e6b6064 100644 --- a/business/api/auth.go +++ b/business/api/auth.go @@ -80,6 +80,7 @@ func (p DefParty) login() web_iris.Party { UserType: 0, Mobile: "", Role: 0, + Status: 1, } err := database.Instance().Create(&newUser).Error zap_server.ZAPLOG.Info("create", zap.Any("err", err)) diff --git a/business/api/car.go b/business/api/car.go index e3c345c..a0e17cb 100644 --- a/business/api/car.go +++ b/business/api/car.go @@ -7,6 +7,7 @@ import ( "gorm.io/gorm/clause" "io" "pet-house.com/business/models" + "pet-house.com/business/utils" "pet-house.com/core/server/database" "pet-house.com/core/server/web/web_iris" "time" @@ -61,11 +62,11 @@ func (p DefParty) carServiceOrderList() web_iris.Party { } type CarServiceProcessRequest struct { - Type int //操作类型 1开始 2结束 - SubOrderId string //子订单ID - PayAmount int //实际支付金额 - PayRemark string //支付备注 - FileName string //拍照文件 + Type int //操作类型 1开始 2结束 + SubOrderId string //子订单ID + PayAmount float64 //实际支付金额 + PayRemark string //支付备注 + FileName string //拍照文件 } type CarServiceProcessResponse struct { @@ -124,18 +125,21 @@ func (p DefParty) carServiceProcess() web_iris.Party { var orderUserInfo *models.User database.Instance().Model(&models.User{}).Where("id = ?", mainOrder.Uid).Find(&orderUserInfo) - if carServiceProcessRequest.PayAmount > 0 && subOrderInfo.TotalAmount != carServiceProcessRequest.PayAmount { + var processPayAmount = carServiceProcessRequest.PayAmount + var originTotalAmount = float64(subOrderInfo.TotalAmount) + if processPayAmount > 0 && originTotalAmount != processPayAmount { //原价 originAmount := subOrderInfo.PayAmount userOriginAmount := orderUserInfo.Amount - mainOrder.TotalAmount = mainOrder.TotalAmount - subOrderInfo.TotalAmount + carServiceProcessRequest.PayAmount - if mainOrder.PayTotalAmount > 0 && subOrderInfo.TotalAmount != carServiceProcessRequest.PayAmount { - mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + carServiceProcessRequest.PayAmount*10 + p := int(utils.RoundToOneDecimalPlace(processPayAmount)) + p1 := int(processPayAmount * 10) + mainOrder.TotalAmount = mainOrder.TotalAmount - subOrderInfo.TotalAmount + p + if mainOrder.PayTotalAmount > 0 && originTotalAmount != processPayAmount { + mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + p1 } - subOrderInfo.TotalAmount = carServiceProcessRequest.PayAmount - subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount + subOrderInfo.TotalAmount = p + subOrderInfo.PayAmount = p1 if mainOrder.PayStatus == 1 { - subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount * 10 recordType := 2 amount := 0 //新价格大于原价格 加回差价 @@ -155,17 +159,19 @@ func (p DefParty) carServiceProcess() web_iris.Party { "Amount": orderUserInfo.Amount, } database.Instance().Model(&orderUserInfo).Updates(&updateValues) - userAmountRecord := models.UserAmountRecord{ - UserId: orderUserInfo.Id, - Type: recordType, - OriginAmount: userOriginAmount, - ProAmount: amount, - CurrAmount: orderUserInfo.Amount, - OrderId: mainOrder.OrderId, - ProScene: "修改订单金额", - Status: 1, + if amount > 0 { + userAmountRecord := models.UserAmountRecord{ + UserId: orderUserInfo.Id, + Type: recordType, + OriginAmount: userOriginAmount, + ProAmount: amount, + CurrAmount: orderUserInfo.Amount, + OrderId: mainOrder.OrderId, + ProScene: "修改订单金额", + Status: 1, + } + database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord) } - database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord) } subOrderInfo.PayTime = time.Now() subOrderInfo.PayStatus = 1 diff --git a/business/api/order.go b/business/api/order.go index 96f9e23..a08139b 100644 --- a/business/api/order.go +++ b/business/api/order.go @@ -696,26 +696,28 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { } var orderMain models.OrderMain database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", orderSub.MainOrderId).Find(&orderMain) - var totalAmount = 0 + var nowOrderTotalAmount = 0 var projectionServiceTime = 0 for _, value := range orderGoodsUpdateRequest.GoodsIds { goods := GoodsMap[value] - totalAmount = totalAmount + goods.Price + nowOrderTotalAmount = nowOrderTotalAmount + goods.Price if goods.Time != "/" && len(goods.Time) > 0 { goodsTime, _ := strconv.Atoi(goods.Time) projectionServiceTime += goodsTime } } - var originOrderAmount = orderSub.PayAmount + var originOrderPayAmount = orderSub.PayAmount + var originOrderTotalAmount = orderSub.TotalAmount //非当前订单 var orderSubList []models.OrderSub database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and order_id != ?", orderMain.OrderId, orderGoodsUpdateRequest.OrderId).Find(&orderSubList) - //新价格 - var newAmount = totalAmount + + var newTotalAmount = nowOrderTotalAmount + var subOrderAmount = nowOrderTotalAmount var allProjectionServiceTime = projectionServiceTime for _, value := range orderSubList { - newAmount = newAmount + value.TotalAmount + newTotalAmount = newTotalAmount + value.TotalAmount allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime } @@ -724,37 +726,44 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { 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 + var originAmount = userInfo.Amount + //先退还 当前订单 + userInfo.Amount = userInfo.Amount + orderSub.PayAmount if userInfo.Discount > 0 { discount := float64(userInfo.Discount) - newAmount = int(utils.RoundToOneDecimalPlace(float64(newAmount)*(discount/100.0)) * 10) + subOrderAmount = int(utils.RoundToOneDecimalPlace(float64(subOrderAmount)*(discount/100.0)) * 10) } + orderMain.PayTotalAmount = orderMain.PayTotalAmount - originOrderPayAmount + subOrderAmount + orderMain.TotalAmount = orderMain.TotalAmount - originOrderTotalAmount + nowOrderTotalAmount + //余额不足 - 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)+";修改服务项目后余额不足,请充值后再支付") + if userInfo.Amount < subOrderAmount { + OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付") return } var amountType = 2 var proAmount = 0 //原始价格小于新价格 扣,原始价格大于新价格 加 - if originOrderAmount < newAmount { - proAmount = newAmount - originOrderAmount + if originOrderPayAmount < subOrderAmount { } else { amountType = 1 - proAmount = originOrderAmount - newAmount } - var originAmount = userInfo.Amount var preAmount = orderMain.PayTotalAmount - userInfo.Amount = userInfo.Amount - newAmount - orderMain.PayTotalAmount = newAmount + userInfo.Amount = userInfo.Amount - subOrderAmount updateValues := map[string]interface{}{ "Amount": userInfo.Amount, } database.Instance().Model(&userInfo).Updates(&updateValues) + + if amountType == 1 { + proAmount = userInfo.Amount - originAmount + } else { + proAmount = originAmount - userInfo.Amount + } + orderMain.PayDiscount = userInfo.Discount userAmountRecord := models.UserAmountRecord{ UserId: userInfo.Id, @@ -782,8 +791,8 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail) } - orderSub.TotalAmount = totalAmount - orderSub.PayAmount = newAmount + orderSub.TotalAmount = nowOrderTotalAmount + orderSub.PayAmount = subOrderAmount orderSub.ProjectionServiceTime = projectionServiceTime updateValues := map[string]interface{}{ "TotalAmount": orderSub.TotalAmount, @@ -793,6 +802,7 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party { orderMain.ProjectionServiceTime = allProjectionServiceTime updateValues1 := map[string]interface{}{ "PayTotalAmount": orderMain.PayTotalAmount, + "TotalAmount": orderMain.TotalAmount, "ProjectionServiceTime": orderMain.ProjectionServiceTime, } database.Instance().Model(&orderMain).Updates(&updateValues1) diff --git a/business/utils/commonUtil_test.go b/business/utils/commonUtil_test.go index 308d446..b7e4c32 100644 --- a/business/utils/commonUtil_test.go +++ b/business/utils/commonUtil_test.go @@ -51,6 +51,6 @@ func TestCalc5(t *testing.T) { fmt.Printf(float) } func TestMath(t *testing.T) { - i := int(float64(256) * (85 / 100.0) * 10) - fmt.Println(i) + var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10) + fmt.Println(a) }