acquirer_student_add_logic.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. erpId, 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 erpId == "" {
  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. //获取渠道收单信息
  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 {
  71. return &types.Response{500, "二维码已失效", nil}, nil
  72. }
  73. bean.MkId = erpId
  74. bean.NetworkDetailId = acquirerInfo.QudaoId
  75. bean.ActiveId = acquirerInfo.ActivityId
  76. bean.DelFlag = 0
  77. bean.CheckState = 54
  78. bean.StuName = req.StuName
  79. bean.StuLinkPerson = req.StuLinkPerson
  80. bean.SchId = int64(req.SchId)
  81. bean.CreateTime = time.Now()
  82. _, err = l.svcCtx.DB.Insert(bean)
  83. if err != nil {
  84. logx.Error(err.Error())
  85. return &types.Response{500, err.Error(), nil}, nil
  86. }
  87. return &types.Response{200, "", nil}, nil
  88. }