|
@@ -1266,8 +1266,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1266,8 +1266,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1266
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
1266
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
1267
|
}
|
1267
|
}
|
1268
|
|
1268
|
|
1269
|
- fmt.Print(person.EmployeeInfo.Uid, "\n")
|
|
|
1270
|
-
|
|
|
1271
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1269
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1272
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
1270
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
1273
|
"transactionContext": transactionContext,
|
1271
|
"transactionContext": transactionContext,
|
|
@@ -1354,7 +1352,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1354,7 +1352,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1354
|
}
|
1352
|
}
|
1355
|
|
1353
|
|
1356
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
1354
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
1357
|
- systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1355
|
+ //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1358
|
|
1356
|
|
1359
|
// 获取平台素币状况
|
1357
|
// 获取平台素币状况
|
1360
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1358
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
@@ -1398,10 +1396,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1398,10 +1396,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1398
|
|
1396
|
|
1399
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1397
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1400
|
CashPoolId: cashPools[0].CashPoolId,
|
1398
|
CashPoolId: cashPools[0].CashPoolId,
|
1401
|
- ExchangedCash: systemExchangedCash - person.ExchangedCash,
|
|
|
1402
|
- UnExchangeCash: systemUnExchangeCash + person.ExchangedCash,
|
1399
|
+ ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
1400
|
+ UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
1403
|
Rate: newRate,
|
1401
|
Rate: newRate,
|
1404
|
- ExchangedSuMoney: systemExchangedSuMoney - person.ExchangedSuMoney,
|
1402
|
+ ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
1405
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1403
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1406
|
}
|
1404
|
}
|
1407
|
|
1405
|
|
|
@@ -1481,15 +1479,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1481,15 +1479,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1481
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
1479
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
1482
|
}
|
1480
|
}
|
1483
|
|
1481
|
|
1484
|
- // 更新兑换清单,个人已兑换现金计算
|
|
|
1485
|
- updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
1486
|
-
|
|
|
1487
|
- fmt.Print(updateExchangeCashPersonCommand.ExchangedCash, "\n")
|
|
|
1488
|
-
|
|
|
1489
|
- if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
1490
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1491
|
- }
|
|
|
1492
|
-
|
|
|
1493
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1482
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1494
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1483
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1495
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1484
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
@@ -1499,11 +1488,56 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1499,11 +1488,56 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1499
|
ExchangeRate: activityFound.Rate,
|
1488
|
ExchangeRate: activityFound.Rate,
|
1500
|
}
|
1489
|
}
|
1501
|
|
1490
|
|
|
|
1491
|
+ // 更新兑换清单,个人已兑换现金计算
|
|
|
1492
|
+ updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
1493
|
+
|
|
|
1494
|
+ if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
|
|
1495
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1496
|
+ }
|
|
|
1497
|
+
|
|
|
1498
|
+ personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
|
|
1499
|
+ if err != nil {
|
|
|
1500
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1501
|
+ }
|
|
|
1502
|
+
|
|
|
1503
|
+ // 更新员工素币,生成素币兑换流水记录
|
|
|
1504
|
+ var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1505
|
+ if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1506
|
+ "transactionContext": transactionContext,
|
|
|
1507
|
+ }); err != nil {
|
|
|
1508
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1509
|
+ } else {
|
|
|
1510
|
+ operationSuMoneyService = value
|
|
|
1511
|
+ }
|
|
|
1512
|
+
|
|
|
1513
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
1514
|
+ Uid: person.EmployeeInfo.Uid,
|
|
|
1515
|
+ Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
1516
|
+ SuMoney: 0,
|
|
|
1517
|
+ OperationType: 0,
|
|
|
1518
|
+ OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
|
|
1519
|
+ }
|
|
|
1520
|
+
|
|
|
1521
|
+ if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
|
|
1522
|
+ operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
1523
|
+ operationSuMoneyCommand.OperationType = 1
|
|
|
1524
|
+ } else {
|
|
|
1525
|
+ operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
1526
|
+ operationSuMoneyCommand.OperationType = 3
|
|
|
1527
|
+ }
|
|
|
1528
|
+
|
|
|
1529
|
+ task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
1530
|
+ if err != nil {
|
|
|
1531
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1532
|
+ }
|
|
|
1533
|
+ if task == nil {
|
|
|
1534
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
1535
|
+ }
|
|
|
1536
|
+
|
1502
|
// 更新兑换活动
|
1537
|
// 更新兑换活动
|
1503
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1538
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1504
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1539
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1505
|
}
|
1540
|
}
|
1506
|
-
|
|
|
1507
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1541
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1508
|
if err != nil {
|
1542
|
if err != nil {
|
1509
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1543
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1512,6 +1546,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1512,6 +1546,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1512
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
1546
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
1513
|
}
|
1547
|
}
|
1514
|
|
1548
|
|
|
|
1549
|
+ // 更新现金池
|
1515
|
var cashPoolDao *dao.CashPoolDao
|
1550
|
var cashPoolDao *dao.CashPoolDao
|
1516
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
1551
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
1517
|
"transactionContext": transactionContext,
|
1552
|
"transactionContext": transactionContext,
|
|
@@ -1543,44 +1578,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1543,44 +1578,16 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1543
|
}
|
1578
|
}
|
1544
|
|
1579
|
|
1545
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1580
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1546
|
-
|
|
|
1547
|
- // 判断是否超过平台未兑换现金
|
|
|
1548
|
- if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
1549
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
1550
|
- }
|
|
|
1551
|
-
|
|
|
1552
|
- operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
1553
|
- Uid: person.EmployeeInfo.Uid,
|
|
|
1554
|
- Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
1555
|
- SuMoney: 0,
|
|
|
1556
|
- OperationType: 0,
|
|
|
1557
|
- OperationDescription: activityUpdated.ExchangeActivityName + "素币调整",
|
|
|
1558
|
- }
|
|
|
1559
|
-
|
|
|
1560
|
- if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
|
|
1561
|
- operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
1562
|
- operationSuMoneyCommand.OperationType = 1
|
|
|
1563
|
- } else {
|
|
|
1564
|
- operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
|
|
1565
|
- operationSuMoneyCommand.OperationType = 3
|
|
|
1566
|
- }
|
|
|
1567
|
-
|
|
|
1568
|
- var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1569
|
- if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1570
|
- "transactionContext": transactionContext,
|
|
|
1571
|
- }); err != nil {
|
|
|
1572
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1573
|
- } else {
|
|
|
1574
|
- operationSuMoneyService = value
|
|
|
1575
|
- }
|
|
|
1576
|
-
|
|
|
1577
|
- // 更新员工素币,生成素币兑换流水记录
|
|
|
1578
|
- task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
1579
|
if err != nil {
|
1581
|
if err != nil {
|
1580
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1582
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1581
|
}
|
1583
|
}
|
1582
|
- if task == nil {
|
|
|
1583
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1584
|
+ if systemCashStatistics == nil {
|
|
|
1585
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1586
|
+ }
|
|
|
1587
|
+
|
|
|
1588
|
+ // 判断是否超过平台未兑换现金
|
|
|
1589
|
+ if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
1590
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
1584
|
}
|
1591
|
}
|
1585
|
|
1592
|
|
1586
|
// 重新获取系统现金兑换情况
|
1593
|
// 重新获取系统现金兑换情况
|
|
@@ -1593,7 +1600,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1593,7 +1600,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1593
|
}
|
1600
|
}
|
1594
|
|
1601
|
|
1595
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
1602
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
1596
|
- systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
1603
|
+ //systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
1597
|
|
1604
|
|
1598
|
// 获取平台素币状况
|
1605
|
// 获取平台素币状况
|
1599
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1606
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
@@ -1637,10 +1644,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1637,10 +1644,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1637
|
|
1644
|
|
1638
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1645
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1639
|
CashPoolId: cashPools[0].CashPoolId,
|
1646
|
CashPoolId: cashPools[0].CashPoolId,
|
1640
|
- ExchangedCash: systemUnExchangeCash,
|
|
|
1641
|
- UnExchangeCash: systemUnExchangeCash,
|
1647
|
+ ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
1648
|
+ UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1642
|
Rate: newRate,
|
1649
|
Rate: newRate,
|
1643
|
- ExchangedSuMoney: systemExchangedSuMoney,
|
1650
|
+ ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1644
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1651
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1645
|
}
|
1652
|
}
|
1646
|
|
1653
|
|
|
@@ -1656,15 +1663,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1656,15 +1663,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1656
|
if cashPoolUpdated == nil {
|
1663
|
if cashPoolUpdated == nil {
|
1657
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1664
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1658
|
}
|
1665
|
}
|
1659
|
-
|
|
|
1660
|
- if personUpdated, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
|
|
1661
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1662
|
- } else {
|
|
|
1663
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1664
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1665
|
- }
|
|
|
1666
|
- return personUpdated, nil
|
1666
|
+
|
|
|
1667
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1668
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1667
|
}
|
1669
|
}
|
|
|
1670
|
+ return personUpdated, nil
|
1668
|
}
|
1671
|
}
|
1669
|
|
1672
|
|
1670
|
// 根据id获取兑换清单
|
1673
|
// 根据id获取兑换清单
|