check.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package bws
  2. import (
  3. "context"
  4. "encoding/json"
  5. bwsmdl "go-common/app/interface/main/activity/model/bws"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // RedisInfo .
  10. func (s *Service) RedisInfo(c context.Context, loginMid, mid int64, key, day, typ string, del int) (data json.RawMessage, err error) {
  11. if !s.isAdmin(loginMid) {
  12. err = ecode.ActivityNotAdmin
  13. return
  14. }
  15. if key == "" {
  16. if key, err = s.midToKey(c, mid); err != nil {
  17. return
  18. }
  19. }
  20. var (
  21. bid int64 = 1
  22. bs []byte
  23. )
  24. switch typ {
  25. case "point":
  26. if del == 1 {
  27. err = s.dao.DelCachePoints(c, bid)
  28. return
  29. }
  30. var points *bwsmdl.Points
  31. if points, err = s.dao.CachePoints(c, bid); err != nil || points == nil || len(points.Points) == 0 {
  32. log.Error("RedisInfo point error (%v)", err)
  33. return
  34. }
  35. if bs, err = json.Marshal(points.Points); err != nil {
  36. log.Error("RedisInfo point json error (%v)", err)
  37. return
  38. }
  39. data = json.RawMessage(bs)
  40. case "achieve":
  41. if del == 1 {
  42. err = s.dao.DelCacheAchievements(c, bid)
  43. return
  44. }
  45. var achieves *bwsmdl.Achievements
  46. if achieves, err = s.dao.CacheAchievements(c, bid); err != nil || achieves == nil || len(achieves.Achievements) == 0 {
  47. log.Error("RedisInfo achieve error (%v)", err)
  48. return
  49. }
  50. if bs, err = json.Marshal(achieves.Achievements); err != nil {
  51. log.Error("RedisInfo achieve json error (%v)", err)
  52. return
  53. }
  54. data = json.RawMessage(bs)
  55. case "user_point":
  56. if del == 1 {
  57. err = s.dao.DelCacheUserPoints(c, bid, key)
  58. return
  59. }
  60. var res []*bwsmdl.UserPoint
  61. if res, err = s.dao.CacheUserPoints(c, bid, key); err != nil {
  62. log.Error("RedisInfo user point key(%s) error (%v)", key, err)
  63. return
  64. }
  65. if bs, err = json.Marshal(res); err != nil {
  66. log.Error("RedisInfo user point json error (%v)", err)
  67. return
  68. }
  69. data = json.RawMessage(bs)
  70. case "user_achieve":
  71. if del == 1 {
  72. err = s.dao.DelCacheUserAchieves(c, bid, key)
  73. return
  74. }
  75. var res []*bwsmdl.UserAchieve
  76. if res, err = s.dao.CacheUserAchieves(c, bid, key); err != nil {
  77. log.Error("RedisInfo user achieve key(%s) error (%v)", key, err)
  78. return
  79. }
  80. if bs, err = json.Marshal(res); err != nil {
  81. log.Error("RedisInfo user achieve json error (%v)", err)
  82. return
  83. }
  84. data = json.RawMessage(bs)
  85. case "achieve_cnt":
  86. if day == "" {
  87. day = today()
  88. }
  89. if del == 1 {
  90. err = s.dao.DelCacheAchieveCounts(c, bid, day)
  91. return
  92. }
  93. var res []*bwsmdl.CountAchieves
  94. if res, err = s.dao.CacheAchieveCounts(c, bid, day); err != nil {
  95. log.Error("RedisInfo achieve_cnt day(%s) error (%v)", day, err)
  96. return
  97. }
  98. if bs, err = json.Marshal(res); err != nil {
  99. log.Error("RedisInfo achieve_cnt json error (%v)", err)
  100. return
  101. }
  102. data = json.RawMessage(bs)
  103. case "achieve_cnt_db":
  104. if day == "" {
  105. day = today()
  106. }
  107. var res []*bwsmdl.CountAchieves
  108. if res, err = s.dao.RawAchieveCounts(c, bid, day); err != nil {
  109. log.Error("RedisInfo achieve_cnt_db day(%s) error (%v)", day, err)
  110. return
  111. }
  112. if bs, err = json.Marshal(res); err != nil {
  113. log.Error("RedisInfo achieve_cnt_db json error (%v)", err)
  114. return
  115. }
  116. data = json.RawMessage(bs)
  117. default:
  118. err = ecode.RequestErr
  119. }
  120. return
  121. }
  122. // KeyInfo .
  123. func (s *Service) KeyInfo(c context.Context, loginMid, keyID, mid int64, key, typ string, del int) (data json.RawMessage, err error) {
  124. if !s.isAdmin(loginMid) {
  125. err = ecode.ActivityNotAdmin
  126. return
  127. }
  128. var (
  129. bs []byte
  130. )
  131. switch typ {
  132. case "id":
  133. if keyID == 0 {
  134. err = ecode.RequestErr
  135. return
  136. }
  137. var user *bwsmdl.Users
  138. if user, err = s.dao.UserByID(c, keyID); err != nil {
  139. return
  140. }
  141. if bs, err = json.Marshal(user); err != nil {
  142. return
  143. }
  144. data = json.RawMessage(bs)
  145. case "mid":
  146. if mid == 0 {
  147. err = ecode.RequestErr
  148. return
  149. }
  150. if del == 1 {
  151. err = s.dao.DelCacheUsersMid(c, mid)
  152. return
  153. }
  154. var res *bwsmdl.Users
  155. if res, err = s.dao.CacheUsersMid(c, mid); err != nil {
  156. return
  157. }
  158. if bs, err = json.Marshal(res); err != nil {
  159. return
  160. }
  161. data = json.RawMessage(bs)
  162. case "key":
  163. if key == "" {
  164. err = ecode.RequestErr
  165. return
  166. }
  167. if del == 1 {
  168. err = s.dao.DelCacheUsersKey(c, key)
  169. return
  170. }
  171. var res *bwsmdl.Users
  172. if res, err = s.dao.CacheUsersKey(c, key); err != nil {
  173. return
  174. }
  175. if bs, err = json.Marshal(res); err != nil {
  176. return
  177. }
  178. data = json.RawMessage(bs)
  179. default:
  180. err = ecode.RequestErr
  181. }
  182. return
  183. }
  184. // AdminInfo get admin info.
  185. func (s *Service) AdminInfo(c context.Context, bid, mid int64) (data *bwsmdl.AdminInfo, err error) {
  186. data = new(bwsmdl.AdminInfo)
  187. if s.isAdmin(mid) {
  188. data.IsAdmin = true
  189. }
  190. var points *bwsmdl.Points
  191. if points, err = s.dao.Points(c, bid); err != nil || points == nil || len(points.Points) == 0 {
  192. log.Error("s.dao.Points error(%v)", err)
  193. err = ecode.ActivityPointFail
  194. return
  195. }
  196. for _, v := range points.Points {
  197. if v.Ower == mid {
  198. data.Point = v
  199. }
  200. }
  201. if data.Point == nil {
  202. data.Point = struct{}{}
  203. }
  204. return
  205. }