Merge branch 'feature/mhw-v1.01' of gitee.com:fusenpack/fusenapi into feature/mhw-v1.01
This commit is contained in:
commit
751232c32e
|
@ -18,12 +18,15 @@ func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...s
|
|||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
||||
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string, fields ...string) (resp []FsProduct, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return
|
||||
}
|
||||
db := p.db.Model(&FsProduct{}).WithContext(ctx).
|
||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
db = db.Order("`sort` ASC")
|
||||
|
|
|
@ -23,11 +23,11 @@ func (p *FsProductPriceModel) GetSimplePriceListByProductIds(ctx context.Context
|
|||
}
|
||||
return
|
||||
}
|
||||
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
|
||||
if len(sizeIds) == 0 {
|
||||
func (p *FsProductPriceModel) GetPriceListByProductIdsSizeIds(ctx context.Context, productIds, sizeIds []int64) (resp []FsProductPrice, err error) {
|
||||
if len(sizeIds) == 0 || len(productIds) == 0 {
|
||||
return
|
||||
}
|
||||
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
|
||||
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `product_id` in (?) and `status` = ? ", sizeIds, productIds, 1).Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -71,6 +71,11 @@ func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, prod
|
|||
}
|
||||
return
|
||||
}
|
||||
func (p *FsProductPriceModel) FindOneBySizeId(ctx context.Context, sizeId int64) (resp *FsProductPrice, err error) {
|
||||
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).
|
||||
Where("`size_id` = ? and `status` = ?", sizeId, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// 产品价格
|
||||
type ProductPrice struct {
|
||||
|
|
|
@ -33,17 +33,22 @@ func (s *FsShoppingCartModel) FineOneUserCart(ctx context.Context, id, userId in
|
|||
|
||||
// 创建
|
||||
func (s *FsShoppingCartModel) Create(ctx context.Context, data *FsShoppingCart) error {
|
||||
return s.db.WithContext(ctx).Create(&data).Error
|
||||
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Create(&data).Error
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (s *FsShoppingCartModel) Delete(ctx context.Context, id, userId int64) error {
|
||||
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ? and id = ?", userId, id).Delete(&FsShoppingCart{}).Error
|
||||
}
|
||||
|
||||
// 更新
|
||||
func (s *FsShoppingCartModel) Update(ctx context.Context, id, userId int64, data *FsShoppingCart) error {
|
||||
return s.db.WithContext(ctx).Where("user_id = ? and id = ?", userId, id).Updates(&data).Error
|
||||
return s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ? and id = ?", userId, id).Updates(&data).Error
|
||||
}
|
||||
|
||||
// 获取用户购物车数量
|
||||
func (s *FsShoppingCartModel) CountUserCart(ctx context.Context, userId int64) (total int64, err error) {
|
||||
err = s.db.WithContext(ctx).Where("user_id = ?", userId).Limit(1).Count(&total).Error
|
||||
err = s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("user_id = ?", userId).Limit(1).Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
|
@ -52,7 +57,7 @@ func (s *FsShoppingCartModel) GetAllByIds(ctx context.Context, ids []int64, sort
|
|||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
db := s.db.WithContext(ctx).Where("id in (?)", ids)
|
||||
db := s.db.WithContext(ctx).Model(&FsShoppingCart{}).Where("id in (?)", ids)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
|
@ -74,7 +79,7 @@ type GetAllCartsByParamReq struct {
|
|||
}
|
||||
|
||||
func (s *FsShoppingCartModel) GetAllCartsByParam(ctx context.Context, req GetAllCartsByParamReq) (resp []FsShoppingCart, total int64, err error) {
|
||||
db := s.db.WithContext(ctx)
|
||||
db := s.db.WithContext(ctx).Model(&FsShoppingCart{})
|
||||
if req.UserId > 0 {
|
||||
db = db.Where("user_id = ?", req.UserId)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func NewGetCanteenDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
// 获取餐厅详情
|
||||
func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
//获取餐厅类型数据
|
||||
canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
||||
|
|
|
@ -32,7 +32,7 @@ func NewSaveCanteenTypeProductLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
|||
// 保存餐厅类型的关联产品
|
||||
func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
if len(req.ProductList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "product list can`t be empty")
|
||||
|
|
|
@ -29,7 +29,7 @@ func NewGetQrCodeSetListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
// 获取二维码配置列表
|
||||
func (l *GetQrCodeSetListLogic) GetQrCodeSetList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn)
|
||||
qrCodeList, err := qrCodeModel.GetAll(l.ctx)
|
||||
|
|
|
@ -29,7 +29,7 @@ func NewGetStandardLogoListLogic(ctx context.Context, svcCtx *svc2.ServiceContex
|
|||
// 获取标准logo列表
|
||||
func (l *GetStandardLogoListLogic) GetStandardLogoList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
standardLogoModel := gmodel.NewFsStandardLogoModel(l.svcCtx.MysqlConn)
|
||||
logoList, err := standardLogoModel.GetAll(l.ctx)
|
||||
|
|
|
@ -30,7 +30,7 @@ func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
|
||||
func (l *GetMapLibraryListLogic) GetMapLibraryList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||
mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx)
|
||||
|
|
|
@ -46,7 +46,7 @@ func (l *SaveMapLibraryLogic) BeforeLogic(w http.ResponseWriter, r *http.Request
|
|||
|
||||
func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
|
||||
if len(l.bodyData) == 0 {
|
||||
|
|
|
@ -30,7 +30,7 @@ func NewGetLastProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
|||
|
||||
func (l *GetLastProductDesignLogic) GetLastProductDesign(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatusAddMessage(basic.CodeUnAuth, "please login")
|
||||
return resp.SetStatusAddMessage(basic.CodeUnAuth, "please sign in")
|
||||
}
|
||||
//获取用户信息
|
||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||
|
|
|
@ -31,7 +31,7 @@ func NewGetProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
|
||||
func (l *GetProductDesignLogic) GetProductDesign(req *types.GetProductDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first")
|
||||
}
|
||||
if req.Sn == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
||||
|
|
|
@ -35,7 +35,7 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
// 获取分类下的产品以及尺寸
|
||||
func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first")
|
||||
}
|
||||
//获取所有网站目录
|
||||
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||
|
@ -74,14 +74,14 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
|||
}
|
||||
//获取价格列表
|
||||
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||
productPriceList, err := productPriceModel.GetPriceListBySizeIds(l.ctx, sizeIds)
|
||||
productPriceList, err := productPriceModel.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
||||
}
|
||||
mapProductPrice := make(map[int64]gmodel.FsProductPrice)
|
||||
mapProductPrice := make(map[string]gmodel.FsProductPrice)
|
||||
for _, v := range productPriceList {
|
||||
mapProductPrice[*v.SizeId] = v
|
||||
mapProductPrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
||||
}
|
||||
//组装返回
|
||||
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
||||
|
@ -103,7 +103,7 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
|||
}
|
||||
|
||||
// 第一层子层
|
||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||
childrenList = make([]types.Children, 0, len(productList))
|
||||
for _, product := range productList {
|
||||
if *product.Type != tag.Id {
|
||||
|
@ -126,14 +126,14 @@ func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productL
|
|||
}
|
||||
|
||||
// 第2层子层
|
||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
||||
for _, productSize := range productSizeList {
|
||||
if product.Id != *productSize.ProductId {
|
||||
continue
|
||||
}
|
||||
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
||||
price, ok := mapProductPrice[productSize.Id]
|
||||
price, ok := mapProductPrice[fmt.Sprintf("%d_%d", *productSize.ProductId, productSize.Id)]
|
||||
//无对应尺寸价格
|
||||
if !ok {
|
||||
priceList = []types.PriceObj{
|
||||
|
|
|
@ -30,7 +30,7 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
|||
// 获取推荐的产品列表
|
||||
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, userInfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userInfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first")
|
||||
}
|
||||
//获取用户信息
|
||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
|
|
|
@ -47,7 +47,7 @@ func NewSaveDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveDe
|
|||
|
||||
func (l *SaveDesignLogic) SaveDesign(req *types.SaveDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first")
|
||||
}
|
||||
//查询是否是加密的(不太合理)
|
||||
encryptWebsetting, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, "is_encrypt")
|
||||
|
|
|
@ -14,17 +14,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/shopping-cart/add_to_cart",
|
||||
Path: "/api/shopping-cart/add",
|
||||
Handler: AddToCartHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/shopping-cart/delete_cart",
|
||||
Path: "/api/shopping-cart/delete",
|
||||
Handler: DeleteCartHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/shopping-cart/modify_cart_purchase_quantity",
|
||||
Path: "/api/shopping-cart/modify",
|
||||
Handler: ModifyCartPurchaseQuantityHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
|
|
|
@ -65,6 +65,7 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
templateJson string //模板表的记录中的json设计信息
|
||||
templateTag string //模板表的模板标签
|
||||
fittingJson string //配件的json设计信息
|
||||
fittingName string //配件名
|
||||
)
|
||||
//有模板
|
||||
if req.TemplateId > 0 {
|
||||
|
@ -105,6 +106,7 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "the fitting`s design info is empty")
|
||||
}
|
||||
fittingJson = *fittingInfo.ModelInfo
|
||||
fittingName = *fittingInfo.Title
|
||||
}
|
||||
//获取尺寸信息
|
||||
sizeInfo, err := l.svcCtx.AllModels.FsProductSize.FindOne(l.ctx, req.SizeId)
|
||||
|
@ -138,11 +140,12 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
if modelInfo.ModelInfo == nil || *modelInfo.ModelInfo == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "the model`s design info is empty")
|
||||
}
|
||||
var sizeTitleInfo shopping_cart.SizeInfo
|
||||
if err = json.Unmarshal([]byte(*sizeInfo.Title), &sizeTitleInfo); err != nil {
|
||||
var sizeKeyInfo shopping_cart.SizeInfo
|
||||
if err = json.Unmarshal([]byte(*sizeInfo.Title), &sizeKeyInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse size info`s title ")
|
||||
}
|
||||
sizeKeyInfo.Capacity = *sizeInfo.Capacity
|
||||
//快照数据
|
||||
snapshot := shopping_cart.CartSnapshot{
|
||||
Logo: req.Logo,
|
||||
|
@ -157,8 +160,9 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
},
|
||||
FittingInfo: shopping_cart.FittingInfo{
|
||||
FittingJson: fittingJson,
|
||||
FittingName: fittingName,
|
||||
},
|
||||
SizeInfo: sizeTitleInfo,
|
||||
SizeInfo: sizeKeyInfo,
|
||||
ProductInfo: shopping_cart.ProductInfo{
|
||||
ProductName: *productInfo.Title,
|
||||
ProductSn: *productInfo.Sn,
|
||||
|
|
|
@ -31,9 +31,14 @@ func NewDeleteCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
|||
// }
|
||||
|
||||
func (l *DeleteCartLogic) DeleteCart(req *types.DeleteCartReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
|
||||
}
|
||||
//删除购物车
|
||||
if err := l.svcCtx.AllModels.FsShoppingCart.Delete(l.ctx, userinfo.UserId, req.Id); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to delete shopping cart")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,17 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"fusenapi/utils/step_price"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
|
@ -41,7 +46,6 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
//获取用户购物车列表
|
||||
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
UserId: userinfo.UserId,
|
||||
Fields: "",
|
||||
Sort: "id DESC",
|
||||
Page: req.CurrentPage,
|
||||
Limit: limit,
|
||||
|
@ -61,47 +65,28 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
CartList: nil,
|
||||
})
|
||||
}
|
||||
lenCarts := len(carts)
|
||||
templateIds := make([]int64, 0, lenCarts)
|
||||
modelIds := make([]int64, 0, lenCarts) //模型 + 配件
|
||||
sizeIds := make([]int64, 0, lenCarts)
|
||||
for index := range carts {
|
||||
templateIds = append(templateIds, *carts[index].TemplateId)
|
||||
modelIds = append(modelIds, *carts[index].ModelId, *carts[index].FittingId)
|
||||
sizeIds = append(sizeIds, *carts[index].SizeId)
|
||||
}
|
||||
//获取尺寸列表
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")
|
||||
var (
|
||||
mapSize = make(map[int64]gmodel.FsProductSize)
|
||||
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
||||
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
||||
mapSizePrice = make(map[string]gmodel.FsProductPrice)
|
||||
mapProduct = make(map[int64]struct{})
|
||||
)
|
||||
//获取相关信息
|
||||
err = l.GetRelationInfo(GetRelationInfoReq{
|
||||
Carts: carts,
|
||||
MapSize: mapSize,
|
||||
MapModel: mapModel,
|
||||
MapTemplate: mapTemplate,
|
||||
MapSizePrice: mapSizePrice,
|
||||
MapProduct: mapProduct,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
||||
}
|
||||
mapSize := make(map[int64]gmodel.FsProductSize)
|
||||
for _, v := range sizeList {
|
||||
mapSize[v.Id] = v
|
||||
}
|
||||
//获取模型和配件信息
|
||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, modelIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
|
||||
}
|
||||
mapModel := make(map[int64]gmodel.FsProductModel3d)
|
||||
for _, v := range modelList {
|
||||
mapModel[v.Id] = v
|
||||
}
|
||||
//获取模板列表
|
||||
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIds(l.ctx, templateIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list")
|
||||
}
|
||||
mapTemplate := make(map[int64]gmodel.FsProductTemplateV2)
|
||||
for _, v := range templateList {
|
||||
mapTemplate[v.Id] = v
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
//定义map收集变更信息
|
||||
mapCartChange := make(map[int64]string)
|
||||
mapSnapshot := make(map[int64]shopping_cart.CartSnapshot)
|
||||
//校验购物车数据是否变更
|
||||
err = shopping_cart.VerifyShoppingCartSnapshotDataChange(shopping_cart.VerifyShoppingCartSnapshotDataChangeReq{
|
||||
Carts: carts,
|
||||
|
@ -109,16 +94,172 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
MapModel: mapModel,
|
||||
MapTemplate: mapTemplate,
|
||||
MapCartChange: mapCartChange,
|
||||
MapSnapshot: mapSnapshot,
|
||||
MapProduct: mapProduct,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "system err:failed to check shopping cart change data")
|
||||
}
|
||||
/*list := make([]types.CartItem, 0, lenCarts)
|
||||
for index := range carts {
|
||||
|
||||
}*/
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
list := make([]types.CartItem, 0, len(carts))
|
||||
for _, cart := range carts {
|
||||
snapShot := mapSnapshot[cart.Id]
|
||||
sizePrice, ok := mapSizePrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
|
||||
if !ok {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price info is not exists:%d", *cart.SizeId))
|
||||
}
|
||||
//阶梯数量切片
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step number:%d", *cart.SizeId))
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price:%d", *cart.SizeId))
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price or step number is not set:%d ", *cart.SizeId))
|
||||
}
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(*cart.PurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
||||
//获取阶梯数量
|
||||
stepQuantityList := make([]int64, 0, 20)
|
||||
tmpMinBuyNum := *sizePrice.MinBuyNum
|
||||
for tmpMinBuyNum < (int64(stepNum[lenStepNum-1]) + 5) {
|
||||
//阶梯数
|
||||
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
|
||||
stepQuantityList = append(stepQuantityList, tmpQuantity)
|
||||
tmpMinBuyNum++
|
||||
}
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
//如果有配件,单价也要加入配件价格
|
||||
if *cart.FittingId > 0 {
|
||||
if curFittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||
itemPrice += *curFittingInfo.Price
|
||||
}
|
||||
}
|
||||
totalPrice := itemPrice * (*cart.PurchaseQuantity)
|
||||
item := types.CartItem{
|
||||
ProductId: *cart.ProductId,
|
||||
SizeInfo: types.SizeInfo{
|
||||
SizeId: *cart.SizeId,
|
||||
Capacity: snapShot.SizeInfo.Capacity,
|
||||
Title: types.SizeTitle{
|
||||
Cm: snapShot.SizeInfo.Cm,
|
||||
Inch: snapShot.SizeInfo.Inch,
|
||||
},
|
||||
},
|
||||
FittingInfo: types.FittingInfo{
|
||||
FittingId: *cart.FittingId,
|
||||
FittingName: snapShot.FittingInfo.FittingName,
|
||||
},
|
||||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
|
||||
DiyInformation: types.DiyInformation{
|
||||
Phone: snapShot.UserDiyInformation.Phone,
|
||||
Address: snapShot.UserDiyInformation.Address,
|
||||
Website: snapShot.UserDiyInformation.Website,
|
||||
Qrcode: snapShot.UserDiyInformation.Qrcode,
|
||||
Slogan: snapShot.UserDiyInformation.Slogan,
|
||||
},
|
||||
PurchaseQuantity: *cart.PurchaseQuantity,
|
||||
StepNum: stepQuantityList,
|
||||
IsInvalid: false,
|
||||
InvalidDescription: "",
|
||||
}
|
||||
//是否有失效的
|
||||
if description, ok := mapCartChange[cart.Id]; ok {
|
||||
item.IsInvalid = true
|
||||
item.InvalidDescription = description
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCartsRsp{
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(limit))),
|
||||
CurrentPage: req.CurrentPage,
|
||||
PerPage: limit,
|
||||
},
|
||||
CartList: list,
|
||||
})
|
||||
}
|
||||
|
||||
// 获取相关信息
|
||||
type GetRelationInfoReq struct {
|
||||
Carts []gmodel.FsShoppingCart
|
||||
MapSize map[int64]gmodel.FsProductSize
|
||||
MapModel map[int64]gmodel.FsProductModel3d
|
||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||
MapSizePrice map[string]gmodel.FsProductPrice
|
||||
MapProduct map[int64]struct{}
|
||||
}
|
||||
|
||||
func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
||||
lenCarts := len(req.Carts)
|
||||
templateIds := make([]int64, 0, lenCarts)
|
||||
modelIds := make([]int64, 0, lenCarts) //模型 + 配件
|
||||
sizeIds := make([]int64, 0, lenCarts)
|
||||
productIds := make([]int64, 0, lenCarts)
|
||||
for index := range req.Carts {
|
||||
templateIds = append(templateIds, *req.Carts[index].TemplateId)
|
||||
modelIds = append(modelIds, *req.Carts[index].ModelId, *req.Carts[index].FittingId)
|
||||
sizeIds = append(sizeIds, *req.Carts[index].SizeId)
|
||||
productIds = append(productIds, *req.Carts[index].ProductId)
|
||||
}
|
||||
//获取产品集合
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "", "id")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New("failed to get product list")
|
||||
}
|
||||
for _, v := range productList {
|
||||
req.MapProduct[v.Id] = struct{}{}
|
||||
}
|
||||
//获取尺寸列表
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New("failed to get size list")
|
||||
}
|
||||
for _, v := range sizeList {
|
||||
req.MapSize[v.Id] = v
|
||||
}
|
||||
//获取模型和配件信息
|
||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, modelIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New("failed to get model list")
|
||||
}
|
||||
for _, v := range modelList {
|
||||
req.MapModel[v.Id] = v
|
||||
}
|
||||
//获取模板列表
|
||||
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIds(l.ctx, templateIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New("failed to get template list")
|
||||
}
|
||||
for _, v := range templateList {
|
||||
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
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
|
|
@ -48,9 +48,10 @@ type CartItem struct {
|
|||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"totalPrice"` //单价X数量=总价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
}
|
||||
|
@ -76,6 +77,7 @@ type DiyInformation struct {
|
|||
Address string `json:"address"`
|
||||
Website string `json:"website"`
|
||||
Qrcode string `json:"qrcode"`
|
||||
Slogan string `json:"slogan"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
|
|
@ -32,7 +32,7 @@ func NewUploadQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uplo
|
|||
|
||||
func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
|
||||
}
|
||||
if req.Url == "" {
|
||||
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
||||
|
|
|
@ -11,13 +11,13 @@ import "basic.api"
|
|||
service shopping-cart {
|
||||
//加入购物车
|
||||
@handler AddToCartHandler
|
||||
post /api/shopping-cart/add_to_cart(AddToCartReq) returns (response);
|
||||
post /api/shopping-cart/add(AddToCartReq) returns (response);
|
||||
//删除购物车
|
||||
@handler DeleteCartHandler
|
||||
post /api/shopping-cart/delete_cart(DeleteCartReq) returns (response);
|
||||
post /api/shopping-cart/delete(DeleteCartReq) returns (response);
|
||||
//修改购物车购买数量
|
||||
@handler ModifyCartPurchaseQuantityHandler
|
||||
post /api/shopping-cart/modify_cart_purchase_quantity(ModifyCartPurchaseQuantityReq) returns (response);
|
||||
post /api/shopping-cart/modify(ModifyCartPurchaseQuantityReq) returns (response);
|
||||
//获取购物车列表
|
||||
@handler GetCartsHandler
|
||||
get /api/shopping-cart/get_carts(GetCartsReq) returns (response);
|
||||
|
@ -64,9 +64,10 @@ type CartItem {
|
|||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"totalPrice"` //单价X数量=总价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
}
|
||||
|
@ -88,4 +89,5 @@ type DiyInformation {
|
|||
Address string `json:"address"`
|
||||
Website string `json:"website"`
|
||||
Qrcode string `json:"qrcode"`
|
||||
Slogan string `json:"slogan"`
|
||||
}
|
|
@ -5,9 +5,9 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// 美分转美元
|
||||
func CentoDollar(price int64) float64 {
|
||||
str := fmt.Sprintf("%.2f", float64(price)/float64(100))
|
||||
// 厘转美元
|
||||
func CentitoDollar(price int64) float64 {
|
||||
str := fmt.Sprintf("%.3f", float64(price)/float64(1000))
|
||||
dollar, _ := strconv.ParseFloat(str, 64)
|
||||
return dollar
|
||||
}
|
||||
|
|
|
@ -21,14 +21,16 @@ type ModelInfo struct {
|
|||
}
|
||||
type FittingInfo struct {
|
||||
FittingJson string `json:"fitting_json"` //配件设计json数据
|
||||
FittingName string `json:"fitting_name"` //配件名称
|
||||
}
|
||||
type TemplateInfo struct {
|
||||
TemplateJson string `json:"template_json"` //模板设计json数据
|
||||
TemplateTag string `json:"template_tag"` //模板标签
|
||||
}
|
||||
type SizeInfo struct {
|
||||
Inch string `json:"inch"`
|
||||
Cm string `json:"cm"`
|
||||
Inch string `json:"inch"`
|
||||
Cm string `json:"cm"`
|
||||
Capacity string `json:"capacity"`
|
||||
}
|
||||
type UserDiyInformation struct {
|
||||
Phone string `json:"phone"` //电话
|
||||
|
|
|
@ -14,21 +14,28 @@ type VerifyShoppingCartSnapshotDataChangeReq struct {
|
|||
MapModel map[int64]gmodel.FsProductModel3d //模型跟配件都在
|
||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||
MapCartChange map[int64]string
|
||||
MapSnapshot map[int64]CartSnapshot
|
||||
MapProduct map[int64]struct{}
|
||||
}
|
||||
|
||||
func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error {
|
||||
for _, cartInfo := range req.Carts {
|
||||
descrptionBuilder := strings.Builder{}
|
||||
//产品下架/删除
|
||||
if _, ok := req.MapProduct[*cartInfo.ProductId]; !ok {
|
||||
descrptionBuilder.WriteString("<p>the product is off shelf or deleted </p>")
|
||||
}
|
||||
var snapShotParseInfo CartSnapshot
|
||||
if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
req.MapSnapshot[cartInfo.Id] = snapShotParseInfo
|
||||
//快照中模板设计json数据哈希值
|
||||
snapshotTemplateJsonHash := hash.JsonHashKey(snapShotParseInfo.TemplateInfo.TemplateJson)
|
||||
//快照中模型设计json数据哈希值
|
||||
snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson)
|
||||
//快照中配件设计json数据哈希值
|
||||
snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson)
|
||||
descrptionBuilder := strings.Builder{}
|
||||
//有模板验证模板相关
|
||||
if *cartInfo.TemplateId > 0 {
|
||||
if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok {
|
||||
|
|
|
@ -3,20 +3,20 @@ package step_price
|
|||
// 返回美元
|
||||
func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
|
||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
for k, v := range stepNum {
|
||||
if minBuyNum <= v {
|
||||
if k <= (len(stepPrice) - 1) {
|
||||
return float64(stepPrice[k]) / float64(100)
|
||||
return float64(stepPrice[k]) / float64(1000)
|
||||
}
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
}
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
|
||||
// 返回美分
|
||||
// 返回厘
|
||||
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||
return int64(stepPrice[len(stepPrice)-1])
|
||||
|
|
Loading…
Reference in New Issue
Block a user