...
|
...
|
@@ -64,8 +64,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
&cooperationContract.CooperationContractDescription,
|
|
|
&cooperationContract.CooperationContractName,
|
|
|
&cooperationContract.CooperationContractNumber,
|
|
|
&cooperationContract.CooperationContractReferrer,
|
|
|
&cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
|
|
&cooperationContract.CooperationContractSponsor,
|
|
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
...
|
...
|
@@ -83,8 +81,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.CooperationContractDescription,
|
|
|
cooperationContract.CooperationContractName,
|
|
|
cooperationContract.CooperationContractNumber,
|
|
|
cooperationContract.CooperationContractReferrer,
|
|
|
cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
|
|
cooperationContract.CooperationContractSponsor,
|
|
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
...
|
...
|
@@ -200,8 +196,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
&cooperationContract.CooperationContractDescription,
|
|
|
&cooperationContract.CooperationContractName,
|
|
|
&cooperationContract.CooperationContractNumber,
|
|
|
&cooperationContract.CooperationContractReferrer,
|
|
|
&cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
|
|
&cooperationContract.CooperationContractSponsor,
|
|
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
...
|
...
|
@@ -219,8 +213,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.CooperationContractDescription,
|
|
|
cooperationContract.CooperationContractName,
|
|
|
cooperationContract.CooperationContractNumber,
|
|
|
cooperationContract.CooperationContractReferrer,
|
|
|
cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
|
|
cooperationContract.CooperationContractSponsor,
|
|
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
...
|
...
|
@@ -237,8 +229,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
return cooperationContract, err
|
|
|
}
|
|
|
|
|
|
// 更新相关人
|
|
|
|
|
|
/******************************* 更新相关人 ****************************/
|
|
|
// 查找相关人列表
|
|
|
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
|
...
|
...
|
@@ -324,16 +315,93 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新承接人
|
|
|
|
|
|
/************************* 更新承接人 ****************************/
|
|
|
// 获取承接人列表
|
|
|
var cooperationContractUndertakersFetched []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersFetched)
|
|
|
var cooperationContractUndertakersModelsFetched []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersModelsFetched)
|
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新分红激励规则
|
|
|
// 提取承接人id
|
|
|
var cooperationContractUndertakersIdsFetched []int64
|
|
|
for _, cooperationContractUndertaker := range cooperationContractUndertakersModelsFetched {
|
|
|
cooperationContractUndertakersIdsFetched = append(cooperationContractUndertakersIdsFetched, cooperationContractUndertaker.CooperationContractUndertakerId)
|
|
|
}
|
|
|
|
|
|
// 待更新相关人
|
|
|
var cooperationContractUndertakersToUpdate []*domain.Undertaker
|
|
|
|
|
|
// 待添加相关人
|
|
|
var cooperationContractUndertakersToAdd []*domain.Undertaker
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
if undertaker.UndertakerId != 0 {
|
|
|
cooperationContractUndertakersToUpdate = append(cooperationContractUndertakersToUpdate, undertaker)
|
|
|
} else {
|
|
|
cooperationContractUndertakersToAdd = append(cooperationContractUndertakersToAdd, undertaker)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 将待添加的相关人领域模型转换为数据模型
|
|
|
var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
|
|
|
for _, undertakerDomain := range cooperationContractUndertakersToAdd {
|
|
|
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
|
|
|
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
|
|
|
UserId: undertakerDomain.UserId,
|
|
|
UserBaseId: undertakerDomain.UserBaseId,
|
|
|
Org: undertakerDomain.Org,
|
|
|
Orgs: undertakerDomain.Orgs,
|
|
|
Department: undertakerDomain.Department,
|
|
|
Role: undertakerDomain.Role,
|
|
|
UserInfo: undertakerDomain.UserInfo,
|
|
|
UserType: undertakerDomain.UserType,
|
|
|
Status: undertakerDomain.Status,
|
|
|
Company: undertakerDomain.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
// 添加承接人
|
|
|
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 待更新或者删除的ids
|
|
|
var cooperationContractUndertakersToUpdateOrDeleteIds []int64
|
|
|
for _, cooperationContractUndertakerToUpdate := range cooperationContractUndertakersToUpdate {
|
|
|
cooperationContractUndertakersToUpdateOrDeleteIds = append(cooperationContractUndertakersToUpdateOrDeleteIds, cooperationContractUndertakerToUpdate.UndertakerId)
|
|
|
}
|
|
|
|
|
|
// 待更新的承接人id
|
|
|
undertakerIdsToUpdate := utils.Intersect(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
|
|
|
var undertakerModelsToUpdate []*models.CooperationContractUndertaker
|
|
|
for _, id := range undertakerIdsToUpdate {
|
|
|
for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
|
|
|
if undertakerModel.CooperationContractUndertakerId == id {
|
|
|
undertakerModelsToUpdate = append(undertakerModelsToUpdate, undertakerModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 待删除的相关人id
|
|
|
undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
|
|
|
var undertakerModelsToDelete []*models.CooperationContractUndertaker
|
|
|
for _, id := range undertakerIdsToDelete {
|
|
|
for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
|
|
|
if undertakerModel.CooperationContractUndertakerId == id {
|
|
|
undertakerModelsToDelete = append(undertakerModelsToDelete, undertakerModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO /************************ 更新分红激励规则 **************************/
|
|
|
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
|
...
|
...
|
@@ -342,7 +410,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
//TODO 更新金额激励规则
|
|
|
//TODO /********************** 更新金额激励规则 **************************/
|
|
|
|
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
|
...
|
...
|
|