This commit is contained in:
yan.y 2024-07-08 14:38:21 +08:00
parent 8729de390f
commit 65ec2c5dde
4 changed files with 60 additions and 43 deletions

View File

@ -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))

View File

@ -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"
@ -63,7 +64,7 @@ func (p DefParty) carServiceOrderList() web_iris.Party {
type CarServiceProcessRequest struct {
Type int //操作类型 1开始 2结束
SubOrderId string //子订单ID
PayAmount int //实际支付金额
PayAmount float64 //实际支付金额
PayRemark string //支付备注
FileName string //拍照文件
}
@ -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,6 +159,7 @@ func (p DefParty) carServiceProcess() web_iris.Party {
"Amount": orderUserInfo.Amount,
}
database.Instance().Model(&orderUserInfo).Updates(&updateValues)
if amount > 0 {
userAmountRecord := models.UserAmountRecord{
UserId: orderUserInfo.Id,
Type: recordType,
@ -167,6 +172,7 @@ func (p DefParty) carServiceProcess() web_iris.Party {
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
}
}
subOrderInfo.PayTime = time.Now()
subOrderInfo.PayStatus = 1

View File

@ -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)

View File

@ -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)
}