...
|
...
|
@@ -80,7 +80,7 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions |
|
|
// CooperationModeStatistics 企业-共创模式统计
|
|
|
//
|
|
|
// p1 p1_desc
|
|
|
func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
|
|
|
func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
|
|
// 参数验证
|
|
|
var request = struct {
|
...
|
...
|
@@ -100,7 +100,101 @@ func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions |
|
|
modeStatistics = make([]*domain.CooperationModeStatisticsDto, 0)
|
|
|
}
|
|
|
|
|
|
return modeStatistics, nil
|
|
|
modeStatistics = make([]*domain.CooperationModeStatisticsDto, 0)
|
|
|
// 1.当前企业有效的模式(不包含禁用、删除)
|
|
|
cooperationModeRepository, _ := repository.NewCooperationModeRepository(ptr.transactionContext)
|
|
|
_, models, err := cooperationModeRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "status": int32(1)})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(models) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// 2.遍历模式 当前模式包含的合约列表
|
|
|
// 2.1 根据合约查询订单金额,已分红预算的订单
|
|
|
// 2.2 根据合约查询分红预算的金额
|
|
|
// 2.3 根据合约去重参与的共创人数
|
|
|
cooperationContractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext)
|
|
|
var totalContracts []*domain.CooperationContract
|
|
|
var cooperationModes = make([]map[string]interface{}, 0)
|
|
|
for i := range models {
|
|
|
_, contracts, err := cooperationContractRepository.Find(map[string]interface{}{"companyId": request.CompanyId, "orgId": request.OrgId, "cooperationModeNumber": models[i].CooperationModeNumber})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
result, err := ptr.cooperationModeStatistics(models[i], contracts, request.CompanyId, request.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
modeStatistics = append(modeStatistics, result)
|
|
|
totalContracts = append(totalContracts, contracts...)
|
|
|
cooperationModes = append(cooperationModes, map[string]interface{}{
|
|
|
"cooperationModeId": models[i].CooperationModeId,
|
|
|
"cooperationModeName": models[i].CooperationModeName,
|
|
|
"cooperationModeNumber": models[i].CooperationModeNumber,
|
|
|
})
|
|
|
}
|
|
|
totalModeStatistics, err := ptr.cooperationModeStatistics(&domain.CooperationMode{}, totalContracts, request.CompanyId, request.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"cooperationModeStatistics": modeStatistics,
|
|
|
"totalCooperationModeStatistics": totalModeStatistics,
|
|
|
"cooperationModes": cooperationModes,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func (ptr *CooperationStatisticsService) cooperationModeStatistics(mode *domain.CooperationMode, contracts []*domain.CooperationContract, companyId, orgId int64) (*domain.CooperationModeStatisticsDto, error) {
|
|
|
initStatistic := &domain.CooperationModeStatisticsDto{
|
|
|
CooperationPeople: 0,
|
|
|
DividendsEstimate: 0,
|
|
|
OrderAmount: 0,
|
|
|
CooperationModeNumber: mode.CooperationModeNumber,
|
|
|
SettlementAmount: 0,
|
|
|
}
|
|
|
var err error
|
|
|
var undertakers []*domain.CooperationContractUndertaker
|
|
|
var mapUndertakers = make(map[int64]int64)
|
|
|
if len(contracts) == 0 {
|
|
|
return initStatistic, nil
|
|
|
}
|
|
|
var contractNumbers = make([]string, 0)
|
|
|
for i := range contracts {
|
|
|
contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
|
|
|
}
|
|
|
dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
|
|
|
initStatistic.OrderAmount, err = dividendsOrderDao.CalculateGoodOrderAmount(map[string]interface{}{"companyId": companyId, "orgId": orgId, "cooperationContractNumbers": contractNumbers})
|
|
|
if err != nil {
|
|
|
return initStatistic, err
|
|
|
}
|
|
|
dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
|
|
|
initStatistic.DividendsEstimate, err = dividendsEstimateDao.CountDividendsEstimateDividendsAmount(map[string]interface{}{"companyId": companyId, "orgId": orgId, "cooperationContractNumbers": contractNumbers})
|
|
|
if err != nil {
|
|
|
return initStatistic, err
|
|
|
}
|
|
|
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
|
|
|
if _, undertakers, err = undertakerRepository.Find(map[string]interface{}{}); err != nil {
|
|
|
return initStatistic, err
|
|
|
}
|
|
|
for i := range undertakers {
|
|
|
undertaker := undertakers[i]
|
|
|
if undertaker.Undertaker != nil && undertaker.Undertaker.UserId != 0 {
|
|
|
u1 := undertaker.Undertaker
|
|
|
mapUndertakers[u1.UserId] = u1.UserId
|
|
|
if u1.Referrer != nil && u1.Referrer.UserId != 0 {
|
|
|
mapUndertakers[u1.Referrer.UserId] = u1.Referrer.UserId
|
|
|
}
|
|
|
if u1.Salesman != nil && u1.Salesman.UserId != 0 {
|
|
|
mapUndertakers[u1.Salesman.UserId] = u1.Salesman.UserId
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
initStatistic.OrderAmount = utils.Round(initStatistic.OrderAmount, 1)
|
|
|
initStatistic.DividendsEstimate = utils.Round(initStatistic.DividendsEstimate, 1)
|
|
|
initStatistic.CooperationPeople = len(mapUndertakers)
|
|
|
return initStatistic, nil
|
|
|
}
|
|
|
|
|
|
// DividendsStatistics 分红统计
|
...
|
...
|
|