enrolllogic.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package acquirer
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "time"
  7. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  8. "git.i2edu.net/i2/i2-bill-api/internal/types"
  9. "git.i2edu.net/i2/i2-bill-api/model"
  10. "git.i2edu.net/i2/go-zero/core/logx"
  11. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  12. )
  13. type EnrollLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. UserId int64
  18. SessionKey string
  19. }
  20. func NewEnrollLogic(ctx context.Context, svcCtx *svc.ServiceContext) EnrollLogic {
  21. return EnrollLogic{
  22. Logger: logx.WithContext(ctx),
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. }
  26. }
  27. func (l *EnrollLogic) Enroll(req types.EnrollRequest) (*types.Response, error) {
  28. var stu model.I2billAcquirerStudent
  29. var qrScence struct {
  30. UserId int64 `json:"userId"`
  31. Timestamp time.Time `json:"timestamp"`
  32. Type string `json:"type"`
  33. }
  34. err := l.svcCtx.Wechat.GetQrParams(svc.QrcodeJzPrefix, req.Scene, &qrScence)
  35. if err != nil {
  36. return &types.Response{Code: 500, Msg: err.Error(), Data: nil}, nil
  37. }
  38. err = l.svcCtx.SqlConn.QueryRowPartial(&stu, fmt.Sprintf("select %s from i2bill_acquirer_student where `user_id`=? and `stu_phone`=? limit 1", model.I2billAcquirerStudentRows), qrScence.UserId, req.IponeNumber)
  39. if err != sqlc.ErrNotFound && err != nil {
  40. return &types.Response{Code: 500, Msg: err.Error(), Data: nil}, nil
  41. } else if stu.Id > 0 {
  42. return &types.Response{Code: 500, Msg: "已录入成功, 请勿重复操作", Data: nil}, nil
  43. } else {
  44. stu.UserId = sql.NullInt64{Int64: qrScence.UserId, Valid: true}
  45. stu.StuPhone = sql.NullString{String: req.IponeNumber, Valid: true}
  46. }
  47. return &types.Response{}, nil
  48. }