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.

86 lines
2.7 KiB

3 years ago
3 years ago
  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. if err != nil {
  60. return
  61. }
  62. var dataId []string
  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 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. }