wangkaiyue 3 éve
szülő
commit
13ef826f59

+ 51 - 13
etc/config.yaml

@@ -31,12 +31,13 @@ etcd:
 
 #消息队列
 nsq:
-  address: 192.168.3.206:4150
+  #address: 192.168.3.207:4150
+  address: 123.56.53.97:4161
 
 #数据库配置
 databases:
   # redis配置
-  redis: other=192.168.3.206:1712
+  redis: main=192.168.3.206:1712,other=192.168.3.206:1712
   # nsq操作日志库
   mogLog:
     address: 192.168.3.206:27090
@@ -53,16 +54,6 @@ databases:
     userName:
     password:
 
-#其他配置
-docPoints:
-  appId: 10000
-  jywx_subscribe_new: 100,
-  jywx_subscribe_invite: 500,
-  jywx_subscribe_invited: 600
-  open:
-    max: 5
-    jydocs_doc_open: 5
-    jyweb_article_open: 5
 #wx
 wx:
   wxJianyu:
@@ -70,4 +61,51 @@ wx:
     appsecret: d55898fde0b7887e5fe4660bd2494700
   weixinrpc: 127.0.0.1:8083
   pcSessionFlag: true
-  sessionTimeout: 168
+  sessionTimeout: 168
+
+#其他配置
+newUserAward:
+  points: 500
+
+inviteRegister: #分享裂变活动
+  rewardNumMax:
+    points: 2000
+    subvip: 28
+  invite:
+    points: 500
+    subvip: 7
+  invited:
+    points: 500
+    subvip: 7
+
+shareOpenDetail: #三级页分享
+  openDetail:
+    points: 5
+  rewardTimesMax: #邀请与被邀请奖励上限 2000剑鱼币、28天超级订阅
+    points: 5
+    cycle: day
+
+
+
+bidderPlan: # 临时活动
+  name: 投标人专属免费计划
+  code: bidderFreePlan
+  dateRange: #活动时间
+    st: 2022-05-01
+    ed: 2022-06-01
+  missions: #任务列表
+    subscribe: #订阅
+      points: 300
+      schedule: 3
+    invite: #邀请
+      points: 500
+      schedule: 5
+    improveInfo: #完善信息
+      points: 200
+      schedule: 2
+  scheduleReward: #进度奖励
+    8:
+      subvip: 7
+    10:
+      subvip: 30
+

+ 69 - 0
handler/activity/inviteRegister.go

@@ -0,0 +1,69 @@
+package activity
+
+import (
+	"app.yhyue.com/moapp/jybase/go-logger/logger"
+	"app.yhyue.com/moapp/message/handler/award"
+	"app.yhyue.com/moapp/message/model"
+	"fmt"
+	"github.com/gogf/gf/v2/os/gcfg"
+	"github.com/gogf/gf/v2/os/gctx"
+)
+
+/*
+分享裂变活动
+活动详情
+邀请新用户注册可获得剑鱼币和超级订阅奖励
+分享者可新用户都可获得500积分,7天超级订阅
+上限:2000剑鱼币 28天超级订阅
+*/
+
+const (
+	InviteRegisterActivityName = "inviteRegister"
+)
+
+// InviteActivity 邀请活动奖励
+func InviteActivity(msg *model.Message) {
+	// 超级订阅
+	subVipTimes, _ := award.GetActivityAwardDesc(msg.E_userId, InviteRegisterActivityName, award.AwardSubVip)
+	subVipMax := gcfg.Instance().MustGet(gctx.New(), "inviteRegister.rewardNumMax.subvip", nil).Int64()
+	if subVipTimes < subVipMax {
+		award.GivenSubVip(msg, award.SubVip{
+			Num:  gcfg.Instance().MustGet(gctx.New(), "inviteRegister.invite.subvip", nil).Int64(),
+			From: InviteRegisterActivityName,
+			Desc: "被邀请注册成功",
+		})
+	} else {
+		logger.Info(fmt.Sprintf("%+v", msg), msg.E_userId, "用户已达邀请奖励上限,停止赠送权益", subVipMax, "限制,不再增加超级订阅")
+	}
+
+	// 积分
+	pointsTimes, _ := award.GetActivityAwardDesc(msg.E_userId, InviteRegisterActivityName, award.AwardPoints)
+	pointsMax := gcfg.Instance().MustGet(gctx.New(), "inviteRegister.rewardNumMax.points", nil).Int64()
+	if pointsTimes < pointsMax {
+		award.GivenPoints(msg, award.Points{
+			Num:  gcfg.Instance().MustGet(gctx.New(), "inviteRegister.invite.points", nil).Int64(),
+			Type: 1003,
+			From: InviteRegisterActivityName,
+			Desc: "邀请好友成功",
+		})
+	} else {
+		logger.Info(fmt.Sprintf("%+v", msg), msg.E_userId, "用户已达邀请奖励上限,停止赠送权益", pointsMax, "限制,不再增加积分")
+	}
+}
+
+// InvitedActivity 被邀请奖励
+func InvitedActivity(msg *model.Message) {
+	// 超级订阅
+	award.GivenSubVip(msg, award.SubVip{
+		Num:  gcfg.Instance().MustGet(gctx.New(), "inviteRegister.invited.subvip", nil).Int64(),
+		From: InviteRegisterActivityName,
+		Desc: "被邀请注册成功",
+	})
+	// 积分
+	award.GivenPoints(msg, award.Points{
+		Num:  gcfg.Instance().MustGet(gctx.New(), "inviteRegister.invited.points", nil).Int64(),
+		Type: 1002,
+		From: InviteRegisterActivityName,
+		Desc: "被邀请注册成功",
+	})
+}

+ 27 - 0
handler/activity/newUserAward.go

@@ -0,0 +1,27 @@
+package activity
+
+import (
+	"app.yhyue.com/moapp/message/handler/award"
+	"app.yhyue.com/moapp/message/model"
+	"github.com/gogf/gf/v2/os/gcfg"
+	"github.com/gogf/gf/v2/os/gctx"
+)
+
+/*
+新用户注册奖励
+活动详情
+非邀请注册新用户可获得500剑鱼币奖励
+*/
+
+const (
+	NewUserAwardActivityName = "newUserAward"
+)
+
+func NewUserActivity(msg *model.Message) {
+	award.GivenPoints(msg, award.Points{
+		Num:  gcfg.Instance().MustGet(gctx.New(), "newUserAward.points", nil).Int64(),
+		Type: 1002,
+		From: NewUserAwardActivityName,
+		Desc: "被邀请注册成功",
+	})
+}

+ 46 - 0
handler/activity/shareOpen.go

@@ -0,0 +1,46 @@
+package activity
+
+import (
+	"app.yhyue.com/moapp/jybase/go-logger/logger"
+	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/message/handler/award"
+	"app.yhyue.com/moapp/message/model"
+	"fmt"
+	"github.com/gogf/gf/v2/os/gcfg"
+	"github.com/gogf/gf/v2/os/gctx"
+	"time"
+)
+
+const (
+	RedisMain                   = "main"
+	ShareOpenDetailActivityName = "ShareOpenDetail"
+)
+
+/*
+活动详情
+用户分享标讯详情或文库详情,
+可获得5剑鱼币,每天上限25个
+*/
+
+// ShareOpenDetail 分享打开三级页
+func ShareOpenDetail(msg *model.Message) {
+	if len(msg.E_body) == 0 {
+		return
+	}
+	openMax := gcfg.Instance().MustGet(gctx.New(), "shareOpenDetail.rewardTimesMax.points", nil).Int64()
+	pointsNum := gcfg.Instance().MustGet(gctx.New(), "shareOpenDetail.openDetail.points", nil).Int64()
+	key := fmt.Sprintf("jypoints_share_article_open_%s", msg.E_userId)
+	if redis.Incr(RedisMain, key) <= openMax {
+		now := time.Now()
+		_ = redis.SetExpire(RedisMain, key, int(time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix()-now.Unix()))
+		//积分奖励
+		award.GivenPoints(msg, award.Points{
+			Num:  pointsNum,
+			Type: 1005,
+			From: ShareOpenDetailActivityName,
+			Desc: "用户分享信息",
+		})
+	} else {
+		logger.Info(fmt.Sprintf("%+v", msg), "超过一天最大次数", openMax, "限制,不再增加积分")
+	}
+}

+ 50 - 0
handler/award/points.go

@@ -0,0 +1,50 @@
+package award
+
+import (
+	"app.yhyue.com/moapp/message/model"
+	"app.yhyue.com/moapp/message/rpc"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+/*// Jy_user_new 产生新用户
+func (p *Points) Jy_user_new(msg *model.Message) {
+	rpc.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) {
+	rpc.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) {
+	rpc.IntegralHarvest(msg, gcfg.Instance().MustGet(gctx.New(), "docPoints.open.jywx_subscribe_invited", nil).Int64(), 1002)
+}
+
+var VarPoints = &Points{}
+*/
+
+type Points struct {
+	Num, Type  int64  //数量,类型
+	From, Desc string //来源活动,描述
+}
+
+const (
+	AwardPoints = "points"
+)
+
+// GivenPoints 积分奖励
+func GivenPoints(msg *model.Message, p Points) {
+	//记录
+	if err := rpc.IntegralHarvest(msg, p.Num, p.Type); err == nil {
+		AddAwardRecord(AwardRecord{
+			UserId:       msg.E_userId,
+			Award:        AwardPoints,
+			Num:          gconv.Int(p.Num),
+			GetWay:       p.Desc,
+			ActivityCode: p.From,
+			Detail:       "",
+			Date:         msg.E_time,
+		})
+	}
+}

+ 33 - 0
handler/award/record.go

@@ -0,0 +1,33 @@
+package award
+
+import "app.yhyue.com/moapp/message/db"
+
+type AwardRecord struct {
+	UserId       string `json:"userId"`        //用户
+	Award        string `json:"award"`         //奖品 subvip(超级订阅,单位天)、points(积分,单位个)
+	Num          int    `json:"num"`           //数量
+	GetWay       string `json:"getWay"`        //获取方式
+	ActivityCode string `json:"activity_code"` //活动
+	Detail       string `json:"detail"`        //详情
+	Date         int64  `json:"date"`          //领取时间
+}
+
+//AddAwardRecord 增加领取记录
+func AddAwardRecord(record AwardRecord) {
+	db.Mgo.Save("activity_award", map[string]interface{}{
+		"activity_code": record.ActivityCode,
+		"detail":        record.Detail,
+		"userid":        record.UserId,
+		"award":         record.Award,
+		"num":           record.Num,
+		"getway":        record.GetWay,
+		"date":          record.Date,
+	})
+}
+
+// GetActivityAwardDesc 查询奖励详情
+// times 奖励次数
+// total 总量
+func GetActivityAwardDesc(userId, activity, award string) (times, total int64) {
+	return -1, -1
+}

+ 17 - 0
handler/award/subvip.go

@@ -0,0 +1,17 @@
+package award
+
+import "app.yhyue.com/moapp/message/model"
+
+const (
+	AwardSubVip = "subvip"
+)
+
+type SubVip struct {
+	Num        int64  //超级订阅 天
+	From, Desc string //来源活动,描述
+}
+
+// GivenSubVip 超级订阅奖励
+func GivenSubVip(msg *model.Message, sVip SubVip) {
+
+}

+ 14 - 9
handler/handler.go

@@ -1,6 +1,7 @@
 package handler
 
 import (
+	"app.yhyue.com/moapp/message/handler/activity"
 	"encoding/json"
 	"fmt"
 	"time"
@@ -14,15 +15,19 @@ import (
 
 var (
 	funcMap = map[string]func(msg *model.Message){
-		"jyapp_wx_register":      VarPoints.Jy_user_new,
-		"jyapp_phone_register":   VarPoints.Jy_user_new,
-		"jypc_phone_register":    VarPoints.Jy_user_new,
-		"jywx_subscribe_new":     VarPoints.Jy_user_new,
-		"jywx_subscribe_invite":  VarPoints.Jywx_subscribe_invite,
-		"jywx_subscribe_invited": VarPoints.Jywx_subscribe_invited,
-		"jydocs_doc_open":        VarPoints.Jydocs_doc_open,
-		"jyweb_article_open":     VarPoints.Jyweb_article_open,
-		"jywx_activity_message":  VarPush.Jywx_activity_message,
+		//新用户注册活动
+		"jyapp_wx_register":    activity.NewUserActivity,
+		"jyapp_phone_register": activity.NewUserActivity,
+		"jypc_phone_register":  activity.NewUserActivity,
+		"jywx_subscribe_new":   activity.NewUserActivity,
+		//邀请注册活动
+		"jywx_subscribe_invite":  activity.InviteActivity,  //邀请奖励
+		"jywx_subscribe_invited": activity.InvitedActivity, //被邀请奖励
+		//三级页分享活动
+		"jydocs_doc_open":    activity.ShareOpenDetail, //分享打开文库详情
+		"jyweb_article_open": activity.ShareOpenDetail, //分享打开标讯详情
+		//其他
+		"jywx_activity_message": VarPush.Jywx_activity_message,
 	}
 )
 

+ 0 - 89
handler/points.go

@@ -1,89 +0,0 @@
-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
-	}
-}

+ 53 - 0
rpc/integral.go

@@ -0,0 +1,53 @@
+package rpc
+
+import (
+	"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/message/model"
+	"fmt"
+	"github.com/gogf/gf/v2/os/gcfg"
+	"github.com/gogf/gf/v2/os/gctx"
+	"github.com/tal-tech/go-zero/core/discov"
+	"github.com/tal-tech/go-zero/zrpc"
+	"log"
+	"time"
+)
+
+var zrpcClient zrpc.Client
+
+func init() {
+	var err error
+	zrpcClient, err = zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.address", nil).Strings(),
+			Key:   gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.key", nil).String(),
+		},
+	})
+	if err != nil {
+		log.Fatalln(err)
+	}
+}
+
+func IntegralHarvest(msg *model.Message, point, pointType int64) error {
+	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(gctx.New(), req)
+	if err != nil {
+		return fmt.Errorf(fmt.Sprintf("%+v", msg), "IntegralHarvest Resp error", err)
+	}
+	if resp.Code == 1 {
+		logger.Info(fmt.Sprintf("%+v", msg), "已成功增加", point, "积分")
+		return nil
+	} else {
+		return fmt.Errorf(fmt.Sprintf("%+v", msg), "增加", point, "积分失败", "Code", resp.Code, "Message", resp.Message)
+	}
+}

+ 1 - 0
rpc/subvip.go

@@ -0,0 +1 @@
+package rpc

+ 57 - 0
services/activity/bidderPlan/entity.go

@@ -1 +1,58 @@
 package bidderPlan
+
+import (
+	"app.yhyue.com/moapp/message/db"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+type BidderPlan struct {
+	Schedule interface{} //进度
+	Missions interface{} //任务
+}
+
+// List 活动列表
+func (receiver *BidderPlan) List() (map[string]interface{}, error) {
+	return nil, nil
+}
+
+// CheckStatus 任务完成校验
+func (receiver *BidderPlan) CheckStatus(userId, flag string) (bool, error) {
+	return false, nil
+}
+
+// GetSchedule 获取进度
+func (receiver *BidderPlan) GetSchedule() {
+
+}
+
+// 订阅任务
+func subscribe(userId string) (finish bool) {
+	//非7天超级订阅或存在订阅内容则完成任务
+	res, ok := db.Mgo.FindById("user", userId, `{"i_vip_status":1,"o_vipjy":1,"l_vip_starttime":1,"l_vip_endtime":1,"i_member_status":1}`)
+	if !ok || res == nil || len(*res) == 0 {
+		return
+	}
+
+	if gconv.Int((*res)["i_vip_status"]) > 0 { //超级订阅
+		if gconv.Int((*res)["l_vip_starttime"])-gconv.Int((*res)["l_vip_endtime"]) > 7*24*60*60 { //非赠送
+
+		}
+	} else if gconv.Int((*res)["i_member_status"]) > 0 { //大会员
+		return true
+	} else if false { //商机管理
+
+	}
+	return
+}
+
+// 邀请任务
+func invite(userId string) bool {
+
+	return false
+}
+
+// 完善信息
+func improveInfo(userId string) bool {
+
+	return false
+}

+ 15 - 2
services/activity/bidderPlan/services.go

@@ -1,8 +1,9 @@
 package bidderPlan
 
 import (
-	. "app.yhyue.com/moapp/message/util"
+	. "app.yhyue.com/moapp/jybase/api"
 	"github.com/gogf/gf/v2/net/ghttp"
+	"log"
 )
 
 // Activity BidderPlan 投标人专属免费计划
@@ -11,7 +12,19 @@ type Activity struct{}
 // Schedule 活动进度
 // url /jyActivity/bidderPlan/schedule
 func (act *Activity) Schedule(r *ghttp.Request) {
+	userId := r.GetHeader("userId")
+	rData, errMsg := func() (map[string]interface{}, error) {
+		//校验是否达标
 
+		//领取
+		return map[string]interface{}{
+			"userId": userId,
+		}, nil
+	}()
+	if errMsg != nil {
+		log.Printf("Activity BidderPlan Schedule  %s error:%s\n", userId, errMsg.Error())
+	}
+	_ = r.Response.WriteJson(NewResult(rData, errMsg))
 }
 
 // Receive 领取奖励
@@ -29,7 +42,7 @@ func (act *Activity) Receive(r *ghttp.Request) {
 		}, nil
 	}()
 	if errMsg != nil {
-
+		log.Printf("Activity BidderPlan Receive  %s error:%s\n", userId, errMsg.Error())
 	}
 	_ = r.Response.WriteJson(NewResult(rData, errMsg))
 }