feat:新增商户列表/保存用户信息
This commit is contained in:
commit
fde5ef8b25
|
@ -10,6 +10,15 @@ import (
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
|
func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *FsMerchantCategory, err error) {
|
||||||
|
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
|
||||||
|
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
func (m *FsMerchantCategoryModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB {
|
func (m *FsMerchantCategoryModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB {
|
||||||
if selectData != nil {
|
if selectData != nil {
|
||||||
return m.db.WithContext(ctx).Select(selectData)
|
return m.db.WithContext(ctx).Select(selectData)
|
||||||
|
|
|
@ -101,3 +101,14 @@ func (d *FsProductModel3dModel) FindOneJoinSize(ctx context.Context, productId i
|
||||||
Order("s.sort ASC").Take(&resp).Error
|
Order("s.sort ASC").Take(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *FsProductModel3dModel) GetOneBySizeIdTag(ctx context.Context, sizeId int64, tag int64, fields ...string) (resp *FsProductModel3d, err error) {
|
||||||
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).
|
||||||
|
Where("`size_id` = ? and `tag` = ? and `status` = ?", sizeId, tag, 1).
|
||||||
|
Order("sort DESC")
|
||||||
|
if len(fields) != 0 {
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
|
err = db.Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// fs_product_recommend 推荐商品表
|
|
||||||
type FsProductRecommend struct {
|
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
|
||||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID
|
|
||||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常
|
|
||||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
|
||||||
}
|
|
||||||
type FsProductRecommendModel struct {
|
|
||||||
db *gorm.DB
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFsProductRecommendModel(db *gorm.DB) *FsProductRecommendModel {
|
|
||||||
return &FsProductRecommendModel{db: db, name: "fs_product_recommend"}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package gmodel
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GetRecommendProductListReq struct {
|
|
||||||
Ctx context.Context
|
|
||||||
Page int
|
|
||||||
Limit int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) {
|
|
||||||
db := r.db.WithContext(req.Ctx).
|
|
||||||
Table("fs_product_recommend as r").
|
|
||||||
Joins("inner join fs_product as p on r.product_id = p.id").
|
|
||||||
Where("r.status = ? ", 1).
|
|
||||||
Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1)
|
|
||||||
if err = db.Limit(1).Count(&total).Error; err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
db = db.Select("p.*")
|
|
||||||
offset := (req.Page - 1) * req.Limit
|
|
||||||
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
|
|
||||||
return resp, total, err
|
|
||||||
}
|
|
||||||
func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, data *FsProductRecommend) error {
|
|
||||||
var info FsProductRecommend
|
|
||||||
err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Take(&info).Error
|
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.Id == 0 {
|
|
||||||
return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Create(data).Error
|
|
||||||
}
|
|
||||||
return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Updates(data).Error
|
|
||||||
}
|
|
|
@ -140,22 +140,6 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取产品某个物料下的第一个模板
|
|
||||||
func (t *FsProductTemplateV2Model) GetSizeLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) {
|
|
||||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
|
||||||
Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0).
|
|
||||||
Order("sort ASC").Take(&resp).Error
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取产品第一个物料下的第一个模板
|
|
||||||
func (t *FsProductTemplateV2Model) GetProductLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) {
|
|
||||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
|
||||||
Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0).
|
|
||||||
Order("sort ASC").Take(&resp).Error
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取产品在指定模板标签下的所有模板
|
// 获取产品在指定模板标签下的所有模板
|
||||||
func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) {
|
func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) {
|
||||||
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||||
|
|
|
@ -62,7 +62,6 @@ type AllModelsGen struct {
|
||||||
FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表
|
FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表
|
||||||
FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃)
|
FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃)
|
||||||
FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表
|
FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表
|
||||||
FsProductRecommend *FsProductRecommendModel // fs_product_recommend 推荐商品表
|
|
||||||
FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design
|
FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design
|
||||||
FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表
|
FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表
|
||||||
FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表
|
FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表
|
||||||
|
@ -159,7 +158,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||||
FsProductModel3dLight: NewFsProductModel3dLightModel(gdb),
|
FsProductModel3dLight: NewFsProductModel3dLightModel(gdb),
|
||||||
FsProductOption: NewFsProductOptionModel(gdb),
|
FsProductOption: NewFsProductOptionModel(gdb),
|
||||||
FsProductPrice: NewFsProductPriceModel(gdb),
|
FsProductPrice: NewFsProductPriceModel(gdb),
|
||||||
FsProductRecommend: NewFsProductRecommendModel(gdb),
|
|
||||||
FsProductRenderDesign: NewFsProductRenderDesignModel(gdb),
|
FsProductRenderDesign: NewFsProductRenderDesignModel(gdb),
|
||||||
FsProductScene: NewFsProductSceneModel(gdb),
|
FsProductScene: NewFsProductSceneModel(gdb),
|
||||||
FsProductSize: NewFsProductSizeModel(gdb),
|
FsProductSize: NewFsProductSizeModel(gdb),
|
||||||
|
|
|
@ -113,14 +113,27 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//获取用户信息(不用判断存在)
|
//获取用户信息(不用判断存在)
|
||||||
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) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user")
|
||||||
|
}*/
|
||||||
|
//获取产品标签相关属性
|
||||||
|
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
|
||||||
|
}
|
||||||
|
mapTagProp := make(map[int64][]types.CoverDefaultItem)
|
||||||
|
for _, v := range productTagPropList {
|
||||||
|
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||||
|
Tag: v.Title,
|
||||||
|
Cover: *v.Cover,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
|
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
|
||||||
for _, v := range recommendProductList {
|
for _, v := range recommendProductList {
|
||||||
r := image.ThousandFaceImageFormatReq{
|
/*r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: 0,
|
IsThousandFace: 0,
|
||||||
Cover: *v.Cover,
|
Cover: *v.Cover,
|
||||||
|
@ -133,7 +146,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
r.IsThousandFace = int(*user.IsThousandFace)
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
}
|
}
|
||||||
//千人前面处理
|
//千人前面处理
|
||||||
image.ThousandFaceImageFormat(&r)
|
image.ThousandFaceImageFormat(&r)*/
|
||||||
isRecommend := int64(0)
|
isRecommend := int64(0)
|
||||||
if _, ok := mapRecommend[v.Id]; ok {
|
if _, ok := mapRecommend[v.Id]; ok {
|
||||||
isRecommend = 1
|
isRecommend = 1
|
||||||
|
@ -142,18 +155,22 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
if minVal, ok := mapProductMinPrice[v.Id]; ok {
|
if minVal, ok := mapProductMinPrice[v.Id]; ok {
|
||||||
minPrice = minVal
|
minPrice = minVal
|
||||||
}
|
}
|
||||||
list = append(list, types.GetRecommandProductListRsp{
|
item := types.GetRecommandProductListRsp{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Sn: *v.Sn,
|
Sn: *v.Sn,
|
||||||
Title: *v.Title,
|
Title: *v.Title,
|
||||||
TitleCn: *v.TitleCn,
|
TitleCn: *v.TitleCn,
|
||||||
Cover: r.Cover,
|
Cover: *productInfo.Cover,
|
||||||
CoverImg: r.CoverImg,
|
CoverImg: *productInfo.CoverImg,
|
||||||
CoverDefault: r.CoverDefault,
|
CoverDefault: []types.CoverDefaultItem{},
|
||||||
Intro: *v.Intro,
|
Intro: *v.Intro,
|
||||||
IsRecommend: isRecommend,
|
IsRecommend: isRecommend,
|
||||||
MinPrice: minPrice,
|
MinPrice: minPrice,
|
||||||
})
|
}
|
||||||
|
if _, ok := mapTagProp[productInfo.Id]; ok {
|
||||||
|
item.CoverDefault = mapTagProp[productInfo.Id]
|
||||||
|
}
|
||||||
|
list = append(list, item)
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,12 +366,13 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||||
MinPrice: minPrice,
|
MinPrice: minPrice,
|
||||||
HaveOptionalFitting: haveOptionalFitting,
|
HaveOptionalFitting: haveOptionalFitting,
|
||||||
Recommended: *productInfo.IsRecommend > 0,
|
Recommended: *productInfo.IsRecommend > 0,
|
||||||
|
Cover: *productInfo.Cover,
|
||||||
}
|
}
|
||||||
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
||||||
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
||||||
}
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
r := image.ThousandFaceImageFormatReq{
|
/*r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: 0,
|
IsThousandFace: 0,
|
||||||
Cover: *productInfo.Cover,
|
Cover: *productInfo.Cover,
|
||||||
|
@ -383,7 +384,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||||
r.IsThousandFace = int(*req.User.IsThousandFace)
|
r.IsThousandFace = int(*req.User.IsThousandFace)
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&r)
|
image.ThousandFaceImageFormat(&r)
|
||||||
item.Cover = r.Cover
|
item.Cover = r.Cover*/
|
||||||
//加入分类产品切片
|
//加入分类产品切片
|
||||||
productListRsp = append(productListRsp, item)
|
productListRsp = append(productListRsp, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -40,7 +40,6 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
||||||
if req.ProductTemplateTagId <= 0 {
|
if req.ProductTemplateTagId <= 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品信息(只获取id)
|
//获取产品信息(只获取id)
|
||||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,46 +49,77 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||||
}
|
}
|
||||||
//获取该产品该模板标签下的模板列表(只获取id)
|
//没有指定物料
|
||||||
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.
|
sizeIds := make([]int64, 0, 10)
|
||||||
GetListByProductAndTemplateTag(l.ctx, fmt.Sprintf("%d", req.ProductTemplateTagId), productInfo.Id, "id")
|
if req.ProductSizeId <= 0 {
|
||||||
if err != nil {
|
//获取产品所有物料
|
||||||
logx.Error(err)
|
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get templates")
|
if err != nil {
|
||||||
}
|
logx.Error(err)
|
||||||
if len(templateList) == 0 {
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get product size list")
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "templates are not exists")
|
|
||||||
}
|
|
||||||
templateIds := make([]int64, 0, len(templateList))
|
|
||||||
for _, v := range templateList {
|
|
||||||
templateIds = append(templateIds, v.Id)
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
templateInfo *gmodel.FsProductTemplateV2
|
|
||||||
)
|
|
||||||
//传了指定物料,则获取该物料的第一个模板
|
|
||||||
if req.ProductSizeId > 0 {
|
|
||||||
templateInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.GetSizeLatestTemplate(l.ctx, templateIds, productInfo.Id)
|
|
||||||
} else { //没有指定物料则获取第一个物料的第一个模板
|
|
||||||
templateInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.GetProductLatestTemplate(l.ctx, templateIds, productInfo.Id)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info not found")
|
|
||||||
}
|
}
|
||||||
|
if len(sizeList) == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product size list is empty")
|
||||||
|
}
|
||||||
|
for _, v := range sizeList {
|
||||||
|
sizeIds = append(sizeIds, v.Id)
|
||||||
|
}
|
||||||
|
} else { //指定物料
|
||||||
|
sizeIds = append(sizeIds, req.ProductSizeId)
|
||||||
|
}
|
||||||
|
//根据尺寸id获取模型
|
||||||
|
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL)
|
||||||
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
|
||||||
}
|
}
|
||||||
if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" {
|
if len(modelList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "template info is not set")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty")
|
||||||
}
|
}
|
||||||
var info interface{}
|
modelIds := make([]int64, 0, len(modelList))
|
||||||
if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil {
|
mapModel := make(map[int64]int)
|
||||||
|
for k, v := range modelList {
|
||||||
|
modelIds = append(modelIds, v.Id)
|
||||||
|
mapModel[v.Id] = k
|
||||||
|
}
|
||||||
|
//查询模型ids下对应tag标签的模板
|
||||||
|
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "")
|
||||||
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse json product template info:", templateInfo.Id)
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list")
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateByPidRsp{
|
rsp := make(map[string]interface{})
|
||||||
TemplateId: templateInfo.Id,
|
for _, templateInfo := range templateList {
|
||||||
TemplateInfo: info,
|
//没有设置模板据不要
|
||||||
})
|
if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
modelIndex, ok := mapModel[*templateInfo.ModelId]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//基础模板信息
|
||||||
|
var info map[string]map[string]interface{}
|
||||||
|
if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id))
|
||||||
|
}
|
||||||
|
//后台隐藏/显示信息
|
||||||
|
var switchInfo interface{}
|
||||||
|
if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" {
|
||||||
|
_ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo)
|
||||||
|
}
|
||||||
|
modelInfo := modelList[modelIndex]
|
||||||
|
var material interface{}
|
||||||
|
if info["module_data"] != nil && info["module_data"]["material"] != nil {
|
||||||
|
material = info["module_data"]["material"]
|
||||||
|
}
|
||||||
|
mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId)
|
||||||
|
rsp[mapKey] = map[string]interface{}{
|
||||||
|
"id": templateInfo.Id,
|
||||||
|
"material": material,
|
||||||
|
"material_data": switchInfo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -36,28 +35,51 @@ func NewHomePageRecommendProductListLogic(ctx context.Context, svcCtx *svc.Servi
|
||||||
|
|
||||||
func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
//查询用户信息(不用判断存在)
|
//查询用户信息(不用判断存在)
|
||||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
_, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
merchantInfo *gmodel.FsMerchantCategory
|
||||||
recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||||
mapProductHaveOptionFitting = make(map[int64]struct{})
|
mapProductHaveOptionFitting = make(map[int64]struct{}) //是否有配件map
|
||||||
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||||
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
||||||
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
||||||
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
||||||
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||||
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
||||||
)
|
)
|
||||||
|
//选了商家类型
|
||||||
|
if req.MerchantType > 0 {
|
||||||
|
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType)
|
||||||
|
} else {
|
||||||
|
//随机获取一个商家类型
|
||||||
|
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant type info")
|
||||||
|
}
|
||||||
|
if *merchantInfo.RecommendProduct == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||||
|
}
|
||||||
|
recommendProductIds, err := format.StrSlicToInt64Slice(strings.Split(*merchantInfo.RecommendProduct, ","))
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse recommend product")
|
||||||
|
}
|
||||||
//获取列表推荐产品
|
//获取列表推荐产品
|
||||||
recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{
|
recommendProductList, err = l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "sort-desc")
|
||||||
Ctx: l.ctx,
|
if err != nil {
|
||||||
Page: 1,
|
logx.Error(err)
|
||||||
Limit: 500, //设置最大500
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
|
||||||
})
|
}
|
||||||
if len(recommendProductList) == 0 {
|
if len(recommendProductList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||||
}
|
}
|
||||||
|
@ -125,6 +147,19 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
||||||
for _, v := range productSizeCountList {
|
for _, v := range productSizeCountList {
|
||||||
mapProductSizeCount[v.ProductId] = v.Num
|
mapProductSizeCount[v.ProductId] = v.Num
|
||||||
}
|
}
|
||||||
|
//获取产品标签相关属性
|
||||||
|
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
|
||||||
|
}
|
||||||
|
mapTagProp := make(map[int64][]types.CoverDefaultItem)
|
||||||
|
for _, v := range productTagPropList {
|
||||||
|
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||||
|
Tag: v.Title,
|
||||||
|
Cover: *v.Cover,
|
||||||
|
})
|
||||||
|
}
|
||||||
//组装返回
|
//组装返回
|
||||||
listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList))
|
listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList))
|
||||||
for _, productInfo := range recommendProductList {
|
for _, productInfo := range recommendProductList {
|
||||||
|
@ -147,12 +182,17 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
||||||
Id: productInfo.Id,
|
Id: productInfo.Id,
|
||||||
Sn: *productInfo.Sn,
|
Sn: *productInfo.Sn,
|
||||||
Title: *productInfo.Title,
|
Title: *productInfo.Title,
|
||||||
|
Cover: *productInfo.Cover,
|
||||||
|
CoverDefault: []types.CoverDefaultItem{},
|
||||||
SizeNum: uint32(sizeNum),
|
SizeNum: uint32(sizeNum),
|
||||||
MinPrice: minPrice,
|
MinPrice: minPrice,
|
||||||
HaveOptionalFitting: haveOptionalFitting,
|
HaveOptionalFitting: haveOptionalFitting,
|
||||||
}
|
}
|
||||||
|
if _, ok = mapTagProp[productInfo.Id]; ok {
|
||||||
|
item.CoverDefault = mapTagProp[productInfo.Id]
|
||||||
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
r := image.ThousandFaceImageFormatReq{
|
/*r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: 0,
|
IsThousandFace: 0,
|
||||||
Cover: *productInfo.Cover,
|
Cover: *productInfo.Cover,
|
||||||
|
@ -166,7 +206,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&r)
|
image.ThousandFaceImageFormat(&r)
|
||||||
item.Cover = r.Cover
|
item.Cover = r.Cover
|
||||||
item.CoverDefault = r.CoverDefault
|
item.CoverDefault = r.CoverDefault*/
|
||||||
//加入分类产品切片
|
//加入分类产品切片
|
||||||
listRsp = append(listRsp, item)
|
listRsp = append(listRsp, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,16 +234,16 @@ type GetRecommandProductListReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetRecommandProductListRsp struct {
|
type GetRecommandProductListRsp struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
TitleCn string `json:"title_cn"`
|
TitleCn string `json:"title_cn"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
CoverDefault string `json:"cover_default"`
|
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||||
Intro string `json:"intro"`
|
Intro string `json:"intro"`
|
||||||
IsRecommend int64 `json:"is_recommend"`
|
IsRecommend int64 `json:"is_recommend"`
|
||||||
MinPrice int64 `json:"min_price"`
|
MinPrice int64 `json:"min_price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTagProductListReq struct {
|
type GetTagProductListReq struct {
|
||||||
|
@ -341,13 +341,8 @@ type GetSizeByPidRsp struct {
|
||||||
|
|
||||||
type GetTemplateByPidReq struct {
|
type GetTemplateByPidReq struct {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
|
||||||
ProductSizeId int64 `form:"product_size_id,optional"`
|
ProductSizeId int64 `form:"product_size_id,optional"`
|
||||||
}
|
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
||||||
|
|
||||||
type GetTemplateByPidRsp struct {
|
|
||||||
TemplateId int64 `json:"template_id"` //模板id
|
|
||||||
TemplateInfo interface{} `json:"template_info"` //模板信息
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetFittingByPidReq struct {
|
type GetFittingByPidReq struct {
|
||||||
|
@ -395,18 +390,19 @@ type GetLastProductDesignRsp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomePageRecommendProductListReq struct {
|
type HomePageRecommendProductListReq struct {
|
||||||
Size uint32 `form:"size"`
|
Size uint32 `form:"size"`
|
||||||
|
MerchantType int64 `form:"merchant_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomePageRecommendProductListRsp struct {
|
type HomePageRecommendProductListRsp struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
SizeNum uint32 `json:"size_num"`
|
SizeNum uint32 `json:"size_num"`
|
||||||
MinPrice int64 `json:"min_price"`
|
MinPrice int64 `json:"min_price"`
|
||||||
CoverDefault string `json:"cover_default"`
|
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||||
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
|
|
@ -183,10 +183,10 @@ func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo
|
||||||
//需要替换的参数
|
//需要替换的参数
|
||||||
replaceData := map[string]interface{}{
|
replaceData := map[string]interface{}{
|
||||||
"logo_url": parseInfo.RenderData.Logo,
|
"logo_url": parseInfo.RenderData.Logo,
|
||||||
"website": "",
|
"website": parseInfo.RenderData.Website,
|
||||||
"slogan": "",
|
"slogan": parseInfo.RenderData.Slogan,
|
||||||
"address": "",
|
"address": parseInfo.RenderData.Address,
|
||||||
"phone": "",
|
"phone": parseInfo.RenderData.Phone,
|
||||||
"colors": []string{},
|
"colors": []string{},
|
||||||
"template_tagid": []string{"b1a"},
|
"template_tagid": []string{"b1a"},
|
||||||
"is_crop": false,
|
"is_crop": false,
|
||||||
|
|
|
@ -286,16 +286,16 @@ type GetRecommandProductListReq {
|
||||||
Sn string `form:"sn"`
|
Sn string `form:"sn"`
|
||||||
}
|
}
|
||||||
type GetRecommandProductListRsp {
|
type GetRecommandProductListRsp {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
TitleCn string `json:"title_cn"`
|
TitleCn string `json:"title_cn"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
CoverDefault string `json:"cover_default"`
|
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||||
Intro string `json:"intro"`
|
Intro string `json:"intro"`
|
||||||
IsRecommend int64 `json:"is_recommend"`
|
IsRecommend int64 `json:"is_recommend"`
|
||||||
MinPrice int64 `json:"min_price"`
|
MinPrice int64 `json:"min_price"`
|
||||||
}
|
}
|
||||||
//获取分类产品列表
|
//获取分类产品列表
|
||||||
type GetTagProductListReq {
|
type GetTagProductListReq {
|
||||||
|
@ -386,12 +386,8 @@ type GetSizeByPidRsp {
|
||||||
//获取产品模板
|
//获取产品模板
|
||||||
type GetTemplateByPidReq {
|
type GetTemplateByPidReq {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
|
||||||
ProductSizeId int64 `form:"product_size_id,optional"`
|
ProductSizeId int64 `form:"product_size_id,optional"`
|
||||||
}
|
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
||||||
type GetTemplateByPidRsp {
|
|
||||||
TemplateId int64 `json:"template_id"` //模板id
|
|
||||||
TemplateInfo interface{} `json:"template_info"` //模板信息
|
|
||||||
}
|
}
|
||||||
//获取产品配件数据
|
//获取产品配件数据
|
||||||
type GetFittingByPidReq {
|
type GetFittingByPidReq {
|
||||||
|
@ -437,15 +433,16 @@ type GetLastProductDesignRsp {
|
||||||
}
|
}
|
||||||
//获取列表页推荐产品(返回是这个维度数组)
|
//获取列表页推荐产品(返回是这个维度数组)
|
||||||
type HomePageRecommendProductListReq {
|
type HomePageRecommendProductListReq {
|
||||||
Size uint32 `form:"size"`
|
Size uint32 `form:"size"`
|
||||||
|
MerchantType int64 `form:"merchant_type"`
|
||||||
}
|
}
|
||||||
type HomePageRecommendProductListRsp {
|
type HomePageRecommendProductListRsp {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
SizeNum uint32 `json:"size_num"`
|
SizeNum uint32 `json:"size_num"`
|
||||||
MinPrice int64 `json:"min_price"`
|
MinPrice int64 `json:"min_price"`
|
||||||
CoverDefault string `json:"cover_default"`
|
CoverDefault []CoverDefaultItem `json:"cover_default"`
|
||||||
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||||
}
|
}
|
|
@ -16,6 +16,10 @@ type RenderData struct {
|
||||||
ProductId int64 `json:"product_id"` //产品id
|
ProductId int64 `json:"product_id"` //产品id
|
||||||
UserMaterialId int64 `json:"user_material_id"` //用户素材id
|
UserMaterialId int64 `json:"user_material_id"` //用户素材id
|
||||||
Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值)
|
Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值)
|
||||||
|
Website string `json:"website"` //网站
|
||||||
|
Slogan string `json:"slogan"` //slogan
|
||||||
|
Address string `json:"address"` //地址
|
||||||
|
Phone string `json:"phone"` //电话
|
||||||
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
|
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
|
||||||
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
|
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user