|
@@ -498,8 +498,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
@@ -498,8 +498,8 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
498
|
"companyId": activity.CompanyId,
|
498
|
"companyId": activity.CompanyId,
|
499
|
"exchangedCash": activity.ExchangedCash,
|
499
|
"exchangedCash": activity.ExchangedCash,
|
500
|
"exchangedSuMoney": activity.ExchangedSuMoney,
|
500
|
"exchangedSuMoney": activity.ExchangedSuMoney,
|
501
|
- "deadline": activity.Deadline.Unix(),
|
|
|
502
|
- "countDown": activity.CountDown,
|
501
|
+ "deadline": activity.Deadline.UnixNano() / 1e6,
|
|
|
502
|
+ "countdown": activity.CountDown,
|
503
|
"rate": activity.Rate,
|
503
|
"rate": activity.Rate,
|
504
|
"createTime": "2020-11-13T09:32:45.259856Z",
|
504
|
"createTime": "2020-11-13T09:32:45.259856Z",
|
505
|
}
|
505
|
}
|
|
@@ -1231,9 +1231,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
@@ -1231,9 +1231,9 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
1231
|
}
|
1231
|
}
|
1232
|
}
|
1232
|
}
|
1233
|
|
1233
|
|
1234
|
-// 移除兑换素币清单
|
|
|
1235
|
-func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
|
|
|
1236
|
- if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
1234
|
+// 更新兑换清单
|
|
|
1235
|
+func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
1236
|
+ if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
1237
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
1237
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
1238
|
}
|
1238
|
}
|
1239
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
1239
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
@@ -1247,7 +1247,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1247,7 +1247,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1247
|
transactionContext.RollbackTransaction()
|
1247
|
transactionContext.RollbackTransaction()
|
1248
|
}()
|
1248
|
}()
|
1249
|
|
1249
|
|
1250
|
- // 移除兑换素币清单
|
|
|
1251
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1250
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1252
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1251
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1253
|
"transactionContext": transactionContext,
|
1252
|
"transactionContext": transactionContext,
|
|
@@ -1257,13 +1256,13 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1257,13 +1256,13 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1257
|
exchangeCashPersonListRepository = value
|
1256
|
exchangeCashPersonListRepository = value
|
1258
|
}
|
1257
|
}
|
1259
|
|
1258
|
|
1260
|
- // 获取待删除人员
|
|
|
1261
|
- person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
1259
|
+ // 获取兑换清单
|
|
|
1260
|
+ person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
|
1262
|
if err != nil {
|
1261
|
if err != nil {
|
1263
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1262
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1264
|
}
|
1263
|
}
|
1265
|
if person == nil {
|
1264
|
if person == nil {
|
1266
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
1265
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
1267
|
}
|
1266
|
}
|
1268
|
|
1267
|
|
1269
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1268
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
@@ -1286,27 +1285,26 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1286,27 +1285,26 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1286
|
|
1285
|
|
1287
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1286
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1288
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1287
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1289
|
- ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
1290
|
- ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
1288
|
+ ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
1289
|
+ ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1291
|
Deadline: activityFound.Deadline,
|
1290
|
Deadline: activityFound.Deadline,
|
1292
|
CountDown: activityFound.CountDown,
|
1291
|
CountDown: activityFound.CountDown,
|
1293
|
ExchangeRate: activityFound.Rate,
|
1292
|
ExchangeRate: activityFound.Rate,
|
1294
|
}
|
1293
|
}
|
1295
|
|
1294
|
|
1296
|
- // 更新兑换活动
|
|
|
1297
|
- if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1295
|
+ // 更新兑换清单,个人已兑换现金计算
|
|
|
1296
|
+ updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
1297
|
+
|
|
|
1298
|
+ if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
1298
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1299
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1299
|
}
|
1300
|
}
|
1300
|
|
1301
|
|
1301
|
- activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1302
|
+ personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
1302
|
if err != nil {
|
1303
|
if err != nil {
|
1303
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1304
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1304
|
}
|
1305
|
}
|
1305
|
- if activityUpdated == nil {
|
|
|
1306
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
1307
|
- }
|
|
|
1308
|
|
1306
|
|
1309
|
- // 还原个人素币值,生成素币流水,描述修改成和活动相关
|
1307
|
+ // 更新员工素币,生成素币兑换流水记录
|
1310
|
var operationSuMoneyService service.OperationSuMoneyService
|
1308
|
var operationSuMoneyService service.OperationSuMoneyService
|
1311
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
1309
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
1312
|
"transactionContext": transactionContext,
|
1310
|
"transactionContext": transactionContext,
|
|
@@ -1316,14 +1314,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1316,14 +1314,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1316
|
operationSuMoneyService = value
|
1314
|
operationSuMoneyService = value
|
1317
|
}
|
1315
|
}
|
1318
|
|
1316
|
|
1319
|
- operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1317
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1320
|
Uid: person.EmployeeInfo.Uid,
|
1318
|
Uid: person.EmployeeInfo.Uid,
|
1321
|
- Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
1322
|
- SuMoney: person.ExchangedSuMoney,
|
|
|
1323
|
- OperationType: 1, // 增加素币
|
1319
|
+ Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
1320
|
+ SuMoney: 0,
|
|
|
1321
|
+ OperationType: 0,
|
1324
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
1322
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
1325
|
}
|
1323
|
}
|
1326
|
|
1324
|
|
|
|
1325
|
+ if updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney > 0 {
|
|
|
1326
|
+ operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
1327
|
+ operationSuMoneyCommand.OperationType = 1
|
|
|
1328
|
+ } else {
|
|
|
1329
|
+ operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - personUpdated.ExchangedSuMoney)
|
|
|
1330
|
+ operationSuMoneyCommand.OperationType = 3
|
|
|
1331
|
+ }
|
|
|
1332
|
+
|
1327
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
1333
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
1328
|
if err != nil {
|
1334
|
if err != nil {
|
1329
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1335
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1332,7 +1338,40 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1332,7 +1338,40 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1332
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1338
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1333
|
}
|
1339
|
}
|
1334
|
|
1340
|
|
|
|
1341
|
+ // 更新兑换活动
|
|
|
1342
|
+ if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
1343
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1344
|
+ }
|
|
|
1345
|
+ activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
1346
|
+ if err != nil {
|
|
|
1347
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1348
|
+ }
|
|
|
1349
|
+ if activityUpdated == nil {
|
|
|
1350
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
1351
|
+ }
|
|
|
1352
|
+
|
1335
|
// 更新现金池
|
1353
|
// 更新现金池
|
|
|
1354
|
+ var cashPoolDao *dao.CashPoolDao
|
|
|
1355
|
+ if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
1356
|
+ "transactionContext": transactionContext,
|
|
|
1357
|
+ }); err != nil {
|
|
|
1358
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1359
|
+ } else {
|
|
|
1360
|
+ cashPoolDao = value
|
|
|
1361
|
+ }
|
|
|
1362
|
+
|
|
|
1363
|
+ // 统计活动已兑换素币
|
|
|
1364
|
+ activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
1365
|
+ if err != nil {
|
|
|
1366
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1367
|
+ }
|
|
|
1368
|
+ if activitySuMoneyStatistics == nil {
|
|
|
1369
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
1370
|
+ }
|
|
|
1371
|
+
|
|
|
1372
|
+ activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
1373
|
+
|
|
|
1374
|
+ // 统计平台现金兑换情况
|
1336
|
var employeeDao *dao.EmployeeDao
|
1375
|
var employeeDao *dao.EmployeeDao
|
1337
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1376
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1338
|
"transactionContext": transactionContext,
|
1377
|
"transactionContext": transactionContext,
|
|
@@ -1342,7 +1381,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1342,7 +1381,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1342
|
employeeDao = value
|
1381
|
employeeDao = value
|
1343
|
}
|
1382
|
}
|
1344
|
|
1383
|
|
1345
|
- // 获取平台现金状况
|
|
|
1346
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1384
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1347
|
if err != nil {
|
1385
|
if err != nil {
|
1348
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1386
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1351,8 +1389,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1351,8 +1389,22 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1351
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1389
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1352
|
}
|
1390
|
}
|
1353
|
|
1391
|
|
1354
|
- systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
1355
|
- //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1392
|
+ // 判断是否超过平台未兑换现金
|
|
|
1393
|
+ if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
1394
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
1395
|
+ }
|
|
|
1396
|
+
|
|
|
1397
|
+ // 重新获取系统现金兑换情况
|
|
|
1398
|
+ newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
1399
|
+ if err != nil {
|
|
|
1400
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1401
|
+ }
|
|
|
1402
|
+ if systemCashStatistics == nil {
|
|
|
1403
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1404
|
+ }
|
|
|
1405
|
+
|
|
|
1406
|
+ systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
|
|
1407
|
+ //systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
1356
|
|
1408
|
|
1357
|
// 获取平台素币状况
|
1409
|
// 获取平台素币状况
|
1358
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1410
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
@@ -1396,13 +1448,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1396,13 +1448,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1396
|
|
1448
|
|
1397
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1449
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1398
|
CashPoolId: cashPools[0].CashPoolId,
|
1450
|
CashPoolId: cashPools[0].CashPoolId,
|
1399
|
- ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
1400
|
- UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
1451
|
+ ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
1452
|
+ UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1401
|
Rate: newRate,
|
1453
|
Rate: newRate,
|
1402
|
- ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
1454
|
+ ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1403
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1455
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1404
|
}
|
1456
|
}
|
1405
|
|
1457
|
|
|
|
1458
|
+ fmt.Print(updateCashPoolCommand.ExchangedCash, "\n")
|
|
|
1459
|
+
|
1406
|
// 更新现金池
|
1460
|
// 更新现金池
|
1407
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1461
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1408
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1462
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
@@ -1416,20 +1470,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1416,20 +1470,15 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1416
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1470
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1417
|
}
|
1471
|
}
|
1418
|
|
1472
|
|
1419
|
- personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
1420
|
- if err != nil {
|
|
|
1421
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1422
|
- } else {
|
|
|
1423
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1424
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1425
|
- }
|
|
|
1426
|
- return personDeleted, nil
|
1473
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1474
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1427
|
}
|
1475
|
}
|
|
|
1476
|
+ return personUpdated, nil
|
1428
|
}
|
1477
|
}
|
1429
|
|
1478
|
|
1430
|
-// 更新兑换清单
|
|
|
1431
|
-func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeCashPersonCommand *command.UpdateExchangeCashPersonCommand) (interface{}, error) {
|
|
|
1432
|
- if err := updateExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
1479
|
+// 移除兑换素币清单
|
|
|
1480
|
+func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeCashPersonCommand *command.RemoveExchangeCashPersonCommand) (interface{}, error) {
|
|
|
1481
|
+ if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
|
1433
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
1482
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
1434
|
}
|
1483
|
}
|
1435
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
1484
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
@@ -1443,6 +1492,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1443,6 +1492,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1443
|
transactionContext.RollbackTransaction()
|
1492
|
transactionContext.RollbackTransaction()
|
1444
|
}()
|
1493
|
}()
|
1445
|
|
1494
|
|
|
|
1495
|
+ // 移除兑换素币清单
|
1446
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1496
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1447
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1497
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1448
|
"transactionContext": transactionContext,
|
1498
|
"transactionContext": transactionContext,
|
|
@@ -1452,13 +1502,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1452,13 +1502,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1452
|
exchangeCashPersonListRepository = value
|
1502
|
exchangeCashPersonListRepository = value
|
1453
|
}
|
1503
|
}
|
1454
|
|
1504
|
|
1455
|
- // 获取兑换清单
|
|
|
1456
|
- person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": updateExchangeCashPersonCommand.ListId})
|
1505
|
+ // 获取待删除人员
|
|
|
1506
|
+ person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": removeExchangeCashPersonCommand.ListId})
|
1457
|
if err != nil {
|
1507
|
if err != nil {
|
1458
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1508
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1459
|
}
|
1509
|
}
|
1460
|
if person == nil {
|
1510
|
if person == nil {
|
1461
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
1511
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
1462
|
}
|
1512
|
}
|
1463
|
|
1513
|
|
1464
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1514
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
|
@@ -1481,26 +1531,27 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1481,26 +1531,27 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1481
|
|
1531
|
|
1482
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1532
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1483
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1533
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1484
|
- ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
|
|
1485
|
- ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1534
|
+ ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
|
|
1535
|
+ ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
1486
|
Deadline: activityFound.Deadline,
|
1536
|
Deadline: activityFound.Deadline,
|
1487
|
CountDown: activityFound.CountDown,
|
1537
|
CountDown: activityFound.CountDown,
|
1488
|
ExchangeRate: activityFound.Rate,
|
1538
|
ExchangeRate: activityFound.Rate,
|
1489
|
}
|
1539
|
}
|
1490
|
|
1540
|
|
1491
|
- // 更新兑换清单,个人已兑换现金计算
|
|
|
1492
|
- updateExchangeCashPersonCommand.ExchangedCash = updateExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate
|
|
|
1493
|
-
|
|
|
1494
|
- if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
1541
|
+ // 更新兑换活动
|
|
|
1542
|
+ if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1495
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1543
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1496
|
}
|
1544
|
}
|
1497
|
|
1545
|
|
1498
|
- personUpdated, err := exchangeCashPersonListRepository.Save(person)
|
1546
|
+ activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1499
|
if err != nil {
|
1547
|
if err != nil {
|
1500
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1548
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1501
|
}
|
1549
|
}
|
|
|
1550
|
+ if activityUpdated == nil {
|
|
|
1551
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
1552
|
+ }
|
1502
|
|
1553
|
|
1503
|
- // 更新员工素币,生成素币兑换流水记录
|
1554
|
+ // 还原个人素币值,生成素币流水,描述修改成和活动相关
|
1504
|
var operationSuMoneyService service.OperationSuMoneyService
|
1555
|
var operationSuMoneyService service.OperationSuMoneyService
|
1505
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
1556
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
1506
|
"transactionContext": transactionContext,
|
1557
|
"transactionContext": transactionContext,
|
|
@@ -1510,22 +1561,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1510,22 +1561,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1510
|
operationSuMoneyService = value
|
1561
|
operationSuMoneyService = value
|
1511
|
}
|
1562
|
}
|
1512
|
|
1563
|
|
1513
|
- operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1564
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1514
|
Uid: person.EmployeeInfo.Uid,
|
1565
|
Uid: person.EmployeeInfo.Uid,
|
1515
|
- Operator: updateExchangeCashPersonCommand.Operator,
|
|
|
1516
|
- SuMoney: 0,
|
|
|
1517
|
- OperationType: 0,
|
1566
|
+ Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
1567
|
+ SuMoney: person.ExchangedSuMoney,
|
|
|
1568
|
+ OperationType: 1, // 增加素币
|
1518
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
1569
|
OperationDescription: activityFound.ExchangeActivityName + "素币调整",
|
1519
|
}
|
1570
|
}
|
1520
|
|
1571
|
|
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)
|
1572
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
1530
|
if err != nil {
|
1573
|
if err != nil {
|
1531
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1574
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1534,40 +1577,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1534,40 +1577,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1534
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1577
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1535
|
}
|
1578
|
}
|
1536
|
|
1579
|
|
1537
|
- // 更新兑换活动
|
|
|
1538
|
- if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
1539
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
1540
|
- }
|
|
|
1541
|
- activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
|
|
1542
|
- if err != nil {
|
|
|
1543
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1544
|
- }
|
|
|
1545
|
- if activityUpdated == nil {
|
|
|
1546
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
|
|
1547
|
- }
|
|
|
1548
|
-
|
|
|
1549
|
// 更新现金池
|
1580
|
// 更新现金池
|
1550
|
- var cashPoolDao *dao.CashPoolDao
|
|
|
1551
|
- if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
|
1552
|
- "transactionContext": transactionContext,
|
|
|
1553
|
- }); err != nil {
|
|
|
1554
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1555
|
- } else {
|
|
|
1556
|
- cashPoolDao = value
|
|
|
1557
|
- }
|
|
|
1558
|
-
|
|
|
1559
|
- // 统计活动已兑换素币
|
|
|
1560
|
- activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
|
|
1561
|
- if err != nil {
|
|
|
1562
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1563
|
- }
|
|
|
1564
|
- if activitySuMoneyStatistics == nil {
|
|
|
1565
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
|
|
1566
|
- }
|
|
|
1567
|
-
|
|
|
1568
|
- activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
1569
|
-
|
|
|
1570
|
- // 统计平台现金兑换情况
|
|
|
1571
|
var employeeDao *dao.EmployeeDao
|
1581
|
var employeeDao *dao.EmployeeDao
|
1572
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1582
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1573
|
"transactionContext": transactionContext,
|
1583
|
"transactionContext": transactionContext,
|
|
@@ -1577,6 +1587,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1577,6 +1587,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1577
|
employeeDao = value
|
1587
|
employeeDao = value
|
1578
|
}
|
1588
|
}
|
1579
|
|
1589
|
|
|
|
1590
|
+ // 获取平台现金状况
|
1580
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1591
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1581
|
if err != nil {
|
1592
|
if err != nil {
|
1582
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1593
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1585,22 +1596,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1585,22 +1596,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1585
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1596
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1586
|
}
|
1597
|
}
|
1587
|
|
1598
|
|
1588
|
- // 判断是否超过平台未兑换现金
|
|
|
1589
|
- if activitySuMoney * activityFound.Rate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
|
|
1590
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
|
|
1591
|
- }
|
|
|
1592
|
-
|
|
|
1593
|
- // 重新获取系统现金兑换情况
|
|
|
1594
|
- newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
|
|
1595
|
- if err != nil {
|
|
|
1596
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1597
|
- }
|
|
|
1598
|
- if systemCashStatistics == nil {
|
|
|
1599
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
1600
|
- }
|
|
|
1601
|
-
|
|
|
1602
|
- systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
|
|
1603
|
- //systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
1599
|
+ systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
|
|
1600
|
+ //systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1604
|
|
1601
|
|
1605
|
// 获取平台素币状况
|
1602
|
// 获取平台素币状况
|
1606
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1603
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
|
@@ -1644,10 +1641,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1644,10 +1641,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1644
|
|
1641
|
|
1645
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1642
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1646
|
CashPoolId: cashPools[0].CashPoolId,
|
1643
|
CashPoolId: cashPools[0].CashPoolId,
|
1647
|
- ExchangedCash: cashPools[0].ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
|
|
1648
|
- UnExchangeCash: cashPools[0].UnExchangeCash - (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1644
|
+ ExchangedCash: cashPools[0].ExchangedCash - person.ExchangedCash,
|
|
|
1645
|
+ UnExchangeCash: cashPools[0].UnExchangeCash + person.ExchangedCash,
|
1649
|
Rate: newRate,
|
1646
|
Rate: newRate,
|
1650
|
- ExchangedSuMoney: cashPools[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1647
|
+ ExchangedSuMoney: cashPools[0].ExchangedSuMoney - person.ExchangedSuMoney,
|
1651
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1648
|
UnExchangeSuMoney: systemUnExchangeSuMoney,
|
1652
|
}
|
1649
|
}
|
1653
|
|
1650
|
|
|
@@ -1664,10 +1661,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1664,10 +1661,15 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1664
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1661
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1665
|
}
|
1662
|
}
|
1666
|
|
1663
|
|
1667
|
- if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1668
|
- return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1664
|
+ personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
1665
|
+ if err != nil {
|
|
|
1666
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1667
|
+ } else {
|
|
|
1668
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
1669
|
+ return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
1670
|
+ }
|
|
|
1671
|
+ return personDeleted, nil
|
1669
|
}
|
1672
|
}
|
1670
|
- return personUpdated, nil
|
|
|
1671
|
}
|
1673
|
}
|
1672
|
|
1674
|
|
1673
|
// 根据id获取兑换清单
|
1675
|
// 根据id获取兑换清单
|