61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"fusenapi/utils/image"
|
|
"gorm.io/gorm"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/product/internal/svc"
|
|
"fusenapi/server/product/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type OtherProductListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewOtherProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OtherProductListLogic {
|
|
return &OtherProductListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
|
}
|
|
if req.Num <= 0 {
|
|
req.Num = 4
|
|
}
|
|
if req.Size > 0{
|
|
req.Size = image.GetCurrentSize(req.Size)
|
|
}
|
|
tagInfo,err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx,req.Cid)
|
|
if err != nil{
|
|
if errors.Is(err,gorm.ErrRecordNotFound){
|
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr,"the tag info is not exists")
|
|
}
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get tage info")
|
|
}
|
|
if *tagInfo.Status != 1{
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"tage info is not available")
|
|
}
|
|
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
|
|
return resp.SetStatusWithMessage(basic.CodeOK,"success")
|
|
}
|
|
//获取推荐产品信息
|
|
l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx,)
|
|
//TODO 明天再做
|
|
return resp.SetStatus(basic.CodeOK)
|
|
}
|