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.
66 lines
1.6 KiB
66 lines
1.6 KiB
package api
|
|
|
|
import (
|
|
"epur-pay/model"
|
|
"epur-pay/pkg/dapi"
|
|
"epur-pay/pkg/utils"
|
|
)
|
|
|
|
type GetPayChannelResponse struct {
|
|
*dapi.ResponseCommon
|
|
Data []model.PayChannel `json:"data"` //数据列表
|
|
}
|
|
|
|
func GetPayChannel(a *dapi.ApiBase) error {
|
|
|
|
Response := GetPayChannelResponse{
|
|
ResponseCommon: a.NewSuccessResponseCommon(),
|
|
}
|
|
|
|
query := a.Ts.Table(model.PayChannel{}.TableName())
|
|
|
|
query.Count(&Response.Count)
|
|
|
|
utils.Error(query.Limit(a.Limit).Offset(a.Offset).Scan(&Response.Data).Error)
|
|
return a.ReturnSuccessCustomResponse(Response)
|
|
}
|
|
|
|
type AddPayChannelParams struct {
|
|
Name string `json:"name"` // 渠道名称
|
|
Logo string `json:"logo"` // 渠道Logo
|
|
Status bool `json:"status"` // 状态
|
|
}
|
|
|
|
func AddPayChannel(a *dapi.ApiBase, data *AddPayChannelParams) error {
|
|
|
|
instance := model.PayChannel{
|
|
Name: data.Name,
|
|
Logo: data.Logo,
|
|
Status: data.Status,
|
|
CreateTime: utils.Time2StampSecond(),
|
|
}
|
|
utils.Error(a.Ts.Create(&instance).Error)
|
|
|
|
return a.ReturnSuccessResponse()
|
|
}
|
|
|
|
type EditPayChannelParams struct {
|
|
Id int64 `json:"id"` // ID
|
|
Request model.PayRequests `json:"payRequests"` // 接入
|
|
}
|
|
|
|
func EditPayChannel(a *dapi.ApiBase, data *EditPayChannelParams) error {
|
|
|
|
instance := model.PayChannel{}
|
|
utils.Error(a.Ts.Table(instance.TableName()).Where("id = ?", data.Id).Scan(&instance).Error)
|
|
if instance.Id <= 0 {
|
|
return a.ReturnPublicErrorResponse("不存在")
|
|
}
|
|
|
|
utils.DbErrSkipRecordNotFound(a.Ts.Table(instance.TableName()).
|
|
Where("id", instance.Id).
|
|
Updates(map[string]interface{}{"pay_requests": data.Request}).Error)
|
|
|
|
return a.ReturnSuccessResponse()
|
|
}
|