作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

... ... @@ -308,7 +308,11 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
} else {
cooperationModeRepository = value
}
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber})
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
"orgId": createCooperationContractCommand.OrgId,
"cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")
}
... ...
... ... @@ -752,29 +752,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.ORDER_DIVIDENDS,
DividendsTypeName: "订单分红",
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.ORDER_DIVIDENDS,
DividendsTypeName: "订单分红",
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
... ... @@ -806,29 +807,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
DividendsType: domain.RETURN_WRITE_OFF,
DividendsTypeName: "退货冲销",
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
DividendsType: domain.RETURN_WRITE_OFF,
DividendsTypeName: "退货冲销",
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
... ... @@ -1148,27 +1150,28 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateDetail.DividendsAmount, -2).Float64()
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.MONEY_INCENTIVES,
DividendsTypeName: "金额激励",
OrderOrReturnedOrderNum: "",
CooperationContractNumber: cooperationContract.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: nil,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
PaymentStatus: int32(1),
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.MONEY_INCENTIVES,
DividendsTypeName: "金额激励",
OrderOrReturnedOrderNum: "",
CooperationContractNumber: cooperationContract.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: nil,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
... ...
... ... @@ -145,6 +145,10 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
}
}
log.Logger.Info("查询到的合约", map[string]interface{}{
"cooperationContractsMap": cooperationContractsMap,
})
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
if err != nil {
... ... @@ -163,9 +167,14 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
ruleMatchedFlag := false
if orderGood.CooperationContractNumber != "" {
// 校验共创合约激励类型是否正确
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
if cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
}
} else {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
}
// 校验产品关联合约的激励规则是否匹配订单时间
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
... ...
... ... @@ -43,6 +43,8 @@ type DividendsEstimate struct {
OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"`
// 共创项目合约编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创合约承接人id
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"`
// 分红用户(共创参与)
DividendsUser *User `json:"dividendsUser"`
// 分红阶段
... ...
... ... @@ -8,13 +8,14 @@ import (
)
type DividendsEstimateDetail struct {
DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
DividendsStage int32 `json:"dividendsStage"` // 分红阶段
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
Reason string `json:"reason"` // 错误原因
DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
DividendsStage int32 `json:"dividendsStage"` // 分红阶段
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
Reason string `json:"reason"` // 错误原因
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"` // 承接人记录ID
}
// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
... ...
... ... @@ -2,7 +2,7 @@ package domain
// Undertaker 共创合约承接方值对象
type Undertaker struct {
// 承接人id
// 承接人记录ID
UndertakerId int64 `json:"undertakerId,string"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
... ... @@ -20,6 +20,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
//var cooperationContactRepository domain.CooperationContractRepository // 合约仓储
// 分红预算单仓储初始化
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
... ... @@ -49,6 +50,13 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
orderGoodRepository = repo
}
// 共创合约仓储初始化
//if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// cooperationContactRepository = repo
//}
// 获取分红预算单
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
"dividendsEstimateIds": dividendsEstimateIds,
... ... @@ -61,18 +69,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
// 自定义查询
queryOptions := make(map[string]interface{})
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{1, 2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
}
//queryOptions := map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
// "dividendsParticipateTypes": []int32{1, 2, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsTypes": []int32{1, 2},
//}
//参与分红类型,1承接人,2推荐人,3关联业务员
//if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
// queryOptions = map[string]interface{}{
... ... @@ -107,7 +113,17 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
//}
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
"dividendsParticipateTypes": []int32{1, 2, 3},
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsTypes": []int32{1, 2},
"orderGoodId": dividendsEstimate.OrderGoodId,
}); err2 != nil {
return nil, err2
} else {
if countRelative > 0 {
... ... @@ -125,19 +141,27 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
}
}
} else if dividendsEstimate.DividendsType == 3 { // 3.金额激励
// 自定义查询
queryOptions := make(map[string]interface{})
queryOptions = map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"dividendsParticipateTypes": []int32{1, 2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}
// 查询合约
//cooperationContract, err3 := cooperationContactRepository.FindOne(map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
//})
//if err3 != nil {
// return nil, err3
//}
// 自定义查询
//queryOptions := map[string]interface{}{
// "companyId": dividendsEstimate.Company.CompanyId,
// "orgId": dividendsEstimate.Org.OrgId,
// "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
// "dividendsParticipateTypes": []int32{1, 2, 3},
// "offsetLimit": false,
// "dividendsStage": dividendsEstimate.DividendsStage,
// "dividendsType": int32(3),
//}
//参与分红类型,1承接人,2推荐人,3关联业务员
//if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
// queryOptions = map[string]interface{}{
... ... @@ -172,7 +196,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
//}
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil {
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsEstimate.Company.CompanyId,
"orgId": dividendsEstimate.Org.OrgId,
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
"cooperationContractUndertakerId": dividendsEstimate.CooperationContractUndertakerId,
"dividendsParticipateTypes": []int32{1, 2, 3},
"offsetLimit": false,
"dividendsStage": dividendsEstimate.DividendsStage,
"dividendsType": int32(3),
}); err2 != nil {
return nil, err2
} else {
if countRelative > 0 {
... ... @@ -180,9 +213,9 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
dividendsEstimatesRelative[i].IsCanceled = true
dividendsEstimatesRelative[i].Operator = operator
}
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
return nil, err3
dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err4 != nil {
return nil, err4
}
dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
}
... ...
... ... @@ -243,11 +243,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -269,11 +270,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -295,11 +297,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -364,11 +367,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -390,11 +394,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -417,11 +422,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ...
... ... @@ -64,7 +64,6 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
return nil, fmt.Errorf("承接人 " + undertaker.UserName + " 已分红")
} else {
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Float64()
//Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -80,9 +79,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: 1,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
DividendsParticipateType: 1,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -114,9 +114,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: 3,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
DividendsParticipateType: 3,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -150,9 +151,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: 2,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
DividendsParticipateType: 2,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ...
... ... @@ -29,6 +29,8 @@ type DividendsEstimate struct {
OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"`
// 共创项目合约编号
CooperationContractNumber string `comment:"共创项目合约编号"`
// 共创合约承接人id
CooperationContractUndertakerId int64 `comment:"共创合约承接人ID"`
// 分红用户
DividendsUser *domain.User `comment:"分红用户"`
// 分红阶段
... ... @@ -42,7 +44,7 @@ type DividendsEstimate struct {
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 取消状态
IsCanceled bool `comment:"取消状态" pg:",use_zero,default:false"`
IsCanceled bool `comment:"取消状态" pg:",use_zero"`
// 产品ID
OrderGoodId int64 `comment:"产品ID"`
// 创建时间
... ...
... ... @@ -9,27 +9,28 @@ import (
func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel *models.DividendsEstimate) (*domain.DividendsEstimate, error) {
dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateModel.DividendsAmount, -2).Float64()
return &domain.DividendsEstimate{
DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,
PaymentStatus: dividendsEstimateModel.PaymentStatus,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType,
DividendsType: dividendsEstimateModel.DividendsType,
DividendsTypeName: dividendsEstimateModel.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,
DividendsUser: dividendsEstimateModel.DividendsUser,
DividendsStage: dividendsEstimateModel.DividendsStage,
Org: dividendsEstimateModel.Org,
Company: dividendsEstimateModel.Company,
Operator: dividendsEstimateModel.Operator,
OperateTime: dividendsEstimateModel.OperateTime,
IsCanceled: dividendsEstimateModel.IsCanceled,
OrderGoodId: dividendsEstimateModel.OrderGoodId,
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,
PaymentStatus: dividendsEstimateModel.PaymentStatus,
DividendsAmount: dividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType,
DividendsType: dividendsEstimateModel.DividendsType,
DividendsTypeName: dividendsEstimateModel.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,
CooperationContractUndertakerId: dividendsEstimateModel.CooperationContractUndertakerId,
DividendsUser: dividendsEstimateModel.DividendsUser,
DividendsStage: dividendsEstimateModel.DividendsStage,
Org: dividendsEstimateModel.Org,
Company: dividendsEstimateModel.Company,
Operator: dividendsEstimateModel.Operator,
OperateTime: dividendsEstimateModel.OperateTime,
IsCanceled: dividendsEstimateModel.IsCanceled,
OrderGoodId: dividendsEstimateModel.OrderGoodId,
CreatedAt: dividendsEstimateModel.CreatedAt,
DeletedAt: dividendsEstimateModel.DeletedAt,
UpdatedAt: dividendsEstimateModel.UpdatedAt,
}, nil
}
... ...
... ... @@ -824,13 +824,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
// 返回新增的合约
cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
"cooperationContractId": cooperationContract.CooperationContractId,
})
if err != nil {
return nil, err
}
return cooperationContractSaved, nil
//cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
// "cooperationContractId": cooperationContract.CooperationContractId,
//})
//if err != nil {
// return nil, err
//}
return cooperationContract, nil
}
func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
... ...
... ... @@ -48,6 +48,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
"created_at",
"deleted_at",
"updated_at",
"cooperation_contract_undertaker_id",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -86,6 +87,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
&dividendsEstimate.CooperationContractUndertakerId,
),
fmt.Sprintf("INSERT INTO dividends_estimates (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
... ... @@ -110,6 +112,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.CreatedAt,
nil,
dividendsEstimate.UpdatedAt,
dividendsEstimate.CooperationContractUndertakerId,
); err != nil {
return dividendsEstimate, err
}
... ... @@ -138,6 +141,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
&dividendsEstimate.CreatedAt,
&dividendsEstimate.DeletedAt,
&dividendsEstimate.UpdatedAt,
&dividendsEstimate.CooperationContractUndertakerId,
),
fmt.Sprintf("UPDATE dividends_estimates SET %s WHERE dividends_estimate_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsEstimate.DividendsEstimateId,
... ... @@ -162,6 +166,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di
dividendsEstimate.CreatedAt,
nil,
dividendsEstimate.UpdatedAt,
dividendsEstimate.CooperationContractUndertakerId,
dividendsEstimate.Identify(),
); err != nil {
return dividendsEstimate, err
... ... @@ -183,28 +188,29 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
}
}
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimate.DividendsParticipateType,
DividendsType: dividendsEstimate.DividendsType,
DividendsTypeName: dividendsEstimate.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: dividendsEstimate.UpdatedAt,
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimate.DividendsParticipateType,
DividendsType: dividendsEstimate.DividendsType,
DividendsTypeName: dividendsEstimate.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: dividendsEstimate.UpdatedAt,
CooperationContractUndertakerId: dividendsEstimate.CooperationContractUndertakerId,
})
}
if len(dividendsEstimateModels) > 0 {
... ... @@ -229,28 +235,29 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimate.DividendsParticipateType,
DividendsType: dividendsEstimate.DividendsType,
DividendsTypeName: dividendsEstimate.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
PaymentStatus: dividendsEstimate.PaymentStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime,
DividendsParticipateType: dividendsEstimate.DividendsParticipateType,
DividendsType: dividendsEstimate.DividendsType,
DividendsTypeName: dividendsEstimate.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
DividendsUser: dividendsEstimate.DividendsUser,
DividendsStage: dividendsEstimate.DividendsStage,
Org: dividendsEstimate.Org,
Company: dividendsEstimate.Company,
Operator: dividendsEstimate.Operator,
OperateTime: dividendsEstimate.OperateTime,
IsCanceled: dividendsEstimate.IsCanceled,
OrderGoodId: dividendsEstimate.OrderGoodId,
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: time.Now(),
CooperationContractUndertakerId: dividendsEstimate.CooperationContractUndertakerId,
})
}
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
... ... @@ -325,6 +332,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 cooperationContractUndertakerId, ok := queryOptions["cooperationContractUndertakerId"]; ok && cooperationContractUndertakerId.(int64) != 0 {
query.Where("cooperation_contract_undertaker_id = ?", cooperationContractUndertakerId)
}
if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
query.Where("dividends_participate_type = ?", dividendsParticipateType)
}
... ... @@ -340,6 +350,10 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 {
query.Where(`dividends_user @> '{"userId":"?"}'`, dividendsUserId)
}
if dividendsUserIds, ok := queryOptions["dividendsUserIds"]; ok && len(dividendsUserIds.([]int64)) > 0 {
newDividendsUserIds := utils.SliceItoa(dividendsUserIds.([]int64))
query.Where("dividends_user->>'userId' in (?)", pg.In(newDividendsUserIds))
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.Where(`dividends_user @> '{"userBaseId":"?"}'`, userBaseId)
}
... ...
... ... @@ -45,7 +45,7 @@ func (serviceGateway *httplibBaseServiceGateway) createRequest(url string, metho
case "head":
request = httplib.Head(url)
break
default:
:
request = httplib.Get(url)
}
return request.SetTimeout(serviceGateway.connectTimeout, serviceGateway.readWriteTimeout)
... ...