acquirer_student_add_logic.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  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/model"
  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. //去重
  26. 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()
  27. if err != nil {
  28. return &types.Response{500, err.Error(), nil}, nil
  29. }
  30. if len(stu) > 0 {
  31. return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil
  32. }
  33. bean := new(model.I2billAcquirerStudent)
  34. bean.AgeGroup = int64(req.AgeGroup)
  35. bean.StuPhone.String = req.StuPhone
  36. bean.Address.String = req.Address
  37. bean.UserId.Int64 = int64(req.UserId)
  38. partUserSql := fmt.Sprintf("select * from %s where user_id = ? and del_flag = 0 and check_state = ?", "i2bill_mkt_part_time_user")
  39. res, err := l.svcCtx.DB.SQL(partUserSql, req.UserId, 57).Query().List()
  40. if err != nil {
  41. return &types.Response{500, err.Error(), nil}, nil
  42. }
  43. if len(res) < 1 {
  44. return &types.Response{500, "无效二维码", nil}, nil
  45. }
  46. bean.MkId.String = res[0]["mk_id"].(string)
  47. bean.NetworkDetailId.Int64 = int64(req.NetworkId)
  48. bean.ActiveId.Int64 = int64(req.ActiveId)
  49. bean.DelFlag = 0
  50. bean.CheckState.Int64 = 54
  51. bean.StuName.String = req.Name
  52. bean.StuLinkPerson.String = req.StuLinkPerson
  53. bean.SchId.Int64 = int64(req.SchId)
  54. bean.CreateTime.Time = time.Now()
  55. sql := `INSERT INTO i2bill_acquirer_student (stu_link_person,stu_phone,create_time,mk_id,user_id,address,
  56. check_state,stu_name,age_group,sch_id,del_flag,network_detail_id,active_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`
  57. var args []interface{}
  58. args = append(args, sql,
  59. bean.StuLinkPerson.String, bean.StuPhone.String,
  60. bean.CreateTime.Time, bean.MkId.String, bean.UserId.Int64,
  61. bean.Address.String, bean.CheckState.Int64, bean.StuName.String,
  62. bean.AgeGroup, bean.SchId.Int64, bean.DelFlag)
  63. if req.NetworkId != 0 {
  64. args = append(args, req.NetworkId)
  65. } else {
  66. args = append(args, 1058)
  67. }
  68. if req.ActiveId != 0 {
  69. args = append(args, req.ActiveId)
  70. } else {
  71. args = append(args, nil)
  72. }
  73. _, err = l.svcCtx.DB.Exec(args...)
  74. if err != nil {
  75. return &types.Response{500, err.Error(), nil}, nil
  76. }
  77. return &types.Response{200, "", nil}, nil
  78. }