104 lines
2.8 KiB
Go
104 lines
2.8 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
v1 "voucher/api/v1"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/biz/kog"
|
|
)
|
|
|
|
func (v *VoucherBiz) cmbToBB(ctx context.Context, cmbReq *v1.CmbOrderRequest) error {
|
|
|
|
req := &kog.CmbToBBRequest{
|
|
TransactionId: cmbReq.TransactionId,
|
|
ActivityId: cmbReq.ActivityId,
|
|
CmbUid: cmbReq.CmbUid,
|
|
CmbUidType: cmbReq.CmbUidType,
|
|
Timestamp: cmbReq.Timestamp,
|
|
AppId: cmbReq.AppId,
|
|
Attach: cmbReq.Attach,
|
|
}
|
|
|
|
return v.KxMixRepo.Request(ctx, req.GetNotice())
|
|
}
|
|
|
|
func (v *VoucherBiz) bbToWx(ctx context.Context, order *bo.OrderBo, cmbReply *v1.CmbReply) error {
|
|
|
|
b, err := json.Marshal(cmbReply)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
wxRes, err := json.Marshal(map[string]string{"coupon_id": order.VoucherNo})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
req := &kog.BBToWechatRequest{
|
|
TransactionId: order.OutBizNo,
|
|
StockId: order.BatchNo,
|
|
OutRequestNo: order.OrderNo,
|
|
AppId: order.AppID,
|
|
StockCreatorMhId: order.MerchantNo,
|
|
CouponValue: order.CouponValue,
|
|
CouponMinimum: order.MiniMum,
|
|
CouponId: order.VoucherNo,
|
|
WxRes: string(wxRes),
|
|
CmbRes: string(b),
|
|
}
|
|
|
|
return v.KxMixRepo.Request(ctx, req.GetNotice())
|
|
}
|
|
|
|
func (v *VoucherBiz) wxToBBUse(ctx context.Context, order *bo.OrderBo, wxReq *bo.WechatVoucherNotifyBo) error {
|
|
|
|
req := &kog.WechatToBBRequest{
|
|
ActivityId: order.BatchNo,
|
|
ActivityName: wxReq.PlainText.CouponName,
|
|
VoucherId: order.VoucherNo,
|
|
UserId: order.Account,
|
|
UseTime: wxReq.PlainText.ConsumeInformation.ConsumeTime,
|
|
UseAmount: wxReq.PlainText.ConsumeInformation.ConsumeAmount,
|
|
BizType: "V_USE",
|
|
RefundTime: "",
|
|
RefundAmount: "",
|
|
VoucherStatus: "",
|
|
OrderId: order.OutBizNo,
|
|
TradeNo: order.OrderNo,
|
|
GmtVoucherCreate: fmt.Sprintf("%d", order.ReceiveSuccessTime.Unix()),
|
|
}
|
|
|
|
inputFormat := time.RFC3339
|
|
|
|
if wxReq.PlainText.ConsumeInformation.ConsumeTime != "" {
|
|
useTime, _ := time.Parse(inputFormat, wxReq.PlainText.ConsumeInformation.ConsumeTime)
|
|
req.UseTime = fmt.Sprintf("%d", useTime.Unix())
|
|
}
|
|
|
|
return v.KxMixRepo.Request(ctx, req.GetNotice())
|
|
}
|
|
|
|
func (v *VoucherBiz) wxToBBRefund(ctx context.Context, order *bo.OrderBo) error {
|
|
|
|
req := &kog.WechatToBBRequest{
|
|
ActivityId: order.BatchNo,
|
|
ActivityName: "",
|
|
VoucherId: order.VoucherNo,
|
|
UserId: order.Account,
|
|
UseTime: "",
|
|
UseAmount: 0,
|
|
BizType: "V_REFUND",
|
|
RefundTime: "",
|
|
RefundAmount: "",
|
|
VoucherStatus: "",
|
|
OrderId: order.OutBizNo,
|
|
TradeNo: order.OrderNo,
|
|
GmtVoucherCreate: fmt.Sprintf("%d", order.ReceiveSuccessTime.Unix()),
|
|
}
|
|
|
|
return v.KxMixRepo.Request(ctx, req.GetNotice())
|
|
}
|