作者 陈志颖

fix:修复平均兑换汇率计算

... ... @@ -71,7 +71,12 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
cashPoolRepository = value
}
// 计算系统平均兑换汇率
rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
var rate float64
if systemExchangedSuMoney == 0 {
rate = 0
} else {
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
}
// 新建现金池
newCashPool := &domain.CashPool{
CompanyId: createCashPoolCommand.CompanyId,
... ...
... ... @@ -130,7 +130,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
}
// 系统已兑换现金素币
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.su_money) AS system_changed_su_money").
Where("e.company_id = ?", companyId).
Where("e.status = ?", 1).
... ... @@ -153,7 +153,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
)
// 系统已兑换现金
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint").
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
ColumnExpr("sum(su_money_transaction_record.cash) AS system_exchanged_cash").
Where("e.company_id = ?", companyId).
//Where(`e.status = ?`, 1).
... ... @@ -165,7 +165,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
cashPool := new(models.CashPool)
if err := tx.Model(cashPool).
Column("un_exchange_cash").
Where("cash_pools.company_id = ?", companyId).
Where("cash_pool.company_id = ?", companyId).
Order("id DESC").
Limit(1).
Select(&systemUnExchangeCash) ; err != nil {
... ...