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. //
  21. func NewPower(conn *entity.Conn) *PowerService {
  22. return &PowerService{
  23. conn,
  24. }
  25. }
  26. var level_map = map[int64]string{
  27. 1: "专家版",
  28. 2: "智慧版",
  29. 3: "商机版",
  30. 4: "试用版",
  31. 5: "自定义",
  32. 6: "商机版2.0",
  33. 7: "专家版2.0",
  34. }
  35. /*
  36. 权益相关
  37. userid //mongodb用户id
  38. baseUserId //base_user用户id
  39. accountId //账户id
  40. entId =5; //企业id
  41. positionType //职位类型 0个人 1企业
  42. positionId //职位id
  43. 切换到企业身份后,session中userId存的是企业雇员的职位id,个人身份,userId还是原来mgo库里的_id
  44. */
  45. func (this *PowerService) Power(userid string, baseUserId, accountId, entId, positionType, positionId int64) *entity.Power {
  46. logx.Info("-----req------", userid, baseUserId, accountId, entId, positionType, positionId)
  47. ent := &entity.Ent{}
  48. entniche := &entity.Entniche{}
  49. vip := &entity.Vip{}
  50. member := &entity.Member{}
  51. free := &entity.Free{}
  52. userPower := entity.Power{}
  53. if positionId == 0 {
  54. free.IsFree = true
  55. return &entity.Power{
  56. Vip: vip,
  57. Member: member,
  58. Free: free,
  59. Ent: ent,
  60. Entniche: entniche,
  61. }
  62. }
  63. cacheBl := false
  64. if bytes, err := redis.GetBytes("newother", GetRedisName(positionId)); err == nil && bytes != nil {
  65. if err := json.Unmarshal(*bytes, &userPower); err == nil {
  66. cacheBl = true
  67. }
  68. }
  69. if !cacheBl {
  70. if userid == "" && positionId > 0 {
  71. logx.Info("检测到异常数据:", userid, baseUserId, accountId, entId, positionType, positionId)
  72. if baseUserId <= 0 {
  73. //获取mongodb的userid
  74. pd := this.Conn.BaseMysql.SelectBySql(`select user_id from base_service.base_position where id =? limit 1`, positionId)
  75. if pd != nil && len(*pd) > 0 {
  76. baseUserId = common.Int64All((*pd)[0]["user_id"])
  77. }
  78. }
  79. if baseUserId > 0 {
  80. ud, ok := this.Conn.MgoJy.FindOneByField("user", map[string]interface{}{"base_user_id": baseUserId}, `{"_id:1"}`)
  81. if ud != nil && ok && len(*ud) > 0 {
  82. userid = mongodb.BsonIdToSId((*ud)["_id"])
  83. }
  84. }
  85. entity.Alert(fmt.Sprintf("检测到异常数据已修复: userId:%s ,positionId:%v ,positionType:%v </br>", userid, positionId, positionType))
  86. logx.Info("检测到异常数据修复后:", userid, baseUserId, accountId, entId, positionType, positionId)
  87. }
  88. //获取用户本身的注册时间和邮箱、这个与个人、企业无关
  89. mgoUserFields := map[string]interface{}{
  90. "s_myemail": 1,
  91. "l_registedate": 1,
  92. "s_phone": 1,
  93. "s_m_phone": 1,
  94. "base_user_id": 1,
  95. }
  96. //大会员权益表查询条件
  97. bigmemberServiceUserQuery := map[string]interface{}{"s_userid": userid, "i_status": 0}
  98. //个人身份 取user表中权益
  99. if positionType == 0 {
  100. mgoUserFields["i_vip_status"] = 1
  101. mgoUserFields["l_vip_starttime"] = 1
  102. mgoUserFields["l_vip_endtime"] = 1
  103. mgoUserFields["o_vipjy"] = 1
  104. mgoUserFields["i_member_status"] = 1
  105. mgoUserFields["i_member_give"] = 1
  106. mgoUserFields["s_member_mainid"] = 1
  107. mgoUserFields["i_member_sub_status"] = 1
  108. mgoUserFields["i_member_trial"] = 1
  109. mgoUserFields["o_member_jy"] = 1
  110. mgoUserFields["o_jy"] = 1
  111. mgoUserFields["i_ts_guide"] = 1
  112. mgoUserFields["i_member_apppushunread"] = 1
  113. mgoUserFields["i_entniche_apppushunread"] = 1
  114. mgoUserFields["i_apppushunread"] = 1
  115. mgoUserFields["i_member_starttime"] = 1
  116. mgoUserFields["i_member_endtime"] = 1
  117. } else {
  118. bigmemberServiceUserQuery["s_userid"] = positionId
  119. }
  120. data, ok := this.Conn.MgoJy.FindById("user", userid, mgoUserFields)
  121. if ok && data != nil && len(*data) > 0 {
  122. //基本信息
  123. registeDate := common.Int64All((*data)["l_registedate"]) //注册时间
  124. phone, _ := common.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string) //
  125. ent.PrivateGD = this.Conn.Mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0 //广东移动DICT 用户
  126. mail := common.ObjToString((*data)["s_myemail"])
  127. i_ts_guide := common.Int64All((*data)["i_ts_guide"])
  128. i_member_apppushunread := common.Int64All((*data)["i_member_apppushunread"])
  129. i_entniche_apppushunread := common.Int64All((*data)["i_entniche_apppushunread"])
  130. i_apppushunread := common.Int64All((*data)["i_apppushunread"])
  131. free.Mail = mail
  132. free.Registedate = registeDate
  133. free.Phone = phone
  134. free.TsGuide = i_ts_guide
  135. free.Apppushunread = i_apppushunread
  136. free.EntnicheApppushunread = i_entniche_apppushunread
  137. free.MemberApppushunread = i_member_apppushunread
  138. //个人权益
  139. if positionType == 0 {
  140. o_jy, _ := (*data)["o_jy"].(map[string]interface{})
  141. a_key, _ := o_jy["a_key"].([]interface{})
  142. free.FreeHasKey = len(a_key) > 0
  143. free.OjyLength = int64(len(o_jy))
  144. if common.IntAll((o_jy)["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate {
  145. //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
  146. free.IsUpgrade = true //新免费用户
  147. }
  148. //超级订阅
  149. vipStatus := common.Int64All((*data)["i_vip_status"])
  150. vipStartTime := common.Int64All((*data)["l_vip_starttime"])
  151. vipEndTime := common.Int64All((*data)["l_vip_endtime"])
  152. ovipjy := common.ObjToMap((*data)["o_vipjy"])
  153. oBuyset := common.ObjToMap((*ovipjy)["o_buyset"])
  154. upgrade := common.Int64All((*oBuyset)["upgrade"])
  155. areacount := common.Int64All((*oBuyset)["areacount"])
  156. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  157. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  158. newcitysArr := ConfirmInt64Arr(newcitys)
  159. vip = &entity.Vip{
  160. Status: vipStatus,
  161. StartTime: vipStartTime,
  162. EndTime: vipEndTime,
  163. Upgrade: upgrade,
  164. Areacount: areacount,
  165. Buyerclasscount: buyerclasscount,
  166. MaxKeyLength: 300,
  167. PowerType: common.Int64All(common.If(vipStatus > 0, 1, 0)),
  168. NewCitys: newcitysArr,
  169. }
  170. if (*ovipjy)["a_items"] != nil {
  171. a_items := common.ObjArrToMapArr((*ovipjy)["a_items"].([]interface{}))
  172. vip.HasKey = HasKey(a_items)
  173. }
  174. //个人member
  175. i_member_sub_status := common.IntAllDef((*data)["i_member_sub_status"], 0)
  176. memberStatus := common.Int64All((*data)["i_member_status"])
  177. memberStarttime := common.Int64All((*data)["i_member_starttime"])
  178. memberEndtime := common.Int64All((*data)["i_member_endtime"])
  179. member = &entity.Member{
  180. Status: memberStatus,
  181. StartTime: memberStarttime,
  182. EndTime: memberEndtime,
  183. MaxKeyLength: 300, //最大关键词数量限制
  184. PowerType: common.Int64All(common.If(memberStatus > 0, 1, 0)),
  185. }
  186. omemberjy := common.ObjToMap((*data)["o_member_jy"])
  187. if (*omemberjy)["a_items"] != nil {
  188. if arr, ok := (*omemberjy)["a_items"].([]interface{}); ok {
  189. a_items := common.ObjArrToMapArr(arr)
  190. member.HasKey = HasKey(a_items)
  191. }
  192. }
  193. if memberStatus > 0 {
  194. member.MemberPower = 1 //是否分配了大会员;0:否 1:是
  195. }
  196. logx.Info("in--------------------->", (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0)
  197. if (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
  198. member.Pid = common.ObjToString((*data)["s_member_mainid"])
  199. bigmemberServiceUserQuery["s_userid"] = member.Pid
  200. member.IsSubCount = 1
  201. }
  202. if (member.Pid != "" && common.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": userid}) > 0 {
  203. member.Used = true
  204. }
  205. if (*data)["i_member_trial"] != nil {
  206. member.IsMemberTrial = 1
  207. }
  208. //获取大会员版本名称
  209. member.MemberName = level_map[memberStatus]
  210. } else if positionType == 1 {
  211. entnicheUserId := this.GetEntnicheUserId(entId, phone)
  212. //免费
  213. fdata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  214. "i_entid": entId,
  215. "i_userid": entnicheUserId,
  216. "i_type": 2, //0:商机管理 1:超级订阅/大会员 2:免费
  217. })
  218. o_jy, _ := (*fdata)["o_entniche"].(map[string]interface{})
  219. free.OjyLength = int64(len(o_jy))
  220. a_key, _ := o_jy["a_key"].([]interface{})
  221. free.FreeHasKey = len(a_key) > 0
  222. if common.IntAll(o_jy["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate { //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
  223. free.IsUpgrade = true //新免费用户
  224. }
  225. //企业
  226. edata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  227. "i_entid": entId,
  228. "i_userid": entnicheUserId,
  229. "i_type": 1, //0:商机管理 1:超级订阅/大会员
  230. })
  231. eudata, _ := this.Conn.MgoJy.FindOne("ent_user", map[string]interface{}{
  232. "i_entid": entId,
  233. "i_userid": entnicheUserId,
  234. })
  235. if eudata != nil && len(*eudata) > 0 {
  236. i_ts_guide := common.Int64All((*eudata)["i_ts_guide"])
  237. free.TsGuide = i_ts_guide
  238. haskey := false
  239. o_entniche := &map[string]interface{}{}
  240. if edata != nil && len(*edata) > 0 {
  241. o_entniche = common.ObjToMap((*edata)["o_entniche"])
  242. if (*o_entniche)["a_items"] != nil {
  243. if arr, ok := (*o_entniche)["a_items"].([]interface{}); ok {
  244. a_items := common.ObjArrToMapArr(arr)
  245. haskey = HasKey(a_items)
  246. }
  247. }
  248. }
  249. if common.Int64All((*eudata)["i_vip_status"]) > 0 {
  250. oBuyset := common.ObjToMap((*o_entniche)["o_buyset"])
  251. areacount := common.Int64All((*oBuyset)["areacount"])
  252. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  253. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  254. newcitysArr := ConfirmInt64Arr(newcitys)
  255. status := common.Int64All((*eudata)["i_vip_status"])
  256. starttime := common.Int64All((*eudata)["l_vip_starttime"])
  257. endtime := common.Int64All((*eudata)["l_vip_endtime"])
  258. vip = &entity.Vip{
  259. Status: status,
  260. StartTime: starttime,
  261. EndTime: endtime,
  262. Upgrade: 1, //企业版默认是升级版
  263. Areacount: areacount,
  264. Buyerclasscount: buyerclasscount,
  265. MaxKeyLength: 300,
  266. PowerType: 2,
  267. HasKey: haskey,
  268. NewCitys: newcitysArr,
  269. }
  270. }
  271. if common.Int64All((*eudata)["i_member_status"]) > 0 {
  272. member.PowerType = 2
  273. status := common.Int64All((*eudata)["i_member_status"])
  274. starttime := common.Int64All((*eudata)["i_member_starttime"])
  275. endtime := common.Int64All((*eudata)["i_member_endtime"])
  276. member = &entity.Member{
  277. Status: status,
  278. StartTime: starttime,
  279. EndTime: endtime,
  280. MemberName: level_map[status],
  281. PowerType: 2,
  282. HasKey: haskey,
  283. }
  284. //是否使用
  285. s_positionId := strconv.Itoa(int(positionId))
  286. if this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": s_positionId}) > 0 {
  287. member.Used = true
  288. }
  289. }
  290. }
  291. }
  292. //大会员相关权益数量
  293. memberServiceMap := map[int64]bool{}
  294. serviceList := this.Conn.Mysql.Find("bigmember_service_user", bigmemberServiceUserQuery, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
  295. logx.Info("-----bigmemberServiceUserQuery-------", bigmemberServiceUserQuery)
  296. if serviceList != nil && len(*serviceList) != 0 {
  297. pCount, eCount, dailyNum, customers := 0, 0, 0, 10
  298. for _, item := range *serviceList {
  299. serviceid := common.Int64All(item["s_serviceid"])
  300. memberServiceMap[serviceid] = true
  301. member.MemberPowerList = append(member.MemberPowerList, serviceid)
  302. if serviceid == 14 { //项目数量
  303. pCount = common.IntAll(item["i_frequency"])
  304. } else if serviceid == 4 || serviceid == 12 || serviceid == 13 { //企业情报监控 企业中标动态
  305. tEcount := common.IntAll(item["i_frequency"])
  306. if tEcount > eCount {
  307. eCount = tEcount
  308. }
  309. } else if serviceid == 17 || serviceid == 18 { //每日数据包
  310. dailyNum = common.IntAll(item["i_frequency"])
  311. } else if serviceid == 7 { //潜在客户 关注客户
  312. customers = common.IntAll(item["i_frequency"])
  313. }
  314. }
  315. member.EntNum = int64(eCount)
  316. member.ProNum = int64(pCount)
  317. member.DailyNum = int64(dailyNum)
  318. member.Customers = int64(customers)
  319. }
  320. //
  321. if phone != "" {
  322. //查询是否是商机管理付费用户
  323. 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)
  324. if res != nil && len(*res) > 0 {
  325. for _, v := range *res {
  326. if common.IntAll(v["id"]) == 0 {
  327. continue
  328. }
  329. entnicheStatus := common.Int64All(v["status"])
  330. entnichePower := common.Int64All(v["power"])
  331. if entnicheStatus == 1 {
  332. entnicheStatus = entnichePower
  333. }
  334. entniche.IsNew = common.Int64All(v["isNew"])
  335. entniche.Status = entnicheStatus //企业是否有商机管理权限
  336. entniche.IsEntPower = entnichePower //个人是否有商机管理权限
  337. entniche.PowerSource = common.Int64All(v["power_source"])
  338. entniche.StartTime = common.Int64All(v["startdate"])
  339. entniche.EndTime = common.Int64All(v["enddate"])
  340. entniche.Model = common.Int64All(v["model"])
  341. //
  342. ent.Name = common.ObjToString(v["name"])
  343. ent.EntRoleId = common.Int64All(v["role_id"])
  344. ent.EntAuthStatus = common.Int64All(v["auth_status"])
  345. ent.EntAuthReason = common.ObjToString(v["auth_reason"])
  346. ent.DeptSubscribe = common.Int64All(v["dept_subscribe"])
  347. //判断企业是否购买企业版相关
  348. eweData := this.Conn.Mysql.SelectBySql(`select * from entniche_wait_empower where ent_id=? and end_time>?`, entId, time.Now().Format(date.Date_Full_Layout))
  349. if eweData != nil && len(*eweData) > 0 {
  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. }