exa_customer.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  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: err error, customer model.ExaCustomer
  43. func (exa *CustomerService) GetExaCustomer(id uint) (err error, customer example.ExaCustomer) {
  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: err error, list interface{}, total int64
  52. func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
  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. err, auth := systemService.AuthorityServiceApp.GetAuthorityInfo(a)
  59. var dataId []string
  60. for _, v := range auth.DataAuthorityId {
  61. dataId = append(dataId, v.AuthorityId)
  62. }
  63. var CustomerList []example.ExaCustomer
  64. err = db.Where("sys_user_authority_id in ?", dataId).Count(&total).Error
  65. if err != nil {
  66. return err, CustomerList, total
  67. } else {
  68. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in ?", dataId).Find(&CustomerList).Error
  69. }
  70. return err, CustomerList, total
  71. }