userdocslogic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jy_docs/rpc/userlib/internal/svc"
  4. "app.yhyue.com/moapp/jy_docs/rpc/userlib/userlib"
  5. userLibService "app.yhyue.com/moapp/jy_docs/services/userlib"
  6. "context"
  7. "strings"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type UserDocsLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewUserDocsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDocsLogic {
  16. return &UserDocsLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. const (
  23. ProductTypeMemberFree = 1 // 商品类型 会员免费
  24. ProductTypePremium = 2 // 商品类型 精品文档
  25. )
  26. // 我的文档 收藏和兑换
  27. func (l *UserDocsLogic) UserDocs(in *userlib.UserDocsRequest) (*userlib.UserDocsResponse, error) {
  28. // todo: add your logic here and delete this line
  29. result := &userlib.UserDocsResponse{}
  30. data, count, code, msg := userLibService.UserDocsList(in)
  31. docList := []*userlib.UserDocs{}
  32. for _, value := range data {
  33. if value.IsDownload == 1 {
  34. value.Cost = "已购买"
  35. }
  36. // 因为tidb的历史数据没有处理 收藏列表需要展示商品类型 所以需要处理一下
  37. if value.ProductType == 0 && in.UserDocCategory == int64(1) {
  38. var flag bool
  39. tags := strings.Split(value.DocTags, ",")
  40. for i := 0; i < len(tags); i++ {
  41. if l.svcCtx.Config.JyPremiumTag[tags[i]] {
  42. // 说明是剑鱼精品文档
  43. flag = true
  44. value.ProductType = ProductTypePremium
  45. break
  46. }
  47. }
  48. if !flag {
  49. // 否则是剑鱼会员免费文档
  50. value.ProductType = ProductTypeMemberFree
  51. }
  52. }
  53. docList = append(docList, &userlib.UserDocs{
  54. CreateAt: value.CreateAt.Unix(),
  55. UpdateAt: value.UpdateAt.Unix(),
  56. DeletedAt: value.DeletedAt.Unix(),
  57. DocId: value.DocId,
  58. IsDelete: int64(value.IsDelete),
  59. DocName: value.DocName,
  60. DocFileType: int64(value.DocFileType),
  61. DocFileSuffix: value.DocFileSuffix,
  62. DocFileSize: int64(value.DocFileSize),
  63. DocPageSize: int64(value.DocPageSize),
  64. DocSummary: value.DocSummary,
  65. IsDownload: int64(value.IsDownload),
  66. IsCollection: int64(value.IsCollection),
  67. Cost: value.Cost,
  68. ProductType: value.ProductType,
  69. Source: value.Source,
  70. })
  71. }
  72. if code {
  73. result.Code = 1
  74. result.Message = msg
  75. result.Data = docList
  76. result.Count = count
  77. return result, nil
  78. }
  79. result.Code = 0
  80. result.Message = msg
  81. result.Data = docList
  82. result.Count = count
  83. return result, nil
  84. }