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, UserType: 0,
Mobile: "", Mobile: "",
Role: 0, Role: 0,
Status: 1,
} }
err := database.Instance().Create(&newUser).Error err := database.Instance().Create(&newUser).Error
zap_server.ZAPLOG.Info("create", zap.Any("err", err)) zap_server.ZAPLOG.Info("create", zap.Any("err", err))

View File

@ -7,6 +7,7 @@ import (
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"io" "io"
"pet-house.com/business/models" "pet-house.com/business/models"
"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"
"time" "time"
@ -61,11 +62,11 @@ func (p DefParty) carServiceOrderList() web_iris.Party {
} }
type CarServiceProcessRequest struct { type CarServiceProcessRequest struct {
Type int //操作类型 1开始 2结束 Type int //操作类型 1开始 2结束
SubOrderId string //子订单ID SubOrderId string //子订单ID
PayAmount int //实际支付金额 PayAmount float64 //实际支付金额
PayRemark string //支付备注 PayRemark string //支付备注
FileName string //拍照文件 FileName string //拍照文件
} }
type CarServiceProcessResponse struct { type CarServiceProcessResponse struct {
@ -124,18 +125,21 @@ func (p DefParty) carServiceProcess() web_iris.Party {
var orderUserInfo *models.User var orderUserInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", mainOrder.Uid).Find(&orderUserInfo) 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 originAmount := subOrderInfo.PayAmount
userOriginAmount := orderUserInfo.Amount userOriginAmount := orderUserInfo.Amount
mainOrder.TotalAmount = mainOrder.TotalAmount - subOrderInfo.TotalAmount + carServiceProcessRequest.PayAmount p := int(utils.RoundToOneDecimalPlace(processPayAmount))
if mainOrder.PayTotalAmount > 0 && subOrderInfo.TotalAmount != carServiceProcessRequest.PayAmount { p1 := int(processPayAmount * 10)
mainOrder.PayTotalAmount = mainOrder.PayTotalAmount - originAmount + carServiceProcessRequest.PayAmount*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.TotalAmount = p
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount subOrderInfo.PayAmount = p1
if mainOrder.PayStatus == 1 { if mainOrder.PayStatus == 1 {
subOrderInfo.PayAmount = carServiceProcessRequest.PayAmount * 10
recordType := 2 recordType := 2
amount := 0 amount := 0
//新价格大于原价格 加回差价 //新价格大于原价格 加回差价
@ -155,17 +159,19 @@ func (p DefParty) carServiceProcess() web_iris.Party {
"Amount": orderUserInfo.Amount, "Amount": orderUserInfo.Amount,
} }
database.Instance().Model(&orderUserInfo).Updates(&updateValues) database.Instance().Model(&orderUserInfo).Updates(&updateValues)
userAmountRecord := models.UserAmountRecord{ if amount > 0 {
UserId: orderUserInfo.Id, userAmountRecord := models.UserAmountRecord{
Type: recordType, UserId: orderUserInfo.Id,
OriginAmount: userOriginAmount, Type: recordType,
ProAmount: amount, OriginAmount: userOriginAmount,
CurrAmount: orderUserInfo.Amount, ProAmount: amount,
OrderId: mainOrder.OrderId, CurrAmount: orderUserInfo.Amount,
ProScene: "修改订单金额", OrderId: mainOrder.OrderId,
Status: 1, ProScene: "修改订单金额",
Status: 1,
}
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
} }
database.Instance().Model(&models.UserAmountRecord{}).Create(&userAmountRecord)
} }
subOrderInfo.PayTime = time.Now() subOrderInfo.PayTime = time.Now()
subOrderInfo.PayStatus = 1 subOrderInfo.PayStatus = 1

View File

@ -696,26 +696,28 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
} }
var orderMain models.OrderMain var orderMain models.OrderMain
database.Instance().Model(&models.OrderMain{}).Where("order_id = ? and status = 1", orderSub.MainOrderId).Find(&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 var projectionServiceTime = 0
for _, value := range orderGoodsUpdateRequest.GoodsIds { for _, value := range orderGoodsUpdateRequest.GoodsIds {
goods := GoodsMap[value] goods := GoodsMap[value]
totalAmount = totalAmount + goods.Price nowOrderTotalAmount = nowOrderTotalAmount + goods.Price
if goods.Time != "/" && len(goods.Time) > 0 { if goods.Time != "/" && len(goods.Time) > 0 {
goodsTime, _ := strconv.Atoi(goods.Time) goodsTime, _ := strconv.Atoi(goods.Time)
projectionServiceTime += goodsTime projectionServiceTime += goodsTime
} }
} }
var originOrderAmount = orderSub.PayAmount var originOrderPayAmount = orderSub.PayAmount
var originOrderTotalAmount = orderSub.TotalAmount
//非当前订单 //非当前订单
var orderSubList []models.OrderSub var orderSubList []models.OrderSub
database.Instance().Model(&models.OrderSub{}).Where("main_order_id = ? and order_id != ?", orderMain.OrderId, orderGoodsUpdateRequest.OrderId).Find(&orderSubList) 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 var allProjectionServiceTime = projectionServiceTime
for _, value := range orderSubList { for _, value := range orderSubList {
newAmount = newAmount + value.TotalAmount newTotalAmount = newTotalAmount + value.TotalAmount
allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime allProjectionServiceTime = allProjectionServiceTime + value.ProjectionServiceTime
} }
@ -724,37 +726,44 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
if orderMain.PayType == 3 { if orderMain.PayType == 3 {
var userInfo *models.User var userInfo *models.User
database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo) database.Instance().Model(&models.User{}).Where("id = ?", orderMain.Uid).Find(&userInfo)
//先退还 var originAmount = userInfo.Amount
userInfo.Amount = userInfo.Amount + orderMain.PayTotalAmount //先退还 当前订单
userInfo.Amount = userInfo.Amount + orderSub.PayAmount
if userInfo.Discount > 0 { if userInfo.Discount > 0 {
discount := float64(userInfo.Discount) 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 { if userInfo.Amount < subOrderAmount {
OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(newAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付") OrderUpdateBalanceNotEnough.DefFail(ctx, orderGoodsUpdateRequest, "原订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+" 修改后订单金额:"+strconv.FormatFloat(float64(orderMain.PayTotalAmount)/10, 'f', 1, 64)+";修改服务项目后余额不足,请充值后再支付")
return return
} }
var amountType = 2 var amountType = 2
var proAmount = 0 var proAmount = 0
//原始价格小于新价格 扣,原始价格大于新价格 加 //原始价格小于新价格 扣,原始价格大于新价格 加
if originOrderAmount < newAmount { if originOrderPayAmount < subOrderAmount {
proAmount = newAmount - originOrderAmount
} else { } else {
amountType = 1 amountType = 1
proAmount = originOrderAmount - newAmount
} }
var originAmount = userInfo.Amount
var preAmount = orderMain.PayTotalAmount var preAmount = orderMain.PayTotalAmount
userInfo.Amount = userInfo.Amount - newAmount userInfo.Amount = userInfo.Amount - subOrderAmount
orderMain.PayTotalAmount = newAmount
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"Amount": userInfo.Amount, "Amount": userInfo.Amount,
} }
database.Instance().Model(&userInfo).Updates(&updateValues) database.Instance().Model(&userInfo).Updates(&updateValues)
if amountType == 1 {
proAmount = userInfo.Amount - originAmount
} else {
proAmount = originAmount - userInfo.Amount
}
orderMain.PayDiscount = userInfo.Discount orderMain.PayDiscount = userInfo.Discount
userAmountRecord := models.UserAmountRecord{ userAmountRecord := models.UserAmountRecord{
UserId: userInfo.Id, UserId: userInfo.Id,
@ -782,8 +791,8 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail) database.Instance().Model(&models.OrderDetail{}).Create(&orderDetail)
} }
orderSub.TotalAmount = totalAmount orderSub.TotalAmount = nowOrderTotalAmount
orderSub.PayAmount = newAmount orderSub.PayAmount = subOrderAmount
orderSub.ProjectionServiceTime = projectionServiceTime orderSub.ProjectionServiceTime = projectionServiceTime
updateValues := map[string]interface{}{ updateValues := map[string]interface{}{
"TotalAmount": orderSub.TotalAmount, "TotalAmount": orderSub.TotalAmount,
@ -793,6 +802,7 @@ func (p DefParty) orderGoodsUpdate() web_iris.Party {
orderMain.ProjectionServiceTime = allProjectionServiceTime orderMain.ProjectionServiceTime = allProjectionServiceTime
updateValues1 := map[string]interface{}{ updateValues1 := map[string]interface{}{
"PayTotalAmount": orderMain.PayTotalAmount, "PayTotalAmount": orderMain.PayTotalAmount,
"TotalAmount": orderMain.TotalAmount,
"ProjectionServiceTime": orderMain.ProjectionServiceTime, "ProjectionServiceTime": orderMain.ProjectionServiceTime,
} }
database.Instance().Model(&orderMain).Updates(&updateValues1) database.Instance().Model(&orderMain).Updates(&updateValues1)

View File

@ -51,6 +51,6 @@ func TestCalc5(t *testing.T) {
fmt.Printf(float) fmt.Printf(float)
} }
func TestMath(t *testing.T) { func TestMath(t *testing.T) {
i := int(float64(256) * (85 / 100.0) * 10) var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10)
fmt.Println(i) fmt.Println(a)
} }