user.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package service
  2. import (
  3. "kpt.notice/apiserver/model"
  4. "kpt.notice/pkg/log"
  5. )
  6. func (svc *Service) InsertUser(phone, openid string) (err error) {
  7. sql := `insert user (openid,phone) values(?,?) ON DUPLICATE KEY UPDATE phone=? `
  8. return svc.DB.Exec(sql, openid, phone, phone).Error
  9. }
  10. func (svc *Service) QueryOpenid(phones []string) (users []model.User, err error) {
  11. err = svc.DB.Where("phone in ?", phones).Find(&users).Error
  12. return
  13. }
  14. func (svc *Service) InsertSysUser(openid, user, sysname, pastureid string) (err error) {
  15. sql := ` REPLACE INTO sys_user (open_id,user,sys_name,pasture_id) VALUES(?,?,?,?) `
  16. return svc.DB.Exec(sql, openid, user, sysname, pastureid).Error
  17. }
  18. func (svc *Service) GetSysUser(user []string, sysname string, pastureid int) ([]*model.SysUser, error) {
  19. dataList := make([]*model.SysUser, 0)
  20. rows := svc.DB.Table("sys_user").Select("open_id")
  21. rows.Where(" sys_name = ?", sysname)
  22. rows.Where(" pasture_id = ? ", pastureid)
  23. err := rows.Where("user in (?) ", user).Find(&dataList).Error
  24. if err != nil {
  25. log.Errorf("GetSysUser-err:%v", err)
  26. return nil, err
  27. }
  28. return dataList, nil
  29. }