作者 陈志颖

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

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