aa
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/jx-print/globals"
|
"git.rosy.net.cn/jx-print/globals"
|
||||||
"git.rosy.net.cn/jx-print/model"
|
"git.rosy.net.cn/jx-print/model"
|
||||||
|
"git.rosy.net.cn/jx-print/services"
|
||||||
"git.rosy.net.cn/jx-print/utils"
|
"git.rosy.net.cn/jx-print/utils"
|
||||||
"github.com/dchest/captcha"
|
"github.com/dchest/captcha"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -135,3 +136,23 @@ func buildErrJson(c *gin.Context, err error) {
|
|||||||
})
|
})
|
||||||
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
globals.SugarLogger.Debugf("End API :%s error:%v:", c.Request.URL, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetConfig(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
param = &struct {
|
||||||
|
Type string `json:"type" form:"type" binding:"required"`
|
||||||
|
Key string `json:"key" form:"key" binding:"required"`
|
||||||
|
}{}
|
||||||
|
)
|
||||||
|
if err = c.ShouldBind(¶m); err != nil {
|
||||||
|
buildErrJson(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = services.GetConfig(c, param.Type, param.Key)
|
||||||
|
return retVal, "", err
|
||||||
|
}) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
55
controllers/order_controller.go
Normal file
55
controllers/order_controller.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-print/model"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateOrder(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
tokenInfo *model.TokenInfo
|
||||||
|
param = &struct {
|
||||||
|
OrderType string `json:"order_type" form:"order_type" binding:"required"` //订单类型,流量充值等
|
||||||
|
Origin string `json:"origin" form:"origin" binding:"required"` //订单来源,小程序,开放后台
|
||||||
|
ThingID string `json:"thing_id" form:"thing_id" binding:"required"` //订单充值项目ID,充流量就是iccid
|
||||||
|
TypeID string `json:"type_id" form:"type_id" binding:"required"` //类型ID,充流量就是套餐对应的id
|
||||||
|
}{}
|
||||||
|
)
|
||||||
|
if err = c.ShouldBind(¶m); err != nil {
|
||||||
|
buildErrJson(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||||
|
return retVal, "", err
|
||||||
|
}) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Pay(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
tokenInfo *model.TokenInfo
|
||||||
|
param = &struct {
|
||||||
|
OrderID string `json:"order_id" form:"order_id" binding:"required"` //订单号
|
||||||
|
PayType string `json:"pay_type" form:"pay_type" binding:"required"` //支付类型
|
||||||
|
VendorPayType string `json:"vendor_pay_type" form:"vendor_pay_type" binding:"required"` //支付方式
|
||||||
|
}{}
|
||||||
|
)
|
||||||
|
if err = c.ShouldBind(¶m); err != nil {
|
||||||
|
buildErrJson(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tokenInfo = checkToken(c); tokenInfo == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !callFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||||
|
return retVal, "", err
|
||||||
|
}) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
20
dao/config_dao.go
Normal file
20
dao/config_dao.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-print/model"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetConfig(db *sqlx.DB, configType, key string) (config *model.NewConfig, err error) {
|
||||||
|
var (
|
||||||
|
configs []*model.NewConfig
|
||||||
|
)
|
||||||
|
sql := `
|
||||||
|
SELECT * FROM new_config WHERE type = ? AND key = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{configType, key}
|
||||||
|
if err = db.Select(&configs, sql, sqlParams...); err == nil && len(configs) > 0 {
|
||||||
|
return configs[0], err
|
||||||
|
}
|
||||||
|
return config, err
|
||||||
|
}
|
||||||
@@ -36,6 +36,17 @@ const (
|
|||||||
FieldID = "id"
|
FieldID = "id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderTypeFlow = "flow"
|
||||||
|
|
||||||
|
OrderOriginWxMini = "weixinmini"
|
||||||
|
OrderOriginOpenAPI = "openAPI"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ConfigTypeSys = "Sys"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
FieldNormalMap = map[string]string{
|
FieldNormalMap = map[string]string{
|
||||||
FieldDeletedAt: "删除时间",
|
FieldDeletedAt: "删除时间",
|
||||||
@@ -180,3 +191,32 @@ type SimFlowIncome struct {
|
|||||||
FlowUnit string `json:"flow_unit" db:"flow_unit"` //流量单位
|
FlowUnit string `json:"flow_unit" db:"flow_unit"` //流量单位
|
||||||
IncomeType int `json:"income_type" db:"income_type"` //1 表示系统每月自动划转,2 表示商户自己冲的
|
IncomeType int `json:"income_type" db:"income_type"` //1 表示系统每月自动划转,2 表示商户自己冲的
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PayOrder struct {
|
||||||
|
ID int `json:"id" db:"id"`
|
||||||
|
CreatedAt *time.Time `json:"created_at" db:"created_at"`
|
||||||
|
OrderID string `json:"order_id" db:"order_id"` //订单号
|
||||||
|
UserID string `json:"user_id" db:"user_id"` //用户ID
|
||||||
|
OrderType string `json:"order_type" db:"order_type"` //订单类型,流量充值等
|
||||||
|
Origin string `json:"origin"` //订单来源,小程序,开放后台
|
||||||
|
Status int `json:"status"` //订单状态,待支付2,已支付5,支付成功110,支付失败115
|
||||||
|
PayPrice int `json:"pay_price" db:"pay_price"` //支付金额
|
||||||
|
TransactionID string `json:"transaction_id" db:"transaction_id"` // 支付成功后,支付方生成的事务ID
|
||||||
|
PayFinishedAt *time.Time `json:"pay_finished_at" db:"pay_finished_at"`
|
||||||
|
PrepayID string `json:"prepay_id" db:"prepay_id"` // 下单后,支付前,支付方生成的事务ID
|
||||||
|
OriginalData string `json:"original_data" db:"original_data"`
|
||||||
|
Comment string `json:"comment"` //备注
|
||||||
|
ThingID string `json:"thing_id" db:"thing_id"` //订单充值项目ID
|
||||||
|
TypeID string `json:"type_id" db:"type_id"` //类型ID,充流量就是套餐对应的id
|
||||||
|
}
|
||||||
|
|
||||||
|
type NewConfig struct {
|
||||||
|
ID int `json:"id" db:"id"`
|
||||||
|
CreatedAt *time.Time `json:"created_at" db:"created_at"`
|
||||||
|
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
|
||||||
|
LastOperator string `json:"last_operator" db:"last_operator"`
|
||||||
|
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ func Init(r *gin.Engine) {
|
|||||||
print.POST("/updatePrinter", controllers.UpdatePrinter)
|
print.POST("/updatePrinter", controllers.UpdatePrinter)
|
||||||
print.POST("/testPrint", controllers.TestPrint)
|
print.POST("/testPrint", controllers.TestPrint)
|
||||||
print.GET("/getPrintMessages", controllers.GetPrintMessages)
|
print.GET("/getPrintMessages", controllers.GetPrintMessages)
|
||||||
|
//order
|
||||||
|
order := v2.Group("/order")
|
||||||
|
order.POST("/createOrder", controllers.CreateOrder)
|
||||||
|
order.POST("/pay", controllers.Pay)
|
||||||
|
|
||||||
//v1是不需要token的
|
//v1是不需要token的
|
||||||
v1 := r.Group("v1")
|
v1 := r.Group("v1")
|
||||||
@@ -36,6 +40,10 @@ func Init(r *gin.Engine) {
|
|||||||
userw.GET("/getMenus", controllers.GetMenus)
|
userw.GET("/getMenus", controllers.GetMenus)
|
||||||
userw.GET("/getMenuDetail", controllers.GetMenuDetail)
|
userw.GET("/getMenuDetail", controllers.GetMenuDetail)
|
||||||
|
|
||||||
|
//config
|
||||||
|
config := v1.Group("/config")
|
||||||
|
config.GET("/getConfig", controllers.GetConfig)
|
||||||
|
|
||||||
//自动路由
|
//自动路由
|
||||||
r.Any("/callback/*path", router.AutoRoute(&controllers.CallbackController{}))
|
r.Any("/callback/*path", router.AutoRoute(&controllers.CallbackController{}))
|
||||||
}
|
}
|
||||||
|
|||||||
12
services/config.go
Normal file
12
services/config.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-print/dao"
|
||||||
|
"git.rosy.net.cn/jx-print/globals"
|
||||||
|
"git.rosy.net.cn/jx-print/model"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetConfig(c *gin.Context, configType, key string) (config *model.NewConfig, err error) {
|
||||||
|
return dao.GetConfig(globals.GetDB(), configType, key)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user