scrm-go

staff_manager_service.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package staff_service
  2. import (
  3. "SCRM/models"
  4. "SCRM/service"
  5. "time"
  6. )
  7. func AddStaffInfo(info models.SgjUserStaffInfo) error {
  8. err := service.UserWriteDB().Create(&info).Error
  9. return err
  10. }
  11. func GetAllStaffInfo(orgID int64,page int64,limit int64,keyword string)(userStaffInfo []*models.SgjUserStaffInfo,total int64,err error){
  12. db := service.UserReadDB().Table("sgj_user_staff_info as s").Where("s.status = 1")
  13. if(orgID>0){
  14. db = db.Where("s.user_org_id = ?", orgID)
  15. }
  16. if len(keyword) >0{
  17. keyword = "%" + keyword + "%"
  18. db =db.Where("s.name LIKE ?",keyword)
  19. }
  20. offset := (page - 1) * limit
  21. err = db.Count(&total).Order("s.ctime desc").Offset(offset).Limit(limit).
  22. 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
  23. if err != nil {
  24. return
  25. }
  26. return
  27. }
  28. func UpdateStaffInfo(info models.SgjUserStaffInfo,OrgID int64,id int64) error {
  29. 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
  30. return err
  31. }
  32. func DeleteStaffs(orgID int64,ids[] int64)(err error) {
  33. if len(ids) ==1{
  34. 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
  35. }else {
  36. 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
  37. }
  38. return
  39. }