init: 初始化 web_hgdjb_server 项目
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package srv_cointrans
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/cointransmod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type CoinTransReq struct {
|
||||
pubdef.Page
|
||||
UserId *int64 `json:"userId"` // 用户ID
|
||||
FlowDir *cointransmod.FlowDir `json:"flowDir"` // 收支方向:1收入 -1支出
|
||||
TranType *cointransmod.TranType `json:"tranType"` // 交易类型
|
||||
StartTime *string `json:"startTime"` // 开始时间 2006-01-02 15:04:05
|
||||
EndTime *string `json:"endTime"` // 结束时间 2006-01-02 15:04:05
|
||||
}
|
||||
|
||||
type CoinTransResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List cointransmod.CoinTransList `json:"list"`
|
||||
}
|
||||
|
||||
func parseTime(s string) (time.Time, bool) {
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04:05", s, time.Local)
|
||||
return t, err == nil
|
||||
}
|
||||
@@ -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