package logic import ( "context" "fmt" "git.i2edu.net/i2/i2-bill-api/internal/svc" "git.i2edu.net/i2/i2-bill-api/internal/types" "git.i2edu.net/i2/i2-bill-api/model" "time" "git.i2edu.net/i2/go-zero/core/logx" ) type AcquirerStudentAddLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewAcquirerStudentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentAddLogic { return AcquirerStudentAddLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *AcquirerStudentAddLogic) AcquirerStudentAdd(req types.EnrollAddReq) (*types.Response, error) { // todo: add your logic here and delete this line //去重 stu, err := l.svcCtx.DB.SQL("select * from i2bill_acquirer_student where stu_phone = ? and DATE_FORMAT(create_time,'%Y-%m-%d') = ? ", req.StuPhone, time.Now().Format("2006-01-02")).Query().List() if err != nil { return &types.Response{500, err.Error(), nil}, nil } if len(stu) > 0 { return &types.Response{500, "你今天已提交过信息,感谢你的填写", nil}, nil } bean := new(model.I2billAcquirerStudent) bean.AgeGroup = int64(req.AgeGroup) bean.StuPhone.String = req.StuPhone bean.Address.String = req.Address bean.UserId.Int64 = int64(req.UserId) partUserSql := fmt.Sprintf("select * from %s where user_id = ? and del_flag = 0 and check_state = ?", "i2bill_mkt_part_time_user") res, err := l.svcCtx.DB.SQL(partUserSql, req.UserId, 57).Query().List() if err != nil { return &types.Response{500, err.Error(), nil}, nil } if len(res) < 1 { return &types.Response{500, "无效二维码", nil}, nil } bean.MkId.String = res[0]["mk_id"].(string) bean.NetworkDetailId.Int64 = int64(req.NetworkId) bean.ActiveId.Int64 = int64(req.ActiveId) bean.DelFlag = 0 bean.CheckState.Int64 = 54 bean.StuName.String = req.Name bean.StuLinkPerson.String = req.StuLinkPerson bean.SchId.Int64 = int64(req.SchId) bean.CreateTime.Time = time.Now() sql := `INSERT INTO i2bill_acquirer_student (stu_link_person,stu_phone,create_time,mk_id,user_id,address, check_state,stu_name,age_group,sch_id,del_flag,network_detail_id,active_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)` var args []interface{} args = append(args, sql, bean.StuLinkPerson.String, bean.StuPhone.String, bean.CreateTime.Time, bean.MkId.String, bean.UserId.Int64, bean.Address.String, bean.CheckState.Int64, bean.StuName.String, bean.AgeGroup, bean.SchId.Int64, bean.DelFlag) if req.NetworkId != 0 { args = append(args, req.NetworkId) } else { args = append(args, 1058) } if req.ActiveId != 0 { args = append(args, req.ActiveId) } else { args = append(args, nil) } _, err = l.svcCtx.DB.Exec(args...) if err != nil { return &types.Response{500, err.Error(), nil}, nil } return &types.Response{200, "", nil}, nil }