作者 陈志颖

fix:增加新增兑换素币清单时对员工的判断

@@ -21,6 +21,7 @@ func (configService *ConfigService) ListTaskStatus(listTaskStatusQuery *query.Li @@ -21,6 +21,7 @@ func (configService *ConfigService) ListTaskStatus(listTaskStatusQuery *query.Li
21 4: "待验收", 21 4: "待验收",
22 5: "已完成", 22 5: "已完成",
23 7: "待确认", 23 7: "待确认",
  24 + 8: "已过期",
24 } 25 }
25 var list []map[string]interface{} 26 var list []map[string]interface{}
26 for key, value := range taskStatusMap { 27 for key, value := range taskStatusMap {
@@ -12,6 +12,10 @@ type UpdateCashPoolCommand struct { @@ -12,6 +12,10 @@ type UpdateCashPoolCommand struct {
12 UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金 12 UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换现金
13 UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换素币 13 UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换素币
14 Rate float64 `json:"rate"` // 平均兑换汇率 14 Rate float64 `json:"rate"` // 平均兑换汇率
  15 + Cash float64 `json:"cash"`
  16 + //CompanyId int64 `json:"companyId"`
  17 + LastRate float64 `json:"lastRate"`
  18 + //CreateTime time.Time `json:"createTime"`
15 } 19 }
16 20
17 func (updateCashPoolCommand *UpdateCashPoolCommand) ValidateCommand() error { 21 func (updateCashPoolCommand *UpdateCashPoolCommand) ValidateCommand() error {
@@ -99,6 +99,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -99,6 +99,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
99 UnExchangeCash: createCashPoolCommand.Cash, 99 UnExchangeCash: createCashPoolCommand.Cash,
100 ExchangedSuMoney: 0, 100 ExchangedSuMoney: 0,
101 UnExchangeSuMoney: systemUnExchangeSuMoney, 101 UnExchangeSuMoney: systemUnExchangeSuMoney,
  102 + LastRate: 0,
102 Rate: 0, 103 Rate: 0,
103 CreateTime: time.Now(), 104 CreateTime: time.Now(),
104 } 105 }
@@ -123,6 +124,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -123,6 +124,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
123 ExchangedSuMoney: systemExchangedSuMoney, 124 ExchangedSuMoney: systemExchangedSuMoney,
124 UnExchangeSuMoney: systemUnExchangeSuMoney, 125 UnExchangeSuMoney: systemUnExchangeSuMoney,
125 Rate: cashPools[0].Rate, 126 Rate: cashPools[0].Rate,
  127 + LastRate: cashPools[0].LastRate,
126 CreateTime: time.Now(), 128 CreateTime: time.Now(),
127 } 129 }
128 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { 130 if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
@@ -610,11 +612,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -610,11 +612,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
610 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId))) 612 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
611 } 613 }
612 614
613 - //var timeNow = time.Now()  
614 - //var deadline = activityFound.Deadline  
615 - //var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)  
616 var t1 = time.Now() 615 var t1 = time.Now()
617 - //var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)  
618 var t2 = activityFound.Deadline 616 var t2 = activityFound.Deadline
619 617
620 // 更新兑换现金活动倒计时命令 618 // 更新兑换现金活动倒计时命令
@@ -790,6 +788,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -790,6 +788,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
790 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") 788 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
791 } 789 }
792 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) 790 systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
  791 + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
793 792
794 // 获取平台现金状况 793 // 获取平台现金状况
795 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId) 794 systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
@@ -815,11 +814,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -815,11 +814,11 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
815 CashPoolId: cashPoolsFound[0].CashPoolId, 814 CashPoolId: cashPoolsFound[0].CashPoolId,
816 ExchangedCash: systemUnExchangeCash, 815 ExchangedCash: systemUnExchangeCash,
817 UnExchangeCash: systemUnExchangeCash, 816 UnExchangeCash: systemUnExchangeCash,
  817 + ExchangedSuMoney: systemExchangedSuMoney,
  818 + UnExchangeSuMoney: systemUnExchangeSuMoney,
818 Rate: rate, 819 Rate: rate,
819 } 820 }
820 821
821 - fmt.Printf("更新现金池命令:%+v\n", updateCashPoolCommand)  
822 -  
823 // 更新现金池 822 // 更新现金池
824 if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil { 823 if err := cashPoolsFound[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
825 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 824 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -854,8 +853,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -854,8 +853,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
854 // 更新兑换活动命令已兑换素币 853 // 更新兑换活动命令已兑换素币
855 updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney 854 updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
856 855
857 - fmt.Printf("更新兑换活动命令:%+v\n", updateExchangeCashActivityCommand)  
858 -  
859 // 更新兑换活动 856 // 更新兑换活动
860 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 857 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
861 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 858 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -868,7 +865,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -868,7 +865,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
868 if err := transactionContext.CommitTransaction(); err != nil { 865 if err := transactionContext.CommitTransaction(); err != nil {
869 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 866 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
870 } 867 }
871 -  
872 return activityUpdated, nil 868 return activityUpdated, nil
873 } 869 }
874 } 870 }
@@ -970,10 +966,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -970,10 +966,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
970 if createExchangeCashPersonCommand.PersonAccount == "" { 966 if createExchangeCashPersonCommand.PersonAccount == "" {
971 getEmployee = map[string]interface{}{ 967 getEmployee = map[string]interface{}{
972 "uid": createExchangeCashPersonCommand.Uid, 968 "uid": createExchangeCashPersonCommand.Uid,
  969 + "companyId": activityFound.CompanyId,
973 } 970 }
974 } else { 971 } else {
975 getEmployee = map[string]interface{}{ 972 getEmployee = map[string]interface{}{
976 "account": createExchangeCashPersonCommand.PersonAccount, 973 "account": createExchangeCashPersonCommand.PersonAccount,
  974 + "companyId": activityFound.CompanyId,
977 } 975 }
978 } 976 }
979 977
@@ -1030,6 +1028,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1030,6 +1028,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1030 // 更新兑换活动命令 1028 // 更新兑换活动命令
1031 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{ 1029 updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
1032 ExchangeCashActivityId: personSaved.ExchangeCashActivityId, 1030 ExchangeCashActivityId: personSaved.ExchangeCashActivityId,
  1031 + ExchangeActivityName: activityFound.ExchangeActivityName,
1033 ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney, 1032 ExchangedSuMoney: activityFound.ExchangedSuMoney + createExchangeCashPersonCommand.ExchangedSuMoney,
1034 ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate, 1033 ExchangedCash: activityFound.ExchangedCash + createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate,
1035 Deadline: activityFound.Deadline, 1034 Deadline: activityFound.Deadline,
@@ -1052,7 +1051,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1052,7 +1051,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1052 } 1051 }
1053 1052
1054 // 获取兑换活动素币兑换情况 1053 // 获取兑换活动素币兑换情况
1055 - activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId) 1054 + activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
1056 if err != nil { 1055 if err != nil {
1057 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1056 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1058 } 1057 }
@@ -1110,11 +1109,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1110,11 +1109,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1110 // 更新现金池命令 1109 // 更新现金池命令
1111 updateCashPoolCommand := &command.UpdateCashPoolCommand{ 1110 updateCashPoolCommand := &command.UpdateCashPoolCommand{
1112 CashPoolId: cashPoolsFound[0].CashPoolId, 1111 CashPoolId: cashPoolsFound[0].CashPoolId,
  1112 + Cash: cashPoolsFound[0].Cash,
  1113 + //CompanyId: cashPoolsFound[0].CompanyId,
1113 ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash, 1114 ExchangedCash: cashPoolsFound[0].ExchangedCash + personSaved.ExchangedCash,
1114 UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash, 1115 UnExchangeCash: cashPoolsFound[0].UnExchangeCash - personSaved.ExchangedCash,
1115 ExchangedSuMoney: systemExchangedSuMoney, 1116 ExchangedSuMoney: systemExchangedSuMoney,
1116 UnExchangeSuMoney: systemUnExchangeSuMoney, 1117 UnExchangeSuMoney: systemUnExchangeSuMoney,
1117 Rate: newRate, 1118 Rate: newRate,
  1119 + LastRate: cashPoolsFound[0].LastRate,
  1120 + //CreateTime: time.Now(),
1118 } 1121 }
1119 1122
1120 // 更新现金池 1123 // 更新现金池
@@ -1459,17 +1462,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1459,17 +1462,6 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1459 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1462 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金")
1460 } 1463 }
1461 1464
1462 - // 重新获取系统现金兑换情况  
1463 - //newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)  
1464 - //if err != nil {  
1465 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
1466 - //}  
1467 - //if newSystemCashStatistics == nil {  
1468 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")  
1469 - //}  
1470 - //newSystemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)  
1471 - //newSystemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)  
1472 -  
1473 // 获取当前现金池 1465 // 获取当前现金池
1474 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ 1466 _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{
1475 "companyId": activityUpdated.CompanyId, 1467 "companyId": activityUpdated.CompanyId,
@@ -1497,6 +1489,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC @@ -1497,6 +1489,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC
1497 Rate: newRate, 1489 Rate: newRate,
1498 ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney), 1490 ExchangedSuMoney: cashPoolsFound[0].ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - personFoundExchangedSuMoney),
1499 UnExchangeSuMoney: systemUnExchangeSuMoney, 1491 UnExchangeSuMoney: systemUnExchangeSuMoney,
  1492 + LastRate: cashPoolsFound[0].LastRate,
  1493 + //CompanyId: cashPoolsFound[0].CompanyId,
  1494 + //CreateTime: time.Now(),
1500 } 1495 }
1501 1496
1502 // 更新现金池 1497 // 更新现金池
@@ -1743,6 +1738,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang @@ -1743,6 +1738,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
1743 transactionContext.RollbackTransaction() 1738 transactionContext.RollbackTransaction()
1744 }() 1739 }()
1745 1740
  1741 + // 兑换素币清单仓储初始化
1746 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository 1742 var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
1747 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ 1743 if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
1748 "transactionContext": transactionContext, 1744 "transactionContext": transactionContext,
@@ -1752,10 +1748,11 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang @@ -1752,10 +1748,11 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
1752 exchangeCashPersonListRepository = value 1748 exchangeCashPersonListRepository = value
1753 } 1749 }
1754 1750
1755 - if len(exportExchangeCashListCommand.IDs) == 0 {  
1756 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")  
1757 - } 1751 + //if len(exportExchangeCashListCommand.IDs) == 0 {
  1752 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未勾选需要导出的数据")
  1753 + //}
1758 1754
  1755 + // 获取兑换清单
1759 if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil { 1756 if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil {
1760 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1757 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1761 } else { 1758 } else {
@@ -1782,6 +1779,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ @@ -1782,6 +1779,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
1782 transactionContext.RollbackTransaction() 1779 transactionContext.RollbackTransaction()
1783 }() 1780 }()
1784 1781
  1782 + // 现金池DAO初始化
1785 var cashPoolDao *dao.CashPoolDao 1783 var cashPoolDao *dao.CashPoolDao
1786 if value, err := factory.CreateCashPoolDao(map[string]interface{}{ 1784 if value, err := factory.CreateCashPoolDao(map[string]interface{}{
1787 "transactionContext": transactionContext, 1785 "transactionContext": transactionContext,
@@ -1791,6 +1789,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ @@ -1791,6 +1789,7 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
1791 cashPoolDao = value 1789 cashPoolDao = value
1792 } 1790 }
1793 1791
  1792 + // 素币兑换清单榜单
1794 if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil { 1793 if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil {
1795 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1794 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1796 } else { 1795 } else {
@@ -177,7 +177,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf @@ -177,7 +177,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
177 systemUnExchangeCash float64 177 systemUnExchangeCash float64
178 systemExchangedCash float64 178 systemExchangedCash float64
179 ) 179 )
180 - // 系统兑换现金 180 + // 系统兑换现金
181 cashPool := new(models.CashPool) 181 cashPool := new(models.CashPool)
182 if err := tx.Model(cashPool). 182 if err := tx.Model(cashPool).
183 Column("exchanged_cash"). 183 Column("exchanged_cash").
@@ -187,6 +187,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf @@ -187,6 +187,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
187 Select(&systemExchangedCash) ; err != nil { 187 Select(&systemExchangedCash) ; err != nil {
188 return nil, err 188 return nil, err
189 } 189 }
  190 + // 系统未兑换现金
190 if err := tx.Model(cashPool). 191 if err := tx.Model(cashPool).
191 Column("un_exchange_cash"). 192 Column("un_exchange_cash").
192 Where("cash_pool.company_id = ?", companyId). 193 Where("cash_pool.company_id = ?", companyId).
@@ -66,6 +66,10 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{ @@ -66,6 +66,10 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
66 if account, ok := queryOptions["account"]; ok { 66 if account, ok := queryOptions["account"]; ok {
67 query = query.Where("employee.employee_account = ?", account) 67 query = query.Where("employee.employee_account = ?", account)
68 } 68 }
  69 + if companyId, ok := queryOptions["companyId"]; ok {
  70 + query = query.Where("employee.company_id = ?", companyId)
  71 + }
  72 + query = query.Where(`employee.status = ?`, 1)
69 if err := query.First(); err != nil { 73 if err := query.First(); err != nil {
70 if err.Error() == "pg: no rows in result set" { 74 if err.Error() == "pg: no rows in result set" {
71 return nil, fmt.Errorf("没有此员工") 75 return nil, fmt.Errorf("没有此员工")