|
@@ -4,12 +4,64 @@ import (
|
|
|
dataUtil "app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"app.yhyue.com/moapp/message/handler/award"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/os/gcfg"
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
|
+ "log"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+//当日中奖信息
|
|
|
+func (BP *JyActivity) WinnerInfo() map[string]interface{} {
|
|
|
+ var res map[string]interface{}
|
|
|
+ //加个redis缓存
|
|
|
+ redisCache, err := redis.GetBytes(BidderPlanRedis, WinnerInfoKey)
|
|
|
+ if err == nil {
|
|
|
+ if err = json.Unmarshal(*redisCache, &res); err == nil {
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = award.GetWinnerInfo()
|
|
|
+ if res != nil {
|
|
|
+ b, err := json.Marshal(res)
|
|
|
+ if err == nil && len(b) > 0 {
|
|
|
+ if err = redis.PutBytes(BidderPlanRedis, WinnerInfoKey, &b, 24*60*60); err != nil {
|
|
|
+ log.Println("中将人信息 缓存信息有误")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+// 问卷提交
|
|
|
+func (BP *JyActivity) Questionnaire(userId, phone, answers string) error {
|
|
|
+ if inActivity, _, _ := BP.InActivity(); !inActivity {
|
|
|
+ return fmt.Errorf("不在活动时间内")
|
|
|
+ }
|
|
|
+ //判断是否是符合条件的免费用户
|
|
|
+ user := GetUserInfoRedisCache(userId)
|
|
|
+ if user.VipStatus > 0 || user.Status > 0 || user.EntnicheStatus > 0 {
|
|
|
+ return fmt.Errorf("用户身份不符合活动要求")
|
|
|
+ }
|
|
|
+ if user.Registedate < gcfg.Instance().MustGet(gctx.New(), "jyactivity.power.time", 1609430400).Int64() {
|
|
|
+ return fmt.Errorf("用户注册时间不符合活动要求")
|
|
|
+ }
|
|
|
+ //保存问卷
|
|
|
+ if ok := award.SaveQuestionnaire(userId, phone, answers); ok {
|
|
|
+ if redis.Put(BidderPlanRedis, fmt.Sprintf(QuestionnaireSubmit, userId), "qs", BP.cacheLong()) != true {
|
|
|
+ return fmt.Errorf("redis de22q 存储异常")
|
|
|
+ }
|
|
|
+ //问卷保存后--赠送7天超级订阅
|
|
|
+ if err := BP.GetDailyBoonSVip(userId); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return fmt.Errorf("mongodb de22q 存储异常")
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
// ShareFinish 分享完成
|
|
|
func (BP *JyActivity) ShareFinish(userId string) error {
|
|
|
if _, inActivity, _ := BP.InActivity(); !inActivity {
|
|
@@ -24,8 +76,9 @@ func (BP *JyActivity) ShareFinish(userId string) error {
|
|
|
// GetDailyBoonDetail 查询领取情况及剩余
|
|
|
// has 是否已经领取
|
|
|
// todayBalance 今日余额
|
|
|
+// 允许参加预热活动 用户注册时间限制
|
|
|
// err 异常
|
|
|
-func (BP *JyActivity) GetDailyBoonDetail(userId string) (has bool, todayBalance int, err error) {
|
|
|
+func (BP *JyActivity) GetDailyBoonDetail(userId string) (has bool, todayBalance int, registerBool bool, err error) {
|
|
|
if preHeatTime, _, _ := BP.InActivity(); !preHeatTime {
|
|
|
err = fmt.Errorf("不在预热活动时间内")
|
|
|
return
|
|
@@ -33,12 +86,25 @@ func (BP *JyActivity) GetDailyBoonDetail(userId string) (has bool, todayBalance
|
|
|
//查询是否领取
|
|
|
hasKey := fmt.Sprintf(BidderPlanHasDailyBoonKey, userId)
|
|
|
has = redis.GetInt(BidderPlanRedis, hasKey) >= 1
|
|
|
+ ActivityLock.Lock()
|
|
|
//查询剩余
|
|
|
todaySumKey := fmt.Sprintf(BidderPlanDailyBoonKey, time.Now().Format(dataUtil.Date_yyyyMMdd))
|
|
|
todayBalance = gcfg.Instance().MustGet(gctx.New(), "jyactivity.dailyBoon.reward.limit", 500).Int() - redis.GetInt(BidderPlanRedis, todaySumKey)
|
|
|
if todayBalance < 0 {
|
|
|
todayBalance = 0
|
|
|
}
|
|
|
+ ActivityLock.Unlock()
|
|
|
+ // 注册时间也在活动允许范围内
|
|
|
+ registerBool = true
|
|
|
+ //是否有权限领取
|
|
|
+ powerSwitch := gcfg.Instance().MustGet(gctx.New(), "jyactivity.power.switch", false).Bool()
|
|
|
+ //权限判断及问卷调查开关
|
|
|
+ if powerSwitch {
|
|
|
+ registerTime := gcfg.Instance().MustGet(gctx.New(), "jyactivity.power.time", 1609430400).Int64()
|
|
|
+ //注册时间是否在允许范围内
|
|
|
+ userInfo := GetUserInfoRedisCache(userId)
|
|
|
+ registerBool = userInfo != nil && registerTime <= userInfo.Registedate
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -58,8 +124,12 @@ func (BP *JyActivity) GetDailyBoonSVip(userId string) (err error) {
|
|
|
err = fmt.Errorf("活动没有开始")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- has, todayBalance, err = BP.GetDailyBoonDetail(userId)
|
|
|
+ qs := redis.GetStr(BidderPlanRedis, fmt.Sprintf(QuestionnaireSubmit, userId))
|
|
|
+ if MembershipDay.DoubleEleven && qs == "" {
|
|
|
+ err = fmt.Errorf("未提交问卷")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ has, todayBalance, _, err = BP.GetDailyBoonDetail(userId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -74,16 +144,18 @@ func (BP *JyActivity) GetDailyBoonSVip(userId string) (err error) {
|
|
|
err = func() error {
|
|
|
hasKey := fmt.Sprintf(BidderPlanHasDailyBoonKey, userId)
|
|
|
if redis.Incr(BidderPlanRedis, hasKey) == 1 {
|
|
|
+ ActivityLock.Lock()
|
|
|
todaySumKey := fmt.Sprintf(BidderPlanDailyBoonKey, time.Now().Format(dataUtil.Date_yyyyMMdd))
|
|
|
balance := redis.Incr(BidderPlanRedis, todaySumKey)
|
|
|
if balance > gcfg.Instance().MustGet(gctx.New(), "jyactivity.dailyBoon.reward.limit", 500).Int64() {
|
|
|
return fmt.Errorf("剩余为零")
|
|
|
}
|
|
|
+ ActivityLock.Unlock()
|
|
|
if err := award.GivenSubVip(userId, award.SubVip{
|
|
|
Num: gcfg.Instance().MustGet(gctx.New(), "jyactivity.dailyBoon.reward.svip", nil).Int64(),
|
|
|
ActivityCode: BP.ActivityCode,
|
|
|
Date: time.Now().Unix(),
|
|
|
- Desc: "预热福利",
|
|
|
+ Desc: "22年双十一预热福利",
|
|
|
}); err != nil {
|
|
|
redis.Del(BidderPlanRedis, hasKey)
|
|
|
return fmt.Errorf("稍后重试")
|
|
@@ -102,3 +174,16 @@ func (BP *JyActivity) GetDailyBoonSVip(userId string) (err error) {
|
|
|
}()
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+// GetUserInfoRedisCache 获取用户信息
|
|
|
+func GetUserInfoRedisCache(userId string) *award.UserBaseMsg {
|
|
|
+ //先从缓存中获取
|
|
|
+ cacheKey := fmt.Sprintf(PowerCacheKey, userId)
|
|
|
+ if bytes, err := redis.GetBytes(PowerCacheDb, cacheKey); err == nil && bytes != nil {
|
|
|
+ userPower := award.UserBaseMsg{}
|
|
|
+ if err := json.Unmarshal(*bytes, &userPower); err == nil {
|
|
|
+ return &userPower
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return award.GetUserInfo(userId)
|
|
|
+}
|