瀏覽代碼

Merge branch 'feature/v1.2.9' into feature/v1.2.11

123456 2 年之前
父節點
當前提交
fe4290cd4a
共有 1 個文件被更改,包括 85 次插入37 次删除
  1. 85 37
      entity/user.go

+ 85 - 37
entity/user.go

@@ -3,7 +3,6 @@ package entity
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/zeromicro/go-zero/core/logx"
 	"strconv"
 	"strings"
 	"sync"
@@ -22,6 +21,7 @@ const (
 	UserEntIdKey            = "jy_userentid_%s_%d_%s"
 	UserRegisterTime        = "jy_userregistertime_%s"
 	EntnicheWaitEmpower     = "entniche_wait_empower"
+	EntnichePower           = "entniche_power"
 )
 
 type UserInfo struct {
@@ -68,14 +68,19 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 			isFree = true
 			//第一版领域化权限判断  ;第二版:超级订阅||大会员 到期时间超过90天
 			//商机管理服务 前提是超级订阅、大会员、医械通
-			domainBool          = false
-			registerTime  int64 = 0
-			entnichePower       = false //企业级服务 企业管理员
+			domainBool           = false
+			registerTime   int64 = 0
+			entnicheRoleId       = 0                     //企业级服务 企业管理员
+			entnicheIsNew        = -1                    //是否是新版商机管理
+			powerSource          = 0                     //商机管理服务
+			memberStatus         = 0                     //大会员
+			serviceIds           = map[string][]string{} //大会员服务id集合
 		)
 		phone, _ := MC.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string)
 		if phone != "" {
 			//大会员
-			if memberStatus := MC.IntAll((*data)["i_member_status"]); memberStatus > 0 || ConfigJson.BigMemberOff {
+			memberStatus = MC.IntAll((*data)["i_member_status"])
+			if memberStatus > 0 || ConfigJson.BigMemberOff {
 				mainUserId := m.UserId
 				if memberStatus > 0 {
 					registerTime = MC.Int64All((*data)["i_member_endtime"])
@@ -83,6 +88,7 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 					isFree = false
 					UserPowerMap["0"] = memberStatus
 					UserPowerMap[strconv.Itoa(50+memberStatus)] = 1
+					serviceIds["M"] = append(serviceIds["M"], "0", strconv.Itoa(50+memberStatus))
 					//是否是子账号 而且 子账号被启用
 					if (*data)["s_member_mainid"] != nil && MC.ObjToString((*data)["s_member_mainid"]) != "" && MC.IntAllDef((*data)["i_member_sub_status"], 0) > 0 {
 						mainUserId = MC.ObjToString((*data)["s_member_mainid"])
@@ -93,6 +99,7 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 				if serviceList != nil && len(*serviceList) != 0 {
 					for _, sv := range *serviceList {
 						UserPowerMap[MC.ObjToString(sv["s_serviceid"])] = MC.If(MC.IntAll(sv["i_frequency"]) > 0, MC.IntAll(sv["i_frequency"]), memberStatus).(int)
+						serviceIds["M"] = append(serviceIds["M"], MC.ObjToString(sv["s_serviceid"]))
 					}
 				}
 			}
@@ -104,11 +111,13 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 				domainBool = true
 				isFree = false
 				UserPowerMap["200"] = vipStatus
+				serviceIds["V"] = append(serviceIds["V"], "200")
 				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 {
 							UserPowerMap["201"] = vipStatus
+							serviceIds["V"] = append(serviceIds["V"], "201")
 						}
 					}
 				}
@@ -119,31 +128,48 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 				//商机管理用户信息判断
 				if entNicheInfos != nil && len(*entNicheInfos) > 0 {
 					entNicheInfo := (*entNicheInfos)[0]
-					//判断是否是企业级服务管理员
-					entnichePower = MC.IntAll(entNicheInfo["role_id"]) == 1
+					//1:企业管理员 2:部门管理员
+					entnicheRoleId = MC.IntAll(entNicheInfo["role_id"])
 					//商机管理
-					if MC.IntAll(entNicheInfo["status"]) == 1 && MC.IntAll(entNicheInfo["power"]) == 1 {
-						//商机管理服务 P259需求
-						//有商机管理服务 不会再有商机管理订阅菜单
-						switch MC.IntAll(entNicheInfo["power_source"]) {
-						case 0:
-							isFree = false
-							switch MC.IntAll(entNicheInfo["isNew"]) {
-							case 1: //新版商机管理
-								UserPowerMap["110"] = 1
-								switch MC.IntAll(entNicheInfo["role_id"]) {
-								case 2: //部门管理员
-									UserPowerMap["111"] = 1
-								case 1: //企业管理员
-									UserPowerMap["112"] = 1
+					//status>0 商机管理付费用户
+					if MC.IntAll(entNicheInfo["status"]) == 1 {
+						//是否是新版商机管理
+						entnicheIsNew = MC.IntAll(entNicheInfo["isNew"])
+						//管理员entnicheRoleId>0 并不一定 power==1,即使power==0 也有权限
+						//员工被分配后power==1否则没有权限
+						if MC.IntAll(entNicheInfo["power"]) == 1 || entnicheRoleId > 0 {
+							//商机管理服务 P259需求
+							//有商机管理服务 不会再有商机管理订阅菜单
+							powerSource = MC.IntAll(entNicheInfo["power_source"])
+							switch powerSource {
+							case 0:
+								isFree = false
+								switch entnicheIsNew {
+								case 1: //新版商机管理
+									UserPowerMap["110"] = 1
+									switch MC.IntAll(entNicheInfo["role_id"]) {
+									case 2: //部门管理员
+										UserPowerMap["111"] = 1
+									case 1: //企业管理员
+										UserPowerMap["112"] = 1
+									}
+								case 0: //老版商机管理
+									UserPowerMap["100"] = 1
+									switch MC.IntAll(entNicheInfo["role_id"]) {
+									case 2: //部门管理员
+										UserPowerMap["101"] = 1
+									case 1: //企业管理员
+										UserPowerMap["102"] = 1
+									}
 								}
-							case 0: //老版商机管理
-								UserPowerMap["100"] = 1
+							case 1:
+								//客户管理服务(商机管理服务) [前提:大会员、超级订阅、医械通用户]---免费用户也可以用 (需求调整来自刘苗:产品已确认)
+								UserPowerMap["600"] = 1
 								switch MC.IntAll(entNicheInfo["role_id"]) {
 								case 2: //部门管理员
-									UserPowerMap["101"] = 1
+									UserPowerMap["602"] = 1
 								case 1: //企业管理员
-									UserPowerMap["102"] = 1
+									UserPowerMap["601"] = 1
 								}
 								//老版商机管理: model:1-统一订阅,2-个人订阅
 								if MC.IntAll(entNicheInfo["model"]) == 1 {
@@ -152,15 +178,6 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 									UserPowerMap["104"] = 1
 								}
 							}
-						case 1:
-							//客户管理服务(商机管理服务) [前提:大会员、超级订阅、医械通用户]---免费用户也可以用 (需求调整来自刘苗:产品已确认)
-							UserPowerMap["600"] = 1
-							switch MC.IntAll(entNicheInfo["role_id"]) {
-							case 2: //部门管理员
-								UserPowerMap["602"] = 1
-							case 1: //企业管理员
-								UserPowerMap["601"] = 1
-							}
 						}
 					}
 				}
@@ -185,12 +202,22 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 					UserPowerMap[plv] = 1
 				}
 			}
+			//人员行为统计菜单-1、购买大会员且创建了企业的管理员;2、新版商机管理管理员;3、商机管理服务管理员
+			if entnicheRoleId > 0 && memberStatus > 0 {
+				UserPowerMap["50"] = 1
+			}
 			//必须是企业管理员-&-购买了企业级应用服务
-			c := Mysql.CountBySql(fmt.Sprintf(`SELECT COUNT(id) FROM %s WHERE ent_id = ? AND TO_DAYS(end_time) >= TO_DAYS(NOW())`, EntnicheWaitEmpower), m.EntId)
-			logx.Info(entnichePower, "cccccc:", c)
-			if c > 0 && entnichePower {
+			c := Mysql.CountBySql(fmt.Sprintf(`SELECT COUNT(id) FROM %s WHERE ent_id = ? AND TO_DAYS(end_time) >= TO_DAYS(NOW()) AND (LOCATE('VIP订阅',product_type) OR LOCATE('大会员',product_type))`, EntnicheWaitEmpower), m.EntId)
+			//企业级服务 权限管理(只有企业管理员有权限)
+			if entnicheRoleId == 1 && c > 0 {
 				UserPowerMap["700"] = 1
 			}
+			//企业级服务 企业订阅--
+			//1、存在未到期的购买主体为“企业”切购买产品为大会员或者超级订阅的部门管理员或企业管理员;c > 0
+			//2、存在未到期的老版或者新版商机管理的企业管理员或部门管理员(非商机管理服务)。entnicheIsNew > -1 && powerSource == 0
+			if (c > 0 || entnicheIsNew > -1 && powerSource == 0) && entnicheRoleId > 0 {
+				UserPowerMap["701"] = 1
+			}
 			//领域化产品权限
 			//第一版:必须是大会员或者超级订阅用户 且留资 留资表:capital_retention;source = 'medical_domain',未留资提示留资信息
 			//第二版:调资源中台rpc获取用户是否有使用领域化产品的权限 无权限则去购买
@@ -203,6 +230,27 @@ func (m *WorkDesktopMenu) AutoUserPowerInfo() map[string]int {
 				redis.Put(RedisCode, userRegisterTimeKey, strconv.Itoa(int(registerTime)), int(registerTime))
 				UserPowerMap["500"] = 1
 			}
+			//当前用户是否被分配权限
+			entnichePowers := Mysql.SelectBySql(fmt.Sprintf(`SELECT a.product_type,a.ent_id FROM %s a LEFT JOIN %s b ON a.id = b.wait_empower_id WHERE b.status = 1 AND b.ent_user_id = ?`, EntnicheWaitEmpower, EntnichePower), m.EntUserId)
+			if entnichePowers != nil && len(*entnichePowers) > 0 {
+				for _, entnichePower := range *entnichePowers {
+					//排除非当前企业分配的权限
+					if MC.Int64All(entnichePower["ent_id"]) != m.EntId {
+						productType := MC.ObjToString(entnichePower["product_type"])
+						if strings.Contains(productType, "大会员") && len(serviceIds["M"]) > 0 {
+							for _, v := range serviceIds["M"] {
+								UserPowerMap[v] = 0
+							}
+						}
+						if strings.Contains(productType, "VIP订阅") && len(serviceIds["V"]) > 0 {
+							for _, v := range serviceIds["V"] {
+								UserPowerMap[v] = 0
+							}
+						}
+					}
+
+				}
+			}
 		}
 		if UserPowerMap != nil {
 			bytes, err := json.Marshal(UserPowerMap)