低空智控平台 后端go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

202 lines
4.9 KiB

package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"laic-backend/common"
"laic-backend/service"
"laic-backend/vo"
)
// GrantTrafficForTest adds traffic to a regular user without a payment order.
func GrantTrafficForTest(c *gin.Context) {
if common.AppConf == nil || !common.AppConf.Testing.AllowTrafficGrant {
common.FailWithBusiErrorWithHttpStatus(c, http.StatusForbidden, common.ErrForbidden)
return
}
var req vo.TrafficTestGrantReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
data, e := service.DefaultBillingService.GrantTrafficForTest(common.GetUserId(c), req.UserID, req.AmountGb, req.Reason)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func GetSimProviderPlans(c *gin.Context) {
var req vo.SimPackageSyncReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
plans, e := service.DefaultSimRechargeService.ListProviderPlans(req.Iccid)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, plans)
}
func GetSimPackagePage(c *gin.Context) {
var req vo.SimPackagePageReq
bindPage(c, &req.Pagination)
_ = c.ShouldBindQuery(&req)
data, e := service.DefaultPlatformBillingService.GetSimPackagePage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func CreateSimPackage(c *gin.Context) {
var req vo.SimPackageCreateReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
data, e := service.DefaultPlatformBillingService.CreateSimPackage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func UpdateSimPackage(c *gin.Context) {
id, e := parseID(c)
if e != nil {
common.FailWithBusiError(c, e)
return
}
var req vo.SimPackageUpdateReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
if e := service.DefaultPlatformBillingService.UpdateSimPackage(id, &req); e != nil {
common.FailWithBusiError(c, e)
return
}
common.OK(c)
}
func DeleteSimPackage(c *gin.Context) {
id, e := parseID(c)
if e != nil {
common.FailWithBusiError(c, e)
return
}
if e := service.DefaultPlatformBillingService.DisableSimPackage(id); e != nil {
common.FailWithBusiError(c, e)
return
}
common.OK(c)
}
func GetPlatformResourcePool(c *gin.Context) {
data, e := service.DefaultPlatformBillingService.GetPool()
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func CreatePlatformPurchase(c *gin.Context) {
var req vo.PlatformPurchaseCreateReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
data, e := service.DefaultPlatformBillingService.CreatePurchase(common.GetUserId(c), &req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func GetPlatformPurchasePage(c *gin.Context) {
var req vo.PlatformPurchasePageReq
bindPage(c, &req.Pagination)
_ = c.ShouldBindQuery(&req)
data, e := service.DefaultPlatformBillingService.GetPurchasePage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func GetTrafficPackagePage(c *gin.Context) {
var req vo.TrafficPackagePageReq
bindPage(c, &req.Pagination)
_ = c.ShouldBindQuery(&req)
data, e := service.DefaultPlatformBillingService.GetPackagePage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func CreateTrafficPackage(c *gin.Context) {
var req vo.TrafficPackageCreateReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
data, e := service.DefaultPlatformBillingService.CreatePackage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}
func UpdateTrafficPackage(c *gin.Context) {
id, e := parseID(c)
if e != nil {
common.FailWithBusiError(c, e)
return
}
var req vo.TrafficPackageUpdateReq
if err := c.ShouldBindJSON(&req); err != nil {
common.FailWithBindError(c, common.ErrParam, err)
return
}
if e := service.DefaultPlatformBillingService.UpdatePackage(id, &req); e != nil {
common.FailWithBusiError(c, e)
return
}
common.OK(c)
}
func DeleteTrafficPackage(c *gin.Context) {
id, e := parseID(c)
if e != nil {
common.FailWithBusiError(c, e)
return
}
if e := service.DefaultPlatformBillingService.DisablePackage(id); e != nil {
common.FailWithBusiError(c, e)
return
}
common.OK(c)
}
func GetTrafficLedgerPage(c *gin.Context) {
var req vo.TrafficLedgerPageReq
bindPage(c, &req.Pagination)
_ = c.ShouldBindQuery(&req)
data, e := service.DefaultPlatformBillingService.GetLedgerPage(&req)
if e != nil {
common.FailWithBusiError(c, e)
return
}
common.OKWithData(c, data)
}