add_mkt_logic.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.RecommendStu = sql.NullInt64{Int64: 0, Valid: true}
  39. mkt.StuLoadSchool = sql.NullInt64{Int64: in.LoadSchId, Valid: true}
  40. mkt.StuAddress = sql.NullString{String: in.Address, Valid: true}
  41. mkt.AgeGroup = sql.NullInt64{Int64: in.AgeGroup, Valid: true}
  42. mkt.StuType = 8
  43. mkt.NetworkDetail = sql.NullInt64{Int64: in.NetworkDetailId, Valid: true}
  44. mkt.CallType = sql.NullInt64{Int64: in.CallType, Valid: true}
  45. mkt.MaType = sql.NullInt64{Int64: in.MaType, Valid: true}
  46. mkt.QuaoYji = sql.NullInt64{Int64: in.QuaoYji, Valid: true}
  47. mkt.LoadUser = sql.NullString{String: in.MkId, Valid: true}
  48. mkt.StuFollowUpMonthly = sql.NullInt64{Int64: 1309, Valid: true}
  49. mkt.PtuserId = sql.NullInt64{Int64: in.PartTimeUserId, Valid: true}
  50. mkt.StuEnName = sql.NullString{String: "", Valid: true}
  51. ret, err := l.svcCtx.MktResourceModel.Insert(mkt)
  52. if err != nil {
  53. l.Logger.Error(err)
  54. return &transform.MktRes{Status: 500}, nil
  55. }
  56. if in.ActiveId != 0 {
  57. id, _ := ret.LastInsertId()
  58. act := model.MktStudentMarketActivity{}
  59. act.DelFlag = sql.NullInt64{Int64: 0, Valid: true}
  60. act.CreateBy = sql.NullString{String: in.MkId, Valid: true}
  61. act.CreateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
  62. act.LastUpdateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
  63. act.LastUpdateBy = sql.NullString{String: in.MkId, Valid: true}
  64. act.SutId = sql.NullInt64{Int64: id, Valid: true}
  65. act.MaId = sql.NullInt64{Int64: in.ActiveId, Valid: true}
  66. _, err = l.svcCtx.MktStudentMarketActivityModel.Insert(act)
  67. }
  68. if err != nil {
  69. l.Logger.Error(err)
  70. return &transform.MktRes{Status: 500}, nil
  71. }
  72. return &transform.MktRes{Status: 200}, nil
  73. }
  74. if old.Id != 0 {
  75. // 已经存在不处理
  76. return &transform.MktRes{Status: 201}, nil
  77. }
  78. return &transform.MktRes{Status: 500}, nil
  79. }