作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -15,7 +15,7 @@ type CreateDividendsIncentivesRulesCommand struct {
ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"`
SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"`
DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"`
DividendsIncentivesStage int `cname:"分红激励阶段" json:"dividendsIncentivesStage"`
DividendsIncentivesStage int32 `cname:"分红激励阶段" json:"dividendsIncentivesStage"`
DividendsIncentivesStageEnd time.Time `cname:"" json:"dividendsIncentivesStageEnd"`
DividendsIncentivesStageStart time.Time `cname:"" json:"dividendsIncentivesStageStart"`
}
... ... @@ -23,8 +23,8 @@ type CreateDividendsIncentivesRulesCommand struct {
type CreateMoneyIncentivesRulesCommand struct {
MoneyIncentivesRuleId string `cname:"" json:"moneyIncentivesRuleId,string"`
CooperationContractNumber string `cname:"" json:"cooperationContractNumber"`
MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"`
MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"`
MoneyIncentivesAmount float64 `cname:"" json:"moneyIncentivesAmount"`
MoneyIncentivesStage int32 `cname:"" json:"moneyIncentivesStage"`
MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`
MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"`
MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"`
... ... @@ -33,7 +33,7 @@ type CreateMoneyIncentivesRulesCommand struct {
}
type CreateUndertakersCommand struct {
UndertakerId int64 `cname:"承接人ID" json:"relevantId"`
UndertakerId string `cname:"承接人ID" json:"relevantId"`
UserId string `cname:"承接人UID" json:"userId"`
ContractAttachment []struct {
FileType string `cname:"文件类型" json:"fileType"`
... ...
... ... @@ -106,7 +106,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
// 生成共创合约编号
contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
// 校验共创合约编号是否唯一
numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
... ... @@ -209,7 +209,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage),
DividendsIncentivesStage: dividendsIncentivesRule.DividendsIncentivesStage,
DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
Org: organization,
... ... @@ -226,8 +226,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: 0,
CooperationContractNumber: contractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesAmount: moneyIncentivesRule.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
... ... @@ -780,8 +780,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
}
undertakerId, err3 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
}
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: undertaker.UndertakerId,
UndertakerId: undertakerId,
UserId: undertakerDomain.UserId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserBaseId: undertakerDomain.UserBaseId,
... ... @@ -804,14 +808,17 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取分红规则列表
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
dividendsIncentivesRuleId, err2 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
}
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage),
DividendsIncentivesStage: dividendsIncentivesRule.DividendsIncentivesStage,
DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
Org: organization,
... ... @@ -827,12 +834,15 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 获取金额激励规则列表
var moneyIncentivesRules []*domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
moneyIncentivesRuleId, err4 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
if err4 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
}
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesAmount: moneyIncentivesRule.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
... ...
... ... @@ -641,7 +641,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
}
// 共创合约预算
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, int64(confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage), undertakerUIDs); err2 != nil {
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
} else {
if err3 := transactionContext.CommitTransaction(); err3 != nil {
... ...
... ... @@ -17,7 +17,7 @@ type DividendsIncentivesRule struct {
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage"`
DividendsIncentivesStage int32 `json:"dividendsIncentivesStage"`
// 分红激励规则阶段中文表示
DividendsIncentivesStageCN string `json:"dividendsIncentivesStageCN"`
// 分红规则激励阶段结束
... ... @@ -69,7 +69,7 @@ func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]i
dividendsIncentivesRule.DividendsIncentivesPercentage = dividendsIncentivesPercentage.(float64)
}
if dividendsIncentivesStage, ok := data["dividendsIncentivesStage"]; ok {
dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int64)
dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int32)
}
if dividendsIncentivesStageEnd, ok := data["dividendsIncentivesStageEnd"]; ok {
dividendsIncentivesRule.DividendsIncentivesStageEnd = dividendsIncentivesStageEnd.(time.Time)
... ...
... ... @@ -13,7 +13,7 @@ type MoneyIncentivesRule struct {
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `json:"moneyIncentivesStage"`
MoneyIncentivesStage int32 `json:"moneyIncentivesStage"`
// 金额激励规则阶段中文表示
MoneyIncentivesStageCN string `json:"moneyIncentivesStageCN"`
// 金额激励阶段有效期结束
... ... @@ -65,7 +65,7 @@ func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface
moneyIncentivesRule.MoneyIncentivesAmount = moneyIncentivesAmount.(float64)
}
if moneyIncentivesStage, ok := data["moneyIncentivesStage"]; ok {
moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int64)
moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int32)
}
if moneyIncentivesStageEnd, ok := data["moneyIncentivesStageEnd"]; ok {
moneyIncentivesRule.MoneyIncentivesStageEnd = moneyIncentivesStageEnd.(time.Time)
... ...
... ... @@ -7,5 +7,5 @@ import (
type ConfirmMoneyIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*DividendsEstimateDetail, error)
Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*DividendsEstimateDetail, error)
}
... ...
... ... @@ -53,6 +53,28 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer
return !ok, err
}
// UserEstimated 判断金额激励用户是否已分红(已生成分红预算单)
func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if undertakerUid, ok := queryOptions["undertakerUid"]; ok && undertakerUid.(int64) != 0 {
query = query.Where(`dividends_estimate.dividends_user @> '{"userId":"?"}'`, undertakerUid)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
// 非取消的分红预算单
query.Where("dividends_estimate.is_canceled = ?", false)
// 过滤出金额激励
query.Where("dividends_estimate.dividends_type = ?", 3)
ok, err := query.Exists()
return ok, err
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -88,7 +88,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
})
// 添加推荐人分红预算信息详情
... ... @@ -109,7 +109,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
})
}
... ... @@ -131,7 +131,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
})
}
... ... @@ -175,7 +175,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
})
// 添加推荐人分红退货预算信息详情
... ... @@ -196,7 +196,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
})
}
... ... @@ -218,7 +218,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage),
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
})
}
... ...
... ... @@ -6,6 +6,7 @@ import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"time"
)
... ... @@ -14,9 +15,28 @@ type ConfirmMoneyIncentivesEstimateService struct {
transactionContext *pgTransaction.TransactionContext
}
func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
//var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储
var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO
// 分红预算单仓储初始化
//if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// dividendsEstimateRepository = repo
//}
// 分红预算DAO初始化
if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil {
return nil, err
} else {
dividendsEstimateDao = estimateDao
}
// 金额激励详情
var dividendsEstimateDetails []*service.DividendsEstimateDetail
// 获取金额激励规则
// 匹配金额激励规则
var moneyIncentivesRuleMatched *domain.MoneyIncentivesRule
for _, moneyIncentivesRule := range contract.MoneyIncentivesRules {
if moneyIncentivesRule.MoneyIncentivesStage == stage {
... ... @@ -24,12 +44,83 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
break
}
}
// 判断分红阶段时间
// 判断金额激励阶段是否合法
currentTime := time.Now()
if moneyIncentivesRuleMatched.MoneyIncentivesStageStart.After(currentTime) {
return nil, fmt.Errorf("还未到分红时间")
}
// TODO 判断承接人在当前阶段是否已经分红
// 金额激励预算
for _, undertaker := range contract.Undertakers {
// 判断承接人在当前阶段是否已经分红
undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
if err != nil {
return nil, err
}
if undertakerEstimated {
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
} else {
undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100)
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
UserName: undertaker.UserName,
UserPhone: undertaker.UserPhone,
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.MONEY_INCENTIVES,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
})
}
// 判断业务员在当前阶段是否已经分红
salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
"undertakerUid": undertaker.Salesman.UserId,
"companyId": contract.Company.CompanyId,
"orgId": contract.Org.OrgId,
})
if err != nil {
return nil, err
}
if salesmanEstimated {
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
} else {
undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100)
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
Orgs: undertaker.Orgs,
Department: undertaker.Department,
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
UserName: undertaker.UserName,
UserPhone: undertaker.UserPhone,
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.MONEY_INCENTIVES,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
})
}
// 判断关联业务员在当前阶段是否已经分红
}
return dividendsEstimateDetails, nil
}
... ...
... ... @@ -18,7 +18,7 @@ type DividendsIncentivesRule struct {
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `comment:"分红规则激励百分点"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"`
DividendsIncentivesStage int32 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"`
// 分红规则激励阶段开始
... ...
... ... @@ -14,7 +14,7 @@ type MoneyIncentivesRule struct {
// 激励金额
MoneyIncentivesAmount float64 `comment:"激励金额"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"`
MoneyIncentivesStage int32 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"`
// 金额激励阶段有效期结束
MoneyIncentivesStageEnd time.Time `comment:"金额激励阶段有效期结束"`
// 金额激励阶段有效期开始
... ...