level_output.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package service
  2. import (
  3. "gadmin/config"
  4. "gadmin/internal/admin/consts"
  5. "gadmin/internal/admin/forms"
  6. "gadmin/internal/gorm/query"
  7. )
  8. var LevelOutput = new(sLevelOutput)
  9. type sLevelOutput struct{}
  10. type LevelOutputReportInfo struct {
  11. Level []int64 `json:"Level"`
  12. Coin []int64 `json:"Coin"`
  13. Diamond []int64 `json:"Diamond"`
  14. }
  15. type LevelOutputLogItem struct {
  16. Level int64 `json:"Level"`
  17. Coin int64 `json:"Coin"`
  18. Diamond int64 `json:"Diamond"`
  19. }
  20. type LevelOutputInfo struct {
  21. Info LevelOutputReportInfo `json:"info"`
  22. Rows []LevelOutputLogItem `json:"rows"`
  23. }
  24. func (s *sLevelOutput) QueryLog(params forms.LevelOutputReq) (respData LevelOutputInfo, err error) {
  25. resp := LevelOutputReportInfo{}
  26. rdb := query.Use(config.DB).ReportLevelOutput
  27. m := rdb.Select(rdb.ALL, rdb.ID, rdb.Level,
  28. rdb.Coin.Sum().As("coin"),
  29. rdb.Diamond.Sum().As("diamond"),
  30. ).Where(rdb.Level.Gte(int64(params.StartLevel)), rdb.Level.Lt(int64(params.EndLevel)))
  31. switch params.ChannelId {
  32. case consts.ChannelIdNone:
  33. // 不选择渠道
  34. case consts.ChannelIdAllAdv, consts.ChannelIdAllWx, consts.ChannelIdAllTT:
  35. // 所有的广告渠道
  36. m = m.Where(rdb.ChannelID.In(Channel.GetIdsByType(params.ChannelId)...))
  37. default:
  38. // 指定渠道
  39. m = m.Where(rdb.ChannelID.Eq(params.ChannelId))
  40. }
  41. if params.ServerId > 0 {
  42. m = m.Where(rdb.ServerID.Eq(int32(params.ServerId)))
  43. }
  44. result, err := m.Group(rdb.Level).Order(rdb.Level.Desc()).Find()
  45. if err != nil {
  46. return
  47. }
  48. for _, v := range result {
  49. if v != nil {
  50. resp.Level = append(resp.Level, v.Level)
  51. resp.Coin = append(resp.Coin, v.Coin)
  52. resp.Diamond = append(resp.Diamond, v.Diamond)
  53. item := LevelOutputLogItem{
  54. Level: v.Level,
  55. Coin: v.Coin,
  56. Diamond: v.Diamond,
  57. }
  58. respData.Rows = append(respData.Rows, item)
  59. }
  60. }
  61. respData.Info = resp
  62. return
  63. }