power.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. free.PpStatus = common.Int64All(o_jy["i_ppstatus"])
  149. free.PpStartTime = common.Int64All(o_jy["l_areaStart_p"])
  150. free.PpEndTime = common.Int64All(o_jy["l_areaEnd_p"])
  151. //超级订阅
  152. vipStatus := common.Int64All((*data)["i_vip_status"])
  153. vipStartTime := common.Int64All((*data)["l_vip_starttime"])
  154. vipEndTime := common.Int64All((*data)["l_vip_endtime"])
  155. ovipjy := common.ObjToMap((*data)["o_vipjy"])
  156. oBuyset := common.ObjToMap((*ovipjy)["o_buyset"])
  157. upgrade := common.Int64All((*oBuyset)["upgrade"])
  158. areacount := common.Int64All((*oBuyset)["areacount"])
  159. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  160. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  161. newcitysArr := ConfirmInt64Arr(newcitys)
  162. vip = &entity.Vip{
  163. Status: vipStatus,
  164. StartTime: vipStartTime,
  165. EndTime: vipEndTime,
  166. Upgrade: upgrade,
  167. Areacount: areacount,
  168. Buyerclasscount: buyerclasscount,
  169. MaxKeyLength: 300,
  170. PowerType: common.Int64All(common.If(vipStatus > 0, 1, 0)),
  171. NewCitys: newcitysArr,
  172. }
  173. if (*ovipjy)["a_items"] != nil {
  174. a_items := common.ObjArrToMapArr((*ovipjy)["a_items"].([]interface{}))
  175. vip.HasKey = HasKey(a_items)
  176. }
  177. //个人member
  178. i_member_sub_status := common.IntAllDef((*data)["i_member_sub_status"], 0)
  179. memberStatus := common.Int64All((*data)["i_member_status"])
  180. memberStarttime := common.Int64All((*data)["i_member_starttime"])
  181. memberEndtime := common.Int64All((*data)["i_member_endtime"])
  182. member = &entity.Member{
  183. Status: memberStatus,
  184. StartTime: memberStarttime,
  185. EndTime: memberEndtime,
  186. MaxKeyLength: 300, //最大关键词数量限制
  187. PowerType: common.Int64All(common.If(memberStatus > 0, 1, 0)),
  188. }
  189. omemberjy := common.ObjToMap((*data)["o_member_jy"])
  190. if (*omemberjy)["a_items"] != nil {
  191. if arr, ok := (*omemberjy)["a_items"].([]interface{}); ok {
  192. a_items := common.ObjArrToMapArr(arr)
  193. member.HasKey = HasKey(a_items)
  194. }
  195. }
  196. if memberStatus > 0 {
  197. member.MemberPower = 1 //是否分配了大会员;0:否 1:是
  198. }
  199. logx.Info("in--------------------->", (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0)
  200. if (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
  201. member.Pid = common.ObjToString((*data)["s_member_mainid"])
  202. bigmemberServiceUserQuery["s_userid"] = member.Pid
  203. member.IsSubCount = 1
  204. }
  205. if (member.Pid != "" && common.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": userid}) > 0 {
  206. member.Used = true
  207. }
  208. if (*data)["i_member_trial"] != nil {
  209. member.IsMemberTrial = 1
  210. }
  211. //获取大会员版本名称
  212. member.MemberName = level_map[memberStatus]
  213. } else if positionType == 1 {
  214. entnicheUserId := this.GetEntnicheUserId(entId, phone)
  215. //免费
  216. fdata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  217. "i_entid": entId,
  218. "i_userid": entnicheUserId,
  219. "i_type": 2, //0:商机管理 1:超级订阅/大会员 2:免费
  220. })
  221. o_jy, _ := (*fdata)["o_entniche"].(map[string]interface{})
  222. free.OjyLength = int64(len(o_jy))
  223. a_key, _ := o_jy["a_key"].([]interface{})
  224. free.FreeHasKey = len(a_key) > 0
  225. if common.IntAll(o_jy["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate { //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
  226. free.IsUpgrade = true //新免费用户
  227. }
  228. //企业
  229. edata, _ := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
  230. "i_entid": entId,
  231. "i_userid": entnicheUserId,
  232. "i_type": 1, //0:商机管理 1:超级订阅/大会员
  233. })
  234. eudata, _ := this.Conn.MgoJy.FindOne("ent_user", map[string]interface{}{
  235. "i_entid": entId,
  236. "i_userid": entnicheUserId,
  237. })
  238. if eudata != nil && len(*eudata) > 0 {
  239. i_ts_guide := common.Int64All((*eudata)["i_ts_guide"])
  240. free.TsGuide = i_ts_guide
  241. haskey := false
  242. o_entniche := &map[string]interface{}{}
  243. if edata != nil && len(*edata) > 0 {
  244. o_entniche = common.ObjToMap((*edata)["o_entniche"])
  245. if (*o_entniche)["a_items"] != nil {
  246. if arr, ok := (*o_entniche)["a_items"].([]interface{}); ok {
  247. a_items := common.ObjArrToMapArr(arr)
  248. haskey = HasKey(a_items)
  249. }
  250. }
  251. }
  252. if common.Int64All((*eudata)["i_vip_status"]) > 0 {
  253. oBuyset := common.ObjToMap((*o_entniche)["o_buyset"])
  254. areacount := common.Int64All((*oBuyset)["areacount"])
  255. buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
  256. newcitys, _ := (*oBuyset)["newcitys"].([]interface{})
  257. newcitysArr := ConfirmInt64Arr(newcitys)
  258. status := common.Int64All((*eudata)["i_vip_status"])
  259. starttime := common.Int64All((*eudata)["l_vip_starttime"])
  260. endtime := common.Int64All((*eudata)["l_vip_endtime"])
  261. vip = &entity.Vip{
  262. Status: status,
  263. StartTime: starttime,
  264. EndTime: endtime,
  265. Upgrade: 1, //企业版默认是升级版
  266. Areacount: areacount,
  267. Buyerclasscount: buyerclasscount,
  268. MaxKeyLength: 300,
  269. PowerType: 2,
  270. HasKey: haskey,
  271. NewCitys: newcitysArr,
  272. }
  273. }
  274. if common.Int64All((*eudata)["i_member_status"]) > 0 {
  275. member.PowerType = 2
  276. status := common.Int64All((*eudata)["i_member_status"])
  277. starttime := common.Int64All((*eudata)["i_member_starttime"])
  278. endtime := common.Int64All((*eudata)["i_member_endtime"])
  279. member = &entity.Member{
  280. Status: status,
  281. StartTime: starttime,
  282. EndTime: endtime,
  283. MemberName: level_map[status],
  284. PowerType: 2,
  285. HasKey: haskey,
  286. }
  287. //是否使用
  288. s_positionId := strconv.Itoa(int(positionId))
  289. if this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": s_positionId}) > 0 {
  290. member.Used = true
  291. }
  292. }
  293. }
  294. }
  295. //大会员相关权益数量
  296. memberServiceMap := map[int64]bool{}
  297. serviceList := this.Conn.Mysql.Find("bigmember_service_user", bigmemberServiceUserQuery, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
  298. logx.Info("-----bigmemberServiceUserQuery-------", bigmemberServiceUserQuery)
  299. if serviceList != nil && len(*serviceList) != 0 {
  300. pCount, eCount, dailyNum, customers := 0, 0, 0, 10
  301. for _, item := range *serviceList {
  302. serviceid := common.Int64All(item["s_serviceid"])
  303. memberServiceMap[serviceid] = true
  304. member.MemberPowerList = append(member.MemberPowerList, serviceid)
  305. if serviceid == 14 { //项目数量
  306. pCount = common.IntAll(item["i_frequency"])
  307. } else if serviceid == 4 || serviceid == 12 || serviceid == 13 { //企业情报监控 企业中标动态
  308. tEcount := common.IntAll(item["i_frequency"])
  309. if tEcount > eCount {
  310. eCount = tEcount
  311. }
  312. } else if serviceid == 17 || serviceid == 18 { //每日数据包
  313. dailyNum = common.IntAll(item["i_frequency"])
  314. } else if serviceid == 7 { //潜在客户 关注客户
  315. customers = common.IntAll(item["i_frequency"])
  316. }
  317. }
  318. member.EntNum = int64(eCount)
  319. member.ProNum = int64(pCount)
  320. member.DailyNum = int64(dailyNum)
  321. member.Customers = int64(customers)
  322. }
  323. //
  324. if phone != "" {
  325. //查询是否是商机管理付费用户
  326. 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)
  327. if res != nil && len(*res) > 0 {
  328. for _, v := range *res {
  329. if common.IntAll(v["id"]) == 0 {
  330. continue
  331. }
  332. entnicheStatus := common.Int64All(v["status"])
  333. entnichePower := common.Int64All(v["power"])
  334. if entnicheStatus == 1 {
  335. entnicheStatus = entnichePower
  336. }
  337. entniche.IsNew = common.Int64All(v["isNew"])
  338. entniche.Status = entnicheStatus //企业是否有商机管理权限
  339. entniche.IsEntPower = entnichePower //个人是否有商机管理权限
  340. entniche.PowerSource = common.Int64All(v["power_source"])
  341. entniche.StartTime = common.Int64All(v["startdate"])
  342. entniche.EndTime = common.Int64All(v["enddate"])
  343. entniche.Model = common.Int64All(v["model"])
  344. //
  345. ent.Name = common.ObjToString(v["name"])
  346. ent.EntRoleId = common.Int64All(v["role_id"])
  347. ent.EntAuthStatus = common.Int64All(v["auth_status"])
  348. ent.EntAuthReason = common.ObjToString(v["auth_reason"])
  349. ent.DeptSubscribe = common.Int64All(v["dept_subscribe"])
  350. //判断企业是否购买企业版相关
  351. eweData := this.Conn.Mysql.SelectBySql(`select * from entniche_wait_empower where ent_id=? and end_time>?`, entId, time.Now().Format(date.Date_Full_Layout))
  352. if eweData != nil && len(*eweData) > 0 {
  353. ent.Services = true
  354. for _, v := range *eweData {
  355. product_type := common.ObjToString(v["product_type"])
  356. if strings.Contains(product_type, entity.ProductType_member) {
  357. ent.BuyMember = 1
  358. } else if strings.Contains(product_type, entity.ProductType_vip) {
  359. ent.BuyVip = 1
  360. }
  361. }
  362. }
  363. //企业管理员
  364. if ent.EntRoleId == 1 && ((ent.BuyMember == 1 || ent.BuyVip == 1) || (entniche.Status == 1 && entniche.PowerSource == 0)) {
  365. ent.EntSubscribeManager = 1
  366. }
  367. //部门管理员
  368. if ent.EntRoleId == 2 && entniche.Status == 1 && entniche.PowerSource == 0 && ent.DeptSubscribe == 1 {
  369. ent.EntSubscribeManager = 1
  370. }
  371. //
  372. if ent.EntRoleId == 1 || ent.EntRoleId == 2 {
  373. if (ent.BuyMember == 1 || ent.BuyVip == 1) || (entniche.Status == 1 && entniche.PowerSource == 0) {
  374. ent.EntSubscribe = 1
  375. }
  376. }
  377. }
  378. }
  379. }
  380. if vip.Status <= 0 && member.Status <= 0 && (entniche.Status <= 0 || (entniche.Status > 0 && entniche.PowerSource == 1)) {
  381. free.IsFree = true
  382. } else {
  383. free.IsFree = false
  384. }
  385. //查看原文
  386. var (
  387. originalData = this.Conn.BaseMysql.SelectBySql(`SELECT user_type,total FROM jianyu.original_power WHERE state = 0`)
  388. )
  389. if originalData != nil && len(*originalData) > 0 {
  390. for _, ov := range *originalData {
  391. total := common.Int64All(ov["total"])
  392. switch common.IntAll(ov["user_type"]) {
  393. case 1:
  394. vip.Original = total
  395. case 2:
  396. member.Original = total
  397. case 3:
  398. entniche.Original = total
  399. default:
  400. free.Original = total
  401. }
  402. }
  403. }
  404. }
  405. userPower = entity.Power{
  406. Vip: vip,
  407. Member: member,
  408. Free: free,
  409. Ent: ent,
  410. Entniche: entniche,
  411. }
  412. }
  413. //存储缓存
  414. go func() {
  415. if bytes, err := json.Marshal(userPower); err == nil && bytes != nil {
  416. oneDayMore := 60*60*24 + rand.Intn(60*60)
  417. _ = redis.PutBytes("newother", GetRedisName(positionId), &bytes, oneDayMore)
  418. }
  419. }()
  420. //实时更新的数据 没法存缓存
  421. //免费用户在企业画像/采购单位画像/附件下载留资
  422. userPower.Free.FreeEntPort, userPower.Free.FreeBuyerPort, userPower.Free.FreeFile = FreeExperience(userid, positionId, positionType)
  423. //
  424. notBigFileBool := userPower.Member.Status <= 0 || !strings.Contains(intStringsJoin(userPower.Member.MemberPowerList), "3")
  425. uk := common.If(notBigFileBool && userPower.Vip.Status > 0 && userPower.Vip.Upgrade > 0, "v", "f").(string)
  426. userPower.Vip.FileNum = FileNum(uk, userid, positionId, positionType)
  427. return &userPower
  428. }
  429. // 免费用户体验会员功能权限
  430. // 免费用户在企业画像/采购单位画像/附件下载留资 留资成功后用户才有功能使用次数
  431. func FreeExperience(userId string, positionId, positionType int64) (int64, int64, int64) {
  432. if positionType == 1 {
  433. userId = strconv.Itoa(int(positionId))
  434. }
  435. entPortKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheEntPortKey, userId)))
  436. buyerPortKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheBuyerPortKey, userId)))
  437. fileKey := common.Int64All(redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheFileKey, userId)))
  438. return entPortKey, buyerPortKey, fileKey
  439. }
  440. // 获取附件下载次数
  441. func FileNum(uk, userid string, positionId, positionType int64) int64 {
  442. if positionType == 1 {
  443. userid = strconv.Itoa(int(positionId))
  444. }
  445. fileUploadNum := map[string]int{
  446. "f": 0,
  447. "v": 10,
  448. }
  449. //附件下载包的剩余次数
  450. filePackKey := fmt.Sprintf(entity.FilePackNumKey, userid, fmt.Sprint(time.Now().Month()))
  451. filePackNum := redis.GetInt(entity.PowerCacheDb, filePackKey)
  452. num := fileUploadNum[uk] - redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.VipFileUploadNumKey, userid, fmt.Sprint(time.Now().Month()))) + filePackNum
  453. return int64(num)
  454. }
  455. /*
  456. 判断是企业或个人
  457. 1.企业
  458. entniche_rule
  459. 查询 vip/member free ent entniche
  460. 2.个人
  461. 查询vip member free
  462. */
  463. func (this *PowerService) GetEntnicheUserId(entId int64, phone string) int64 {
  464. data := this.Conn.Mysql.SelectBySql(`select id from entniche_user where phone =? and ent_id =?`, phone, entId)
  465. if data != nil && len(*data) > 0 {
  466. return common.Int64All((*data)[0]["id"])
  467. }
  468. return -1
  469. }
  470. // 是否有关键词
  471. func HasKey(a_items []map[string]interface{}) bool {
  472. for _, v := range a_items {
  473. akey, _ := v["a_key"].([]interface{})
  474. if len(akey) > 0 {
  475. return true
  476. }
  477. }
  478. return false
  479. }
  480. // 获取redis key
  481. func GetRedisName(positionId int64) string {
  482. if positionId == 0 {
  483. return ""
  484. }
  485. return fmt.Sprintf("user_power_info_%v", positionId)
  486. }
  487. // 清除redis缓存
  488. func (this *PowerService) DelRedisPower(positionId int64) bool {
  489. if positionId == 0 {
  490. return false
  491. }
  492. return redis.Del("newother", GetRedisName(positionId))
  493. }
  494. func intStringsJoin(is []int64) string {
  495. var str = []string{}
  496. for _, v := range is {
  497. str = append(str, strconv.Itoa(int(v)))
  498. }
  499. return strings.Join(str, ",")
  500. }
  501. func ConfirmInt64Arr(arr []interface{}) []int64 {
  502. tmp := make([]int64, 0)
  503. for _, v := range arr {
  504. tmp = append(tmp, common.Int64All(v))
  505. }
  506. return tmp
  507. }