From ab916ac13d2a5fb0cdb68e39e794bc06c6591ae4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:13:37 +0800 Subject: [PATCH 01/33] fix --- model/gmodel/fs_product_model3d_logic.go | 14 +++++ .../internal/logic/gettagproductlistlogic.go | 59 ++++++++++++------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index df5f7200..5de5f05a 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -152,3 +152,17 @@ 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 +} diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index f0538caf..1cc13901 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,10 +3,11 @@ package logic import ( "encoding/json" "errors" + "fmt" + "fusenapi/constants" "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 +229,50 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn CoverMetadata: req.MapResourceMetadata[*v.Cover], }) } - //获取产品价格列表 - productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) + //获取产品模型价格列表 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,step_price") if err != nil { logx.Error(err) - return nil, errors.New("failed to get product min price list") + return nil, errors.New("failed to get model 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") + mapModelMinPrice := make(map[int64]int64) + //每个模型/配件存储最小价格 + for _, modelInfo := range modelList { + switch *modelInfo.Tag { + case constants.TAG_MODEL: //模型 + if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { + return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + } + var stepPrice gmodel.StepPriceJsonStruct + if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { + logx.Error(err) + return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) + } + lenRange := len(stepPrice.PriceRange) + if lenRange == 0 { + return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + } + mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price + case constants.TAG_PARTS: //配件 + mapModelMinPrice[modelInfo.Id] = *modelInfo.Price } - if len(priceSlice) == 0 { + } + //给产品存储最小价格 + for _, v := range modelList { + if *v.Tag != constants.TAG_MODEL { 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]) + itemPrice := mapModelMinPrice[v.Id] + if *v.PartId > 0 { + itemPrice += mapModelMinPrice[*v.PartId] } + if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok { + if itemPrice < minPrice { + req.MapProductMinPrice[*v.ProductId] = itemPrice + } + continue + } + req.MapProductMinPrice[*v.ProductId] = itemPrice } //获取模板 productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") From 36ae64f3e7164c87ead3864f1566a406c75215dc Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:21:16 +0800 Subject: [PATCH 02/33] fix --- server/product/internal/logic/gettagproductlistlogic.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 1cc13901..94fd02e4 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -264,7 +264,9 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn } itemPrice := mapModelMinPrice[v.Id] if *v.PartId > 0 { - itemPrice += mapModelMinPrice[*v.PartId] + if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok { + itemPrice += fittingPrice + } } if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok { if itemPrice < minPrice { From 0967df9113722dd6f9c7d4999c7d698f2aa86158 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:23:22 +0800 Subject: [PATCH 03/33] fix --- server/product/internal/logic/gettagproductlistlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 94fd02e4..acd47689 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -230,7 +230,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn }) } //获取产品模型价格列表 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,step_price") + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price") if err != nil { logx.Error(err) return nil, errors.New("failed to get model list") From 2eadff787655470f59ebb372eac8656f53a29d35 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:30:17 +0800 Subject: [PATCH 04/33] info get profile --- model/gmodel/fs_address_gen.go | 33 +++++++++---------- model/gmodel/fs_order_gen.go | 29 +++++++++------- model/gmodel/fs_product_model3d_gen.go | 2 +- server/info/internal/logic/addressaddlogic.go | 25 +++++++------- .../info/internal/logic/addressupdatelogic.go | 25 +++++++------- server/info/internal/types/types.go | 25 ++++++-------- server_api/info.api | 25 ++++++-------- 7 files changed, 79 insertions(+), 85 deletions(-) diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go index b6085c7d..c2c8c448 100644 --- a/model/gmodel/fs_address_gen.go +++ b/model/gmodel/fs_address_gen.go @@ -7,23 +7,22 @@ import ( // 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异常 + 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"` // 上次被使用的时间 } type FsAddressModel struct { db *gorm.DB diff --git a/model/gmodel/fs_order_gen.go b/model/gmodel/fs_order_gen.go index 8a914f08..3329dc28 100644 --- a/model/gmodel/fs_order_gen.go +++ b/model/gmodel/fs_order_gen.go @@ -7,17 +7,24 @@ import ( // fs_order 订单表 type FsOrder struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID - DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型 - OrderSn *string `gorm:"unique_key;default:'';" json:"order_sn"` // - OrderSource *string `gorm:"default:'';" json:"order_source"` // - Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态 - Metadata *[]byte `gorm:"default:'';" json:"metadata"` // - 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"` // - IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是 - PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID + DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型 + OrderSn *string `gorm:"unique_key;default:'';" json:"order_sn"` // + OrderSource *string `gorm:"default:'';" json:"order_source"` // + Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态 + Metadata *[]byte `gorm:"default:'';" json:"metadata"` // + 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"` // + IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是 + PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态 + StatusLink *[]byte `gorm:"default:'';" json:"status_link"` // + OrderProduct *[]byte `gorm:"default:'';" json:"order_product"` // + OrderAddress *[]byte `gorm:"default:'';" json:"order_address"` // + OrderAmount *[]byte `gorm:"default:'';" json:"order_amount"` // + PayStatusLink *[]byte `gorm:"default:'';" json:"pay_status_link"` // + ShoppingCartSnapshot *[]byte `gorm:"default:'';" json:"shopping_cart_snapshot"` // + ShoppingProductSnapshot *[]byte `gorm:"default:'';" json:"shopping_product_snapshot"` // } type FsOrderModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_model3d_gen.go b/model/gmodel/fs_product_model3d_gen.go index f8647a23..e33f097d 100644 --- a/model/gmodel/fs_product_model3d_gen.go +++ b/model/gmodel/fs_product_model3d_gen.go @@ -23,7 +23,7 @@ type FsProductModel3d struct { Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 - Price *int64 `gorm:"default:0;" json:"price"` // + Price *int64 `gorm:"default:0;" json:"price"` // 仅配件用,配件的价格, 单位:0.1美分 Sku *string `gorm:"default:'';" json:"sku"` // sku IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型 diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index 61599266..0673e91c 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -55,19 +55,18 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U ) 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, + IsDefault: &isDefautl, } _, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index 91648145..8cd33bd2 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -47,19 +47,18 @@ 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, + IsDefault: &req.IsDefault, + 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) diff --git a/server/info/internal/types/types.go b/server/info/internal/types/types.go index a3fbf2f8..b510ac96 100644 --- a/server/info/internal/types/types.go +++ b/server/info/internal/types/types.go @@ -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 { diff --git a/server_api/info.api b/server_api/info.api index 1770f022..a3dc8a6d 100644 --- a/server_api/info.api +++ b/server_api/info.api @@ -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 { From 9de1099b120c913c0e7a9cbd7bf6ffae9bfa85f9 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:35:34 +0800 Subject: [PATCH 05/33] info get profile --- model/gmodel/fs_address_logic.go | 31 ++++++------ .../internal/logic/useraddaddresslogic.go | 50 +++++++++---------- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index bff0471f..6909304d 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -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, + IsDefault: address.IsDefault, + Ctime: &now, + Utime: &now, + Ltime: &now, } // lastOne := &FsAddress{} diff --git a/server/home-user-auth/internal/logic/useraddaddresslogic.go b/server/home-user-auth/internal/logic/useraddaddresslogic.go index 2e2cbe33..0fac637f 100644 --- a/server/home-user-auth/internal/logic/useraddaddresslogic.go +++ b/server/home-user-auth/internal/logic/useraddaddresslogic.go @@ -49,19 +49,18 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri isDefautl int64 = 1 // 默认地址为1 ) 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, + IsDefault: &isDefautl, } created, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { @@ -72,19 +71,18 @@ 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, + IsDefault: &req.IsDefault, } // 插入数据库 更新地址 From 884ce87972672303f1c75849f07db8049422147b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:36:09 +0800 Subject: [PATCH 06/33] fix --- service/repositories/{shopping-cart.go => shopping_cart.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename service/repositories/{shopping-cart.go => shopping_cart.go} (100%) diff --git a/service/repositories/shopping-cart.go b/service/repositories/shopping_cart.go similarity index 100% rename from service/repositories/shopping-cart.go rename to service/repositories/shopping_cart.go From 4e45e1e393c198493c332f69be9ae7dee91bd4e7 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:47:38 +0800 Subject: [PATCH 07/33] info get profile --- server/info/internal/logic/addressdefaultlogic.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/info/internal/logic/addressdefaultlogic.go b/server/info/internal/logic/addressdefaultlogic.go index 440dde95..903a5dd5 100644 --- a/server/info/internal/logic/addressdefaultlogic.go +++ b/server/info/internal/logic/addressdefaultlogic.go @@ -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 必须重新处理 From 4ea3487043b6b9ca91bbafa96863b4817951b318 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:48:15 +0800 Subject: [PATCH 08/33] fix --- model/gmodel/fs_product_model3d_logic.go | 57 +++++++++++++++++++ .../logic/getrecommandproductlistlogic.go | 34 +---------- .../internal/logic/gettagproductlistlogic.go | 50 +--------------- .../homepagerecommendproductlistlogic.go | 30 +--------- 4 files changed, 65 insertions(+), 106 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 5de5f05a..e7449a84 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -2,6 +2,11 @@ package gmodel import ( "context" + "encoding/json" + "errors" + "fmt" + "fusenapi/constants" + "github.com/zeromicro/go-zero/core/logx" ) // 阶梯价结构 @@ -166,3 +171,55 @@ func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, prod err = db.Find(&resp).Error return resp, err } + +// 获取每个产品最低价格 +func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64) (productMinPrice map[int64]int64, err 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 + } + mapModelMinPrice := make(map[int64]int64) + //每个模型/配件存储最小价格 + for _, modelInfo := range modelList { + switch *modelInfo.Tag { + case constants.TAG_MODEL: //模型 + if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { + return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + } + var stepPrice StepPriceJsonStruct + if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { + logx.Error(err) + return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) + } + lenRange := len(stepPrice.PriceRange) + if lenRange == 0 { + return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + } + mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price + case constants.TAG_PARTS: //配件 + mapModelMinPrice[modelInfo.Id] = *modelInfo.Price + } + } + productMinPrice = make(map[int64]int64) + //给产品存储最小价格 + 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 := productMinPrice[*v.ProductId]; ok { + if itemPrice < minPrice { + productMinPrice[*v.ProductId] = itemPrice + } + continue + } + productMinPrice[*v.ProductId] = itemPrice + } + return productMinPrice, nil +} diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index c708f8f9..3f0545d0 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -10,7 +10,6 @@ import ( "fusenapi/utils/image" "fusenapi/utils/s3url_to_s3id" "gorm.io/gorm" - "sort" "strings" "context" @@ -92,39 +91,10 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec recommendProductList = append(recommendProductList, v) } } - - //查询产品价格 - priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds) + mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list") + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price") } - 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) { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user") - }*/ //获取产品标签相关属性 productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) if err != nil { diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index acd47689..5107c10e 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,8 +3,6 @@ package logic import ( "encoding/json" "errors" - "fmt" - "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -229,52 +227,10 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn CoverMetadata: req.MapResourceMetadata[*v.Cover], }) } - //获取产品模型价格列表 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price") + //获取产品最低价格 + req.MapProductMinPrice, err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) if err != nil { - logx.Error(err) - return nil, 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 { - return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) - } - var stepPrice gmodel.StepPriceJsonStruct - if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { - logx.Error(err) - return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) - } - lenRange := len(stepPrice.PriceRange) - if lenRange == 0 { - return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) - } - 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 := req.MapProductMinPrice[*v.ProductId]; ok { - if itemPrice < minPrice { - req.MapProductMinPrice[*v.ProductId] = itemPrice - } - continue - } - req.MapProductMinPrice[*v.ProductId] = itemPrice + return nil, err } //获取模板 productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 75d8963f..c5be671a 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -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,10 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } mapProductHaveOptionFitting[partList.ProductId] = struct{}{} } - //获取产品价格列表 - productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) + //获取产品最低价格 + mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) if 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") From 5fcd76e32eabbbe74003ded1ef52f4047601e985 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:51:24 +0800 Subject: [PATCH 09/33] info get profile --- model/gmodel/fs_address_logic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 6909304d..86848aa4 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -86,14 +86,14 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i now := time.Now().UTC() - err = tx.Model(&FsAddress{}).Where(" `user_id` = ? and `status` = ? and `address_id` = ? ", userId, 1, addressId). + err = tx.Model(&FsAddress{}).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.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) From 53446bb606df18d5dfe3d097342b392a9159f6ed Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:55:21 +0800 Subject: [PATCH 10/33] info get profile --- model/gmodel/fs_address_logic.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 86848aa4..2dfcc55b 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -86,7 +86,12 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i now := time.Now().UTC() - err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, 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 { From 788dbd325ee74f8dd5e384bf1bf8d05a68a1387d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:57:10 +0800 Subject: [PATCH 11/33] fix --- .../internal/logic/gettagproductlistlogic.go | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 5107c10e..10c61c59 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,6 +3,8 @@ package logic import ( "encoding/json" "errors" + "fmt" + "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -228,9 +230,51 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn }) } //获取产品最低价格 - req.MapProductMinPrice, err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price") if err != nil { - return nil, err + logx.Error(err) + return nil, 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 { + return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + } + var stepPrice gmodel.StepPriceJsonStruct + if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { + logx.Error(err) + return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) + } + lenRange := len(stepPrice.PriceRange) + if lenRange == 0 { + return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + } + 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 := req.MapProductMinPrice[*v.ProductId]; ok { + if itemPrice < minPrice { + req.MapProductMinPrice[*v.ProductId] = itemPrice + } + continue + } + req.MapProductMinPrice[*v.ProductId] = itemPrice } //获取模板 productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") From 82ce9a5114c6711e13c782ab84d88fe9bfcef355 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:04:53 +0800 Subject: [PATCH 12/33] info get profile --- model/gmodel/fs_address_logic.go | 2 ++ server/info/internal/logic/addressaddlogic.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 2dfcc55b..f890b1a5 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -84,6 +84,8 @@ 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.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index 0673e91c..dc291724 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -68,12 +68,16 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U ZipCode: &req.ZipCode, IsDefault: &isDefautl, } - _, 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) From 943eba6f1a46f517b7e66291d01262a6ba184527 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:12:28 +0800 Subject: [PATCH 13/33] info get profile --- model/gmodel/fs_address_logic.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index f890b1a5..af2ea9bd 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -93,14 +93,18 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId). + 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` = 1 and `address_id` != ? and `ltime` > ? ", userId, addressId, now.AddDate(10, 0, 0)). + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error + if err != nil { + logx.Error(err) + } + err = tx.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) From b4f201eb98043614aea7f4315d79f0ba8514594d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:18:16 +0800 Subject: [PATCH 14/33] info get profile --- model/gmodel/fs_address_logic.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index af2ea9bd..7230f658 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -2,6 +2,7 @@ package gmodel import ( "context" + "fmt" "time" "github.com/zeromicro/go-zero/core/logx" @@ -100,10 +101,11 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error + err = tx.Where(fmt.Sprintf("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > '%s'", now.AddDate(10, 0, 0)), userId, addressId).Take(nil).Error if err != nil { logx.Error(err) } + err = tx.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 { From fe577052868fb56a00bbe7e746aeecd5797a203a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:23:02 +0800 Subject: [PATCH 15/33] info get profile --- model/gmodel/fs_address_logic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 7230f658..22498d89 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -2,7 +2,6 @@ package gmodel import ( "context" - "fmt" "time" "github.com/zeromicro/go-zero/core/logx" @@ -101,7 +100,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where(fmt.Sprintf("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > '%s'", now.AddDate(10, 0, 0)), userId, addressId).Take(nil).Error + err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and ltime > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error if err != nil { logx.Error(err) } From d61e939685f6dc6d837ed107cb5a9a13c2510bd3 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:24:47 +0800 Subject: [PATCH 16/33] info get profile --- model/gmodel/fs_address_logic.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 22498d89..3408e052 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -100,12 +100,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and ltime > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error - if err != nil { - logx.Error(err) - } - - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, 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) From 3dc822fcde0710d0ce49ff21b2a0d42a1c699c1c Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:28:53 +0800 Subject: [PATCH 17/33] info get profile --- model/gmodel/fs_address_logic.go | 2 +- server/info/internal/logic/addressupdatelogic.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 3408e052..2efce67b 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -84,7 +84,7 @@ 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") + logx.Info("address_id:", addressId, " set default ") now := time.Now().UTC() diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index 8cd33bd2..cc962cbe 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -66,7 +66,16 @@ 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_list": addresses, + }) // 返回成功并返回地址ID + } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 From 02f2e08329aefc60373d9a0b36fd49b9ba3272bb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 14:05:26 +0800 Subject: [PATCH 18/33] fix --- model/gmodel/fs_product_model3d_logic.go | 19 ++++--- .../logic/getrecommandproductlistlogic.go | 5 +- .../internal/logic/gettagproductlistlogic.go | 50 +------------------ .../homepagerecommendproductlistlogic.go | 4 +- 4 files changed, 16 insertions(+), 62 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index e7449a84..bd53a467 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -173,11 +173,11 @@ func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, prod } // 获取每个产品最低价格 -func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64) (productMinPrice map[int64]int64, err error) { +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 + return errors.New("failed to get model list") } mapModelMinPrice := make(map[int64]int64) //每个模型/配件存储最小价格 @@ -185,23 +185,22 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI switch *modelInfo.Tag { case constants.TAG_MODEL: //模型 if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { - return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + return errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) } var stepPrice StepPriceJsonStruct if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { logx.Error(err) - return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) + return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) } lenRange := len(stepPrice.PriceRange) if lenRange == 0 { - return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) } mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price case constants.TAG_PARTS: //配件 mapModelMinPrice[modelInfo.Id] = *modelInfo.Price } } - productMinPrice = make(map[int64]int64) //给产品存储最小价格 for _, v := range modelList { if *v.Tag != constants.TAG_MODEL { @@ -213,13 +212,13 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI itemPrice += fittingPrice } } - if minPrice, ok := productMinPrice[*v.ProductId]; ok { + if minPrice, ok := mapProductMinPrice[*v.ProductId]; ok { if itemPrice < minPrice { - productMinPrice[*v.ProductId] = itemPrice + mapProductMinPrice[*v.ProductId] = itemPrice } continue } - productMinPrice[*v.ProductId] = itemPrice + mapProductMinPrice[*v.ProductId] = itemPrice } - return productMinPrice, nil + return nil } diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 3f0545d0..b65c3cb1 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -91,8 +91,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec recommendProductList = append(recommendProductList, v) } } - mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) - if err != nil { + //获取产品最低价 + mapProductMinPrice := make(map[int64]int64) + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price") } //获取产品标签相关属性 diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 10c61c59..fdc951e6 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,8 +3,6 @@ package logic import ( "encoding/json" "errors" - "fmt" - "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -230,51 +228,8 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn }) } //获取产品最低价格 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price") - if err != nil { - logx.Error(err) - return nil, 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 { - return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) - } - var stepPrice gmodel.StepPriceJsonStruct - if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { - logx.Error(err) - return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) - } - lenRange := len(stepPrice.PriceRange) - if lenRange == 0 { - return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) - } - 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 := req.MapProductMinPrice[*v.ProductId]; ok { - if itemPrice < minPrice { - req.MapProductMinPrice[*v.ProductId] = itemPrice - } - continue - } - req.MapProductMinPrice[*v.ProductId] = itemPrice + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil { + 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") @@ -290,7 +245,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 { diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index c5be671a..eeb5726b 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -112,8 +112,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty mapProductHaveOptionFitting[partList.ProductId] = struct{}{} } //获取产品最低价格 - mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) - if err != nil { + mapProductMinPrice := make(map[int64]int64) + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price") } //获取模板(只是获取产品product_id) From 59114aa94a7837adead09880cd872a7ec4d71709 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 14:13:34 +0800 Subject: [PATCH 19/33] fix --- model/gmodel/fs_product_model3d_logic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index bd53a467..c2d001f8 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -7,6 +7,7 @@ import ( "fmt" "fusenapi/constants" "github.com/zeromicro/go-zero/core/logx" + "sort" ) // 阶梯价结构 @@ -196,6 +197,9 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI if lenRange == 0 { return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) } + 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 From 2ac507ef34ab323064729a6e285d20830c0d63c8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 14:14:16 +0800 Subject: [PATCH 20/33] fix --- model/gmodel/fs_product_model3d_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index c2d001f8..c84373b1 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -198,7 +198,7 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) } sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool { - return stepPrice.PriceRange[i].Price < stepPrice.PriceRange[j].Price + return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price }) mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price case constants.TAG_PARTS: //配件 From 9e2526405f3666ac1bfe0bc429413d21ac8210a9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 15:12:18 +0800 Subject: [PATCH 21/33] fix --- .../logic/getproductsteppricelogic.go | 7 ++++-- utils/format/number.go | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index 9a96014c..bf5bc09d 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -108,14 +108,17 @@ 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)), + "range_description": fmt.Sprintf(">=%s Units", begin), "item_price": format.CentitoDollar(rangeInfo.Price, 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)), + "range_description": fmt.Sprintf("%s-%s Units", begin, end), "item_price": format.CentitoDollar(rangeInfo.Price, 3), }) } diff --git a/utils/format/number.go b/utils/format/number.go index 8cbca6d3..d4912c5e 100644 --- a/utils/format/number.go +++ b/utils/format/number.go @@ -1,18 +1,31 @@ package format import ( - "fmt" + "log" + "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 { + log.Fatalln("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() } From 43752954aee06c66c1a2504cd259b788c95ff960 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 15:37:02 +0800 Subject: [PATCH 22/33] info get profile --- server/info/internal/logic/addressaddlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index dc291724..606dea84 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -85,6 +85,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 From 89e8b4cff97dac1eb2e4d9aea7599523e647e822 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 15:46:35 +0800 Subject: [PATCH 23/33] info get profile --- model/gmodel/fs_address_gen.go | 1 - model/gmodel/fs_address_logic.go | 8 ++++---- server/info/internal/logic/addressdeletelogic.go | 4 +++- server/info/internal/logic/addressupdatelogic.go | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go index c2c8c448..83a4b3b9 100644 --- a/model/gmodel/fs_address_gen.go +++ b/model/gmodel/fs_address_gen.go @@ -19,7 +19,6 @@ type FsAddress struct { 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"` // 上次被使用的时间 diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 2efce67b..8b7ae175 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -37,10 +37,10 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res Country: address.Country, ZipCode: address.ZipCode, Status: address.Status, - IsDefault: address.IsDefault, - Ctime: &now, - Utime: &now, - Ltime: &now, + + Ctime: &now, + Utime: &now, + Ltime: &now, } // lastOne := &FsAddress{} diff --git a/server/info/internal/logic/addressdeletelogic.go b/server/info/internal/logic/addressdeletelogic.go index b2a398ff..d06729ec 100644 --- a/server/info/internal/logic/addressdeletelogic.go +++ b/server/info/internal/logic/addressdeletelogic.go @@ -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 必须重新处理 diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index cc962cbe..572353bc 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -49,7 +49,6 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo * address := gmodel.FsAddress{ AddressId: req.AddressId, UserId: &userinfo.UserId, - IsDefault: &req.IsDefault, FirstName: &req.FirstName, LastName: &req.LastName, Mobile: &req.Mobile, @@ -73,6 +72,7 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo * } return resp.SetStatus(basic.CodeOK, map[string]any{ + "address_id": req.AddressId, "address_list": addresses, }) // 返回成功并返回地址ID From 0a8f3cd5ba1cd347b54f2cd532e204e513eb2c8b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 15:47:40 +0800 Subject: [PATCH 24/33] info get profile --- model/gmodel/fs_address_gen.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go index 83a4b3b9..2feb031b 100644 --- a/model/gmodel/fs_address_gen.go +++ b/model/gmodel/fs_address_gen.go @@ -1,8 +1,9 @@ package gmodel import ( - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) // fs_address 用户地址表 From 31b712784f694c3a800ff9b9174f9975f70fe6a7 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 15:48:13 +0800 Subject: [PATCH 25/33] info get profile --- server/home-user-auth/internal/logic/useraddaddresslogic.go | 5 +---- server/info/internal/logic/addressaddlogic.go | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/server/home-user-auth/internal/logic/useraddaddresslogic.go b/server/home-user-auth/internal/logic/useraddaddresslogic.go index 0fac637f..be56cd5e 100644 --- a/server/home-user-auth/internal/logic/useraddaddresslogic.go +++ b/server/home-user-auth/internal/logic/useraddaddresslogic.go @@ -45,8 +45,7 @@ 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结构体 FirstName: &req.FirstName, @@ -60,7 +59,6 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri Status: &status, UserId: &userinfo.UserId, ZipCode: &req.ZipCode, - IsDefault: &isDefautl, } created, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { @@ -82,7 +80,6 @@ func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, useri Status: &status, UserId: &userinfo.UserId, ZipCode: &req.ZipCode, - IsDefault: &req.IsDefault, } // 插入数据库 更新地址 diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index 606dea84..b53a3978 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -49,9 +49,8 @@ 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结构体 @@ -66,7 +65,6 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U Status: &status, UserId: &userinfo.UserId, ZipCode: &req.ZipCode, - IsDefault: &isDefautl, } address, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { From b6d4d06c2502d6c5a94ea3c6d70c756a0827fccf Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 16:01:22 +0800 Subject: [PATCH 26/33] fix --- .../internal/logic/getproductsteppricelogic.go | 12 ++++++++---- utils/format/number.go | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index bf5bc09d..9c8454ba 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -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 @@ -111,7 +115,7 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity)) stepRange = append(stepRange, map[string]interface{}{ "range_description": fmt.Sprintf(">=%s Units", begin), - "item_price": format.CentitoDollar(rangeInfo.Price, 3), + "item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3), }) break } @@ -119,7 +123,7 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity)) stepRange = append(stepRange, map[string]interface{}{ "range_description": fmt.Sprintf("%s-%s Units", begin, end), - "item_price": format.CentitoDollar(rangeInfo.Price, 3), + "item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3), }) } mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ diff --git a/utils/format/number.go b/utils/format/number.go index d4912c5e..a4a0b2ec 100644 --- a/utils/format/number.go +++ b/utils/format/number.go @@ -8,11 +8,12 @@ import ( // 数字变成带千分位的字符串 func NumToStringWithThousandthPercentile(numberStr string) string { + numberStr = strings.TrimLeft(numberStr, "0") //去掉左边开始的0 if _, err := strconv.ParseFloat(numberStr, 64); err != nil { log.Fatalln("is not a number") return "" } - sliceList := strings.Split(numberStr, ".") + sliceList := strings.Split(numberStr, ".") //切分开小数 s := sliceList[0] f := "" if len(sliceList) == 2 { From 142ada5b075003976449108dd680cd5b019802f6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 16:09:28 +0800 Subject: [PATCH 27/33] fix --- utils/format/number.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/format/number.go b/utils/format/number.go index a4a0b2ec..dec25c3c 100644 --- a/utils/format/number.go +++ b/utils/format/number.go @@ -1,7 +1,7 @@ package format import ( - "log" + "github.com/zeromicro/go-zero/core/logx" "strconv" "strings" ) @@ -10,7 +10,7 @@ import ( func NumToStringWithThousandthPercentile(numberStr string) string { numberStr = strings.TrimLeft(numberStr, "0") //去掉左边开始的0 if _, err := strconv.ParseFloat(numberStr, 64); err != nil { - log.Fatalln("is not a number") + logx.Error("is not a number") return "" } sliceList := strings.Split(numberStr, ".") //切分开小数 From 1dfa390557b54928e50dffc4519d54eb34d42b4b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 16:16:33 +0800 Subject: [PATCH 28/33] fix --- model/gmodel/fs_product_model3d_logic.go | 5 ++--- .../product/internal/logic/getrecommandproductlistlogic.go | 1 + server/product/internal/logic/gettagproductlistlogic.go | 1 + .../internal/logic/homepagerecommendproductlistlogic.go | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index c84373b1..7f399a01 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "fusenapi/constants" - "github.com/zeromicro/go-zero/core/logx" "sort" ) @@ -186,11 +185,11 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI switch *modelInfo.Tag { case constants.TAG_MODEL: //模型 if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { - return errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + mapModelMinPrice[modelInfo.Id] = 0 + continue } var stepPrice StepPriceJsonStruct if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { - logx.Error(err) return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) } lenRange := len(stepPrice.PriceRange) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index b65c3cb1..24721e95 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -94,6 +94,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec //获取产品最低价 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.CodeDbSqlErr, "failed to get product min price") } //获取产品标签相关属性 diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index fdc951e6..a3861e39 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -229,6 +229,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn } //获取产品最低价格 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") } //获取模板 diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index eeb5726b..a4447811 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -114,6 +114,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty //获取产品最低价格 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") } //获取模板(只是获取产品product_id) From b6d0ef1c7c37ecad8f005b6792689e5206c7081e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 16:36:38 +0800 Subject: [PATCH 29/33] fix --- model/gmodel/fs_product_model3d_logic.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 7f399a01..92a54a39 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -194,7 +194,8 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI } lenRange := len(stepPrice.PriceRange) if lenRange == 0 { - return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + mapModelMinPrice[modelInfo.Id] = 0 + continue } sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool { return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price From 50c5e283814bd7426482200bcf23bfd9b2d8d76e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 16:51:29 +0800 Subject: [PATCH 30/33] fix --- server/product/internal/logic/getproductsteppricelogic.go | 6 ++++++ utils/format/number.go | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index 9c8454ba..71bba318 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -126,6 +126,11 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep "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, @@ -133,6 +138,7 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep "max_price": maxPrice, "step_range": stepRange, "min_buy_units_quantity": stepPrice.MinBuyUnitsNum, + "min_buy_units_quantity_item_price": format.CentitoDollar(minBuyUnitsQuantityPrice, 3), } } return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) diff --git a/utils/format/number.go b/utils/format/number.go index dec25c3c..3782ac74 100644 --- a/utils/format/number.go +++ b/utils/format/number.go @@ -8,7 +8,6 @@ import ( // 数字变成带千分位的字符串 func NumToStringWithThousandthPercentile(numberStr string) string { - numberStr = strings.TrimLeft(numberStr, "0") //去掉左边开始的0 if _, err := strconv.ParseFloat(numberStr, 64); err != nil { logx.Error("is not a number") return "" From 13420cd400ce794fca1ccfe8fdb2e5909b7bed48 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 17:01:30 +0800 Subject: [PATCH 31/33] fix --- .../internal/logic/getsizebypidlogic.go | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/server/product/internal/logic/getsizebypidlogic.go b/server/product/internal/logic/getsizebypidlogic.go index 7f27f40e..f59c6108 100644 --- a/server/product/internal/logic/getsizebypidlogic.go +++ b/server/product/internal/logic/getsizebypidlogic.go @@ -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") From 60749646e23d81b0873706a466d722d381a171aa Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 17:03:15 +0800 Subject: [PATCH 32/33] fix --- server/product/internal/logic/getproductsteppricelogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index 71bba318..1c59f729 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -138,6 +138,7 @@ 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), } } From 8bce140dd2f1389c32b10786513bd273d6750c87 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 17:10:17 +0800 Subject: [PATCH 33/33] fix --- server/product/internal/logic/getproductsteppricelogic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index 1c59f729..60527bcf 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -114,6 +114,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep if rIndex+1 == rangeLen { begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity)) stepRange = append(stepRange, map[string]interface{}{ + "start": rangeInfo.StartQuantity, + "end": rangeInfo.EndQuantity, "range_description": fmt.Sprintf(">=%s Units", begin), "item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3), }) @@ -122,6 +124,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity)) end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity)) stepRange = append(stepRange, map[string]interface{}{ + "start": rangeInfo.StartQuantity, + "end": rangeInfo.EndQuantity, "range_description": fmt.Sprintf("%s-%s Units", begin, end), "item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3), })