作者 陈志颖

fix:修复个人素币收支统计

@@ -217,20 +217,22 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -217,20 +217,22 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
217 var ( 217 var (
218 incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加 6: 兑换素币撤回) 218 incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加 6: 兑换素币撤回)
219 expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金) 219 expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
  220 + expendSuMoneyExchange float64
  221 + incomeSuMoneyExchangeRestore float64
220 ) 222 )
221 tx := dao.transactionContext.PgTx 223 tx := dao.transactionContext.PgTx
222 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 224 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
223 - // 收入素币 225 + // 收入素币
224 if err := tx.Model(suMoneyTransactionRecordModel). 226 if err := tx.Model(suMoneyTransactionRecordModel).
225 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 227 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
226 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 228 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
227 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})). 229 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
228 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 230 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
229 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 231 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
230 Select(&incomeSuMoney); err != nil { 232 Select(&incomeSuMoney); err != nil {
231 return nil, err 233 return nil, err
232 } 234 }
233 - // 支出素币 235 + // 支出素币
234 if err := tx.Model(suMoneyTransactionRecordModel). 236 if err := tx.Model(suMoneyTransactionRecordModel).
235 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 237 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
236 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 238 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -240,9 +242,29 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -240,9 +242,29 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
240 Select(&expendSuMoney); err != nil { 242 Select(&expendSuMoney); err != nil {
241 return nil, err 243 return nil, err
242 } 244 }
  245 + // 兑换现金的
  246 + if err := tx.Model(suMoneyTransactionRecordModel).
  247 + ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
  248 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  249 + Where(`su_money_transaction_record.record_type =?`, 5).
  250 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  251 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  252 + Select(&expendSuMoneyExchange); err != nil {
  253 + return nil, err
  254 + }
  255 + // 兑换现金撤回的
  256 + if err := tx.Model(suMoneyTransactionRecordModel).
  257 + ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
  258 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  259 + Where(`su_money_transaction_record.record_type = ?`, 6).
  260 + Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
  261 + Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
  262 + Select(&incomeSuMoneyExchangeRestore); err != nil {
  263 + return nil, err
  264 + }
243 return map[string]interface{}{ 265 return map[string]interface{}{
244 - "incomeSuMoney": incomeSuMoney - expendSuMoney, // 个人素币盈利  
245 - "expendSuMoney": expendSuMoney, // 个人素币支出 266 + "incomeSuMoney": incomeSuMoney, // 个人素币收入
  267 + "expendSuMoney": expendSuMoney + expendSuMoneyExchange - incomeSuMoneyExchangeRestore, // 个人素币支出
246 }, nil 268 }, nil
247 } 269 }
248 270
@@ -254,7 +276,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -254,7 +276,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
254 ) 276 )
255 tx := dao.transactionContext.PgTx 277 tx := dao.transactionContext.PgTx
256 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 278 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
257 - // 收入的贡献值 279 + // 收入的贡献值
258 if err := tx.Model(suMoneyTransactionRecordModel). 280 if err := tx.Model(suMoneyTransactionRecordModel).
259 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 281 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
260 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 282 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -264,7 +286,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -264,7 +286,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
264 Select(&incomeContributions); err != nil { 286 Select(&incomeContributions); err != nil {
265 return nil, err 287 return nil, err
266 } 288 }
267 - // 支出的贡献值 289 + // 支出的贡献值
268 if err := tx.Model(suMoneyTransactionRecordModel). 290 if err := tx.Model(suMoneyTransactionRecordModel).
269 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 291 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
270 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 292 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -275,7 +297,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -275,7 +297,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
275 return nil, err 297 return nil, err
276 } 298 }
277 return map[string]interface{}{ 299 return map[string]interface{}{
278 - "incomeContributions": incomeContributions - expendContributions, // 个人贡献值盈利 300 + "incomeContributions": incomeContributions, // 个人贡献值收入
279 "expendContributions": expendContributions, // 个人贡献支出 301 "expendContributions": expendContributions, // 个人贡献支出
280 }, nil 302 }, nil
281 } 303 }