package staff_service import ( "SCRM/models" "SCRM/service" "time" ) func AddStaffInfo(info models.SgjUserStaffInfo) error { err := service.UserWriteDB().Create(&info).Error return err } func GetAllStaffInfo(orgID int64, page int64, limit int64, keyword string) (userStaffInfo []*models.SgjUserStaffInfo, total int64, err error) { db := service.UserReadDB().Table("sgj_user_staff_info as s").Where("s.status = 1") if orgID > 0 { db = db.Where("s.user_org_id = ?", orgID) } if len(keyword) > 0 { keyword = "%" + keyword + "%" db = db.Where("s.name LIKE ?", keyword) } offset := (page - 1) * limit err = db.Count(&total).Order("s.ctime desc").Offset(offset).Limit(limit). Select("s.id,s.name,s.phone,s.birthday,s.gender,s.user_type,s.user_title,s.dochead,s.content,s.ctime,s.mtime,s.status,s.user_org_id").Find(&userStaffInfo).Error if err != nil { return } return } func UpdateStaffInfo(info models.SgjUserStaffInfo, OrgID int64, id int64) error { err := service.UserWriteDB().Model(&info).Where("user_org_id = ? AND id =? AND status = ?", OrgID, id, 1).Update(map[string]interface{}{"Name": info.Name, "phone": info.Phone, "birthday": info.Birthday, "gender": info.Gender, "user_type": info.UserType, "user_title": info.UserTitle, "dochead": info.Dochead, "content": info.Content, "mtime": info.Mtime}).Error return err } func DeleteStaffs(orgID int64, ids []int64) (err error) { if len(ids) == 1 { err = service.UserWriteDB().Model(&models.SgjUserStaffInfo{}).Where("id=? and user_org_id = ?", ids[0], orgID).Update(map[string]interface{}{"Status": 0, "mtime": time.Now().Unix()}).Error } else { err = service.UserWriteDB().Model(&models.SgjUserStaffInfo{}).Where("id IN (?) and user_org_id = ?", ids, orgID).Update(map[string]interface{}{"Status": 0, "mtime": time.Now().Unix()}).Error } return }