Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo
2023-09-27 17:24:05 +08:00
17 changed files with 267 additions and 250 deletions

View File

@@ -45,23 +45,20 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
// 如果ID为0, 表示新增地址
if req.Id == 0 {
var (
country string = "USA" // 国家默认为美国
isDefautl int64 = 1 // 默认地址为1
country string = "USA" // 国家默认为美国
)
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
AddressName: &req.Name,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Country: &country,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
IsDefault: &isDefautl,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Country: &country,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
}
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
if err != nil {
@@ -72,19 +69,17 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
}
address := &gmodel.FsAddress{
AddressId: req.Id,
AddressName: &req.Name,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
IsDefault: &req.IsDefault,
AddressId: req.Id,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
}
// 插入数据库 更新地址

View File

@@ -49,32 +49,33 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U
// 如果ID为0, 表示新增地址
var (
country string = "USA" // 国家默认为美国
isDefautl int64 = 1 // 默认地址为1
status int64 = 1 // 默认地址状态为1(正常)
country string = "USA" // 国家默认为美国
status int64 = 1 // 默认地址状态为1(正常)
)
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
AddressName: &req.AddressName,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Country: &country,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
IsDefault: &isDefautl,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Country: &country,
Status: &status,
UserId: &userinfo.UserId,
ZipCode: &req.ZipCode,
}
_, err := m.CreateOne(l.ctx, createOne) // 新增地址
address, err := m.CreateOne(l.ctx, createOne) // 新增地址
if err != nil {
logx.Error(err) // 日志记录错误
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
}
if req.IsDefault > 0 {
m.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId)
}
addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
@@ -82,6 +83,7 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U
}
return resp.SetStatus(basic.CodeOK, map[string]any{
"address_id": address.AddressId,
"address_list": addresses,
}) // 返回成功并返回地址ID

View File

@@ -43,7 +43,15 @@ func (l *AddressDefaultLogic) AddressDefault(req *types.AddressIdRequest, userin
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}
return resp.SetStatus(basic.CodeOK)
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr) // 返回数据库创建错误
}
return resp.SetStatus(basic.CodeOK, map[string]any{
"address_list": addresses,
}) // 返回成功并返回地址ID
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@@ -43,7 +43,9 @@ func (l *AddressDeleteLogic) AddressDelete(req *types.AddressIdRequest, userinfo
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}
return resp.SetStatus(basic.CodeOK)
return resp.SetStatus(basic.CodeOK, map[string]any{
"address_id": req.AddressId,
}) // 返回成功并返回地址ID
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@@ -47,19 +47,17 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
}
address := gmodel.FsAddress{
AddressId: req.AddressId,
UserId: &userinfo.UserId,
IsDefault: &req.IsDefault,
AddressName: &req.AddressName,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
ZipCode: &req.ZipCode,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Utime: &now,
AddressId: req.AddressId,
UserId: &userinfo.UserId,
FirstName: &req.FirstName,
LastName: &req.LastName,
Mobile: &req.Mobile,
ZipCode: &req.ZipCode,
Street: &req.Street,
Suite: &req.Suite,
City: &req.City,
State: &req.State,
Utime: &now,
}
err := l.svcCtx.AllModels.FsAddress.UpdateAddress(l.ctx, &address)
@@ -67,7 +65,17 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}
return resp.SetStatus(basic.CodeOK)
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr) // 返回数据库创建错误
}
return resp.SetStatus(basic.CodeOK, map[string]any{
"address_id": req.AddressId,
"address_list": addresses,
}) // 返回成功并返回地址ID
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@@ -18,22 +18,17 @@ type AddressIdRequest struct {
AddressId int64 `json:"address_id"` // 地址id
}
type AddressNameRequest struct {
AddressName string `json:"address_name"` // 地址
}
type AddressRequest struct {
AddressId int64 `json:"address_id,optional"`
IsDefault int64 `json:"is_default"` //是否默认
AddressName string `json:"address_name"` //收货人
FirstName string `json:"first_name"` //first_name
LastName string `json:"last_name"` //last_name
Mobile string `json:"mobile"` //手机
ZipCode string `json:"zip_code"` //邮编
Street string `json:"street"` //街道
Suite string `json:"suite"` //房号
City string `json:"city"` //城市
State string `json:"state"` //州
AddressId int64 `json:"address_id,optional"`
IsDefault int64 `json:"is_default"` //是否默认
FirstName string `json:"first_name"` //first_name
LastName string `json:"last_name"` //last_name
Mobile string `json:"mobile"` //手机
ZipCode string `json:"zip_code"` //邮编
Street string `json:"street"` //街道
Suite string `json:"suite"` //房号
City string `json:"city"` //城市
State string `json:"state"` //
}
type ProfileBaseRequest struct {

View File

@@ -91,13 +91,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
stepPurchaseQuantity := *modelPriceInfo.PackedUnit
//购买数步进基数描述
stepPurchaseQuantityDescription := "主体装箱数为步进基数"
//配件价格
fittingPrice := int64(0)
if *modelPriceInfo.PartId > 0 {
fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId]
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId))
}
//最小价格要加配件
minPrice += *fittingPriceInfo.Price
//最小/最大价格要加配件
fittingPrice = *fittingPriceInfo.Price
minPrice += fittingPrice
maxPrice += fittingPrice
//如果配件装箱基数比主体大,则基数以配件为主
if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity {
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
@@ -108,17 +112,29 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
for rIndex, rangeInfo := range stepPrice.PriceRange {
//最后一个
if rIndex+1 == rangeLen {
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
stepRange = append(stepRange, map[string]interface{}{
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf(">=%s Units", begin),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
break
}
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
stepRange = append(stepRange, map[string]interface{}{
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
}
//计算起购数量的单价
_, minBuyUnitsQuantityPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(stepPrice.MinBuyUnitsNum, stepPrice, fittingPrice)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get min buy quantity item price")
}
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{
"step_purchase_quantity": stepPurchaseQuantity,
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
@@ -126,6 +142,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
"max_price": maxPrice,
"step_range": stepRange,
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum,
"min_buy_units_quantity_total_price": format.CentitoDollarWithNoHalfAdjust(minBuyUnitsQuantityPrice*stepPrice.MinBuyUnitsNum, 2),
"min_buy_units_quantity_item_price": format.CentitoDollar(minBuyUnitsQuantityPrice, 3),
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)

View File

@@ -10,7 +10,6 @@ import (
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"sort"
"strings"
"context"
@@ -92,39 +91,12 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
recommendProductList = append(recommendProductList, v)
}
}
//查询产品价格
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list")
}
//获取产品最低价
mapProductMinPrice := make(map[int64]int64)
for _, v := range priceList {
if v.StepPrice == nil || *v.StepPrice == "" {
continue
}
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*v.StepPrice, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse step price")
}
//正序排序
sort.Ints(stepPriceSlice)
if min, ok := mapProductMinPrice[*v.ProductId]; ok {
if min > int64(stepPriceSlice[0]) {
mapProductMinPrice[*v.ProductId] = int64(stepPriceSlice[0])
}
} else {
mapProductMinPrice[*v.ProductId] = int64(stepPriceSlice[0])
}
}
//获取用户信息(不用判断存在)
/*user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user")
}*/
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
}
//获取产品标签相关属性
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
if err != nil {

View File

@@ -6,9 +6,7 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"sort"
"strings"
"context"
@@ -81,32 +79,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
productIds = append(productIds, *v.ProductId)
}
//获取产品价格列表
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
}
mapProductMinPrice := make(map[int64]int64)
//存储产品最小价格
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
}
if len(priceSlice) == 0 {
continue
}
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
sort.Ints(priceSlice)
if min, ok := mapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
} else {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
}
//获取对应模型数据
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")

View File

@@ -6,7 +6,6 @@ import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
@@ -228,32 +227,10 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
CoverMetadata: req.MapResourceMetadata[*v.Cover],
})
}
//获取产品价格列表
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
if err != nil {
//获取产品最低价格
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil {
logx.Error(err)
return nil, errors.New("failed to get product min price list")
}
//存储产品最小价格
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return nil, errors.New("parse price err")
}
if len(priceSlice) == 0 {
continue
}
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
sort.Ints(priceSlice)
if min, ok := req.MapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
} else {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
return nil, errors.New("failed to get product min price")
}
//获取模板
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")
@@ -269,7 +246,6 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
req.MapProductTemplate[*v.ProductId] = v.Id
}
}
//获取产品尺寸数量
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
if err != nil {

View File

@@ -9,7 +9,6 @@ import (
"fusenapi/utils/format"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
"sort"
"strings"
"context"
@@ -46,8 +45,6 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
recommendProductList []gmodel.FsProduct //产品列表select 字段需要看查询的地方)
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表select 字段需要看查询的地方)
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方)
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方)
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
@@ -114,31 +111,11 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
}
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
}
//获取产品价格列表
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
if err != nil {
//获取产品最低价格
mapProductMinPrice := make(map[int64]int64)
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
}
//存储产品最小价格
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
}
if len(priceSlice) == 0 {
continue
}
sort.Ints(priceSlice)
if min, ok := mapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
} else {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
}
//获取模板(只是获取产品product_id)
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id")