作者 陈志颖

refactor:整理导入素币兑换清单流程

@@ -1184,11 +1184,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1184,11 +1184,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1184 return personUpdated, nil 1184 return personUpdated, nil
1185 } 1185 }
1186 1186
1187 -// 新增导入兑换素币清单 1187 +// 导入新增兑换素币清单
1188 func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) { 1188 func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
1189 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil { 1189 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
1190 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1190 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1191 } 1191 }
  1192 +
1192 transactionContext, err := factory.CreateTransactionContext(nil) 1193 transactionContext, err := factory.CreateTransactionContext(nil)
1193 if err != nil { 1194 if err != nil {
1194 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1195 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1265,6 +1266,20 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1265,6 +1266,20 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1265 if err != nil { 1266 if err != nil {
1266 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1267 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1267 } 1268 }
  1269 + if activityFound == nil {
  1270 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR,"当前未创建任务兑换活动")
  1271 + }
  1272 +
  1273 + // 获取当前公司现金池
  1274 + _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
  1275 + "companyId": activityFound.CompanyId,
  1276 + })
  1277 + if err != nil {
  1278 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1279 + }
  1280 + if len(cashPoolsFound) == 0 {
  1281 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")
  1282 + }
1268 1283
1269 // 获取员工查询条件 1284 // 获取员工查询条件
1270 getEmployee := map[string]interface{}{ 1285 getEmployee := map[string]interface{}{
@@ -1281,11 +1296,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1281,11 +1296,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1281 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工") 1296 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
1282 } 1297 }
1283 1298
1284 - // 判断该员工兑换的素币是否超过本人持有的素币  
1285 - if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {  
1286 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")  
1287 - }  
1288 -  
1289 // 判断当前员工是否已经在素币兑换清单中 1299 // 判断当前员工是否已经在素币兑换清单中
1290 _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{ 1300 _, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
1291 "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount, 1301 "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
@@ -1297,17 +1307,25 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1297,17 +1307,25 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1297 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1307 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1298 } 1308 }
1299 1309
1300 - if len(peopleFound) > 0 { // 追加素币兑换或撤回素币兑换  
1301 - // 获取兑换清单员工已兑换素币 1310 + // 判断该员工兑换的素币是否超过本人持有的素币
  1311 + if employeeFound.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
  1312 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
  1313 + }
  1314 +
  1315 + if len(peopleFound) > 0 { // 当前导入员工在素币兑换清单中,判断追加素币兑换或撤回素币兑换
  1316 + // 获取当前员工已兑换素币
1302 personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney 1317 personFoundExchangedSuMoney := peopleFound[0].ExchangedSuMoney
1303 1318
1304 - fmt.Print(createExchangeCashPersonCommand.ExchangedSuMoney, "\n")  
1305 - fmt.Print(personFoundExchangedSuMoney, "\n") 1319 + // 获取当前兑换员工已兑换现金
  1320 + //personFoundExchangedCash := peopleFound[0].ExchangedCash
1306 1321
1307 - if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币  
1308 - // 减量 1322 + if createExchangeCashPersonCommand.ExchangedSuMoney < personFoundExchangedSuMoney { // 当前兑换的素币小于本人已兑换素币,撤回兑换素币
  1323 + // 素币减量
1309 suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney 1324 suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney
1310 1325
  1326 + // 现金减量
  1327 + cashDecrement := suMoneyDecrement * activityFound.Rate
  1328 +
1311 // 更新兑换素币清单命令 1329 // 更新兑换素币清单命令
1312 updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{ 1330 updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{
1313 ListId: peopleFound[0].ListId, 1331 ListId: peopleFound[0].ListId,
@@ -1329,8 +1347,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1329,8 +1347,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1329 // 更新素币兑换活动命令 1347 // 更新素币兑换活动命令
1330 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1348 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1331 ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId, 1349 ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
1332 - ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),  
1333 - ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate, 1350 + ExchangedSuMoney: activityFound.ExchangedSuMoney - suMoneyDecrement,
  1351 + ExchangedCash: activityFound.ExchangedCash - cashDecrement,
1334 Deadline: activityFound.Deadline, 1352 Deadline: activityFound.Deadline,
1335 CountDown: activityFound.CountDown, 1353 CountDown: activityFound.CountDown,
1336 ExchangeRate: activityFound.Rate, 1354 ExchangeRate: activityFound.Rate,
@@ -1350,16 +1368,18 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1350,16 +1368,18 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1350 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1368 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
1351 } 1369 }
1352 1370
1353 - // 操作素币命令 1371 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1372 +
  1373 + // 个人素币操作命令
1354 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1374 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1355 Uid: employeeFound.EmployeeInfo.Uid, 1375 Uid: employeeFound.EmployeeInfo.Uid,
1356 Operator: createExchangeCashPersonCommand.Operator, 1376 Operator: createExchangeCashPersonCommand.Operator,
1357 - SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,  
1358 - OperationType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE, 1377 + SuMoney: suMoneyDecrement,
  1378 + OperationType: 41,
1359 OperationDescription: activityFound.ExchangeActivityName + "调整", 1379 OperationDescription: activityFound.ExchangeActivityName + "调整",
1360 } 1380 }
1361 1381
1362 - // 操作素币,生成素币流水 1382 + // 操作个人素币,生成素币流水记录
1363 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription) 1383 task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
1364 if err != nil { 1384 if err != nil {
1365 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1385 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1368,17 +1388,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1368,17 +1388,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1368 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1388 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
1369 } 1389 }
1370 1390
1371 - // 获取当前现金池  
1372 - _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{  
1373 - "companyId": activityFound.CompanyId,  
1374 - })  
1375 - if err != nil {  
1376 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1377 - }  
1378 - if len(cashPoolsFound) == 0 {  
1379 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")  
1380 - }  
1381 -  
1382 // 判断兑换活动的现金是否超过现金池未兑换现金 1391 // 判断兑换活动的现金是否超过现金池未兑换现金
1383 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 1392 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1393 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
@@ -1407,8 +1416,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1407,8 +1416,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1407 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1416 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1408 CashPoolId: cashPoolsFound[0].CashPoolId, 1417 CashPoolId: cashPoolsFound[0].CashPoolId,
1409 Cash: cashPoolsFound[0].Cash, 1418 Cash: cashPoolsFound[0].Cash,
1410 - ExchangedCash: cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash,  
1411 - UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personUpdated.ExchangedCash, 1419 + ExchangedCash: cashPoolsFound[0].ExchangedCash - cashDecrement,
  1420 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash + cashDecrement,
1412 ExchangedSuMoney: systemExchangedSuMoney, 1421 ExchangedSuMoney: systemExchangedSuMoney,
1413 UnExchangeSuMoney: systemUnExchangeSuMoney, 1422 UnExchangeSuMoney: systemUnExchangeSuMoney,
1414 Rate: newRate, 1423 Rate: newRate,
@@ -1432,11 +1441,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1432,11 +1441,13 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1432 if err := transactionContext.CommitTransaction(); err != nil { 1441 if err := transactionContext.CommitTransaction(); err != nil {
1433 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1442 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1434 } 1443 }
1435 -  
1436 return personUpdated, nil 1444 return personUpdated, nil
1437 } else if createExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币 1445 } else if createExchangeCashPersonCommand.ExchangedSuMoney > personFoundExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
1438 - // 增量  
1439 - suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney 1446 + // 素币增量
  1447 + suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney
  1448 +
  1449 + // 现金增量
  1450 + cashIncrement := suMoneyIncrement * activityFound.Rate
1440 1451
1441 // 更新兑换素币清单命令 1452 // 更新兑换素币清单命令
1442 updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{ 1453 updateExchangeCashPersonCommand := command.UpdateExchangeCashPersonCommand{
@@ -1459,8 +1470,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1459,8 +1470,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1459 // 更新素币兑换活动命令 1470 // 更新素币兑换活动命令
1460 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1471 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1461 ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId, 1472 ExchangeCashActivityId: peopleFound[0].ExchangeCashActivityId,
1462 - ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),  
1463 - ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney) * activityFound.Rate, 1473 + ExchangedSuMoney: activityFound.ExchangedSuMoney + suMoneyIncrement,
  1474 + ExchangedCash: activityFound.ExchangedCash + cashIncrement,
1464 Deadline: activityFound.Deadline, 1475 Deadline: activityFound.Deadline,
1465 CountDown: activityFound.CountDown, 1476 CountDown: activityFound.CountDown,
1466 ExchangeRate: activityFound.Rate, 1477 ExchangeRate: activityFound.Rate,
@@ -1480,12 +1491,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1480,12 +1491,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1480 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1491 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
1481 } 1492 }
1482 1493
  1494 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1495 +
1483 // 操作素币命令 1496 // 操作素币命令
1484 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1497 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1485 Uid: employeeFound.EmployeeInfo.Uid, 1498 Uid: employeeFound.EmployeeInfo.Uid,
1486 Operator: createExchangeCashPersonCommand.Operator, 1499 Operator: createExchangeCashPersonCommand.Operator,
1487 SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney, 1500 SuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
1488 - OperationType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE_CASH_RESTORE, 1501 + OperationType: 41,
1489 OperationDescription: activityFound.ExchangeActivityName + "调整", 1502 OperationDescription: activityFound.ExchangeActivityName + "调整",
1490 } 1503 }
1491 1504
@@ -1498,17 +1511,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1498,17 +1511,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1498 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid))) 1511 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
1499 } 1512 }
1500 1513
1501 - // 获取当前现金池  
1502 - _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{  
1503 - "companyId": activityFound.CompanyId,  
1504 - })  
1505 - if err != nil {  
1506 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1507 - }  
1508 - if len(cashPoolsFound) == 0 {  
1509 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")  
1510 - }  
1511 -  
1512 // 判断兑换活动的现金是否超过现金池未兑换现金 1514 // 判断兑换活动的现金是否超过现金池未兑换现金
1513 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 1515 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1514 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1516 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
@@ -1537,8 +1539,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1537,8 +1539,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1537 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1539 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1538 CashPoolId: cashPoolsFound[0].CashPoolId, 1540 CashPoolId: cashPoolsFound[0].CashPoolId,
1539 Cash: cashPoolsFound[0].Cash, 1541 Cash: cashPoolsFound[0].Cash,
1540 - ExchangedCash: cashPoolsFound[0].ExchangedCash + personUpdated.ExchangedCash,  
1541 - UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personUpdated.ExchangedCash, 1542 + ExchangedCash: cashPoolsFound[0].ExchangedCash + cashIncrement,
  1543 + UnExchangeCash: cashPoolsFound[0].UnExchangeCash - cashIncrement,
1542 ExchangedSuMoney: systemExchangedSuMoney, 1544 ExchangedSuMoney: systemExchangedSuMoney,
1543 UnExchangeSuMoney: systemUnExchangeSuMoney, 1545 UnExchangeSuMoney: systemUnExchangeSuMoney,
1544 Rate: newRate, 1546 Rate: newRate,
@@ -1562,10 +1564,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1562,10 +1564,14 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1562 if err := transactionContext.CommitTransaction(); err != nil { 1564 if err := transactionContext.CommitTransaction(); err != nil {
1563 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1565 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1564 } 1566 }
1565 -  
1566 return personUpdated, nil 1567 return personUpdated, nil
  1568 + } else { // 当前导入兑换素币清单素币等于本人已兑换素币
  1569 + if err := transactionContext.CommitTransaction(); err != nil {
  1570 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1571 + }
  1572 + return nil, nil
1567 } 1573 }
1568 - } else if len(peopleFound) == 0 { // 新增 1574 + } else if len(peopleFound) == 0 { // 导入兑换素币清单员工不存在兑换素币清单中,新增兑换素币清单
1569 // 新增兑换素币清单命令 1575 // 新增兑换素币清单命令
1570 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64) 1576 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
1571 newPerson := &domain.ExchangeCashPersonList{ 1577 newPerson := &domain.ExchangeCashPersonList{
@@ -1585,6 +1591,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1585,6 +1591,8 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1585 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1591 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1586 } 1592 }
1587 1593
  1594 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1595 +
1588 // 操作素币命令 1596 // 操作素币命令
1589 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1597 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1590 Uid: employeeFound.EmployeeInfo.Uid, 1598 Uid: employeeFound.EmployeeInfo.Uid,
@@ -1628,17 +1636,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1628,17 +1636,6 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1628 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId))) 1636 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
1629 } 1637 }
1630 1638
1631 - // 获取当前现金池  
1632 - _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{  
1633 - "companyId": activityFound.CompanyId,  
1634 - })  
1635 - if err != nil {  
1636 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1637 - }  
1638 - if len(cashPoolsFound) == 0 {  
1639 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "当前现金池为空,请先投入现金")  
1640 - }  
1641 -  
1642 // 判断兑换活动的现金是否超过现金池未兑换现金 1639 // 判断兑换活动的现金是否超过现金池未兑换现金
1643 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 1640 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1644 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1641 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
@@ -1655,7 +1652,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1655,7 +1652,7 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1655 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 1652 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
1656 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) 1653 systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
1657 1654
1658 - // 计算平均兑换汇率 1655 + // 重新计算现金池平均兑换汇率
1659 var newRate float64 1656 var newRate float64
1660 if systemExchangedSuMoney == 0 { 1657 if systemExchangedSuMoney == 0 {
1661 newRate = 0 1658 newRate = 0
@@ -1693,15 +1690,20 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc @@ -1693,15 +1690,20 @@ func (cashPoolService *CashPoolService) ImportCreateExchangeCashPerson(createExc
1693 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1690 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1694 } 1691 }
1695 return personSaved, nil 1692 return personSaved, nil
  1693 + } else { // 未知情况
  1694 + if err := transactionContext.CommitTransaction(); err != nil {
  1695 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
1696 } 1696 }
1697 return nil, nil 1697 return nil, nil
  1698 + }
1698 } 1699 }
1699 1700
1700 -// 新增兑换素币清单 1701 +// 页面新增兑换素币清单
1701 func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) { 1702 func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeCashPersonCommand *command.CreateExchangeCashPersonCommand) (interface{}, error) {
1702 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil { 1703 if err := createExchangeCashPersonCommand.ValidateCommand(); err != nil {
1703 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1704 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1704 } 1705 }
  1706 +
1705 transactionContext, err := factory.CreateTransactionContext(nil) 1707 transactionContext, err := factory.CreateTransactionContext(nil)
1706 if err != nil { 1708 if err != nil {
1707 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1709 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1812,7 +1814,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1812,7 +1814,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1812 1814
1813 // 新增兑换清单命令 1815 // 新增兑换清单命令
1814 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64) 1816 newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
1815 -  
1816 newPerson := &domain.ExchangeCashPersonList{ 1817 newPerson := &domain.ExchangeCashPersonList{
1817 EmployeeInfo: &domain.EmployeeInfo{ 1818 EmployeeInfo: &domain.EmployeeInfo{
1818 Uid: employeeFound.EmployeeInfo.Uid, 1819 Uid: employeeFound.EmployeeInfo.Uid,
@@ -1830,6 +1831,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1830,6 +1831,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1830 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1831 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1831 } 1832 }
1832 1833
  1834 + // 操作类型->记录类型对应:1->3: 增加 2->4: 扣除 3->1: 兑换物资 4->5: 兑换现金活动 41->6: 撤回兑换现金素币 5->2: 任务奖励
  1835 +
1833 // 操作素币命令 1836 // 操作素币命令
1834 operationSuMoneyCommand := &command.OperationSuMoneyCommand{ 1837 operationSuMoneyCommand := &command.OperationSuMoneyCommand{
1835 Uid: employeeFound.EmployeeInfo.Uid, 1838 Uid: employeeFound.EmployeeInfo.Uid,
@@ -1945,6 +1948,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer @@ -1945,6 +1948,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
1945 if err := getExchangeCashPersonQuery.ValidateQuery(); err != nil { 1948 if err := getExchangeCashPersonQuery.ValidateQuery(); err != nil {
1946 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1949 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1947 } 1950 }
  1951 +
1948 transactionContext, err := factory.CreateTransactionContext(nil) 1952 transactionContext, err := factory.CreateTransactionContext(nil)
1949 if err != nil { 1953 if err != nil {
1950 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1954 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1981,11 +1985,12 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer @@ -1981,11 +1985,12 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
1981 } 1985 }
1982 } 1986 }
1983 1987
1984 -// 返回兑换素币清单列表 1988 +// 返回兑换素币清单列表(全量导出该公司兑换素币清单)
1985 func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { 1989 func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) {
1986 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { 1990 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil {
1987 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 1991 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
1988 } 1992 }
  1993 +
1989 transactionContext, err := factory.CreateTransactionContext(nil) 1994 transactionContext, err := factory.CreateTransactionContext(nil)
1990 if err != nil { 1995 if err != nil {
1991 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1996 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -2031,6 +2036,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -2031,6 +2036,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
2031 activityIds = append(activityIds, activity.ActivityId) 2036 activityIds = append(activityIds, activity.ActivityId)
2032 } 2037 }
2033 2038
  2039 + // 获取该公司活动下所有兑换员工
2034 if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{ 2040 if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{
2035 "exchangeCashActivityIds": activityIds, 2041 "exchangeCashActivityIds": activityIds,
2036 "offset": listExchangeCashPersonQuery.Offset, 2042 "offset": listExchangeCashPersonQuery.Offset,
@@ -2068,6 +2074,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -2068,6 +2074,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
2068 if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil { 2074 if err := removeExchangeCashPersonCommand.ValidateCommand(); err != nil {
2069 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 2075 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
2070 } 2076 }
  2077 +
2071 transactionContext, err := factory.CreateTransactionContext(nil) 2078 transactionContext, err := factory.CreateTransactionContext(nil)
2072 if err != nil { 2079 if err != nil {
2073 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2080 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -2261,11 +2268,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC @@ -2261,11 +2268,12 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC
2261 } 2268 }
2262 } 2269 }
2263 2270
2264 -// 根据员工ids获取兑换清单 2271 +// 导出员工兑换素币清单
2265 func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) { 2272 func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) {
2266 if err := exportExchangeCashListCommand.ValidateCommand(); err != nil { 2273 if err := exportExchangeCashListCommand.ValidateCommand(); err != nil {
2267 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 2274 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
2268 } 2275 }
  2276 +
2269 transactionContext, err := factory.CreateTransactionContext(nil) 2277 transactionContext, err := factory.CreateTransactionContext(nil)
2270 if err != nil { 2278 if err != nil {
2271 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2279 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -2287,11 +2295,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang @@ -2287,11 +2295,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
2287 exchangeCashPersonListRepository = value 2295 exchangeCashPersonListRepository = value
2288 } 2296 }
2289 2297
  2298 + // 判断勾选、筛选条件
2290 if len(exportExchangeCashListCommand.Ids) == 0 && exportExchangeCashListCommand.Where == nil { 2299 if len(exportExchangeCashListCommand.Ids) == 0 && exportExchangeCashListCommand.Where == nil {
2291 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据") 2300 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
2292 } 2301 }
2293 2302
2294 - // 获取兑换清单 2303 + // 获取兑换素币清单
2295 if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil { 2304 if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil {
2296 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2305 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
2297 } else { 2306 } else {
@@ -69,7 +69,7 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ @@ -69,7 +69,7 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
69 if companyId, ok := queryOptions["companyId"]; ok { 69 if companyId, ok := queryOptions["companyId"]; ok {
70 query = query.Where("employee.company_id = ?", companyId) 70 query = query.Where("employee.company_id = ?", companyId)
71 } 71 }
72 - query = query.Where(`employee.status = ?`, 1) 72 + query = query.Where(`employee.status = ?`, 1) // 筛除已离职员工
73 if err := query.First(); err != nil { 73 if err := query.First(); err != nil {
74 if err.Error() == "pg: no rows in result set" { 74 if err.Error() == "pg: no rows in result set" {
75 return nil, fmt.Errorf("没有此员工") 75 return nil, fmt.Errorf("没有此员工")