bcactionlogic.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/init"
  6. util2 "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/util"
  7. "log"
  8. "time"
  9. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/bxbase"
  10. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/internal/svc"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type BCActionLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewBCActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BCActionLogic {
  19. return &BCActionLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 招标信息收藏
  26. func (l *BCActionLogic) BCAction(in *bxbase.BCActionReq) (*bxbase.LabelActionRes, error) {
  27. var (
  28. insertCollKey = []string{"userid", "bid", "buyerclass", "buyerinfo", "winnerinfo", "createdate"}
  29. //insertCollKey2 = []string{"userid", "bid", "labelid", "buyerclass", "buyerinfo", "winnerinfo", "createdate"}
  30. )
  31. var i = 0
  32. ok, msg := true, ""
  33. insertValue := []interface{}{}
  34. maxCount := 10
  35. isPay, _ := util2.Power(in.UserId)
  36. redisArr := []string{}
  37. if isPay {
  38. maxCount = 5000
  39. }
  40. //已收藏的次数
  41. collCount := IC.MainMysql.Count("bdcollection", map[string]interface{}{"userid": in.UserId})
  42. collMap := map[string]bool{}
  43. for _, v := range util2.IsCollByBids("", in.UserId) {
  44. collMap[v] = true
  45. }
  46. //格式化数据
  47. info := util2.FormatColl(in.Bids)
  48. for _, bd := range info {
  49. queryMap := map[string]interface{}{
  50. "bid": util2.DecodeId(bd.Bid),
  51. "userid": in.UserId,
  52. }
  53. redisArr = append(redisArr, util2.DecodeId(bd.Bid))
  54. //移除收藏
  55. if in.Baction == "R" {
  56. if IC.MainMysql.Delete("bdcollection", queryMap) {
  57. i++
  58. } else {
  59. log.Printf("userid :%s,取消收藏失败 id : %s", in.UserId, util2.DecodeId(bd.Bid))
  60. }
  61. } else {
  62. //if db.Mysql.Count(db.DbConf.Bdcollection, queryMap) == 0 {
  63. if int(collCount) >= maxCount {
  64. ok, msg = false, common.If(isPay, "付费用户收藏已达上限", "免费用户收藏已达上限").(string)
  65. log.Printf("userid :%s,收藏失败 id : %s ,已收藏数量:%v ,上限数量:%v", in.UserId, util2.DecodeId(bd.Bid), collCount, maxCount)
  66. } else {
  67. if collMap[util2.DecodeId(bd.Bid)] {
  68. log.Printf("userid :%s,已收藏 id : %s", in.UserId, util2.DecodeId(bd.Bid))
  69. } else {
  70. insertValue = append(insertValue, in.UserId, util2.DecodeId(bd.Bid), util2.PushMapping.Buyerclass[bd.Buyerclass], bd.Buyerinfo, bd.Winnerinfo, time.Now().Format("2006-01-02 15:04:05"))
  71. collCount++
  72. i++
  73. }
  74. }
  75. }
  76. }
  77. //批量插入
  78. if len(insertValue)/len(insertCollKey) > 0 {
  79. x, _ := IC.MainMysql.InsertBatch("bdcollection", insertCollKey, insertValue)
  80. if x < 0 {
  81. log.Printf("userid :%s收藏失败", in.UserId)
  82. }
  83. }
  84. typ := "a" //新增
  85. if in.Baction == "R" {
  86. typ = "d" //删除
  87. }
  88. if bl := util2.UpdateCollListRedis(typ, in.UserId, redisArr); !bl { //更新redis
  89. log.Println("更新redis失败", in.UserId)
  90. }
  91. sta, _ := common.If(ok, i <= len(in.Bids), ok).(bool)
  92. return &bxbase.LabelActionRes{
  93. ErrMsg: msg,
  94. Status: sta,
  95. }, nil
  96. }