points.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package handler
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/os/gcfg"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. "time"
  8. "app.yhyue.com/moapp/jyPoints/rpc/integral"
  9. "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
  10. "app.yhyue.com/moapp/jybase/date"
  11. "app.yhyue.com/moapp/jybase/go-logger/logger"
  12. "app.yhyue.com/moapp/jybase/redis"
  13. . "app.yhyue.com/moapp/message/client"
  14. "app.yhyue.com/moapp/message/model"
  15. )
  16. const (
  17. Redis_Main = "main"
  18. )
  19. var VarPoints = &Points{}
  20. type Points struct {
  21. }
  22. // Jy_user_new 产生新用户
  23. func (p *Points) Jy_user_new(msg *model.Message) {
  24. p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_new", nil).Int64(), 1002)
  25. }
  26. // Jywx_subscribe_invite 邀请人
  27. func (p *Points) Jywx_subscribe_invite(msg *model.Message) {
  28. p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_invite", nil).Int64(), 1003)
  29. }
  30. // Jywx_subscribe_invited 被邀请人
  31. func (p *Points) Jywx_subscribe_invited(msg *model.Message) {
  32. p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_invited", nil).Int64(), 1002)
  33. }
  34. // Jydocs_doc_open 打开文库文章页
  35. func (p *Points) Jydocs_doc_open(msg *model.Message) {
  36. p.Jy_open(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jydocs_doc_open", nil).Int64())
  37. }
  38. // Jyweb_article_open 打开招投标信息文章页
  39. func (p *Points) Jyweb_article_open(msg *model.Message) {
  40. p.Jy_open(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jyweb_article_open", nil).Int64())
  41. }
  42. //
  43. func (p *Points) Jy_open(msg *model.Message, point int64) {
  44. key := fmt.Sprintf("jypoints_share_article_open_%s", msg.E_userId)
  45. openMax := gcfg.Instance().MustGet(gctx.New(), "docPoints.open.max", nil).Int64()
  46. if redis.Incr(Redis_Main, key) <= openMax {
  47. now := time.Now()
  48. _ = redis.SetExpire(Redis_Main, key, int(time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix()-now.Unix()))
  49. p.integralHarvest(msg, point, 1005)
  50. } else {
  51. logger.Info(fmt.Sprintf("%+v", msg), "超过一天最大次数", openMax, "限制,不再增加积分")
  52. }
  53. }
  54. //增加积分
  55. func (p *Points) integralHarvest(msg *model.Message, point, pointType int64) bool {
  56. t := time.Unix(msg.E_time, 0).AddDate(1, 0, 0)
  57. req := &integral.Req{
  58. UserId: msg.E_userId,
  59. AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(),
  60. PointType: pointType,
  61. Point: point,
  62. EndDate: date.FormatDate(&t, date.Date_Full_Layout),
  63. OperationType: false,
  64. }
  65. resp, err := integralclient.NewIntegral(ZrpcClient).IntegralHarvest(context.Background(), req)
  66. if err != nil {
  67. logger.Info(fmt.Sprintf("%+v", msg), "IntegralHarvest Resp error", err)
  68. return false
  69. }
  70. if resp.Code == 1 {
  71. logger.Info(fmt.Sprintf("%+v", msg), "已成功增加", point, "积分")
  72. return true
  73. } else {
  74. logger.Info(fmt.Sprintf("%+v", msg), "增加", point, "积分失败", "Code", resp.Code, "Message", resp.Message)
  75. return false
  76. }
  77. }