正在显示
1 个修改的文件
包含
119 行增加
和
29 行删除
@@ -51,18 +51,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -51,18 +51,15 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
51 | if systemSuMoneyStatistics == nil { | 51 | if systemSuMoneyStatistics == nil { |
52 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | 52 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") |
53 | } | 53 | } |
54 | - | ||
55 | systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) | 54 | systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) |
56 | systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) | 55 | systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) |
57 | systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) | 56 | systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) |
58 | - | ||
59 | if err != nil { | 57 | if err != nil { |
60 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 58 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
61 | } | 59 | } |
62 | if systemCashStatistics == nil { | 60 | if systemCashStatistics == nil { |
63 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | 61 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") |
64 | } | 62 | } |
65 | - | ||
66 | systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) | 63 | systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) |
67 | systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) | 64 | systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) |
68 | var cashPoolRepository domain.CashPoolRepository | 65 | var cashPoolRepository domain.CashPoolRepository |
@@ -268,12 +265,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas | @@ -268,12 +265,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas | ||
268 | } else { | 265 | } else { |
269 | exchangeActivityRepository = value | 266 | exchangeActivityRepository = value |
270 | } | 267 | } |
271 | - | ||
272 | - // TODO 需要更新兑换活动结束倒计时 | ||
273 | - | ||
274 | if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil { | 268 | if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil { |
275 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 269 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
276 | } else { | 270 | } else { |
271 | + // TODO 需要更新兑换活动结束倒计时 | ||
272 | + | ||
273 | + | ||
277 | if err := transactionContext.CommitTransaction(); err != nil { | 274 | if err := transactionContext.CommitTransaction(); err != nil { |
278 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 275 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
279 | } | 276 | } |
@@ -347,21 +344,56 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA | @@ -347,21 +344,56 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA | ||
347 | } else { | 344 | } else { |
348 | exchangeCashActivityRepository = value | 345 | exchangeCashActivityRepository = value |
349 | } | 346 | } |
350 | - | ||
351 | - // TODO 需要更新兑换活动结束倒计时 | ||
352 | - | ||
353 | - activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": getExchangeCashActivityQuery.ExchangeCashActivityId}) | 347 | + // 需要更新兑换活动结束倒计时 |
348 | + activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId}) | ||
354 | if err != nil { | 349 | if err != nil { |
355 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 350 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
356 | } | 351 | } |
357 | if activity == nil { | 352 | if activity == nil { |
358 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId))) | 353 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId))) |
354 | + } | ||
355 | + var timeNow = time.Now() | ||
356 | + var deadline = activity.Deadline | ||
357 | + var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local) | ||
358 | + var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local) | ||
359 | + updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand { | ||
360 | + ExchangeCashActivityId: activity.ActivityId, | ||
361 | + //ExchangeActivityName: activity.ExchangeActivityName, | ||
362 | + //Deadline: activity.Deadline, | ||
363 | + CountDown: int64(t2.Sub(t1).Hours() / 24), | ||
364 | + //ExchangedSuMoney: activity.ExchangedSuMoney, | ||
365 | + //ExchangedCash: activity.ExchangedCash, | ||
366 | + //ExchangeRate: activity.Rate, | ||
367 | + } | ||
368 | + if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil { | ||
369 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
370 | + } | ||
371 | + activityFound, err := exchangeCashActivityRepository.Save(activity) | ||
372 | + if err != nil { | ||
373 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
374 | + } | ||
375 | + // 返回兑换现金活动 | ||
376 | + if activityFound == nil { | ||
377 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
359 | } else { | 378 | } else { |
360 | if err := transactionContext.CommitTransaction(); err != nil { | 379 | if err := transactionContext.CommitTransaction(); err != nil { |
361 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 380 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
362 | } | 381 | } |
363 | - return activity, nil | 382 | + return activityFound, nil |
364 | } | 383 | } |
384 | + // 返回兑换现金活动 | ||
385 | + //activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"exchangeCashActivityId": getExchangeCashActivityQuery.ExchangeCashActivityId}) | ||
386 | + //if err != nil { | ||
387 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
388 | + //} | ||
389 | + //if activityFound == nil { | ||
390 | + // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId))) | ||
391 | + //} else { | ||
392 | + // if err := transactionContext.CommitTransaction(); err != nil { | ||
393 | + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
394 | + // } | ||
395 | + // return activityFound, nil | ||
396 | + //} | ||
365 | } | 397 | } |
366 | 398 | ||
367 | // 更新兑换现金活动,名称,截止日期、汇率 | 399 | // 更新兑换现金活动,名称,截止日期、汇率 |
@@ -379,6 +411,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -379,6 +411,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
379 | defer func() { | 411 | defer func() { |
380 | transactionContext.RollbackTransaction() | 412 | transactionContext.RollbackTransaction() |
381 | }() | 413 | }() |
414 | + // 更新兑换活动 | ||
382 | var exchangeCashActivityRepository domain.ExchangeActivityRepository | 415 | var exchangeCashActivityRepository domain.ExchangeActivityRepository |
383 | if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ | 416 | if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ |
384 | "transactionContext": transactionContext, | 417 | "transactionContext": transactionContext, |
@@ -397,7 +430,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -397,7 +430,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
397 | if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { | 430 | if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { |
398 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 431 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
399 | } | 432 | } |
433 | + // 更新兑换活动兑换汇率 | ||
400 | if updateExchangeCashActivityCommand.ExchangeRate != 0 { | 434 | if updateExchangeCashActivityCommand.ExchangeRate != 0 { |
435 | + // 获取当前现金池 | ||
401 | var cashPoolRepository domain.CashPoolRepository | 436 | var cashPoolRepository domain.CashPoolRepository |
402 | if value, err := factory.CreateCashPoolRepository(map[string] interface{} { | 437 | if value, err := factory.CreateCashPoolRepository(map[string] interface{} { |
403 | "transactionContext": transactionContext, | 438 | "transactionContext": transactionContext, |
@@ -415,7 +450,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -415,7 +450,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
415 | if cashPools == nil { | 450 | if cashPools == nil { |
416 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId))) | 451 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId))) |
417 | } | 452 | } |
418 | - // 修改汇率时判断兑换活动清单中现金总金额是否超过平台未兑换现金值 | 453 | + // 判断兑换活动清单中现金总金额是否超过平台未兑换现金值 |
419 | var cashPoolDao *dao.CashPoolDao | 454 | var cashPoolDao *dao.CashPoolDao |
420 | if value, err := factory.CreateCashPoolDao(map[string]interface{}{ | 455 | if value, err := factory.CreateCashPoolDao(map[string]interface{}{ |
421 | "transactionContext": transactionContext, | 456 | "transactionContext": transactionContext, |
@@ -429,13 +464,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -429,13 +464,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
429 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 464 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
430 | } | 465 | } |
431 | if activitySuMoneyStatistics == nil { | 466 | if activitySuMoneyStatistics == nil { |
432 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | 467 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业") |
433 | } | 468 | } |
434 | activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) | 469 | activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) |
435 | if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash { | 470 | if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash { |
436 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金") | 471 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金") |
437 | } | 472 | } |
438 | - // 计算系统平均兑换汇率 | 473 | + // 计算系统平均兑换汇率并更新现金池 |
439 | var employeeDao *dao.EmployeeDao | 474 | var employeeDao *dao.EmployeeDao |
440 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | 475 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ |
441 | "transactionContext": transactionContext, | 476 | "transactionContext": transactionContext, |
@@ -452,7 +487,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -452,7 +487,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
452 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | 487 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") |
453 | } | 488 | } |
454 | systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) | 489 | systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) |
455 | - //systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) | ||
456 | systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId) | 490 | systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId) |
457 | if err != nil { | 491 | if err != nil { |
458 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 492 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -462,14 +496,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -462,14 +496,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
462 | } | 496 | } |
463 | systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) | 497 | systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) |
464 | systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) | 498 | systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) |
465 | - rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率 | ||
466 | - // 更新现金池 | 499 | + // 平均兑换汇率 |
500 | + var rate float64 | ||
501 | + if systemExchangedSuMoney == 0 { | ||
502 | + rate = 0 | ||
503 | + } else { | ||
504 | + rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) | ||
505 | + } | ||
506 | + // TODO 更新现金池 | ||
467 | updateCashPoolCommand := &command.UpdateCashPoolCommand{ | 507 | updateCashPoolCommand := &command.UpdateCashPoolCommand{ |
468 | CashPoolId: cashPools[0].CashPoolId, | 508 | CashPoolId: cashPools[0].CashPoolId, |
469 | - //ExchangedSuMoney: systemExchangedSuMoney, | ||
470 | ExchangedCash: systemExchangedCash, | 509 | ExchangedCash: systemExchangedCash, |
471 | UnExchangeCash: systemUnExchangeCash, | 510 | UnExchangeCash: systemUnExchangeCash, |
472 | - //UnExchangeSuMoney: systemUnExchangeSuMoney, | ||
473 | Rate: rate, | 511 | Rate: rate, |
474 | } | 512 | } |
475 | if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { | 513 | if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { |
@@ -482,8 +520,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -482,8 +520,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
482 | if cashPoolUpdated == nil { | 520 | if cashPoolUpdated == nil { |
483 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 521 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
484 | } | 522 | } |
485 | - | ||
486 | - // TODO 更新兑换清单中已兑换现金值 | 523 | + // TODO 批量更新兑换清单中已兑换现金值 |
487 | 524 | ||
488 | } | 525 | } |
489 | 526 | ||
@@ -621,11 +658,37 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC | @@ -621,11 +658,37 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC | ||
621 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) | 658 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) |
622 | } | 659 | } |
623 | 660 | ||
624 | - // TODO 判断清单中现金总额超过现金池未兑换现金时创建失败,提示:“已超过投入现金池的未兑换现金” | 661 | + // 判断清单中现金总额超过平台未兑换现金 |
662 | + var cashPoolDao *dao.CashPoolDao | ||
663 | + if value, err := factory.CreateCashPoolDao(map[string]interface{}{ | ||
664 | + "transactionContext": transactionContext, | ||
665 | + }); err != nil { | ||
666 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
667 | + } else { | ||
668 | + cashPoolDao = value | ||
669 | + } | ||
670 | + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId) | ||
671 | + if err != nil { | ||
672 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
673 | + } | ||
674 | + if activitySuMoneyStatistics == nil { | ||
675 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业") | ||
676 | + } | ||
677 | + activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) | ||
678 | + var employeeDao *dao.EmployeeDao | ||
679 | + if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | ||
680 | + "transactionContext": transactionContext, | ||
681 | + }); err != nil { | ||
682 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
683 | + } else { | ||
684 | + employeeDao = value | ||
685 | + } | ||
686 | + systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId) | ||
687 | + if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) { | ||
688 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金") | ||
689 | + } | ||
625 | 690 | ||
626 | // TODO 更新现金池 | 691 | // TODO 更新现金池 |
627 | - // 获取现金池 | ||
628 | - // 更新现金池 | ||
629 | 692 | ||
630 | if err := transactionContext.CommitTransaction(); err != nil { | 693 | if err := transactionContext.CommitTransaction(); err != nil { |
631 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 694 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -721,6 +784,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | @@ -721,6 +784,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | ||
721 | defer func() { | 784 | defer func() { |
722 | transactionContext.RollbackTransaction() | 785 | transactionContext.RollbackTransaction() |
723 | }() | 786 | }() |
787 | + // 移除兑换素币清单 | ||
724 | var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository | 788 | var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository |
725 | if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ | 789 | if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ |
726 | "transactionContext": transactionContext, | 790 | "transactionContext": transactionContext, |
@@ -736,12 +800,11 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | @@ -736,12 +800,11 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | ||
736 | if person == nil { | 800 | if person == nil { |
737 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId))) | 801 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId))) |
738 | } | 802 | } |
739 | - // 移除兑换素币清单 | ||
740 | personDeleted, err := exchangeCashPersonListRepository.Remove(person) | 803 | personDeleted, err := exchangeCashPersonListRepository.Remove(person) |
741 | if err != nil { | 804 | if err != nil { |
742 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 805 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
743 | } | 806 | } |
744 | - // 生成素币流水,更新个人素币 | 807 | + // 生成素币流水,还原个人素币值 |
745 | var operationSuMoneyService service.OperationSuMoneyService | 808 | var operationSuMoneyService service.OperationSuMoneyService |
746 | if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ | 809 | if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{ |
747 | "transactionContext": transactionContext, | 810 | "transactionContext": transactionContext, |
@@ -764,7 +827,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | @@ -764,7 +827,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC | ||
764 | if task == nil { | 827 | if task == nil { |
765 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) | 828 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) |
766 | } | 829 | } |
767 | - // 更新兑换活动 | 830 | + // 更新兑换活动兑换情况 |
768 | var exchangeCashActivityRepository domain.ExchangeActivityRepository | 831 | var exchangeCashActivityRepository domain.ExchangeActivityRepository |
769 | if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ | 832 | if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ |
770 | "transactionContext": transactionContext, | 833 | "transactionContext": transactionContext, |
@@ -878,8 +941,35 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | @@ -878,8 +941,35 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | ||
878 | if activityUpdated == nil { | 941 | if activityUpdated == nil { |
879 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) | 942 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) |
880 | } | 943 | } |
881 | - | ||
882 | - // TODO 判断现金池未兑换现金 | 944 | + // 判断是否超过平台未兑换现金 |
945 | + var cashPoolDao *dao.CashPoolDao | ||
946 | + if value, err := factory.CreateCashPoolDao(map[string]interface{}{ | ||
947 | + "transactionContext": transactionContext, | ||
948 | + }); err != nil { | ||
949 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
950 | + } else { | ||
951 | + cashPoolDao = value | ||
952 | + } | ||
953 | + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId) | ||
954 | + if err != nil { | ||
955 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
956 | + } | ||
957 | + if activitySuMoneyStatistics == nil { | ||
958 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业") | ||
959 | + } | ||
960 | + activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64) | ||
961 | + var employeeDao *dao.EmployeeDao | ||
962 | + if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | ||
963 | + "transactionContext": transactionContext, | ||
964 | + }); err != nil { | ||
965 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
966 | + } else { | ||
967 | + employeeDao = value | ||
968 | + } | ||
969 | + systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId) | ||
970 | + if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) { | ||
971 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金") | ||
972 | + } | ||
883 | 973 | ||
884 | // TODO 更新现金池 | 974 | // TODO 更新现金池 |
885 | 975 |
-
请 注册 或 登录 后发表评论