Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
39efb7eefb
@ -1,15 +1,15 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fs_address 用户地址表
|
// fs_address 用户地址表
|
||||||
type FsAddress struct {
|
type FsAddress struct {
|
||||||
AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` //
|
AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` //
|
||||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户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
|
FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName
|
||||||
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
|
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
|
||||||
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
|
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
|
||||||
@ -20,7 +20,6 @@ type FsAddress struct {
|
|||||||
Country *string `gorm:"default:'';" json:"country"` //
|
Country *string `gorm:"default:'';" json:"country"` //
|
||||||
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
||||||
Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常
|
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"` // 创建时间
|
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"` // 更新时间
|
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"` // 上次被使用的时间
|
Ltime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间
|
||||||
|
@ -27,7 +27,6 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
result = &FsAddress{
|
result = &FsAddress{
|
||||||
UserId: address.UserId,
|
UserId: address.UserId,
|
||||||
AddressName: address.AddressName,
|
|
||||||
FirstName: address.FirstName,
|
FirstName: address.FirstName,
|
||||||
LastName: address.LastName,
|
LastName: address.LastName,
|
||||||
Mobile: address.Mobile,
|
Mobile: address.Mobile,
|
||||||
@ -38,7 +37,7 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||||||
Country: address.Country,
|
Country: address.Country,
|
||||||
ZipCode: address.ZipCode,
|
ZipCode: address.ZipCode,
|
||||||
Status: address.Status,
|
Status: address.Status,
|
||||||
IsDefault: address.IsDefault,
|
|
||||||
Ctime: &now,
|
Ctime: &now,
|
||||||
Utime: &now,
|
Utime: &now,
|
||||||
Ltime: &now,
|
Ltime: &now,
|
||||||
@ -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 {
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||||
|
|
||||||
|
logx.Info("address_id:", addressId, " set default ")
|
||||||
|
|
||||||
now := time.Now().UTC()
|
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("ltime", now.AddDate(250, 0, 0)).
|
||||||
UpdateColumn("utime", now).Error
|
UpdateColumn("utime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
UpdateColumn("ltime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -2,6 +2,11 @@ package gmodel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 阶梯价结构
|
// 阶梯价结构
|
||||||
@ -152,3 +157,72 @@ func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context,
|
|||||||
err = db.Take(&resp).Error
|
err = db.Take(&resp).Error
|
||||||
return resp, err
|
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
|
||||||
|
}
|
||||||
|
@ -46,10 +46,8 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
|||||||
if req.Id == 0 {
|
if req.Id == 0 {
|
||||||
var (
|
var (
|
||||||
country string = "USA" // 国家默认为美国
|
country string = "USA" // 国家默认为美国
|
||||||
isDefautl int64 = 1 // 默认地址为1
|
|
||||||
)
|
)
|
||||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
||||||
AddressName: &req.Name,
|
|
||||||
FirstName: &req.FirstName,
|
FirstName: &req.FirstName,
|
||||||
LastName: &req.LastName,
|
LastName: &req.LastName,
|
||||||
Mobile: &req.Mobile,
|
Mobile: &req.Mobile,
|
||||||
@ -61,7 +59,6 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
|||||||
Status: &status,
|
Status: &status,
|
||||||
UserId: &userinfo.UserId,
|
UserId: &userinfo.UserId,
|
||||||
ZipCode: &req.ZipCode,
|
ZipCode: &req.ZipCode,
|
||||||
IsDefault: &isDefautl,
|
|
||||||
}
|
}
|
||||||
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,7 +70,6 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
|||||||
|
|
||||||
address := &gmodel.FsAddress{
|
address := &gmodel.FsAddress{
|
||||||
AddressId: req.Id,
|
AddressId: req.Id,
|
||||||
AddressName: &req.Name,
|
|
||||||
FirstName: &req.FirstName,
|
FirstName: &req.FirstName,
|
||||||
LastName: &req.LastName,
|
LastName: &req.LastName,
|
||||||
Mobile: &req.Mobile,
|
Mobile: &req.Mobile,
|
||||||
@ -84,7 +80,6 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri
|
|||||||
Status: &status,
|
Status: &status,
|
||||||
UserId: &userinfo.UserId,
|
UserId: &userinfo.UserId,
|
||||||
ZipCode: &req.ZipCode,
|
ZipCode: &req.ZipCode,
|
||||||
IsDefault: &req.IsDefault,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入数据库 更新地址
|
// 插入数据库 更新地址
|
||||||
|
@ -50,12 +50,10 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
country string = "USA" // 国家默认为美国
|
country string = "USA" // 国家默认为美国
|
||||||
isDefautl int64 = 1 // 默认地址为1
|
|
||||||
status int64 = 1 // 默认地址状态为1(正常)
|
status int64 = 1 // 默认地址状态为1(正常)
|
||||||
)
|
)
|
||||||
|
|
||||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
||||||
AddressName: &req.AddressName,
|
|
||||||
FirstName: &req.FirstName,
|
FirstName: &req.FirstName,
|
||||||
LastName: &req.LastName,
|
LastName: &req.LastName,
|
||||||
Mobile: &req.Mobile,
|
Mobile: &req.Mobile,
|
||||||
@ -67,14 +65,17 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U
|
|||||||
Status: &status,
|
Status: &status,
|
||||||
UserId: &userinfo.UserId,
|
UserId: &userinfo.UserId,
|
||||||
ZipCode: &req.ZipCode,
|
ZipCode: &req.ZipCode,
|
||||||
IsDefault: &isDefautl,
|
|
||||||
}
|
}
|
||||||
_, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
address, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err) // 日志记录错误
|
logx.Error(err) // 日志记录错误
|
||||||
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
|
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)
|
addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
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{
|
return resp.SetStatus(basic.CodeOK, map[string]any{
|
||||||
|
"address_id": address.AddressId,
|
||||||
"address_list": addresses,
|
"address_list": addresses,
|
||||||
}) // 返回成功并返回地址ID
|
}) // 返回成功并返回地址ID
|
||||||
|
|
||||||
|
@ -43,7 +43,15 @@ func (l *AddressDefaultLogic) AddressDefault(req *types.AddressIdRequest, userin
|
|||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
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 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
@ -43,7 +43,9 @@ func (l *AddressDeleteLogic) AddressDelete(req *types.AddressIdRequest, userinfo
|
|||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
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 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
@ -49,8 +49,6 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
|
|||||||
address := gmodel.FsAddress{
|
address := gmodel.FsAddress{
|
||||||
AddressId: req.AddressId,
|
AddressId: req.AddressId,
|
||||||
UserId: &userinfo.UserId,
|
UserId: &userinfo.UserId,
|
||||||
IsDefault: &req.IsDefault,
|
|
||||||
AddressName: &req.AddressName,
|
|
||||||
FirstName: &req.FirstName,
|
FirstName: &req.FirstName,
|
||||||
LastName: &req.LastName,
|
LastName: &req.LastName,
|
||||||
Mobile: &req.Mobile,
|
Mobile: &req.Mobile,
|
||||||
@ -67,7 +65,17 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
|
|||||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
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 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
@ -18,14 +18,9 @@ type AddressIdRequest struct {
|
|||||||
AddressId int64 `json:"address_id"` // 地址id
|
AddressId int64 `json:"address_id"` // 地址id
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressNameRequest struct {
|
|
||||||
AddressName string `json:"address_name"` // 地址
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddressRequest struct {
|
type AddressRequest struct {
|
||||||
AddressId int64 `json:"address_id,optional"`
|
AddressId int64 `json:"address_id,optional"`
|
||||||
IsDefault int64 `json:"is_default"` //是否默认
|
IsDefault int64 `json:"is_default"` //是否默认
|
||||||
AddressName string `json:"address_name"` //收货人
|
|
||||||
FirstName string `json:"first_name"` //first_name
|
FirstName string `json:"first_name"` //first_name
|
||||||
LastName string `json:"last_name"` //last_name
|
LastName string `json:"last_name"` //last_name
|
||||||
Mobile string `json:"mobile"` //手机
|
Mobile string `json:"mobile"` //手机
|
||||||
|
@ -91,13 +91,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
|||||||
stepPurchaseQuantity := *modelPriceInfo.PackedUnit
|
stepPurchaseQuantity := *modelPriceInfo.PackedUnit
|
||||||
//购买数步进基数描述
|
//购买数步进基数描述
|
||||||
stepPurchaseQuantityDescription := "主体装箱数为步进基数"
|
stepPurchaseQuantityDescription := "主体装箱数为步进基数"
|
||||||
|
//配件价格
|
||||||
|
fittingPrice := int64(0)
|
||||||
if *modelPriceInfo.PartId > 0 {
|
if *modelPriceInfo.PartId > 0 {
|
||||||
fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId]
|
fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId]
|
||||||
if !ok {
|
if !ok {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId))
|
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 {
|
if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity {
|
||||||
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
|
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
|
||||||
@ -108,17 +112,29 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
|||||||
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
||||||
//最后一个
|
//最后一个
|
||||||
if rIndex+1 == rangeLen {
|
if rIndex+1 == rangeLen {
|
||||||
|
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||||
stepRange = append(stepRange, map[string]interface{}{
|
stepRange = append(stepRange, map[string]interface{}{
|
||||||
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
|
"start": rangeInfo.StartQuantity,
|
||||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
"end": rangeInfo.EndQuantity,
|
||||||
|
"range_description": fmt.Sprintf(">=%s Units", begin),
|
||||||
|
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||||
|
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
|
||||||
stepRange = append(stepRange, map[string]interface{}{
|
stepRange = append(stepRange, map[string]interface{}{
|
||||||
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
|
"start": rangeInfo.StartQuantity,
|
||||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
"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{}{
|
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{
|
||||||
"step_purchase_quantity": stepPurchaseQuantity,
|
"step_purchase_quantity": stepPurchaseQuantity,
|
||||||
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
|
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
|
||||||
@ -126,6 +142,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
|||||||
"max_price": maxPrice,
|
"max_price": maxPrice,
|
||||||
"step_range": stepRange,
|
"step_range": stepRange,
|
||||||
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum,
|
"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)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
"fusenapi/utils/s3url_to_s3id"
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -92,39 +91,12 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
|||||||
recommendProductList = append(recommendProductList, v)
|
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)
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
for _, v := range priceList {
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
|
||||||
if v.StepPrice == nil || *v.StepPrice == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*v.StepPrice, ","))
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse step price")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min 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) {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user")
|
|
||||||
}*/
|
|
||||||
//获取产品标签相关属性
|
//获取产品标签相关属性
|
||||||
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
|
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6,9 +6,7 @@ import (
|
|||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -81,32 +79,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||||||
productIds = append(productIds, *v.ProductId)
|
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)
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
//存储产品最小价格
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
|
||||||
for _, v := range productPriceList {
|
|
||||||
priceStrSlic := strings.Split(v.Price, ",")
|
|
||||||
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
|
||||||
}
|
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//获取对应模型数据
|
//获取对应模型数据
|
||||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
|
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
"fusenapi/utils/s3url_to_s3id"
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -228,32 +227,10 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
|
|||||||
CoverMetadata: req.MapResourceMetadata[*v.Cover],
|
CoverMetadata: req.MapResourceMetadata[*v.Cover],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//获取产品价格列表
|
//获取产品最低价格
|
||||||
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil {
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, errors.New("failed to get product min price list")
|
return nil, errors.New("failed to get product min price")
|
||||||
}
|
|
||||||
//存储产品最小价格
|
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//获取模板
|
//获取模板
|
||||||
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")
|
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
|
req.MapProductTemplate[*v.ProductId] = v.Id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品尺寸数量
|
//获取产品尺寸数量
|
||||||
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/s3url_to_s3id"
|
"fusenapi/utils/s3url_to_s3id"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -46,8 +45,6 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||||||
recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||||
mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map
|
mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map
|
||||||
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
|
||||||
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
|
||||||
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
||||||
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
||||||
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||||
@ -114,31 +111,11 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||||||
}
|
}
|
||||||
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
||||||
}
|
}
|
||||||
//获取产品价格列表
|
//获取产品最低价格
|
||||||
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
if err != nil {
|
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
|
||||||
}
|
|
||||||
//存储产品最小价格
|
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//获取模板(只是获取产品product_id)
|
//获取模板(只是获取产品product_id)
|
||||||
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id")
|
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id")
|
||||||
|
@ -49,14 +49,9 @@ type (
|
|||||||
AddressId int64 `json:"address_id"` // 地址id
|
AddressId int64 `json:"address_id"` // 地址id
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressNameRequest {
|
|
||||||
AddressName string `json:"address_name"` // 地址
|
|
||||||
}
|
|
||||||
|
|
||||||
AddressRequest {
|
AddressRequest {
|
||||||
AddressId int64 `json:"address_id,optional"`
|
AddressId int64 `json:"address_id,optional"`
|
||||||
IsDefault int64 `json:"is_default"` //是否默认
|
IsDefault int64 `json:"is_default"` //是否默认
|
||||||
AddressName string `json:"address_name"` //收货人
|
|
||||||
FirstName string `json:"first_name"` //first_name
|
FirstName string `json:"first_name"` //first_name
|
||||||
LastName string `json:"last_name"` //last_name
|
LastName string `json:"last_name"` //last_name
|
||||||
Mobile string `json:"mobile"` //手机
|
Mobile string `json:"mobile"` //手机
|
||||||
|
@ -1,18 +1,31 @@
|
|||||||
package format
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 数字变成带千分位的字符串
|
// 数字变成带千分位的字符串
|
||||||
func NumToStringWithThousandthPercentile(number int64) string {
|
func NumToStringWithThousandthPercentile(numberStr string) string {
|
||||||
s := fmt.Sprintf("%d", number)
|
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)
|
l := len(s)
|
||||||
if l <= 3 {
|
if l <= 3 {
|
||||||
return s
|
return s + f
|
||||||
}
|
}
|
||||||
r := l % 3 //前面第几位开始加入千分位
|
r := l % 3 //前面第几位开始加入千分位
|
||||||
|
if r == 0 {
|
||||||
|
r = 3
|
||||||
|
}
|
||||||
b := strings.Builder{}
|
b := strings.Builder{}
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
b.WriteString(string(s[i]))
|
b.WriteString(string(s[i]))
|
||||||
@ -21,5 +34,6 @@ func NumToStringWithThousandthPercentile(number int64) string {
|
|||||||
r += 3
|
r += 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.WriteString(f)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user