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, }) } func (this *CmbService) QueryByOrderNo(ctx http.Context) error { // 获取访问 ip ip := ctx.Request().Header.Get("X-Forwarded-For") if len(ip) == 0 { ip = ctx.Request().RemoteAddr } if ip != "117.175.169.61" && ip != "127.0.0.1" { return fmt.Errorf("ip check fail,IP:%s", ip) } orderNo := ctx.Vars().Get("order_no") if orderNo == "" { return fmt.Errorf("orderNo is empty") } order, err := this.VoucherBiz.OrderQuery(ctx.Request().Context(), orderNo) if err != nil { return err } receiveSuccessTimeStr := "" if order.ReceiveSuccessTime != nil { receiveSuccessTimeStr = order.ReceiveSuccessTime.Format("2006-01-02 15:04:05") } lastUseTimeStr := "" if order.LastUseTime != nil { lastUseTimeStr = order.LastUseTime.Format("2006-01-02 15:04:05") } html := ` 订单查询结果

订单查询

查询结果 [%s] 悉知

订单号 %s
招行订单号 %s
订单状态 %s
openid %s
微信券 ID %s
商品编号 %s
批次号 %s
商户号 %s
appId %s
订单创建时间 %s
领取成功时间(成功即有该值) %s
最后一次核销时间(核销即有该值) %s
订单备注说明(失败说明) %s
` str := fmt.Sprintf(html, orderNo, orderNo, order.OutBizNo, order.Status.GetText(), order.Account, order.VoucherNo, order.ProductNo, order.BatchNo, order.MerchantNo, order.AppID, order.CreateTime.Format("2006-01-02 15:04:05"), receiveSuccessTimeStr, lastUseTimeStr, order.Remark, ) return ctx.String(http2.StatusOK, str) }