From c6085f42d6f6de8feb9c7fdf54ba08342e8ededa Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Wed, 17 Jan 2024 21:57:45 +0800 Subject: [PATCH] op order_list --- api/proto/vas/proto/op.go | 23 +++++++++++----- app/mix/controller/init.go | 2 +- app/mix/controller/vas_op.go | 24 +++++++++++------ app/mix/dao/mysql.go | 19 +++++++++++++ app/mix/service/logic/vas_op.go | 12 ++++++--- app/mix/service/vasservice.go | 47 +++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 19 deletions(-) diff --git a/api/proto/vas/proto/op.go b/api/proto/vas/proto/op.go index e592d11a..d98e89b1 100644 --- a/api/proto/vas/proto/op.go +++ b/api/proto/vas/proto/op.go @@ -10,8 +10,8 @@ type OpCreateOrderReq struct { type OpCreateOrderData struct{} -// 获取订单列表 -type OpOrderListReq struct { +// 获取金币订单列表 +type OpCoinOrderListReq struct { Mid int64 `json:"mid"` // 用户mid UserName int64 `json:"user_name"` // 用户昵称 St int64 `json:"st"` // 开始时间戳 @@ -21,11 +21,20 @@ type OpOrderListReq struct { Limit int `json:"limit"` } -type OpOrderVO struct { +type OpCoinOrderVO struct { + Mid int64 `json:"mid"` + UserUserId int64 `json:"user_user_id"` + Uid int64 `json:"uid"` + StreamerUserId int64 `json:"streamer_user_id"` + OrderId string `json:"order_id"` + OrderStatus int32 `json:"order_status"` + OrderStatusDesc string `json:"order_status_desc"` + Coins int64 `json:"coins"` + Ct int64 `json:"ct"` } -type OpOrderListData struct { - List []*OpOrderVO `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` +type OpCoinOrderListData struct { + List []*OpCoinOrderVO `json:"list"` + //Offset int `json:"offset"` + //More int `json:"more"` } diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 92e9662a..666e74e9 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -198,7 +198,7 @@ func Init(r *gin.Engine) { opVasPayGroup := r.Group("/op/vas", PrepareOp()) opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder) - opVasPayGroup.POST("order_list") + opVasPayGroup.POST("order_list", middleware.JSONParamValidator(vasproto.OpCoinOrderListReq{}), OpOrderList) // 验证码 opVeriCodeGroup := r.Group("/op/veri_code", PrepareOp()) diff --git a/app/mix/controller/vas_op.go b/app/mix/controller/vas_op.go index 9deae30e..cd95a3aa 100644 --- a/app/mix/controller/vas_op.go +++ b/app/mix/controller/vas_op.go @@ -2,15 +2,23 @@ package controller import ( "github.com/gin-gonic/gin" + "service/api/errcode" + vasproto "service/api/proto/vas/proto" + "service/app/mix/service" + "service/bizcommon/util" + "service/library/logger" ) func OpOrderList(ctx *gin.Context) { - //req := ctx.MustGet("client_req").(*vasproto.OpOrderListReq) - //data, ec := service.DefaultService.H5DirectUnlockWechat(ctx, req) - //if ec != errcode.ErrCodeVasSrvOk { - // logger.Error("H5DirectUnlockWechat fail, req: %v, ec: %v", util.ToJson(req), ec) - // ReplyErrCodeMsg(ctx, ec) - // return - //} - //ReplyOk(ctx, data) + req := ctx.MustGet("client_req").(*vasproto.OpCoinOrderListReq) + list, ec := service.DefaultService.OpCoinOrderList(ctx, req) + if ec != errcode.ErrCodeVasSrvOk { + logger.Error("OpCoinOrderList fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + data := &vasproto.OpCoinOrderListData{ + List: list, + } + ReplyOk(ctx, data) } diff --git a/app/mix/dao/mysql.go b/app/mix/dao/mysql.go index bd1296b3..3c269ea8 100644 --- a/app/mix/dao/mysql.go +++ b/app/mix/dao/mysql.go @@ -408,6 +408,25 @@ func (m *Mysql) GetCoinOrderById(ctx *gin.Context, tx *sqlx.Tx, id string) (orde return } +// 获取金币订单 +func (m *Mysql) GetCoinOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64) (list []*dbstruct.CoinOrder, err error) { + list = make([]*dbstruct.CoinOrder, 0) + sqlStr := fmt.Sprintf("select * from %s where ct>=%d and ct<%d", TableCoinOrder, st, et) + if mid > 0 { + sqlStr = fmt.Sprintf("select * from %s where mid=%d", TableCoinOrder, mid) + } + if tx != nil { + err = tx.SelectContext(ctx, &list, sqlStr) + } else { + db := m.getDBVas() + err = db.SelectContext(ctx, &list, sqlStr) + } + if err != nil { + return + } + return +} + // 获取金币订单 for update func (m *Mysql) GetCoinOrderByIdForUpdate(ctx *gin.Context, tx *sqlx.Tx, id string) (order *dbstruct.CoinOrder, err error) { var tmpOrder dbstruct.CoinOrder diff --git a/app/mix/service/logic/vas_op.go b/app/mix/service/logic/vas_op.go index 30e511c4..b0652c69 100644 --- a/app/mix/service/logic/vas_op.go +++ b/app/mix/service/logic/vas_op.go @@ -1,6 +1,12 @@ package logic +import ( + "github.com/gin-gonic/gin" + vasproto "service/api/proto/vas/proto" + "service/dbstruct" +) + // 获取订单 -//func (v *Vas) GetOrders(ctx *gin.Context, mid int64) (*dbstruct.CoinOrder, error) { -// return v.store.GetCoinOrderById(ctx, nil, id) -//} +func (v *Vas) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderListReq) ([]*dbstruct.CoinOrder, error) { + return v.store.GetCoinOrders(ctx, nil, req.Mid, req.St, req.Et) +} diff --git a/app/mix/service/vasservice.go b/app/mix/service/vasservice.go index 3227af04..7e98c9d5 100644 --- a/app/mix/service/vasservice.go +++ b/app/mix/service/vasservice.go @@ -447,3 +447,50 @@ func (s *Service) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq } return } + +func (s *Service) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderListReq) (list []*vasproto.OpCoinOrderVO, ec errcode.ErrCode) { + list = make([]*vasproto.OpCoinOrderVO, 0) + // 获取金币订单 + coinOrders, err := _DefaultVas.OpCoinOrderList(ctx, req) + ec, err = errs.DealVasErr(err) + if err != nil { + logger.Error("OpCoinOrderList fail, req: %v, err: %v", util.ToJson(req), err) + return + } + + // 获取用户信息 + mids := make([]int64, 0) + for _, co := range coinOrders { + mids = append(mids, co.GetMid()) + mids = append(mids, co.GetUid()) + } + acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids) + + // 组装 + for _, co := range coinOrders { + var ( + userUserId = int64(0) + streamerUserId = int64(0) + ) + if a, ok := acntMap[co.GetMid()]; ok { + userUserId = util.DerefInt64(a.UserId) + } + if a, ok := acntMap[co.GetUid()]; ok { + streamerUserId = util.DerefInt64(a.UserId) + } + + item := &vasproto.OpCoinOrderVO{ + Mid: co.GetMid(), + UserUserId: userUserId, + Uid: co.GetUid(), + StreamerUserId: streamerUserId, + OrderId: co.GetID(), + OrderStatus: co.GetOrderStatus(), + OrderStatusDesc: dbstruct.CoinOrderStatusDescMap[co.GetOrderStatus()], + Coins: co.GetCoins(), + Ct: co.GetCt(), + } + list = append(list, item) + } + return +}