From 52e10035a8999316558a0719d7d8022478cb491f Mon Sep 17 00:00:00 2001 From: howell <2827207845@qq.com> Date: Thu, 31 Mar 2022 16:15:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A0=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/mobile/goods/detail.go | 4 +-- .../api/mobile/order_preview/normal_create.go | 3 +- .../order_preview/shopping_trolley_create.go | 1 + internal/model/order/goods_detail.go | 31 +++++++++++-------- internal/model/order/info.go | 1 + internal/model/order_preview/goods_detail.go | 1 + internal/service/app/shop/benefit.go | 12 +++++-- .../v2/model/recook/goods/recookGoodsSku.go | 10 ++++-- .../recook/order/recookOrderGoodsDetail.go | 4 +++ 9 files changed, 46 insertions(+), 21 deletions(-) diff --git a/internal/api/mobile/goods/detail.go b/internal/api/mobile/goods/detail.go index fbaa1fa..95ef4d0 100644 --- a/internal/api/mobile/goods/detail.go +++ b/internal/api/mobile/goods/detail.go @@ -298,7 +298,7 @@ func QueryGoodsDetailNew(c *gin.Context) { var minAllPrice goods.AllPrice selectMinPriceStr := "MIN(original_price) AS original_price, " + "MIN(discount_price) AS discount_price, " + - "MIN(ROUND(discount_price-purchase_price*1.03, 2)) AS commission, " + + "MIN(ROUND(discount_price-IF(extra_price=0,purchase_price*1.03,purchase_price+ extra_price), 2)) AS commission, " + "MIN(purchase_price) AS purchase_price, " + "MIN(min_num) AS min_num, " + "MIN(limit_num) AS limit_num, " + @@ -311,7 +311,7 @@ func QueryGoodsDetailNew(c *gin.Context) { var maxAllPrice goods.AllPrice selectMaxPriceStr := "MAX(original_price) AS original_price, " + "MAX(discount_price) AS discount_price, " + - "MAX(ROUND(discount_price-purchase_price*1.03, 2)) AS commission, " + + "MAX(ROUND(discount_price-IF(extra_price=0,purchase_price*1.03,purchase_price+ extra_price), 2)) AS commission, " + "MAX(purchase_price) AS purchase_price, " + "MAX(min_num) AS min_num, " + "MAX(limit_num) AS limit_num, " + diff --git a/internal/api/mobile/order_preview/normal_create.go b/internal/api/mobile/order_preview/normal_create.go index a655ca2..d6fb592 100755 --- a/internal/api/mobile/order_preview/normal_create.go +++ b/internal/api/mobile/order_preview/normal_create.go @@ -397,7 +397,8 @@ func CreatePreviewNormalOrder(c *gin.Context) { preOrderGoods.IsImport = goodsInfo.IsImport preOrderGoods.Storehouse = goodsInfo.Storehouse preOrderGoods.IsFerme = goodsInfo.IsFerme - preOrderInfo.IsVirtual = gs.IsVirtual + preOrderGoods.IsVirtual = gs.IsVirtual + preOrderGoods.ExtraPrice = sku.ExtraPrice err = tx.Create(&preOrderGoods).Error if err != nil { diff --git a/internal/api/mobile/order_preview/shopping_trolley_create.go b/internal/api/mobile/order_preview/shopping_trolley_create.go index ac64b84..161c57a 100755 --- a/internal/api/mobile/order_preview/shopping_trolley_create.go +++ b/internal/api/mobile/order_preview/shopping_trolley_create.go @@ -235,6 +235,7 @@ func CreatePreviewShoppingTrolleyOrder(c *gin.Context) { IsFerme: goodsInfo.IsFerme, CoinAmount: coinAmount, ActualAmount: goodsAmount.Sub(coinAmount), + ExtraPrice: sku.ExtraPrice, } preOrderGoodsList = append(preOrderGoodsList, &one) goodsTotalAmount = goodsTotalAmount.Add(one.GoodsAmount) diff --git a/internal/model/order/goods_detail.go b/internal/model/order/goods_detail.go index ddfde0a..a2504f6 100755 --- a/internal/model/order/goods_detail.go +++ b/internal/model/order/goods_detail.go @@ -64,19 +64,20 @@ type GoodsDetail struct { IsClosed int `gorm:"is_closed" json:"isClosed"` RStatus string `gorm:"-" json:"rStatus"` DetailInfo string - Bill int `gorm:"bill" json:"bill"` //是否开发票0代表未开1处理中2已成功3失败 - Fpqqlsh string `gorm:"fpqqlsh" json:"fpqqlsh"` //流水号 - IsExport int `gorm:"is_export" json:"is_export"` //舶茂的是否导出 - BomaoNo string `gorm:"bomao_no" json:"bomao_no"` //舶茂的订单编号 - EvaluatedId int `gorm:"evaluated_id" json:"evaluated_id"` //评价id - ReportMsg string `gorm:"report_msg" json:"reportMsg"` - Report int `gorm:"report" json:"report"` - IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品 - Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库 - IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税 - ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"` - ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id - MakeUpStatus uint `json:"make_up_status"` + Bill int `gorm:"bill" json:"bill"` //是否开发票0代表未开1处理中2已成功3失败 + Fpqqlsh string `gorm:"fpqqlsh" json:"fpqqlsh"` //流水号 + IsExport int `gorm:"is_export" json:"is_export"` //舶茂的是否导出 + BomaoNo string `gorm:"bomao_no" json:"bomao_no"` //舶茂的订单编号 + EvaluatedId int `gorm:"evaluated_id" json:"evaluated_id"` //评价id + ReportMsg string `gorm:"report_msg" json:"reportMsg"` + Report int `gorm:"report" json:"report"` + IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品 + Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库 + IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税 + ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"` + ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id + MakeUpStatus uint `json:"make_up_status"` + ExtraPrice decimal.Decimal `json:"-"` } // TableName sets the insert table name for this struct type @@ -86,6 +87,9 @@ func (r *GoodsDetail) TableName() string { func (r *GoodsDetail) GetBase() decimal.Decimal { cost := r.PurchasePrice.Mul(decimal.NewFromFloat(1.03)) + if !r.ExtraPrice.IsZero() { + cost = r.PurchasePrice.Add(r.ExtraPrice) + } base := r.UnitPrice.Sub(cost).Mul(decimal.NewFromFloat32(define.Coefficient)) return base.Round(2) } @@ -157,6 +161,7 @@ func (*GoodsDetail) Reflect(r *order_preview.GoodsDetail, o *Information) *Goods IsImport: r.IsImport, Storehouse: r.Storehouse, IsFerme: r.IsFerme, + ExtraPrice: r.ExtraPrice, } } diff --git a/internal/model/order/info.go b/internal/model/order/info.go index ac9bfaa..f2549b5 100755 --- a/internal/model/order/info.go +++ b/internal/model/order/info.go @@ -101,5 +101,6 @@ func (*Information) Reflect(r *order_preview.Information) *Information { Cost: r.Cost, OrderType: r.OrderType, IsSplit: r.IsVirtual, + } } diff --git a/internal/model/order_preview/goods_detail.go b/internal/model/order_preview/goods_detail.go index 7835aac..33db2a9 100755 --- a/internal/model/order_preview/goods_detail.go +++ b/internal/model/order_preview/goods_detail.go @@ -42,6 +42,7 @@ type GoodsDetail struct { Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库 IsFerme int `gorm:"column:is_ferme" json:"isFerme"` IsVirtual bool `gorm:"column:is_virtual" json:"is_virtual"` // 是否虚拟订单 + ExtraPrice decimal.Decimal `json:"-"` } // TableName sets the insert table name for this struct type diff --git a/internal/service/app/shop/benefit.go b/internal/service/app/shop/benefit.go index 2ae788b..0a07ecf 100644 --- a/internal/service/app/shop/benefit.go +++ b/internal/service/app/shop/benefit.go @@ -27,9 +27,11 @@ func OrderProfit(od order.Information, tx *gorm.DB) error { case 1: // 零售收益 switch u1.Level { case 0: - // 会员买 if condition { - // 自购平台100% + // 消费者自购相当于公司分享 + if err := tx.Create(order.CreateProfit(u1.RootID, order.Share, base, od.ID)).Error; err != nil { + return err + } return nil } else if s1.Level != 0 { if s1.Level == 10 { @@ -123,7 +125,11 @@ func OrderProfit(od order.Information, tx *gorm.DB) error { // 实体店产生批发收益给子公司 extraBase := decimal.Zero for _, v := range ods { - extra := v.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2).Mul(decimal.NewFromFloat(0.2)).Round(2) + cost := v.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2) + if !v.ExtraPrice.IsZero() { + cost = v.PurchasePrice.Add(v.ExtraPrice).Round(2) + } + extra := cost.Mul(decimal.NewFromFloat(0.2)).Round(2) extraBase = extraBase.Add(extra.Mul(decimal.NewFromFloat(define.Coefficient)).Round(2).Mul(decimal.NewFromInt(int64(v.Quantity)))) } if err := tx.Create(order.CreateProfit(u1.RootID, order.Sale, base, od.ID)).Error; err != nil { diff --git a/internal/v2/model/recook/goods/recookGoodsSku.go b/internal/v2/model/recook/goods/recookGoodsSku.go index 373e2b2..40d865f 100644 --- a/internal/v2/model/recook/goods/recookGoodsSku.go +++ b/internal/v2/model/recook/goods/recookGoodsSku.go @@ -65,10 +65,16 @@ func (r *RecookGoodsSkuModel) GetSalePrice(level int) decimal.Decimal { return decimal.Zero } if level == 10 { + if !r.SaleExtraPrice.IsZero() { + return r.SaleExtraPrice.Add(r.SaleExtraPrice) + } return r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2) } - s1 := r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2).Mul(decimal.NewFromFloat(1.2)).Round(2) - // s1 = s1.Add(r.DiscountPrice.Sub(r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03))).Mul(decimal.NewFromFloat(0.2)).Round(2)) + cost := r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)) + if !r.SaleExtraPrice.IsZero() { + cost = r.SaleExtraPrice.Add(r.SaleExtraPrice) + } + s1 := cost.Round(2).Mul(decimal.NewFromFloat(1.2)).Round(2) return s1.Round(2) } diff --git a/internal/v2/model/recook/order/recookOrderGoodsDetail.go b/internal/v2/model/recook/order/recookOrderGoodsDetail.go index 79181b3..7eeba6b 100644 --- a/internal/v2/model/recook/order/recookOrderGoodsDetail.go +++ b/internal/v2/model/recook/order/recookOrderGoodsDetail.go @@ -118,6 +118,7 @@ type RecookOrderGoodsDetailModel struct { ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"` ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id MakeUpStatus uint `json:"make_up_status"` + ExtraPrice decimal.Decimal `json:"-"` } // TableName sets the insert table name for this struct type @@ -150,6 +151,9 @@ func (r *RecookOrderGoodsDetailModel) GetSelfProfit(level int) decimal.Decimal { func (r *RecookOrderGoodsDetailModel) GetBase() decimal.Decimal { cost := r.PurchasePrice.Mul(decimal.NewFromFloat(1.03)) + if !r.ExtraPrice.IsZero() { + cost = r.PurchasePrice.Add(r.ExtraPrice) + } base := r.UnitPrice.Sub(cost).Mul(decimal.NewFromFloat32(define.Coefficient)) return base.Round(2) }