fix
This commit is contained in:
parent
42bd585fe9
commit
d07350969f
|
@ -11,4 +11,22 @@ type Config struct {
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
ReplicaId uint64
|
ReplicaId uint64
|
||||||
|
AWS struct {
|
||||||
|
S3 struct {
|
||||||
|
Credentials struct {
|
||||||
|
AccessKeyID string
|
||||||
|
Secret string
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BLMService struct {
|
||||||
|
Url string
|
||||||
|
LogoCombine struct {
|
||||||
|
Url string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Unity struct {
|
||||||
|
Host string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/step_price"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -65,9 +64,11 @@ func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateP
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model info")
|
||||||
}
|
}
|
||||||
var stepPrice gmodel.StepPriceJsonStruct
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
if modelInfo.StepPrice != nil && len(*modelInfo.StepPrice) != 0 {
|
||||||
logx.Error(err)
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price")
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//配件
|
//配件
|
||||||
fittingPrice := int64(0)
|
fittingPrice := int64(0)
|
||||||
|
@ -82,7 +83,7 @@ func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateP
|
||||||
}
|
}
|
||||||
fittingPrice = *fittingInfo.Price
|
fittingPrice = *fittingInfo.Price
|
||||||
}
|
}
|
||||||
totalPrice, itemPrice, err := step_price.GetNewCentStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
|
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to calculate product price ")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to calculate product price ")
|
||||||
|
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/server/product/internal/config"
|
"fusenapi/server/product/internal/config"
|
||||||
"fusenapi/shared"
|
"fusenapi/shared"
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
|
@ -18,15 +21,28 @@ type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
SharedState *shared.SharedState
|
SharedState *shared.SharedState
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
AllModels *gmodel.AllModelsGen
|
AllModels *gmodel.AllModelsGen
|
||||||
|
Repositories *initalize.Repositories
|
||||||
|
AwsSession *session.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
conn := initalize.InitMysql(c.SourceMysql)
|
||||||
|
config := aws.Config{
|
||||||
|
Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token),
|
||||||
|
}
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||||
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
|
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||||
|
GormDB: conn,
|
||||||
|
BLMServiceUrl: &c.BLMService.Url,
|
||||||
|
AwsSession: session.Must(session.NewSession(&config)),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,8 +98,11 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var stepPrice gmodel.StepPriceJsonStruct
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
if modelInfo.StepPrice != nil && len(*modelInfo.StepPrice) != 0 {
|
||||||
return err
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//请求的数量
|
//请求的数量
|
||||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
||||||
|
|
|
@ -104,9 +104,11 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s model info is not exists:%d_%d", *cart.ProductId, *cart.SizeId))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s model info is not exists:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||||
}
|
}
|
||||||
var stepPrice gmodel.StepPriceJsonStruct
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
if modelInfo.StepPrice != nil && len(*modelInfo.StepPrice) != 0 {
|
||||||
logx.Error(err)
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse model step price:%d", *cart.ModelId))
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse model step price:%d", *cart.ModelId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//购买数量步进量
|
//购买数量步进量
|
||||||
stepPurchaseQuantity := *modelInfo.PackedUnit
|
stepPurchaseQuantity := *modelInfo.PackedUnit
|
||||||
|
|
|
@ -843,7 +843,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
}
|
}
|
||||||
|
|
||||||
var stepPriceJson gmodel.StepPriceJsonStruct
|
var stepPriceJson gmodel.StepPriceJsonStruct
|
||||||
if shoppingCartProductModel3d.StepPrice != nil {
|
if shoppingCartProductModel3d.StepPrice != nil && len(*shoppingCartProductModel3d.StepPrice) != 0 {
|
||||||
json.Unmarshal(*shoppingCartProductModel3d.StepPrice, &shoppingCartProductModel3d.StepPrice)
|
json.Unmarshal(*shoppingCartProductModel3d.StepPrice, &shoppingCartProductModel3d.StepPrice)
|
||||||
} else {
|
} else {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package step_price
|
package step_price
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 旧的返回厘(即将废弃)
|
// 旧的返回厘(即将废弃)
|
||||||
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||||
|
@ -20,47 +15,3 @@ func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||||
}
|
}
|
||||||
return int64(stepPrice[len(stepPrice)-1])
|
return int64(stepPrice[len(stepPrice)-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新的阶梯价格(返回美元)
|
|
||||||
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice float64, err error) {
|
|
||||||
l := len(stepPrice.PriceRange)
|
|
||||||
if l == 0 {
|
|
||||||
return 0, 0, errors.New("price range is not set")
|
|
||||||
}
|
|
||||||
//遍历查询合适的价格
|
|
||||||
for k, v := range stepPrice.PriceRange {
|
|
||||||
//购买数量>起点
|
|
||||||
if purchaseQuantity > v.StartQuantity {
|
|
||||||
//最后一个 || 小于等于终点
|
|
||||||
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
|
||||||
itemPrice = float64(v.Price+fittingPrice) / 1000
|
|
||||||
return itemPrice * float64(purchaseQuantity), itemPrice / 1000, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//遍历里面没有则返回第一个
|
|
||||||
itemPrice = float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000
|
|
||||||
return itemPrice * float64(purchaseQuantity), itemPrice, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新的阶梯价格(返回厘)
|
|
||||||
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice int64, err error) {
|
|
||||||
l := len(stepPrice.PriceRange)
|
|
||||||
if l == 0 {
|
|
||||||
return 0, 0, errors.New("price range is not set")
|
|
||||||
}
|
|
||||||
//遍历查询合适的价格
|
|
||||||
for k, v := range stepPrice.PriceRange {
|
|
||||||
//购买数量>起点
|
|
||||||
if purchaseQuantity > v.StartQuantity {
|
|
||||||
//最后一个 || 小于等于终点
|
|
||||||
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
|
||||||
itemPrice = v.Price + fittingPrice
|
|
||||||
return itemPrice * purchaseQuantity, itemPrice, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//遍历里面没有则返回第一个
|
|
||||||
itemPrice = stepPrice.PriceRange[0].Price + fittingPrice
|
|
||||||
return itemPrice * purchaseQuantity, itemPrice, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user