作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation 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, "共创模式不存在")
}
... ...
... ... @@ -775,6 +775,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
... ... @@ -829,6 +830,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
... ... @@ -1169,6 +1171,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
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 {
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"`
// 分红阶段
... ...
... ... @@ -15,6 +15,7 @@ type DividendsEstimateDetail struct {
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...)
}
... ...
... ... @@ -248,6 +248,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -274,6 +275,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -300,6 +302,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -369,6 +372,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: -undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -395,6 +399,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: -referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
}
... ... @@ -422,6 +427,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
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,
... ... @@ -83,6 +82,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
DividendsParticipateType: 1,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -117,6 +117,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
DividendsParticipateType: 3,
DividendsStage: stage,
DividendsAmount: undertakerDividendsAmount,
CooperationContractUndertakerId: undertaker.UndertakerId,
})
}
... ... @@ -153,6 +154,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
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"`
// 创建时间
... ...
... ... @@ -20,6 +20,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel
DividendsTypeName: dividendsEstimateModel.DividendsTypeName,
OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,
CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,
CooperationContractUndertakerId: dividendsEstimateModel.CooperationContractUndertakerId,
DividendsUser: dividendsEstimateModel.DividendsUser,
DividendsStage: dividendsEstimateModel.DividendsStage,
Org: dividendsEstimateModel.Org,
... ...
... ... @@ -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
... ... @@ -205,6 +210,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
CreatedAt: dividendsEstimate.CreatedAt,
DeletedAt: dividendsEstimate.DeletedAt,
UpdatedAt: dividendsEstimate.UpdatedAt,
CooperationContractUndertakerId: dividendsEstimate.CooperationContractUndertakerId,
})
}
if len(dividendsEstimateModels) > 0 {
... ... @@ -251,6 +257,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
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)
... ...