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.

66 lines
1.7 KiB

  1. package model
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type ExaCustomer struct {
  7. gorm.Model
  8. CustomerName string `json:"customerName"`
  9. CustomerPhoneData string `json:"customerPhoneData"`
  10. SysUserID uint `json:"sysUserId"`
  11. SysUserAuthorityID string `json:"sysUserAuthorityID"`
  12. SysUser SysUser `json:"sysUser"`
  13. }
  14. //创建用户
  15. func (e *ExaCustomer) CreateExaCustomer() (err error) {
  16. err = global.GVA_DB.Create(e).Error
  17. return err
  18. }
  19. //删除用户
  20. func (e *ExaCustomer) DeleteExaCustomer() (err error) {
  21. err = global.GVA_DB.Delete(e).Error
  22. return err
  23. }
  24. //更新用户
  25. func (e *ExaCustomer) UpdateExaCustomer() (err error) {
  26. err = global.GVA_DB.Save(e).Error
  27. return err
  28. }
  29. //获取用户信息
  30. func (e *ExaCustomer) GetExaCustomer() (err error, customer ExaCustomer) {
  31. err = global.GVA_DB.Where("id = ?", e.ID).First(&customer).Error
  32. return
  33. }
  34. //获取用户列表
  35. // 分页获取数据
  36. func (e *ExaCustomer) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
  37. limit := info.PageSize
  38. offset := info.PageSize * (info.Page - 1)
  39. db := global.GVA_DB
  40. if err != nil {
  41. return
  42. } else {
  43. var a SysAuthority
  44. a.AuthorityId = e.SysUserAuthorityID
  45. err, auth := a.GetAuthorityInfo()
  46. var dataId []string
  47. for _, v := range auth.DataAuthorityId {
  48. dataId = append(dataId, v.AuthorityId)
  49. }
  50. var CustomerList []ExaCustomer
  51. err = db.Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Count(&total).Error
  52. if err != nil {
  53. return err, CustomerList, total
  54. } else {
  55. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Error
  56. }
  57. return err, CustomerList, total
  58. }
  59. }