101 lines
2.0 KiB
Go
101 lines
2.0 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"
|
|
)
|
|
|
|
const (
|
|
cmbOrderFuncName = "/voucher/cmb/v1/order"
|
|
cmbProductQueryFuncName = "/voucher/cmb/v1/product/query"
|
|
)
|
|
|
|
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
|
|
|
reply, err := s.cmbOrder(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return ctx.JSON(200, reply)
|
|
}
|
|
|
|
func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, 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.OrderVerify(ctx, req, cmbOrderFuncName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
boReq := &bo.OrderCreateReqBo{
|
|
OutBizNo: bizContent.TransactionId,
|
|
ProductNo: bizContent.ActivityId,
|
|
Account: bizContent.CmbUid,
|
|
AccountType: vo.OrderAccountTypeOpenId,
|
|
}
|
|
|
|
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &v1.CmbOrderReply{
|
|
CodeNo: orderNo,
|
|
}, nil
|
|
}
|
|
|
|
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|
|
|
reply, err := s.cmbProductQuery(ctx)
|
|
if err != nil {
|
|
return 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, cmbProductQueryFuncName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
wechatResp, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &v1.CmbQueryProductReply{
|
|
ActivityName: *wechatResp.GoodsName,
|
|
ActivityId: "",
|
|
Amount: "",
|
|
MinAmount: "",
|
|
AvailableType: "",
|
|
AvailableDays: "",
|
|
StartTime: "",
|
|
EndTime: "",
|
|
AvailableStock: "",
|
|
Detail: "",
|
|
}, nil
|
|
}
|