1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package msg
import (
"fmt"
"git.hilo.cn/hilo-common/_const/common"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/internal/enum/msg_e"
"git.hilo.cn/hilo-common/internal/model/msg_m"
"git.hilo.cn/hilo-common/internal/model/res_m"
"git.hilo.cn/hilo-common/internal/model/user_m"
"git.hilo.cn/hilo-common/myerr"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
)
// 发送小助手消息
func SendLittleAssistantMsg(model *domain.Model, userId mysql.ID, t msg_e.MsgUserRecordType, diamondIncome mysql.Str,
dayNum mysql.Str, propertyUrl mysql.Str, beanNum mysql.Str, groupCode mysql.Str, users ...*user_m.User) (err error) {
defer utils.CheckGoPanic()
var user *user_m.User
if len(users) > 0 {
user = users[0]
} else {
user, err = user_m.GetUser(model, userId)
if err != nil {
model.Log.Errorf("SendLittleAssistantMsg GetUser userId:%v, err:%v", userId, err)
return err
}
}
if t > 0 {
if err = msg_m.NewUserRecord(model, user.ID, t, user.Nick, user.ID, diamondIncome, dayNum, propertyUrl, beanNum, groupCode).Persistent(); err != nil {
model.Log.Errorf("SendLittleAssistantMsg NewUserRecord err:%v", err)
return err
}
}
err = msg_m.SendEmasMsgAssistant(model, user.ExternalId, user.DeviceType)
if err != nil {
model.Log.Errorf("SendLittleAssistantMsg SendEmasMsgAssistant userId:%v, err:%v", userId, err)
return err
}
return nil
}
// 错误toast翻译
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, _ := res_m.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{})
}
func GetResMultiTextBy(model *domain.Model, msgId uint, Language mysql.Str) (string, error) {
r := res_m.ResMultiText{}
if err := model.DB().Where(&res_m.ResMultiText{
MsgId: msgId,
Language: Language,
}).First(&r).Error; err != nil {
if err == gorm.ErrRecordNotFound {
if err := model.DB().Where(&res_m.ResMultiText{
MsgId: msgId,
Language: common.DEFAULT_LANG,
}).First(&r).Error; err != nil {
return "", myerr.WrapErr(err)
}
} else {
return "", myerr.WrapErr(err)
}
}
return r.Content, nil
}