Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
93b0cadea9
|
@ -95,23 +95,21 @@ type OrderStatus struct {
|
||||||
|
|
||||||
// 订单商品
|
// 订单商品
|
||||||
type OrderProduct struct {
|
type OrderProduct struct {
|
||||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||||
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
|
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||||
PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量
|
PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量
|
||||||
ProductID int64 `json:"product_id"` // 商品ID
|
ProductID int64 `json:"product_id"` // 商品ID
|
||||||
ProductName string `json:"product_name"` // 商品名称
|
ProductName string `json:"product_name"` // 商品名称
|
||||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||||
ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照
|
ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照
|
||||||
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照
|
||||||
ShoppingCartSnapshotInfo map[string]interface{} `json:"shopping_cart_snapshot_info"` // 商品封面
|
ProductCover string `json:"product_cover"` // 商品封面
|
||||||
ProductCover string `json:"product_cover"` // 商品封面
|
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
||||||
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
ProductSn string `json:"product_sn"` // 商品编码
|
||||||
ProductSn string `json:"product_sn"` // 商品编码
|
DiyInformation *UserDiyInformation `json:"diy_information"`
|
||||||
DiyInformation *UserDiyInformation `json:"diy_information"`
|
SizeInfo *OrderProductSizeInfo `json:"size_info"`
|
||||||
SizeInfo *OrderProductSizeInfo `json:"size_info"`
|
FittingInfo *OrderProductFittingInfo `json:"fitting_info"`
|
||||||
FittingInfo *OrderProductFittingInfo `json:"fitting_info"`
|
IsHighlyCustomized int64 `json:"is_highly_customized"`
|
||||||
StepNum []int `json:"step_num"` // 阶梯数量
|
|
||||||
IsHighlyCustomized int64 `json:"is_highly_customized"`
|
|
||||||
}
|
}
|
||||||
type PurchaseQuantity struct {
|
type PurchaseQuantity struct {
|
||||||
Current interface{} `json:"current"`
|
Current interface{} `json:"current"`
|
||||||
|
|
|
@ -2,6 +2,7 @@ package gmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *FsShoppingCartModel) TableName() string {
|
func (m *FsShoppingCartModel) TableName() string {
|
||||||
|
@ -11,10 +12,26 @@ func (m *FsShoppingCartModel) TableName() string {
|
||||||
// 关联查询
|
// 关联查询
|
||||||
type RelaFsShoppingCart struct {
|
type RelaFsShoppingCart struct {
|
||||||
FsShoppingCart
|
FsShoppingCart
|
||||||
ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"`
|
ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"`
|
||||||
ShoppingCartProductPriceList []*FsProductPrice `json:"shopping_cart_product_price_list" gorm:"foreignkey:product_id;references:product_id"`
|
ShoppingCartProductModel3d *FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:model_id;references:id"`
|
||||||
ShoppingCartProductModel3dList []*FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:product_id;references:product_id"`
|
ShoppingCartProductModel3dFitting *FsProductModel3d `json:"shopping_cart_product_model3d_list_fitting" gorm:"foreignkey:fitting_id;references:id"`
|
||||||
ShoppingCartProductModel3dFitting *FsProductModel3d `json:"shopping_cart_product_model3d_list_fitting" gorm:"foreignkey:fitting_id;references:id"`
|
}
|
||||||
|
type FsShoppingCartData struct {
|
||||||
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||||
|
UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户id
|
||||||
|
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
||||||
|
TemplateId *int64 `gorm:"default:0;" json:"template_id"` // 模板id
|
||||||
|
ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型id
|
||||||
|
SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id
|
||||||
|
LightId *int64 `gorm:"default:0;" json:"light_id"` // 灯光id
|
||||||
|
FittingId *int64 `gorm:"default:0;" json:"fitting_id"` // 配件id
|
||||||
|
PurchaseQuantity *int64 `gorm:"default:0;" json:"purchase_quantity"` // 购买数量
|
||||||
|
Snapshot *map[string]interface{} `gorm:"default:'';" json:"snapshot"` //
|
||||||
|
SnapshotData *string `gorm:"default:'';" json:"snapshot_data"` //
|
||||||
|
IsSelected *int64 `gorm:"default:0;" json:"is_selected"` // 是否被选中 0非 1是
|
||||||
|
IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车)
|
||||||
|
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||||
|
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||||
}
|
}
|
||||||
|
|
||||||
// 快照json数据结构
|
// 快照json数据结构
|
||||||
|
|
|
@ -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)),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/server/shopping-cart/internal/svc"
|
"fusenapi/server/shopping-cart/internal/svc"
|
||||||
"fusenapi/server/shopping-cart/internal/types"
|
"fusenapi/server/shopping-cart/internal/types"
|
||||||
|
@ -53,7 +53,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
//获取购物车列表
|
//获取购物车列表
|
||||||
carts, _, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
carts, _, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||||
Ids: cartIds,
|
Ids: cartIds,
|
||||||
Fields: "id,size_id,product_id,fitting_id",
|
Fields: "id,size_id,product_id,fitting_id,model_id",
|
||||||
UserId: userinfo.UserId,
|
UserId: userinfo.UserId,
|
||||||
Page: 1,
|
Page: 1,
|
||||||
Limit: len(cartIds),
|
Limit: len(cartIds),
|
||||||
|
@ -67,33 +67,24 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
}
|
}
|
||||||
sizeIds := make([]int64, 0, len(carts))
|
sizeIds := make([]int64, 0, len(carts))
|
||||||
productIds := make([]int64, 0, len(carts))
|
productIds := make([]int64, 0, len(carts))
|
||||||
fittingIds := make([]int64, 0, len(carts))
|
modelIds := make([]int64, 0, len(carts)) //模型+配件
|
||||||
for _, v := range carts {
|
for _, v := range carts {
|
||||||
sizeIds = append(sizeIds, *v.SizeId)
|
sizeIds = append(sizeIds, *v.SizeId)
|
||||||
productIds = append(productIds, *v.ProductId)
|
productIds = append(productIds, *v.ProductId)
|
||||||
|
modelIds = append(modelIds, *v.ModelId)
|
||||||
if *v.FittingId > 0 {
|
if *v.FittingId > 0 {
|
||||||
fittingIds = append(fittingIds, *v.FittingId)
|
modelIds = append(modelIds, *v.FittingId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//根据sizeid获取价格列表
|
|
||||||
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get price list")
|
|
||||||
}
|
|
||||||
mapPrice := make(map[string]gmodel.FsProductPrice)
|
|
||||||
for _, v := range priceList {
|
|
||||||
mapPrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
|
||||||
}
|
|
||||||
//获取配件列表(只有id跟价格)
|
//获取配件列表(只有id跟价格)
|
||||||
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsTag(l.ctx, fittingIds, constants.TAG_PARTS, "id,price")
|
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, modelIds, "id,step_price,price")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
|
||||||
}
|
}
|
||||||
mapFitting := make(map[int64]int64)
|
mapModel := make(map[int64]gmodel.FsProductModel3d)
|
||||||
for _, v := range fittingList {
|
for _, v := range modelList {
|
||||||
mapFitting[v.Id] = *v.Price
|
mapModel[v.Id] = v
|
||||||
}
|
}
|
||||||
//开始计算价格
|
//开始计算价格
|
||||||
calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList))
|
calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList))
|
||||||
|
@ -102,9 +93,16 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
shoppingCartModel := gmodel.NewFsShoppingCartModel(tx)
|
shoppingCartModel := gmodel.NewFsShoppingCartModel(tx)
|
||||||
for _, cart := range carts {
|
for _, cart := range carts {
|
||||||
sizePrice, ok := mapPrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
|
modelInfo, ok := mapModel[*cart.ModelId]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New(fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId))
|
return err
|
||||||
|
}
|
||||||
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
|
if modelInfo.StepPrice != nil && len(*modelInfo.StepPrice) != 0 {
|
||||||
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//请求的数量
|
//请求的数量
|
||||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
||||||
|
@ -115,16 +113,15 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
//如果有配件,单价也要加入配件价格
|
//如果有配件,单价也要加入配件价格
|
||||||
fittingPrice := int64(0)
|
fittingPrice := int64(0)
|
||||||
if *cart.FittingId > 0 {
|
if *cart.FittingId > 0 {
|
||||||
if fPrice, ok := mapFitting[*cart.FittingId]; ok {
|
if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||||
fittingPrice = fPrice
|
fittingPrice = *fittingInfo.Price
|
||||||
} else {
|
} else {
|
||||||
return errors.New(fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
return errors.New(fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//计算价格
|
//计算价格
|
||||||
itemPrice, totalPrice, _, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(reqPurchaseQuantity, &sizePrice, fittingPrice)
|
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(reqPurchaseQuantity, stepPrice, fittingPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
calculateResultList = append(calculateResultList, types.CalculateResultItem{
|
calculateResultList = append(calculateResultList, types.CalculateResultItem{
|
||||||
|
@ -149,6 +146,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error())
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{
|
||||||
|
|
|
@ -63,7 +63,6 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
mapSize = make(map[int64]gmodel.FsProductSize)
|
mapSize = make(map[int64]gmodel.FsProductSize)
|
||||||
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
||||||
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
||||||
mapSizePrice = make(map[string]gmodel.FsProductPrice)
|
|
||||||
mapProduct = make(map[int64]gmodel.FsProduct)
|
mapProduct = make(map[int64]gmodel.FsProduct)
|
||||||
mapResourceMetadata = make(map[string]interface{})
|
mapResourceMetadata = make(map[string]interface{})
|
||||||
)
|
)
|
||||||
|
@ -73,7 +72,6 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
MapSize: mapSize,
|
MapSize: mapSize,
|
||||||
MapModel: mapModel,
|
MapModel: mapModel,
|
||||||
MapTemplate: mapTemplate,
|
MapTemplate: mapTemplate,
|
||||||
MapSizePrice: mapSizePrice,
|
|
||||||
MapProduct: mapProduct,
|
MapProduct: mapProduct,
|
||||||
MapResourceMetadata: mapResourceMetadata,
|
MapResourceMetadata: mapResourceMetadata,
|
||||||
})
|
})
|
||||||
|
@ -101,21 +99,34 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
list := make([]types.CartItem, 0, len(carts))
|
list := make([]types.CartItem, 0, len(carts))
|
||||||
for _, cart := range carts {
|
for _, cart := range carts {
|
||||||
snapShot := mapSnapshot[cart.Id]
|
snapShot := mapSnapshot[cart.Id]
|
||||||
sizePrice, ok := mapSizePrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
|
modelInfo, ok := mapModel[*cart.ModelId]
|
||||||
if !ok {
|
if !ok {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price 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
|
||||||
|
if modelInfo.StepPrice != nil && len(*modelInfo.StepPrice) != 0 {
|
||||||
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse model step price:%d", *cart.ModelId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//购买数量步进量
|
||||||
|
stepPurchaseQuantity := *modelInfo.PackedUnit
|
||||||
//如果有配件,单价也要加入配件价格
|
//如果有配件,单价也要加入配件价格
|
||||||
fittingPrice := int64(0)
|
fittingPrice := int64(0)
|
||||||
if *cart.FittingId > 0 {
|
if *cart.FittingId > 0 {
|
||||||
if curFittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
curFittingInfo, ok := mapModel[*cart.FittingId]
|
||||||
fittingPrice = *curFittingInfo.Price
|
if !ok {
|
||||||
} else {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
||||||
}
|
}
|
||||||
|
fittingPrice = *curFittingInfo.Price
|
||||||
|
//取大的为步进量基数
|
||||||
|
if *curFittingInfo.PackedUnit > stepPurchaseQuantity {
|
||||||
|
stepPurchaseQuantity = *curFittingInfo.PackedUnit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//计算价格
|
//计算阶梯价格
|
||||||
itemPrice, totalPrice, _, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice)
|
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(*cart.PurchaseQuantity, stepPrice, fittingPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||||
|
@ -144,6 +155,10 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
productCoverMetadata = metadata
|
productCoverMetadata = metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
templateTag := ""
|
||||||
|
if templateInfo, ok := mapTemplate[*cart.TemplateId]; ok {
|
||||||
|
templateTag = *templateInfo.TemplateTag
|
||||||
|
}
|
||||||
item := types.CartItem{
|
item := types.CartItem{
|
||||||
CartId: cart.Id,
|
CartId: cart.Id,
|
||||||
ProductInfo: types.ProductInfo{
|
ProductInfo: types.ProductInfo{
|
||||||
|
@ -175,10 +190,12 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
Slogan: snapShot.UserDiyInformation.Slogan,
|
Slogan: snapShot.UserDiyInformation.Slogan,
|
||||||
},
|
},
|
||||||
PurchaseQuantity: *cart.PurchaseQuantity,
|
PurchaseQuantity: *cart.PurchaseQuantity,
|
||||||
MinPurchaseQuantity: *sizePrice.EachBoxNum * (*sizePrice.MinBuyNum),
|
MinPurchaseQuantity: stepPrice.MinBuyUnitsNum,
|
||||||
StepPurchaseQuantity: *sizePrice.EachBoxNum,
|
StepPurchaseQuantity: stepPurchaseQuantity,
|
||||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||||
IsSelected: *cart.IsSelected > 0,
|
IsSelected: *cart.IsSelected > 0,
|
||||||
|
TemplateTag: templateTag,
|
||||||
|
Logo: snapShot.Logo,
|
||||||
}
|
}
|
||||||
//是否有失效的
|
//是否有失效的
|
||||||
if description, ok := mapCartChange[cart.Id]; ok {
|
if description, ok := mapCartChange[cart.Id]; ok {
|
||||||
|
@ -206,7 +223,6 @@ type GetRelationInfoReq struct {
|
||||||
MapSize map[int64]gmodel.FsProductSize
|
MapSize map[int64]gmodel.FsProductSize
|
||||||
MapModel map[int64]gmodel.FsProductModel3d
|
MapModel map[int64]gmodel.FsProductModel3d
|
||||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||||
MapSizePrice map[string]gmodel.FsProductPrice
|
|
||||||
MapProduct map[int64]gmodel.FsProduct
|
MapProduct map[int64]gmodel.FsProduct
|
||||||
MapResourceMetadata map[string]interface{}
|
MapResourceMetadata map[string]interface{}
|
||||||
}
|
}
|
||||||
|
@ -274,15 +290,6 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
||||||
for _, v := range templateList {
|
for _, v := range templateList {
|
||||||
req.MapTemplate[v.Id] = v
|
req.MapTemplate[v.Id] = v
|
||||||
}
|
}
|
||||||
//根据sizeid获取价格列表
|
|
||||||
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return errors.New("failed to get cart`s product price list")
|
|
||||||
}
|
|
||||||
for _, v := range priceList {
|
|
||||||
req.MapSizePrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ type CartItem struct {
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
IsSelected bool `json:"is_selected"` //是否选中
|
IsSelected bool `json:"is_selected"` //是否选中
|
||||||
|
TemplateTag string `json:"template_tag"` //模板标签
|
||||||
|
Logo string `json:"logo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductInfo struct {
|
type ProductInfo struct {
|
||||||
|
|
|
@ -70,6 +70,8 @@ type CartItem {
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
IsSelected bool `json:"is_selected"` //是否选中
|
IsSelected bool `json:"is_selected"` //是否选中
|
||||||
|
TemplateTag string `json:"template_tag"` //模板标签
|
||||||
|
Logo string `json:"logo"`
|
||||||
}
|
}
|
||||||
type ProductInfo {
|
type ProductInfo {
|
||||||
ProductId int64 `json:"product_id"` //产品id
|
ProductId int64 `json:"product_id"` //产品id
|
||||||
|
|
|
@ -268,6 +268,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
||||||
StatusTitle: constants.OrderStatusMessage[statusCode],
|
StatusTitle: constants.OrderStatusMessage[statusCode],
|
||||||
}
|
}
|
||||||
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
||||||
|
Ctime: &ntime,
|
||||||
Utime: &ntime,
|
Utime: &ntime,
|
||||||
StatusCode: statusCode,
|
StatusCode: statusCode,
|
||||||
StatusTitle: constants.OrderStatusMessage[statusCode],
|
StatusTitle: constants.OrderStatusMessage[statusCode],
|
||||||
|
@ -342,8 +343,14 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
||||||
Utime: &ntime,
|
Utime: &ntime,
|
||||||
PayTitle: &payTitle,
|
PayTitle: &payTitle,
|
||||||
})
|
})
|
||||||
|
var sql string
|
||||||
|
if *orderInfo.Status == int64(constants.ORDERSTATUSUNPAIDDEPOSIT) {
|
||||||
|
sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d, `status` = %d ", ntime, orderPayStatusCode, statusCode)
|
||||||
|
} else {
|
||||||
|
sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d", ntime, orderPayStatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
// 更新订单信息
|
// 更新订单信息
|
||||||
var sql string = fmt.Sprintf(", `utime` = '%s'", ntime)
|
|
||||||
uOrderDetail["pay_status"] = orderPayStatusCode
|
uOrderDetail["pay_status"] = orderPayStatusCode
|
||||||
uOrderDetail["order_info"] = struct {
|
uOrderDetail["order_info"] = struct {
|
||||||
Utime *time.Time `json:"utime"`
|
Utime *time.Time `json:"utime"`
|
||||||
|
@ -354,6 +361,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
||||||
Status: status,
|
Status: status,
|
||||||
StatusLink: statusLink,
|
StatusLink: statusLink,
|
||||||
}
|
}
|
||||||
|
fmt.Printf("uOrderDetail :%+v", uOrderDetail)
|
||||||
if len(uOrderDetail) > 0 {
|
if len(uOrderDetail) > 0 {
|
||||||
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id)
|
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -739,8 +747,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
resShoppingCartFind := tx.Table(gmodel.NewFsShoppingCartModel(tx).TableName()).
|
resShoppingCartFind := tx.Table(gmodel.NewFsShoppingCartModel(tx).TableName()).
|
||||||
Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB {
|
Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB {
|
||||||
return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource")
|
return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource")
|
||||||
}).Preload("ShoppingCartProductPriceList").
|
}).
|
||||||
Preload("ShoppingCartProductModel3dList").
|
Preload("ShoppingCartProductModel3d").
|
||||||
Preload("ShoppingCartProductModel3dFitting").
|
Preload("ShoppingCartProductModel3dFitting").
|
||||||
Where("id IN ?", in.CartIds).
|
Where("id IN ?", in.CartIds).
|
||||||
Where("user_id = ?", in.UserId).
|
Where("user_id = ?", in.UserId).
|
||||||
|
@ -801,10 +809,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
for _, shoppingCart := range shoppingCartList {
|
for _, shoppingCart := range shoppingCartList {
|
||||||
// 购物车快照
|
// 购物车快照
|
||||||
var shoppingCartSnapshot gmodel.CartSnapshot
|
var shoppingCartSnapshot gmodel.CartSnapshot
|
||||||
// 购物车商品价格
|
|
||||||
var shoppingCartProductPrice *gmodel.FsProductPrice
|
|
||||||
// 购物车商品模型
|
|
||||||
var shoppingCartProductModel3d *gmodel.FsProductModel3d
|
|
||||||
if shoppingCart.Snapshot != nil {
|
if shoppingCart.Snapshot != nil {
|
||||||
json.Unmarshal([]byte(*shoppingCart.Snapshot), &shoppingCartSnapshot)
|
json.Unmarshal([]byte(*shoppingCart.Snapshot), &shoppingCartSnapshot)
|
||||||
}
|
}
|
||||||
|
@ -814,69 +818,21 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
}
|
}
|
||||||
// 商品价格异常
|
|
||||||
if len(shoppingCart.ShoppingCartProductPriceList) == 0 {
|
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
|
||||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
|
||||||
return errors.New(errorCode.Message)
|
|
||||||
} else {
|
|
||||||
var isProductPrice bool
|
|
||||||
for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList {
|
|
||||||
if *shoppingCart.SizeId == *shoppingCartProductPriceInfo.SizeId {
|
|
||||||
shoppingCartProductPrice = shoppingCartProductPriceInfo
|
|
||||||
isProductPrice = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isProductPrice {
|
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
|
||||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
|
||||||
return errors.New(errorCode.Message)
|
|
||||||
}
|
|
||||||
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 商品模型异常
|
var stepPriceJson gmodel.StepPriceJsonStruct
|
||||||
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
|
if shoppingCart.ShoppingCartProductModel3d.StepPrice != nil {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
err = json.Unmarshal(*shoppingCart.ShoppingCartProductModel3d.StepPrice, &stepPriceJson)
|
||||||
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
if err != nil {
|
||||||
return errors.New(errorCode.Message)
|
return err
|
||||||
} else {
|
|
||||||
var isProductModel bool
|
|
||||||
for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList {
|
|
||||||
if *shoppingCart.SizeId == *shoppingCartProductModel3dInfo.SizeId {
|
|
||||||
shoppingCartProductModel3d = shoppingCartProductModel3dInfo
|
|
||||||
isProductModel = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !isProductModel {
|
|
||||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
|
||||||
errorCode.Message = "create order failed, accessory of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
|
||||||
return errors.New(errorCode.Message)
|
|
||||||
}
|
|
||||||
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
|
|
||||||
}
|
|
||||||
|
|
||||||
var stepNum []int
|
|
||||||
var stepPrice []int
|
|
||||||
if *shoppingCartProductPrice.StepNum == "" {
|
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
|
||||||
errorCode.Message = "create order failed, step num of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
|
||||||
return errors.New(errorCode.Message)
|
|
||||||
} else {
|
} else {
|
||||||
json.Unmarshal([]byte(*shoppingCartProductPrice.StepNum), &stepNum)
|
|
||||||
}
|
|
||||||
if *shoppingCartProductPrice.StepPrice == "" {
|
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New("shoppingCartProductModel3d.StepPrice nil")
|
||||||
} else {
|
|
||||||
json.Unmarshal([]byte(*shoppingCartProductPrice.StepPrice), &stepPrice)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 计算价格 */
|
/* 计算价格 */
|
||||||
productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
|
productTotalPrice, productPrice, err := NewShoppingCart(tx, nil, nil).CaculateStepPrice(*shoppingCart.PurchaseQuantity, stepPriceJson, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
||||||
|
@ -892,7 +848,32 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
||||||
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata)
|
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata)
|
||||||
}
|
}
|
||||||
orderProductList = append(orderProductList, gmodel.OrderProduct{
|
snapshot, err := d.OrderDetailSnapshotHandler(ctx, shoppingCart.FsShoppingCart.Snapshot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var shoppingCartSnapshotInter = &gmodel.FsShoppingCartData{
|
||||||
|
Id: shoppingCart.FsShoppingCart.Id,
|
||||||
|
UserId: shoppingCart.FsShoppingCart.UserId,
|
||||||
|
ProductId: shoppingCart.FsShoppingCart.ProductId,
|
||||||
|
TemplateId: shoppingCart.FsShoppingCart.TemplateId,
|
||||||
|
ModelId: shoppingCart.FsShoppingCart.ModelId,
|
||||||
|
SizeId: shoppingCart.FsShoppingCart.SizeId,
|
||||||
|
LightId: shoppingCart.FsShoppingCart.LightId,
|
||||||
|
FittingId: shoppingCart.FsShoppingCart.FittingId,
|
||||||
|
PurchaseQuantity: shoppingCart.FsShoppingCart.PurchaseQuantity,
|
||||||
|
Snapshot: &snapshot,
|
||||||
|
SnapshotData: shoppingCart.FsShoppingCart.Snapshot,
|
||||||
|
IsSelected: shoppingCart.FsShoppingCart.IsSelected,
|
||||||
|
IsHighlyCustomized: shoppingCart.FsShoppingCart.IsHighlyCustomized,
|
||||||
|
Ctime: shoppingCart.FsShoppingCart.Ctime,
|
||||||
|
Utime: shoppingCart.FsShoppingCart.Utime,
|
||||||
|
}
|
||||||
|
var purchaseQuantityInter = gmodel.PurchaseQuantity{
|
||||||
|
Current: *shoppingCart.PurchaseQuantity,
|
||||||
|
Initiate: *shoppingCart.PurchaseQuantity,
|
||||||
|
}
|
||||||
|
productInter := gmodel.OrderProduct{
|
||||||
TotalPrice: order.GetAmountInfo(order.GetAmountInfoReq{
|
TotalPrice: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||||
ExchangeRate: in.ExchangeRate,
|
ExchangeRate: in.ExchangeRate,
|
||||||
Initiate: productTotalPrice,
|
Initiate: productTotalPrice,
|
||||||
|
@ -901,10 +882,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
OriginalCurrency: in.OriginalCurrency,
|
OriginalCurrency: in.OriginalCurrency,
|
||||||
}),
|
}),
|
||||||
ExpectedDeliveryTime: &in.ExpectedDeliveryTime,
|
ExpectedDeliveryTime: &in.ExpectedDeliveryTime,
|
||||||
PurchaseQuantity: gmodel.PurchaseQuantity{
|
PurchaseQuantity: purchaseQuantityInter,
|
||||||
Current: *shoppingCart.PurchaseQuantity,
|
|
||||||
Initiate: *shoppingCart.PurchaseQuantity,
|
|
||||||
},
|
|
||||||
ProductID: *shoppingCart.ProductId,
|
ProductID: *shoppingCart.ProductId,
|
||||||
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
||||||
ProductCoverMetadata: productCoverMetadata,
|
ProductCoverMetadata: productCoverMetadata,
|
||||||
|
@ -917,7 +895,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
OriginalCurrency: in.OriginalCurrency,
|
OriginalCurrency: in.OriginalCurrency,
|
||||||
}),
|
}),
|
||||||
ProductSnapshot: shoppingCart.ShoppingCartProduct,
|
ProductSnapshot: shoppingCart.ShoppingCartProduct,
|
||||||
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
|
ShoppingCartSnapshot: shoppingCartSnapshotInter,
|
||||||
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
||||||
DiyInformation: &shoppingCartSnapshot.UserDiyInformation,
|
DiyInformation: &shoppingCartSnapshot.UserDiyInformation,
|
||||||
FittingInfo: &gmodel.OrderProductFittingInfo{
|
FittingInfo: &gmodel.OrderProductFittingInfo{
|
||||||
|
@ -932,9 +910,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
Cm: shoppingCartSnapshot.SizeInfo.Cm,
|
Cm: shoppingCartSnapshot.SizeInfo.Cm,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
StepNum: stepNum,
|
|
||||||
IsHighlyCustomized: *shoppingCart.IsHighlyCustomized,
|
IsHighlyCustomized: *shoppingCart.IsHighlyCustomized,
|
||||||
})
|
}
|
||||||
|
orderProductList = append(orderProductList, productInter)
|
||||||
}
|
}
|
||||||
|
|
||||||
subtotal = order.GetAmountInfo(order.GetAmountInfoReq{
|
subtotal = order.GetAmountInfo(order.GetAmountInfoReq{
|
||||||
|
@ -1060,6 +1038,66 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理订单购物车快照
|
||||||
|
func (d *defaultOrder) OrderDetailSnapshotHandler(ctx context.Context, req *string) (res map[string]interface{}, err error) {
|
||||||
|
var snapshot map[string]interface{}
|
||||||
|
json.Unmarshal([]byte(*req), &snapshot)
|
||||||
|
snapshotFittingInfoData, snapshotFittingInfoEx := snapshot["fitting_info"]
|
||||||
|
var fittingInfoMap map[string]interface{}
|
||||||
|
if snapshotFittingInfoEx {
|
||||||
|
var snapshotFittingInfoJson map[string]interface{}
|
||||||
|
var fittingName string
|
||||||
|
snapshotFittingInfo := snapshotFittingInfoData.(map[string]interface{})
|
||||||
|
snapshotFittingInfoJsonData, snapshotFittingInfoJsonEx := snapshotFittingInfo["fitting_json"]
|
||||||
|
if snapshotFittingInfoJsonEx {
|
||||||
|
json.Unmarshal([]byte(snapshotFittingInfoJsonData.(string)), &snapshotFittingInfoJson)
|
||||||
|
}
|
||||||
|
fittingNameData, fittingNameEx := snapshotFittingInfo["fitting_name"]
|
||||||
|
if fittingNameEx {
|
||||||
|
fittingName = fittingNameData.(string)
|
||||||
|
}
|
||||||
|
fittingInfoMap = make(map[string]interface{}, 2)
|
||||||
|
fittingInfoMap["fitting_json"] = snapshotFittingInfoJson
|
||||||
|
fittingInfoMap["fitting_name"] = fittingName
|
||||||
|
}
|
||||||
|
snapshot["fitting_info"] = fittingInfoMap
|
||||||
|
|
||||||
|
snapshotModelInfoData, snapshotModelInfoEx := snapshot["model_info"]
|
||||||
|
var modelInfoMap map[string]interface{}
|
||||||
|
if snapshotModelInfoEx {
|
||||||
|
var snapshotModelInfoJson map[string]interface{}
|
||||||
|
snapshotModelInfo := snapshotModelInfoData.(map[string]interface{})
|
||||||
|
snapshotModelInfoJsonData, snapshotModelInfoJsonEx := snapshotModelInfo["model_json"]
|
||||||
|
if snapshotModelInfoJsonEx {
|
||||||
|
json.Unmarshal([]byte(snapshotModelInfoJsonData.(string)), &snapshotModelInfoJson)
|
||||||
|
}
|
||||||
|
modelInfoMap = make(map[string]interface{}, 1)
|
||||||
|
modelInfoMap["model_json"] = snapshotModelInfoJson
|
||||||
|
}
|
||||||
|
snapshot["model_info"] = modelInfoMap
|
||||||
|
|
||||||
|
snapshotTemplateInfoData, snapshotTemplateInfoEx := snapshot["template_info"]
|
||||||
|
var templateInfoMap map[string]interface{}
|
||||||
|
if snapshotTemplateInfoEx {
|
||||||
|
var snapshotTemplateInfoJson map[string]interface{}
|
||||||
|
var templateTag string
|
||||||
|
snapshotTemplateInfo := snapshotTemplateInfoData.(map[string]interface{})
|
||||||
|
snapshotTemplateInfoJsonData, snapshotTemplateInfoJsonEx := snapshotTemplateInfo["template_json"]
|
||||||
|
if snapshotTemplateInfoJsonEx {
|
||||||
|
json.Unmarshal([]byte(snapshotTemplateInfoJsonData.(string)), &snapshotTemplateInfoJson)
|
||||||
|
}
|
||||||
|
templateTagData, templateTagEx := snapshotTemplateInfo["template_tag"]
|
||||||
|
if templateTagEx {
|
||||||
|
templateTag = templateTagData.(string)
|
||||||
|
}
|
||||||
|
templateInfoMap = make(map[string]interface{}, 2)
|
||||||
|
templateInfoMap["template_json"] = snapshotTemplateInfoJson
|
||||||
|
templateInfoMap["template_tag"] = templateTag
|
||||||
|
}
|
||||||
|
snapshot["template_info"] = templateInfoMap
|
||||||
|
return snapshot, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 详情处理
|
// 详情处理
|
||||||
func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder, original int64) (res *DetailRes, err error) {
|
func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder, original int64) (res *DetailRes, err error) {
|
||||||
var orderDetail gmodel.OrderDetail
|
var orderDetail gmodel.OrderDetail
|
||||||
|
@ -1076,42 +1114,7 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
|
||||||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||||
orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity)
|
orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity)
|
||||||
orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil
|
orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil
|
||||||
var snapshot map[string]interface{}
|
orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot.SnapshotData = nil
|
||||||
if orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot.Snapshot != nil {
|
|
||||||
json.Unmarshal([]byte(*orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot.Snapshot), &snapshot)
|
|
||||||
}
|
|
||||||
snapshotfittingInfoData, snapshotfittingInfoEx := snapshot["fitting_info"]
|
|
||||||
var snapshotfittingInfoJson map[string]interface{}
|
|
||||||
if snapshotfittingInfoEx {
|
|
||||||
snapshotfittingInfo := snapshotfittingInfoData.(map[string]interface{})
|
|
||||||
snapshotfittingInfoJsonData, snapshotfittingInfoJsonEx := snapshotfittingInfo["fitting_json"]
|
|
||||||
if snapshotfittingInfoJsonEx {
|
|
||||||
var snapshotfittingInfoJson map[string]interface{}
|
|
||||||
json.Unmarshal([]byte(snapshotfittingInfoJsonData.(string)), &snapshotfittingInfoJson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snapshot["fitting_info"] = snapshotfittingInfoJson
|
|
||||||
snapshotModelInfoData, snapshotModelInfoEx := snapshot["model_info"]
|
|
||||||
var snapshotModelInfoJson map[string]interface{}
|
|
||||||
if snapshotModelInfoEx {
|
|
||||||
snapshotModelInfo := snapshotModelInfoData.(map[string]interface{})
|
|
||||||
snapshotModelInfoJsonData, snapshotModelInfoJsonEx := snapshotModelInfo["model_json"]
|
|
||||||
if snapshotModelInfoJsonEx {
|
|
||||||
json.Unmarshal([]byte(snapshotModelInfoJsonData.(string)), &snapshotModelInfoJson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snapshot["model_info"] = snapshotModelInfoJson
|
|
||||||
snapshotTemplateInfoData, snapshotTemplateInfoEx := snapshot["template_info"]
|
|
||||||
var snapshotTemplateInfoJson map[string]interface{}
|
|
||||||
if snapshotTemplateInfoEx {
|
|
||||||
snapshotTemplateInfo := snapshotTemplateInfoData.(map[string]interface{})
|
|
||||||
snapshotTemplateInfoJsonData, snapshotTemplateInfoJsonEx := snapshotTemplateInfo["template_json"]
|
|
||||||
if snapshotTemplateInfoJsonEx {
|
|
||||||
json.Unmarshal([]byte(snapshotTemplateInfoJsonData.(string)), &snapshotTemplateInfoJson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snapshot["template_info"] = snapshotTemplateInfoJson
|
|
||||||
orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshotInfo = snapshot
|
|
||||||
}
|
}
|
||||||
orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink)
|
orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink)
|
||||||
orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount)
|
orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount)
|
||||||
|
|
|
@ -3,15 +3,10 @@ package repositories
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/format"
|
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
"fusenapi/utils/step_price"
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"math"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +28,7 @@ type (
|
||||||
// 校验订单
|
// 校验订单
|
||||||
VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error
|
VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error
|
||||||
//计算购物车价格
|
//计算购物车价格
|
||||||
CaculateCartPrice(purchaseQuantity int64, productPrice *gmodel.FsProductPrice, fittingPrice int64) (ItemPrice, totalPrice int64, stepNum, stepPrice []int, err error)
|
CaculateStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice int64, err error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -132,33 +127,23 @@ func (d *defaultShoppingCart) VerifyShoppingCartSnapshotDataChange(req VerifySho
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算价格
|
// 计算价格
|
||||||
func (d *defaultShoppingCart) CaculateCartPrice(purchaseQuantity int64, productPrice *gmodel.FsProductPrice, fittingPrice int64) (ItemPrice, totalPrice int64, stepNum, stepPrice []int, err error) {
|
func (d *defaultShoppingCart) CaculateStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice int64, err error) {
|
||||||
//阶梯数量切片
|
l := len(stepPrice.PriceRange)
|
||||||
stepNum, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepNum, ","))
|
if l == 0 {
|
||||||
if err != nil {
|
return 0, 0, errors.New("price range is not set")
|
||||||
logx.Error(err)
|
|
||||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
|
||||||
}
|
}
|
||||||
lenStepNum := len(stepNum)
|
//遍历查询合适的价格
|
||||||
//阶梯价格切片
|
for k, v := range stepPrice.PriceRange {
|
||||||
stepPrice, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepPrice, ","))
|
//购买数量>起点
|
||||||
if err != nil {
|
if purchaseQuantity > v.StartQuantity {
|
||||||
logx.Error(err)
|
//最后一个 || 小于等于终点
|
||||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
||||||
|
itemPrice = v.Price + fittingPrice
|
||||||
|
return itemPrice * purchaseQuantity, itemPrice, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lenStepPrice := len(stepPrice)
|
//遍历里面没有则返回第一个
|
||||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
itemPrice = stepPrice.PriceRange[0].Price + fittingPrice
|
||||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
return itemPrice * purchaseQuantity, itemPrice, nil
|
||||||
}
|
|
||||||
//请求的数量
|
|
||||||
reqPurchaseQuantity := purchaseQuantity
|
|
||||||
//购买箱数
|
|
||||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*productPrice.EachBoxNum)))
|
|
||||||
//根据数量获取阶梯价格中对应的价格
|
|
||||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
|
||||||
//如果有配件,单价也要加入配件价格
|
|
||||||
itemPrice += fittingPrice
|
|
||||||
//单个购物车总价
|
|
||||||
totalPrice = itemPrice * reqPurchaseQuantity
|
|
||||||
return itemPrice, totalPrice, stepNum, stepPrice, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ var (
|
||||||
CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "create order failed, price of product is absent"} // 订单创建失败,商品价格不存在
|
CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "create order failed, price of product is absent"} // 订单创建失败,商品价格不存在
|
||||||
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
||||||
CodeErrOrderCreatePrePaymentParam = &StatusResponse{5306, "create payment failed, the shipping address is illegal"} // 订单创建失败,商品配件不存在
|
CodeErrOrderCreatePrePaymentParam = &StatusResponse{5306, "create payment failed, the shipping address is illegal"} // 订单创建失败,商品配件不存在
|
||||||
CodeErrOrderCreatePrePaymentInfoNoFound = &StatusResponse{5307, "create payment failed, order info not found"}
|
CodeErrOrderCreatePrePaymentInfoNoFound = &StatusResponse{5307, "order info not found"}
|
||||||
CodeErrOrderCreatePrePaymentNoUnPaid = &StatusResponse{5308, "create payment failed, order is not unpaid"}
|
CodeErrOrderCreatePrePaymentNoUnPaid = &StatusResponse{5308, "create payment failed, order is not unpaid"}
|
||||||
CodeErrOrderCreatePrePaymentPaid = &StatusResponse{5309, "create payment failed, order is paid"}
|
CodeErrOrderCreatePrePaymentPaid = &StatusResponse{5309, "create payment failed, order is paid"}
|
||||||
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
||||||
|
|
|
@ -166,6 +166,9 @@ func UpdateOrderStatusLink(statusLink []gmodel.OrderStatus, status gmodel.OrderS
|
||||||
if status.Utime != nil {
|
if status.Utime != nil {
|
||||||
item.Utime = status.Utime
|
item.Utime = status.Utime
|
||||||
}
|
}
|
||||||
|
if status.Ctime != nil {
|
||||||
|
item.Ctime = status.Ctime
|
||||||
|
}
|
||||||
if status.Metadata != nil {
|
if status.Metadata != nil {
|
||||||
item.Metadata = status.Metadata
|
item.Metadata = status.Metadata
|
||||||
}
|
}
|
||||||
|
|
|
@ -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