作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -784,7 +784,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
orderGoodSavedIds = append(orderGoodSavedIds, dividendsEstimate.OrderGoodId)
}
// 获取订单产品
// 更新订单产品分红状态
var orderGoodsSaved []*domain.OrderGood
if len(orderGoodSavedIds) > 0 {
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
"orderGoodIds": orderGoodSavedIds,
... ... @@ -795,6 +796,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
for i, _ := range orderGoodsFound {
orderGoodsFound[i].OrderGoodDividendsStatus = int32(2) // 已分红
}
orderGoodsSaved = orderGoodsFound
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
}
... ... @@ -834,12 +836,21 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
} else {
if countDividendsOrdersFound > 0 {
for i, dividendsOrderFound := range dividendsOrdersFound {
for i, _ := range dividendsOrderFound.Goods {
for _, good := range orderGoodsSaved {
if dividendsOrderFound.Goods[i].OrderGoodId == good.OrderGoodId {
dividendsOrderFound.Goods[i].OrderGoodDividendsStatus = good.OrderGoodDividendsStatus
}
}
}
var dividendsGoodCount int
for _, orderGood := range dividendsOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
dividendsGoodCount = dividendsGoodCount + 1
}
}
if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红
dividendsOrdersFound[i].DividendStatus = 2
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红
... ... @@ -848,6 +859,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
dividendsOrdersFound[i].DividendStatus = 1
}
}
// 保存订单状态
if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -867,6 +879,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
} else {
if countDividendsReturnedOrdersFound > 0 {
for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {
for i, _ := range dividendsReturnedOrderFound.Goods {
for _, good := range orderGoodsSaved {
if dividendsReturnedOrderFound.Goods[i].OrderGoodId == good.OrderGoodId {
dividendsReturnedOrderFound.Goods[i].OrderGoodDividendsStatus = good.OrderGoodDividendsStatus
}
}
}
var dividendsGoodCount int
for _, orderGood := range dividendsReturnedOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
... ... @@ -1307,10 +1327,12 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
})
if err != nil {
log.Logger.Error(err.Error())
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
log.Logger.Info(fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
}
... ... @@ -1326,10 +1348,12 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
})
if err != nil {
log.Logger.Error(err.Error())
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
log.Logger.Info(fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
}
... ... @@ -1401,12 +1425,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
// 初始化阶段承接人map
for _, rule := range cooperationContract.MoneyIncentivesRules {
stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
}
// TODO 校验当前时间和激励阶段是否匹配
log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
"stageUndertakerMap": stageUndertakerMap,
})
... ... @@ -1424,6 +1447,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
"orgId": cooperationContract.Org.OrgId,
"dividendsUserId": undertaker.UserId,
"offsetLimit": false,
"dividendsParticipateType": int32(1),
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1445,7 +1469,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
}
}
// TODO 去除没有承接人的阶段
// 校验当前时间和激励阶段是否匹配
currentTime := time.Now()
for _, rule := range cooperationContract.MoneyIncentivesRules {
if currentTime.After(rule.MoneyIncentivesTime) || currentTime.Equal(rule.MoneyIncentivesTime) {
delete(stageUndertakerMap, rule.MoneyIncentivesStage)
}
}
// 去除没有承接人的阶段
for k, v := range stageUndertakerMap {
if len(v) == 0 {
delete(stageUndertakerMap, k)
}
}
log.Logger.Info("阶段承接人map", map[string]interface{}{
"stageUndertakerMap": stageUndertakerMap,
... ...
... ... @@ -8,6 +8,8 @@ type CooperationContractUndertaker struct {
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId,string"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 合约ID
CooperationContractId int64 `json:"cooperationContractId"`
// 共创合约承接人
Undertaker *Undertaker `json:"undertaker"`
// 创建时间
... ...
... ... @@ -10,6 +10,8 @@ type Undertaker struct {
UserBaseId int64 `json:"userBaseId,string"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创合约ID
CooperationContractId int64 `json:"cooperationContractId"`
// 用户所属组织机构
Org *Org `json:"org"`
// 用户关联的组织机构
... ...
... ... @@ -11,6 +11,8 @@ type CooperationContractUndertaker struct {
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约ID
CooperationContractId int64 `comment:"共创合约ID"`
// 共创合约承接人uid
UserId int64 `comment:"共创合约承接人uid"`
// 用户基础数据id
... ...
... ... @@ -43,6 +43,8 @@ type DividendsEstimate struct {
OperateTime time.Time `comment:"操作时间"`
// 取消状态
IsCanceled bool `comment:"取消状态"`
// 产品ID
OrderGoodId int64 `comment:"产品ID"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
... ...
... ... @@ -27,6 +27,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
Operator: dividendsEstimateModel.Operator,
OperateTime: dividendsEstimateModel.OperateTime,
IsCanceled: dividendsEstimateModel.IsCanceled,
OrderGoodId: dividendsEstimateModel.OrderGoodId,
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
... ...
... ... @@ -145,6 +145,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
for _, undertaker := range cooperationContract.Undertakers {
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
CooperationContractId: cooperationContract.CooperationContractId,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
... ... @@ -445,6 +446,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
CooperationContractUndertakerId: undertakerDomain.UndertakerId,
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
CooperationContractId: undertakerDomain.CooperationContractId,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
... ... @@ -498,6 +500,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
undertakerModelsToUpdate[i] = &models.CooperationContractUndertaker{
CooperationContractUndertakerId: undertaker.UndertakerId,
CooperationContractNumber: undertaker.CooperationContractNumber,
CooperationContractId: undertaker.CooperationContractId,
UserId: undertaker.UserId,
UserBaseId: undertaker.UserBaseId,
Org: undertaker.Org,
... ... @@ -1233,7 +1236,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的承接人列表不存在")
return 0, nil, fmt.Errorf("合约关联的承接人列表不存在")
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
... ... @@ -1243,7 +1246,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, fmt.Errorf("合约相关的相关人列表不存在")
return 0, nil, fmt.Errorf("合约关联的相关人列表不存在")
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
... ...
... ... @@ -44,6 +44,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
"operator",
"operate_time",
"is_canceled",
"order_good_id",
"created_at",
"deleted_at",
"updated_at",
... ... @@ -81,6 +82,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.IsCanceled,
&dividendsEstimate.OrderGoodId,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
... ... @@ -104,6 +106,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.IsCanceled,
dividendsEstimate.OrderGoodId,
dividendsEstimate.CreatedAt,
nil,
dividendsEstimate.UpdatedAt,
... ... @@ -131,6 +134,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.Operator,
&dividendsEstimate.OperateTime,
&dividendsEstimate.IsCanceled,
&dividendsEstimate.OrderGoodId,
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
... ... @@ -154,6 +158,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.Operator,
dividendsEstimate.OperateTime,
dividendsEstimate.IsCanceled,
dividendsEstimate.OrderGoodId,
dividendsEstimate.CreatedAt,
nil,
dividendsEstimate.UpdatedAt,
... ... @@ -196,6 +201,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: dividendsEstimate.UpdatedAt,
... ... @@ -241,6 +247,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
... ... @@ -315,6 +322,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
query.Where("cooperation_contract_number in (?)", pg.In(v))
}
if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
query.Where("dividends_participate_type = ?", dividendsParticipateType)
}
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query.Where("cooperation_contract_number = ?", cooperationContractNumber)
}
... ...