acquirer_student_add_logic.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package logic
  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. //解析id
  26. //sign, err := hex.DecodeString(req.Sign)
  27. sign := req.Sign
  28. if sign == "" {
  29. return &types.Response{500, "二维码已失效", nil}, nil
  30. }
  31. //userIdByte, err := utils.AesDecrypt(sign, []byte(l.svcCtx.Config.AesSecret))
  32. //if err != nil {
  33. // logx.Error(err.Error())
  34. // return &types.Response{500, "二维码已失效", nil}, nil
  35. //}
  36. userId, err := strconv.ParseInt(sign, 10, 64)
  37. if err != nil {
  38. logx.Error(err.Error())
  39. return &types.Response{500, err.Error(), nil}, nil
  40. }
  41. //是否有权限收单
  42. erpUser, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
  43. if err != nil {
  44. logx.Error(err.Error())
  45. return &types.Response{500, err.Error(), nil}, nil
  46. }
  47. if erpUser == nil || erpUser.UserId == "" {
  48. return &types.Response{500, "二维码已失效", nil}, nil
  49. }
  50. //去重
  51. 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()
  52. if err != nil {
  53. logx.Error(err.Error())
  54. return &types.Response{500, err.Error(), nil}, nil
  55. }
  56. if len(stu) > 0 {
  57. return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil
  58. }
  59. bean := new(model.I2billAcquirerStudentXorm)
  60. bean.AgeGroup = int64(req.AgeGroup)
  61. bean.StuPhone = req.StuPhone
  62. bean.Address = req.Address
  63. bean.UserId = userId
  64. bean.LoadSchId = erpUser.SchId
  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 {
  72. return &types.Response{500, "二维码已失效", nil}, nil
  73. }
  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. }