diamond.go 1.66 KB
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
}
hujiebin's avatar
hujiebin committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

// 下发钻石
func SendDiamondPink(model *domain.Model, userId mysql.ID, opt diamond_e.OperateType, originId mysql.ID, diamondNum mysql.Num, operateIds string,
	msgType ...msg_e.MsgUserRecordType) error {
	diamondAccount, err := diamond_m.GetDiamondAccountByUserId(model, userId)
	if err != nil {
		return err
	}
	diamondSendAccountDetail, err := diamondAccount.ChangePinkDiamondAccountDetail(opt, originId, diamondNum, operateIds)
	if err != nil {
		return err
	}
	if err := diamondSendAccountDetail.Persistent(); err != nil {
		return err
	}
	if len(msgType) > 0 {
		// 小助手提示获得钻石
		msg.SendLittleAssistantMsg(model, userId, msgType[0], fmt.Sprintf("%d", diamondNum), "", "", "", "")
	}
	return nil
}