Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package srv_cointrans
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/cointransmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetCoinTrans 分页查询金币交易流水
|
||||
func GetCoinTrans(ctx context.Context, req *CoinTransReq) (*CoinTransResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
|
||||
if req.UserId != nil && *req.UserId > 0 {
|
||||
filter[cointransmod.FN.CoinTrans.UserId] = *req.UserId
|
||||
}
|
||||
if req.FlowDir != nil {
|
||||
filter[cointransmod.FN.CoinTrans.FlowDir] = *req.FlowDir
|
||||
}
|
||||
if req.TranType != nil {
|
||||
filter[cointransmod.FN.CoinTrans.TranType] = *req.TranType
|
||||
}
|
||||
|
||||
timeFilter := bson.M{}
|
||||
if req.StartTime != nil && *req.StartTime != "" {
|
||||
if t, ok := parseTime(*req.StartTime); ok {
|
||||
timeFilter["$gte"] = t
|
||||
}
|
||||
}
|
||||
if req.EndTime != nil && *req.EndTime != "" {
|
||||
if t, ok := parseTime(*req.EndTime); ok {
|
||||
timeFilter["$lte"] = t
|
||||
}
|
||||
}
|
||||
if len(timeFilter) > 0 {
|
||||
filter[cointransmod.FN.CoinTrans.CreatedAt] = timeFilter
|
||||
}
|
||||
|
||||
total, serr := cointransmod.CountCoinTrans(ctx, filter)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
resp := &CoinTransResp{Total: total}
|
||||
if total == 0 {
|
||||
resp.List = cointransmod.CoinTransList{}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
opt := options.Find().
|
||||
SetSort(bson.D{{Key: cointransmod.FN.CoinTrans.CreatedAt, Value: -1}}).
|
||||
SetSkip((req.PageNum - 1) * req.PageSize).
|
||||
SetLimit(req.PageSize)
|
||||
|
||||
list, serr := cointransmod.FindManyCoinTrans(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
resp.List = list
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user