op order list

This commit is contained in:
lwl0608 2024-03-21 16:02:41 +08:00
parent b263f04fd1
commit 6d73c70cf7
8 changed files with 223 additions and 13 deletions

View File

@ -12,13 +12,15 @@ type OpCreateOrderData struct{}
// 获取金币订单列表
type OpCoinOrderListReq struct {
Mid int64 `json:"mid"` // 用户mid
UserName int64 `json:"user_name"` // 用户昵称
St int64 `json:"st"` // 开始时间戳
Et int64 `json:"et"` // 结束时间戳
OrderStatus int32 `json:"order_status"` // 订单状态
Offset int `json:"offset"`
Limit int `json:"limit"`
Mid int64 `json:"mid"` // 用户mid
UserId int64 `json:"user_id"` // 用户user_id
OrderId string `json:"order_id"` // 金币订单id
UserName int64 `json:"user_name"` // 用户昵称
St int64 `json:"st"` // 开始时间戳
Et int64 `json:"et"` // 结束时间戳
OrderStatus int32 `json:"order_status"` // 订单状态
Offset int `json:"offset"`
Limit int `json:"limit"`
}
type OpCoinOrderVO struct {
@ -31,6 +33,7 @@ type OpCoinOrderVO struct {
OrderStatusDesc string `json:"order_status_desc"`
Coins int64 `json:"coins"`
Ct int64 `json:"ct"`
ProductName string `json:"product_name"`
}
type OpCoinOrderListData struct {
@ -62,3 +65,35 @@ type RefundCoinOrderReq struct {
type RefundCoinOrderData struct {
}
// 获取金币订单列表
type OpOrderListReq struct {
Mid int64 `json:"mid"` // 用户mid
UserId int64 `json:"user_id"` // 用户user_id
OrderId string `json:"order_id"` // 金币订单id
UserName int64 `json:"user_name"` // 用户昵称
St int64 `json:"st"` // 开始时间戳
Et int64 `json:"et"` // 结束时间戳
OrderStatus int32 `json:"order_status"` // 订单状态
Offset int `json:"offset"`
Limit int `json:"limit"`
}
type OpOrderVO 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"`
ProductName string `json:"product_name"`
}
type OpOrderListData struct {
List []*OpOrderVO `json:"list"`
//Offset int `json:"offset"`
//More int `json:"more"`
}

View File

@ -239,7 +239,8 @@ func Init(r *gin.Engine) {
opVasPayGroup := r.Group("/op/vas", PrepareOp())
opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder)
opVasPayGroup.POST("coin_order_list", middleware.JSONParamValidator(vasproto.OpCoinOrderListReq{}), OpOrderList)
opVasPayGroup.POST("coin_order_list", middleware.JSONParamValidator(vasproto.OpCoinOrderListReq{}), OpCoinOrderList)
opVasPayGroup.POST("order_list", middleware.JSONParamValidator(vasproto.OpOrderListReq{}), OpOrderList)
opVasPayGroup.POST("refund_order", middleware.JSONParamValidator(vasproto.RefundOrderReq{}), RefundOrder)
opVasPayGroup.POST("refund_coin_order", middleware.JSONParamValidator(vasproto.RefundCoinOrderReq{}), RefundCoinOrder)

View File

@ -9,8 +9,11 @@ import (
"service/library/logger"
)
func OpOrderList(ctx *gin.Context) {
func OpCoinOrderList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*vasproto.OpCoinOrderListReq)
if req.Limit <= 0 {
req.Limit = 1000
}
list, ec := service.DefaultService.OpCoinOrderList(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("OpCoinOrderList fail, req: %v, ec: %v", util.ToJson(req), ec)
@ -22,3 +25,20 @@ func OpOrderList(ctx *gin.Context) {
}
ReplyOk(ctx, data)
}
func OpOrderList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*vasproto.OpOrderListReq)
if req.Limit <= 0 {
req.Limit = 1000
}
list, ec := service.DefaultService.OpOrderList(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("OpOrderList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &vasproto.OpOrderListData{
List: list,
}
ReplyOk(ctx, data)
}

View File

@ -487,6 +487,23 @@ func (m *Mongo) GetProductById(ctx *gin.Context, id string) (*dbstruct.Product,
return product, nil
}
func (m *Mongo) GetProductByIds(ctx *gin.Context, ids []string) ([]*dbstruct.Product, error) {
list := make([]*dbstruct.Product, 0)
col := m.getColProduct()
query := qmgo.M{
"_id": qmgo.M{
"$in": ids,
},
"del_flag": 0,
}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, nil
}
return list, nil
}
func (m *Mongo) GetProductByDtType(ctx *gin.Context, dt int32, typ string) ([]*dbstruct.Product, error) {
list := make([]*dbstruct.Product, 0)
col := m.getColProduct()

View File

@ -227,6 +227,25 @@ func (m *Mysql) GetOrdersByMid(ctx *gin.Context, tx *sqlx.Tx, mid int64, offset,
return
}
// 获取订单
func (m *Mysql) GetOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64, offset, limit int) (list []*dbstruct.Order, err error) {
list = make([]*dbstruct.Order, 0)
sqlStr := fmt.Sprintf("select * from %s where ct>=%d and ct<%d limit %d offset %s", TableOrder, st, et, limit, offset)
if mid > 0 {
sqlStr = fmt.Sprintf("select * from %s where mid=%d", TableOrder, 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
}
// 更新订单状态
func (m *Mysql) UpdateOrderStatus(ctx *gin.Context, tx *sqlx.Tx, orderId string, preStatus, aftStatus int32) error {
var err error
@ -468,9 +487,9 @@ func (m *Mysql) GetCoinOrderById(ctx *gin.Context, tx *sqlx.Tx, id string) (orde
}
// 获取金币订单
func (m *Mysql) GetCoinOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64) (list []*dbstruct.CoinOrder, err error) {
func (m *Mysql) GetCoinOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64, offset, limit int) (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)
sqlStr := fmt.Sprintf("select * from %s where ct>=%d and ct<%d limit %d offset %d", TableCoinOrder, st, et, limit, offset)
if mid > 0 {
sqlStr = fmt.Sprintf("select * from %s where mid=%d", TableCoinOrder, mid)
}

View File

@ -77,6 +77,19 @@ func (v *Vas) GetCoinsProductList(ctx *gin.Context, req *vasproto.GetCoinsProduc
return
}
func (v *Vas) GetProductMapByIds(ctx *gin.Context, ids []string) (m map[string]*dbstruct.Product, err error) {
list, err := v.store.GetProductByIds(ctx, ids)
if err != nil {
return
}
m = make(map[string]*dbstruct.Product)
for _, p := range list {
m[p.Id] = p
}
return
}
func (v *Vas) GetMembershipProductList(ctx *gin.Context, req *vasproto.GetMembershipProductListReq) (product *dbstruct.Product, err error) {
// 获取所有会员商品
product, err = v.store.GetProductById(ctx, dbstruct.ProductIdMembership)

View File

@ -6,7 +6,20 @@ import (
"service/dbstruct"
)
// 获取订单
// 获取金币订单
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)
if len(req.OrderId) > 0 {
o, err := v.store.GetCoinOrderByIdForUpdate(ctx, nil, req.OrderId)
return []*dbstruct.CoinOrder{o}, err
}
return v.store.GetCoinOrders(ctx, nil, req.Mid, req.St, req.Et, req.Offset, req.Limit)
}
// 获取订单
func (v *Vas) OpOrderList(ctx *gin.Context, req *vasproto.OpOrderListReq) ([]*dbstruct.Order, error) {
if len(req.OrderId) > 0 {
o, err := v.store.GetOrderById(ctx, nil, req.OrderId)
return []*dbstruct.Order{o}, err
}
return v.store.GetOrders(ctx, nil, req.Mid, req.St, req.Et, req.Offset, req.Limit)
}

View File

@ -3,8 +3,10 @@ package service
import (
"encoding/base64"
"fmt"
goproto "google.golang.org/protobuf/proto"
"service/api/errcode"
"service/api/errs"
accountproto "service/api/proto/account/proto"
vasproto "service/api/proto/vas/proto"
vericodeproto "service/api/proto/vericode/proto"
"service/bizcommon/util"
@ -476,6 +478,15 @@ func (s *Service) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq
func (s *Service) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderListReq) (list []*vasproto.OpCoinOrderVO, ec errcode.ErrCode) {
list = make([]*vasproto.OpCoinOrderVO, 0)
if req.UserId > 0 && req.Mid <= 0 {
a, _ := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
UserId: goproto.Int64(req.UserId),
})
if a != nil && a.Mid != nil {
req.Mid = *a.Mid
}
}
// 获取金币订单
coinOrders, err := _DefaultVas.OpCoinOrderList(ctx, req)
ec, err = errs.DealVasErr(err)
@ -486,12 +497,21 @@ func (s *Service) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderLis
// 获取用户信息
mids := make([]int64, 0)
productIdMap := make(map[string]struct{})
for _, co := range coinOrders {
mids = append(mids, co.GetMid())
mids = append(mids, co.GetUid())
productIdMap[co.GetProductId()] = struct{}{}
}
acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids)
// 获取商品
productIds := make([]string, 0)
for id := range productIdMap {
productIds = append(productIds, id)
}
_, _ = _DefaultVas.GetProductMapByIds(ctx, productIds)
// 组装
for _, co := range coinOrders {
var (
@ -516,6 +536,78 @@ func (s *Service) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderLis
Coins: co.GetCoins(),
Ct: co.GetCt(),
}
switch co.GetProductId() {
case dbstruct.ProductIdContactWechat:
item.ProductName = "微信联系方式"
}
list = append(list, item)
}
return
}
func (s *Service) OpOrderList(ctx *gin.Context, req *vasproto.OpOrderListReq) (list []*vasproto.OpOrderVO, ec errcode.ErrCode) {
list = make([]*vasproto.OpOrderVO, 0)
if req.UserId > 0 && req.Mid <= 0 {
a, _ := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
UserId: goproto.Int64(req.UserId),
})
if a != nil && a.Mid != nil {
req.Mid = *a.Mid
}
}
// 获取金币订单
orders, err := _DefaultVas.OpOrderList(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("OpOrderList fail, req: %v, err: %v", util.ToJson(req), err)
return
}
// 获取用户信息
mids := make([]int64, 0)
productIdMap := make(map[string]struct{})
for _, co := range orders {
mids = append(mids, co.GetMid())
mids = append(mids, co.GetUid())
productIdMap[co.GetProductId()] = struct{}{}
}
acntMap, _ := _DefaultAccount.GetAccountMapByMids(ctx, mids)
// 获取商品
productIds := make([]string, 0)
for id := range productIdMap {
productIds = append(productIds, id)
}
productMap, _ := _DefaultVas.GetProductMapByIds(ctx, productIds)
// 组装
for _, o := range orders {
var (
userUserId = int64(0)
streamerUserId = int64(0)
)
if a, ok := acntMap[o.GetMid()]; ok {
userUserId = util.DerefInt64(a.UserId)
}
if a, ok := acntMap[o.GetUid()]; ok {
streamerUserId = util.DerefInt64(a.UserId)
}
item := &vasproto.OpOrderVO{
Mid: o.GetMid(),
UserUserId: userUserId,
Uid: o.GetUid(),
StreamerUserId: streamerUserId,
OrderId: o.GetID(),
OrderStatus: o.GetOrderStatus(),
OrderStatusDesc: dbstruct.CoinOrderStatusDescMap[o.GetOrderStatus()],
Coins: o.GetCoins(),
Ct: o.GetCt(),
}
if p, ok := productMap[o.GetProductId()]; ok {
item.ProductName = p.Name
}
list = append(list, item)
}
return