...
|
...
|
@@ -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,20 +281,21 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
|
|
|
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
|
|
|
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
|
|
|
CooperationContractNumber: relevantDomain.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,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
CooperationContractRelevantId: 0,
|
|
|
CooperationContractNumber: relevantDomain.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,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
// 添加相关人
|
...
|
...
|
@@ -333,8 +337,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantModelsToDelete).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
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,8 +437,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(&undertakerModelsToDelete).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
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,8 +535,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
log.Logger.Info("待删除的分红激励规则", map[string]interface{}{})
|
|
|
if len(dividendsIncentivesRuleModelsToDelete) > 0 {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/********************** 更新金额激励规则 **************************/
|
...
|
...
|
@@ -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 {
|
|
|
return nil, err
|
|
|
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,8 +769,10 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
if len(dividendsIncentivesRuleModels) > 0 {
|
|
|
if _, err := tx.Model(÷ndsIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取金额激励规则列表
|
...
|
...
|
@@ -740,8 +781,10 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
if len(moneyIncentivesRuleModels) > 0 {
|
|
|
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取承接人列表
|
...
|
...
|
@@ -750,8 +793,10 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
if len(cooperationContractUndertakerModels) > 0 {
|
|
|
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 获取相关人列表
|
...
|
...
|
@@ -760,8 +805,10 @@ func (repository *CooperationContractRepository) BatchRemove(cooperationContract |
|
|
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).Delete(); err != nil {
|
|
|
return nil, err
|
|
|
if len(cooperationContractRelevantModels) > 0 {
|
|
|
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|