diff --git a/model/gmodel/fs_admin_role_gen.go b/model/gmodel/fs_admin_role_gen.go index 498a4a09..15dfeb91 100644 --- a/model/gmodel/fs_admin_role_gen.go +++ b/model/gmodel/fs_admin_role_gen.go @@ -23,6 +23,7 @@ type FsAdminRole struct { DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人 IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否 MenuAuth *[]byte `gorm:"default:'';" json:"menu_auth"` // + ApiAuth *[]byte `gorm:"default:'';" json:"api_auth"` // } type FsAdminRoleModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_collection_gen.go b/model/gmodel/fs_product_collection_gen.go new file mode 100644 index 00000000..320376a2 --- /dev/null +++ b/model/gmodel/fs_product_collection_gen.go @@ -0,0 +1,27 @@ +package gmodel + +import ( + "gorm.io/gorm" + "time" +) + +// fs_product_collection 产品收藏表 +type FsProductCollection struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id + UserId *int64 `gorm:"default:0;" json:"user_id"` // 用户id + GuestId *int64 `gorm:"default:0;" json:"guest_id"` // 游客id + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id + TemplateTag *string `gorm:"default:'';" json:"template_tag"` // + SelectColorIndex *int64 `gorm:"default:0;" json:"select_color_index"` // 选择的颜色索引 + Logo *string `gorm:"default:'';" json:"logo"` // logo地址 + 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"` // +} +type FsProductCollectionModel struct { + db *gorm.DB + name string +} + +func NewFsProductCollectionModel(db *gorm.DB) *FsProductCollectionModel { + return &FsProductCollectionModel{db: db, name: "fs_product_collection"} +} diff --git a/model/gmodel/fs_product_collection_logic.go b/model/gmodel/fs_product_collection_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_collection_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index 96ae7dea..b29f8e91 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -67,6 +67,7 @@ type AllModelsGen struct { FsPay *FsPayModel // fs_pay 支付记录 FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志 FsProduct *FsProductModel // fs_product 产品表 + FsProductCollection *FsProductCollectionModel // fs_product_collection 产品收藏表 FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表 FsProductDesign *FsProductDesignModel // fs_product_design 产品设计表 FsProductDesignGather *FsProductDesignGatherModel // fs_product_design_gather @@ -178,6 +179,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { FsPay: NewFsPayModel(gdb), FsPayEvent: NewFsPayEventModel(gdb), FsProduct: NewFsProductModel(gdb), + FsProductCollection: NewFsProductCollectionModel(gdb), FsProductCopy1: NewFsProductCopy1Model(gdb), FsProductDesign: NewFsProductDesignModel(gdb), FsProductDesignGather: NewFsProductDesignGatherModel(gdb), diff --git a/server/product/internal/handler/getproductlisthandler.go b/server/product/internal/handler/getproductlisthandler.go deleted file mode 100644 index 41360ef6..00000000 --- a/server/product/internal/handler/getproductlisthandler.go +++ /dev/null @@ -1,35 +0,0 @@ -package handler - -import ( - "net/http" - "reflect" - - "fusenapi/utils/basic" - - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" -) - -func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.GetProductListReq - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - - // 创建一个业务逻辑层实例 - l := logic.NewGetProductListLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.GetProductList(&req, userinfo) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/product/internal/handler/getsuccessrecommandhandler.go b/server/product/internal/handler/getsuccessrecommandhandler.go deleted file mode 100644 index 63bdeae3..00000000 --- a/server/product/internal/handler/getsuccessrecommandhandler.go +++ /dev/null @@ -1,35 +0,0 @@ -package handler - -import ( - "net/http" - "reflect" - - "fusenapi/utils/basic" - - "fusenapi/server/product/internal/logic" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" -) - -func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.GetSuccessRecommandReq - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - - // 创建一个业务逻辑层实例 - l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.GetSuccessRecommand(&req, userinfo) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go index 67db4302..e0a07c88 100644 --- a/server/product/internal/handler/routes.go +++ b/server/product/internal/handler/routes.go @@ -12,16 +12,6 @@ import ( func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ - { - Method: http.MethodGet, - Path: "/api/product/list", - Handler: GetProductListHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/api/product/success-recommand", - Handler: GetSuccessRecommandHandler(serverCtx), - }, { Method: http.MethodGet, Path: "/api/product/get-size-by-product", diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go deleted file mode 100644 index aa8d4daa..00000000 --- a/server/product/internal/logic/getproductlistlogic.go +++ /dev/null @@ -1,188 +0,0 @@ -package logic - -import ( - "context" - "encoding/json" - "errors" - "fusenapi/constants" - "fusenapi/model/gmodel" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" - "fusenapi/utils/auth" - "fusenapi/utils/basic" - "fusenapi/utils/format" - "fusenapi/utils/image" - "math" - "sort" - "strings" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/core/stores/sqlc" - "gorm.io/gorm" -) - -type GetProductListLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductListLogic { - return &GetProductListLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 获取产品列表 -func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) { - //如果是demo - if req.IsDemo == 1 { - var demo types.GetProductListRsp - if err := json.Unmarshal([]byte(constants.PRODUCT_LIST_DEMO), &demo); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "demo data format err") - } - return resp.SetStatusWithMessage(basic.CodeOK, "success", demo) - } - if req.Page <= 0 { - req.Page = constants.DEFAULT_PAGE - } - //获取合适尺寸 - if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) - } - pageSize := constants.DEFAULT_PAGE_SIZE - //查询用户信息(不用判断存在) - userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn) - 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") - } - //查询符合的产品列表 - productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn) - productList, total, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, int(req.Page), pageSize, "sort-desc") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") - } - productLen := len(productList) - if productLen == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success") - } - //提取产品ids - productIds := make([]int64, 0, productLen) - for _, v := range productList { - productIds = append(productIds, v.Id) - } - productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn) - productPriceList, err := productPriceModel.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) - mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) - } - //获取模板 - productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") - } - mapProductTemplate := make(map[int64]struct{}) - for _, v := range productTemplatesV2 { - mapProductTemplate[*v.ProductId] = struct{}{} - } - //获取分类 - tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn) - tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid) - if err != nil && !errors.Is(err, sqlc.ErrNotFound) { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not exists") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "get tag err") - } - //获取产品尺寸数量 - productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn) - 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 { - mapProductSizeCount[v.ProductId] = v.Num - } - //拼接返回 - itemList := make([]types.Items, 0, productLen) - for _, v := range productList { - minPrice, ok := mapProductMinPrice[v.Id] - _, tmpOk := mapProductTemplate[v.Id] - //无最小价格则不显示 || 没有模板也不显示 - if !ok || !tmpOk { - continue - } - sizeNum := int64(0) - if mapSizeNum, ok := mapProductSizeCount[v.Id]; ok { - sizeNum = mapSizeNum - } - item := types.Items{ - Id: v.Id, - Sn: *v.Sn, - Title: *v.Title, - Intro: *v.Intro, - IsEnv: *v.IsProtection, - IsMicro: *v.IsMicrowave, - SizeNum: uint32(sizeNum), - MinPrice: minPrice, - } - //千人千面处理 - r := image.ThousandFaceImageFormatReq{ - Size: int(req.Size), - IsThousandFace: 0, - Cover: *v.Cover, - CoverImg: *v.CoverImg, - CoverDefault: *v.CoverImg, - ProductId: v.Id, - UserId: user.Id, - } - if user.Id != 0 { - r.IsThousandFace = 1 - } - 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{ - Ob: types.Ob{ - Items: itemList, - Meta: types.Meta{ - TotalCount: total, - PageCount: int64(math.Ceil(float64(total) / float64(pageSize))), - CurrentPage: int(req.Page), - PerPage: pageSize, - }, - }, - TypeName: *tagInfo.Title, - Description: *tagInfo.Description, - }) -} diff --git a/server/product/internal/logic/getsuccessrecommandlogic.go b/server/product/internal/logic/getsuccessrecommandlogic.go deleted file mode 100644 index 6fa90620..00000000 --- a/server/product/internal/logic/getsuccessrecommandlogic.go +++ /dev/null @@ -1,88 +0,0 @@ -package logic - -import ( - "context" - "errors" - "fusenapi/model/gmodel" - "fusenapi/server/product/internal/svc" - "fusenapi/server/product/internal/types" - "fusenapi/utils/auth" - "fusenapi/utils/basic" - "fusenapi/utils/image" - - "github.com/zeromicro/go-zero/core/logx" - "gorm.io/gorm" -) - -type GetSuccessRecommandLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSuccessRecommandLogic { - return &GetSuccessRecommandLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 获取推荐的产品列表 -func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, userInfo *auth.UserInfo) (resp *basic.Response) { - if userInfo.GetIdType() != auth.IDTYPE_User { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first") - } - //获取用户信息 - userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn) - user, err := userModel.FindUserById(l.ctx, userInfo.UserId) - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info") - } - if req.Num == 0 || req.Num > 500 { - req.Num = 8 - } - if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) - } - //随机取8个产品 - productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn) - productList, err := productModel.GetRandomProductList(l.ctx, int(req.Num)) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") - } - //没有推荐产品就返回 - if len(productList) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success") - } - list := make([]types.GetSuccessRecommandRsp, 0, len(productList)) - for _, v := range productList { - data := types.GetSuccessRecommandRsp{ - Title: *v.Title, - Sn: *v.Sn, - Id: v.Id, - SkuId: 0, //??????? - } - //千人千面处理 - r := image.ThousandFaceImageFormatReq{ - Size: int(req.Size), - IsThousandFace: 0, - Cover: *v.Cover, - CoverImg: *v.CoverImg, - CoverDefault: *v.CoverImg, - ProductId: v.Id, - UserId: user.Id, - } - if user.Id > 0 { - r.IsThousandFace = int(1) - } - 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) -} diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index e1951538..33475691 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -5,54 +5,6 @@ import ( "fusenapi/utils/basic" ) -type GetProductListReq struct { - Cid int64 `form:"cid"` - Size uint32 `form:"size"` - Page uint32 `form:"page,optional"` - IsDemo uint32 `form:"is_demo,optional"` -} - -type GetProductListRsp struct { - Ob Ob `json:"ob"` - TypeName string `json:"typeName"` - Description string `json:"description"` -} - -type Ob struct { - Items []Items `json:"items"` - Meta Meta `json:"_meta"` -} - -type Items struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"isEnv"` - IsMicro int64 `json:"isMicro"` - SizeNum uint32 `json:"sizeNum"` - MinPrice int64 `json:"minPrice"` - CoverDefault string `json:"coverDefault"` -} - -type GetSuccessRecommandReq struct { - Num uint32 `form:"num"` - Size uint32 `form:"size"` - Sn string `form:"sn"` -} - -type GetSuccessRecommandRsp struct { - Title string `json:"title"` - Cover string `json:"cover"` - CoverImg string `json:"coverImg"` - Sn string `json:"sn"` - Id int64 `json:"id"` - SkuId int64 `json:"skuId"` - CoverDefault string `json:"coverDefault"` -} - type GetSizeByProductRsp struct { Id int64 `json:"id"` Name string `json:"name"` diff --git a/server_api/product.api b/server_api/product.api index 68bc4033..7485ebcd 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -10,12 +10,6 @@ info ( import "basic.api" service product { - //获取产品列表 - @handler GetProductListHandler - get /api/product/list(GetProductListReq) returns (response); - //获取支付成功后推荐产品 - @handler GetSuccessRecommandHandler - get /api/product/success-recommand(GetSuccessRecommandReq) returns (response); //获取分类下的产品以及尺寸 @handler GetSizeByProductHandler get /api/product/get-size-by-product(request) returns (response); @@ -83,51 +77,6 @@ service product { //*********************推荐产品接口结束×××××××××××××××××××××××××× } -//获取产品列表 -type GetProductListReq { - Cid int64 `form:"cid"` - Size uint32 `form:"size"` - Page uint32 `form:"page,optional"` - IsDemo uint32 `form:"is_demo,optional"` -} -type GetProductListRsp { - Ob Ob `json:"ob"` - TypeName string `json:"typeName"` - Description string `json:"description"` -} -type Ob { - Items []Items `json:"items"` - Meta Meta `json:"_meta"` -} -type Items { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"isEnv"` - IsMicro int64 `json:"isMicro"` - SizeNum uint32 `json:"sizeNum"` - MinPrice int64 `json:"minPrice"` - CoverDefault string `json:"coverDefault"` -} -//获取支付成功后推荐产品 -type GetSuccessRecommandReq { - Num uint32 `form:"num"` - Size uint32 `form:"size"` - Sn string `form:"sn"` -} -type GetSuccessRecommandRsp { - Title string `json:"title"` - Cover string `json:"cover"` - CoverImg string `json:"coverImg"` - Sn string `json:"sn"` - Id int64 `json:"id"` - SkuId int64 `json:"skuId"` - CoverDefault string `json:"coverDefault"` -} - //获取分类下的产品以及尺寸 type GetSizeByProductRsp { Id int64 `json:"id"`