...
|
...
|
@@ -3,6 +3,7 @@ package repository |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
...
|
...
|
@@ -34,7 +35,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
"cooperation_contract_salesman",
|
|
|
"cooperation_contract_undertaker_type",
|
|
|
"cooperation_contract_sponsor",
|
|
|
"cooperation_mode",
|
|
|
"cooperation_mode_number",
|
|
|
"status",
|
|
|
"org",
|
|
|
"company",
|
...
|
...
|
@@ -67,7 +68,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
&cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(&cooperationContract.CooperationContractUndertakerType),
|
|
|
&cooperationContract.CooperationContractSponsor,
|
|
|
&cooperationContract.CooperationMode,
|
|
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
|
|
&cooperationContract.Status,
|
|
|
&cooperationContract.Org,
|
|
|
&cooperationContract.Company,
|
...
|
...
|
@@ -86,7 +87,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(cooperationContract.CooperationContractUndertakerType),
|
|
|
cooperationContract.CooperationContractSponsor,
|
|
|
cooperationContract.CooperationMode,
|
|
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
|
|
cooperationContract.Status,
|
|
|
cooperationContract.Org,
|
|
|
cooperationContract.Company,
|
...
|
...
|
@@ -97,6 +98,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.UpdatedAt,
|
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
// 新增相关人
|
|
|
var relevantPeopleModel []*models.CooperationContractRelevant
|
|
|
for _, relevant := range cooperationContract.RelevantPeople {
|
|
|
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Relevant: relevant,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 新增承接人
|
|
|
var undertakersModel []*models.CooperationContractUndertaker
|
|
|
for _, undertaker := range cooperationContract.Undertakers {
|
|
|
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
Undertaker: undertaker,
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 新增分红激励规则
|
|
|
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
|
|
|
for _, rule := range cooperationContract.DividendsIncentivesRules {
|
|
|
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
|
|
|
DividendsIncentivesStage: rule.DividendsIncentivesStage,
|
|
|
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
|
|
|
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(÷ndsIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 新增金额激励规则
|
|
|
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
|
|
|
for _, rule := range cooperationContract.MoneyIncentivesRules {
|
|
|
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
|
|
|
CooperationContractNumber: cooperationContract.CooperationContractNumber,
|
|
|
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
|
|
|
MoneyIncentivesStage: rule.MoneyIncentivesStage,
|
|
|
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
|
|
|
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
|
|
|
MoneyIncentivesTime: rule.MoneyIncentivesTime,
|
|
|
ReferrerPercentage: rule.ReferrerPercentage,
|
|
|
SalesmanPercentage: rule.SalesmanPercentage,
|
|
|
Org: rule.Org,
|
|
|
Company: rule.Company,
|
|
|
UpdatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
CreatedAt: time.Now(),
|
|
|
})
|
|
|
}
|
|
|
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if _, err := tx.QueryOne(
|
...
|
...
|
@@ -109,7 +184,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
&cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(&cooperationContract.CooperationContractUndertakerType),
|
|
|
&cooperationContract.CooperationContractSponsor,
|
|
|
&cooperationContract.CooperationMode,
|
|
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
|
|
&cooperationContract.Status,
|
|
|
&cooperationContract.Org,
|
|
|
&cooperationContract.Company,
|
...
|
...
|
@@ -128,7 +203,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.CooperationContractSalesman,
|
|
|
pg.Array(cooperationContract.CooperationContractUndertakerType),
|
|
|
cooperationContract.CooperationContractSponsor,
|
|
|
cooperationContract.CooperationMode,
|
|
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
|
|
cooperationContract.Status,
|
|
|
cooperationContract.Org,
|
|
|
cooperationContract.Company,
|
...
|
...
|
@@ -140,6 +215,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
|
cooperationContract.Identify(),
|
|
|
); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
//TODO 更新相关人
|
|
|
//TODO 更新承接人
|
|
|
//TODO 更新分红激励规则
|
|
|
//TODO 更新金额激励规则
|
|
|
}
|
|
|
}
|
|
|
return cooperationContract, nil
|
...
|
...
|
@@ -150,6 +230,8 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom |
|
|
cooperationContractModel.CooperationContractId = cooperationContract.Identify().(int64)
|
|
|
if _, err := tx.Model(cooperationContractModel).WherePK().Delete(); err != nil {
|
|
|
return cooperationContract, err
|
|
|
} else {
|
|
|
//TODO 删除关联数据
|
|
|
}
|
|
|
return cooperationContract, nil
|
|
|
}
|
...
|
...
|
|