exa_customer.go 2.3 KB

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