作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -75,7 +75,11 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -615,7 +619,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
... ... @@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -31,3 +31,10 @@ type Relevant struct {
// 公司
Company *Company `json:"company"`
}
func (relevant *Relevant) Identify() interface{} {
if relevant.RelevantId == 0 {
return nil
}
return relevant.RelevantId
}
... ...
... ... @@ -37,3 +37,10 @@ type Undertaker struct {
// 合同附件
ContractAttachment []*Attachment `json:"contractAttachment"`
}
func (undertaker *Undertaker) Identify() interface{} {
if undertaker.UndertakerId == 0 {
return nil
}
return undertaker.UndertakerId
}
... ...
... ... @@ -53,6 +53,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
... ...
... ... @@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
DividendsUser: item.DividendsUser,
}
if item.DividendsType == 1 {
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum})
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": item.OrderOrReturnedOrderNum,
"companyId": item.Company.CompanyId,
"orgId": item.Org.OrgId,
})
if err != nil {
return nil, err
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type ContractUndertakerFeedbackRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &ContractUndertakerFeedbackRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -17,14 +17,11 @@ import (
type CooperationApplicationRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationApplicationRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractChangeLogRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractChangeLogRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractRelevantRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractRelevantRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -16,14 +16,11 @@ import (
type CooperationContractRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -108,21 +105,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增相关人
var relevantPeopleModel []*models.CooperationContractRelevant
for _, relevant := range cooperationContract.RelevantPeople {
if relevant.Identify() == nil {
orderGoodId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
relevant.RelevantId = orderGoodId
}
}
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Roles: relevant.Roles,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
CooperationContractRelevantId: relevant.RelevantId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Roles: relevant.Roles,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if len(relevantPeopleModel) > 0 {
... ... @@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增分红激励规则
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
for _, rule := range cooperationContract.DividendsIncentivesRules {
if rule.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
rule.DividendsIncentivesRuleId = ruleId
}
}
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
... ... @@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增金额激励规则
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
if rule.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
rule.MoneyIncentivesRuleId = ruleId
}
}
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
... ... @@ -302,21 +326,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的相关人领域模型转换为数据模型
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
if relevantDomain.Identify() == nil {
relevantId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
relevantDomain.RelevantId = relevantId
}
}
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: relevantDomain.RelevantId,
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(),
})
}
... ... @@ -401,24 +434,33 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的相关人领域模型转换为数据模型
var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
for _, undertakerDomain := range cooperationContractUndertakersToAdd {
if undertakerDomain.Identify() == nil {
undertakerId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
undertakerDomain.UndertakerId = undertakerId
}
}
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: undertakerDomain.Referrer,
Salesman: undertakerDomain.Salesman,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: undertakerDomain.ContractAttachment,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
CooperationContractUndertakerId: undertakerDomain.UndertakerId,
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: undertakerDomain.Referrer,
Salesman: undertakerDomain.Salesman,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: undertakerDomain.ContractAttachment,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
log.Logger.Info("待添加的承接人", map[string]interface{}{
... ... @@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的分红激励规则领域模型转换为数据模型
var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
if dividendsIncentivesRuleDomain.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsIncentivesRuleDomain.DividendsIncentivesRuleId = ruleId
}
}
dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleDomain.DividendsIncentivesRuleId,
CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
... ... @@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的金额激励规则领域模型转换为数据模型
var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule
for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd {
if moneyIncentivesRuleDomain.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
moneyIncentivesRuleDomain.MoneyIncentivesRuleId = ruleId
}
}
moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleDomain.MoneyIncentivesRuleId,
CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber,
MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage,
... ... @@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractUndertakerRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractUndertakerRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -14,14 +14,11 @@ import (
type CooperationModeRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationModeRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationModeRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -17,14 +17,11 @@ import (
type CooperationProjectRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationProjectRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationProjectRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CreditAccountRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CreditAccountRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CreditAccountRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -16,14 +16,11 @@ import (
type DividendsEstimateRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &DividendsEstimateRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type DividendsIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &DividendsIncentivesRuleRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 更新分红订单产品
var orderGoodsFetched []*models.OrderGood
orderGoodsQuery := tx.Model(&orderGoodsFetched)
if err := orderGoodsQuery.Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Select(); err != nil {
if err := orderGoodsQuery.
Where("company_id = ?", dividendsOrder.Company.CompanyId).
Where("org_id = ?", dividendsOrder.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 待更新分红产品
var orderGoodsToUpdate []*domain.OrderGood
// 待添加分红产品
var orderGoodsToAdd []*domain.OrderGood
for _, good := range dividendsOrder.Goods {
... ... @@ -230,10 +235,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
})
}
// 添加分红订单产品
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if len(orderGoodsToAddModels) > 0 {
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
return nil, err
}
... ... @@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("分红订单不存在")
... ...
... ... @@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
Delete(); err != nil {
return nil, err
}
}
... ... @@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return nil, fmt.Errorf("分红退货单关联的产品不存在")
}
// 聚合分红退货单
... ...
... ... @@ -15,14 +15,11 @@ import (
type MoneyIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &MoneyIncentivesRuleRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...