239 lines
4.9 KiB
Go
239 lines
4.9 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
"io"
|
|
v1 "voucher/api/v1"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/biz/vo"
|
|
)
|
|
|
|
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
|
|
|
var (
|
|
reply *v1.CmbReply
|
|
|
|
bizReply *v1.CmbOrderReply
|
|
)
|
|
|
|
orderNo, err := s.cmbOrder(ctx)
|
|
|
|
if err != nil {
|
|
log.Errorf("cmbOrder error: %v", err)
|
|
bizReply = &v1.CmbOrderReply{
|
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
|
RespMsg: err.Error(),
|
|
CodeNo: "",
|
|
}
|
|
} else {
|
|
bizReply = &v1.CmbOrderReply{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
CodeNo: orderNo,
|
|
}
|
|
}
|
|
|
|
replyBizContent, _ := json.Marshal(bizReply)
|
|
xx := &bo.CmbResponseBo{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
BizContent: string(replyBizContent),
|
|
}
|
|
|
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
|
if err != nil {
|
|
log.Errorf("cmbOrder CmbMixRepo GetResponse error: %v", err)
|
|
return ctx.JSON(400, err)
|
|
}
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
|
|
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var req *v1.CmbRequest
|
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err = req.Validate(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err = bizContent.Validate(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
boReq := &bo.OrderCreateReqBo{
|
|
OutBizNo: bizContent.TransactionId,
|
|
ProductNo: bizContent.ActivityId,
|
|
Account: bizContent.CmbUid,
|
|
AppID: bizContent.AppId,
|
|
AccountType: vo.OrderAccountTypeOpenId,
|
|
Type: vo.OrderTypeCmb,
|
|
}
|
|
|
|
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return orderNo, nil
|
|
}
|
|
|
|
func (s *VoucherService) CmbQuery(ctx http.Context) error {
|
|
|
|
var (
|
|
reply *v1.CmbReply
|
|
|
|
bizReply *v1.CmbQueryReply
|
|
)
|
|
|
|
bizReply, err := s.cmbQuery(ctx)
|
|
if err != nil {
|
|
bizReply = &v1.CmbQueryReply{}
|
|
}
|
|
|
|
replyBizContent, _ := json.Marshal(bizReply)
|
|
xx := &bo.CmbResponseBo{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
BizContent: string(replyBizContent),
|
|
}
|
|
|
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
|
if err != nil {
|
|
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
|
return ctx.JSON(400, err)
|
|
}
|
|
|
|
log.Warnf("CmbQuery CmbMixRepo GetResponse: %v", reply)
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
|
|
|
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var req *v1.CmbRequest
|
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = req.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
bizContent, err := s.CmbMixRepo.QueryVerify(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = bizContent.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s.VoucherBiz.CmbQuery(ctx, bizContent.CodeNo)
|
|
}
|
|
|
|
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|
|
|
var (
|
|
reply *v1.CmbReply
|
|
|
|
bizReply *v1.CmbQueryProductReply
|
|
)
|
|
|
|
bizReply, err := s.cmbProductQuery(ctx)
|
|
if err != nil {
|
|
log.Errorf("cmbProductQuery error: %v", err)
|
|
bizReply = &v1.CmbQueryProductReply{
|
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
|
RespMsg: err.Error(),
|
|
}
|
|
}
|
|
|
|
replyBizContent, _ := json.Marshal(bizReply)
|
|
xx := &bo.CmbResponseBo{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
BizContent: string(replyBizContent),
|
|
}
|
|
|
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
|
if err != nil {
|
|
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
|
return ctx.JSON(400, err)
|
|
}
|
|
|
|
log.Warnf("cmbProductQuery CmbMixRepo GetResponse: %v", reply)
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
|
|
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var req *v1.CmbRequest
|
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = req.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = bizContent.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
|
}
|
|
|
|
func (s *VoucherService) DecryptBody(ctx http.Context) error {
|
|
|
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var req *v1.EncryptBody
|
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
|
return err
|
|
}
|
|
|
|
decryptBody, err := s.CmbMixRepo.Decrypt(ctx, req.EncryptBody)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ctx.JSON(200, &v1.DecryptBody{
|
|
DecryptBody: decryptBody,
|
|
})
|
|
}
|