diamond.go 3.12 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10
package diamond_s

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
	"git.hilo.cn/hilo-common/resource/mysql"
	"hilo-group/common"
	"hilo-group/domain/model/diamond_m"
	"hilo-group/domain/model/groupPower_m"
	"hilo-group/domain/model/res_m"
chenweijian's avatar
chenweijian committed
11
	"hilo-group/domain/model/user_m"
hujiebin's avatar
hujiebin committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
	"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)
chenweijian's avatar
chenweijian committed
28 29 30 31 32 33 34 35 36 37 38 39 40

	//获取国家信息
	_, dealerArea, err := user_m.GetUserCountryArea(model, dealerId)
	if err != nil {
		model.Log.Errorf("CheckDealerTransferFamilyLimit 获取国家资源错误 dealerId:%d, err:%v", dealerId, err)
		return err
	}
	_, area, err := user_m.GetUserCountryArea(model, userId)
	if err != nil {
		model.Log.Errorf("CheckDealerTransferFamilyLimit 获取国家资源错误 userId:%d, err:%v", userId, err)
		return err
	}
	if dealerArea != area {
chenweijian's avatar
chenweijian committed
41
		return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_CHARGE_NO_AREA, lang, bizerr.DealerCannotSaleToOtherArea))
chenweijian's avatar
chenweijian committed
42 43
	}

hujiebin's avatar
hujiebin committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	// 代理、用户是否加入了家族
	dealerFamily, err := groupPower_m.GetGroupPowerUserOrNil(model, dealerId)
	if err != nil {
		return err
	}
	// 代理是否是家族代理
	isFamilyAgent, err := diamond_m.IsFamilyDiamondDealer(mysql.Db, dealerId)
	if err != nil {
		return err
	}

	userFamily, err := groupPower_m.GetGroupPowerUserOrNil(model, userId)
	if err != nil {
		return err
	}
	// 用户的家族是否有家族代理
chenweijian's avatar
chenweijian committed
60 61 62 63 64 65 66
	//var userHasFamilyAgent bool
	//if userFamily != nil {
	//	userHasFamilyAgent, err = groupPower_m.IsGroupPowerHasFamilyAgent(model, userFamily.GroupPowerId)
	//	if err != nil {
	//		return err
	//	}
	//}
hujiebin's avatar
hujiebin committed
67 68 69 70
	if dealerFamily != nil && dealerFamily.GroupPowerId > 0 { // 代理加入了家族
		if isFamilyAgent && (userFamily == nil || userFamily.GroupPowerId != dealerFamily.GroupPowerId) { // 是家族代理:只能向本家族成员转移钻石,如果向非家族成员转移钻石,则提示“非家族成员”
			return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_NOT_FAMILY_MEMBER, lang, bizerr.GroupPowerDealerNotMember))
		}
chenweijian's avatar
chenweijian committed
71 72 73
		//if !isFamilyAgent && userHasFamilyAgent { // 不是家族代理:如果用户加入了家族,且家族中有家族代理,那么也不能,“此用户已有家族代理,不能出售钻石”
		//	return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
		//}
hujiebin's avatar
hujiebin committed
74 75
	} else { // 代理没有加入家族的
		// 普通代理:不能向已经加入家族的成员(并且家族有家族代理)转移钻石,如果转移则提示“此用户已有家族代理,不能出售钻石”
chenweijian's avatar
chenweijian committed
76 77 78
		//if userHasFamilyAgent {
		//	return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
		//}
hujiebin's avatar
hujiebin committed
79 80 81
	}
	return nil
}