power.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "app.yhyue.com/moapp/jybase/common"
  10. "app.yhyue.com/moapp/jybase/date"
  11. "app.yhyue.com/moapp/jybase/mongodb"
  12. "app.yhyue.com/moapp/jybase/redis"
  13. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/entity"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. // 权益
  17. type PowerService struct {
  18. *entity.Conn
  19. }
  20. func NewPower(conn *entity.Conn) *PowerService {
  21. return &PowerService{
  22. conn,
  23. }
  24. }
  25. var level_map = map[int64]string{
  26. 1: "专家版",
  27. 2: "智慧版",
  28. 3: "商机版",
  29. 4: "试用版",
  30. 5: "自定义",
  31. 6: "商机版2.0",
  32. 7: "专家版2.0",
  33. }
  34. /*
  35. 权益相关
  36. userid //mongodb用户id
  37. baseUserId //base_user用户id
  38. accountId //账户id
  39. entId =5; //企业id
  40. positionType //职位类型 0个人 1企业
  41. positionId //职位id
  42. 切换到企业身份后,session中userId存的是企业雇员的职位id,个人身份,userId还是原来mgo库里的_id
  43. */
  44. func (this *PowerService) Power(userid string, baseUserId, accountId, entId, positionType, positionId int64) *entity.Power {
  45. logx.Info("-----req------", userid, baseUserId, accountId, entId, positionType, positionId)
  46. ent := &entity.Ent{}
  47. entniche := &entity.Entniche{}
  48. vip := &entity.Vip{}
  49. member := &entity.Member{}
  50. free := &entity.Free{}
  51. userPower := entity.Power{}
  52. if positionId == 0 {
  53. free.IsFree = true
  54. return &entity.Power{
  55. Vip: vip,
  56. Member: member,
  57. Free: free,
  58. Ent: ent,
  59. Entniche: entniche,
  60. }
  61. }
  62. cacheBl := false
  63. if bytes, err := redis.GetBytes("newother", GetRedisName(positionId)); err == nil && bytes != nil {
  64. if err := json.Unmarshal(*bytes, &userPower); err == nil {
  65. cacheBl = true
  66. }
  67. }
  68. if !cacheBl {
  69. if userid == "" && positionId > 0 {
  70. logx.Info("检测到异常数据:", userid, baseUserId, accountId, entId, positionType, positionId)
  71. if baseUserId <= 0 {
  72. //获取mongodb的userid
  73. pd := this.Conn.BaseMysql.SelectBySql(`select user_id from base_service.base_position where id =? limit 1`, positionId)
  74. if pd != nil && len(*pd) > 0 {
  75. baseUserId = common.Int64All((*pd)[0]["user_id"])
  76. }
  77. }
  78. if baseUserId > 0 {
  79. ud, ok := this.Conn.MgoJy.FindOneByField("user", map[string]interface{}{"base_user_id": baseUserId}, `{"_id:1"}`)
  80. if ud != nil && ok && len(*ud) > 0 {
  81. userid = mongodb.BsonIdToSId((*ud)["_id"])
  82. }
  83. }
  84. entity.Alert(fmt.Sprintf("检测到异常数据已修复: userId:%s ,positionId:%v ,positionType:%v </br>", userid, positionId, positionType))
  85. logx.Info("检测到异常数据修复后:", userid, baseUserId, accountId, entId, positionType, positionId)
  86. }
  87. //获取用户本身的注册时间和邮箱、这个与个人、企业无关
  88. mgoUserFields := map[string]interface{}{
  89. "s_myemail": 1,
  90. "l_registedate": 1,
  91. "s_phone": 1,
  92. "s_m_phone": 1,
  93. "base_user_id": 1,
  94. }
  95. //大会员权益表查询条件
  96. bigmemberServiceUserQuery := map[string]interface{}{"s_userid": userid, "i_status": 0}
  97. //个人身份 取user表中权益
  98. if positionType == 0 {
  99. mgoUserFields["i_vip_status"] = 1
  100. mgoUserFields["l_vip_starttime"] = 1
  101. mgoUserFields["l_vip_endtime"] = 1
  102. mgoUserFields["o_vipjy"] = 1
  103. mgoUserFields["i_member_status"] = 1
  104. mgoUserFields["i_member_give"] = 1
  105. mgoUserFields["s_member_mainid"] = 1
  106. mgoUserFields["i_member_sub_status"] = 1
  107. mgoUserFields["i_member_trial"] = 1
  108. mgoUserFields["o_member_jy"] = 1
  109. mgoUserFields["o_jy"] = 1
  110. mgoUserFields["i_ts_guide"] = 1
  111. mgoUserFields["i_member_apppushunread"] = 1
  112. mgoUserFields["i_entniche_apppushunread"] = 1
  113. mgoUserFields["i_apppushunread"] = 1
  114. mgoUserFields["i_member_starttime"] = 1
  115. mgoUserFields["i_member_endtime"] = 1
  116. } else {
  117. bigmemberServiceUserQuery["s_userid"] = positionId
  118. }
  119. data, ok := this.Conn.MgoJy.FindById("user", userid, mgoUserFields)
  120. if ok && data != nil && len(*data) > 0 {
  121. //基本信息
  122. registeDate := common.Int64All((*data)["l_registedate"]) //注册时间
  123. phone, _ := common.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string) //
  124. ent.PrivateGD = this.Conn.Mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0 //广东移动DICT 用户
  125. mail := common.ObjToString((*data)["s_myemail"])
  126. i_ts_guide := common.Int64All((*data)["i_ts_guide"])
  127. i_member_apppushunread := common.Int64All((*data)["i_member_apppushunread"])
  128. i_entniche_apppushunread := common.Int64All((*data)["i_entniche_apppushunread"])
  129. i_apppushunread := common.Int64All((*data)["i_apppushunread"])
  130. free.Mail = mail
  131. free.Registedate = registeDate
  132. free.Phone = phone
  133. free.TsGuide = i_ts_guide
  134. free.Apppushunread = i_apppushunread
  135. free.EntnicheApppushunread = i_entniche_apppushunread
  136. free.MemberApppushunread = i_member_apppushunread
  137. //个人权益
  138. if positionType == 0 {
  139. o_jy, _ := (*data)["o_jy"].(map[string]interface{})
  140. a_key, _ := o_jy["a_key"].([]interface{})
  141. free.FreeHasKey = len(a_key) > 0
  142. free.OjyLength = int64(len(o_jy))
  143. if common.IntAll((o_jy)["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate {
  144. //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
  145. free.IsUpgrade = true //新免费用户
  146. }
  147. //超级订阅
  148. vipStatus := common.Int64All((*data)["i_vip_status"])
  149. vipStartTime := common.Int64All((*data)["l_vip_starttime"])
  150. vipEndTime := common.Int64All((*data)["l_vip_endtime"])
  151. ovipjy := common.ObjToMap((*data)["o_vipjy"])
  152. oBuyset := common.ObjToMap((*ovipjy)["o_buyset"])
  153. upgrade := common.Int64All((*oBuyset)["upgrade"])
  154. areacount := common.Int64All((*oBuyset)["areacount"])
  155. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  156. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  157. newcitysArr := ConfirmInt64Arr(newcitys)
  158. vip = &entity.Vip{
  159. Status: vipStatus,
  160. StartTime: vipStartTime,
  161. EndTime: vipEndTime,
  162. Upgrade: upgrade,
  163. Areacount: areacount,
  164. Buyerclasscount: buyerclasscount,
  165. MaxKeyLength: 300,
  166. PowerType: common.Int64All(common.If(vipStatus > 0, 1, 0)),
  167. NewCitys: newcitysArr,
  168. }
  169. if (*ovipjy)["a_items"] != nil {
  170. a_items := common.ObjArrToMapArr((*ovipjy)["a_items"].([]interface{}))
  171. vip.HasKey = HasKey(a_items)
  172. }
  173. //个人member
  174. i_member_sub_status := common.IntAllDef((*data)["i_member_sub_status"], 0)
  175. memberStatus := common.Int64All((*data)["i_member_status"])
  176. memberStarttime := common.Int64All((*data)["i_member_starttime"])
  177. memberEndtime := common.Int64All((*data)["i_member_endtime"])
  178. member = &entity.Member{
  179. Status: memberStatus,
  180. StartTime: memberStarttime,
  181. EndTime: memberEndtime,
  182. MaxKeyLength: 300, //最大关键词数量限制
  183. PowerType: common.Int64All(common.If(memberStatus > 0, 1, 0)),
  184. }
  185. omemberjy := common.ObjToMap((*data)["o_member_jy"])
  186. if (*omemberjy)["a_items"] != nil {
  187. if arr, ok := (*omemberjy)["a_items"].([]interface{}); ok {
  188. a_items := common.ObjArrToMapArr(arr)
  189. member.HasKey = HasKey(a_items)
  190. }
  191. }
  192. if memberStatus > 0 {
  193. member.MemberPower = 1 //是否分配了大会员;0:否 1:是
  194. }
  195. logx.Info("in--------------------->", (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0)
  196. if (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
  197. member.Pid = common.ObjToString((*data)["s_member_mainid"])
  198. bigmemberServiceUserQuery["s_userid"] = member.Pid
  199. member.IsSubCount = 1
  200. }
  201. if (member.Pid != "" && common.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": userid}) > 0 {
  202. member.Used = true
  203. }
  204. if (*data)["i_member_trial"] != nil {
  205. member.IsMemberTrial = 1
  206. }
  207. //获取大会员版本名称
  208. member.MemberName = level_map[memberStatus]
  209. } else if positionType == 1 {
  210. entnicheUserId := this.GetEntnicheUserId(entId, phone)
  211. //免费
  212. fdata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  213. "i_entid": entId,
  214. "i_userid": entnicheUserId,
  215. "i_type": 2, //0:商机管理 1:超级订阅/大会员 2:免费
  216. })
  217. o_jy, _ := (*fdata)["o_entniche"].(map[string]interface{})
  218. free.OjyLength = int64(len(o_jy))
  219. a_key, _ := o_jy["a_key"].([]interface{})
  220. free.FreeHasKey = len(a_key) > 0
  221. if common.IntAll(o_jy["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate { //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
  222. free.IsUpgrade = true //新免费用户
  223. }
  224. //企业
  225. edata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  226. "i_entid": entId,
  227. "i_userid": entnicheUserId,
  228. "i_type": 1, //0:商机管理 1:超级订阅/大会员
  229. })
  230. eudata, _ := this.Conn.MgoJy.FindOne("ent_user", map[string]interface{}{
  231. "i_entid": entId,
  232. "i_userid": entnicheUserId,
  233. })
  234. if eudata != nil && len(*eudata) > 0 {
  235. i_ts_guide := common.Int64All((*eudata)["i_ts_guide"])
  236. free.TsGuide = i_ts_guide
  237. haskey := false
  238. o_entniche := &map[string]interface{}{}
  239. if edata != nil && len(*edata) > 0 {
  240. o_entniche = common.ObjToMap((*edata)["o_entniche"])
  241. if (*o_entniche)["a_items"] != nil {
  242. if arr, ok := (*o_entniche)["a_items"].([]interface{}); ok {
  243. a_items := common.ObjArrToMapArr(arr)
  244. haskey = HasKey(a_items)
  245. }
  246. }
  247. }
  248. if common.Int64All((*eudata)["i_vip_status"]) > 0 {
  249. oBuyset := common.ObjToMap((*o_entniche)["o_buyset"])
  250. areacount := common.Int64All((*oBuyset)["areacount"])
  251. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  252. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  253. newcitysArr := ConfirmInt64Arr(newcitys)
  254. status := common.Int64All((*eudata)["i_vip_status"])
  255. starttime := common.Int64All((*eudata)["l_vip_starttime"])
  256. endtime := common.Int64All((*eudata)["l_vip_endtime"])
  257. vip = &entity.Vip{
  258. Status: status,
  259. StartTime: starttime,
  260. EndTime: endtime,
  261. Upgrade: 1, //企业版默认是升级版
  262. Areacount: areacount,
  263. Buyerclasscount: buyerclasscount,
  264. MaxKeyLength: 300,
  265. PowerType: 2,
  266. HasKey: haskey,
  267. NewCitys: newcitysArr,
  268. }
  269. }
  270. if common.Int64All((*eudata)["i_member_status"]) > 0 {
  271. member.PowerType = 2
  272. status := common.Int64All((*eudata)["i_member_status"])
  273. starttime := common.Int64All((*eudata)["i_member_starttime"])
  274. endtime := common.Int64All((*eudata)["i_member_endtime"])
  275. member = &entity.Member{
  276. Status: status,
  277. StartTime: starttime,
  278. EndTime: endtime,
  279. MemberName: level_map[status],
  280. PowerType: 2,
  281. HasKey: haskey,
  282. }
  283. //是否使用
  284. s_positionId := strconv.Itoa(int(positionId))
  285. if this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": s_positionId}) > 0 {
  286. member.Used = true
  287. }
  288. }
  289. }
  290. }
  291. //大会员相关权益数量
  292. memberServiceMap := map[int64]bool{}
  293. serviceList := this.Conn.Mysql.Find("bigmember_service_user", bigmemberServiceUserQuery, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
  294. logx.Info("-----bigmemberServiceUserQuery-------", bigmemberServiceUserQuery)
  295. if serviceList != nil && len(*serviceList) != 0 {
  296. pCount, eCount, dailyNum, customers := 0, 0, 0, 10
  297. for _, item := range *serviceList {
  298. serviceid := common.Int64All(item["s_serviceid"])
  299. memberServiceMap[serviceid] = true
  300. member.MemberPowerList = append(member.MemberPowerList, serviceid)
  301. if serviceid == 14 { //项目数量
  302. pCount = common.IntAll(item["i_frequency"])
  303. } else if serviceid == 4 || serviceid == 12 || serviceid == 13 { //企业情报监控 企业中标动态
  304. tEcount := common.IntAll(item["i_frequency"])
  305. if tEcount > eCount {
  306. eCount = tEcount
  307. }
  308. } else if serviceid == 17 || serviceid == 18 { //每日数据包
  309. dailyNum = common.IntAll(item["i_frequency"])
  310. } else if serviceid == 7 { //潜在客户 关注客户
  311. customers = common.IntAll(item["i_frequency"])
  312. }
  313. }
  314. member.EntNum = int64(eCount)
  315. member.ProNum = int64(pCount)
  316. member.DailyNum = int64(dailyNum)
  317. member.Customers = int64(customers)
  318. }
  319. //
  320. if phone != "" {
  321. //查询是否是商机管理付费用户
  322. res := this.Conn.Mysql.SelectBySql(`SELECT i. STATUS AS status,i.model , i.isNew, i.power_source, r.role_id, u.power, i.name,i.id,i.startdate,i.enddate,i.auth_status,i.auth_reason,i.dept_subscribe FROM (entniche_user u LEFT JOIN entniche_user_role r ON r.user_id = u.id ) LEFT JOIN entniche_info i ON u.ent_id = i.id WHERE u.phone = ? and i.id = ? ORDER BY i. STATUS DESC, i.auth_status DESC`, phone, entId)
  323. if res != nil && len(*res) > 0 {
  324. for _, v := range *res {
  325. if common.IntAll(v["id"]) == 0 {
  326. continue
  327. }
  328. entnicheStatus := common.Int64All(v["status"])
  329. entnichePower := common.Int64All(v["power"])
  330. if entnicheStatus == 1 {
  331. entnicheStatus = entnichePower
  332. }
  333. entniche.IsNew = common.Int64All(v["isNew"])
  334. entniche.Status = entnicheStatus //企业是否有商机管理权限
  335. entniche.IsEntPower = entnichePower //个人是否有商机管理权限
  336. entniche.PowerSource = common.Int64All(v["power_source"])
  337. entniche.StartTime = common.Int64All(v["startdate"])
  338. entniche.EndTime = common.Int64All(v["enddate"])
  339. entniche.Model = common.Int64All(v["model"])
  340. //
  341. ent.Name = common.ObjToString(v["name"])
  342. ent.EntRoleId = common.Int64All(v["role_id"])
  343. ent.EntAuthStatus = common.Int64All(v["auth_status"])
  344. ent.EntAuthReason = common.ObjToString(v["auth_reason"])
  345. ent.DeptSubscribe = common.Int64All(v["dept_subscribe"])
  346. //判断企业是否购买企业版相关
  347. eweData := this.Conn.Mysql.SelectBySql(`select * from entniche_wait_empower where ent_id=? and end_time>?`, entId, time.Now().Format(date.Date_Full_Layout))
  348. if eweData != nil && len(*eweData) > 0 {
  349. ent.Services = true
  350. for _, v := range *eweData {
  351. product_type := common.ObjToString(v["product_type"])
  352. if strings.Contains(product_type, entity.ProductType_member) {
  353. ent.BuyMember = 1
  354. } else if strings.Contains(product_type, entity.ProductType_vip) {
  355. ent.BuyVip = 1
  356. }
  357. }
  358. }
  359. //企业管理员
  360. if ent.EntRoleId == 1 && ((ent.BuyMember == 1 || ent.BuyVip == 1) || (entniche.Status == 1 && entniche.PowerSource == 0)) {
  361. ent.EntSubscribeManager = 1
  362. }
  363. //部门管理员
  364. if ent.EntRoleId == 2 && entniche.Status == 1 && entniche.PowerSource == 0 && ent.DeptSubscribe == 1 {
  365. ent.EntSubscribeManager = 1
  366. }
  367. //
  368. if ent.EntRoleId == 1 || ent.EntRoleId == 2 {
  369. if (ent.BuyMember == 1 || ent.BuyVip == 1) || (entniche.Status == 1 && entniche.PowerSource == 0) {
  370. ent.EntSubscribe = 1
  371. }
  372. }
  373. }
  374. }
  375. }
  376. if vip.Status <= 0 && member.Status <= 0 && (entniche.Status <= 0 || (entniche.Status > 0 && entniche.PowerSource == 1)) {
  377. free.IsFree = true
  378. } else {
  379. free.IsFree = false
  380. }
  381. //查看原文
  382. var (
  383. originalData = this.Conn.BaseMysql.SelectBySql(`SELECT user_type,total FROM jianyu.original_power WHERE state = 0`)
  384. )
  385. if originalData != nil && len(*originalData) > 0 {
  386. for _, ov := range *originalData {
  387. total := common.Int64All(ov["total"])
  388. switch common.IntAll(ov["user_type"]) {
  389. case 1:
  390. vip.Original = total
  391. case 2:
  392. member.Original = total
  393. case 3:
  394. entniche.Original = total
  395. default:
  396. free.Original = total
  397. }
  398. }
  399. }
  400. }
  401. userPower = entity.Power{
  402. Vip: vip,
  403. Member: member,
  404. Free: free,
  405. Ent: ent,
  406. Entniche: entniche,
  407. }
  408. }
  409. //存储缓存
  410. go func() {
  411. if bytes, err := json.Marshal(userPower); err == nil && bytes != nil {
  412. oneDayMore := 60*60*24 + rand.Intn(60*60)
  413. _ = redis.PutBytes("newother", GetRedisName(positionId), &bytes, oneDayMore)
  414. }
  415. }()
  416. //实时更新的数据 没法存缓存
  417. //免费用户在企业画像/采购单位画像/附件下载留资
  418. userPower.Free.FreeEntPort, userPower.Free.FreeBuyerPort, userPower.Free.FreeFile = FreeExperience(userid, positionId, positionType)
  419. //
  420. notBigFileBool := userPower.Member.Status <= 0 || !strings.Contains(intStringsJoin(userPower.Member.MemberPowerList), "3")
  421. uk := common.If(notBigFileBool && userPower.Vip.Status > 0 && userPower.Vip.Upgrade > 0, "v", "f").(string)
  422. userPower.Vip.FileNum = FileNum(uk, userid, positionId, positionType)
  423. return &userPower
  424. }
  425. // 免费用户体验会员功能权限
  426. // 免费用户在企业画像/采购单位画像/附件下载留资 留资成功后用户才有功能使用次数
  427. func FreeExperience(userId string, positionId, positionType int64) (int64, int64, int64) {
  428. if positionType == 1 {
  429. userId = strconv.Itoa(int(positionId))
  430. }
  431. entPortKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheEntPortKey, userId)))
  432. buyerPortKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheBuyerPortKey, userId)))
  433. fileKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheFileKey, userId)))
  434. return entPortKey, buyerPortKey, fileKey
  435. }
  436. // 获取附件下载次数
  437. func FileNum(uk, userid string, positionId, positionType int64) int64 {
  438. if positionType == 1 {
  439. userid = strconv.Itoa(int(positionId))
  440. }
  441. fileUploadNum := map[string]int{
  442. "f": 0,
  443. "v": 10,
  444. }
  445. //附件下载包的剩余次数
  446. filePackKey := fmt.Sprintf(entity.FilePackNumKey, userid, fmt.Sprint(time.Now().Month()))
  447. filePackNum := redis.GetInt(entity.PowerCacheDb, filePackKey)
  448. num := fileUploadNum[uk] - redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.VipFileUploadNumKey, userid, fmt.Sprint(time.Now().Month()))) + filePackNum
  449. return int64(num)
  450. }
  451. /*
  452. 判断是企业或个人
  453. 1.企业
  454. entniche_rule
  455. 查询 vip/member free ent entniche
  456. 2.个人
  457. 查询vip member free
  458. */
  459. func (this *PowerService) GetEntnicheUserId(entId int64, phone string) int64 {
  460. data := this.Conn.Mysql.SelectBySql(`select id from entniche_user where phone =? and ent_id =?`, phone, entId)
  461. if data != nil && len(*data) > 0 {
  462. return common.Int64All((*data)[0]["id"])
  463. }
  464. return -1
  465. }
  466. // 是否有关键词
  467. func HasKey(a_items []map[string]interface{}) bool {
  468. for _, v := range a_items {
  469. akey, _ := v["a_key"].([]interface{})
  470. if len(akey) > 0 {
  471. return true
  472. }
  473. }
  474. return false
  475. }
  476. // 获取redis key
  477. func GetRedisName(positionId int64) string {
  478. if positionId == 0 {
  479. return ""
  480. }
  481. return fmt.Sprintf("user_power_info_%v", positionId)
  482. }
  483. // 清除redis缓存
  484. func (this *PowerService) DelRedisPower(positionId int64) bool {
  485. if positionId == 0 {
  486. return false
  487. }
  488. return redis.Del("newother", GetRedisName(positionId))
  489. }
  490. func intStringsJoin(is []int64) string {
  491. var str = []string{}
  492. for _, v := range is {
  493. str = append(str, strconv.Itoa(int(v)))
  494. }
  495. return strings.Join(str, ",")
  496. }
  497. func ConfirmInt64Arr(arr []interface{}) []int64 {
  498. tmp := make([]int64, 0)
  499. for _, v := range arr {
  500. tmp = append(tmp, common.Int64All(v))
  501. }
  502. return tmp
  503. }