group_power.go 18.3 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package group_power_s

import (
chenweijian's avatar
chenweijian committed
4 5
	"encoding/json"
	"git.hilo.cn/hilo-common/_const/enum/diamond_e"
hujiebin's avatar
hujiebin committed
6 7 8
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
9 10 11 12 13 14 15
	"git.hilo.cn/hilo-common/txop/award_tx"
	"git.hilo.cn/hilo-common/utils"
	"github.com/jinzhu/now"
	"hilo-group/_const/enum/groupPower_e"
	"hilo-group/_const/enum/msg_e"
	"hilo-group/cv/group_power_cv"
	"hilo-group/cv/user_cv"
hujiebin's avatar
hujiebin committed
16
	"hilo-group/domain/cache/groupPower_c"
chenweijian's avatar
chenweijian committed
17
	"hilo-group/domain/cache/user_c"
hujiebin's avatar
hujiebin committed
18 19
	"hilo-group/domain/event/group_power_ev"
	"hilo-group/domain/model/groupPower_m"
chenweijian's avatar
chenweijian committed
20
	"hilo-group/domain/model/msg_m"
chenweijian's avatar
chenweijian committed
21
	"hilo-group/domain/model/noble_m"
chenweijian's avatar
chenweijian committed
22
	"hilo-group/domain/model/user_m"
chenweijian's avatar
chenweijian committed
23
	"hilo-group/myerr/bizerr"
chenweijian's avatar
chenweijian committed
24
	"time"
hujiebin's avatar
hujiebin committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38
)

type GroupPowerService struct {
	svc *domain.Service
}

func NewGroupPowerService(myContext *mycontext.MyContext) *GroupPowerService {
	svc := domain.CreateService(myContext)
	return &GroupPowerService{svc}
}

//用户加入国家势力
func (s *GroupPowerService) GroupPowerUserJoin(groupPowerId mysql.ID, userId mysql.ID) error {
	return s.svc.Transactional(func() error {
39
		model := domain.CreateModel(s.svc.CtxAndDb)
hujiebin's avatar
hujiebin committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
		groupPower, err := groupPower_m.GetGroupPower(model, groupPowerId)
		if err != nil {
			return err
		}
		groupPowerUser, err := groupPower.UserJoin(userId)
		if err != nil {
			return err
		}
		if err := groupPowerUser.Persistent(); err != nil {
			return err
		}
		return group_power_ev.PublishGroupPowerJoin(model, &group_power_ev.GroupPowerJoinEvent{
			UserId:       userId,
			GroupPowerId: groupPowerId,
		})
	})
}

//用户退出国家势力
func (s *GroupPowerService) GroupPowerUserLeave(groupPowerId mysql.ID, userId mysql.ID) (int, error) {
	remainSeconds := 0
	err := s.svc.Transactional(func() error {
62
		model := domain.CreateModel(s.svc.CtxAndDb)
hujiebin's avatar
hujiebin committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
		groupPower, err := groupPower_m.GetGroupPower(model, groupPowerId)
		if err != nil {
			return err
		}
		groupPowerUser, timeDiff, err := groupPower.UserLeave(userId)
		if err != nil {
			if timeDiff > 0 {
				remainSeconds = int(timeDiff.Seconds())
				return err
			}
			return err
		}
		if err := groupPowerUser.Persistent(); err != nil {
			return err
		}
		return group_power_ev.PublishGroupPowerLeave(model, &group_power_ev.GroupPowerLeaveEvent{
			UserId:       userId,
			GroupPowerId: groupPowerId,
		})
	})
	return remainSeconds, err
}
chenweijian's avatar
chenweijian committed
85

86 87 88
func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userId uint64, gpStatus groupPower_e.GroupPowerStatus,
	area int) (response group_power_cv.CvGroupPowerRank, err error) {
	rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 30, gpStatus, area)
chenweijian's avatar
chenweijian committed
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 147 148 149 150 151 152 153 154 155 156 157
	if err != nil {
		return
	}
	var ids []mysql.ID
	for _, g := range rank {
		ids = append(ids, g.GroupPowerId)
	}
	var myGroupPower *groupPower_m.GroupPowerUser
	if userId > 0 {
		myGroupPower, err = groupPower_m.GetGroupPowerUserOrNil(model, userId)
		if err != nil {
			return
		}
	}
	if myGroupPower != nil {
		ids = append(ids, myGroupPower.GroupPowerId)
	}
	grades, err := groupPower_m.MGetGroupPowerGrade(model, ids)
	if err != nil {
		return
	}
	groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids)
	if err != nil {
		return
	}
	if myGroupPower != nil {
		myGroupPowerRank, err := groupPower_m.GetMyGroupPowerExpRank(model, beginDate, endDate, myGroupPower.GroupPowerId)
		if err != nil {
			return response, err
		}
		response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{
			CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
				Id:        myGroupPower.GroupPowerId,
				Icon:      groupPowers[myGroupPower.GroupPowerId].Icon,
				Name:      groupPowers[myGroupPower.GroupPowerId].Name,
				Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate,
			},
			CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
				Grade: grades[myGroupPower.GroupPowerId].Grade,
				Exp:   myGroupPowerRank.Exp,
			},
			Rank: 0,
		}
	}
	for _, v := range rank {
		if response.MyGroupPower != nil && v.GroupPowerId == response.MyGroupPower.Id {
			response.MyGroupPower.Rank = v.Rank
		}
		response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{
			CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
				Id:        v.GroupPowerId,
				Icon:      groupPowers[v.GroupPowerId].Icon,
				Name:      groupPowers[v.GroupPowerId].Name,
				Nameplate: groupPowers[v.GroupPowerId].Nameplate,
			},
			CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
				Grade: grades[v.GroupPowerId].Grade,
				Exp:   v.Exp,
			},
			Rank: v.Rank,
		})
	}
	if response.MyGroupPower != nil && response.MyGroupPower.Rank == 0 {
		response.MyGroupPower.Rank = 31 // 客户端统一显示30+
	}
	return response, nil
}

func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*group_power_cv.CvGroupPowerStarData, error) {
hujiebin's avatar
hujiebin committed
158 159 160 161 162 163
	monthTime, err := time.Parse("200601", month)
	if err != nil {
		return nil, err
	}
	//rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month)
	rank, err := groupPower_c.GetGroupPowerStarRankPeriod(model, "month", groupPowerId, _type, offset, limit, monthTime.Format("2006-01-02"))
chenweijian's avatar
chenweijian committed
164 165 166 167 168 169 170 171 172
	if err != nil {
		return nil, err
	}
	//var response []group_power_cv.CvGroupPowerStarData
	response := make([]*group_power_cv.CvGroupPowerStarData, 0)
	var userIds []mysql.ID
	for _, row := range rank {
		userIds = append(userIds, row.UserId)
	}
chenweijian's avatar
chenweijian committed
173 174
	users, err := user_c.GetUserTinyMap(model, userIds, true)
	//users, err := user_m.GetUserMapByIds(model, userIds)
chenweijian's avatar
chenweijian committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
	for _, row := range rank {
		user := users[row.UserId]
		score := row.Score
		if _type == groupPower_e.GroupPowerStarTypeActive {
			score = score / 60
		}
		if score <= 0 {
			continue
		}
		response = append(response, &group_power_cv.CvGroupPowerStarData{
			User: user_cv.CvUserTiny{
				Id:         user.ID,
				ExternalId: user.ExternalId,
				Code:       user.Code,
				Nick:       user.Nick,
				Avatar:     user.Avatar,
			},
			Score: score,
		})
	}
	return response, nil
}

func CalcGroupPowerMonthRankAct(model *domain.Model) error {
	lastDayTime := time.Now().AddDate(0, 0, -1)
	_now := now.New(lastDayTime)
	calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT)
chenweijian's avatar
chenweijian committed
202 203 204 205 206 207 208 209 210 211
	starDate := _now.BeginningOfMonth().Format(utils.COMPACT_MONTH_FORMAT)
	beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02")
	return DoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate, starDate)
}

func BufaCalcGroupPowerMonthRankAct(model *domain.Model) error {
	lastDayTime := time.Now().AddDate(0, 0, -1)
	_now := now.New(lastDayTime)
	calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT)
	starDate := _now.BeginningOfMonth().Format(utils.COMPACT_MONTH_FORMAT)
chenweijian's avatar
chenweijian committed
212
	beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02")
chenweijian's avatar
chenweijian committed
213
	return BufaDoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate, starDate)
chenweijian's avatar
chenweijian committed
214 215
}

chenweijian's avatar
chenweijian committed
216
func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate, starDate string) error {
217 218 219 220
	areaList := []int{1, 2}
	for _, area := range areaList { // 计算获奖
		model := domain.CreateModelContext(model.MyContext)
		response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0, groupPower_e.GroupPowerUserHas, area)
chenweijian's avatar
chenweijian committed
221 222 223
		if err != nil {
			return err
		}
224 225 226
		powerIds := make([]uint64, 0, len(response.Items))
		for i, v := range response.Items {
			powerIds = append(powerIds, v.Id)
chenweijian's avatar
chenweijian committed
227
			response.Items[i].StarList, err = GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, starDate)
228 229 230 231 232 233
			if err != nil {
				return err
			}
		}
		// 奖励、日志
		awardList, logList, err := getAwardAndLogList(model, powerIds, response.Items, calcMonth, area)
chenweijian's avatar
chenweijian committed
234 235 236
		if err != nil {
			return err
		}
237 238 239 240

		err = model.Transaction(func(model *domain.Model) error {
			// log
			err = groupPower_m.CreateActFamilyMonthRankLog(model, logList)
chenweijian's avatar
chenweijian committed
241
			if err != nil {
242
				model.Log.Errorf("CalcGroupPowerMonthRankAct area:%d, err:%+v", area, err)
chenweijian's avatar
chenweijian committed
243 244
				return err
			}
245 246 247 248 249 250 251 252 253 254 255 256 257
			// award
			for _, v := range awardList {
				err = award_tx.SendUserAward(model, v, diamond_e.GeneralActivity, msg_e.MgrSendDiamondProperty)
				if err != nil {
					model.Log.Errorf("CalcGroupPowerMonthRankAct award:%+v, err:%+v", v, err)
					return err
				}
			}
			return nil
		})
		if err != nil {
			model.Log.Errorf("CalcGroupPowerMonthRankAct area:%d, err:%+v", area, err)
			return err
chenweijian's avatar
chenweijian committed
258
		}
259 260
	}
	return nil
chenweijian's avatar
chenweijian committed
261 262
}

chenweijian's avatar
chenweijian committed
263
func BufaDoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate, starDate string) error {
chenweijian's avatar
chenweijian committed
264
	areaList := []int{2}
chenweijian's avatar
chenweijian committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
	for _, area := range areaList { // 计算获奖
		model := domain.CreateModelContext(model.MyContext)
		response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0, groupPower_e.GroupPowerUserHas, area)
		if err != nil {
			return err
		}
		powerIds := make([]uint64, 0, len(response.Items))
		for i, v := range response.Items {
			powerIds = append(powerIds, v.Id)
			response.Items[i].StarList, err = GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, starDate)
			if err != nil {
				return err
			}
		}
		// 奖励、日志
		awardList, logList, err := bufaGetAwardAndLogList(model, powerIds, response.Items, calcMonth, area)
chenweijian's avatar
chenweijian committed
281
		//_, _, err = bufaGetAwardAndLogList(model, powerIds, response.Items, calcMonth, area)
chenweijian's avatar
chenweijian committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
		if err != nil {
			return err
		}

		err = model.Transaction(func(model *domain.Model) error {
			// log
			err = groupPower_m.CreateActFamilyMonthRankLog(model, logList)
			if err != nil {
				model.Log.Errorf("CalcGroupPowerMonthRankAct area:%d, err:%+v", area, err)
				return err
			}
			// award
			for _, v := range awardList {
				err = award_tx.SendUserAward(model, v, diamond_e.GeneralActivity, msg_e.MgrSendDiamondProperty)
				if err != nil {
					model.Log.Errorf("CalcGroupPowerMonthRankAct award:%+v, err:%+v", v, err)
					return err
				}
			}
			return nil
		})
		if err != nil {
			model.Log.Errorf("CalcGroupPowerMonthRankAct area:%d, err:%+v", area, err)
			return err
		}
	}
	return nil
}

311
func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_power_cv.CvGroupPowerRankData, calcMonth string, area int) ([]*award_tx.UserAward, []*groupPower_m.ActFamilyMonthRankLog, error) {
chenweijian's avatar
chenweijian committed
312 313
	// 读奖励配置
	confMap := CalcGroupPowerMonthRankActConf()
chenweijian's avatar
chenweijian committed
314
	awardList := make([]*award_tx.UserAward, 0, 120) // 奖励
chenweijian's avatar
chenweijian committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
	ownerMap, err := groupPower_m.GetPowerOwnerMap(model, powerIds)
	if err != nil {
		return nil, nil, err
	}
	// log list
	logList := make([]*groupPower_m.ActFamilyMonthRankLog, 0, 50)
	for _, v := range items {
		teamRank := 0
		if v.Rank >= 1 && v.Rank <= 3 {
			teamRank = v.Rank
		} else if v.Rank >= 4 && v.Rank <= 10 {
			teamRank = 4
		} else {
			break
		}
		ownerId, ok := ownerMap[v.Id]
		if !ok || ownerId <= 0 {
			model.Log.Errorf("CalcGroupPowerMonthRankAct 获取势力主错误 familyId:%d", v.Id)
			return nil, nil, bizerr.InvalidParameter
		}
		uRankConfMap, tCOk := confMap[teamRank]
		if !tCOk {
			break
		}
		// 家族长奖励
		oAward, aOk := uRankConfMap[0]
		if !aOk {
			model.Log.Errorf("CalcGroupPowerMonthRankAct 配置错误:%v", confMap)
			return nil, nil, bizerr.InvalidParameter
		}
		oAwardJ, _ := json.Marshal(oAward)
		logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
			Period:     calcMonth,
			FamilyId:   v.Id,
			RankFamily: v.Rank,
			RankUser:   0,
			UserId:     ownerId,
			Award:      string(oAwardJ),
353
			Area:       area,
chenweijian's avatar
chenweijian committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
		})
		awardList = append(awardList, &award_tx.UserAward{
			UserId:            ownerId,
			MedalId:           oAward.MedalId,
			MedalDuration:     oAward.MedalDay,
			Diamond:           oAward.Diamond,
			NobleLevel:        oAward.Noble,
			NobleDuration:     oAward.NobleDay,
			HeaddressId:       oAward.HeaddressId,
			HeaddressDuration: oAward.HeaddressDay})
		// 家族成员奖励
		for i, m := range v.StarList {
			uRank := i + 1
			confIdx := 9
			if uRank >= 1 && uRank <= 3 {
				confIdx = 1
			} else if uRank >= 4 && uRank <= 10 {
				confIdx = 4
			}
			mAward, aOk := uRankConfMap[confIdx]
			if !aOk {
				break
			}
			mAwardJ, _ := json.Marshal(mAward)
			logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
				Period:     calcMonth,
				FamilyId:   v.Id,
				RankFamily: v.Rank,
				RankUser:   uRank,
				UserId:     m.User.Id,
				Award:      string(mAwardJ),
385
				Area:       area,
chenweijian's avatar
chenweijian committed
386 387 388 389 390 391 392 393 394 395
			})
			awardList = append(awardList, &award_tx.UserAward{
				UserId:            m.User.Id,
				MedalId:           mAward.MedalId,
				MedalDuration:     mAward.MedalDay,
				Diamond:           mAward.Diamond,
				NobleLevel:        mAward.Noble,
				NobleDuration:     mAward.NobleDay,
				HeaddressId:       mAward.HeaddressId,
				HeaddressDuration: mAward.HeaddressDay})
chenweijian's avatar
chenweijian committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
		}
	}
	return awardList, logList, nil
}

func bufaGetAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_power_cv.CvGroupPowerRankData, calcMonth string, area int) ([]*award_tx.UserAward, []*groupPower_m.ActFamilyMonthRankLog, error) {
	// 读奖励配置
	confMap := CalcGroupPowerMonthRankActConf()
	awardList := make([]*award_tx.UserAward, 0, 120) // 奖励
	ownerMap, err := groupPower_m.GetPowerOwnerMap(model, powerIds)
	if err != nil {
		return nil, nil, err
	}
	// log list
	logList := make([]*groupPower_m.ActFamilyMonthRankLog, 0, 50)
	for _, v := range items {
		teamRank := 0
		if v.Rank >= 1 && v.Rank <= 3 {
			teamRank = v.Rank
		} else if v.Rank >= 4 && v.Rank <= 10 {
			teamRank = 4
		} else {
			break
		}
		ownerId, ok := ownerMap[v.Id]
		if !ok || ownerId <= 0 {
			model.Log.Errorf("CalcGroupPowerMonthRankAct 获取势力主错误 familyId:%d", v.Id)
			return nil, nil, bizerr.InvalidParameter
		}
		uRankConfMap, tCOk := confMap[teamRank]
		if !tCOk {
			break
		}
		//// 家族长奖励
		//oAward, aOk := uRankConfMap[0]
		//if !aOk {
		//	model.Log.Errorf("CalcGroupPowerMonthRankAct 配置错误:%v", confMap)
		//	return nil, nil, bizerr.InvalidParameter
		//}
		//oAwardJ, _ := json.Marshal(oAward)
		//logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
		//	Period:     calcMonth,
		//	FamilyId:   v.Id,
		//	RankFamily: v.Rank,
		//	RankUser:   0,
		//	UserId:     ownerId,
		//	Award:      string(oAwardJ),
		//	Area:       area,
		//})
		//awardList = append(awardList, &award_tx.UserAward{
		//	UserId:            ownerId,
		//	MedalId:           oAward.MedalId,
		//	MedalDuration:     oAward.MedalDay,
		//	Diamond:           oAward.Diamond,
		//	NobleLevel:        oAward.Noble,
		//	NobleDuration:     oAward.NobleDay,
		//	HeaddressId:       oAward.HeaddressId,
		//	HeaddressDuration: oAward.HeaddressDay})
		// 家族成员奖励
		for i, m := range v.StarList {
			uRank := i + 1
			confIdx := 9
			if uRank >= 1 && uRank <= 3 {
				confIdx = 1
			} else if uRank >= 4 && uRank <= 10 {
				confIdx = 4
			}
chenweijian's avatar
chenweijian committed
463 464 465
			if v.Id == 2481 && uRank == 1 {
				continue
			}
chenweijian's avatar
chenweijian committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
			mAward, aOk := uRankConfMap[confIdx]
			if !aOk {
				break
			}
			mAwardJ, _ := json.Marshal(mAward)
			logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
				Period:     calcMonth,
				FamilyId:   v.Id,
				RankFamily: v.Rank,
				RankUser:   uRank,
				UserId:     m.User.Id,
				Award:      string(mAwardJ),
				Area:       area,
			})
			awardList = append(awardList, &award_tx.UserAward{
				UserId:            m.User.Id,
				MedalId:           mAward.MedalId,
				MedalDuration:     mAward.MedalDay,
				Diamond:           mAward.Diamond,
				NobleLevel:        mAward.Noble,
				NobleDuration:     mAward.NobleDay,
				HeaddressId:       mAward.HeaddressId,
				HeaddressDuration: mAward.HeaddressDay})
chenweijian's avatar
chenweijian committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
		}
	}
	return awardList, logList, nil
}

// 奖励配置
type awardConf struct {
	MedalId      uint64
	MedalDay     uint32
	Diamond      uint32
	Noble        uint32
	NobleDay     uint32
	HeaddressId  uint64
	HeaddressDay int
}

func CalcGroupPowerMonthRankActConf() map[int]map[int]*awardConf {
	return map[int]map[int]*awardConf{
		1: {
			0: {MedalId: 5211, MedalDay: 30, Diamond: 320000, Noble: 5, NobleDay: 15},
			1: {MedalId: 5251, MedalDay: 30, Diamond: 120000, Noble: 5, NobleDay: 7, HeaddressId: 2121, HeaddressDay: 30},
			4: {HeaddressId: 2121, HeaddressDay: 30},
		},
		2: {
chenweijian's avatar
chenweijian committed
513 514
			0: {MedalId: 5221, MedalDay: 30, Diamond: 220000, Noble: 5, NobleDay: 15},
			1: {MedalId: 5261, MedalDay: 30, Diamond: 100000, Noble: 5, NobleDay: 7, HeaddressId: 2131, HeaddressDay: 30},
chenweijian's avatar
chenweijian committed
515 516 517 518 519 520 521 522 523 524 525 526 527
			4: {HeaddressId: 2131, HeaddressDay: 30},
		},
		3: {
			0: {MedalId: 5231, MedalDay: 30, Diamond: 120000, Noble: 5, NobleDay: 5},
			1: {MedalId: 5271, MedalDay: 30, Diamond: 70000, HeaddressId: 2141, HeaddressDay: 30},
			4: {HeaddressId: 2141, HeaddressDay: 30},
		},
		4: {
			0: {MedalId: 5241, MedalDay: 30},
			1: {MedalId: 5281, MedalDay: 30, HeaddressId: 2151, HeaddressDay: 30},
		},
	}
}
chenweijian's avatar
chenweijian committed
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

func GetGroupPowerMaxMemberNum(model *domain.Model, familyId uint64, groupPowerGrade groupPower_e.GroupPowerGrade) (maxNum int) {
	maxNum = group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade][0].Num
	ownerId, err := groupPower_m.GetPowerOwner(model.Db, familyId)
	if err == nil {
		//检查是否是贵族
		if flag, err := noble_m.CheckNobleLevel(model.Db, ownerId, 6); err != nil {
		} else if flag {
			newNumMap := map[groupPower_e.GroupPowerGrade]int{
				groupPower_e.GroupPowerGrade0: 400,
				groupPower_e.GroupPowerGrade1: 600,
				groupPower_e.GroupPowerGrade2: 1000,
				groupPower_e.GroupPowerGrade3: 1400}
			if newNum, ok := newNumMap[groupPowerGrade]; ok {
				maxNum = newNum
			}
		}
	}
	users, err := groupPower_m.GetGroupPowerUser(model, familyId)
	if err != nil {
		return
	}
	memberNum := len(users)
	if memberNum > maxNum {
		maxNum = memberNum
	}
	return
}

// 检查需不需要通知用户拉取家族小助手消息
func CheckoutSendMsgToMgr(myContext *mycontext.MyContext, groupPowerId uint64) {
	defer utils.CheckGoPanic()
	model := domain.CreateModelContext(myContext)
	//// 申请人数
	//cnt, err := groupPower_m.CountGroupPowerApply(model, groupPowerId, 0)
	//if err != nil {
	//	model.Log.Errorf("CheckoutSendMsgToMgr err:%v, id:%v", err, groupPowerId)
	//	return
	//}
	//if cnt <= 0 {
	//	return
	//}
	// 找到家族管理员们
	mgrList, err := groupPower_m.GetGroupPowerMgrList(model, groupPowerId)
	if err != nil {
		model.Log.Errorf("CheckoutSendMsgToMgr err:%v, id:%v", err, groupPowerId)
		return
	}
	userMap, err := user_m.GetUserMapByIds(model, mgrList)
	if err != nil {
		model.Log.Errorf("CheckoutSendMsgToMgr err:%v, id:%v", err, groupPowerId)
		return
	}
	for _, v := range mgrList {
		if user, ok := userMap[v]; ok {
			msg_m.SendEmasMsgAssistant(model, user.ExternalId, user.DeviceType)
		}
	}
}