正在显示
1 个修改的文件
包含
38 行增加
和
24 行删除
| @@ -57,6 +57,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -57,6 +57,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 57 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id") | 57 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id") |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | + // 获取平台素币兑换情况 | ||
| 60 | var employeeDao *dao.EmployeeDao | 61 | var employeeDao *dao.EmployeeDao |
| 61 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | 62 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ |
| 62 | "transactionContext": transactionContext, | 63 | "transactionContext": transactionContext, |
| @@ -74,28 +75,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -74,28 +75,10 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 74 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | 75 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | - systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) | ||
| 78 | - systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) | ||
| 79 | - | ||
| 80 | - systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) | ||
| 81 | - if err != nil { | ||
| 82 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 83 | - } | ||
| 84 | - if systemCashStatistics == nil { | ||
| 85 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64) | ||
| 89 | - systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64) | ||
| 90 | - | ||
| 91 | - // 计算系统平均兑换汇率 | ||
| 92 | - var rate float64 | ||
| 93 | - if systemExchangedSuMoney == 0 { | ||
| 94 | - rate = 0 | ||
| 95 | - } else { | ||
| 96 | - rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率 | ||
| 97 | - } | 78 | + systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币 |
| 79 | + systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币 | ||
| 98 | 80 | ||
| 81 | + // 判断当前是否有现金池 | ||
| 99 | var cashPoolRepository domain.CashPoolRepository | 82 | var cashPoolRepository domain.CashPoolRepository |
| 100 | if value, err := factory.CreateCashPoolRepository(map[string] interface{} { | 83 | if value, err := factory.CreateCashPoolRepository(map[string] interface{} { |
| 101 | "transactionContext": transactionContext, | 84 | "transactionContext": transactionContext, |
| @@ -105,18 +88,49 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -105,18 +88,49 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 105 | cashPoolRepository = value | 88 | cashPoolRepository = value |
| 106 | } | 89 | } |
| 107 | 90 | ||
| 91 | + countCashPools, _, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(createCashPoolCommand)); | ||
| 92 | + if err != nil { | ||
| 93 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 94 | + } | ||
| 95 | + | ||
| 108 | // 新建现金池 | 96 | // 新建现金池 |
| 109 | newCashPool := &domain.CashPool{ | 97 | newCashPool := &domain.CashPool{ |
| 110 | CompanyId: createCashPoolCommand.CompanyId, | 98 | CompanyId: createCashPoolCommand.CompanyId, |
| 111 | Cash: createCashPoolCommand.Cash, | 99 | Cash: createCashPoolCommand.Cash, |
| 112 | - ExchangedCash: systemExchangedCash, | ||
| 113 | - UnExchangeCash: createCashPoolCommand.Cash + systemUnExchangeCash, | 100 | + ExchangedCash: 0, |
| 101 | + UnExchangeCash: 0, | ||
| 114 | ExchangedSuMoney: systemExchangedSuMoney, | 102 | ExchangedSuMoney: systemExchangedSuMoney, |
| 115 | UnExchangeSuMoney: systemUnExchangeSuMoney, | 103 | UnExchangeSuMoney: systemUnExchangeSuMoney, |
| 116 | - Rate: rate, | 104 | + Rate: 0, |
| 117 | CreateTime: time.Now(), | 105 | CreateTime: time.Now(), |
| 118 | } | 106 | } |
| 119 | 107 | ||
| 108 | + if countCashPools == 0 { // 现金池为空时处理 | ||
| 109 | + newCashPool.ExchangedCash = 0.0 | ||
| 110 | + newCashPool.UnExchangeCash = createCashPoolCommand.Cash | ||
| 111 | + } else { | ||
| 112 | + systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId) | ||
| 113 | + if err != nil { | ||
| 114 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 115 | + } | ||
| 116 | + if systemCashStatistics == nil { | ||
| 117 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司") | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + newCashPool.ExchangedCash = systemCashStatistics["systemExchangedCash"].(float64) | ||
| 121 | + newCashPool.UnExchangeCash = systemCashStatistics["systemUnExchangeCash"].(float64) + createCashPoolCommand.Cash | ||
| 122 | + | ||
| 123 | + // 计算系统平均兑换汇率 | ||
| 124 | + var rate float64 | ||
| 125 | + if systemExchangedSuMoney == 0 { | ||
| 126 | + rate = 0 | ||
| 127 | + } else { | ||
| 128 | + rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", newCashPool.ExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率 | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + newCashPool.Rate = rate | ||
| 132 | + } | ||
| 133 | + | ||
| 120 | if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { | 134 | if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil { |
| 121 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 135 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 122 | } else { | 136 | } else { |
-
请 注册 或 登录 后发表评论