127 lines
3.1 KiB
Go
127 lines
3.1 KiB
Go
package yl
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"rs/cmd/api/internal/logic/vo"
|
|
"rs/cmd/api/internal/svc"
|
|
"rs/cmd/api/internal/types"
|
|
"rs/rpc/transfer"
|
|
"time"
|
|
)
|
|
|
|
type GetOrderLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 订单查询接口
|
|
func NewGetOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderLogic {
|
|
return &GetOrderLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetOrderLogic) GetOrder(req *types.GetOrderReq) (resp *types.GetOrderRsp, err error) {
|
|
var (
|
|
status int
|
|
)
|
|
|
|
order, err := l.svcCtx.BaseServiceContext.YlOrdersMarketRepo.FindOneByDeliverOrderNoSupplierOrderNo(l.ctx, req.DeliverOrderNo, req.SupplierOrderNo)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if order.Status != 1 {
|
|
return nil, fmt.Errorf("订单发货失败")
|
|
}
|
|
|
|
// 响应参数
|
|
data := transfer.MarketKeySendRes{}
|
|
err = json.Unmarshal([]byte(order.Resp.String), &data)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if data.Data.ShortUrl != "" {
|
|
status = 1
|
|
}
|
|
startTime, err := time.Parse("20060102", data.Data.VoucherSdate)
|
|
if err != nil {
|
|
startTime = time.Now()
|
|
}
|
|
endTime, err := time.Parse("20060102", data.Data.VoucherEdate)
|
|
if err != nil {
|
|
endTime = startTime.AddDate(0, 0, 30).Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
|
}
|
|
|
|
// 请求参数
|
|
asyncReq := types.AsyncReq{}
|
|
err = json.Unmarshal([]byte(order.Request), &asyncReq)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
resp = &types.GetOrderRsp{
|
|
DeliverOrderNo: req.DeliverOrderNo,
|
|
SupplierOrderNo: req.SupplierOrderNo,
|
|
SupplierSkuId: asyncReq.SupplierSkuId,
|
|
Account: asyncReq.Account,
|
|
SendStatus: status,
|
|
Price: asyncReq.Price,
|
|
StatusTime: order.UpdateTime.Unix(),
|
|
Msg: "",
|
|
SupplierId: asyncReq.SupplierId,
|
|
CardNo: "",
|
|
CardKey: "",
|
|
CardExpireTime: endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second).Format(time.DateTime),
|
|
CardExchangeUrl: data.Data.ShortUrl,
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 营销系统查询
|
|
func (l *GetOrderLogic) GetOrder2(req *types.GetOrderReq) (resp *types.GetOrderRsp, err error) {
|
|
request := transfer.MarketQueryReq{
|
|
AppId: l.svcCtx.Config.MarketConfig.AppId,
|
|
ReqCode: "voucher.query",
|
|
MemId: fmt.Sprintf("%d", req.SupplierId),
|
|
ReqSerialNo: req.DeliverOrderNo,
|
|
Timestamp: time.Unix(req.RequestTime, 0).Format("20060102150405"),
|
|
//VoucherId: "yl20240730",
|
|
//VoucherCode: "AAAESSGEVVpTHsbe",
|
|
}
|
|
|
|
request.Sign = l.svcCtx.Config.Sys.PrimaryKey
|
|
|
|
result, err := l.svcCtx.TransferRpc.MarketQuery(l.ctx, &request)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if result.ErrCode != vo.RES_SUCCESS {
|
|
return nil, fmt.Errorf("请求失败:%v", result.Msg)
|
|
}
|
|
|
|
resp = &types.GetOrderRsp{
|
|
DeliverOrderNo: req.DeliverOrderNo,
|
|
SupplierOrderNo: req.SupplierOrderNo,
|
|
//SupplierSkuId: req,
|
|
//Count: req.,
|
|
SendStatus: 1,
|
|
Price: 0,
|
|
StatusTime: 0,
|
|
Msg: "",
|
|
SupplierId: 0,
|
|
CardNo: "",
|
|
CardKey: "",
|
|
CardExpireTime: "",
|
|
CardExchangeUrl: result.Data.VoucherCode,
|
|
}
|
|
|
|
return
|
|
}
|