acquirer_student_add_logic.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.Remark = req.Remark
  57. bean.UserId = userId
  58. //加入part信息
  59. partUser, err := model.GetPartTimeXormByUserId(userId, l.svcCtx.DB)
  60. if err != nil {
  61. logx.Error(err.Error())
  62. return &types.Response{500, err.Error(), nil}, nil
  63. }
  64. bean.PartTimeUserId = partUser.Id
  65. //获取渠道收单信息
  66. acquirerInfo, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
  67. if err != nil {
  68. logx.Error(err.Error())
  69. return &types.Response{500, err.Error(), nil}, nil
  70. }
  71. if acquirerInfo.Id == 0 || acquirerInfo.Role != erpUser.Role {
  72. return &types.Response{500, "二维码已失效", nil}, nil
  73. }
  74. bean.LoadSchId = acquirerInfo.SchoolId
  75. bean.MkId = erpUser.UserId
  76. bean.NetworkDetailId = acquirerInfo.NetworkDetailId
  77. bean.QuaoYji = acquirerInfo.QuaoYji
  78. bean.MaType = acquirerInfo.MaType
  79. bean.CallType = acquirerInfo.CallType
  80. bean.ActiveId = acquirerInfo.ActivityId
  81. bean.DelFlag = 0
  82. bean.CheckState = 54
  83. bean.StuName = req.StuName
  84. bean.StuLinkPerson = req.StuLinkPerson
  85. bean.SchId = int64(req.SchId)
  86. bean.CreateTime = time.Now()
  87. _, err = l.svcCtx.DB.Insert(bean)
  88. if err != nil {
  89. logx.Error(err.Error())
  90. return &types.Response{500, err.Error(), nil}, nil
  91. }
  92. return &types.Response{200, "", nil}, nil
  93. }