forked from free-lancers/electricity_bill_calc_service
refactor(types):将日期时间类型提取到公共的类型定义包中。
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/tools"
|
||||
"electricity_bill_calc/tools/time"
|
||||
"electricity_bill_calc/types"
|
||||
"fmt"
|
||||
st "time"
|
||||
|
||||
@@ -110,7 +111,7 @@ func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *st.Time,
|
||||
}
|
||||
|
||||
// 在用户充值记录中创建一条新的记录
|
||||
func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, uid string, fee, discount, amount *decimal.Decimal, chargeTo model.Date) (bool, error) {
|
||||
func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, uid string, fee, discount, amount *decimal.Decimal, chargeTo types.Date) (bool, error) {
|
||||
createQuery, createArgs, _ := cr.ds.
|
||||
Insert(goqu.T("user_charge")).
|
||||
Cols("user_id", "fee", "discount", "amount", "charge_to", "created_at").
|
||||
@@ -142,7 +143,7 @@ func (cr _ChargeRepository) CancelCharge(tx pgx.Tx, ctx context.Context, uid str
|
||||
}
|
||||
|
||||
// 检索用户最近有效的服务期限
|
||||
func (cr _ChargeRepository) LatestValidChargeTo(tx pgx.Tx, ctx context.Context, uid string) (*model.Date, error) {
|
||||
func (cr _ChargeRepository) LatestValidChargeTo(tx pgx.Tx, ctx context.Context, uid string) (*types.Date, error) {
|
||||
searchSql, searchArgs, _ := cr.ds.
|
||||
From(goqu.T("user_charge")).
|
||||
Select("charge_to").
|
||||
@@ -154,7 +155,7 @@ func (cr _ChargeRepository) LatestValidChargeTo(tx pgx.Tx, ctx context.Context,
|
||||
).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
var chargeTo []*model.Date
|
||||
var chargeTo []*types.Date
|
||||
if err := pgxscan.Select(ctx, tx, &chargeTo, searchSql, searchArgs...); err != nil {
|
||||
cr.log.Error("检索用户有效服务期限列表失败。", zap.Error(err))
|
||||
return nil, err
|
||||
@@ -162,6 +163,6 @@ func (cr _ChargeRepository) LatestValidChargeTo(tx pgx.Tx, ctx context.Context,
|
||||
if len(chargeTo) == 0 {
|
||||
return nil, fmt.Errorf("无法找到用户最近的有效服务期限。")
|
||||
}
|
||||
lastCharge := lo.MaxBy(chargeTo, func(a, b *model.Date) bool { return a.Time.After(b.Time) })
|
||||
lastCharge := lo.MaxBy(chargeTo, func(a, b *types.Date) bool { return a.Time.After(b.Time) })
|
||||
return lastCharge, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user