...
|
...
|
@@ -330,7 +330,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont |
|
|
} else {
|
|
|
cooperationContractDao = value
|
|
|
}
|
|
|
//TODO 获取可删除的承接对象类型
|
|
|
// 获取可删除的承接对象类型
|
|
|
undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
|
|
|
"cooperationContractNumber": cooperationContract.CooperationContractNumber,
|
|
|
"cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes,
|
...
|
...
|
@@ -502,6 +502,38 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 公司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 {
|
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(updateCooperationContractCommand.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(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
@@ -517,6 +549,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
if cooperationContract == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
|
|
|
}
|
|
|
// 更新合约基础信息
|
|
|
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
// 用户REST服务初始化
|
|
|
var userService service.UserService
|
|
|
if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
|
...
|
...
|
@@ -549,9 +585,106 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC |
|
|
Company: relevantDomain.Company,
|
|
|
})
|
|
|
}
|
|
|
if err := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
// 更新合约相关人
|
|
|
cooperationContract.RelevantPeople = relevantPeople
|
|
|
|
|
|
//TODO 获取承接人
|
|
|
var undertakers []*domain.Undertaker
|
|
|
for _, undertaker := range updateCooperationContractCommand.Undertakers {
|
|
|
var undertakerDomain *domain.Undertaker
|
|
|
undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64)
|
|
|
if data, err := userService.UndertakerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, undertakerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
undertakerDomain = data
|
|
|
}
|
|
|
|
|
|
// 获取推荐人
|
|
|
var referrerDomain *domain.Referrer
|
|
|
referrerUid, _ := strconv.ParseInt(undertaker.ReferrerId, 10, 64)
|
|
|
if data, err := userService.ReferrerFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, referrerUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
referrerDomain = data
|
|
|
}
|
|
|
|
|
|
// 获取业务员
|
|
|
var salesmanDomain *domain.Salesman
|
|
|
salesmanUid, _ := strconv.ParseInt(undertaker.SalesmanId, 10, 64)
|
|
|
if data, err := userService.SalesmanFrom(updateCooperationContractCommand.CompanyId, updateCooperationContractCommand.OrgId, salesmanUid); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
salesmanDomain = data
|
|
|
}
|
|
|
|
|
|
undertakers = append(undertakers, &domain.Undertaker{
|
|
|
UndertakerId: undertaker.UndertakerId,
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
CooperationContractNumber: cooperationContract.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: undertakerDomain.Status,
|
|
|
Company: undertakerDomain.Company,
|
|
|
ContractAttachment: nil,
|
|
|
})
|
|
|
}
|
|
|
//TODO 更新承接人
|
|
|
cooperationContract.Undertakers = undertakers
|
|
|
|
|
|
//TODO 获取分红规则列表
|
|
|
var dividendsIncentivesRules []*domain.DividendsIncentivesRule
|
|
|
for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
|
|
|
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
|
|
|
DividendsIncentivesRuleId: dividendsIncentivesRuleId,
|
|
|
CooperationContractNumber: cooperationContract.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(),
|
|
|
})
|
|
|
}
|
|
|
//TODO 更新分红规则列表
|
|
|
cooperationContract.DividendsIncentivesRules = dividendsIncentivesRules
|
|
|
|
|
|
//TODO 获取金额激励规则列表
|
|
|
var moneyIncentivesRules []*domain.MoneyIncentivesRule
|
|
|
for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
|
|
|
moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
|
|
|
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
|
|
|
MoneyIncentivesRuleId: moneyIncentivesRuleId,
|
|
|
CooperationContractNumber: cooperationContract.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(),
|
|
|
})
|
|
|
}
|
|
|
//TODO 更新金额激励规则列表
|
|
|
cooperationContract.MoneyIncentivesRules = moneyIncentivesRules
|
|
|
|
|
|
if cooperationContract, err := cooperationContractRepository.Save(cooperationContract); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
|