|
@@ -1,12 +1,11 @@
|
|
|
package activity
|
|
|
|
|
|
import (
|
|
|
- "app.yhyue.com/moapp/jybase/common"
|
|
|
+ dateFormate "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/db"
|
|
|
"app.yhyue.com/moapp/message/handler/award"
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/os/gcfg"
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
@@ -19,9 +18,10 @@ import (
|
|
|
投标人专属免费计划
|
|
|
*/
|
|
|
|
|
|
-type BidderPlan struct {
|
|
|
- St, Ed time.Time //活动开始时间、结束时间
|
|
|
- Missions map[string]struct { //任务
|
|
|
+type JyActivity struct {
|
|
|
+ St, Ed time.Time //活动开始时间、结束时间
|
|
|
+ ActivityCode string //活动code
|
|
|
+ Missions map[string]struct { //任务
|
|
|
Points int `json:"points"`
|
|
|
Schedule int `json:"schedule"`
|
|
|
}
|
|
@@ -32,53 +32,63 @@ type BidderPlan struct {
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
- BidderPlanActivityCode = "bidderPlan"
|
|
|
- BidderPlanRedis = "main"
|
|
|
- //活动累计进度
|
|
|
- BidderPlanScheduleCache = "bidderPlanScheduleValue_%s"
|
|
|
- BidderPlanFastClickCheck = "bidderPlanFastClickValue_%s"
|
|
|
- //奖励领取状态
|
|
|
- BidderPlanScheduleAwardStatus = "bidderPlanScheduleAward_%s_%d"
|
|
|
- BidderPlanSubscribeMissionsStatus = "bidderPlanActivitySubscribeCacheKey_%s"
|
|
|
- BidderPlanInviteMissionsStatus = "bidderPlanActivityInviteCacheKey_%s"
|
|
|
- BidderPlanImproveInfoMissionsStatus = "bidderPlanActivityImproveInfoCacheKey_%s"
|
|
|
+ BidderPlanRedis = "main" //redis缓存库名
|
|
|
+
|
|
|
+ BidderPlanScheduleCache = "bidderPlan_v1_ScheduleValue_%s" //活动累计进度
|
|
|
+ BidderPlanFastClickCheck = "bidderPlanFastClickValue_%s" //防止连点
|
|
|
+
|
|
|
+ BidderPlanScheduleAwardStatus = "bidderPlan_v1_ScheduleAward_%s_%d" //奖励领取状态
|
|
|
+
|
|
|
+ BidderPlanBuySVipStatus = "bidderPlanActivity_v1_BuySVipCacheKey_%s" //购买
|
|
|
+ BidderPlanInviteMissionsStatus = "bidderPlanActivity_v1_InviteCacheKey_%s" //邀请
|
|
|
+ BidderPlanShareMissionsStatus = "bidderPlanActivity_v1_ShareCacheKey_%s" //分享
|
|
|
)
|
|
|
|
|
|
-var JyBidderPlan *BidderPlan
|
|
|
+var MembershipDay *JyActivity
|
|
|
|
|
|
func init() {
|
|
|
- JyBidderPlan = &BidderPlan{
|
|
|
- St: gtime.NewFromStrLayout(gcfg.Instance().MustGet(gctx.New(), "bidderPlan.dateRange.st").String(), "2006-01-02T15:04:05Z").Time,
|
|
|
- Ed: gtime.NewFromStrLayout(gcfg.Instance().MustGet(gctx.New(), "bidderPlan.dateRange.ed").String(), "2006-01-02T15:04:05Z").Time,
|
|
|
+ MembershipDay = &JyActivity{
|
|
|
+ St: gtime.NewFromStrLayout(gcfg.Instance().MustGet(gctx.New(), "jyactivity.dateRange.st").String(), "2006-01-02T15:04:05Z").Time,
|
|
|
+ Ed: gtime.NewFromStrLayout(gcfg.Instance().MustGet(gctx.New(), "jyactivity.dateRange.ed").String(), "2006-01-02T15:04:05Z").Time,
|
|
|
}
|
|
|
+ MembershipDay.ActivityCode = gcfg.Instance().MustGet(gctx.New(), "jyactivity.code").String()
|
|
|
//加载任务
|
|
|
- if loadMissionsErr := gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions").Scan(&JyBidderPlan.Missions); loadMissionsErr != nil {
|
|
|
+ if loadMissionsErr := gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions").Scan(&MembershipDay.Missions); loadMissionsErr != nil {
|
|
|
logger.Error(fmt.Sprintf("JyBidderPlan 加载任务异常 %v", loadMissionsErr))
|
|
|
}
|
|
|
//加载进度奖励
|
|
|
- if loadScheduleErr := gcfg.Instance().MustGet(gctx.New(), "bidderPlan.scheduleReward").Scan(&JyBidderPlan.ScheduleReward); loadScheduleErr != nil {
|
|
|
+ if loadScheduleErr := gcfg.Instance().MustGet(gctx.New(), "jyactivity.scheduleReward").Scan(&MembershipDay.ScheduleReward); loadScheduleErr != nil {
|
|
|
logger.Error(fmt.Sprintf("JyBidderPlan 加载进度异常 %v", loadScheduleErr))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// InActivity 是否在活动时间内
|
|
|
-func (BP *BidderPlan) InActivity() bool {
|
|
|
+func (BP *JyActivity) InActivity() bool {
|
|
|
now := time.Now()
|
|
|
- return now.After(JyBidderPlan.St) && now.Before(JyBidderPlan.Ed)
|
|
|
+ return now.After(MembershipDay.St) && now.Before(MembershipDay.Ed)
|
|
|
}
|
|
|
|
|
|
// cacheLong 缓存时间
|
|
|
-func (BP *BidderPlan) cacheLong() int {
|
|
|
- //return int(JyBidderPlan.Ed.Unix()-time.Now().Unix()))+ 60 * 60 * 24
|
|
|
+func (BP *JyActivity) cacheLong() int {
|
|
|
return 60 * 60 * 24 * 30
|
|
|
}
|
|
|
|
|
|
+// FastClickCheck 连点处理,防止重复领取
|
|
|
+func (BP *JyActivity) FastClickCheck(userId string) bool {
|
|
|
+ key := fmt.Sprintf(BidderPlanFastClickCheck, userId)
|
|
|
+ if redis.Incr(BidderPlanRedis, key) == 1 {
|
|
|
+ _ = redis.SetExpire(BidderPlanRedis, key, 1)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
// GetSchedule 查询活动任务进度
|
|
|
-func (BP *BidderPlan) GetSchedule(userId string) int {
|
|
|
+func (BP *JyActivity) GetSchedule(userId string) int {
|
|
|
return -redis.GetInt(BidderPlanRedis, fmt.Sprintf(BidderPlanScheduleCache, userId))
|
|
|
}
|
|
|
|
|
|
-func (BP *BidderPlan) GetScheduleQuery(userId string, schedule int) (status int) {
|
|
|
+func (BP *JyActivity) GetScheduleQuery(userId string, schedule int) (status int) {
|
|
|
if BP.GetSchedule(userId) < schedule {
|
|
|
return 0
|
|
|
}
|
|
@@ -96,7 +106,7 @@ func (BP *BidderPlan) GetScheduleQuery(userId string, schedule int) (status int)
|
|
|
}
|
|
|
|
|
|
// ScheduleGiven 活动任务进度奖励
|
|
|
-func (BP *BidderPlan) ScheduleGiven(userId string, schedule int) error {
|
|
|
+func (BP *JyActivity) ScheduleGiven(userId string, schedule int) error {
|
|
|
if !BP.InActivity() {
|
|
|
return fmt.Errorf("活动已结束")
|
|
|
}
|
|
@@ -110,7 +120,7 @@ func (BP *BidderPlan) ScheduleGiven(userId string, schedule int) error {
|
|
|
|
|
|
if err := award.GivenSubVip(userId, award.SubVip{
|
|
|
Num: gconv.Int64(scheduleAward.SubVip),
|
|
|
- ActivityCode: BidderPlanActivityCode,
|
|
|
+ ActivityCode: BP.ActivityCode,
|
|
|
Desc: fmt.Sprintf("达到%d剑鱼币", schedule),
|
|
|
Date: time.Now().Unix(),
|
|
|
}); err != nil {
|
|
@@ -122,7 +132,7 @@ func (BP *BidderPlan) ScheduleGiven(userId string, schedule int) error {
|
|
|
}
|
|
|
|
|
|
// AddSchedule 增加活动进度
|
|
|
-func (BP *BidderPlan) AddSchedule(userId string, value int) (after int) {
|
|
|
+func (BP *JyActivity) AddSchedule(userId string, value int) (after int) {
|
|
|
if value > 0 {
|
|
|
key := fmt.Sprintf(BidderPlanScheduleCache, userId)
|
|
|
after = -gconv.Int(redis.Decrby(BidderPlanRedis, key, value))
|
|
@@ -139,41 +149,15 @@ type FreeSubscribe struct {
|
|
|
AKey []interface{} `json:"a_key"`
|
|
|
}
|
|
|
|
|
|
-// MissionsSubscribeQuery 订阅任务
|
|
|
+// MissionsSVipBuyQuery 购买超级订阅
|
|
|
// status:0 未完成 1 待领取 -1已领取
|
|
|
-// 付费账户直接视为完成任务
|
|
|
-func (BP *BidderPlan) MissionsSubscribeQuery(userId string) (status int) {
|
|
|
+// 是否购买超级订阅
|
|
|
+func (BP *JyActivity) MissionsSVipBuyQuery(userId string) (status int) {
|
|
|
finish := func() bool {
|
|
|
- uData, ok := db.Mgo.FindById("user", userId, `{"o_jy":1,"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone:1"}`)
|
|
|
- if !ok || uData == nil || len(*uData) == 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- if gconv.Int((*uData)["i_vip_status"]) > 0 { //超级订阅
|
|
|
- return true
|
|
|
- } else if gconv.Int((*uData)["i_member_status"]) > 0 { //大会员
|
|
|
+ count := db.Mysql.CountBySql(`SELECT count(id) FROM dataexport_order WHERE product_type ='VIP订阅' AND order_money > 0 AND order_status>0 AND create_time > ? AND user_id=? `, BP.St.Format(dateFormate.Date_Full_Layout), userId)
|
|
|
+ if count > 0 {
|
|
|
return true
|
|
|
}
|
|
|
- //查询是否是商机管理用户
|
|
|
- phone, _ := common.If((*uData)["s_phone"] != nil, (*uData)["s_phone"], (*uData)["s_m_phone"]).(string)
|
|
|
- if phone != "" {
|
|
|
- if count := db.Mysql.CountBySql(`SELECT count(1) FROM entniche_user u LEFT JOIN entniche_info i ON u.ent_id=i.id WHERE u.phone=? and u.power=1 and i.status=1`, phone); count > 0 {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- //免费用户查询是否完成订阅
|
|
|
- bytes := gconv.Bytes((*uData)["o_jy"])
|
|
|
- if bytes == nil || len(bytes) == 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- freeSub := FreeSubscribe{}
|
|
|
- if err := json.Unmarshal(bytes, &freeSub); err != nil {
|
|
|
- logger.Error("MissionsSubscribeQuery 格式化订阅内存出错", err)
|
|
|
- return false
|
|
|
- }
|
|
|
- if len(freeSub.AKey) > 0 && len(freeSub.OAreaP) > 0 {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
return false
|
|
|
}()
|
|
|
|
|
@@ -181,7 +165,7 @@ func (BP *BidderPlan) MissionsSubscribeQuery(userId string) (status int) {
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
- key := fmt.Sprintf(BidderPlanSubscribeMissionsStatus, userId)
|
|
|
+ key := fmt.Sprintf(BidderPlanBuySVipStatus, userId)
|
|
|
if redis.Get(BidderPlanRedis, key) == nil {
|
|
|
status = gconv.Int(redis.Incr(BidderPlanRedis, key))
|
|
|
_ = redis.SetExpire(BidderPlanRedis, key, BP.cacheLong())
|
|
@@ -194,46 +178,36 @@ func (BP *BidderPlan) MissionsSubscribeQuery(userId string) (status int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// FastClickCheck 连点处理,防止重复领取
|
|
|
-func (BP *BidderPlan) FastClickCheck(userId string) bool {
|
|
|
- key := fmt.Sprintf(BidderPlanFastClickCheck, userId)
|
|
|
- if redis.Incr(BidderPlanRedis, key) == 1 {
|
|
|
- _ = redis.SetExpire(BidderPlanRedis, key, 1)
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-// MissionsSubscribeGiven 订阅任务领取奖励
|
|
|
-func (BP *BidderPlan) MissionsSubscribeGiven(userId string) error {
|
|
|
+// MissionsSVipBuyGiven 订阅任务领取奖励
|
|
|
+func (BP *JyActivity) MissionsSVipBuyGiven(userId string) error {
|
|
|
if !BP.InActivity() {
|
|
|
return fmt.Errorf("活动已结束")
|
|
|
}
|
|
|
- status := BP.MissionsSubscribeQuery(userId)
|
|
|
+ status := BP.MissionsSVipBuyQuery(userId)
|
|
|
if status != 1 {
|
|
|
return fmt.Errorf("非领取状态")
|
|
|
}
|
|
|
|
|
|
if givenPointsErr := award.GivenPoints(userId, award.Points{
|
|
|
- Num: gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.subscribe.points").Int64(),
|
|
|
- Type: 1007,
|
|
|
- ActivityCode: BidderPlanActivityCode,
|
|
|
- Desc: "免费订阅任务完成",
|
|
|
+ Num: gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.buysubvip.points").Int64(),
|
|
|
+ Type: 1010,
|
|
|
+ ActivityCode: BP.ActivityCode,
|
|
|
+ Desc: "购买超级订阅任务完成",
|
|
|
Date: time.Now().Unix(),
|
|
|
}); givenPointsErr != nil {
|
|
|
return fmt.Errorf("领取奖励异常")
|
|
|
}
|
|
|
|
|
|
//设置已领取
|
|
|
- redis.Put(BidderPlanRedis, fmt.Sprintf(BidderPlanSubscribeMissionsStatus, userId), -1, BP.cacheLong())
|
|
|
+ redis.Put(BidderPlanRedis, fmt.Sprintf(BidderPlanBuySVipStatus, userId), -1, BP.cacheLong())
|
|
|
//增加任务进度
|
|
|
- BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.subscribe.schedule").Int())
|
|
|
+ BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.buysubvip.schedule").Int())
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// MissionsInviteQuery 邀请任务状态查询
|
|
|
// status:0 未完成 1 待领取 -1已领取
|
|
|
-func (BP *BidderPlan) MissionsInviteQuery(userId string) (status int) {
|
|
|
+func (BP *JyActivity) MissionsInviteQuery(userId string) (status int) {
|
|
|
status = redis.GetInt(BidderPlanRedis, fmt.Sprintf(BidderPlanInviteMissionsStatus, userId))
|
|
|
if status > 1 {
|
|
|
status = 1
|
|
@@ -242,7 +216,7 @@ func (BP *BidderPlan) MissionsInviteQuery(userId string) (status int) {
|
|
|
}
|
|
|
|
|
|
// MissionsInviteGiven 邀请任务奖励领取
|
|
|
-func (BP *BidderPlan) MissionsInviteGiven(userId string) error {
|
|
|
+func (BP *JyActivity) MissionsInviteGiven(userId string) error {
|
|
|
if !BP.InActivity() {
|
|
|
return fmt.Errorf("活动已结束")
|
|
|
}
|
|
@@ -252,10 +226,10 @@ func (BP *BidderPlan) MissionsInviteGiven(userId string) error {
|
|
|
}
|
|
|
//领取
|
|
|
if givenPointsErr := award.GivenPoints(userId, award.Points{
|
|
|
- Num: gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.invite.points").Int64(),
|
|
|
+ Num: gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.invite.points").Int64(),
|
|
|
Type: 1008,
|
|
|
- ActivityCode: BidderPlanActivityCode,
|
|
|
- Desc: "邀请领好礼任务",
|
|
|
+ ActivityCode: BP.ActivityCode,
|
|
|
+ Desc: "邀请领好礼任务完成",
|
|
|
Date: time.Now().Unix(),
|
|
|
}); givenPointsErr != nil {
|
|
|
return fmt.Errorf("领取奖励异常")
|
|
@@ -264,20 +238,20 @@ func (BP *BidderPlan) MissionsInviteGiven(userId string) error {
|
|
|
//设置已领取
|
|
|
redis.Put(BidderPlanRedis, fmt.Sprintf(BidderPlanInviteMissionsStatus, userId), -1, BP.cacheLong())
|
|
|
//增加任务进度
|
|
|
- BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.invite.schedule").Int())
|
|
|
+ BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.invite.schedule").Int())
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// MissionsImproveInfoQuery 完善信息任务
|
|
|
+// MissionsShareQuery 分享活动
|
|
|
// status:0 未完成 1 待领取 -1已领取
|
|
|
-func (BP *BidderPlan) MissionsImproveInfoQuery(userId string) (status int) {
|
|
|
+func (BP *JyActivity) MissionsShareQuery(userId string) (status int) {
|
|
|
hasMsg := db.Mgo.Count("saleLeads", map[string]interface{}{
|
|
|
"userid": userId,
|
|
|
}) > 0
|
|
|
if !hasMsg {
|
|
|
return 0
|
|
|
}
|
|
|
- key := fmt.Sprintf(BidderPlanImproveInfoMissionsStatus, userId)
|
|
|
+ key := fmt.Sprintf(BidderPlanShareMissionsStatus, userId)
|
|
|
if redis.Get(BidderPlanRedis, key) == nil {
|
|
|
status = gconv.Int(redis.Incr(BidderPlanRedis, key))
|
|
|
_ = redis.SetExpire(BidderPlanRedis, key, BP.cacheLong())
|
|
@@ -290,29 +264,29 @@ func (BP *BidderPlan) MissionsImproveInfoQuery(userId string) (status int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// MissionsImproveInfoGiven 完善信息奖励领取
|
|
|
-func (BP *BidderPlan) MissionsImproveInfoGiven(userId string) error {
|
|
|
+// MissionsShareGiven 分享活动
|
|
|
+func (BP *JyActivity) MissionsShareGiven(userId string) error {
|
|
|
if !BP.InActivity() {
|
|
|
return fmt.Errorf("活动已结束")
|
|
|
}
|
|
|
- status := BP.MissionsImproveInfoQuery(userId)
|
|
|
+ status := BP.MissionsShareQuery(userId)
|
|
|
if status != 1 {
|
|
|
return fmt.Errorf("非领取状态")
|
|
|
}
|
|
|
|
|
|
if givenPointsErr := award.GivenPoints(userId, award.Points{
|
|
|
- Num: gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.improveInfo.points").Int64(),
|
|
|
- Type: 1009,
|
|
|
- ActivityCode: BidderPlanActivityCode,
|
|
|
- Desc: "完善信息任务",
|
|
|
+ Num: gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.share.points").Int64(),
|
|
|
+ Type: 1011,
|
|
|
+ ActivityCode: BP.ActivityCode,
|
|
|
+ Desc: "分享活动任务完成",
|
|
|
Date: time.Now().Unix(),
|
|
|
}); givenPointsErr != nil {
|
|
|
return fmt.Errorf("领取奖励异常")
|
|
|
}
|
|
|
|
|
|
//设置已领取
|
|
|
- redis.Put(BidderPlanRedis, fmt.Sprintf(BidderPlanImproveInfoMissionsStatus, userId), -1, BP.cacheLong())
|
|
|
+ redis.Put(BidderPlanRedis, fmt.Sprintf(BidderPlanShareMissionsStatus, userId), -1, BP.cacheLong())
|
|
|
//增加任务进度
|
|
|
- BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "bidderPlan.missions.improveInfo.schedule").Int())
|
|
|
+ BP.AddSchedule(userId, gcfg.Instance().MustGet(gctx.New(), "jyactivity.missions.share.schedule").Int())
|
|
|
return nil
|
|
|
}
|