init.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package cache
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/cache"
  5. )
  6. const (
  7. DEL = "del"
  8. GET = "get"
  9. )
  10. var Cache cache.Cache
  11. func init() {
  12. var err error
  13. Cache, err = cache.NewCache("memory", `{"interval":60}`)
  14. if err != nil {
  15. panic(err)
  16. }
  17. }
  18. const (
  19. //根据公众号openid查询用户公众号
  20. GetWxUserGzhByOpenId = "user_model.GetWxUserGzhByOpenId"
  21. //根据微信用户id查询用户公众号
  22. GetWxUserGzhByWxUId = "user_model.GetWxUserGzhByWxUId"
  23. //根据微信用户id和appid查询用户公众号
  24. GetWxUserGzhByWxUIdAndAppId = "user_model.GetWxUserGzhByWxUIdAndAppId"
  25. //项目当前融资总额
  26. ProjectCurrentInvestment = "project_join_model.CurrentInvestment"
  27. //项目当前融资总额-我想认购
  28. ProjectCurrentExpectInvestment = "project_join_model.CurrentExpectInvestment"
  29. //项目关注人数
  30. ProjectFollowCount = "project_model.GetFollowersCountByPId"
  31. //项目投资人列表
  32. ProjectInvestors = "project_join_model.GetInvestorsByPId"
  33. //我想认购-投资人列表
  34. ProjectExpectInvestors = "project_join_model.GetExpectInvestorsByPId"
  35. //抽奖活动-已开奖的奖品数量
  36. OpenedAwardCount = "lottery_model.GetOpenedProductCount"
  37. //翻红包专题-合体次数
  38. FHBSuccessCount = "zt_model.GetFHBSuccessCount"
  39. //翻红包专题-红包记录
  40. FHBRecordById = "zt_model.GetFHBRecordById"
  41. //翻红包专题-合体成功列表
  42. FHBSuccessRecordsByWxUId = "zt_model.GetFHBSuccessRecordsByWxUId"
  43. //
  44. GetWxUserById = "user_model.GetWxUserById"
  45. GetThreeWxUserById = "user_model.GetThreeWxUserById"
  46. //商品
  47. GetProductPackagetByPId = "product_model.GetPackageList"
  48. GetProductByPId = "product_model.GetProductById"
  49. GetProductByPIdAndProvince = "product_model.GetProductByPIdAndProvince"
  50. //项目
  51. GetProjectById = "project_model.GetProjectById"
  52. //默认签章
  53. GetDefaultSealByUId = "tsign_model.GetDefaultSealByUId"
  54. // 根据uId,pId查询个人摘要签
  55. GetAllUserFileSignByPIdAndUId = "tsign_model.GetAllUserFileSignByPIdAndUId"
  56. // 根据uId查询个人摘要签
  57. GetAllUserFileSignByUId = "tsign_model.GetAllUserFileSignByUId"
  58. //文章详情分享送佣金
  59. ArticleDetailOpenBenefitByAId = "article_model.ArticleDetailOpenBenefitByAId"
  60. // 根据活动ID,获取活动信息
  61. GetActivityById = "kj_model.GetActivityById"
  62. //自动登录Key
  63. WapAutoLoginKey = "permit_controller.WapAutoLoginKey"
  64. )
  65. func GetKey(key string, params ...interface{}) string {
  66. cacheKey := ""
  67. switch key {
  68. case GetWxUserGzhByWxUIdAndAppId:
  69. cacheKey = fmt.Sprintf("%s.wxUid(%d).appId(%s)", key, params[0], params[1])
  70. case GetWxUserGzhByWxUId:
  71. cacheKey = fmt.Sprintf("%s.wxUid(%d)", key, params[0])
  72. case GetWxUserGzhByOpenId:
  73. cacheKey = fmt.Sprintf("%s.openId(%s)", key, params[0])
  74. case GetProjectById:
  75. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  76. case ProjectCurrentInvestment:
  77. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  78. case ProjectCurrentExpectInvestment:
  79. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  80. case ProjectFollowCount:
  81. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  82. case ProjectInvestors:
  83. cacheKey = fmt.Sprintf("%s.pId(%d).page(%d).perPage(%d)", key, params[0], params[1], params[2])
  84. case ProjectExpectInvestors:
  85. cacheKey = fmt.Sprintf("%s.pId(%d).page(%d).perPage(%d)", key, params[0], params[1], params[2])
  86. case OpenedAwardCount:
  87. cacheKey = fmt.Sprintf("%s.actId(%d).proId(%d)", key, params[0], params[1])
  88. case FHBSuccessCount:
  89. cacheKey = fmt.Sprintf("%s.wxUId(%d).cId(%d).date(%s)", key, params[0], params[1], params[2])
  90. case FHBRecordById:
  91. cacheKey = fmt.Sprintf("%s.id(%d)", key, params[0])
  92. case GetWxUserById:
  93. cacheKey = fmt.Sprintf("%s.id(%d)", key, params[0])
  94. case FHBSuccessRecordsByWxUId:
  95. cacheKey = fmt.Sprintf("%s.uId(%d).cId(%d)", key, params[0], params[1])
  96. case GetDefaultSealByUId:
  97. cacheKey = fmt.Sprintf("%s.uId(%d)", key, params[0])
  98. case GetAllUserFileSignByPIdAndUId:
  99. cacheKey = fmt.Sprintf("%s.uId(%d).pId(%d)", key, params[0], params[1])
  100. case GetAllUserFileSignByUId:
  101. cacheKey = fmt.Sprintf("%s.uId(%d)", key, params[0])
  102. case ArticleDetailOpenBenefitByAId:
  103. cacheKey = fmt.Sprintf("%s.aId(%d).wxUId(%d).oTime(%d)", key, params[0], params[1], params[2])
  104. case GetActivityById:
  105. cacheKey = fmt.Sprintf("%s_%d", key, params[0])
  106. case WapAutoLoginKey:
  107. cacheKey = fmt.Sprintf("%s.uId(%d)", key, params[0])
  108. case GetProductPackagetByPId:
  109. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  110. case GetProductByPId:
  111. cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  112. case GetProductByPIdAndProvince:
  113. cacheKey = fmt.Sprintf("%s.pId(%d)prv(%s)", key, params[0], params[1])
  114. }
  115. return cacheKey
  116. }
  117. // func DelKey(key string, params ...interface{}) string {
  118. // cacheKey := ""
  119. // switch key {
  120. // case ProjectCurrentInvestment:
  121. // cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  122. // case ProjectFollowCount:
  123. // cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
  124. // case ProjectInvestors:
  125. // cacheKey = fmt.Sprintf("%s.pId(%d).page(%d).perPage(%d)", key, params[0], params[1], params[2])
  126. // case OpenedAwardCount:
  127. // cacheKey = fmt.Sprintf("%s.actId(%d).proId(%d)", key, params[0], params[1])
  128. // case FHBSuccessCount:
  129. // cacheKey = fmt.Sprintf("%s.wxUId(%d).cId(%d).date(%s)", key, params[0], params[1], params[2])
  130. // case FHBRecordById:
  131. // cacheKey = fmt.Sprintf("%s.id(%d)", key, params[0])
  132. // case GetWxUserById:
  133. // cacheKey = fmt.Sprintf("%s.id(%d)", key, params[0])
  134. // }
  135. // cache.Cache.Delete(cacheKey)
  136. // }