2
0

exa_customer.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package example
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  7. systemService "github.com/flipped-aurora/gin-vue-admin/server/service/system"
  8. )
  9. type CustomerService struct{}
  10. var CustomerServiceApp = new(CustomerService)
  11. //@author: [piexlmax](https://github.com/piexlmax)
  12. //@function: CreateExaCustomer
  13. //@description: 创建客户
  14. //@param: e model.ExaCustomer
  15. //@return: err error
  16. func (exa *CustomerService) CreateExaCustomer(e example.ExaCustomer) (err error) {
  17. err = global.GVA_DB.Create(&e).Error
  18. return err
  19. }
  20. //@author: [piexlmax](https://github.com/piexlmax)
  21. //@function: DeleteFileChunk
  22. //@description: 删除客户
  23. //@param: e model.ExaCustomer
  24. //@return: err error
  25. func (exa *CustomerService) DeleteExaCustomer(e example.ExaCustomer) (err error) {
  26. err = global.GVA_DB.Delete(&e).Error
  27. return err
  28. }
  29. //@author: [piexlmax](https://github.com/piexlmax)
  30. //@function: UpdateExaCustomer
  31. //@description: 更新客户
  32. //@param: e *model.ExaCustomer
  33. //@return: err error
  34. func (exa *CustomerService) UpdateExaCustomer(e *example.ExaCustomer) (err error) {
  35. err = global.GVA_DB.Save(e).Error
  36. return err
  37. }
  38. //@author: [piexlmax](https://github.com/piexlmax)
  39. //@function: GetExaCustomer
  40. //@description: 获取客户信息
  41. //@param: id uint
  42. //@return: customer model.ExaCustomer, err error
  43. func (exa *CustomerService) GetExaCustomer(id uint) (customer example.ExaCustomer, err error) {
  44. err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
  45. return
  46. }
  47. //@author: [piexlmax](https://github.com/piexlmax)
  48. //@function: GetCustomerInfoList
  49. //@description: 分页获取客户列表
  50. //@param: sysUserAuthorityID string, info request.PageInfo
  51. //@return: list interface{}, total int64, err error
  52. func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID uint, info request.PageInfo) (list interface{}, total int64, err error) {
  53. limit := info.PageSize
  54. offset := info.PageSize * (info.Page - 1)
  55. db := global.GVA_DB.Model(&example.ExaCustomer{})
  56. var a system.SysAuthority
  57. a.AuthorityId = sysUserAuthorityID
  58. auth, err := systemService.AuthorityServiceApp.GetAuthorityInfo(a)
  59. if err != nil {
  60. return
  61. }
  62. var dataId []uint
  63. for _, v := range auth.DataAuthorityId {
  64. dataId = append(dataId, v.AuthorityId)
  65. }
  66. var CustomerList []example.ExaCustomer
  67. err = db.Where("sys_user_authority_id in ?", dataId).Count(&total).Error
  68. if err != nil {
  69. return CustomerList, total, err
  70. } else {
  71. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in ?", dataId).Find(&CustomerList).Error
  72. }
  73. return CustomerList, total, err
  74. }