...
|
...
|
@@ -8,7 +8,9 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// CooperationContractService 共创合约服务
|
...
|
...
|
@@ -31,90 +33,234 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC |
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
//userServiceGateway, err := factory.CreateUserServiceGateway(nil)
|
|
|
//if err != nil {
|
|
|
// fmt.Println(err.Error())
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//}
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
//userServiceGateway.GetUser(createCooperationContractCommand.SponsorUid)
|
|
|
// 获取操作人
|
|
|
var operator *domain.User
|
|
|
if data, err := userService.OperatorFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, createCooperationContractCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
operator = data
|
|
|
}
|
|
|
|
|
|
newCooperationContract := &domain.CooperationContract{
|
|
|
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
//CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber,
|
|
|
//DepartmentNumber: createCooperationContractCommand.DepartmentNumber,
|
|
|
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerType,
|
|
|
CooperationContractName: createCooperationContractCommand.CooperationContractName,
|
|
|
//CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber,
|
|
|
//SponsorUid: createCooperationContractCommand.SponsorUid,
|
|
|
//DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
|
|
|
//MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules,
|
|
|
//Undertakers: createCooperationContractCommand.Undertakers,
|
|
|
//RelevantPeople: createCooperationContractCommand.RelevantPeople,
|
|
|
//CompanyId: createCooperationContractCommand.CompanyId,
|
|
|
//OrgId: createCooperationContractCommand.OrgId,
|
|
|
//UserId: createCooperationContractCommand.UserId,
|
|
|
// 获取发起人
|
|
|
var sponsor *domain.User
|
|
|
sponsorUid, _ := strconv.ParseInt(createCooperationContractCommand.SponsorUid, 10, 64)
|
|
|
if data, err := userService.OperatorFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, sponsorUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
sponsor = data
|
|
|
}
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(createCooperationContractCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
//// 共创合约承接人仓储初始化
|
|
|
//var cooperationContractUndertakerRepository domain.CooperationContractUndertakerRepository
|
|
|
//if value, err := factory.CreateCooperationContractUndertakerRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// cooperationContractUndertakerRepository = value
|
|
|
//}
|
|
|
// 获取承接人
|
|
|
var undertakers []*domain.Undertaker
|
|
|
for _, undertaker := range createCooperationContractCommand.Undertakers {
|
|
|
var undertakerDomain *domain.Undertaker
|
|
|
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
|
|
|
if data, err := userService.UndertakerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, undertakerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
undertakerDomain = data
|
|
|
}
|
|
|
|
|
|
//// 共创合约相关人仓储初始化
|
|
|
//var cooperationContractRelevantRepository domain.CooperationContractRelevantRepository
|
|
|
//if value, err := factory.CreateCooperationContractRelevantRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// cooperationContractRelevantRepository = value
|
|
|
//}
|
|
|
// 获取推荐人
|
|
|
var referrerDomain *domain.Referrer
|
|
|
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
|
|
|
if data, err := userService.ReferrerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, referrerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
referrerDomain = data
|
|
|
}
|
|
|
|
|
|
//// 分红激励规则仓储初始化
|
|
|
//var dividendsIncentivesRuleRepository domain.DividendsIncentivesRuleRepository
|
|
|
//if value, err := factory.CreateDividendsIncentivesRuleRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// dividendsIncentivesRuleRepository = value
|
|
|
//}
|
|
|
// 获取业务员
|
|
|
var salesmanDomain *domain.Salesman
|
|
|
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
|
|
|
if data, err := userService.SalesmanFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, salesmanUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
salesmanDomain = data
|
|
|
}
|
|
|
|
|
|
//// 金额激励规则仓储初始化
|
|
|
//var moneyIncentivesRuleRepository domain.MoneyIncentivesRuleRepository
|
|
|
//if value, err := factory.CreateMoneyIncentivesRuleRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
//}); err != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
//} else {
|
|
|
// moneyIncentivesRuleRepository = value
|
|
|
//}
|
|
|
undertakers = append(undertakers, &domain.Undertaker{
|
|
|
UndertakerId: 0,
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
UserBaseId: undertakerDomain.UserBaseId,
|
|
|
Org: undertakerDomain.Org,
|
|
|
Orgs: undertakerDomain.Orgs,
|
|
|
Department: undertakerDomain.Department,
|
|
|
Roles: undertakerDomain.Roles,
|
|
|
UserInfo: undertakerDomain.UserInfo,
|
|
|
UserType: undertakerDomain.UserType,
|
|
|
Referrer: referrerDomain,
|
|
|
Salesman: salesmanDomain,
|
|
|
Status: 0,
|
|
|
Company: company,
|
|
|
ContractAttachment: nil,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 获取相关人
|
|
|
var relevantPeople []*domain.Relevant
|
|
|
for _, relevantPersonUid := range createCooperationContractCommand.RelevantPeople {
|
|
|
var relevantDomain *domain.Relevant
|
|
|
relevantUid, _ := strconv.ParseInt(relevantPersonUid, 10, 64)
|
|
|
if data, err := userService.RelevantFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, relevantUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
relevantDomain = data
|
|
|
}
|
|
|
relevantPeople = append(relevantPeople, &domain.Relevant{
|
|
|
RelevantId: 0,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
UserId: relevantDomain.UserId,
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
|
|
Org: relevantDomain.Org,
|
|
|
Orgs: relevantDomain.Orgs,
|
|
|
Department: relevantDomain.Department,
|
|
|
Roles: relevantDomain.Roles,
|
|
|
UserInfo: relevantDomain.UserInfo,
|
|
|
UserType: relevantDomain.UserType,
|
|
|
Status: relevantDomain.Status,
|
|
|
Company: relevantDomain.Company,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
|
|
|
DividendsIncentivesRuleId: 0,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
|
|
|
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
|
|
|
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
|
|
|
DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage),
|
|
|
DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
|
|
|
DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 获取金额激励规则
|
|
|
var moneyIncentivesRules []*domain.MoneyIncentivesRule
|
|
|
for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules {
|
|
|
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
|
|
|
MoneyIncentivesRuleId: 0,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
|
|
|
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
|
|
|
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
|
|
|
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
|
|
|
MoneyIncentivesTime: time.Now(),
|
|
|
ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
|
|
|
SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 查找共创模式
|
|
|
var cooperationModeRepository domain.CooperationModeRepository
|
|
|
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
//
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
cooperationModeRepository = value
|
|
|
}
|
|
|
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if cooperationMode == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationContractCommand.CooperationModeNumber))
|
|
|
} else {
|
|
|
newCooperationContract := &domain.CooperationContract{
|
|
|
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
|
|
|
CooperationContractName: createCooperationContractCommand.CooperationContractName,
|
|
|
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
|
|
|
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes,
|
|
|
CooperationContractSponsor: sponsor,
|
|
|
CooperationMode: cooperationMode,
|
|
|
Status: 1,
|
|
|
Org: organization,
|
|
|
Company: company,
|
|
|
Operator: operator,
|
|
|
DividendsIncentivesRules: dividendsIncentivesRules,
|
|
|
MoneyIncentivesRules: moneyIncentivesRules,
|
|
|
Undertakers: undertakers,
|
|
|
RelevantPeople: relevantPeople,
|
|
|
OperateTime: time.Now(),
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
|
|
|
// 共创合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
//
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|