power.go 21 KB

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