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.

82 lines
2.5 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. // @title CreateExaCustomer
  15. // @description create a customer, 创建用户
  16. // @auth (2020/04/05 20:22 )
  17. // @return err error
  18. func (e *ExaCustomer) CreateExaCustomer() (err error) {
  19. err = global.GVA_DB.Create(e).Error
  20. return err
  21. }
  22. // @title DeleteFileChunk
  23. // @description delete a customer, 删除用户
  24. // @auth (2020/04/05 20:22 )
  25. // @return error
  26. func (e *ExaCustomer) DeleteExaCustomer() (err error) {
  27. err = global.GVA_DB.Delete(e).Error
  28. return err
  29. }
  30. // @title UpdateExaCustomer
  31. // @description update a customer, 更新用户
  32. // @auth (2020/04/05 20:22 )
  33. // @return error
  34. func (e *ExaCustomer) UpdateExaCustomer() (err error) {
  35. err = global.GVA_DB.Save(e).Error
  36. return err
  37. }
  38. // @title GetExaCustomer
  39. // @description get the info of a costumer , 获取用户信息
  40. // @auth (2020/04/05 20:22 )
  41. // @return error
  42. // @return customer ExaCustomer
  43. func (e *ExaCustomer) GetExaCustomer() (err error, customer ExaCustomer) {
  44. err = global.GVA_DB.Where("id = ?", e.ID).First(&customer).Error
  45. return
  46. }
  47. // @title GetInfoList
  48. // @description get customer list by pagination, 分页获取用户列表
  49. // @auth (2020/04/05 20:22 )
  50. // @param info PageInfo
  51. // @return error
  52. func (e *ExaCustomer) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
  53. limit := info.PageSize
  54. offset := info.PageSize * (info.Page - 1)
  55. db := global.GVA_DB
  56. if err != nil {
  57. return
  58. } else {
  59. var a SysAuthority
  60. a.AuthorityId = e.SysUserAuthorityID
  61. err, auth := a.GetAuthorityInfo()
  62. var dataId []string
  63. for _, v := range auth.DataAuthorityId {
  64. dataId = append(dataId, v.AuthorityId)
  65. }
  66. var CustomerList []ExaCustomer
  67. err = db.Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Count(&total).Error
  68. if err != nil {
  69. return err, CustomerList, total
  70. } else {
  71. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Error
  72. }
  73. return err, CustomerList, total
  74. }
  75. }