cmb
This commit is contained in:
parent
f840cbf0ae
commit
dd27b4293c
|
|
@ -2,13 +2,14 @@ package cmb
|
|||
|
||||
import (
|
||||
"context"
|
||||
"voucher/internal/biz/bo"
|
||||
)
|
||||
|
||||
func (v *Cmb) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
||||
func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (v *Cmb) QueryConsume(ctx context.Context, orderNo string) (err error) {
|
||||
func (v *Cmb) QueryConsume(ctx context.Context, order *bo.OrderBo) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@ func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err erro
|
|||
|
||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("order_consume_%s", orderNo), func(ctx context.Context) error {
|
||||
|
||||
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if order.Type.IsCmb() {
|
||||
return v.Cmb.OrderConsume(ctx, order)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
@ -21,6 +30,15 @@ func (v *VoucherBiz) QueryConsume(ctx context.Context, orderNo string) (err erro
|
|||
|
||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("query_consume_%s", orderNo), func(ctx context.Context) error {
|
||||
|
||||
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if order.Type.IsCmb() {
|
||||
return v.Cmb.QueryConsume(ctx, order)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
type OrderRepo interface {
|
||||
GetByOutBizNo(ctx context.Context, outBizNo string) (*bo.OrderBo, error)
|
||||
GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderBo, error)
|
||||
Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderBo, error)
|
||||
GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error)
|
||||
Ing(ctx context.Context, id uint64) error
|
||||
|
|
|
|||
|
|
@ -2,20 +2,24 @@ package biz
|
|||
|
||||
import (
|
||||
"voucher/internal/biz/cmb"
|
||||
"voucher/internal/biz/repo"
|
||||
"voucher/internal/data"
|
||||
)
|
||||
|
||||
type VoucherBiz struct {
|
||||
rdb *data.Rdb
|
||||
Cmb *cmb.Cmb
|
||||
OrderRepo repo.OrderRepo
|
||||
}
|
||||
|
||||
func NewVoucherBiz(
|
||||
rdb *data.Rdb,
|
||||
Cmb *cmb.Cmb,
|
||||
OrderRepo repo.OrderRepo,
|
||||
) *VoucherBiz {
|
||||
return &VoucherBiz{
|
||||
rdb: rdb,
|
||||
Cmb: Cmb,
|
||||
OrderRepo: OrderRepo,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,22 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er
|
|||
return p.ToBo(info), nil
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderBo, error) {
|
||||
info := &model.Order{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).Find(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return p.ToBo(info), nil
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error {
|
||||
now := time.Now()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue