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.

70 lines
2.3 KiB

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