power.go 22 KB

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