123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package logic
- import (
- "context"
- "database/sql"
- "git.i2edu.net/i2/i2-bill-erp/internal/svc"
- "git.i2edu.net/i2/i2-bill-erp/internal/utils"
- "git.i2edu.net/i2/i2-bill-erp/model"
- "git.i2edu.net/i2/i2-bill-erp/transform"
- "git.i2edu.net/i2/go-zero/core/logx"
- "git.i2edu.net/i2/go-zero/core/stores/sqlc"
- )
- type AddMktLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewAddMktLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMktLogic {
- return &AddMktLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *AddMktLogic) AddMkt(in *transform.MktReq) (*transform.MktRes, error) {
- old := model.MktResource{}
- err := l.svcCtx.SqlConn.QueryRowPartial(&old, "select id from mkt_resource where `stu_phone` = ? and del_flag!=1 limit 1", in.StuPhone)
- if err == sqlc.ErrNotFound {
- mkt := model.MktResource{}
- mkt.DelFlag = 0
- mkt.CreateBy = sql.NullString{String: in.MkId, Valid: true}
- mkt.CreateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
- mkt.LastUpdateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
- mkt.LastUpdateBy = sql.NullString{String: in.MkId, Valid: true}
- mkt.StuName = sql.NullString{String: in.StuName, Valid: true}
- mkt.Relation1 = sql.NullInt64{Int64: in.StuLinkPerson, Valid: true}
- mkt.StuPhone = sql.NullString{String: in.StuPhone, Valid: true}
- mkt.RecommendStu = sql.NullInt64{Int64: 0, Valid: true}
- mkt.StuLoadSchool = sql.NullInt64{Int64: in.LoadSchId, Valid: true}
- mkt.StuAddress = sql.NullString{String: in.Address, Valid: true}
- mkt.AgeGroup = sql.NullInt64{Int64: in.AgeGroup, Valid: true}
- mkt.NetworkDetail = sql.NullInt64{Int64: in.NetworkDetailId, Valid: true}
- mkt.StuSex = sql.NullInt64{Int64: in.Gender, Valid: true}
- if in.NetworkDetailId == 1752 {
- mkt.StuType = 9
- mkt.PtuserId = sql.NullInt64{Int64: 0, Valid: true}
- } else {
- mkt.PtuserId = sql.NullInt64{Int64: in.PartTimeUserId, Valid: true}
- mkt.StuType = 8
- }
- mkt.CallType = sql.NullInt64{Int64: in.CallType, Valid: true}
- mkt.MaType = sql.NullInt64{Int64: in.MaType, Valid: true}
- mkt.QuaoYji = sql.NullInt64{Int64: in.QuaoYji, Valid: true}
- mkt.LoadUser = sql.NullString{String: in.MkId, Valid: true}
- mkt.StuFollowUpMonthly = sql.NullInt64{Int64: 1309, Valid: true}
- mkt.StuEnName = sql.NullString{String: "", Valid: true}
- mkt.Remark = sql.NullString{String: in.Remark, Valid: true}
- mkt.StuRemark = sql.NullString{String: in.Remark, Valid: true}
- ret, err := l.svcCtx.MktResourceModel.Insert(mkt)
- if err != nil {
- l.Logger.Error(err)
- return &transform.MktRes{Status: 500}, nil
- }
- if in.ActiveId != 0 {
- id, _ := ret.LastInsertId()
- act := model.MktStudentMarketActivity{}
- act.DelFlag = sql.NullInt64{Int64: 0, Valid: true}
- act.CreateBy = sql.NullString{String: in.MkId, Valid: true}
- act.CreateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
- act.LastUpdateTime = sql.NullTime{Time: utils.ParseTime(in.CreateTime), Valid: true}
- act.LastUpdateBy = sql.NullString{String: in.MkId, Valid: true}
- act.SutId = sql.NullInt64{Int64: id, Valid: true}
- act.MaId = sql.NullInt64{Int64: in.ActiveId, Valid: true}
- _, err = l.svcCtx.MktStudentMarketActivityModel.Insert(act)
- }
- if err != nil {
- l.Logger.Error(err)
- return &transform.MktRes{Status: 500}, nil
- }
- return &transform.MktRes{Status: 200}, nil
- }
- if old.Id != 0 {
- // 已经存在不处理
- return &transform.MktRes{Status: 201}, nil
- }
- return &transform.MktRes{Status: 500}, nil
- }
|