...
|
...
|
@@ -10,6 +10,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -159,6 +160,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
|
|
|
for _, rule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
|
|
|
DividendsIncentivesRuleId: 0,
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
...
|
...
|
@@ -183,6 +185,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
|
|
|
MoneyIncentivesRuleId: 0,
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
|
|
|
MoneyIncentivesStage: rule.MoneyIncentivesStage,
|
...
|
...
|
@@ -278,6 +281,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
|
|
|
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
|
|
|
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
|
|
|
CooperationContractRelevantId: 0,
|
|
|
CooperationContractNumber: relevantDomain.CooperationContractNumber,
|
|
|
UserId: relevantDomain.UserId,
|
|
|
UserBaseId: relevantDomain.UserBaseId,
|
...
|
...
|
@@ -333,9 +337,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Info("待删除的相关人", map[string]interface{}{
|
|
|
"待删除的相关人": relevantModelsToDelete,
|
|
|
})
|
|
|
if len(relevantModelsToDelete) > 0 {
|
|
|
if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/************************* 更新承接人 ****************************/
|
|
|
// 获取承接人列表
|
...
|
...
|
@@ -383,6 +392,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
log.Logger.Info("待添加的承接人", map[string]interface{}{
|
|
|
"待添加的承接人": cooperationContractUndertakersToAddModels,
|
|
|
})
|
|
|
// 添加承接人
|
|
|
if len(cooperationContractUndertakersToAddModels) > 0 {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
|
...
|
...
|
@@ -406,6 +418,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Info("待更新的承接人", map[string]interface{}{
|
|
|
"待更新的承接人": undertakerModelsToUpdate,
|
|
|
})
|
|
|
if len(undertakerModelsToUpdate) > 0 {
|
|
|
if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -422,9 +437,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Info("待删除的承接人", map[string]interface{}{
|
|
|
"待删除的承接人": undertakerModelsToDelete,
|
|
|
})
|
|
|
if len(undertakerModelsToDelete) > 0 {
|
|
|
if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/************************ 更新分红激励规则 **************************/
|
|
|
// 获取分红激励规则列表
|
...
|
...
|
@@ -471,6 +491,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
})
|
|
|
}
|
|
|
// 添加分红激励规则
|
|
|
log.Logger.Info("待添加的分红激励规则", map[string]interface{}{
|
|
|
"dividendsIncentivesRulesToAddModels": dividendsIncentivesRulesToAddModels,
|
|
|
})
|
|
|
if len(dividendsIncentivesRulesToAddModels) > 0 {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRulesToAddModels).Insert(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -493,6 +516,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Info("待更新的分红激励规则", map[string]interface{}{
|
|
|
"dividendsRuleModelsToUpdate": dividendsRuleModelsToUpdate,
|
|
|
})
|
|
|
if len(dividendsRuleModelsToUpdate) > 0 {
|
|
|
if _, err := tx.Model(÷ndsRuleModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -509,9 +535,12 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).Delete(); err != nil {
|
|
|
log.Logger.Info("待删除的分红激励规则", map[string]interface{}{})
|
|
|
if len(dividendsIncentivesRuleModelsToDelete) > 0 {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/********************** 更新金额激励规则 **************************/
|
|
|
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
|
...
|
...
|
@@ -558,6 +587,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
})
|
|
|
}
|
|
|
// 添加金额激励规则
|
|
|
log.Logger.Info("待添加的金额激励规则", map[string]interface{}{
|
|
|
"moneyIncentivesRulesToAddModels": moneyIncentivesRulesToAddModels,
|
|
|
})
|
|
|
if len(moneyIncentivesRulesToAddModels) > 0 {
|
|
|
if _, err := tx.Model(&moneyIncentivesRulesToAddModels).Insert(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -580,6 +612,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.Logger.Info("待更新的金额激励规则", map[string]interface{}{
|
|
|
"moneyRuleModelsToUpdate": moneyRuleModelsToUpdate,
|
|
|
})
|
|
|
if len(moneyRuleModelsToUpdate) > 0 {
|
|
|
if _, err := tx.Model(&moneyRuleModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -596,10 +631,14 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).Delete(); err != nil {
|
|
|
log.Logger.Info("待删除的金额激励规则", map[string]interface{}{
|
|
|
"moneyIncentivesRuleModelsToDelete": moneyIncentivesRuleModelsToDelete,
|
|
|
})
|
|
|
if len(moneyIncentivesRuleModelsToDelete) > 0 {
|
|
|
if _, err := tx.Model(&moneyIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
}
|
...
|
...
|
@@ -693,7 +732,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -703,7 +742,7 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -730,42 +769,50 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if len(dividendsIncentivesRuleModels) > 0 {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取金额激励规则列表
|
|
|
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
|
|
|
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
|
|
|
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if len(moneyIncentivesRuleModels) > 0 {
|
|
|
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取承接人列表
|
|
|
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
|
|
|
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
|
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
|
|
|
if len(cooperationContractUndertakerModels) > 0 {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取相关人列表
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
|
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
|
|
|
if len(cooperationContractRelevantModels) > 0 {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return cooperationContracts, nil
|
|
|
}
|
|
|
|
...
|
...
|
|