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

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

View File

@ -1,29 +1,28 @@
package gmodel
import (
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
// fs_address 用户地址表
type FsAddress struct {
AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` //
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
AddressName *string `gorm:"default:'';" json:"address_name"` //
FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
Street *string `gorm:"default:'';" json:"street"` // 街道
Suite *string `gorm:"default:'';" json:"suite"` // 房号
City *string `gorm:"default:'';" json:"city"` // 城市
State *string `gorm:"default:'';" json:"state"` //
Country *string `gorm:"default:'';" json:"country"` //
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常
IsDefault *int64 `gorm:"index;default:0;" json:"is_default"` // 1默认地址0非默认地址
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"` // 更新时间
Ltime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间
AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` //
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
Street *string `gorm:"default:'';" json:"street"` // 街道
Suite *string `gorm:"default:'';" json:"suite"` // 房号
City *string `gorm:"default:'';" json:"city"` // 城市
State *string `gorm:"default:'';" json:"state"` //
Country *string `gorm:"default:'';" json:"country"` //
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常
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"` // 更新时间
Ltime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间
}
type FsAddressModel struct {
db *gorm.DB

View File

@ -26,22 +26,21 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
now := time.Now().UTC()
result = &FsAddress{
UserId: address.UserId,
AddressName: address.AddressName,
FirstName: address.FirstName,
LastName: address.LastName,
Mobile: address.Mobile,
Street: address.Street,
Suite: address.Suite,
City: address.City,
State: address.State,
Country: address.Country,
ZipCode: address.ZipCode,
Status: address.Status,
IsDefault: address.IsDefault,
Ctime: &now,
Utime: &now,
Ltime: &now,
UserId: address.UserId,
FirstName: address.FirstName,
LastName: address.LastName,
Mobile: address.Mobile,
Street: address.Street,
Suite: address.Suite,
City: address.City,
State: address.State,
Country: address.Country,
ZipCode: address.ZipCode,
Status: address.Status,
Ctime: &now,
Utime: &now,
Ltime: &now,
}
// lastOne := &FsAddress{}
@ -85,16 +84,23 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
logx.Info("address_id:", addressId, " set default ")
now := time.Now().UTC()
err = tx.Model(&FsAddress{}).Where(" `user_id` = ? and `status` = ? and `address_id` = ? ", userId, 1, addressId).
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error
if err != nil {
return err
}
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ?", userId, addressId).
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id` != ? and `ltime` > ? ", userId, 1, addressId, now.AddDate(10, 0, 0)).
err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).Error
if err != nil {
logx.Error(err)

View File

@ -2,6 +2,11 @@ package gmodel
import (
"context"
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"sort"
)
// 阶梯价结构
@ -152,3 +157,72 @@ func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context,
err = db.Take(&resp).Error
return resp, err
}
func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, productIds []int64, tags []int, fields ...string) (resp []FsProductModel3d, err error) {
if len(productIds) == 0 || len(tags) == 0 {
return
}
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).
Where("`product_id` in (?) and `tag` in (?) and `status` = ?", productIds, tags, 1).
Order("sort DESC")
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Find(&resp).Error
return resp, err
}
// 获取每个产品最低价格
func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64, mapProductMinPrice map[int64]int64) error {
//获取产品模型价格列表
modelList, err := d.GetAllByProductIdsTags(ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
if err != nil {
return errors.New("failed to get model list")
}
mapModelMinPrice := make(map[int64]int64)
//每个模型/配件存储最小价格
for _, modelInfo := range modelList {
switch *modelInfo.Tag {
case constants.TAG_MODEL: //模型
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
mapModelMinPrice[modelInfo.Id] = 0
continue
}
var stepPrice StepPriceJsonStruct
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
}
lenRange := len(stepPrice.PriceRange)
if lenRange == 0 {
mapModelMinPrice[modelInfo.Id] = 0
continue
}
sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool {
return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price
})
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
case constants.TAG_PARTS: //配件
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
}
}
//给产品存储最小价格
for _, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
continue
}
itemPrice := mapModelMinPrice[v.Id]
if *v.PartId > 0 {
if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
itemPrice += fittingPrice
}
}
if minPrice, ok := mapProductMinPrice[*v.ProductId]; ok {
if itemPrice < minPrice {
mapProductMinPrice[*v.ProductId] = itemPrice
}
continue
}
mapProductMinPrice[*v.ProductId] = itemPrice
}
return nil
}

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")

View File

@ -49,22 +49,17 @@ type (
AddressId int64 `json:"address_id"` // 地址id
}
AddressNameRequest {
AddressName string `json:"address_name"` // 地址
}
AddressRequest {
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"` //州
}
ProfileBaseRequest {

View File

@ -1,18 +1,31 @@
package format
import (
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"strconv"
"strings"
)
// 数字变成带千分位的字符串
func NumToStringWithThousandthPercentile(number int64) string {
s := fmt.Sprintf("%d", number)
func NumToStringWithThousandthPercentile(numberStr string) string {
if _, err := strconv.ParseFloat(numberStr, 64); err != nil {
logx.Error("is not a number")
return ""
}
sliceList := strings.Split(numberStr, ".") //切分开小数
s := sliceList[0]
f := ""
if len(sliceList) == 2 {
f = "." + sliceList[1]
}
l := len(s)
if l <= 3 {
return s
return s + f
}
r := l % 3 //前面第几位开始加入千分位
if r == 0 {
r = 3
}
b := strings.Builder{}
for i := 0; i < l; i++ {
b.WriteString(string(s[i]))
@ -21,5 +34,6 @@ func NumToStringWithThousandthPercentile(number int64) string {
r += 3
}
}
b.WriteString(f)
return b.String()
}