Commit 0869e797 authored by chenweijian's avatar chenweijian

错误toast翻译

parent 3537174e
package common
type MsgIdType = uint
type OnlineStatusType = uint
type GroupRoleType = uint16
type AddGroupResultType = uint
const (
APP_KICKOFF_TIME = "2020-12-19"
DEFAULT_LANG = "en"
DEFAULT_COUNTRY = "KSA"
DEFAULT_NICK = "Hilo No.%s"
DEFAULT_DESCRIPTION = "Welcome to Hilo"
DEFAULT_GROUP_NAME = "Hilo Group NO.%s"
DefaultAvatarMan = "hilo/manager/ea48b62d54a24a709de3c38702c89995.png"
DefaultAvatarWoman = "hilo/manager/ea48b62d54a24a709de3c38702c89995.png"
// 用户视频最低要求时长
BASIC_VIDEO_TIME = 1
// 公会用户视频最低要求时长
GUILD_USER_VIDEO_TIME = 15
STATUS_IN_USE = 1
STATUS_UNUSED = 2
// 公会用户是否打开通知
GuildUserNotifyOn = 1
GuildUserNotifyOff = 2
// 平台
PlatformIOS = 1
PlatformGOOGLE = 2
PlatformEggPlant = 3 // 通过starchat回调的茄子充值
PlatformCheckout = 4
PlatformPayerMax = 5 // 通过hilo用户发起,starchat回调的PayerMax/茄子充值
PlatformPaypal = 6 // paypal充值
// 加、减
DIRECTION_ADD = 1
DIRECTION_REDUCE = 2
// 操作类型
//发送礼物
OPERATE_TYPE_SENDGIFT = 1
//匹配条件
OPERATE_TYPE_MATCHCONDITION = 2
//建立融云会话
OPERATE_TYPE_SESSIONPAY = 3
//购买钻石
OPERATE_TYPE_BUYDIAMOND = 4
//接受礼物
OPERATE_TYPE_RECEIVEGIFT = 5
//注册
OPERATE_TYPE_REGISTER = 6
//平台赠送
OPERATE_TYPE_MGRSEND = 8
MATCH_CONFIRM_SUCCESS = 1
MATCH_CONFIRM_FAIL = 2
MATCH_CONFIRM_TEMP = 3
ACCEPT_MATCH_CONFIRM = 1
REFUSE_MATCH_CONFIRM = 2
// 视频通话是否达标
VIDEO_EFFECTIVE_YES = 1
VIDEO_EFFECTIVE_NO = 2
// 最大用户相册数
USER_PHOTO_MAX = 9
// 上下架状态
SWITCH_ON = 1
SWITH_OFF = 0
// 群组角色
GROUP_VISITOR GroupRoleType = 0 // 游客
GROUP_MEMBER GroupRoleType = 1 // 成员
GROUP_ADMIN GroupRoleType = 10 // 管理员
GROUP_MANAGER GroupRoleType = 50 // 经理
GROUP_OWNER GroupRoleType = 100 // owner
ROOM_PASSWORD_LENGTH = 4
CREATE_GROUP_MAX_ATTEMPT = 10
// 在线状态
IM_STATUS_OFF_LINE OnlineStatusType = 0
IM_STATUS_PUSH_ON_LINE OnlineStatusType = 1
IM_STATUS_ON_LINE OnlineStatusType = 2
MSG_ID_GROUP_NAME MsgIdType = 101
MSG_ID_GROUP_INTRODUCTION MsgIdType = 102
MSG_ID_GROUP_NOTIFICATION MsgIdType = 103
MSG_ID_GROUP_WELCOME MsgIdType = 104
MSG_ID_GROUP_INVITE MsgIdType = 105
MSG_ID_GROUP_LEAVE_POWER MsgIdType = 106
MSG_ID_ALL_GROUP_ROCKET MsgIdType = 107
MSG_ID_ROOM_MEADAL MsgIdType = 108
MSG_ID_VIDEO_PUSH_TITITLE MsgIdType = 109
MSG_ID_VIDEO_PUSH_CONTENT MsgIdType = 110
MSG_ID_REPEAT_ACCOUNT MsgIdType = 111
MSG_ID_USER_TRANSFER MsgIdType = 114
MSG_ID_NO_POWER_TO_SVIP6 MsgIdType = 115 // 不能对svip6做某些动作
// ps:116-138 在hilo-finance定义了!
MSG_ID_NOT_FAMILY_MEMBER MsgIdType = 165 // 非家族成员
MSG_ID_DEALER_CAN_NOT_SOLE MsgIdType = 166 // 此用户已有家族代理,不能出售钻石
MSG_ID_BUY_FROM_FAMILY MsgIdType = 167 // 请向本家族代理购买钻石
MSG_ID_NEED_JOIN_FAMILY MsgIdType = 168 // 请加入代理的家族后进行购买
MSG_ID_TRAN_DIAMONDS MsgIdType = 172 // 代理转币
MSG_ID_LINK_CHARGE_REBATE MsgIdType = 173 // 链接充值返利
MSG_ID_LINK_CHARGE MsgIdType = 174 // 链接充值
MSG_ID_AGENT_DIAMOND_REBATE MsgIdType = 175 // 代理充值返利
MSG_ID_AGENT_DIAMOND MsgIdType = 176 // 代理充值
MSG_ID_AGENT_SYSTEM MsgIdType = 178 // 系统给代理充值
MSG_ID_CHARGE_NO_AREA MsgIdType = 181 // 充值(代理转账,用户给代理充值),失败,不是本区域用户
MSG_ID_FAMILY_JOIN MsgIdType = 185 // 用户申请加入家族
MSG_ID_SEND_GIFT_TO_NO_ONE MsgIdType = 229 // 送礼给没人
MSG_ID_TRAN_GEM MsgIdType = 231 // 转移宝石(粉钻)
MSG_ID_BUY_GEM MsgIdType = 232 // 买宝石(粉钻)
ADD_GROUP_FAILED AddGroupResultType = 0
ADD_GROUP_DONE AddGroupResultType = 1
ADD_GROUP_DUPLICATE AddGroupResultType = 2
ADD_GROUP_PENDING AddGroupResultType = 3
SETTING_OFFICIAL = 1
SETTING_CUSTOMIZED = 2
)
var USER_QPS_DEFAULT_MAX int64 = 15
var HEART_VALUE_MAX uint32 = 2000
var BUILDBOARD_SMALL_SIZE = 30
var BUILDBOARD_SIZE = 50
var BUILDBOARD_SMALL_SIZE_10 = 10
var GROUP_CREATE_LIMIT = 1
var GROUP_NAME_LENGTH_LIMIT = 30
var GROUP_INTRODUCTION_LENGTH_LIMIT = 500
var GROUP_NOTIFICATION_LENGTH_LIMIT = 150
var MAX_BEAUTIFUL_CODE_LENGTH = 8
var GROUP_DEFAULT_CODE_LENGTH uint16 = 8
var GROUP_DEFAULT_JOIN_LIMIT uint = 200
var GROUP_VIP_JOIN_LIMIT uint = 500
var GROUP_NOBLE4_JOIN_LIMIT uint = 1000
var GROUP_MANAGER_LIMIT uint = 30
var GROUP_ADMIN_LIMIT uint = 50
var GROUP_ROLE_VIEW_LIMIT = 10
var GROUP_ROLE_PERSONAL_VIEW_LIMIT = 5
var GROUP_RECOMMEND_SIZE = 5
var IM_INVALID_USER = "@TLS#NOT_FOUND"
// TIM相关常量
const (
SYNC_TO_SENDER = 1
NOSYNC_TO_SENDER = 2
TAG_PROFILE_IM_LEVEL = "Tag_Profile_IM_Level"
TAG_PROFILE_IM_NICK = "Tag_Profile_IM_Nick"
TAG_PROFILE_IM_IMAGE = "Tag_Profile_IM_Image"
TAG_PROFILE_IM_HILO = "Tag_Profile_Custom_Hilo"
)
// 群组内游戏相关
const (
GROUP_DICE_NUM_DEFAULT = 5
GROUP_DICE_NUM_MAX = 5
)
var PAY_TEST_USERS = []uint64{11, 21, 41, 71, 151, 251, 291, 881, 1041, 4411, 951, 24091}
var ROCKET_STAGE_NUM uint16 = 3
var ROCKET_STAGE_CHANGE_THRESHOLD = 10
var ROCKET_SHOW_DURATION = 10
// RocketAwardType
const (
ROCKET_AWARD_GUEST_DIAMOND = 0 // 观众分到小额钻石
ROCKET_AWARD_PROPERTY = 1 // TOP6抽到的座驾
ROCKET_AWARD_HEADDRESS = 2 // TOP6抽到的头饰
ROCKET_AWARD_DIAMOND = 3 // TOP6抽到的钻石
)
const DefaultMinimalVersionAndroid = 100
const DefaultMinimalVersionIOS = 100
const DefaultMsgParallelSize = 20
const OldGroupNamePrefix = "@TGS#"
const NewGroupNamePrefix = "HTGS#"
const OverseaGroupNamePrefix = NewGroupNamePrefix + "a"
const (
SendSmsCodeIpMaxHourTimes = 20
SendSmsCodeImeiMaxHourTimes = 10
SendSmsCodePhoneMaxHourTimes = 5
SendSmsCodeUserMaxHourTimes = 3
SendSmsCodeLen = 6 // 验证码长度
SendSmsCodeMaxCheckTimes = 3 // 验证码最大校验次数
SendSmsCodeNoUserIdMaxHourTimes = 1000 // 没有传userId调用发短信,5分钟最大次数
CallbackCheckoutPaySucceed = "payment_captured" // checkout回调支付成功
// ranking
RankingDay = "day"
RankingWeek = "week"
RankingMonth = "month"
RankingAll = "all"
// ranking module
RankingModulePinkDiamond = "pinkDiamond"
// giftwall 礼物墙
GiftWallInitNum = 15000 // 礼物墙初始化数量
GiftWallInitOnceSetNum = 500 // 礼物墙初始化,一次插入的数量
GiftWallStartReduceNum = 20000 // 礼物墙触发清理逻辑数量
GiftWallReduceNum = 3000 // 礼物墙触发清理逻辑,清理的数量
)
package res_m
import (
"fmt"
"git.hilo.cn/hilo-common/_const/common"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/myerr"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
)
type ResMultiText struct {
mysql.Entity
MsgId uint
Language mysql.Str
Content mysql.Str
}
func (r *ResMultiText) Get(db *gorm.DB) error {
return db.Where(r).First(r).Error
}
func GetResMultiTextBy(model *domain.Model, msgId uint, Language mysql.Str) (*ResMultiText, error) {
r := ResMultiText{}
if err := model.DB().Where(&ResMultiText{
MsgId: msgId,
Language: Language,
}).First(&r).Error; err != nil {
if err == gorm.ErrRecordNotFound {
if err := model.DB().Where(&ResMultiText{
MsgId: msgId,
Language: common.DEFAULT_LANG,
}).First(&r).Error; err != nil {
return nil, myerr.WrapErr(err)
}
} else {
return nil, myerr.WrapErr(err)
}
}
return &r, nil
}
func GetErrByLanguage(model *domain.Model, msgId common.MsgIdType, lang string, myErr *myerr.BusinessError, args ...interface{}) *myerr.BusinessError {
var msg string
if len(args) > 0 {
msg = fmt.Sprintf(myErr.GetMsg(), args...)
} else {
msg = myErr.GetMsg()
}
if resMul, _ := GetResMultiTextBy(model, msgId, lang); resMul != nil {
if len(args) > 0 {
msg = fmt.Sprintf(resMul.Content, args...)
} else {
msg = resMul.Content
}
}
return myerr.NewBusinessCodeNoCheck(myErr.GetCode(), msg, myerr.BusinessData{})
}
package myerr
import (
"fmt"
"git.hilo.cn/hilo-common/mylogrus"
"github.com/pkg/errors"
"strconv"
)
//成功
type Success struct {
code uint16
message string
}
func (err *Success) Error() string {
return err.message
}
//正确的标识符
var success = &Success{code: 200, message: "OK"}
func GetSuccessCode() uint16 {
return success.code
}
func GetSuccessMsg() string {
return success.message
}
func GetSuccess() Success {
return *success
}
//系统错误
type SysError struct {
code uint16
message string
err error
}
var sysError = &SysError{
code: 500,
message: "",
}
func (err *SysError) Error() string {
return err.err.Error()
}
func NewSysError(msg string) *SysError {
return &SysError{
code: sysError.code,
message: msg,
err: errors.New("{code:" + strconv.Itoa(int(sysError.code)) + ",message:" + msg + "}"),
}
}
func NewSysErrorF(format string, args ...interface{}) *SysError {
return NewSysError(fmt.Sprintf(format, args...))
}
func GetSysErrorCode() uint16 {
return sysError.code
}
func (sysError *SysError) GetErr() error {
return sysError.err
}
func (sysError *SysError) GetCode() uint16 {
return sysError.code
}
func (sysError *SysError) GetMsg() string {
return sysError.message
}
//警告错误
type WaringError struct {
code uint16
message string
err error
}
var waringError = &WaringError{
code: 300,
message: "",
}
func GetWaringCode() uint16 {
return waringError.code
}
func (err *WaringError) Error() string {
return err.err.Error()
}
func NewWaring(msg string) *WaringError {
return &WaringError{
code: waringError.code,
message: msg,
err: errors.New("{code:" + strconv.Itoa(int(waringError.code)) + ",message:" + msg + "}"),
}
}
func NewWaringErrorF(format string, args ...interface{}) *WaringError {
return NewWaring(fmt.Sprintf(format, args...))
}
func (err *WaringError) GetErr() error {
return err.err
}
func (err *WaringError) GetCode() uint16 {
return err.code
}
func (err *WaringError) GetMsg() string {
return err.message
}
//业务错误
type BusinessError struct {
code uint16
message string
err error
data BusinessData
}
func (err *BusinessError) Error() string {
return err.err.Error()
}
func (err *BusinessError) GetErr() error {
return err.err
}
func (err *BusinessError) GetCode() uint16 {
return err.code
}
func (err *BusinessError) GetMsg() string {
return err.message
}
func (err *BusinessError) GetData() BusinessData {
return err.data
}
var codes = map[uint16]string{}
//定义必须是明确的。不可以修改,字段等同于翻译中要替换的字符
type BusinessData struct {
//剩余秒
Second int `json:"second"`
//所需数量
Num int `json:"num"`
Code string `json:"code"`
Timestamp int64 `json:"timestamp"`
//官网充值地址
CheckOutUrl string `json:"checkOutUrl"`
}
func NewBusiness(err *BusinessError) *BusinessError {
return &BusinessError{
code: err.code,
message: err.message,
err: err.err,
data: err.data,
}
}
func NewBusinessCode(code uint16, msg string, data BusinessData) *BusinessError {
if _, ok := codes[code]; ok {
mylogrus.MyLog.Error(fmt.Sprintf("错误码 %d 已经存在,请更换一个", code))
return nil
}
codes[code] = msg
return &BusinessError{
code: code,
message: msg,
err: errors.New("{code:" + strconv.Itoa(int(code)) + ",message:" + msg + "}"),
data: data,
}
}
func NewBusinessCodeNoCheck(code uint16, msg string, data BusinessData) *BusinessError {
return &BusinessError{
code: code,
message: msg,
err: errors.New("{code:" + strconv.Itoa(int(code)) + ",message:" + msg + "}"),
data: data,
}
}
//包装日志,让日志成堆栈状态
func WrapErrWithStr(err error, msg string) error {
if h, ok := err.(*BusinessError); ok {
h.err = errors.Wrap(h.err, msg)
return h
} else if h, ok := err.(*WaringError); ok {
h.err = errors.Wrap(h.err, msg)
return h
} else if h, ok := err.(*SysError); ok {
h.err = errors.Wrap(h.err, msg)
return h
} else {
return errors.Wrap(err, msg)
}
}
func WrapErr(err error) error {
if h, ok := err.(*BusinessError); ok {
h1 := NewBusiness(h)
h1.err = errors.Wrap(h1.err, "")
return h1
} else if h, ok := err.(*WaringError); ok {
h.err = errors.Wrap(h.err, "")
return h
} else if h, ok := err.(*SysError); ok {
h.err = errors.Wrap(h.err, "")
return h
} else {
return errors.Wrap(err, "")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment