This commit is contained in:
ziming 2025-07-02 15:10:36 +08:00
parent 9959fb0977
commit 0a79405533
5 changed files with 32 additions and 9 deletions

View File

@ -9,10 +9,9 @@ import (
"voucher/internal/pkg/lock" "voucher/internal/pkg/lock"
) )
// RegisterTag 注册通知标签 stock.MchId 批次创建商户, stock.BatchNo 商品批次号 func (this *VoucherBiz) RegisterTag(ctx context.Context, id int32) error {
func (this *VoucherBiz) RegisterTag(ctx context.Context, batchNo string) error {
stock, err := this.ProductRepo.GetByBatchNo(ctx, batchNo) stock, err := this.ProductRepo.GetById(ctx, id)
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,6 +7,7 @@ import (
) )
type ProductRepo interface { type ProductRepo interface {
GetById(ctx context.Context, id int32) (*bo.ProductBo, error)
FindWarningBudget(ctx context.Context, fun func(ctx context.Context, rows []*bo.ProductBo) error) error FindWarningBudget(ctx context.Context, fun func(ctx context.Context, rows []*bo.ProductBo) error) error
GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error)
GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error) GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error)

View File

@ -83,6 +83,23 @@ func (r *ProductRepoImpl) UpdateByWxResp(ctx context.Context, id int32, req *do.
return nil return nil
} }
func (r *ProductRepoImpl) GetById(ctx context.Context, id int32) (*bo.ProductBo, error) {
var item *model.Product
tx := r.db.DB(ctx).Model(model.Product{}).Where(model.Product{ID: id}).First(&item)
if tx.Error != nil {
return nil, tx.Error
}
if tx.RowsAffected == 0 {
return nil, gorm.ErrRecordNotFound
}
return r.ToBo(item), nil
}
func (r *ProductRepoImpl) GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) { func (r *ProductRepoImpl) GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error) {
var item *model.Product var item *model.Product

View File

@ -39,7 +39,7 @@ func NewHTTPServer(
srv.Route("/voucher/").POST("notifyRetry/{id}", cmb.NotifyRetry) srv.Route("/voucher/").POST("notifyRetry/{id}", cmb.NotifyRetry)
srv.Route("/voucher/").POST("queryOrder/{order_no}", cmb.QueryOrder) srv.Route("/voucher/").POST("queryOrder/{order_no}", cmb.QueryOrder)
srv.Route("/voucher/").POST("queryStock/{product_no}", cmb.QueryStock) srv.Route("/voucher/").POST("queryStock/{product_no}", cmb.QueryStock)
srv.Route("/voucher/").POST("registerTag/{batch_no}", cmb.RegisterTag) srv.Route("/voucher/").POST("registerTag/{id}", cmb.RegisterTag)
srv.Route("/voucher/").POST("pushWechatQuery", cmb.PushWechatQuery) srv.Route("/voucher/").POST("pushWechatQuery", cmb.PushWechatQuery)
srv.Route("/voucher/").POST("timeSliceQueryPush", cmb.TimeSliceQueryPush) srv.Route("/voucher/").POST("timeSliceQueryPush", cmb.TimeSliceQueryPush)
srv.Route("/voucher/").POST("pushWechatRetry/{batch_no}", cmb.PushWechatRetry) srv.Route("/voucher/").POST("pushWechatRetry/{batch_no}", cmb.PushWechatRetry)

View File

@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/v2/transport/http" "github.com/go-kratos/kratos/v2/transport/http"
"github.com/robfig/cron" "github.com/robfig/cron"
http2 "net/http" http2 "net/http"
"strconv"
v1 "voucher/api/v1" v1 "voucher/api/v1"
"voucher/internal/biz" "voucher/internal/biz"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
@ -70,16 +71,21 @@ func (c *CmbService) OrderRetry(ctx context.Context, request *v1.OrderRetryReque
func (this *CmbService) RegisterTag(ctx http.Context) error { func (this *CmbService) RegisterTag(ctx http.Context) error {
batchNo := ctx.Vars().Get("batch_no") id := ctx.Vars().Get("id")
if batchNo == "" { if id == "" {
return fmt.Errorf("batch_no is empty") return fmt.Errorf("id is empty")
} }
if err := this.VoucherBiz.RegisterTag(ctx, batchNo); err != nil { int64Id, err := strconv.ParseInt(id, 10, 32)
if err != nil {
return err
}
if err = this.VoucherBiz.RegisterTag(ctx, int32(int64Id)); err != nil {
return err return err
} }
return ctx.JSON(http2.StatusOK, map[string]interface{}{ return ctx.JSON(http2.StatusOK, map[string]interface{}{
"data": batchNo, "data": id,
}) })
} }