chatLog.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package forms
  2. import (
  3. "errors"
  4. "github.com/jinzhu/now"
  5. "strings"
  6. "time"
  7. )
  8. type ChatLogPlayerListReq struct {
  9. ListReq
  10. Time []int64 `json:"time" form:"time[]"`
  11. AccId int64 `json:"accId" form:"accId"`
  12. Name string `json:"name" form:"playerName"`
  13. Text string `json:"text" form:"text"`
  14. OpenId string `json:"openId" form:"openId"`
  15. }
  16. func (req *ChatLogPlayerListReq) Check() error {
  17. if req.Time != nil && len(req.Time) != 2 {
  18. return errors.New("生成时间必须选择一个区间或者留空")
  19. }
  20. if len(req.Time) == 2 {
  21. if req.Time[0] > req.Time[1] {
  22. return errors.New("生成时间选择的区间值不合理")
  23. }
  24. // 默认是毫秒
  25. req.Time[0] = req.Time[0] / 1000
  26. req.Time[1] = req.Time[1] / 1000
  27. }
  28. //如果为空 默认今天
  29. if len(req.Time) == 0 {
  30. req.Time = append(req.Time, now.With(time.Now()).BeginningOfDay().Unix(), now.With(time.Now()).EndOfDay().Unix())
  31. }
  32. if req.OpenId != "" {
  33. if !strings.Contains(req.OpenId, "@") {
  34. req.OpenId = strings.Join([]string{req.OpenId, "@wx"}, "")
  35. }
  36. }
  37. return nil
  38. }
  39. type ChatLogInfoReq struct {
  40. ListReq
  41. OpenId string `json:"openId" form:"openId"`
  42. Time []int64 `json:"time" form:"time[]"`
  43. }
  44. func (req *ChatLogInfoReq) Check() error {
  45. if req.OpenId == "" {
  46. return errors.New("参数为空")
  47. }
  48. if req.Time != nil && len(req.Time) != 2 {
  49. return errors.New("生成时间必须选择一个区间或者留空")
  50. }
  51. if len(req.Time) == 2 {
  52. if req.Time[0] > req.Time[1] {
  53. return errors.New("生成时间选择的区间值不合理")
  54. }
  55. // 默认是毫秒
  56. req.Time[0] = req.Time[0] / 1000
  57. req.Time[1] = req.Time[1] / 1000
  58. }
  59. //如果为空 默认今天
  60. if len(req.Time) == 0 {
  61. req.Time = append(req.Time, now.With(time.Now()).BeginningOfDay().Unix(), now.With(time.Now()).EndOfDay().Unix())
  62. }
  63. return nil
  64. }