acquirer_student_add_logic.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package acquirer_student
  2. import (
  3. "context"
  4. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  5. "git.i2edu.net/i2/i2-bill-api/internal/types"
  6. "git.i2edu.net/i2/i2-bill-api/model"
  7. "strconv"
  8. "time"
  9. "git.i2edu.net/i2/go-zero/core/logx"
  10. )
  11. type AcquirerStudentAddLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewAcquirerStudentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentAddLogic {
  17. return AcquirerStudentAddLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *AcquirerStudentAddLogic) AcquirerStudentAdd(req types.EnrollAddReq) (*types.Response, error) {
  24. // todo: add your logic here and delete this line
  25. sign := req.Sign
  26. if sign == "" {
  27. return &types.Response{500, "二维码已失效", nil}, nil
  28. }
  29. userId, err := strconv.ParseInt(sign, 10, 64)
  30. if err != nil {
  31. logx.Error(err.Error())
  32. return &types.Response{500, err.Error(), nil}, nil
  33. }
  34. //是否有权限收单
  35. erpUser, err := model.GetAcquirePermInfo(userId, l.svcCtx.Transformer, l.svcCtx.DB, l.ctx)
  36. if err != nil {
  37. logx.Error(err.Error())
  38. return &types.Response{500, "二维码已失效", nil}, nil
  39. }
  40. if erpUser == nil || erpUser.UserId == "" {
  41. return &types.Response{500, "二维码已失效", nil}, nil
  42. }
  43. //去重
  44. stu, err := l.svcCtx.DB.SQL("select * from i2bill_acquirer_student where stu_phone = ? and DATE_FORMAT(create_time,'%Y-%m-%d') = ? ", req.StuPhone, time.Now().Format("2006-01-02")).Query().List()
  45. if err != nil {
  46. logx.Error(err.Error())
  47. return &types.Response{500, err.Error(), nil}, nil
  48. }
  49. if len(stu) > 0 {
  50. return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil
  51. }
  52. bean := new(model.I2billAcquirerStudentXorm)
  53. bean.AgeGroup = int64(req.AgeGroup)
  54. bean.StuPhone = req.StuPhone
  55. bean.Address = req.Address
  56. bean.UserId = userId
  57. //加入part信息
  58. partUser, err := model.GetPartTimeXormByUserId(userId, l.svcCtx.DB)
  59. if err != nil {
  60. logx.Error(err.Error())
  61. return &types.Response{500, err.Error(), nil}, nil
  62. }
  63. bean.PartTimeUserId = partUser.Id
  64. //获取渠道收单信息
  65. acquirerInfo, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
  66. if err != nil {
  67. logx.Error(err.Error())
  68. return &types.Response{500, err.Error(), nil}, nil
  69. }
  70. if acquirerInfo.Id == 0 || acquirerInfo.Role != erpUser.Role {
  71. return &types.Response{500, "二维码已失效", nil}, nil
  72. }
  73. bean.LoadSchId = acquirerInfo.SchoolId
  74. bean.MkId = erpUser.UserId
  75. bean.NetworkDetailId = acquirerInfo.NetworkDetailId
  76. bean.QuaoYji = acquirerInfo.QuaoYji
  77. bean.MaType = acquirerInfo.MaType
  78. bean.CallType = acquirerInfo.CallType
  79. bean.ActiveId = acquirerInfo.ActivityId
  80. bean.DelFlag = 0
  81. bean.CheckState = 54
  82. bean.StuName = req.StuName
  83. bean.StuLinkPerson = req.StuLinkPerson
  84. bean.SchId = int64(req.SchId)
  85. bean.CreateTime = time.Now()
  86. _, err = l.svcCtx.DB.Insert(bean)
  87. if err != nil {
  88. logx.Error(err.Error())
  89. return &types.Response{500, err.Error(), nil}, nil
  90. }
  91. return &types.Response{200, "", nil}, nil
  92. }