diamond.go 981 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package diamond_tx

import (
chenweijian's avatar
chenweijian committed
4
	"fmt"
hujiebin's avatar
hujiebin committed
5 6
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/internal/enum/diamond_e"
chenweijian's avatar
chenweijian committed
7
	"git.hilo.cn/hilo-common/internal/enum/msg_e"
hujiebin's avatar
hujiebin committed
8 9
	"git.hilo.cn/hilo-common/internal/model/diamond_m"
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
10
	"git.hilo.cn/hilo-common/txop/msg"
hujiebin's avatar
hujiebin committed
11 12 13
)

// 下发钻石
chenweijian's avatar
chenweijian committed
14 15
func SendDiamond(model *domain.Model, userId mysql.ID, opt diamond_e.OperateType, originId mysql.ID, diamondNum mysql.Num,
	msgType ...msg_e.MsgUserRecordType) error {
hujiebin's avatar
hujiebin committed
16 17 18 19 20 21 22 23 24 25 26
	diamondAccount, err := diamond_m.GetDiamondAccountByUserId(model, userId)
	if err != nil {
		return err
	}
	diamondSendAccountDetail, err := diamondAccount.AddDiamondAccountDetail(opt, originId, diamondNum)
	if err != nil {
		return err
	}
	if err := diamondSendAccountDetail.Persistent(); err != nil {
		return err
	}
chenweijian's avatar
chenweijian committed
27 28 29 30
	if len(msgType) > 0 {
		// 小助手提示获得钻石
		msg.SendLittleAssistantMsg(model, userId, msgType[0], fmt.Sprintf("%d", diamondNum), "", "", "", "")
	}
hujiebin's avatar
hujiebin committed
31 32
	return nil
}