1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package handler
- import (
- "context"
- "fmt"
- "github.com/gogf/gf/v2/os/gcfg"
- "github.com/gogf/gf/v2/os/gctx"
- "time"
- "app.yhyue.com/moapp/jyPoints/rpc/integral"
- "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/go-logger/logger"
- "app.yhyue.com/moapp/jybase/redis"
- . "app.yhyue.com/moapp/message/client"
- "app.yhyue.com/moapp/message/model"
- )
- const (
- Redis_Main = "main"
- )
- var VarPoints = &Points{}
- type Points struct {
- }
- // Jy_user_new 产生新用户
- func (p *Points) Jy_user_new(msg *model.Message) {
- p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_new", nil).Int64(), 1002)
- }
- // Jywx_subscribe_invite 邀请人
- func (p *Points) Jywx_subscribe_invite(msg *model.Message) {
- p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_invite", nil).Int64(), 1003)
- }
- // Jywx_subscribe_invited 被邀请人
- func (p *Points) Jywx_subscribe_invited(msg *model.Message) {
- p.integralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_invited", nil).Int64(), 1002)
- }
- // Jydocs_doc_open 打开文库文章页
- func (p *Points) Jydocs_doc_open(msg *model.Message) {
- p.Jy_open(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jydocs_doc_open", nil).Int64())
- }
- // Jyweb_article_open 打开招投标信息文章页
- func (p *Points) Jyweb_article_open(msg *model.Message) {
- p.Jy_open(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jyweb_article_open", nil).Int64())
- }
- //
- func (p *Points) Jy_open(msg *model.Message, point int64) {
- key := fmt.Sprintf("jypoints_share_article_open_%s", msg.E_userId)
- openMax := gcfg.Instance().MustGet(gctx.New(), "docPoints.open.max", nil).Int64()
- if redis.Incr(Redis_Main, key) <= openMax {
- now := time.Now()
- _ = redis.SetExpire(Redis_Main, key, int(time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix()-now.Unix()))
- p.integralHarvest(msg, point, 1005)
- } else {
- logger.Info(fmt.Sprintf("%+v", msg), "超过一天最大次数", openMax, "限制,不再增加积分")
- }
- }
- //增加积分
- func (p *Points) integralHarvest(msg *model.Message, point, pointType int64) bool {
- t := time.Unix(msg.E_time, 0).AddDate(1, 0, 0)
- req := &integral.Req{
- UserId: msg.E_userId,
- AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(),
- PointType: pointType,
- Point: point,
- EndDate: date.FormatDate(&t, date.Date_Full_Layout),
- OperationType: false,
- }
- resp, err := integralclient.NewIntegral(ZrpcClient).IntegralHarvest(context.Background(), req)
- if err != nil {
- logger.Info(fmt.Sprintf("%+v", msg), "IntegralHarvest Resp error", err)
- return false
- }
- if resp.Code == 1 {
- logger.Info(fmt.Sprintf("%+v", msg), "已成功增加", point, "积分")
- return true
- } else {
- logger.Info(fmt.Sprintf("%+v", msg), "增加", point, "积分失败", "Code", resp.Code, "Message", resp.Message)
- return false
- }
- }
|