dash.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gadmin/config"
  6. "gadmin/internal/admin/forms"
  7. "gadmin/internal/admin/service"
  8. "gadmin/internal/gorm/query"
  9. "gadmin/package/gmdata"
  10. "gadmin/utility"
  11. "gadmin/utility/character"
  12. "gadmin/utility/player"
  13. "gadmin/utility/serializer"
  14. "github.com/gin-gonic/gin"
  15. "github.com/jinzhu/now"
  16. "github.com/spf13/cast"
  17. "sort"
  18. "sync"
  19. "time"
  20. )
  21. func DashboardAdvEcharts(ctx *gin.Context) {
  22. var params forms.QueryAdvEchartsReq
  23. err := ctx.ShouldBindQuery(&params)
  24. if err != nil {
  25. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  26. return
  27. }
  28. if params.Day == "" {
  29. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  30. }
  31. if params.EndDay == "" {
  32. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  33. }
  34. resp, err := service.Dash.QueryAdvEcharts(params)
  35. if err != nil {
  36. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  37. return
  38. }
  39. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  40. }
  41. func GetAllChaptersInfo(ctx *gin.Context) {
  42. data, _ := json.Marshal(gmdata.Chapters)
  43. ctx.JSON(200, gin.H{"code": 0, "data": string(data)})
  44. }
  45. func DashboadDict(ctx *gin.Context) {
  46. resp, err := service.Dash.QueryAllEventItems()
  47. if err != nil {
  48. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  49. return
  50. }
  51. ctx.JSON(200, resp)
  52. }
  53. func Console(ctx *gin.Context) {
  54. type Models struct {
  55. TotalUser int64
  56. Today int64
  57. Week int64
  58. Moon int64
  59. }
  60. t := time.Now()
  61. nt := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
  62. var models Models
  63. for _, DB := range config.GDBGroup {
  64. var u = query.Use(DB).PlayerAttr
  65. totalUser, _ := u.Count()
  66. today, _ := u.Where(u.CreateTime.Gte(nt)).Count()
  67. week, _ := u.Where(u.CreateTime.Gte(nt.Add(-time.Second * 86400 * 7))).Count()
  68. moon, _ := u.Where(u.CreateTime.Gte(nt.Add(-time.Second * 86400 * 30))).Count()
  69. models.TotalUser += totalUser
  70. models.Today += today
  71. models.Week += week
  72. models.Moon += moon
  73. }
  74. ctx.JSON(200, serializer.Suc(models))
  75. }
  76. func DashboadLoginLog(ctx *gin.Context) {
  77. var params forms.LoginlogReq
  78. ctx.ShouldBind(&params)
  79. resp, err := service.Dash.QueryLoginLog(params)
  80. if err != nil {
  81. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  82. return
  83. }
  84. var models forms.ListRes
  85. models.List = resp.Data
  86. ctx.JSON(200, serializer.Suc(models))
  87. }
  88. func DashboadUserChaperLog(ctx *gin.Context) {
  89. var params forms.UserChapterLogReq
  90. err := ctx.ShouldBindQuery(&params)
  91. if err != nil {
  92. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  93. return
  94. }
  95. resp, err := service.Dash.QueryUserChapterLog(params.ServerId, params.Day, params.Days, params.ChapterId, params.Difficulty, params.ChannelId, params.Flag)
  96. if err != nil {
  97. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  98. return
  99. }
  100. if resp == nil {
  101. resp = make([]forms.UserChapterItem, 0)
  102. }
  103. var models forms.ListRes
  104. models.List = resp
  105. ctx.JSON(200, serializer.Suc(models))
  106. }
  107. //func DashboardDieLog(ctx *gin.Context) {
  108. // var params forms.DieDataReq
  109. // err := ctx.ShouldBindQuery(&params)
  110. // if err != nil {
  111. // ctx.JSON(http.StatusOK, ErrorResponse(err))
  112. // return
  113. // }
  114. //
  115. // ctx.JSON(200, service.Dash.QueryUserDieLog(params))
  116. //}
  117. func DashboadConditionUsers(ctx *gin.Context) {
  118. var params forms.DieDataReq
  119. ctx.ShouldBind(&params)
  120. resp, err := service.Dash.QueryConditionUsers(params)
  121. if err != nil {
  122. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  123. return
  124. }
  125. var models forms.ListRes
  126. models.List = resp
  127. ctx.JSON(200, serializer.Suc(models))
  128. }
  129. // 今日基本数据 留存
  130. func DashboardBasicInfo(ctx *gin.Context) {
  131. var params forms.DieDataReq
  132. ctx.ShouldBindQuery(&params)
  133. if params.ServerId <= 0 {
  134. ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
  135. return
  136. }
  137. resp, err := service.Dash.QueryBasicInfo(params.ServerId, params.Day)
  138. if err != nil {
  139. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  140. return
  141. }
  142. ctx.JSON(200, forms.BasicRespData{
  143. Data: resp,
  144. })
  145. }
  146. // DashboardBasicRetention 基础留存率
  147. func DashboardBasicRetention(ctx *gin.Context) {
  148. var params forms.QueryBasicRetentionReq
  149. err := ctx.ShouldBindQuery(&params)
  150. if err != nil {
  151. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  152. return
  153. }
  154. if params.Day == "" {
  155. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  156. }
  157. if params.EndDay == "" {
  158. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  159. }
  160. resp, err := service.Dash.QueryBasicRetention(params)
  161. if err != nil {
  162. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  163. return
  164. }
  165. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  166. }
  167. // 基本数据 爆表
  168. func DashboardBasicReport(ctx *gin.Context) {
  169. var params forms.BasicReportReq
  170. ctx.ShouldBind(&params)
  171. resp, err := service.Dash.QueryBasicReport(ctx, params)
  172. if err != nil {
  173. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  174. return
  175. }
  176. var models forms.ListRes
  177. models.List = resp.Data
  178. if resp.Total <= 0 {
  179. resp.Total = 1
  180. }
  181. models.Page = params.Page
  182. models.PerPage = params.PerPage
  183. models.PageCount = resp.Total / 10
  184. ctx.JSON(200, serializer.Suc(models))
  185. }
  186. // 基本数据 爆表
  187. func DashboardEventReport(ctx *gin.Context) {
  188. var params forms.ConditionReportReq
  189. ctx.ShouldBind(&params)
  190. resp, err := service.Dash.QueryConditionReport(params)
  191. if err != nil {
  192. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  193. return
  194. }
  195. var models forms.ListRes
  196. models.List = resp.Data
  197. if resp.Total <= 0 {
  198. resp.Total = 1
  199. }
  200. models.Page = params.Page
  201. models.PerPage = params.PerPage
  202. models.PageCount = resp.Total / 10
  203. ctx.JSON(200, serializer.Suc(models))
  204. }
  205. // 广告位
  206. func DashboardAdvReport(ctx *gin.Context) {
  207. var params forms.AdvReportReq
  208. ctx.ShouldBindQuery(&params)
  209. if params.Day == "" {
  210. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  211. }
  212. params.PerPage = 1000
  213. resp, err := service.Dash.QueryAdvReport(params)
  214. if err != nil {
  215. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  216. return
  217. }
  218. var models forms.ListRes
  219. models.List = resp.Data
  220. models.Page = 100
  221. models.PerPage = 1
  222. models.PageCount = 1
  223. ctx.JSON(200, serializer.Suc(models))
  224. }
  225. func DashboardFirstAdv(ctx *gin.Context) {
  226. var params forms.FirstAdvReq
  227. ctx.ShouldBindQuery(&params)
  228. resp, err := service.Dash.QueryFirstAdv(ctx, params)
  229. if err != nil {
  230. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  231. return
  232. }
  233. var models forms.ListRes
  234. models.List = resp.Data
  235. if resp.Total <= 0 {
  236. resp.Total = 1
  237. }
  238. models.Page = params.Page
  239. models.PerPage = params.PerPage
  240. models.PageCount = resp.Total / params.PerPage
  241. ctx.JSON(200, serializer.Suc(models))
  242. }
  243. func DashboardFirstAdvStat(ctx *gin.Context) {
  244. var params forms.FirstAdvReq
  245. ctx.ShouldBindQuery(&params)
  246. resp, err := service.Dash.QueryFirstAdvStat(ctx, params)
  247. if err != nil {
  248. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  249. return
  250. }
  251. ctx.JSON(200, serializer.Suc(resp))
  252. }
  253. func DashboardAdvSumm(ctx *gin.Context) {
  254. var params forms.AdvSummReq
  255. ctx.ShouldBindQuery(&params)
  256. resp, err := service.Dash.QueryAdvSumm(ctx, params)
  257. if err != nil {
  258. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  259. return
  260. }
  261. var models forms.ListRes
  262. models.List = resp.Data
  263. if resp.Total <= 0 {
  264. resp.Total = 1
  265. }
  266. models.Page = params.Page
  267. models.PerPage = params.PerPage
  268. models.PageCount = resp.Total / params.PerPage
  269. ctx.JSON(200, serializer.Suc(models))
  270. }
  271. func DashboardAdvDetails(ctx *gin.Context) {
  272. var params forms.AdvDetailsReq
  273. ctx.ShouldBindQuery(&params)
  274. if params.Day == "" {
  275. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  276. }
  277. resp, err := service.Dash.QueryAdvDetailsReq(params)
  278. if err != nil {
  279. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  280. return
  281. }
  282. var models forms.ListRes
  283. models.List = resp.Data
  284. models.Page = 100
  285. models.PerPage = 100
  286. models.PageCount = 1
  287. ctx.JSON(200, serializer.Suc(models))
  288. }
  289. func DashboardAdvUserDetails(ctx *gin.Context) {
  290. var params forms.AdvUserDetailsReq
  291. ctx.ShouldBindQuery(&params)
  292. err := params.Check()
  293. if err != nil {
  294. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  295. }
  296. resp, err := service.Dash.QueryAdvUserDetails(params)
  297. if err != nil {
  298. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  299. return
  300. }
  301. var models forms.ListRes
  302. models.List = resp.Data
  303. models.Page = 100
  304. models.PerPage = 100
  305. models.PageCount = 1
  306. ctx.JSON(200, serializer.Suc(models))
  307. }
  308. // 商品展示位
  309. func DashboardGoodsReport(ctx *gin.Context) {
  310. var params forms.GoodsReportReq
  311. ctx.ShouldBindQuery(&params)
  312. if params.Day == "" {
  313. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  314. }
  315. resp, err := service.Dash.QueryGoodsReport(params)
  316. if err != nil {
  317. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  318. return
  319. }
  320. var models forms.ListRes
  321. models.List = resp.Data
  322. ctx.JSON(200, serializer.Suc(models))
  323. }
  324. // 商品展示位
  325. func DashboardChapterPassLog(ctx *gin.Context) {
  326. var params forms.GoodsReportReq
  327. ctx.ShouldBindQuery(&params)
  328. if params.Day == "" {
  329. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  330. }
  331. var models forms.ListRes
  332. resp, err := service.Dash.QueryChapterPassLog(params)
  333. if err != nil {
  334. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  335. return
  336. }
  337. models.List = resp
  338. ctx.JSON(200, serializer.Suc(models))
  339. }
  340. type ChapterItem struct {
  341. ID int64 `json:"id"`
  342. Diff int `json:"diff"`
  343. Nums int `json:"nums"`
  344. PassNums int `json:"passNums"`
  345. }
  346. var (
  347. GradeLock sync.RWMutex
  348. GradeMap = make(map[string]forms.ListRes)
  349. )
  350. func GradeDistribution(ctx *gin.Context) {
  351. var params forms.GradeDistributionReq
  352. ctx.ShouldBindQuery(&params)
  353. if service.Channel.IsMasterChannel(params.ChannelId) {
  354. ctx.JSON(200, gin.H{"code": 1, "msg": "当前数据仅支持筛选全部渠道或指定子渠道!"})
  355. return
  356. }
  357. if params.ServerId <= 0 {
  358. ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
  359. return
  360. }
  361. DB, err := player.GetDBByServerID(params.ServerId)
  362. if err != nil {
  363. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  364. return
  365. }
  366. marshal, err := json.Marshal(params)
  367. if err != nil {
  368. ctx.JSON(200, gin.H{"code": 1, "msg": err})
  369. return
  370. }
  371. key := character.Md5Content(marshal)
  372. if val, ok := GradeMap[key]; ok {
  373. ctx.JSON(200, serializer.Suc(val))
  374. return
  375. }
  376. GradeLock.RLock()
  377. defer GradeLock.RUnlock()
  378. lists := make([]map[string]interface{}, 0)
  379. var (
  380. q = query.Use(config.GDBGroup[DB]).PlayerAttr
  381. count int64 = 0
  382. levels = []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  383. intervals = [][]int32{{11, 15}, {16, 20}, {21, 40}, {41, 60}, {61, 80}, {81, 90}, {91, 110}, {111, 130}, {131, 160}}
  384. models forms.ListRes
  385. )
  386. day := now.MustParse(params.Day)
  387. endDay := now.MustParse(params.EndDay)
  388. wg := new(sync.WaitGroup)
  389. for _, v := range levels {
  390. wg.Add(1)
  391. go func(v int32, wg *sync.WaitGroup) {
  392. m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))
  393. if params.ChannelId != "" {
  394. tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
  395. pIds := utility.SpiltInt64BySizeFromInt64(tmpIds, 5000)
  396. var tmpCount int64
  397. for _, ids := range pIds {
  398. count, _ = m.Where(q.Playerid.In(ids...), q.Level.Eq(v)).Count()
  399. tmpCount += count
  400. }
  401. lists = append(lists, map[string]interface{}{"level": cast.ToString(v) + "级", "sum": tmpCount, "index": v})
  402. } else {
  403. count, _ = m.Where(q.Level.Eq(v)).Count()
  404. lists = append(lists, map[string]interface{}{"level": cast.ToString(v) + "级", "sum": count, "index": v})
  405. }
  406. wg.Done()
  407. }(v, wg)
  408. }
  409. for _, v := range intervals {
  410. wg.Add(1)
  411. go func(v []int32, wg *sync.WaitGroup) {
  412. m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))
  413. if params.ChannelId != "" {
  414. tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
  415. pIds := utility.SpiltInt64BySizeFromInt64(tmpIds, 5000)
  416. var tmpCount int64
  417. for _, ids := range pIds {
  418. count, _ = m.Where(q.Playerid.In(ids...), q.Level.Between(v[0], v[1])).Count()
  419. tmpCount += count
  420. }
  421. lists = append(lists, map[string]interface{}{"level": fmt.Sprintf("%d~%d级", v[0], v[1]), "sum": tmpCount, "index": v[0] + v[1]})
  422. } else {
  423. count, _ = m.Where(q.Level.Between(v[0], v[1])).Count()
  424. lists = append(lists, map[string]interface{}{"level": fmt.Sprintf("%d~%d级", v[0], v[1]), "sum": count, "index": v[0] + v[1]})
  425. }
  426. wg.Done()
  427. }(v, wg)
  428. }
  429. //wg.Add(1)
  430. //go func(wg *sync.WaitGroup) {
  431. // m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))
  432. //
  433. // if params.ChannelId != "" {
  434. // tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
  435. // pIds := utility.SpiltInt64BySize(tmpIds, 10000)
  436. // var tmpCount int64
  437. // for _, ids := range pIds {
  438. // count, _ = m.Where(q.Playerid.In(ids...), q.Level.Between(141, 1000)).Count()
  439. // tmpCount += count
  440. // }
  441. // lists = append(lists, map[string]interface{}{"level": "140级以上", "sum": tmpCount, "index": 1000})
  442. // } else {
  443. // count, _ = m.Where(q.Level.Between(141, 1000)).Count()
  444. // lists = append(lists, map[string]interface{}{"level": "140级以上", "sum": count, "index": 1000})
  445. // }
  446. //
  447. // wg.Done()
  448. //}(wg)
  449. wg.Wait()
  450. type lev struct {
  451. Level string `json:"level"`
  452. Sum int32 `json:"sum"`
  453. Index int32 `json:"index"`
  454. }
  455. var lst []lev
  456. for _, v := range lists {
  457. lst = append(lst, lev{v["level"].(string), cast.ToInt32(v["sum"]), cast.ToInt32(v["index"])})
  458. }
  459. sort.Slice(lst, func(i, j int) bool {
  460. return lst[i].Index < lst[j].Index // 升序
  461. })
  462. models.List = lst
  463. GradeMap[key] = models
  464. ctx.JSON(200, serializer.Suc(models))
  465. }
  466. func DashboardGudongLog(ctx *gin.Context) {
  467. var params forms.GoodsReportReq
  468. ctx.ShouldBindQuery(&params)
  469. if params.Day == "" {
  470. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  471. }
  472. resp, err := service.Dash.QueryGudongLog(params)
  473. // resp = []ChapterItem{{ID: 1, Diff: 0}}
  474. if err != nil {
  475. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  476. return
  477. }
  478. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  479. }
  480. func DashboardUserRolesMap(ctx *gin.Context) {
  481. var params forms.GoodsReportReq
  482. ctx.ShouldBindQuery(&params)
  483. if params.Day == "" {
  484. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  485. }
  486. if params.ServerId <= 0 {
  487. ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
  488. return
  489. }
  490. resp, err := service.Dash.QueryUserRolesMap(params)
  491. if err != nil {
  492. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  493. return
  494. }
  495. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  496. }
  497. // DashboardExpeditionLog 远征报表
  498. func DashboardExpeditionLog(ctx *gin.Context) {
  499. var params forms.ExpeditionReportReq
  500. err := ctx.ShouldBindQuery(&params)
  501. if err != nil {
  502. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  503. return
  504. }
  505. if params.Day == "" {
  506. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  507. }
  508. if params.EndDay == "" {
  509. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  510. }
  511. resp, err := service.Dash.QueryExpeditionLog(params)
  512. if err != nil {
  513. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  514. return
  515. }
  516. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  517. }
  518. // DashboardExpeditionFloor 远征关卡未通关信息
  519. func DashboardExpeditionFloor(ctx *gin.Context) {
  520. var params forms.ExpeditionFloorReq
  521. err := ctx.ShouldBindQuery(&params)
  522. if err != nil {
  523. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  524. return
  525. }
  526. if params.Day == "" {
  527. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  528. }
  529. resp, err := service.Dash.QueryExpeditionFloor(params)
  530. if err != nil {
  531. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  532. return
  533. }
  534. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  535. }
  536. // DashboardDuelLog 远征报表
  537. func DashboardDuelLog(ctx *gin.Context) {
  538. var params forms.DuelReportReq
  539. err := ctx.ShouldBindQuery(&params)
  540. if err != nil {
  541. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  542. return
  543. }
  544. if params.Day == "" {
  545. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  546. }
  547. if params.EndDay == "" {
  548. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  549. }
  550. resp, err := service.Dash.QueryDuelLog(params)
  551. if err != nil {
  552. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  553. return
  554. }
  555. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  556. }
  557. // DashboardIdiomLog 金榜题名报表
  558. func DashboardIdiomLog(ctx *gin.Context) {
  559. var params forms.IdiomReportReq
  560. err := ctx.ShouldBindQuery(&params)
  561. if err != nil {
  562. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  563. return
  564. }
  565. if params.Day == "" {
  566. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  567. }
  568. if params.EndDay == "" {
  569. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  570. }
  571. resp, err := service.Dash.QueryIdiomLog(params)
  572. if err != nil {
  573. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  574. return
  575. }
  576. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  577. }
  578. // DashboardBossLog 暗影突袭报表
  579. func DashboardBossLog(ctx *gin.Context) {
  580. var params forms.BossReportReq
  581. err := ctx.ShouldBindQuery(&params)
  582. if err != nil {
  583. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  584. return
  585. }
  586. if params.ServerId <= 0 {
  587. ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
  588. return
  589. }
  590. if params.Day == "" {
  591. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  592. }
  593. if params.EndDay == "" {
  594. params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
  595. }
  596. resp, err := service.Dash.QueryBossLog(params)
  597. if err != nil {
  598. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  599. return
  600. }
  601. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  602. }
  603. // HeroLevelDistribution 英雄等级分布
  604. func HeroLevelDistribution(ctx *gin.Context) {
  605. var params forms.HeroLevelDistributedReq
  606. err := ctx.ShouldBindQuery(&params)
  607. if err != nil {
  608. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  609. return
  610. }
  611. if params.Day == "" {
  612. params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
  613. }
  614. if params.ServerId <= 0 {
  615. ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
  616. return
  617. }
  618. resp, err := service.Dash.QueryRolesLog(params)
  619. ctx.JSON(200, gin.H{"data": resp, "code": 0})
  620. }
  621. // DashboardSevenBasic 七日任务基础信息
  622. func DashboardSevenBasic(ctx *gin.Context) {
  623. var params forms.SevenBasicReq
  624. ctx.ShouldBindQuery(&params)
  625. resp, err := service.Dash.QuerySevenBasic(params)
  626. if err != nil {
  627. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  628. return
  629. }
  630. var models forms.ListRes
  631. models.List = resp.Data
  632. if resp.Total <= 0 {
  633. resp.Total = 1
  634. }
  635. models.Page = params.Page
  636. models.PerPage = params.PerPage
  637. models.PageCount = (resp.Total + params.PerPage - 1) / params.PerPage
  638. ctx.JSON(200, serializer.Suc(models))
  639. }
  640. // DashboardSevenTask 七日任务任务统计
  641. func DashboardSevenTask(ctx *gin.Context) {
  642. var params forms.SevenTaskReq
  643. ctx.ShouldBindQuery(&params)
  644. resp, err := service.Dash.QuerySevenTask(params)
  645. if err != nil {
  646. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  647. return
  648. }
  649. var models forms.ListRes
  650. models.List = resp.Data
  651. if resp.Total <= 0 {
  652. resp.Total = 1
  653. }
  654. models.Page = params.Page
  655. models.PerPage = params.PerPage
  656. models.PageCount = resp.Total / 10
  657. ctx.JSON(200, serializer.Suc(models))
  658. }
  659. // DashboardSevenAward 七日任务奖励统计
  660. func DashboardSevenAward(ctx *gin.Context) {
  661. var params forms.SevenAwardReq
  662. ctx.ShouldBindQuery(&params)
  663. resp, err := service.Dash.QuerySevenAward(params)
  664. if err != nil {
  665. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  666. return
  667. }
  668. var models forms.ListRes
  669. models.List = resp.Data
  670. if resp.Total <= 0 {
  671. resp.Total = 1
  672. }
  673. models.Page = params.Page
  674. models.PerPage = params.PerPage
  675. models.PageCount = resp.Total / 10
  676. ctx.JSON(200, serializer.Suc(models))
  677. }
  678. // DashboardDisconnectList 断线重连统计列表
  679. func DashboardDisconnectList(ctx *gin.Context) {
  680. var params forms.DisconnectListReq
  681. ctx.ShouldBindQuery(&params)
  682. resp, err := service.Dash.QueryDisconnectList(params)
  683. if err != nil {
  684. ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
  685. return
  686. }
  687. var models forms.ListRes
  688. models.List = resp.Data
  689. if resp.Total <= 0 {
  690. resp.Total = 1
  691. }
  692. models.Page = params.Page
  693. models.PerPage = params.PerPage
  694. models.PageCount = resp.Total / 10
  695. ctx.JSON(200, serializer.Suc(models))
  696. }