132 lines
2.7 KiB
Go
132 lines
2.7 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"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 {
|
|
|
|
var (
|
|
reply *v1.CmbReply
|
|
|
|
bizReply *v1.CmbOrderReply
|
|
)
|
|
|
|
orderNo, err := s.cmbOrder(ctx)
|
|
|
|
if err != nil {
|
|
bizReply = &v1.CmbOrderReply{
|
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
|
RespMsg: err.Error(),
|
|
CodeNo: orderNo,
|
|
}
|
|
} else {
|
|
bizReply = &v1.CmbOrderReply{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: "成功",
|
|
CodeNo: orderNo,
|
|
}
|
|
}
|
|
|
|
replyBizContent, _ := json.Marshal(bizReply)
|
|
xx := &bo.CmbResponseBo{
|
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
|
RespMsg: err.Error(),
|
|
BizContent: string(replyBizContent),
|
|
}
|
|
|
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
|
if err != nil {
|
|
log.Errorf("cmbOrder CmbMixRepo GetResponse error: %v", err)
|
|
}
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
|
|
|
var req *v1.CmbRequest
|
|
if err := ctx.BindForm(&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
|
|
}
|
|
|
|
boReq := &bo.OrderCreateReqBo{
|
|
OutBizNo: bizContent.TransactionId,
|
|
ProductNo: bizContent.ActivityId,
|
|
Account: bizContent.CmbUid,
|
|
AppID: bizContent.AppId,
|
|
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 {
|
|
|
|
var (
|
|
reply *v1.CmbReply
|
|
|
|
bizReply *v1.CmbQueryProductReply
|
|
)
|
|
|
|
bizReply, err := s.cmbProductQuery(ctx)
|
|
if err != nil {
|
|
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(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
|
|
|
var req *v1.CmbRequest
|
|
if err := ctx.BindForm(&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
|
|
}
|
|
|
|
return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
|
}
|