acquirer_student_add_logic.go 3.2 KB

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