acquirer_student_total_logic.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package acquirer_student
  2. import (
  3. "context"
  4. "git.i2edu.net/i2/i2-bill-erp/utils"
  5. "net/http"
  6. "time"
  7. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  8. "git.i2edu.net/i2/i2-bill-api/internal/types"
  9. "git.i2edu.net/i2/go-zero/core/logx"
  10. )
  11. type AcquirerStudentTotalLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewAcquirerStudentTotalLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentTotalLogic {
  17. return AcquirerStudentTotalLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *AcquirerStudentTotalLogic) AcquirerStudentTotal(r *http.Request) (*types.Response, error) {
  24. // todo: add your logic here and delete this line
  25. r.ParseForm()
  26. totalSta := r.Form.Get("create_time_sta")
  27. totalEnd := r.Form.Get("create_time_end")
  28. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  29. if totalEnd != "" {
  30. end, err := time.Parse("2006-01-02", totalEnd)
  31. if err != nil {
  32. return &types.Response{500, err.Error(), nil}, nil
  33. }
  34. totalEnd = end.Add(time.Second*24*60*60 - 1*time.Second).Format("2006-01-02 15:04:05")
  35. }
  36. totalParams := make(map[string]interface{})
  37. totalParams["create_time_sta"] = totalSta
  38. totalParams["create_time_end"] = totalEnd
  39. totalParams["user_id"] = userId
  40. totalParams["group_by"] = "check_state"
  41. timeNow := time.Now()
  42. start := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
  43. end := start.Add(24*60*60*time.Second - 1*time.Second)
  44. todayParams := make(map[string]interface{})
  45. todayParams["create_time_sta"] = start
  46. todayParams["create_time_end"] = end
  47. todayParams["user_id"] = userId
  48. totalByCheck, err := utils.AllSearch(l.svcCtx.DB, "i2bill_acquirer_student", "total_check", "i2bill_acquirer_student", totalParams)
  49. if err != nil {
  50. logx.Error(err.Error())
  51. return &types.Response{500, err.Error(), nil}, nil
  52. }
  53. totalDay, err := utils.AllSearch(l.svcCtx.DB, "i2bill_acquirer_student", "total_check", "i2bill_acquirer_student", todayParams)
  54. if err != nil {
  55. logx.Error(err.Error())
  56. return &types.Response{500, err.Error(), nil}, nil
  57. }
  58. var target int64
  59. l.svcCtx.DB.Table("i2bill_mkt_part_time_user").Select("target").Where("user_id = ? and del_flag = 0", userId).Get(&target)
  60. var res = make(map[string]interface{})
  61. var invalide, untreated, valide, repeat int64
  62. for _, t := range totalByCheck {
  63. switch t["check_state"].(int64) {
  64. case 54, 56, 59:
  65. untreated += t["total"].(int64)
  66. case 57:
  67. valide += t["total"].(int64)
  68. case 58:
  69. invalide += t["total"].(int64)
  70. case 55:
  71. repeat += t["total"].(int64)
  72. default:
  73. untreated += t["total"].(int64)
  74. }
  75. }
  76. res["invalide"] = invalide
  77. res["untreated"] = untreated
  78. res["valide"] = valide
  79. res["today_total"] = totalDay[0]["total"]
  80. res["target"] = target
  81. res["repeat"] = repeat
  82. return &types.Response{200, "", res}, nil
  83. }