add_mkt_logic.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package logic
  2. import (
  3. "context"
  4. "database/sql"
  5. "git.i2edu.net/i2/i2-bill-erp/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-erp/internal/utils"
  7. "git.i2edu.net/i2/i2-bill-erp/model"
  8. "git.i2edu.net/i2/i2-bill-erp/transform"
  9. "git.i2edu.net/i2/go-zero/core/logx"
  10. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  11. )
  12. type AddMktLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewAddMktLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMktLogic {
  18. return &AddMktLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *AddMktLogic) AddMkt(in *transform.MktReq) (*transform.MktRes, error) {
  25. old := model.MktResource{}
  26. err := l.svcCtx.SqlConn.QueryRowPartial(&old, "select id from mkt_resource where `stu_phone` = ? and del_flag!=1 limit 1", in.StuPhone)
  27. if err == sqlc.ErrNotFound {
  28. mkt := model.MktResource{}
  29. mkt.DelFlag = 0
  30. mkt.CreateBy = sql.NullString{String: in.MkId, Valid: true}
  31. mkt.CreateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
  32. mkt.LastUpdateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
  33. mkt.LastUpdateBy = sql.NullString{String: in.MkId, Valid: true}
  34. mkt.StuName = sql.NullString{String: in.StuName, Valid: true}
  35. mkt.Relation1 = sql.NullInt64{Int64: in.StuLinkPerson, Valid: true}
  36. mkt.StuPhone = sql.NullString{String: in.StuPhone, Valid: true}
  37. // mkt.SchId = sql.NullInt64{Int64: in.SchId, Valid: true}
  38. mkt.StuLoadSchool = sql.NullInt64{Int64: in.LoadSchId, Valid: true}
  39. mkt.StuAddress = sql.NullString{String: in.Address, Valid: true}
  40. mkt.AgeGroup = sql.NullInt64{Int64: in.AgeGroup, Valid: true}
  41. mkt.StuType = 8
  42. mkt.NetworkDetail = sql.NullInt64{Int64: in.NetworkDetailId, Valid: true}
  43. mkt.CallType = sql.NullInt64{Int64: in.CallType, Valid: true}
  44. mkt.MaType = sql.NullInt64{Int64: in.MaType, Valid: true}
  45. mkt.QuaoYji = sql.NullInt64{Int64: in.QuaoYji, Valid: true}
  46. mkt.LoadUser = sql.NullString{String: in.MkId, Valid: true}
  47. mkt.StuFollowUpMonthly = sql.NullInt64{Int64: 1309, Valid: true}
  48. _, err := l.svcCtx.MktResourceModel.Insert(mkt)
  49. if err != nil {
  50. l.Logger.Error(err)
  51. return &transform.MktRes{Status: 500}, nil
  52. }
  53. return &transform.MktRes{Status: 200}, nil
  54. }
  55. if old.Id != 0 {
  56. // 已经存在不处理
  57. return &transform.MktRes{Status: 201}, nil
  58. }
  59. return &transform.MktRes{Status: 500}, nil
  60. }