event_init.go 1.06 KB
Newer Older
hujiebin's avatar
hujiebin committed
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
package event_s

import (
	"fmt"
	"git.hilo.cn/hilo-common/domain"
	"github.com/pkg/errors"
	"hilo-user/_const/enum/msg_e"
	"hilo-user/_const/enum/res_e"
	"hilo-user/domain/event/user_ev"
	"hilo-user/domain/model/msg_m"
	"hilo-user/domain/model/res_m"
	"hilo-user/domain/model/user_m"
)

func EventInit() {
	UserBagSendEvent()
}

func UserBagSendEvent() {
	user_ev.AddUserBagSendAsync(func(model *domain.Model, event interface{}) error {
		e, ok := event.(*user_ev.UserBagSendEvent)
		if !ok {
			return errors.New("AddUserBagSendAsync param fail")
		}
		if e.ResType != res_e.ResUserBagGift {
			return nil
		}
		user, err := user_m.GetUser(model, e.UserId)
		if err != nil {
			return err
		}
		gift, err := res_m.FindResGift(model, e.ResId)
		if err != nil {
			return err
		}
		if err := msg_m.NewUserRecord(model, e.UserId, msg_e.AddUserBag,
			gift.Name, 0, "", fmt.Sprintf("%d", e.Day),
hujiebin's avatar
hujiebin committed
38
			"", "", "").Persistent(); err != nil {
hujiebin's avatar
hujiebin committed
39 40 41 42 43 44 45
			model.Log.Errorf("NewUserRecord fail")
		} else {
			msg_m.SendEmasMsgAssistant(model, user.ExternalId, user.DeviceType)
		}
		return nil
	})
}