You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. package dbModel
  2. import (
  3. "gin-vue-admin/controller/servers"
  4. "gin-vue-admin/init/qmsql"
  5. "gin-vue-admin/model/modelInterface"
  6. "gin-vue-admin/model/sysModel"
  7. "github.com/jinzhu/gorm"
  8. )
  9. type ExaCustomer struct {
  10. gorm.Model
  11. CustomerName string `json:"customerName"`
  12. CustomerPhoneData string `json:"customerPhoneData"`
  13. SysUserID uint `json:"sysUserId"`
  14. SysUserAuthorityID string `json:"sysUserAuthorityID"`
  15. SysUser sysModel.SysUser `json:"sysUser"`
  16. }
  17. //创建用户
  18. func (e *ExaCustomer)CreateExaCustomer()(err error){
  19. err = qmsql.DEFAULTDB.Create(e).Error
  20. return err
  21. }
  22. //删除用户
  23. func (e *ExaCustomer)DeleteExaCustomer()(err error){
  24. err = qmsql.DEFAULTDB.Delete(e).Error
  25. return err
  26. }
  27. //更新用户
  28. func (e *ExaCustomer)UpdataExaCustomer()(err error){
  29. err = qmsql.DEFAULTDB.Save(e).Error
  30. return err
  31. }
  32. //获取用户信息
  33. func (e *ExaCustomer)GetExaCustomer()(err error,customer ExaCustomer){
  34. err= qmsql.DEFAULTDB.Where("id = ?",e.ID).First(&customer).Error
  35. return
  36. }
  37. //获取用户列表
  38. // 分页获取数据 需要分页实现这个接口即可
  39. func (e *ExaCustomer) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
  40. // 封装分页方法 调用即可 传入 当前的结构体和分页信息
  41. err, db, total := servers.PagingServer(e, info)
  42. if err != nil {
  43. return
  44. } else {
  45. var a sysModel.SysAuthority
  46. a.AuthorityId = e.SysUserAuthorityID
  47. err,auth := a.GetAuthorityInfo()
  48. var dataId []string
  49. for _,v := range auth.DataAuthorityId{
  50. dataId = append(dataId, v.AuthorityId)
  51. }
  52. var CustomerList []ExaCustomer
  53. err = db.Where("sys_user_authority_id in (?)",dataId).Find(&CustomerList).Count(&total).Error
  54. if err!=nil{
  55. return err, CustomerList, total
  56. }else{
  57. err = db.Preload("SysUser").Where("sys_user_authority_id in (?)",dataId).Find(&CustomerList).Error
  58. }
  59. return err, CustomerList, total
  60. }
  61. }