acquirer_student_total_logic.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package logic
  2. import (
  3. "context"
  4. "time"
  5. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-api/internal/types"
  7. "git.i2edu.net/i2/go-zero/core/logx"
  8. )
  9. type AcquirerStudentTotalLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewAcquirerStudentTotalLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentTotalLogic {
  15. return AcquirerStudentTotalLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *AcquirerStudentTotalLogic) AcquirerStudentTotal() (*types.Response, error) {
  22. // todo: add your logic here and delete this line
  23. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  24. sqlTotalByCheck := `
  25. SELECT
  26. count(*) total ,check_state
  27. FROM
  28. i2bill_mkt_part_time_user
  29. WHERE
  30. del_flag = 0
  31. and user_id = ?
  32. GROUP BY check_state`
  33. sqlTotalByToDay := `
  34. SELECT
  35. count(*) total
  36. FROM
  37. i2bill_mkt_part_time_user
  38. WHERE
  39. del_flag = 0
  40. and user_id = ?
  41. and create_time between ? and ?`
  42. totalByCheck, err := l.svcCtx.DB.NewSession().SQL(sqlTotalByCheck, userId).Query().List()
  43. if err != nil {
  44. return &types.Response{500, err.Error(), nil}, nil
  45. }
  46. timeNow := time.Now()
  47. start := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
  48. end := start.Add(24*60*60*time.Second - 1*time.Second)
  49. totalDay, err := l.svcCtx.DB.NewSession().SQL(sqlTotalByToDay, userId, start, end).Query().List()
  50. if err != nil {
  51. return &types.Response{500, err.Error(), nil}, nil
  52. }
  53. var target int64
  54. l.svcCtx.DB.Table("i2bill_mkt_part_time_user").Select("target").Where("user_id = ? and del_flag = 0", userId).Get(&target)
  55. var res = make(map[string]interface{})
  56. res["check_total"] = totalByCheck
  57. res["today_total"] = totalDay[0]["total"]
  58. res["target"] = target
  59. return &types.Response{200, "", res}, nil
  60. }