pg_cash_pool_dao.go
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
)
type CashPoolDao struct {
transactionContext *pgTransaction.TransactionContext
}
// 计算系统已兑换素币、未兑换素币
//func (dao *CashPoolDao) CalculateSystemSuMoney(companyId int64) ( map[string]interface{}, error) {
// var systemUnExchangeSuMoney float64
// var systemExchangedSuMoney float64
// tx := dao.transactionContext.PgTx
// employeeModel := new(models.Employee)
// if err := tx.Model(employeeModel).
// ColumnExpr("sum(employee.su_money) AS system_unExchange_su_money").
// Where("employee.company_id = ?", companyId).
// Select(&systemUnExchangeSuMoney); err != nil {
// return nil, err
// }
// exchangeCashActivityModel := new(models.ExchangeCashActivity)
// if err := tx.Model(exchangeCashActivityModel).
// ColumnExpr("sum(exchange_cash_activity.exchanged_su_money) AS system_changed_su_money").
// Where("exchange_cash_activity.company_id = ?", companyId).
// Select(&systemExchangedSuMoney); err != nil {
// return nil, err
// }
// return map[string]interface{}{
// "systemUnExchangeSuMoney": systemUnExchangeSuMoney,
// "systemExchangedSuMoney": systemExchangedSuMoney,
// }, nil
//}
// 计算系统已兑换现金、未兑换现金
//func (dao *CashPoolDao) CalculateSystemCash(companyId int64) (map[string]interface{}, error) {
// var systemExchangedCash float64 // 系统已兑换现金
// var systemUnExchangeCash float64 // 系统未兑换现金
// tx := dao.transactionContext.PgTx
// exchangeCashActivityModel := new(models.ExchangeCashActivity)
// if err := tx.Model(exchangeCashActivityModel).
// ColumnExpr("sum(exchange_cash_activity.exchanged_cash) AS system_exchanged_cash").
// Where("exchange_cash_activity.company_id = ?", companyId).
// Select(&systemExchangedCash) ; err != nil {
// return nil, err
// }
// return map[string]interface{}{
// "systemExchangedCash": systemExchangedCash,
// "systemUnExchangeCash": systemUnExchangeCash,
// }, nil
//}
// 兑换活动兑换清单已兑换素币、已兑换现金
func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map[string]interface{}, error) {
var activityExchangedSuMoney float64
var activityExchangedCash float64
tx := dao.transactionContext.PgTx
exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money").
Where("exchange_cash_person_list.activity_id = ?", activityId).
Select(&activityExchangedSuMoney); err !=nil {
return nil, err
}
if err := tx.Model(exchangeCashPersonListModels).
ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash").
Where("exchange_cash_person_list.activity_id = ?", activityId).
Select(&activityExchangedCash); err !=nil {
return nil, err
}
return map[string]interface{}{
"activityExchangedSuMoney": activityExchangedSuMoney,
"activityExchangedCash": activityExchangedCash,
}, nil
}
func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CashPoolDao{
transactionContext: transactionContext,
}, nil
}
}