119 lines
2.4 KiB
Go
119 lines
2.4 KiB
Go
package bundle
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fonchain-fiee/api/bundle"
|
|
"fonchain-fiee/pkg/common"
|
|
"fonchain-fiee/pkg/service"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
)
|
|
|
|
func CreateBundleOrder(c *gin.Context) {
|
|
var req bundle.OrderRecord
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
if req.BundleUuid == "" {
|
|
service.Error(c, errors.New(common.MissBundleUUID))
|
|
return
|
|
}
|
|
|
|
if req.Signature == "" {
|
|
service.Error(c, errors.New(common.MissOrderSignature))
|
|
return
|
|
}
|
|
|
|
// 获取 用户信息
|
|
|
|
// 获取 套餐信息
|
|
bundleDetailReq := &bundle.BundleDetailRequest{
|
|
Uuid: req.BundleUuid,
|
|
}
|
|
bundleDetail, detailErr := service.BundleProvider.BundleDetail(context.Background(), bundleDetailReq)
|
|
if detailErr != nil {
|
|
service.Error(c, detailErr)
|
|
return
|
|
}
|
|
|
|
req.BundleName = bundleDetail.Bundle.Name
|
|
req.Amount = bundleDetail.Bundle.Price
|
|
req.AmountType = bundleDetail.Bundle.PriceType
|
|
|
|
// 当前 未将 签名 写入合同中
|
|
req.SignContract = bundleDetail.Bundle.Contract
|
|
|
|
req.SignedTime = common.GetBeijingTime()
|
|
|
|
res, err := service.BundleProvider.CreateOrderRecord(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func UpdateBundleOrder(c *gin.Context) {
|
|
var req bundle.OrderRecord
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
// 获取 用户信息
|
|
|
|
// 判断 是否是 本人操作
|
|
|
|
res, err := service.BundleProvider.UpdateOrderRecord(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func OrderRecordsList(c *gin.Context) {
|
|
var req bundle.OrderRecordsRequest
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
// 获取 用户信息
|
|
|
|
res, err := service.BundleProvider.OrderRecordsList(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func OrderRecordsDetail(c *gin.Context) {
|
|
var req bundle.OrderRecordsDetailRequest
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
// 获取 用户信息
|
|
|
|
res, err := service.BundleProvider.OrderRecordsDetail(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
|
|
service.Success(c, res)
|
|
}
|