scrm-go

staff_manager_service.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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) {
  29. 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})
  30. }
  31. func DeleteStaffs(orgID int64,ids[] int64)(err error) {
  32. if len(ids) ==1{
  33. 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
  34. }else {
  35. 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
  36. }
  37. return
  38. }