97 lines
1.7 KiB
Go
97 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
v1 "voucher/api/v1"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/biz/vo"
|
|
)
|
|
|
|
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
|
|
|
reply := &v1.CmbOrderReply{
|
|
RespCode: "",
|
|
RespMsg: "",
|
|
Date: "",
|
|
KeyAlias: "",
|
|
CmbKeyAlias: "",
|
|
EncryptBody: "",
|
|
Sign: "",
|
|
CodeNo: "",
|
|
}
|
|
|
|
orderNo, err := s.cmbOrder(ctx)
|
|
if err != nil {
|
|
reply.RespCode = "1001"
|
|
reply.RespMsg = err.Error()
|
|
} else {
|
|
reply.RespCode = "1000"
|
|
reply.RespMsg = "成功"
|
|
reply.CodeNo = orderNo
|
|
}
|
|
|
|
// todo 签名
|
|
reply.Sign = ""
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
|
|
|
var req v1.CmbOrderRequest
|
|
if err := ctx.BindForm(&req); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := req.Validate(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// todo 签名验证
|
|
|
|
boReq := &bo.OrderCreateReqBo{
|
|
OutBizNo: req.TransactionId,
|
|
ProductNo: req.ActivityId,
|
|
Account: req.CmbUid,
|
|
AccountType: vo.OrderAccountTypeOpenId,
|
|
}
|
|
|
|
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return orderNo, nil
|
|
}
|
|
|
|
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|
|
|
err := s.cmbProductQuery(ctx)
|
|
if err != nil {
|
|
return ctx.JSON(200, &v1.CmbOrderReply{
|
|
RespCode: "1001",
|
|
RespMsg: err.Error(),
|
|
})
|
|
}
|
|
|
|
return ctx.JSON(200, nil)
|
|
}
|
|
|
|
func (s *VoucherService) cmbProductQuery(ctx http.Context) error {
|
|
|
|
var req v1.CmbQueryProductRequest
|
|
if err := ctx.BindForm(&req); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := req.Validate(); err != nil {
|
|
return err
|
|
}
|
|
|
|
// todo 签名验证
|
|
|
|
rep := &v1.CmbQueryProductReply{}
|
|
|
|
return ctx.JSON(200, rep)
|
|
}
|