123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package enums
-
- import "KYA/utils"
-
- const ( // ErrorCode
- // 登录注册错误 6000+
- ErrorCodeLoginTimeout = 6001
- ErrorCodeNotLogin = 6002
- ErrorCodePermissionDenied = 6003
- ErrorCodeMobileRegistered = 6004
- ErrorCodePasswordEmpty = 6005
- ErrorCodeVerificationCodeWrong = 6006
- ErrorCodeRegisterFail = 6007
- ErrorCodeInvalidToken = 6008
- ErrorCodeAccountOrPasswordWrong = 6009
- ErrorCodeMissingOrg = 6010
- ErrorCodeMissingOrgApp = 6011
- ErrorCodeAccountOrVerCodeWrong = 6012
- ErrorCodeMobileNotExit = 6013
- ErrorCodeUserNotExist = 6014
- ErrorCodeUserWasForbidden = 6015
- ErrorCodeNeverCreateTypeApp = 6016
- ErrorCodeContactSuperAdminCreateTypeApp = 6017
- ErrorCodeVerificationCodeLimit = 6018
-
- // 数据验证错误 7000+
- ErrorCodeMobileFormat = 7001
- ErrorCodeTelphoneFormat = 7002
- ErrorCodeParamWrong = 7003
- ErrorCodeParamFormatWrong = 7004
-
- // 数据库操作错误 8000+
- ErrorCodeDBCreate = 8001
- ErrorCodeDBUpdate = 8002
- ErrorCodeDBDelete = 8003
- ErrorCodeDBSelectNoResult = 8004
- ErrorCodeDataException = 8005
-
- // 业务逻辑操作错误 9000+
- ErrorCodeRoleNotExist = 9001
- ErrorCodeAdminUserNotExist = 9002
- ErrorCodeMobileDidUsedInApp = 9003
- ErrorCodeMissingUserName = 9004
- ErrorCodeOldPasswordWrong = 9005
- ErrorCodeCannotRemoveRole = 9006
- ErrorCodeRoleMobileIsSuperAdmin = 9007
-
- ErrorCodeActivityNotExist = 9100
- ErrorCodeActivityPublishedCannotModify = 9101
- ErrorCodeActivityPublishRepeat = 9102
-
- ErrorCodeGetQiniuUpToken = 1001
-
- ErrorCodeNotSubscibe = 4003
- ErrorCodeServeNotExist = 4004
- ErrorCodeInvoiceExist = 4005
- ErrorCodeApplyInvoiceFail = 4006
- ErrorCodeHetongHad = 4007
- ErrorCodeCreateHetongFail = 4008
- ErrorCodePatientReachLimit = 4009
-
- ErrorCodeSMSNoCustomer = 10001
- ErrorCodeSMSLimitInsufficient = 10002
- )
-
- var ErrCodeMsgs = map[int]string{
- // 登录注册错误
- ErrorCodeLoginTimeout: "登录超时",
- ErrorCodeNotLogin: "未登录",
- ErrorCodePermissionDenied: "权限不足",
- ErrorCodeMobileRegistered: "手机号已被注册",
- ErrorCodePasswordEmpty: "密码为空",
- ErrorCodeVerificationCodeWrong: "验证码错误",
- ErrorCodeRegisterFail: "注册失败",
- ErrorCodeInvalidToken: "令牌无效",
- ErrorCodeAccountOrPasswordWrong: "账号或密码错误",
- ErrorCodeMissingOrg: "未创建机构",
- ErrorCodeMissingOrgApp: "未创建任何应用",
- ErrorCodeAccountOrVerCodeWrong: "账号或验证码错误",
- ErrorCodeMobileNotExit: "手机号不存在",
- ErrorCodeUserNotExist: "用户不存在",
- ErrorCodeUserWasForbidden: "该用户被禁用",
- ErrorCodeNeverCreateTypeApp: "未创建此种应用",
- ErrorCodeContactSuperAdminCreateTypeApp: "请联系超级管理员开通此种应用",
- ErrorCodeVerificationCodeLimit: "该号码今日验证码已超限",
-
- // 数据验证错误
- ErrorCodeMobileFormat: "手机号格式错误",
- ErrorCodeTelphoneFormat: "电话格式错误",
- ErrorCodeParamWrong: "参数错误",
- ErrorCodeParamFormatWrong: "参数格式错误",
-
- // 数据库操作错误
- ErrorCodeDBCreate: "数据库创建出错",
- ErrorCodeDBUpdate: "数据库更新出错",
- ErrorCodeDBDelete: "数据库删除出错",
- ErrorCodeDBSelectNoResult: "查询无结果",
- ErrorCodeDataException: "数据异常",
-
- // 业务逻辑操作错误
- ErrorCodeRoleNotExist: "角色不存在",
- ErrorCodeAdminUserNotExist: "管理员不存在",
- ErrorCodeMobileDidUsedInApp: "该手机号已在该应用中被注册为管理员",
- ErrorCodeMissingUserName: "缺少用户名",
- ErrorCodeOldPasswordWrong: "原密码不正确",
- ErrorCodeCannotRemoveRole: "存在该角色的管理员,不能删除该角色",
- ErrorCodeRoleMobileIsSuperAdmin: "该手机号已注册为超级管理员",
-
- ErrorCodeActivityNotExist: "活动不存在",
- ErrorCodeActivityPublishedCannotModify: "已发布的活动不可更改",
- ErrorCodeActivityPublishRepeat: "该活动已发布",
-
- ErrorCodeGetQiniuUpToken: "获取七牛uptoken失败",
-
- ErrorCodeNotSubscibe: "没有订阅服务或服务已过期,请先购买服务!",
- ErrorCodeServeNotExist: "服务订单不存在!",
- ErrorCodeInvoiceExist: "已经申请了发票!",
- ErrorCodeApplyInvoiceFail: "申请发票失败!",
- ErrorCodeHetongHad: "合同已经存在!",
- ErrorCodeCreateHetongFail: "合同创建失败",
- ErrorCodePatientReachLimit: "患者数已达到当前服务版本病人数,需要升级到更高的版本",
-
- ErrorCodeSMSNoCustomer: "没有目标客户",
- ErrorCodeSMSLimitInsufficient: "当月可用短信额度不足",
- }
-
- type SGJError struct {
- Code int
- }
-
- func (e *SGJError) Error() string {
- value, ok := ErrCodeMsgs[e.Code]
- if ok {
- return value
- } else {
- return "未知错误"
- }
- }
-
- func MakeSuccessResponseJSON(data map[string]interface{}) map[string]interface{} {
- json := make(map[string]interface{})
- if data != nil {
- json["data"] = data
- } else {
- json["data"] = make(map[string]interface{})
- }
- json["state"] = 1
- json["code"] = 0
- return json
- }
-
- func MakeFailResponseJSON(errMsg string, errCode int) map[string]interface{} {
- json := make(map[string]interface{})
- json["msg"] = errMsg
- json["code"] = errCode
- json["state"] = 0
- return json
- }
-
- func MakeFailResponseJSONWithSGJError(err *SGJError) map[string]interface{} {
- if err == nil {
- utils.WarningLog("MakeFailResponseJSONWithSGJError 参数err 不能为空")
- return nil
- }
- return MakeFailResponseJSON(err.Error(), err.Code)
- }
-
- func MakeFailResponseJSONWithSGJErrorCode(code int) map[string]interface{} {
- err := &SGJError{Code: code}
- return MakeFailResponseJSON(err.Error(), err.Code)
- }
|