voucher/internal/service/cmb.go

77 lines
1.6 KiB
Go

package service
import (
"fmt"
"github.com/go-kratos/kratos/v2/transport/http"
"github.com/robfig/cron"
http2 "net/http"
"strconv"
v1 "voucher/api/v1"
"voucher/internal/biz"
"voucher/internal/biz/mixrepos"
"voucher/internal/biz/wechatrepo"
"voucher/internal/conf"
)
var _ v1.CmbHTTPServer = (*CmbService)(nil)
type CmbService struct {
bc *conf.Bootstrap
cron *cron.Cron
VoucherBiz *biz.VoucherBiz
CmbMixRepo mixrepos.CmbMixRepo
WechatCpnRepo wechatrepo.WechatCpnRepo
}
func NewCmbService(
bc *conf.Bootstrap,
cron *cron.Cron,
VoucherBiz *biz.VoucherBiz,
CmbMixRepo mixrepos.CmbMixRepo,
WechatCpnRepo wechatrepo.WechatCpnRepo,
) *CmbService {
return &CmbService{
bc: bc,
cron: cron,
VoucherBiz: VoucherBiz,
CmbMixRepo: CmbMixRepo,
WechatCpnRepo: WechatCpnRepo,
}
}
func (this *CmbService) NotifyRetry(ctx http.Context) error {
id := ctx.Vars().Get("id")
if id == "" {
return fmt.Errorf("id is empty")
}
orderNotifyId, err := strconv.ParseUint(id, 10, 64)
if err != nil {
return err
}
return this.VoucherBiz.PushNotifyRetryDelayMQ(ctx, 1, orderNotifyId)
}
func (this *CmbService) QueryOrder(ctx http.Context) error {
orderNo := ctx.Vars().Get("order_no")
if orderNo == "" {
return fmt.Errorf("orderNo is empty")
}
str, err := this.VoucherBiz.QueryOrder(ctx, orderNo)
if err != nil {
return err
}
//wechatResp, err := this.WechatCpnRepo.QueryCallback(ctx)
//if err != nil {
// return err
//}
return ctx.JSON(http2.StatusOK, map[string]interface{}{
"data": str,
})
}