event_init.go 5.24 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5
package event_s

import (
	"git.hilo.cn/hilo-common/domain"
	"hilo-group/_const/enum/msg_e"
6
	"hilo-group/domain/event/group_ev"
hujiebin's avatar
hujiebin committed
7
	"hilo-group/domain/event/group_power_ev"
8
	"hilo-group/domain/model/diamond_m"
hujiebin's avatar
hujiebin committed
9 10 11
	"hilo-group/domain/model/groupPower_m"
	"hilo-group/domain/model/msg_m"
	"hilo-group/domain/model/user_m"
12
	"strconv"
hujiebin's avatar
hujiebin committed
13 14 15 16
)

func EventInit() {
	GroupPowerEvents()
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 83 84 85 86
	GroupSupportEvents()
}

func GroupSupportEvents() {
	//群组支持
	group_ev.AddGroupSupportSync(func(model *domain.Model, e interface{}) error {
		event, ok := e.(*group_ev.GroupSupportEvent)
		if !ok {
			model.Log.Errorf("AddGroupSupportSync fail data")
			return nil
		}
		model.Log.Infof("diamond AddGroupSupport admin:%v mgrs:%v", event.GroupSupportAwardAdmin, event.GroupSupportAwardMgrs)
		diamondAccountAdmin, err := diamond_m.GetDiamondAccountByUserId(model, event.GroupSupportAwardAdmin.UserId)
		if err != nil {
			return err
		}
		diamondAccountDetailAdmin, err := diamondAccountAdmin.GroupSupportAdmin(event.GroupSupportAwardAdmin.GroupSupportAwardId, event.GroupSupportAwardAdmin.DiamondNum)
		if err != nil {
			return err
		}
		if err := diamondAccountDetailAdmin.Persistent(); err != nil {
			return err
		}
		for i, _ := range event.GroupSupportAwardMgrs {
			diamondAccount, err := diamond_m.GetDiamondAccountByUserId(model, event.GroupSupportAwardMgrs[i].UserId)
			if err != nil {
				return err
			}
			diamondAccountDetail, err := diamondAccount.GroupSupportMgr(event.GroupSupportAwardMgrs[i].GroupSupportAwardId, event.GroupSupportAwardMgrs[i].DiamondNum)
			if err != nil {
				return err
			}
			if err := diamondAccountDetail.Persistent(); err != nil {
				return err
			}
		}
		return nil
	})

	//群组支持奖励
	group_ev.AddGroupSupportAsync(func(model *domain.Model, e interface{}) error {
		event, ok := e.(*group_ev.GroupSupportEvent)
		if !ok {
			model.Log.Errorf("AddGroupSupportSync fail data")
			return nil
		}
		model.Log.Infof("msg AddGroupSupportAsync admin:%v, mgr:%v", event.GroupSupportAwardAdmin, event.GroupSupportAwardMgrs)
		for i, _ := range event.GroupSupportAwardMgrs {
			user, err := user_m.GetUser(model, event.GroupSupportAwardMgrs[i].UserId)
			if err != nil {
				model.Log.Errorf("msg AddGroupSupportAsync GetUser userId:%v, err:%v", event.GroupSupportAwardMgrs[i].UserId, err)
			}
			if err := msg_m.NewUserRecord(model, user.ID, msg_e.GroupSupport, user.Nick, user.ID, strconv.FormatUint(uint64(event.GroupSupportAwardMgrs[i].DiamondNum), 10), "", "", "", event.GroupCode).Persistent(); err != nil {
				model.Log.Errorf("msg AddGroupSupportAsync NewUserRecord err:%v", err)
				break
			}
			msg_m.SendEmasMsgAssistant(model, user.ExternalId, user.DeviceType)
		}
		user, err := user_m.GetUser(model, event.GroupSupportAwardAdmin.UserId)
		if err != nil {
			model.Log.Errorf("msg AddGroupSupportAsync GetUser userId:%v, err:%v", event.GroupSupportAwardAdmin.UserId, err)
		}
		if err := msg_m.NewUserRecord(model, user.ID, msg_e.GroupSupport, user.Nick, user.ID, strconv.FormatUint(uint64(event.GroupSupportAwardAdmin.DiamondNum), 10), "", "", "", event.GroupCode).Persistent(); err != nil {
			model.Log.Errorf("msg AddGroupSupportAsync NewUserRecord err:%v", err)
			return nil
		}
		msg_m.SendEmasMsgAssistant(model, user.ExternalId, user.DeviceType)
		return nil
	})

hujiebin's avatar
hujiebin committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
}

func GroupPowerEvents() {
	//加入势力
	group_power_ev.AddGroupPowerJoinAsync(func(model *domain.Model, e interface{}) error {
		event, ok := e.(*group_power_ev.GroupPowerJoinEvent)
		if !ok {
			model.Log.Errorf("AddGroupPowerJoinAsync event type err")
			return nil
		}
		model.Log.Infof("msg AddGroupPowerJoinAsync UserId:%v, GroupPowerId:%v", event.UserId, event.GroupPowerId)
		//获取势力主
		mgrUserId, err := groupPower_m.GetGroupPowerMgr(model, event.GroupPowerId)
		if err != nil {
			return err
		}
		mgrUser, err := user_m.GetUser(model, mgrUserId)
		if err != nil {
			return err
		}
		joinUser, err := user_m.GetUser(model, event.UserId)
		if err != nil {
			return err
		}
		if err := msg_m.NewUserRecord(model, mgrUser.ID, msg_e.GroupPowerUserJoin, joinUser.Nick, joinUser.ID, "", "", "", "", "").Persistent(); err != nil {
			model.Log.Errorf("msg AddGroupPowerJoinAsync NewUserRecord err:%v", err)
			return nil
		}
		msg_m.SendEmasMsgAssistant(model, mgrUser.ExternalId, mgrUser.DeviceType)
		return nil
	})
	//离开势力
	group_power_ev.AddGroupPowerLeaveAsync(func(model *domain.Model, e interface{}) error {
		event, ok := e.(*group_power_ev.GroupPowerLeaveEvent)
		if !ok {
			model.Log.Errorf("AddGroupPowerLeaveAsync event type err")
			return nil
		}
		model.Log.Infof("msg AddGroupPowerLeaveAsync UserId:%v, GroupPowerId:%v", event.UserId, event.GroupPowerId)
		//获取势力主
		mgrUserId, err := groupPower_m.GetGroupPowerMgr(model, event.GroupPowerId)
		if err != nil {
			return err
		}
		mgrUser, err := user_m.GetUser(model, mgrUserId)
		if err != nil {
			return err
		}
		joinUser, err := user_m.GetUser(model, event.UserId)
		if err != nil {
			return err
		}
		if err := msg_m.NewUserRecord(model, mgrUser.ID, msg_e.GroupPowerUserLeave, joinUser.Nick, joinUser.ID, "", "", "", "", "").Persistent(); err != nil {
			model.Log.Errorf("msg AddGroupPowerLeaveAsync NewUserRecord err:%v", err)
			return nil
		}
		msg_m.SendEmasMsgAssistant(model, mgrUser.ExternalId, mgrUser.DeviceType)
		return nil
	})
}