exa_customer.go 2.5 KB

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