...
|
...
|
@@ -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"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -100,6 +101,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
}
|
|
|
|
|
|
// 新增相关人
|
|
|
var relevantPeopleModel []*models.CooperationContractRelevant
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
...
|
...
|
@@ -115,14 +117,18 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
UserType: relevant.UserType,
|
|
|
Status: relevant.Status,
|
|
|
Company: relevant.Company,
|
|
|
UpdatedAt: time.Now(),
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if len(relevantPeopleModel) > 0 {
|
|
|
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
|
|
if result, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
} else {
|
|
|
log.Logger.Info("新增的相关人", map[string]interface{}{
|
|
|
"relevantPeopleModel": result,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -159,6 +165,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 +190,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 +286,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 +342,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 +397,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 +423,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 +442,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 +496,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 +521,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 +540,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 +592,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 +617,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,12 +636,23 @@ 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
|
|
|
// 返回新增的合约
|
|
|
cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
|
|
|
"cooperationContractId":cooperationContract.CooperationContractId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return cooperationContractSaved, nil
|
|
|
}
|
|
|
|
|
|
func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
|
...
|
...
|
@@ -693,7 +744,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 +754,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 +781,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 +793,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 +805,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 +817,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
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|