stat.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/spy/model"
  6. )
  7. // UpdateState update spy state.
  8. func (s *Service) UpdateState(c context.Context, state int8, id int64, operater string) (err error) {
  9. var (
  10. context string
  11. )
  12. if _, err = s.spyDao.UpdateStatState(c, state, id); err != nil {
  13. return
  14. }
  15. if state == 0 {
  16. context = model.WaiteCheck
  17. } else {
  18. context = model.HadCheck
  19. }
  20. s.AddLog2(c, &model.Log{
  21. Name: operater,
  22. RefID: id,
  23. Module: model.UpdateStat,
  24. Context: s.UpdateStateLog(id, context),
  25. Ctime: time.Now(),
  26. })
  27. return
  28. }
  29. // UpdateStatQuantity update stat quantity.
  30. func (s *Service) UpdateStatQuantity(c context.Context, count, id int64, operater string) (err error) {
  31. var (
  32. olds *model.Statistics
  33. )
  34. if olds, err = s.spyDao.Statistics(c, id); err != nil || olds == nil {
  35. return
  36. }
  37. if _, err = s.spyDao.UpdateStatQuantity(c, count, id); err != nil {
  38. return
  39. }
  40. s.AddLog2(c, &model.Log{
  41. Name: operater,
  42. RefID: id,
  43. Module: model.UpdateStat,
  44. Context: s.UpdateStatCountLog(id, olds.Quantity, count),
  45. Ctime: time.Now(),
  46. })
  47. return
  48. }
  49. // DeleteStat delete stat.
  50. func (s *Service) DeleteStat(c context.Context, isdel int8, id int64, operater string) (err error) {
  51. if _, err = s.spyDao.DeleteStat(c, isdel, id); err != nil {
  52. return
  53. }
  54. s.AddLog2(c, &model.Log{
  55. Name: operater,
  56. RefID: id,
  57. Module: model.UpdateStat,
  58. Context: s.DeleteStatLog(id),
  59. Ctime: time.Now(),
  60. })
  61. return
  62. }
  63. // StatPage get stat list.
  64. func (s *Service) StatPage(c context.Context, mid, id int64, t int8, pn, ps int) (page *model.StatPage, err error) {
  65. var (
  66. list []*model.Statistics
  67. count int64
  68. )
  69. page = &model.StatPage{Ps: ps, Pn: pn}
  70. if t == model.AccountType {
  71. count, err = s.spyDao.StatCountByMid(c, mid)
  72. if err != nil || count == 0 {
  73. return
  74. }
  75. list, err = s.spyDao.StatListByMid(c, mid, pn, ps)
  76. } else {
  77. count, err = s.spyDao.StatCountByID(c, id, t)
  78. if err != nil || count == 0 {
  79. return
  80. }
  81. list, err = s.spyDao.StatListByID(c, id, t, pn, ps)
  82. }
  83. for _, st := range list {
  84. st.EventName = s.allEventName[st.EventID]
  85. }
  86. page.Items = list
  87. page.TotalCount = count
  88. return
  89. }