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.

78 lines
2.2 KiB

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