93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"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/bo"
|
|
"voucher/internal/biz/mixrepos"
|
|
"voucher/internal/biz/vo"
|
|
"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 (c *CmbService) GetResponse(ctx context.Context, replyBizContent []byte) (*v1.CmbReply, error) {
|
|
|
|
req := &bo.CmbResponseBo{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
BizContent: string(replyBizContent),
|
|
}
|
|
|
|
reply, err := c.CmbMixRepo.GetResponse(ctx, req)
|
|
if err != nil {
|
|
log.Errorf("build cmb response fail: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
return reply, nil
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
return ctx.JSON(http2.StatusOK, map[string]interface{}{
|
|
"data": str,
|
|
})
|
|
}
|