acquirer_student_add_logic.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package logic
  2. import (
  3. "context"
  4. "encoding/base64"
  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-api/model"
  9. "strconv"
  10. "time"
  11. "git.i2edu.net/i2/go-zero/core/logx"
  12. )
  13. type AcquirerStudentAddLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewAcquirerStudentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentAddLogic {
  19. return AcquirerStudentAddLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *AcquirerStudentAddLogic) AcquirerStudentAdd(req types.EnrollAddReq) (*types.Response, error) {
  26. // todo: add your logic here and delete this line
  27. //解析id
  28. sign, err := base64.StdEncoding.DecodeString(req.Sign)
  29. if err != nil {
  30. logx.Error(err.Error())
  31. return &types.Response{500, "二维码已失效", nil}, nil
  32. }
  33. userIdByte, err := utils.AesDecrypt(sign, []byte(l.svcCtx.Config.AesSecret))
  34. if err != nil {
  35. logx.Error(err.Error())
  36. return &types.Response{500, "二维码已失效", nil}, nil
  37. }
  38. userId, err := strconv.ParseInt(string(userIdByte), 10, 64)
  39. if err != nil {
  40. logx.Error(err.Error())
  41. return &types.Response{500, err.Error(), nil}, nil
  42. }
  43. //是否有权限收单
  44. erpId, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
  45. if err != nil {
  46. logx.Error(err.Error())
  47. return &types.Response{500, err.Error(), nil}, nil
  48. }
  49. if erpId == "" {
  50. return &types.Response{500, "二维码已失效", nil}, nil
  51. }
  52. //去重
  53. 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()
  54. if err != nil {
  55. logx.Error(err.Error())
  56. return &types.Response{500, err.Error(), nil}, nil
  57. }
  58. if len(stu) > 0 {
  59. return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil
  60. }
  61. bean := new(model.I2billAcquirerStudentXorm)
  62. bean.AgeGroup = int64(req.AgeGroup)
  63. bean.StuPhone = req.StuPhone
  64. bean.Address = req.Address
  65. bean.UserId = userId
  66. //获取渠道收单信息
  67. acquirerInfo, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
  68. if err != nil {
  69. logx.Error(err.Error())
  70. return &types.Response{500, err.Error(), nil}, nil
  71. }
  72. if acquirerInfo.Id == 0 {
  73. return &types.Response{500, "二维码已失效", nil}, nil
  74. }
  75. bean.MkId = erpId
  76. bean.NetworkDetailId = acquirerInfo.QudaoId
  77. bean.ActiveId = acquirerInfo.ActivityId
  78. bean.DelFlag = 0
  79. bean.CheckState = 54
  80. bean.StuName = req.StuName
  81. bean.StuLinkPerson = req.StuLinkPerson
  82. bean.SchId = int64(req.SchId)
  83. bean.CreateTime = time.Now()
  84. _, err = l.svcCtx.DB.Insert(bean)
  85. if err != nil {
  86. logx.Error(err.Error())
  87. return &types.Response{500, err.Error(), nil}, nil
  88. }
  89. return &types.Response{200, "", nil}, nil
  90. }