package service import ( "kpt.notice/apiserver/model" "kpt.notice/pkg/log" ) func (svc *Service) InsertUser(phone, openid string) (err error) { sql := `insert user (openid,phone) values(?,?) ON DUPLICATE KEY UPDATE phone=? ` return svc.DB.Exec(sql, openid, phone, phone).Error } func (svc *Service) QueryOpenid(phones []string) (users []model.User, err error) { err = svc.DB.Where("phone in ?", phones).Find(&users).Error return } func (svc *Service) InsertSysUser(openid, user, sysname, pastureid string) (err error) { sql := ` REPLACE INTO sys_user (open_id,user,sys_name,pasture_id) VALUES(?,?,?,?) ` return svc.DB.Exec(sql, openid, user, sysname, pastureid).Error } func (svc *Service) GetSysUser(user []string, sysname string, pastureid int) ([]*model.SysUser, error) { dataList := make([]*model.SysUser, 0) rows := svc.DB.Table("sys_user").Select("open_id") rows.Where(" sys_name = ?", sysname) rows.Where(" pasture_id = ? ", pastureid) err := rows.Where("user in (?) ", user).Find(&dataList).Error if err != nil { log.Errorf("GetSysUser-err:%v", err) return nil, err } return dataList, nil }