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.

85 lines
2.7 KiB

3 years ago
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. //@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: err error, customer model.ExaCustomer
  42. func (exa *CustomerService) GetExaCustomer(id uint) (err error, customer example.ExaCustomer) {
  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: err error, list interface{}, total int64
  51. func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
  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. err, auth := systemService.AuthorityServiceApp.GetAuthorityInfo(a)
  58. if err != nil {
  59. return
  60. }
  61. var dataId []string
  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 err, CustomerList, total
  69. } else {
  70. err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in ?", dataId).Find(&CustomerList).Error
  71. }
  72. return err, CustomerList, total
  73. }