This commit is contained in:
laodaming 2023-07-11 17:08:19 +08:00
parent 406d62a894
commit 98c5727c7e
60 changed files with 407 additions and 161 deletions

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -64,22 +64,22 @@ func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTyp
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProduct{}).
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
return resp,err
return resp, err
}
func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []*FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
return resp, err
}
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int,fields ...string) (resp []FsProduct, err error) {
if len(ids) == 0{
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context, ids []int64, limit int, fields ...string) (resp []FsProduct, err error) {
if len(ids) == 0 {
return
}
db := p.db.WithContext(ctx).Model(&FsProduct{}).
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit)
if len(fields) != 0{
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids, 0, 1).Order("RAND()").Limit(limit)
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Find(&resp).Error
return resp,err
}
return resp, err
}

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -27,15 +27,16 @@ func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort
type CountProductSizeByStatusRsp struct {
ProductId int64 `json:"product_id"`
Num int64 `json:"num"`
Num int64 `json:"num"`
}
func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context,productIds []int64, status int) (resp []CountProductSizeByStatusRsp, err error) {
func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context, productIds []int64, status int) (resp []CountProductSizeByStatusRsp, err error) {
err = s.db.WithContext(ctx).Model(&FsProductSize{}).
Select("product_id,count(*) as num").
Where("`product_id` in (?) and `status` = ?",productIds ,status).
Where("`product_id` in (?) and `status` = ?", productIds, status).
Group("product_id").
Find(&resp).Error
return resp,err
return resp, err
}
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
if len(productIds) == 0 {

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -75,28 +75,29 @@ func (t *FsProductTemplateV2Model) FindOneByModelId(ctx context.Context, modelId
type GetProductTemplateListByParamsReq struct {
ProductIds []int64 //必传哦
GroupBy string
OrderBy string
Fields string
Status *int64
GroupBy string
OrderBy string
Fields string
Status *int64
}
func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Context, req GetProductTemplateListByParamsReq) (resp []FsProductTemplateV2, err error) {
if len(req.ProductIds) == 0{
if len(req.ProductIds) == 0 {
return
}
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?)",req.ProductIds)
if req.GroupBy != ""{
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?)", req.ProductIds)
if req.GroupBy != "" {
db = db.Group(req.GroupBy)
}
if req.OrderBy != ""{
if req.OrderBy != "" {
db = db.Order(req.OrderBy)
}
if req.Fields != ""{
if req.Fields != "" {
db = db.Select(req.Fields)
}
if req.Status != nil{
db = db.Where("`status` = ?",req.Status)
if req.Status != nil {
db = db.Where("`status` = ?", req.Status)
}
err = db.Find(&resp).Error
return resp, err
}
}

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -1,2 +1,3 @@
package gmodel
// TODO: 使用model的属性做你想做的
// TODO: 使用model的属性做你想做的

View File

@ -2,10 +2,12 @@ package logic
import (
"context"
"errors"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"gorm.io/gorm"
"github.com/zeromicro/go-zero/core/logx"
)
@ -35,6 +37,9 @@ func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.Us
user, err := m.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user is not exists")
}
logx.Error(err)
return resp.SetStatus(basic.CodeServiceErr)
}

View File

@ -43,12 +43,12 @@ func (l *GetOrderInvoiceLogic) GetOrderInvoice(req *types.GetOrderInvoiceReq, us
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user not found")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
}
if user.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user not found")
}
if req.Sn == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
}

View File

@ -0,0 +1,78 @@
package handler
import (
"errors"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/server/product/internal/logic"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
)
func GetRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
// 定义错误变量
err error
// 定义用户信息变量
userinfo *auth.UserInfo
)
// 解析JWT token,并对空用户进行判断
claims, err := svcCtx.ParseJwtToken(r)
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 401, // 返回401状态码,表示未授权
Message: "unauthorized", // 返回未授权信息
})
logx.Info("unauthorized:", err.Error()) // 记录错误日志
return
}
if claims != nil {
// 从token中获取对应的用户信息
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 401,
Message: "unauthorized",
})
logx.Info("unauthorized:", err.Error())
return
}
} else {
// 如果claims为nil,则认为用户身份为白板用户
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
var req types.GetRecommandProductListReq
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据
if err := httpx.Parse(r, &req); err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
Code: 510,
Message: "parameter error",
})
logx.Info(err)
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetRecommandProductListLogic(r.Context(), svcCtx)
resp := l.GetRecommandProductList(&req, userinfo)
// 如果响应不为nil则使用httpx.OkJsonCtx方法返回JSON响应;
if resp != nil {
httpx.OkJsonCtx(r.Context(), w, resp)
} else {
err := errors.New("server logic is error, resp must not be nil")
httpx.ErrorCtx(r.Context(), w, err)
logx.Error(err)
}
}
}

View File

@ -52,6 +52,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/product/other-list",
Handler: OtherProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/recommand",
Handler: GetRecommandProductListHandler(serverCtx),
},
},
)
}

View File

@ -35,9 +35,6 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// 获取产品列表
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
}
//如果是demo
if req.IsDemo == 1 {
var demo types.GetProductListRsp
@ -54,16 +51,13 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//查询用户信息
//查询用户信息(不用判断存在)
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
userInfo, err := userModel.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
}
if userInfo.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "user not exists")
}
//查询符合的产品列表
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
productList, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, "sort-desc")
@ -124,13 +118,13 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
}
//获取产品尺寸数量
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
productSizeCountList, err := productSizeModel.GetGroupProductSizeByStatus(l.ctx, productIds,1)
productSizeCountList, err := productSizeModel.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
}
mapProductSizeCount := make(map[int64]int64)
for _,v := range productSizeCountList{
for _, v := range productSizeCountList {
mapProductSizeCount[v.ProductId] = v.Num
}
//拼接返回
@ -143,7 +137,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
continue
}
sizeNum := int64(0)
if mapSizeNum,ok := mapProductSizeCount[v.Id];ok{
if mapSizeNum, ok := mapProductSizeCount[v.Id]; ok {
sizeNum = mapSizeNum
}
item := types.Items{
@ -157,19 +151,22 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
MiniPrice: minPrice,
}
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(*userInfo.IsThousandFace),
IsThousandFace: 0,
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,
ProductId: v.Id,
UserInfo: userInfo,
UserId: user.Id,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
item.Cover = thousandFaceImageFormatReq.Cover
item.CoverImg = thousandFaceImageFormatReq.CoverImg
item.CoverDefault = thousandFaceImageFormatReq.CoverDefault
if user.Id != 0 {
r.IsThousandFace = int(*user.IsThousandFace)
}
image.ThousandFaceImageFormat(&r)
item.Cover = r.Cover
item.CoverImg = r.CoverImg
item.CoverDefault = r.CoverDefault
itemList = append(itemList, item)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{

View File

@ -0,0 +1,79 @@
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 GetRecommandProductListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommandProductListLogic {
return &GetRecommandProductListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Num = 8 //目前写死
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//随机取产品列表
productList, err := l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx, int(req.Num))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend product list")
}
if len(productList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
//获取用户信息(不用判断存在)
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")
}
list := make([]types.GetRecommandProductListRsp, 0, len(productList))
for _, v := range productList {
r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: 0,
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.Cover,
ProductId: v.Id,
UserId: userinfo.UserId,
}
if user.Id != 0 {
r.IsThousandFace = int(*user.IsThousandFace)
}
image.ThousandFaceImageFormat(&r)
list = append(list, types.GetRecommandProductListRsp{
Id: v.Id,
Sn: *v.Sn,
Title: *v.Title,
TitleCn: *v.TitleCn,
Cover: r.Cover,
CoverImg: r.CoverImg,
CoverDefault: r.CoverDefault,
Intro: *v.Intro,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
}

View File

@ -2,6 +2,7 @@ package logic
import (
"context"
"errors"
"fusenapi/model/gmodel"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
@ -9,6 +10,7 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type GetSuccessRecommandLogic struct {
@ -33,13 +35,10 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
//获取用户信息
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
if err != nil {
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
}
if user.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
}
if req.Num == 0 || req.Num > 500 {
req.Num = 8
}
@ -66,19 +65,22 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
SkuId: 0, //???????
}
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(*user.IsThousandFace),
IsThousandFace: 0,
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,
ProductId: v.Id,
UserInfo: user,
UserId: user.Id,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
data.Cover = thousandFaceImageFormatReq.Cover
data.CoverImg = thousandFaceImageFormatReq.CoverImg
data.CoverDefault = thousandFaceImageFormatReq.CoverDefault
if user.Id > 0 {
r.IsThousandFace = int(*user.IsThousandFace)
}
image.ThousandFaceImageFormat(&r)
data.Cover = r.Cover
data.CoverImg = r.CoverImg
data.CoverDefault = r.CoverDefault
list = append(list, data)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)

View File

@ -32,106 +32,103 @@ func NewOtherProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
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 > 100{
if req.Num <= 0 || req.Num > 100 {
req.Num = 4
}
if req.Size > 0{
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取用户信息
user,err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx,userinfo.UserId)
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 info")
}
tagInfo, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, req.Cid)
if err != nil {
if errors.Is(err,gorm.ErrRecordNotFound){
return resp.SetStatusWithMessage(basic.CodeUnAuth,"user not exists")
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 user info")
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tage info")
}
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.Status != 1 {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "tage info is not available")
}
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
return resp.SetStatusWithMessage(basic.CodeOK,"success")
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
pids,err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct,","))
if err != nil{
pids, err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr,"failed to parse recommend product")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse recommend product")
}
list,err := l.getRandom(pids,int(req.Num))
if err != nil{
list, err := l.getRandom(pids, int(req.Num))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get random list")
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random list")
}
if req.Size <= 0{
return resp.SetStatusWithMessage(basic.CodeOK,"success,",list)
if req.Size <= 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success,", list)
}
//千人前面处理
for _,v := range list{
for _, v := range list {
r := &image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(*user.IsThousandFace),
IsThousandFace: 0,
Cover: v.Cover,
CoverImg: v.CoverImg,
CoverDefault: "",
ProductId: v.Id,
UserInfo: user,
UserId: user.Id,
}
if user.Id > 0 {
r.IsThousandFace = int(*user.IsThousandFace)
}
image.ThousandFaceImageFormat(r)
v.Cover = r.Cover
v.CoverImg = r.CoverImg
v.CoverDefault = r.CoverDefault
}
return resp.SetStatusWithMessage(basic.CodeOK,"success,",list)
return resp.SetStatusWithMessage(basic.CodeOK, "success,", list)
}
func (l *OtherProductListLogic) getRandom(productIds []int64,limit int)(result []types.OtherProductListRsp,err error){
if len(productIds) == 0{
func (l *OtherProductListLogic) getRandom(productIds []int64, limit int) (result []types.OtherProductListRsp, err error) {
if len(productIds) == 0 {
return
}
//获取推荐产品信息
recommendProductList,err := l.svcCtx.AllModels.FsProduct.GetRandomProductListInIds(l.ctx,productIds,limit)
if err != nil{
recommendProductList, err := l.svcCtx.AllModels.FsProduct.GetRandomProductListInIds(l.ctx, productIds, limit)
if err != nil {
return nil, err
}
if len(recommendProductList) == 0{
if len(recommendProductList) == 0 {
return
}
mapProduct := make(map[int64]int)
newProductIds := make([]int64,0,len(recommendProductList))
for k,v := range recommendProductList{
newProductIds = append(newProductIds,v.Id)
newProductIds := make([]int64, 0, len(recommendProductList))
for k, v := range recommendProductList {
newProductIds = append(newProductIds, v.Id)
mapProduct[v.Id] = k
}
//查询最新的sku
reqStatus := int64(1)
productTemplateIds,err := l.svcCtx.AllModels.FsProductTemplateV2.GetProductTemplateListByParams(l.ctx,gmodel.GetProductTemplateListByParamsReq{
ProductIds: newProductIds,
GroupBy: "product_id",
OrderBy: "id DESC,sort DESC",
Fields: "product_id,max(id) as id",
Status: &reqStatus,
productTemplateIds, err := l.svcCtx.AllModels.FsProductTemplateV2.GetProductTemplateListByParams(l.ctx, gmodel.GetProductTemplateListByParamsReq{
ProductIds: newProductIds,
GroupBy: "product_id",
OrderBy: "id DESC,sort DESC",
Fields: "product_id,max(id) as id",
Status: &reqStatus,
})
if err != nil{
return nil,err
if err != nil {
return nil, err
}
for _,v := range productTemplateIds{
productIndex,ok := mapProduct[*v.ProductId]
if !ok{
for _, v := range productTemplateIds {
productIndex, ok := mapProduct[*v.ProductId]
if !ok {
continue
}
productInfo := recommendProductList[productIndex]
result = append(result,types.OtherProductListRsp{
result = append(result, types.OtherProductListRsp{
Title: *productInfo.Title,
Cover: *productInfo.Cover,
CoverImg: *productInfo.CoverImg,
@ -140,5 +137,5 @@ func (l *OtherProductListLogic) getRandom(productIds []int64,limit int)(result [
SkuId: v.Id,
})
}
return result,nil
}
return result, nil
}

View File

@ -231,6 +231,23 @@ type OtherProductListRsp struct {
SkuId int64 `json:"sku_id"`
}
type GetRecommandProductListReq struct {
Size uint32 `form:"size"`
Num int64 `form:"num"`
Sn string `form:"sn"`
}
type GetRecommandProductListRsp struct {
Id int64 `json:"id"`
Sn string `json:"sn"`
Title string `json:"title"`
TitleCn string `json:"title_cn"`
Cover string `json:"cover"`
CoverImg string `json:"cover_img"`
CoverDefault string `json:"cover_default"`
Intro string `json:"intro"`
}
type Request struct {
}

View File

@ -13,7 +13,7 @@ service product {
//获取产品列表
@handler GetProductListHandler
get /product/list(GetProductListReq) returns (response);
//获取成功后推荐产品
//获取支付成功后推荐产品
@handler GetSuccessRecommandHandler
get /product/success-recommand (GetSuccessRecommandReq) returns (response);
//获取分类下的产品以及尺寸
@ -34,6 +34,9 @@ service product {
//其他产品推荐列表
@handler OtherProductListHandler
get /product/other-list (OtherProductListReq) returns (response);
//获取详情页推荐产品列表
@handler GetRecommandProductListHandler
get /product/recommand (GetRecommandProductListReq) returns (response);
}
//获取产品列表
@ -68,7 +71,7 @@ type Items {
MiniPrice int64 `json:"miniPrice"`
CoverDefault string `json:"coverDefault"`
}
//获取成功后推荐产品
//获取支付成功后推荐产品
type GetSuccessRecommandReq {
Num uint32 `form:"num"`
Size uint32 `form:"size"`
@ -240,4 +243,20 @@ type OtherProductListRsp {
Sn string `json:"sn"`
Id int64 `json:"id"`
SkuId int64 `json:"sku_id"`
}
//获取详情页推荐产品列表
type GetRecommandProductListReq {
Size uint32 `form:"size"`
Num int64 `form:"num"`
Sn string `form:"sn"`
}
type GetRecommandProductListRsp {
Id int64 `json:"id"`
Sn string `json:"sn"`
Title string `json:"title"`
TitleCn string `json:"title_cn"`
Cover string `json:"cover"`
CoverImg string `json:"cover_img"`
CoverDefault string `json:"cover_default"`
Intro string `json:"intro"`
}

View File

@ -3,7 +3,6 @@ package image
import (
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"strings"
"time"
)
@ -41,7 +40,7 @@ type ThousandFaceImageFormatReq struct {
CoverImg string
CoverDefault string
ProductId int64
UserInfo gmodel.FsUser
UserId int64
}
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
@ -61,7 +60,7 @@ func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
req.Cover = ""
req.CoverDefault = req.CoverImg
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserInfo.Id, req.UserInfo.Id, req.ProductId, time.Now().Unix())
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserId, req.UserId, req.ProductId, time.Now().Unix())
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
}