register tag
This commit is contained in:
parent
62cd85166d
commit
adbdc0e4bd
|
|
@ -72,7 +72,11 @@ func (v *Cmb) bizContent(_ context.Context, order *bo.OrderBo, orderNotify *bo.O
|
|||
}
|
||||
|
||||
if cmbStatus == vo.CmbStatusUse {
|
||||
req.TransDate = order.LastUseTime.Format("2006-01-02 15:04:05.000")
|
||||
if order.LastUseTime == nil || order.LastUseTime.IsZero() {
|
||||
req.TransDate = time.Now().Format("2006-01-02 15:04:05.000")
|
||||
} else {
|
||||
req.TransDate = order.LastUseTime.Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
} else {
|
||||
req.TransDate = time.Now().Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,17 +158,6 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
|||
func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, useNum, sucNum *int) (respErr error) {
|
||||
// 批量通知不做数据存储,量会很大
|
||||
|
||||
if order == nil {
|
||||
return fmt.Errorf("order is nil")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
|
||||
respErr = fmt.Errorf("notice panic:%v, orderNo:%s, file:%s, line:%d", err, order.OrderNo, file, line)
|
||||
}
|
||||
}()
|
||||
|
||||
status, err := v.WechatCpnRepo.Query(ctx, order)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -178,6 +167,8 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, useNum, sucN
|
|||
return nil // 券状态未改变,忽略不处理
|
||||
}
|
||||
|
||||
order.Status = status
|
||||
|
||||
event, err := status.GetOrderNotifyEvent()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -212,11 +203,19 @@ func (v *VoucherBiz) request(ctx context.Context, order *bo.OrderBo, notify *bo.
|
|||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
// 打印堆栈信息
|
||||
stackBuf := make([]byte, 1024)
|
||||
stackSize := runtime.Stack(stackBuf, false)
|
||||
// 获取调用栈信息
|
||||
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
|
||||
respErr = fmt.Errorf("request panic:%v, orderNo:%s, file:%s, line:%d", err, order.OrderNo, file, line)
|
||||
respErr = fmt.Errorf("request panic:%v, orderNo:%s, file:%s, line:%d, stack: %s", err, order.OrderNo, file, line, stackBuf[:stackSize])
|
||||
}
|
||||
}()
|
||||
|
||||
if order == nil {
|
||||
return fmt.Errorf("request order is nil")
|
||||
}
|
||||
|
||||
if notify == nil {
|
||||
return fmt.Errorf("notify is nil")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,20 @@ import (
|
|||
)
|
||||
|
||||
// RegisterTag 注册通知标签 stock.MchId 批次创建商户, stock.BatchNo 商品批次号
|
||||
func (this *VoucherBiz) RegisterTag(ctx context.Context, productNo string) error {
|
||||
func (this *VoucherBiz) RegisterTag(ctx context.Context, batchNo string) error {
|
||||
|
||||
stock, err := this.ProductRepo.GetByProductNo(ctx, productNo)
|
||||
stock, err := this.ProductRepo.GetByBatchNo(ctx, batchNo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.registerNotifyTag(ctx, stock.MchId, stock.BatchNo)
|
||||
if err = this.registerNotifyTag(ctx, stock.MchId, stock.BatchNo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = this.ProductRepo.GetByProductNo(ctx, stock.ProductNo)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) registerNotifyTag(ctx context.Context, stockCreatorMchID, stockID string) error {
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ import (
|
|||
)
|
||||
|
||||
type ProductRepo interface {
|
||||
GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error)
|
||||
GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,27 @@ func NewProductRepoImpl(db *data.Db, rdb *data.Rdb) repo.ProductRepo {
|
|||
return &ProductRepoImpl{db: db, rdb: rdb}
|
||||
}
|
||||
|
||||
func (r *ProductRepoImpl) GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) {
|
||||
|
||||
var item *model.Product
|
||||
|
||||
db := r.db.DB(ctx).Model(model.Product{})
|
||||
tx := db.Where(model.Product{BatchNo: batchNo}).First(&item)
|
||||
|
||||
if tx.Error != nil {
|
||||
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
|
||||
return nil, err2.ErrorDbNotFound("商品数据不存在")
|
||||
}
|
||||
return nil, fmt.Errorf("product db fail %w", tx.Error)
|
||||
}
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, err2.ErrorDbNotFound("商品数据不存在")
|
||||
}
|
||||
|
||||
return r.ToBo(item), nil
|
||||
}
|
||||
|
||||
func (r *ProductRepoImpl) GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error) {
|
||||
|
||||
c := vo.ProductQueryKey.BuildCache([]string{productNo})
|
||||
|
|
|
|||
|
|
@ -70,17 +70,16 @@ func (c *CmbService) OrderRetry(ctx context.Context, request *v1.OrderRetryReque
|
|||
|
||||
func (this *CmbService) RegisterTag(ctx http.Context) error {
|
||||
|
||||
productNo := ctx.Vars().Get("product_no")
|
||||
if productNo == "" {
|
||||
return fmt.Errorf("product_no is empty")
|
||||
batchNo := ctx.Vars().Get("batch_no")
|
||||
if batchNo == "" {
|
||||
return fmt.Errorf("batch_no is empty")
|
||||
}
|
||||
|
||||
err := this.VoucherBiz.RegisterTag(ctx, productNo)
|
||||
if err != nil {
|
||||
if err := this.VoucherBiz.RegisterTag(ctx, batchNo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.JSON(http2.StatusOK, map[string]interface{}{
|
||||
"data": productNo,
|
||||
"data": batchNo,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue