123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package rpc
- import (
- "encoding/json"
- "fmt"
- "app.yhyue.com/moapp/jybase/redis"
- "bp.jydev.jianyu360.cn/BaseService/gateway/common/db"
- . "bp.jydev.jianyu360.cn/BaseService/gateway/common/gatecode"
- "github.com/gogf/gf/v2/util/gconv"
- )
- var PowerCacheDb = "other"
- var PowerCacheKey = "bigmember_power_3_%s"
- //大会员状态redis缓存
- type BigVipBaseMsg struct {
- Status int `json:"status"` //大会员状态
- VipStatus int `json:"vip_status"` //超级订阅状态
- EntnicheStatus int `json:"entniche_status"` //商机管理状态
- }
- /// CheckUserPower 校验账户是否有对应权益
- // userId 老用户id (mongodb里的objectid)
- // power_type 权益判断
- func CheckUserPower(userid, phone string, power_type int) error {
- cacheKey := fmt.Sprintf(PowerCacheKey, userid)
- userPower := BigVipBaseMsg{}
- //判断权益
- if bytes, err := redis.GetBytes(PowerCacheDb, cacheKey); err == nil && bytes != nil {
- if err := json.Unmarshal(*bytes, &userPower); err != nil {
- return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("校验异常"))
- }
- } else {
- //未找到缓存
- data, ok := db.MgoJy.FindById("user", userid, `{"i_member_status":1,"i_vip_status":1}`)
- if ok && *data != nil && len(*data) > 0 {
- userPower.Status = gconv.Int((*data)["i_member_status"])
- userPower.VipStatus = gconv.Int((*data)["i_vip_status"])
- }
- }
- userPower.EntnicheStatus = 0
- if count := db.JyMysql.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 {
- userPower.EntnicheStatus = 1
- }
- /*
- 权益判断方式、0走资源中台
- 1前置代理判断,是否是付费用户
- 2前置代理判断,是否是超级订阅
- 3前置代理判断,是否是大会员
- 4前置代理判断,是否是商机管理
- */
- switch power_type {
- case 1:
- if userPower.VipStatus <= 0 && userPower.Status <= 0 && userPower.EntnicheStatus <= 0 {
- return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非付费用户"))
- }
- case 2:
- if userPower.VipStatus <= 0 {
- return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非超级订阅用户"))
- }
- case 3:
- if userPower.Status <= 0 {
- return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员用户"))
- }
- case 4:
- if userPower.EntnicheStatus <= 0 {
- return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非商机管理用户"))
- }
- case 22: //临时加大会员专家版、商机版判断
- if !(userPower.Status == 1 || userPower.Status == 2 || userPower.Status == 6 || userPower.Status == 7) {
- return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员专家版、商机版用户"))
- }
- }
- return nil
- }
|