|
@@ -5,7 +5,6 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -17,12 +16,6 @@ const (
|
|
|
UserPowerRedisKey = "jy_userpowerredis_%s_%d_%s"
|
|
|
)
|
|
|
|
|
|
-var (
|
|
|
- PowerLock = sync.Mutex{}
|
|
|
- UserPowerLock = map[string]*sync.Mutex{}
|
|
|
- UserPowerMapMap = map[string]map[string]int{}
|
|
|
-)
|
|
|
-
|
|
|
/*
|
|
|
*待调整 调整为存redis
|
|
|
*测试用例放的地方不对 待调整
|
|
@@ -35,25 +28,16 @@ func AutoUserPowerInfo(userId, appId string, internalTime int, bigMemberOff bool
|
|
|
* 超级订阅--》新版超级订阅vs老版超级订阅
|
|
|
* 免费用户--》新免费用户
|
|
|
*/
|
|
|
+ var UserPowerMap = map[string]int{}
|
|
|
//redis newother 查询是否存在用户功能信息
|
|
|
userPowerRedisKey := fmt.Sprintf(UserPowerRedisKey, appId, time.Now().Day(), userId)
|
|
|
bytes, err := redis.GetBytes(RedisCode, userPowerRedisKey)
|
|
|
if err == nil && len(*bytes) > 0 {
|
|
|
- var userPowerData = map[string]int{}
|
|
|
- if err = json.Unmarshal(*bytes, &userPowerData); err == nil {
|
|
|
- return userPowerData
|
|
|
+ if err = json.Unmarshal(*bytes, &UserPowerMap); err == nil {
|
|
|
+ return UserPowerMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- PowerLock.Lock()
|
|
|
- if UserPowerLock[userId] == nil {
|
|
|
- UserPowerLock[userId] = &sync.Mutex{}
|
|
|
- }
|
|
|
- UserPowerMapMap[userId] = map[string]int{}
|
|
|
- PowerLock.Unlock()
|
|
|
- UserPowerLock[userId].Lock()
|
|
|
- defer UserPowerLock[userId].Unlock()
|
|
|
-
|
|
|
//查询用户信息
|
|
|
data, ok := Mgo.FindById("user", userId, `{"s_phone":1,"s_m_phone":1,i_member_status":1,"s_member_mainid":1,"i_member_sub_status":1,"i_vip_status":1,"o_vipjy":1,"o_jy":1,"l_registedate":1}`)
|
|
|
if ok && *data != nil && len(*data) > 0 {
|
|
@@ -68,20 +52,20 @@ func AutoUserPowerInfo(userId, appId string, internalTime int, bigMemberOff bool
|
|
|
if MC.ObjToString(entNicheInfo["isNew"]) != "" {
|
|
|
switch MC.ObjToString(entNicheInfo["isNew"]) {
|
|
|
case "1": //新版商机管理
|
|
|
- UserPowerMapMap[userId]["110"] = 1
|
|
|
+ UserPowerMap["110"] = 1
|
|
|
switch MC.ObjToString(entNicheInfo["role_id"]) {
|
|
|
case "1": //部门管理员
|
|
|
- UserPowerMapMap[userId]["111"] = 1
|
|
|
+ UserPowerMap["111"] = 1
|
|
|
case "2": //企业管理员
|
|
|
- UserPowerMapMap[userId]["112"] = 1
|
|
|
+ UserPowerMap["112"] = 1
|
|
|
}
|
|
|
case "0": //老版商机管理
|
|
|
- UserPowerMapMap[userId]["100"] = 1
|
|
|
+ UserPowerMap["100"] = 1
|
|
|
switch MC.ObjToString(entNicheInfo["role_id"]) {
|
|
|
case "1": //部门管理员
|
|
|
- UserPowerMapMap[userId]["101"] = 1
|
|
|
+ UserPowerMap["101"] = 1
|
|
|
case "2": //企业管理员
|
|
|
- UserPowerMapMap[userId]["102"] = 1
|
|
|
+ UserPowerMap["102"] = 1
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -90,7 +74,7 @@ func AutoUserPowerInfo(userId, appId string, internalTime int, bigMemberOff bool
|
|
|
if memberStatus := MC.IntAll((*data)["i_member_status"]); memberStatus > 0 || bigMemberOff {
|
|
|
userId := userId
|
|
|
if memberStatus > 0 {
|
|
|
- UserPowerMapMap[userId]["1"] = memberStatus
|
|
|
+ UserPowerMap["1"] = memberStatus
|
|
|
//是否是子账号 而且 子账号被启用
|
|
|
if (*data)["s_member_mainid"] != nil && MC.ObjToString((*data)["s_member_mainid"]) != "" && MC.IntAllDef((*data)["i_member_sub_status"], 0) > 0 {
|
|
|
userId = MC.ObjToString((*data)["s_member_mainid"])
|
|
@@ -100,18 +84,18 @@ func AutoUserPowerInfo(userId, appId string, internalTime int, bigMemberOff bool
|
|
|
serviceList := Mysql.Find(BigMemberUserPowerTable, map[string]interface{}{"s_userid": userId, "i_status": 0}, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
|
|
|
if serviceList != nil && len(*serviceList) != 0 {
|
|
|
for _, sv := range *serviceList {
|
|
|
- UserPowerMapMap[userId][MC.ObjToString(sv["s_serviceid"])] = MC.IntAll(sv["i_frequency"])
|
|
|
+ UserPowerMap[MC.ObjToString(sv["s_serviceid"])] = MC.IntAll(sv["i_frequency"])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//VIP用户
|
|
|
if vipStatus := MC.IntAll((*data)["i_vip_status"]); vipStatus > 0 {
|
|
|
- UserPowerMapMap[userId]["200"] = vipStatus
|
|
|
+ UserPowerMap["200"] = vipStatus
|
|
|
if vipSet := MC.ObjToMap((*data)["o_vipjy"]); vipSet != nil {
|
|
|
if buySet := MC.ObjToMap((*vipSet)["o_buyset"]); buySet != nil {
|
|
|
//vip 升级用户
|
|
|
if MC.IntAll((*buySet)["upgrade"]) > 0 {
|
|
|
- UserPowerMapMap[userId]["201"] = vipStatus
|
|
|
+ UserPowerMap["201"] = vipStatus
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -120,23 +104,21 @@ func AutoUserPowerInfo(userId, appId string, internalTime int, bigMemberOff bool
|
|
|
freeSet := MC.ObjToMap((*data)["o_jy"])
|
|
|
if MC.IntAll((*freeSet)["i_newfree"]) > 0 || IsNewFreeTimeCell < MC.IntAll((*data)["l_registedate"]) {
|
|
|
//新免费用户
|
|
|
- UserPowerMapMap[userId]["300"] = 1
|
|
|
+ UserPowerMap["300"] = 1
|
|
|
}
|
|
|
//广东移动DICT
|
|
|
if Mysql.CountBySql(`select count(*) from privatedata where phone = ?`, phone) > 0 {
|
|
|
- UserPowerMapMap[userId]["400"] = 1
|
|
|
+ UserPowerMap["400"] = 1
|
|
|
}
|
|
|
}
|
|
|
- if UserPowerMapMap[userId] != nil {
|
|
|
- PowerLock.Lock()
|
|
|
- bytes, err := json.Marshal(UserPowerMapMap[userId])
|
|
|
+ if UserPowerMap != nil {
|
|
|
+ bytes, err := json.Marshal(UserPowerMap)
|
|
|
if err == nil && len(bytes) > 0 {
|
|
|
redis.PutBytes(RedisCode, userPowerRedisKey, &bytes, internalTime)
|
|
|
}
|
|
|
- PowerLock.Unlock()
|
|
|
}
|
|
|
}
|
|
|
- return UserPowerMapMap[userId]
|
|
|
+ return UserPowerMap
|
|
|
}
|
|
|
|
|
|
//clear One
|