Selaa lähdekoodia

feat:领取会员,免费用户验证

wangshan 2 vuotta sitten
vanhempi
commit
509e84e119
3 muutettua tiedostoa jossa 64 lisäystä ja 24 poistoa
  1. 0 8
      handler/activity/jyActivity.go
  2. 22 9
      handler/activity/jyActivityOther.go
  3. 42 7
      handler/award/user.go

+ 0 - 8
handler/activity/jyActivity.go

@@ -34,14 +34,6 @@ type JyActivity struct {
 	DoubleEleven bool //22年双十一活动开关
 }
 
-//大会员状态redis缓存
-type BigVipBaseMsg struct {
-	Status         int  `json:"status"`          //大会员状态
-	VipStatus      int  `json:"vip_status"`      //超级订阅状态
-	EntnicheStatus int  `json:"entniche_status"` //商机管理状态
-	EntIsNew       bool `json:"entIsNew"`        //是否是新版商机管理用户
-}
-
 const (
 	BidderPlanRedis           = "main" //redis缓存库名
 	PowerCacheDb              = "newother"

+ 22 - 9
handler/activity/jyActivityOther.go

@@ -39,14 +39,13 @@ func (BP *JyActivity) Questionnaire(userId, phone, answers string) error {
 	if inActivity, _, _ := BP.InActivity(); !inActivity {
 		return fmt.Errorf("不在活动时间内")
 	}
-	cacheKey := fmt.Sprintf(PowerCacheKey, userId)
-	if bytes, err := redis.GetBytes(PowerCacheDb, cacheKey); err == nil && bytes != nil {
-		userPower := &BigVipBaseMsg{}
-		if err := json.Unmarshal(*bytes, &userPower); err == nil {
-			if userPower.EntIsNew || userPower.Status > 0 && userPower.VipStatus > 0 {
-				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 {
@@ -103,7 +102,8 @@ func (BP *JyActivity) GetDailyBoonDetail(userId string) (has bool, todayBalance
 	if powerSwitch {
 		registerTime := gcfg.Instance().MustGet(gctx.New(), "jyactivity.power.time", 1609430400).Int64()
 		//注册时间是否在允许范围内
-		registerBool = registerTime < award.GetUserRegisterTime(userId)
+		userInfo := GetUserInfoRedisCache(userId)
+		registerBool = userInfo != nil && registerTime <= userInfo.Registedate
 	}
 	return
 }
@@ -174,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)
+}

+ 42 - 7
handler/award/user.go

@@ -7,15 +7,50 @@ import (
 	"time"
 )
 
-func GetUserRegisterTime(userId string) (t int64) {
-	user, ok := db.Mgo.FindById("user", userId, `"l_registedate":1`)
-	if ok && user != nil {
-		t = common.Int64All((*user)["l_registedate"])
+//用户redis缓存
+type UserBaseMsg struct {
+	Status         int   `json:"status"`          //大会员状态
+	VipStatus      int   `json:"vip_status"`      //超级订阅状态
+	EntnicheStatus int   `json:"entniche_status"` //商机管理状态
+	Registedate    int64 `json:"registedate"`     //用户注册时间
+	EntIsNew       bool  `json:"entIsNew"`        //是否是新版商机管理用户
+}
+
+// GetUserInfo 查看 22年活动 用户是否满足条件
+func GetUserInfo(userId string) *UserBaseMsg {
+	userPower := UserBaseMsg{}
+	if userId == "" {
+		return &userPower
+	}
+	user, ok := db.Mgo.FindById("user", userId, `{"i_member_status":1,"l_registedate":1,"i_vip_status":1,"s_phone":1,"s_m_phone":1}`)
+	if ok && user != nil && len(*user) > 0 {
+		userPower.Status = common.IntAllDef((*user)["i_member_status"], 0)
+		userPower.VipStatus = common.IntAllDef((*user)["i_vip_status"], 0)
+		userPower.Registedate = common.Int64All((*user)["l_registedate"])
+		phone, _ := common.If((*user)["s_phone"] != nil, (*user)["s_phone"], (*user)["s_m_phone"]).(string)
+		if phone != "" {
+			res := db.Mysql.SelectBySql(`SELECT i.isNew,i.name,i.phone,i.status,i.auth_status,u.power FROM entniche_user u LEFT JOIN entniche_info i
+			ON u.ent_id=i.id
+			WHERE u.phone=?
+			ORDER BY  i.status DESC,i.auth_status DESC, CASE WHEN i.phone=? THEN 0  ELSE 1 END  ASC`, phone, phone)
+			if res != nil && len(*res) > 0 {
+				//已购买企业未过期-商机管理用户
+				for _, v := range *res {
+					if common.IntAll(v["status"]) == 1 && common.IntAll(v["power"]) == 1 {
+						userPower.EntnicheStatus = 1
+						if common.IntAll(v["isNew"]) == 1 {
+							userPower.EntIsNew = true
+							break
+						}
+					}
+				}
+			}
+		}
 	}
-	return
+	return &userPower
 }
 
-//
+// SaveQuestionnaire  保存问卷
 func SaveQuestionnaire(userId, phone, answers string) bool {
 	id := db.Mgo.Save("double_eleven_22_q", map[string]interface{}{
 		"l_create":  time.Now().Unix(),
@@ -26,7 +61,7 @@ func SaveQuestionnaire(userId, phone, answers string) bool {
 	return id != ""
 }
 
-//
+// GetWinnerInfo  获取中奖人信息
 func GetWinnerInfo() map[string]interface{} {
 	todayData := db.Mysql.SelectBySql(`SELECT phone,winnerdate,mold FROM winner_info_22_10 WHERE TO_DAYS(winnerdate) = TO_DAYS(NOW())`)
 	if todayData != nil && len(*todayData) > 0 {