cmb
This commit is contained in:
parent
f840cbf0ae
commit
dd27b4293c
|
|
@ -2,13 +2,14 @@ package cmb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"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
|
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
|
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 {
|
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
|
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 {
|
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
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
type OrderRepo interface {
|
type OrderRepo interface {
|
||||||
GetByOutBizNo(ctx context.Context, outBizNo string) (*bo.OrderBo, error)
|
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)
|
Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderBo, error)
|
||||||
GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error)
|
GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error)
|
||||||
Ing(ctx context.Context, id uint64) error
|
Ing(ctx context.Context, id uint64) error
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,24 @@ package biz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"voucher/internal/biz/cmb"
|
"voucher/internal/biz/cmb"
|
||||||
|
"voucher/internal/biz/repo"
|
||||||
"voucher/internal/data"
|
"voucher/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VoucherBiz struct {
|
type VoucherBiz struct {
|
||||||
rdb *data.Rdb
|
rdb *data.Rdb
|
||||||
Cmb *cmb.Cmb
|
Cmb *cmb.Cmb
|
||||||
|
OrderRepo repo.OrderRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVoucherBiz(
|
func NewVoucherBiz(
|
||||||
rdb *data.Rdb,
|
rdb *data.Rdb,
|
||||||
Cmb *cmb.Cmb,
|
Cmb *cmb.Cmb,
|
||||||
|
OrderRepo repo.OrderRepo,
|
||||||
) *VoucherBiz {
|
) *VoucherBiz {
|
||||||
return &VoucherBiz{
|
return &VoucherBiz{
|
||||||
rdb: rdb,
|
rdb: rdb,
|
||||||
Cmb: Cmb,
|
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
|
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 {
|
func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue