作者 linmadan

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

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