add_mkt_logic.go 3.5 KB

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