| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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.SchId = sql.NullInt64{Int64: in.SchId, 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.StuType = 8
- mkt.NetworkDetail = sql.NullInt64{Int64: in.NetworkDetailId, Valid: true}
- 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.PtuserId = sql.NullInt64{Int64: in.PartTimeUserId, Valid: true}
- mkt.StuEnName = sql.NullString{String: "", 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
- }
|