scrm-go

error_code.go 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package enums
  2. import "SCRM/utils"
  3. const ( // ErrorCode
  4. // 登录注册错误 6000+
  5. ErrorCodeLoginTimeout = 6001
  6. ErrorCodeNotLogin = 6002
  7. ErrorCodePermissionDenied = 6003
  8. ErrorCodeMobileRegistered = 6004
  9. ErrorCodePasswordEmpty = 6005
  10. ErrorCodeVerificationCodeWrong = 6006
  11. ErrorCodeRegisterFail = 6007
  12. ErrorCodeInvalidToken = 6008
  13. ErrorCodeAccountOrPasswordWrong = 6009
  14. ErrorCodeMissingOrg = 6010
  15. ErrorCodeMissingOrgApp = 6011
  16. ErrorCodeAccountOrVerCodeWrong = 6012
  17. ErrorCodeMobileNotExit = 6013
  18. ErrorCodeUserNotExist = 6014
  19. ErrorCodeUserWasForbidden = 6015
  20. ErrorCodeNeverCreateTypeApp = 6016
  21. ErrorCodeContactSuperAdminCreateTypeApp = 6017
  22. ErrorCodeVerificationCodeLimit = 6018
  23. // 数据验证错误 7000+
  24. ErrorCodeMobileFormat = 7001
  25. ErrorCodeTelphoneFormat = 7002
  26. ErrorCodeParamWrong = 7003
  27. ErrorCodeParamFormatWrong = 7004
  28. // 数据库操作错误 8000+
  29. ErrorCodeDBCreate = 8001
  30. ErrorCodeDBUpdate = 8002
  31. ErrorCodeDBDelete = 8003
  32. ErrorCodeDBSelectNoResult = 8004
  33. ErrorCodeDataException = 8005
  34. // 业务逻辑操作错误 9000+
  35. ErrorCodeRoleNotExist = 9001
  36. ErrorCodeAdminUserNotExist = 9002
  37. ErrorCodeMobileDidUsedInApp = 9003
  38. ErrorCodeMissingUserName = 9004
  39. ErrorCodeOldPasswordWrong = 9005
  40. ErrorCodeCannotRemoveRole = 9006
  41. ErrorCodeRoleMobileIsSuperAdmin = 9007
  42. ErrorCodeActivityNotExist = 9100
  43. ErrorCodeActivityPublishedCannotModify = 9101
  44. ErrorCodeActivityPublishRepeat = 9102
  45. ErrorCodeGetQiniuUpToken = 1001
  46. ErrorCodeNotSubscibe = 4003
  47. ErrorCodeServeNotExist = 4004
  48. ErrorCodeInvoiceExist = 4005
  49. ErrorCodeApplyInvoiceFail = 4006
  50. ErrorCodeHetongHad = 4007
  51. ErrorCodeCreateHetongFail = 4008
  52. ErrorCodePatientReachLimit = 4009
  53. ErrorCodeSMSNoCustomer = 10001
  54. ErrorCodeSMSLimitInsufficient = 10002
  55. )
  56. var ErrCodeMsgs = map[int]string{
  57. // 登录注册错误
  58. ErrorCodeLoginTimeout: "登录超时",
  59. ErrorCodeNotLogin: "未登录",
  60. ErrorCodePermissionDenied: "权限不足",
  61. ErrorCodeMobileRegistered: "手机号已被注册",
  62. ErrorCodePasswordEmpty: "密码为空",
  63. ErrorCodeVerificationCodeWrong: "验证码错误",
  64. ErrorCodeRegisterFail: "注册失败",
  65. ErrorCodeInvalidToken: "令牌无效",
  66. ErrorCodeAccountOrPasswordWrong: "账号或密码错误",
  67. ErrorCodeMissingOrg: "未创建机构",
  68. ErrorCodeMissingOrgApp: "未创建任何应用",
  69. ErrorCodeAccountOrVerCodeWrong: "账号或验证码错误",
  70. ErrorCodeMobileNotExit: "手机号不存在",
  71. ErrorCodeUserNotExist: "用户不存在",
  72. ErrorCodeUserWasForbidden: "该用户被禁用",
  73. ErrorCodeNeverCreateTypeApp: "未创建此种应用",
  74. ErrorCodeContactSuperAdminCreateTypeApp: "请联系超级管理员开通此种应用",
  75. ErrorCodeVerificationCodeLimit: "该号码今日验证码已超限",
  76. // 数据验证错误
  77. ErrorCodeMobileFormat: "手机号格式错误",
  78. ErrorCodeTelphoneFormat: "电话格式错误",
  79. ErrorCodeParamWrong: "参数错误",
  80. ErrorCodeParamFormatWrong: "参数格式错误",
  81. // 数据库操作错误
  82. ErrorCodeDBCreate: "数据库创建出错",
  83. ErrorCodeDBUpdate: "数据库更新出错",
  84. ErrorCodeDBDelete: "数据库删除出错",
  85. ErrorCodeDBSelectNoResult: "查询无结果",
  86. ErrorCodeDataException: "数据异常",
  87. // 业务逻辑操作错误
  88. ErrorCodeRoleNotExist: "角色不存在",
  89. ErrorCodeAdminUserNotExist: "管理员不存在",
  90. ErrorCodeMobileDidUsedInApp: "该手机号已在该应用中被注册为管理员",
  91. ErrorCodeMissingUserName: "缺少用户名",
  92. ErrorCodeOldPasswordWrong: "原密码不正确",
  93. ErrorCodeCannotRemoveRole: "存在该角色的管理员,不能删除该角色",
  94. ErrorCodeRoleMobileIsSuperAdmin: "该手机号已注册为超级管理员",
  95. ErrorCodeActivityNotExist: "活动不存在",
  96. ErrorCodeActivityPublishedCannotModify: "已发布的活动不可更改",
  97. ErrorCodeActivityPublishRepeat: "该活动已发布",
  98. ErrorCodeGetQiniuUpToken: "获取七牛uptoken失败",
  99. ErrorCodeNotSubscibe: "没有订阅服务或服务已过期,请先购买服务!",
  100. ErrorCodeServeNotExist: "服务订单不存在!",
  101. ErrorCodeInvoiceExist: "已经申请了发票!",
  102. ErrorCodeApplyInvoiceFail: "申请发票失败!",
  103. ErrorCodeHetongHad: "合同已经存在!",
  104. ErrorCodeCreateHetongFail: "合同创建失败",
  105. ErrorCodePatientReachLimit: "患者数已达到当前服务版本病人数,需要升级到更高的版本",
  106. ErrorCodeSMSNoCustomer: "没有目标客户",
  107. ErrorCodeSMSLimitInsufficient: "当月可用短信额度不足",
  108. }
  109. type SGJError struct {
  110. Code int
  111. }
  112. func (e *SGJError) Error() string {
  113. value, ok := ErrCodeMsgs[e.Code]
  114. if ok {
  115. return value
  116. } else {
  117. return "未知错误"
  118. }
  119. }
  120. func MakeSuccessResponseJSON(data map[string]interface{}) map[string]interface{} {
  121. json := make(map[string]interface{})
  122. if data != nil {
  123. json["data"] = data
  124. } else {
  125. json["data"] = make(map[string]interface{})
  126. }
  127. json["state"] = 1
  128. json["code"] = 0
  129. return json
  130. }
  131. func MakeFailResponseJSON(errMsg string, errCode int) map[string]interface{} {
  132. json := make(map[string]interface{})
  133. json["msg"] = errMsg
  134. json["code"] = errCode
  135. json["state"] = 0
  136. return json
  137. }
  138. func MakeFailResponseJSONWithSGJError(err *SGJError) map[string]interface{} {
  139. if err == nil {
  140. utils.WarningLog("MakeFailResponseJSONWithSGJError 参数err 不能为空")
  141. return nil
  142. }
  143. return MakeFailResponseJSON(err.Error(), err.Code)
  144. }
  145. func MakeFailResponseJSONWithSGJErrorCode(code int) map[string]interface{} {
  146. err := &SGJError{Code: code}
  147. return MakeFailResponseJSON(err.Error(), err.Code)
  148. }