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

This commit is contained in:
momo 2023-10-11 12:11:24 +08:00
commit 58d44a38a6
8 changed files with 46 additions and 16 deletions

View File

@ -38,14 +38,14 @@ func FsBool(v bool) *bool {
// SubscriptionStatus 订阅状态 // SubscriptionStatus 订阅状态
type SubscriptionStatus struct { type SubscriptionStatus struct {
NotificationEmail *struct { NotificationEmail struct {
OrderUpdate bool `json:"order_update"` OrderUpdate bool `json:"order_update"`
Newseleter bool `json:"newseleter"` Newseleter bool `json:"newseleter"`
} `json:"notification_email"` } `json:"notification_email"`
NotificationPhone *struct { NotificationPhone struct {
OrderUpdate bool `json:"order_update"` // OrderUpdate bool `json:"order_update"`
Newseleter bool `json:"newseleter"` Newseleter bool `json:"newseleter"`
} `json:"notification_phone"` } `json:"notification_phone"`
} }

View File

@ -47,6 +47,10 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
return resp.SetStatus(basic.CodeOAuthEmailErr) return resp.SetStatus(basic.CodeOAuthEmailErr)
} }
if len(req.Email) > 50 {
return resp.SetStatusWithMessage(basic.CodeOAuthEmailErr, "email len must < 50")
}
if !TimeLimit.Is(req.Email) { if !TimeLimit.Is(req.Email) {
return resp.SetStatus(basic.CodeEmailTimeShortErr) return resp.SetStatus(basic.CodeEmailTimeShortErr)
} }

View File

@ -41,6 +41,10 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
return resp.SetStatus(basic.CodeOAuthEmailErr) return resp.SetStatus(basic.CodeOAuthEmailErr)
} }
if len(req.Email) > 50 {
return resp.SetStatusWithMessage(basic.CodeOAuthEmailErr, "email len must < 50")
}
// _, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(l.ctx, req.Email) // _, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(l.ctx, req.Email)
// if err == nil { // if err == nil {
// return resp.SetStatus(basic.CodeEmailExistsErr) // return resp.SetStatus(basic.CodeEmailExistsErr)

View File

@ -39,6 +39,10 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null // userinfo 传入值时, 一定不为null
if len(req.NewPassword) > 30 {
return resp.SetStatusWithMessage(basic.CodePasswordErr, "password len must < 30")
}
rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.ResetToken) // ResetToken rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.ResetToken) // ResetToken
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)

View File

@ -39,7 +39,7 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
user, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(context.TODO(), req.Email) user, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(context.TODO(), req.Email)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatus(basic.CodeRequestParamsErr, err.Error()) return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, err.Error())
} }
token := &auth.ResetToken{ token := &auth.ResetToken{

View File

@ -113,10 +113,12 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
mapTagLevel := make(map[string]*types.TagItem) mapTagLevel := make(map[string]*types.TagItem)
//处理tags数据 //处理tags数据
minLevel := 0 //层级最高层即prefix层级路径最短 minLevel := 0 //层级最高层即prefix层级路径最短
mapTagProduct := make(map[int64]types.TagProduct)
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{ if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
TagList: tagList, TagList: tagList,
WithProduct: req.WithProduct, WithProduct: req.WithProduct,
ProductList: productList, ProductList: productList,
MapTagProduct: mapTagProduct,
MapTagProp: mapTagProp, MapTagProp: mapTagProp,
MapProductMinPrice: mapProductMinPrice, MapProductMinPrice: mapProductMinPrice,
MapProductTemplate: mapProductTemplate, MapProductTemplate: mapProductTemplate,
@ -132,7 +134,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data") return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
} }
//组装等级从属关系 //组装等级从属关系
rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel) rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel, productList, mapTagProduct)
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{ return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
TotalCategoryProduct: TotalCategoryProduct, TotalCategoryProduct: TotalCategoryProduct,
TagList: rspTagList, TagList: rspTagList,
@ -262,6 +264,7 @@ type dealWithTagMenuDataReq struct {
TagList []gmodel.FsTags TagList []gmodel.FsTags
WithProduct bool WithProduct bool
ProductList []gmodel.FsProduct ProductList []gmodel.FsProduct
MapTagProduct map[int64]types.TagProduct
MapTagProp map[int64][]types.CoverDefaultItem MapTagProp map[int64][]types.CoverDefaultItem
ProductTagPropList []gmodel.FsProductTagProp ProductTagPropList []gmodel.FsProductTagProp
MapProductMinPrice map[int64]int64 MapProductMinPrice map[int64]int64
@ -308,7 +311,8 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
}) })
//tag中产品 //tag中产品
for _, tmpProduct := range productListRsp { for _, tmpProduct := range productListRsp {
tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct) tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct.ProductId)
req.MapTagProduct[tmpProduct.ProductId] = tmpProduct
} }
} }
//加入分类 //加入分类
@ -318,7 +322,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
} }
// 组织等级从属关系 // 组织等级从属关系
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) (rspTagList []types.TagItem, productCount int) { func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem, productList []gmodel.FsProduct, mapTagProduct map[int64]types.TagProduct) (rspTagList []types.TagItem, productCount int) {
mapTop := make(map[string]struct{}) mapTop := make(map[string]struct{})
//设置归属关系 //设置归属关系
for prefix, tagItem := range mapTagLevel { for prefix, tagItem := range mapTagLevel {
@ -341,16 +345,29 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
}) })
mapTagLevel[parentPrefix] = parent mapTagLevel[parentPrefix] = parent
} }
//把子类的产品列表变成产品id列表并且把产品列表都放到最顶级父级中 //顶层集子类产品于一身
for _, v := range mapTagLevel { for _, v := range mapTagLevel {
if _, ok := mapTop[v.LevelPrefix]; ok { if _, ok := mapTop[v.LevelPrefix]; !ok {
continue continue
} }
topPrefixSlic := strings.Split(v.LevelPrefix, "/")[:minLevel] //初始化
topPrefix := strings.Join(topPrefixSlic, "/") v.TagProductList = make([]interface{}, 0, 20)
for k, tmpProduct := range v.TagProductList { mapTypeId := make(map[int64]struct{})
v.TagProductList[k] = tmpProduct.(types.TagProduct).ProductId for _, v2 := range mapTagLevel {
mapTagLevel[topPrefix].TagProductList = append(mapTagLevel[topPrefix].TagProductList, tmpProduct) if strings.Contains(v2.LevelPrefix, v.LevelPrefix) {
mapTypeId[v2.TypeId] = struct{}{}
}
}
for _, p := range productList {
_, ok := mapTypeId[*p.Type]
if !ok {
continue
}
tagProduct, ok := mapTagProduct[p.Id]
if !ok {
continue
}
v.TagProductList = append(v.TagProductList, tagProduct)
} }
} }
//最终值提取最高级别那一层出来 //最终值提取最高级别那一层出来

View File

@ -118,7 +118,7 @@ func ValidateEmail(email string) bool {
// ValidatePassword checks if the provided password is strong enough. // ValidatePassword checks if the provided password is strong enough.
// In this example, we just check if the password length is 8 or more. // In this example, we just check if the password length is 8 or more.
func ValidatePassword(password string) bool { func ValidatePassword(password string) bool {
const minPasswordLength = 8 const minPasswordLength = 30
return len(password) >= minPasswordLength return len(password) >= minPasswordLength
} }

View File

@ -58,6 +58,7 @@ var (
CodeEmailExistsErr = &StatusResponse{5053, "email exists"} // email存在 CodeEmailExistsErr = &StatusResponse{5053, "email exists"} // email存在
CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email重发的时间太短 CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email重发的时间太短
CodeResetPasswordErr = &StatusResponse{5054, "reset password error"} // 无效密码 CodeResetPasswordErr = &StatusResponse{5054, "reset password error"} // 无效密码
CodeEmailErr = &StatusResponse{5054, "email error"}
CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内 CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内
CodeTemplateErr = &StatusResponse{5040, "template parsed error"} // 模板解析错误 CodeTemplateErr = &StatusResponse{5040, "template parsed error"} // 模板解析错误