55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/pkg/errors"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/pkg/lock"
|
|
"voucher/internal/pkg/uid"
|
|
)
|
|
|
|
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) {
|
|
|
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
|
|
|
order, err := v.OrderRepo.GetByOutBizNo(ctx, req.OutBizNo)
|
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return err
|
|
}
|
|
|
|
if order != nil {
|
|
// todo
|
|
return nil
|
|
}
|
|
|
|
orderNo, err := v.GenerateMixRepo.GeneratorString(ctx, uid.Order)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req.OrderNo = orderNo
|
|
v.OrderRepo.Create(ctx, req)
|
|
|
|
return nil
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func (v *VoucherBiz) CmbQuery(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) {
|
|
|
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
|
|
|
return nil
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func (v *VoucherBiz) CmbNotify(ctx context.Context, order *bo.OrderBo) (err error) {
|
|
return
|
|
}
|