acquirer_student_page_logic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package acquirer_student
  2. import (
  3. "context"
  4. "fmt"
  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/i2-bill-api/internal/utils"
  8. "git.i2edu.net/i2/i2-bill-erp/transform"
  9. "net/http"
  10. "strconv"
  11. "time"
  12. "git.i2edu.net/i2/go-zero/core/logx"
  13. )
  14. type AcquirerStudentPageLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewAcquirerStudentPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentPageLogic {
  20. return AcquirerStudentPageLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *AcquirerStudentPageLogic) AcquirerStudentPage(r *http.Request) (*types.Response, error) {
  27. // todo: add your logic here and delete this line
  28. r.ParseForm()
  29. create_time_sta := r.Form.Get("create_time_sta")
  30. create_time_end := r.Form.Get("create_time_end")
  31. page, _ := strconv.Atoi(r.Form.Get("page"))
  32. rows, _ := strconv.Atoi(r.Form.Get("rows"))
  33. check_state := r.Form.Get("check_state")
  34. sort := r.Form.Get("__sort__")
  35. userId := fmt.Sprintf("%d", l.svcCtx.GetUserIdByJwt(l.ctx))
  36. if create_time_end != "" {
  37. end, err := time.Parse("2006-01-02", create_time_end)
  38. if err != nil {
  39. return &types.Response{500, err.Error(), nil}, nil
  40. }
  41. create_time_end = end.Add(time.Second*24*60*60 - 1*time.Second).Format("2006-01-02 15:04:05")
  42. }
  43. if sort == "" {
  44. sort = "id desc"
  45. }
  46. paramMap_i_t := map[string]interface{}{
  47. "page": page,
  48. "rows": rows,
  49. "create_time_sta": create_time_sta,
  50. "create_time_end": create_time_end,
  51. "user_id": userId,
  52. "check_state": check_state,
  53. "__sort__": sort,
  54. }
  55. res, err := utils.PageSearch(l.svcCtx.DB, "i2bill_acquirer_student", "page", "i2bill_acquirer_student", paramMap_i_t)
  56. if err != nil {
  57. logx.Error(err.Error())
  58. return &types.Response{500, err.Error(), nil}, nil
  59. }
  60. erpRes, err := l.svcCtx.Transformer.GetErpSchool(l.ctx, &transform.Empty{})
  61. if err != nil {
  62. logx.Error(err.Error())
  63. return &types.Response{500, err.Error(), res}, nil
  64. }
  65. if res.Content != nil {
  66. for index, r := range res.Content {
  67. for _, sch := range erpRes.School {
  68. if sch.Id == r["sch_id"].(int64) {
  69. r["sch_name"] = sch.Name
  70. res.Content[index] = r
  71. break
  72. }
  73. }
  74. phone := r["stu_phone"].(string)
  75. if len(phone) >= 11 {
  76. r["stu_phone"] = utils.ReplaceSub(phone, "*", 3, 4)
  77. } else if len(phone) > 5 {
  78. r["stu_phone"] = utils.ReplaceSub(phone, "*", 2, 2)
  79. }
  80. }
  81. }
  82. return &types.Response{200, "", res}, nil
  83. }