52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
"voucher/internal/biz/repo"
|
|
"voucher/internal/biz/thirdrepo"
|
|
"voucher/internal/data"
|
|
"voucher/internal/pkg/lock"
|
|
)
|
|
|
|
type VoucherBiz struct {
|
|
rdb *data.Rdb
|
|
OrderRepo repo.OrderRepo
|
|
ThirdMQSend thirdrepo.ThirdMQSend
|
|
}
|
|
|
|
func NewVoucherBiz(rdb *data.Rdb, orderRepo repo.OrderRepo, thirdMQSend thirdrepo.ThirdMQSend) *VoucherBiz {
|
|
return &VoucherBiz{rdb: rdb, OrderRepo: orderRepo, ThirdMQSend: thirdMQSend}
|
|
}
|
|
|
|
func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
|
|
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("order_consume_%s", orderNo), func(ctx context.Context) error {
|
|
|
|
return nil
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func (v *VoucherBiz) QueryConsume(ctx context.Context, orderNo string) (err error) {
|
|
|
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("query_consume_%s", orderNo), func(ctx context.Context) error {
|
|
|
|
return nil
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func (v *VoucherBiz) NotifyConsume(ctx context.Context, orderNo string) (err error) {
|
|
|
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("notify_consume_%s", orderNo), func(ctx context.Context) error {
|
|
|
|
return nil
|
|
})
|
|
|
|
return
|
|
}
|