正在显示
1 个修改的文件
包含
20 行增加
和
3 行删除
@@ -123,6 +123,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -123,6 +123,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
123 | if createCashPoolCommand.Cash < cashPools[0].ExchangedCash { | 123 | if createCashPoolCommand.Cash < cashPools[0].ExchangedCash { |
124 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "投入的现金值必须大于当前已兑换现金值") | 124 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "投入的现金值必须大于当前已兑换现金值") |
125 | } | 125 | } |
126 | + // 重新计算平均兑换汇率 | ||
127 | + newRate := cashPools[0].ExchangedCash / systemExchangedSuMoney | ||
128 | + | ||
129 | + // 更新现金池 | ||
126 | newCashPool := &domain.CashPool{ | 130 | newCashPool := &domain.CashPool{ |
127 | CashPoolId: cashPools[0].CashPoolId, | 131 | CashPoolId: cashPools[0].CashPoolId, |
128 | CompanyId: createCashPoolCommand.CompanyId, | 132 | CompanyId: createCashPoolCommand.CompanyId, |
@@ -131,10 +135,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -131,10 +135,11 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
131 | UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash), | 135 | UnExchangeCash: cashPools[0].UnExchangeCash + (createCashPoolCommand.Cash - cashPools[0].Cash), |
132 | ExchangedSuMoney: systemExchangedSuMoney, | 136 | ExchangedSuMoney: systemExchangedSuMoney, |
133 | UnExchangeSuMoney: systemUnExchangeSuMoney, | 137 | UnExchangeSuMoney: systemUnExchangeSuMoney, |
134 | - Rate: cashPools[0].Rate, | 138 | + Rate: newRate, |
135 | LastRate: cashPools[0].LastRate, | 139 | LastRate: cashPools[0].LastRate, |
136 | CreateTime: time.Now(), | 140 | CreateTime: time.Now(), |
137 | } | 141 | } |
142 | + // 保存现金池更新 | ||
138 | if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { | 143 | if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { |
139 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 144 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
140 | } else { | 145 | } else { |
@@ -500,6 +505,10 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma | @@ -500,6 +505,10 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma | ||
500 | activitiesFormat = append(activitiesFormat, activityFormat) | 505 | activitiesFormat = append(activitiesFormat, activityFormat) |
501 | } | 506 | } |
502 | 507 | ||
508 | + if len(activitiesFormat) == 0 { | ||
509 | + activitiesFormat = []interface{}{} | ||
510 | + } | ||
511 | + | ||
503 | return map[string]interface{}{ | 512 | return map[string]interface{}{ |
504 | "count": count, | 513 | "count": count, |
505 | "activities": activitiesFormat, | 514 | "activities": activitiesFormat, |
@@ -594,6 +603,11 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas | @@ -594,6 +603,11 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas | ||
594 | activitiesWithTs = append(activitiesWithTs, activityWithTs) | 603 | activitiesWithTs = append(activitiesWithTs, activityWithTs) |
595 | } | 604 | } |
596 | } | 605 | } |
606 | + | ||
607 | + if len(activitiesWithTs) == 0 { | ||
608 | + activitiesWithTs = []interface{}{} | ||
609 | + } | ||
610 | + | ||
597 | return map[string]interface{}{ | 611 | return map[string]interface{}{ |
598 | "count": count, | 612 | "count": count, |
599 | "activities": activitiesWithTs, | 613 | "activities": activitiesWithTs, |
@@ -787,7 +801,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -787,7 +801,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
787 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) | 801 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId))) |
788 | } | 802 | } |
789 | 803 | ||
790 | - if updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率 | 804 | + // 获取当前兑换活动汇率 |
805 | + activityFoundRate := activityFound.Rate | ||
806 | + | ||
807 | + if updateExchangeCashActivityCommand.ExchangeRate != activityFoundRate && updateExchangeCashActivityCommand.ExchangeRate != 0 { // 更新兑换活动兑换汇率 | ||
791 | // 获取当前公司现金池 | 808 | // 获取当前公司现金池 |
792 | _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ | 809 | _, cashPoolsFound, err := cashPoolRepository.Find(map[string]interface{}{ |
793 | "companyId": activityFound.CompanyId, | 810 | "companyId": activityFound.CompanyId, |
@@ -886,7 +903,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | @@ -886,7 +903,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang | ||
886 | // 计算倒计时 | 903 | // 计算倒计时 |
887 | var t1 = time.Now() | 904 | var t1 = time.Now() |
888 | var t2 = activityFound.Deadline | 905 | var t2 = activityFound.Deadline |
889 | - updateExchangeCashActivityCommand.CountDown = int64(t2.Sub(t1).Hours() / 24) | 906 | + updateExchangeCashActivityCommand.CountDown = int64(math.Ceil(t2.Sub(t1).Hours() / 24)) |
890 | 907 | ||
891 | // 倒计时结束处理 | 908 | // 倒计时结束处理 |
892 | if t2.Before(t1) { | 909 | if t2.Before(t1) { |
-
请 注册 或 登录 后发表评论