作者 linmadan

重构素币统计算法,增加查询参数

@@ -10,8 +10,10 @@ import ( @@ -10,8 +10,10 @@ import (
10 type SearchSuMoneyTransactionRecordCommand struct { 10 type SearchSuMoneyTransactionRecordCommand struct {
11 // 统一用户UID 11 // 统一用户UID
12 Uid int64 `json:"uid" valid:"Required"` 12 Uid int64 `json:"uid" valid:"Required"`
13 - // 记录类型(1兑换,2任务奖励) 13 + // 记录类型(1兑换,2任务奖励,3增加,4扣除
14 RecordType int `json:"recordType,omitempty"` 14 RecordType int `json:"recordType,omitempty"`
  15 + // 记录类型列表(1兑换,2任务奖励,3增加,4扣除)
  16 + RecordTypes []int `json:"recordTypes,omitempty"`
15 // 操作人UID 17 // 操作人UID
16 // 事务时间区间-开始时间 18 // 事务时间区间-开始时间
17 TransactionStartTime time.Time `json:"transactionStartTime,omitempty"` 19 TransactionStartTime time.Time `json:"transactionStartTime,omitempty"`
@@ -122,7 +122,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -122,7 +122,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
122 if err := tx.Model(suMoneyTransactionRecordModel). 122 if err := tx.Model(suMoneyTransactionRecordModel).
123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
125 - Where(`su_money_transaction_record.record_type = ?`, 2). 125 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
126 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 126 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
127 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 127 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
128 Select(&incomeSuMoney); err != nil { 128 Select(&incomeSuMoney); err != nil {
@@ -131,7 +131,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -131,7 +131,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
131 if err := tx.Model(suMoneyTransactionRecordModel). 131 if err := tx.Model(suMoneyTransactionRecordModel).
132 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 132 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
133 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 133 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
134 - Where(`su_money_transaction_record.record_type = ?`, 1). 134 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})).
135 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 135 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
136 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 136 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
137 Select(&expendSuMoney); err != nil { 137 Select(&expendSuMoney); err != nil {
@@ -73,6 +73,9 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -73,6 +73,9 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
73 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) { 73 if recordType, ok := queryOptions["recordType"]; ok && (recordType != 0) {
74 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType) 74 query = query.Where(`su_money_transaction_record.record_type = ?`, recordType)
75 } 75 }
  76 + if recordTypes, ok := queryOptions["recordTypes"]; ok && (len(recordTypes.([]int)) != 0) {
  77 + query = query.Where(`su_money_transaction_record.record_type IN (?)`, pg.In(recordTypes.([]int)))
  78 + }
76 if operator, ok := queryOptions["operator"]; ok && (operator != int64(0)) { 79 if operator, ok := queryOptions["operator"]; ok && (operator != int64(0)) {
77 query = query.Where(`su_money_transaction_record.operator @> '{"uid":?}'`, operator) 80 query = query.Where(`su_money_transaction_record.operator @> '{"uid":?}'`, operator)
78 } 81 }