msg.go 1.24 KB
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4 5 6 7 8
package msg

import (
	"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/user_m"
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
9
	"git.hilo.cn/hilo-common/utils"
chenweijian's avatar
chenweijian committed
10 11 12 13 14
)

// 发送小助手消息
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) {
chenweijian's avatar
chenweijian committed
15
	defer utils.CheckGoPanic()
chenweijian's avatar
chenweijian committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	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 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
}