diamond.go 2.48 KB
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4 5
package diamond_s

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
chenweijian's avatar
chenweijian committed
6
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
7
	"hilo-group/common"
chenweijian's avatar
chenweijian committed
8
	"hilo-group/domain/model/diamond_m"
chenweijian's avatar
chenweijian committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
	"hilo-group/domain/model/groupPower_m"
	"hilo-group/domain/model/res_m"
	"hilo-group/myerr"
	"hilo-group/myerr/bizerr"
)

type DiamondService struct {
	svc *domain.Service
}

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

// 币商转账钻石-家族限制检查
func (this *DiamondService) CheckDealerTransferFamilyLimit(dealerId, userId uint64, lang string) error {
	model := domain.CreateModelContext(this.svc.MyContext)
	// 代理、用户是否加入了家族
	dealerFamily, err := groupPower_m.GetGroupPowerUserOrNil(model, dealerId)
	if err != nil {
		return err
	}
chenweijian's avatar
chenweijian committed
32 33 34 35 36 37
	// 代理是否是家族代理
	isFamilyAgent, err := diamond_m.IsFamilyDiamondDealer(mysql.Db, dealerId)
	if err != nil {
		return err
	}

chenweijian's avatar
chenweijian committed
38 39 40 41
	userFamily, err := groupPower_m.GetGroupPowerUserOrNil(model, userId)
	if err != nil {
		return err
	}
chenweijian's avatar
chenweijian committed
42 43
	// 用户的家族是否有家族代理
	var userHasFamilyAgent bool
chenweijian's avatar
chenweijian committed
44
	if userFamily != nil {
chenweijian's avatar
chenweijian committed
45
		userHasFamilyAgent, err = groupPower_m.IsGroupPowerHasFamilyAgent(model, userFamily.GroupPowerId)
chenweijian's avatar
chenweijian committed
46 47 48 49
		if err != nil {
			return err
		}
	}
chenweijian's avatar
chenweijian committed
50 51
	if dealerFamily != nil && dealerFamily.GroupPowerId > 0 { // 代理加入了家族
		if isFamilyAgent && (userFamily == nil || userFamily.GroupPowerId != dealerFamily.GroupPowerId) { // 是家族代理:只能向本家族成员转移钻石,如果向非家族成员转移钻石,则提示“非家族成员”
chenweijian's avatar
chenweijian committed
52 53
			return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_NOT_FAMILY_MEMBER, lang, bizerr.GroupPowerDealerNotMember))
		}
chenweijian's avatar
chenweijian committed
54 55 56 57 58 59
		if !isFamilyAgent && userHasFamilyAgent { // 不是家族代理:如果用户加入了家族,且家族中有家族代理,那么也不能,“此用户已有家族代理,不能出售钻石”
			return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
		}
	} else { // 代理没有加入家族的
		// 普通代理:不能向已经加入家族的成员(并且家族有家族代理)转移钻石,如果转移则提示“此用户已有家族代理,不能出售钻石”
		if userHasFamilyAgent {
chenweijian's avatar
chenweijian committed
60 61 62 63 64
			return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
		}
	}
	return nil
}