forked from free-lancers/electricity_bill_calc_service
fix(charge):改进用户充值部分的查询错误。
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/georgysavva/scany/v2/pgxscan"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/samber/lo"
|
||||
"github.com/shopspring/decimal"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -39,7 +38,7 @@ func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *types.Dat
|
||||
tools.CondFn(func(t *types.Date) bool { return t != nil }, beginTime, beginTime.Format("2006-01-02"), "UNDEF"),
|
||||
tools.CondFn(func(t *types.Date) bool { return t != nil }, endTime, endTime.Format("2006-01-02"), "UNDEF"),
|
||||
}
|
||||
if charges, total, err := cache.RetrievePagedSearch[[]*model.UserChargeDetail]("charges", cacheConditions...); err == nil {
|
||||
if charges, total, err := cache.RetrievePagedSearch[[]*model.UserChargeDetail]("charges", cacheConditions...); err == nil && charges != nil {
|
||||
cr.log.Info("从缓存中获取用户的充值记录成功。", zap.Int("count", len(*charges)), zap.Int64("total", total))
|
||||
return *charges, total, nil
|
||||
}
|
||||
@@ -49,15 +48,15 @@ func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *types.Dat
|
||||
chargeQuery := cr.ds.
|
||||
From(goqu.T("user_charge").As("c")).
|
||||
Join(goqu.T("user_detail").As("ud"), goqu.On(goqu.I("c.user_id").Eq(goqu.I("ud.id")))).
|
||||
Join(goqu.T("user").As("u"), goqu.On(goqu.I("ud.user_id").Eq(goqu.I("u.id")))).
|
||||
Join(goqu.T("user").As("u"), goqu.On(goqu.I("ud.id").Eq(goqu.I("u.id")))).
|
||||
Select(
|
||||
"c.seq", "c.user_id", "ud.name", "c.fee", "c.discount", "c.amount", "c.charge_to",
|
||||
"c.settled", "c.settled_at", "c.cancelled", "c.cancelled_at", "c.created_at",
|
||||
"c.settled", "c.settled_at", "c.cancelled", "c.cancelled_at", "c.refunded", "c.refunded_at", "c.created_at",
|
||||
)
|
||||
countQuery := cr.ds.
|
||||
From(goqu.T("user_charge").As("c")).
|
||||
Join(goqu.T("user_detail").As("ud"), goqu.On(goqu.I("c.user_id").Eq(goqu.I("ud.id")))).
|
||||
Join(goqu.T("user").As("u"), goqu.On(goqu.I("ud.user_id").Eq(goqu.I("u.id")))).
|
||||
Join(goqu.T("user").As("u"), goqu.On(goqu.I("ud.id").Eq(goqu.I("u.id")))).
|
||||
Select(goqu.COUNT("*"))
|
||||
|
||||
if keyword != nil && len(*keyword) > 0 {
|
||||
@@ -84,7 +83,7 @@ func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *types.Dat
|
||||
countQuery = countQuery.Where(goqu.I("c.charge_to").Lte(*endTime))
|
||||
}
|
||||
|
||||
chargeQuery = chargeQuery.Order(goqu.I("c.created_by").Desc())
|
||||
chargeQuery = chargeQuery.Order(goqu.I("c.created_at").Desc())
|
||||
|
||||
currentPostion := (page - 1) * config.ServiceSettings.ItemsPageSize
|
||||
chargeQuery = chargeQuery.Offset(currentPostion).Limit(config.ServiceSettings.ItemsPageSize)
|
||||
@@ -109,7 +108,7 @@ func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *types.Dat
|
||||
}
|
||||
|
||||
// 在用户充值记录中创建一条新的记录
|
||||
func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, uid string, fee, discount, amount *decimal.Decimal, chargeTo types.Date) (bool, error) {
|
||||
func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, uid string, fee, discount, amount *float64, chargeTo types.Date) (bool, error) {
|
||||
createQuery, createArgs, _ := cr.ds.
|
||||
Insert(goqu.T("user_charge")).
|
||||
Cols("user_id", "fee", "discount", "amount", "charge_to", "created_at").
|
||||
|
Reference in New Issue
Block a user