getsublistlogic.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package logic
  2. import (
  3. "context"
  4. IC "jyBXSubscribe/rpc/init"
  5. "jyBXSubscribe/rpc/internal/svc"
  6. "jyBXSubscribe/rpc/model"
  7. "jyBXSubscribe/rpc/type/bxsubscribe"
  8. "jyBXSubscribe/rpc/util"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetSubListLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewGetSubListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubListLogic {
  19. return &GetSubListLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 获取订阅推送列表
  26. func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubscribe.SubscribeInfosResp, error) {
  27. start := time.Now().Unix()
  28. //1、推送信息已读标识
  29. //超级订阅 i_apppushunread=0
  30. //大会员 i_member_apppushunread=0
  31. //商机管理 i_entniche_apppushunread=0
  32. if in.IsEnt {
  33. in.UserType = model.EntnicheFlag
  34. }
  35. if in.PageNum == 1 {
  36. go model.UpdateUserPushUnread(in.UserId, in.UserType)
  37. }
  38. isPayUser := false
  39. userInfo := util.GetVipState(IC.MainMysql, IC.Mgo, in.UserId)
  40. //付费用户
  41. if in.UserType != "fType" && userInfo.IsPayedUser() {
  42. isPayUser = true
  43. }
  44. spqp := &model.SubPushQueryParam{
  45. Mgo_bidding: IC.MgoBidding, //mongo
  46. Bidding: IC.DB.Mongo.Bidding.Collection, //招标信息 表
  47. Bidding_back: IC.DB.Mongo.Bidding.CollectionBack, //招标信息备份数据 表名
  48. UserId: in.UserId, //用户id
  49. PageNum: int(in.PageNum), //当前页码
  50. PageSize: int(in.PageSize), //每页多少条数据
  51. SelectTime: in.SelectTime, //时间跨度
  52. Area: in.Area, //省份
  53. City: in.City, //城市
  54. Buyerclass: in.BuyerClass, //采购单位类型
  55. Subtype: in.Subtype, //信息类型
  56. Subscopeclass: in.Industry, //行业
  57. Key: in.KeyWords, //关键词
  58. Price: in.Price, //价格区间
  59. FileExists: in.FileExists, //是否有附件
  60. EntId: in.EntId, //商机管理企业id
  61. EntUserId: in.EntUserId, //商机管理用户id
  62. DeptId: in.DeptId, //商机管理部门id
  63. NewUserId: in.NewUserId,
  64. BaseServiceMysql: IC.BaseServiceMysql,
  65. IsEnt: in.IsEnt,
  66. BuySubject: 0,
  67. UserType: in.UserType,
  68. IsPayUser: isPayUser,
  69. }
  70. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  71. infoCount := int64(0)
  72. if in.UserType == model.MemberFlag {
  73. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%大会员%' ", in.EntId)
  74. } else if in.UserType == model.SubVipFlag {
  75. infoCount = IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and product_type like '%VIP订阅%' ", in.EntId)
  76. }
  77. if infoCount > 0 {
  78. in.UserType = model.EntnicheFlag
  79. //主体等于企业的
  80. spqp.BuySubject = 1
  81. }
  82. if in.UserType == model.EntnicheFlag {
  83. spqp.UserId = common.InterfaceToStr(spqp.EntUserId)
  84. }
  85. hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp)
  86. start1 := time.Now().Unix()
  87. logx.Info("1、查询数据用户", start1-start)
  88. /*
  89. *无推送记录生成推送记录
  90. *免费用户默认推送50条
  91. *大会员、新版商机管理、超级订阅用户 默认推送1000条记录
  92. */
  93. if in.PageNum == 1 && spqp.IsEmpty() && len(list) == 0 && in.IsEnt == false {
  94. hasNextPage, total, list = model.NewSubscribePush(in.UserType).DefaultDatas(spqp)
  95. }
  96. start2 := time.Now().Unix()
  97. logx.Info("2、查询数据用户", start2-start1)
  98. //查询是否收藏
  99. model.NewSubscribePush(in.UserType).MakeCollection(in.UserId, list)
  100. start3 := time.Now().Unix()
  101. logx.Info("3、查询数据用户", start3-start2)
  102. logx.Info("总共查询数据用户", start3-start)
  103. return &bxsubscribe.SubscribeInfosResp{
  104. Data: &bxsubscribe.SubscribeData{
  105. List: list,
  106. Count: total,
  107. HasNextPage: hasNextPage,
  108. },
  109. }, nil
  110. }