作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !22
@@ -281,8 +281,15 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -281,8 +281,15 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
281 cooperationApplicationRepository = value 281 cooperationApplicationRepository = value
282 } 282 }
283 283
  284 + var getCooperationProjectQuerySpecific *query.GetCooperationProjectQuery
  285 + if getCooperationProjectQuery.CooperationProjectId != 0 { // 根据ID查询
  286 + getCooperationProjectQuerySpecific.CooperationProjectId = getCooperationProjectQuery.CooperationProjectId
  287 + } else if getCooperationProjectQuery.CooperationProjectNumber != "" { // 根据编号查询
  288 + getCooperationProjectQuerySpecific = getCooperationProjectQuery
  289 + }
  290 +
284 // 获取共创项目 291 // 获取共创项目
285 - cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuery)) 292 + cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuerySpecific))
286 if err != nil { 293 if err != nil {
287 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 294 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
288 } 295 }
@@ -306,8 +313,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -306,8 +313,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
306 gotUser, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ 313 gotUser, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
307 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber, 314 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
308 "user": true, 315 "user": true,
309 - "companyId": getCooperationProjectQuery.CompanyId,  
310 - "orgId": getCooperationProjectQuery.OrgId, 316 + "companyId": cooperationProject.Company.CompanyId,
  317 + "orgId": cooperationProject.Org.OrgId,
311 }) 318 })
312 if err != nil { 319 if err != nil {
313 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 320 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -320,8 +327,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -320,8 +327,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
320 gotPartner, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ 327 gotPartner, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
321 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber, 328 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
322 "partner": true, 329 "partner": true,
323 - "companyId": getCooperationProjectQuery.CompanyId,  
324 - "orgId": getCooperationProjectQuery.OrgId, 330 + "companyId": cooperationProject.Company.CompanyId,
  331 + "orgId": cooperationProject.Org.OrgId,
325 }) 332 })
326 if err != nil { 333 if err != nil {
327 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 334 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -337,6 +344,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -337,6 +344,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
337 344
338 // 返回所有员工类型的申请通过人 345 // 返回所有员工类型的申请通过人
339 applicants := make([]*domain.User, 0) 346 applicants := make([]*domain.User, 0)
  347 +
340 // 获取当前项目的所有申请 348 // 获取当前项目的所有申请
341 if countApplication, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{ 349 if countApplication, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
342 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber, 350 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber,
@@ -157,6 +157,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred @@ -157,6 +157,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
157 OrderGoodAmount: dividendsEstimate.OrderGoodAmount, 157 OrderGoodAmount: dividendsEstimate.OrderGoodAmount,
158 CooperationContractNumber: dividendsEstimate.CooperationContractNumber, 158 CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
159 }) 159 })
  160 +
160 settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount 161 settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount
161 162
162 goodAmountCount = goodAmountCount + dividendsEstimate.OrderGoodAmount 163 goodAmountCount = goodAmountCount + dividendsEstimate.OrderGoodAmount
@@ -30,6 +30,10 @@ type SearchMoneyIncentivesEstimateQuery struct { @@ -30,6 +30,10 @@ type SearchMoneyIncentivesEstimateQuery struct {
30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` 30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
31 // 激励方式 31 // 激励方式
32 IncentivesType int32 `cname:"激励方式" json:"incentivesType,omitempty"` 32 IncentivesType int32 `cname:"激励方式" json:"incentivesType,omitempty"`
  33 + // 合约状态,1正常,2暂停
  34 + Status int32 `cname:"合约状态" json:"status,omitempty"`
  35 + // 查询限制
  36 + OffsetLimit bool `json:"offsetLimit,omitempty"`
33 } 37 }
34 38
35 func (searchMoneyIncentivesEstimateQuery *SearchMoneyIncentivesEstimateQuery) Valid(validation *validation.Validation) { 39 func (searchMoneyIncentivesEstimateQuery *SearchMoneyIncentivesEstimateQuery) Valid(validation *validation.Validation) {
@@ -1380,6 +1380,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1380,6 +1380,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1380 1380
1381 // 查找共创合约 1381 // 查找共创合约
1382 searchMoneyIncentivesEstimateQuery.IncentivesType = 2 1382 searchMoneyIncentivesEstimateQuery.IncentivesType = 2
  1383 + searchMoneyIncentivesEstimateQuery.Status = 1
  1384 + searchMoneyIncentivesEstimateQuery.OffsetLimit = false
1383 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil { 1385 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil {
1384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1386 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1385 } else { 1387 } else {
@@ -1387,15 +1389,19 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1387,15 +1389,19 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1387 for _, cooperationContract := range cooperationContracts { 1389 for _, cooperationContract := range cooperationContracts {
1388 // 阶段承接人map 1390 // 阶段承接人map
1389 stageUndertakerMap := make(map[int32][]*domain.Undertaker) 1391 stageUndertakerMap := make(map[int32][]*domain.Undertaker)
  1392 +
1390 // 阶段承接人列表 1393 // 阶段承接人列表
1391 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0) 1394 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
  1395 +
1392 // 初始化阶段承接人map 1396 // 初始化阶段承接人map
1393 for _, rule := range cooperationContract.MoneyIncentivesRules { 1397 for _, rule := range cooperationContract.MoneyIncentivesRules {
1394 stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0) 1398 stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
1395 } 1399 }
  1400 +
1396 log.Logger.Info("阶段承接人map初始化", map[string]interface{}{ 1401 log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
1397 "stageUndertakerMap": stageUndertakerMap, 1402 "stageUndertakerMap": stageUndertakerMap,
1398 }) 1403 })
  1404 +
1399 // 获取承接人 1405 // 获取承接人
1400 for _, undertaker := range cooperationContract.Undertakers { 1406 for _, undertaker := range cooperationContract.Undertakers {
1401 // 查询承接人分红预算单 1407 // 查询承接人分红预算单
@@ -1404,6 +1410,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1404,6 +1410,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1404 "companyId": cooperationContract.Company.CompanyId, 1410 "companyId": cooperationContract.Company.CompanyId,
1405 "orgId": cooperationContract.Org.OrgId, 1411 "orgId": cooperationContract.Org.OrgId,
1406 "dividendsUserId": undertaker.UserId, 1412 "dividendsUserId": undertaker.UserId,
  1413 + "offsetLimit": false,
1407 }); err != nil { 1414 }); err != nil {
1408 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1415 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1409 } else { 1416 } else {
@@ -1413,16 +1420,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1413,16 +1420,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1413 stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker) 1420 stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker)
1414 } 1421 }
1415 } 1422 }
  1423 + break
1416 } else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励 1424 } else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励
1417 for i, _ := range stageUndertakerMap { 1425 for i, _ := range stageUndertakerMap {
1418 stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker) 1426 stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker)
1419 } 1427 }
  1428 + break
1420 } 1429 }
1421 } 1430 }
1422 } 1431 }
  1432 +
1423 log.Logger.Info("阶段承接人map", map[string]interface{}{ 1433 log.Logger.Info("阶段承接人map", map[string]interface{}{
1424 "stageUndertakerMap": stageUndertakerMap, 1434 "stageUndertakerMap": stageUndertakerMap,
1425 }) 1435 })
  1436 +
1426 for k, v := range stageUndertakerMap { 1437 for k, v := range stageUndertakerMap {
1427 stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{ 1438 stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{
1428 Stage: k, 1439 Stage: k,
@@ -1431,11 +1442,23 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1431,11 +1442,23 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1431 } 1442 }
1432 1443
1433 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{} 1444 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{}
  1445 +
  1446 + // 判断当前合约的承接人是否全部分红
  1447 + allEstimate := true
  1448 + for i, _ := range stageUndertakerMap {
  1449 + if len(stageUndertakerMap[i]) > 0 {
  1450 + allEstimate = false
  1451 + break
  1452 + }
  1453 + }
  1454 +
  1455 + if !allEstimate {
1434 if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil { 1456 if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil {
1435 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1457 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1436 } 1458 }
1437 moneyIncentivesEstimateDtos = append(moneyIncentivesEstimateDtos, moneyIncentivesEstimateDto) 1459 moneyIncentivesEstimateDtos = append(moneyIncentivesEstimateDtos, moneyIncentivesEstimateDto)
1438 } 1460 }
  1461 + }
1439 1462
1440 if err := transactionContext.CommitTransaction(); err != nil { 1463 if err := transactionContext.CommitTransaction(); err != nil {
1441 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1464 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1122,8 +1122,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide @@ -1122,8 +1122,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
1122 } 1122 }
1123 orderTime := utils.TransformTimestampToTime(orderTimeInt) 1123 orderTime := utils.TransformTimestampToTime(orderTimeInt)
1124 1124
  1125 + // 退货单ID类型转换
  1126 + dividendsReturnedOrderId, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId, 10, 64)
  1127 + if err != nil {
  1128 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单ID类型错误")
  1129 + }
  1130 +
1125 // 获取分红退货单 1131 // 获取分红退货单
1126 - dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId}) 1132 + dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
  1133 + "dividendsReturnedOrderId": dividendsReturnedOrderId,
  1134 + })
1127 if err != nil { 1135 if err != nil {
1128 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1136 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1129 } 1137 }
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 9
10 type DividendsEstimateDetail struct { 10 type DividendsEstimateDetail struct {
11 DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户) 11 DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
12 - DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 12 + DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段 13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段
14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
15 OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号 15 OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
@@ -44,7 +44,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -44,7 +44,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
44 44
45 // 判断金额激励阶段是否合法 45 // 判断金额激励阶段是否合法
46 currentTime := time.Now() 46 currentTime := time.Now()
47 - if currentTime.Before(moneyIncentivesRuleMatched.MoneyIncentivesStageStart) { 47 + if currentTime.Before(moneyIncentivesRuleMatched.MoneyIncentivesTime) {
48 return nil, fmt.Errorf("还未到分红时间") 48 return nil, fmt.Errorf("还未到分红时间")
49 } 49 }
50 50
@@ -61,7 +61,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -61,7 +61,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
61 return nil, err 61 return nil, err
62 } 62 }
63 if undertakerEstimated { 63 if undertakerEstimated {
64 - return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红") 64 + return nil, fmt.Errorf("承接人 " + undertaker.UserName + " 已分红")
65 } else { 65 } else {
66 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Float64() 66 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Float64()
67 //Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64() 67 //Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64()
@@ -80,7 +80,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -80,7 +80,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
80 Status: undertaker.Status, 80 Status: undertaker.Status,
81 Company: undertaker.Company, 81 Company: undertaker.Company,
82 }, 82 },
83 - DividendsParticipateType: domain.MONEY_INCENTIVES, 83 + DividendsParticipateType: 1,
84 DividendsStage: stage, 84 DividendsStage: stage,
85 DividendsAmount: undertakerDividendsAmount, 85 DividendsAmount: undertakerDividendsAmount,
86 }) 86 })
@@ -114,7 +114,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -114,7 +114,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
114 UserPhone: undertaker.Salesman.UserPhone, 114 UserPhone: undertaker.Salesman.UserPhone,
115 Company: undertaker.Salesman.Company, 115 Company: undertaker.Salesman.Company,
116 }, 116 },
117 - DividendsParticipateType: domain.MONEY_INCENTIVES, 117 + DividendsParticipateType: 3,
118 DividendsStage: stage, 118 DividendsStage: stage,
119 DividendsAmount: undertakerDividendsAmount, 119 DividendsAmount: undertakerDividendsAmount,
120 }) 120 })
@@ -122,7 +122,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -122,7 +122,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
122 122
123 } 123 }
124 124
125 - // 判断关联业务员在当前阶段是否已经分红 125 + // 判断推荐人在当前阶段是否已经分红
126 if undertaker.Referrer != nil { 126 if undertaker.Referrer != nil {
127 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 127 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
128 "undertakerUid": undertaker.Referrer.UserId, 128 "undertakerUid": undertaker.Referrer.UserId,
@@ -133,7 +133,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -133,7 +133,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
133 return nil, err 133 return nil, err
134 } 134 }
135 if referrerEstimated { 135 if referrerEstimated {
136 - return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红") 136 + return nil, fmt.Errorf("推荐人 " + undertaker.Referrer.UserName + " 已分红")
137 } else { 137 } else {
138 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64() 138 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
139 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 139 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
@@ -150,7 +150,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -150,7 +150,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
150 UserPhone: undertaker.Referrer.UserPhone, 150 UserPhone: undertaker.Referrer.UserPhone,
151 Company: undertaker.Referrer.Company, 151 Company: undertaker.Referrer.Company,
152 }, 152 },
153 - DividendsParticipateType: domain.MONEY_INCENTIVES, 153 + DividendsParticipateType: 2,
154 DividendsStage: stage, 154 DividendsStage: stage,
155 DividendsAmount: undertakerDividendsAmount, 155 DividendsAmount: undertakerDividendsAmount,
156 }) 156 })