Merge branch 'dev/dev1.0' into feature_413_cjh
# Conflicts: # app/constants/common/common.go
This commit is contained in:
commit
b8e32f407a
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
## 使用官方Go镜像作为构建环境
|
||||||
|
#FROM golang:1.21.0 AS builder
|
||||||
|
#
|
||||||
|
## 设置工作目录
|
||||||
|
#WORKDIR /app
|
||||||
|
#
|
||||||
|
## 复制项目源码
|
||||||
|
#COPY . .
|
||||||
|
#
|
||||||
|
## 复制go模块依赖文件
|
||||||
|
#COPY go.mod go.sum ./
|
||||||
|
#
|
||||||
|
## 安装go模块依赖
|
||||||
|
#RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
#RUN go mod tidy
|
||||||
|
#
|
||||||
|
## 编译Go应用程序,生成静态链接的二进制文件
|
||||||
|
#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .
|
||||||
|
|
||||||
|
# 创建最终镜像,用于运行编译后的Go程序
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
|
||||||
|
&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
|
||||||
|
&& apk update && apk add tzdata \
|
||||||
|
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||||
|
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||||
|
|
||||||
|
ENV server = "admin"
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 将编译好的二进制文件从构建阶段复制到运行阶段
|
||||||
|
COPY /server .
|
||||||
|
#COPY --from=builder /app/server .
|
||||||
|
COPY .env .
|
||||||
|
|
||||||
|
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
# 设置容器启动时运行的命令
|
||||||
|
ENTRYPOINT ["/app/server", "-a", "$server"]
|
|
@ -1,9 +1,86 @@
|
||||||
package console
|
package console
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/data"
|
||||||
|
"PaymentCenter/app/http/entities"
|
||||||
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/utils"
|
||||||
"github.com/qit-team/snow-core/command"
|
"github.com/qit-team/snow-core/command"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterCommand(c *command.Command) {
|
func RegisterCommand(c *command.Command) {
|
||||||
c.AddFunc("test", test)
|
c.AddFunc("test", test)
|
||||||
|
c.AddFunc("closeOrder", closeOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭长时间支付中的订单
|
||||||
|
func closeOrder() {
|
||||||
|
var now = time.Now().Format(time.DateTime)
|
||||||
|
utils.Log(nil, "关闭订单", now)
|
||||||
|
// 查询未支付的订单
|
||||||
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||||
|
// 拼接条件
|
||||||
|
cond := builder.NewCond()
|
||||||
|
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Lt{"create_time": time.Now().Add(-time.Hour)})
|
||||||
|
|
||||||
|
order := make([]ordersmodel.Orders, 0)
|
||||||
|
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "关闭订单,查询未支付订单失败", err)
|
||||||
|
} else if total > 0 {
|
||||||
|
orderIds := make([]int64, 0)
|
||||||
|
for _, v := range order {
|
||||||
|
orderIds = append(orderIds, v.Id)
|
||||||
|
}
|
||||||
|
// 修改订单状态为关闭
|
||||||
|
cond = builder.NewCond()
|
||||||
|
cond = cond.And(builder.In("id", orderIds))
|
||||||
|
_, err = repo.OrderUpdate(&ordersmodel.Orders{Status: common.ORDER_STATUS_CLOSE}, cond, "status")
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "关闭订单,修改订单状态失败", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
utils.Log(nil, "关闭订单,修改订单状态成功", "count="+strconv.Itoa(len(order)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定时查询支付中的订单, 主动查询订单支付状态
|
||||||
|
func queryOrder() {
|
||||||
|
var now = time.Now().Format(time.DateTime)
|
||||||
|
utils.Log(nil, "主动查询订单支付状态", now)
|
||||||
|
// 查询未支付的订单
|
||||||
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||||
|
// 拼接条件
|
||||||
|
cond := builder.NewCond()
|
||||||
|
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"create_time": time.Now().Add(-time.Second)})
|
||||||
|
order := make([]ordersmodel.Orders, 0)
|
||||||
|
total, err := repo.OrderList(cond, entities.PageRequest{}, &order)
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "主动查询订单支付状态,查询未付中订单失败", err)
|
||||||
|
return
|
||||||
|
} else if total > 0 {
|
||||||
|
// 发起查询上游支付
|
||||||
|
for _, v := range order {
|
||||||
|
go func(order ordersmodel.Orders) {
|
||||||
|
// 发起查询
|
||||||
|
utils.Log(nil, "主动查询订单支付状态,发起查询", order.Id)
|
||||||
|
// 解析上游结果
|
||||||
|
|
||||||
|
// 修改订单状态
|
||||||
|
}(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回调下游
|
||||||
|
func callbackOrder() {
|
||||||
|
var now = time.Now().Format(time.DateTime)
|
||||||
|
utils.Log(nil, "回调下游", now)
|
||||||
|
// 查询回调失败的订单
|
||||||
|
|
||||||
|
// 发起回调
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,7 @@ import (
|
||||||
func RegisterSchedule(c *cron.Cron) {
|
func RegisterSchedule(c *cron.Cron) {
|
||||||
//c.AddFunc("0 30 * * * *", test)
|
//c.AddFunc("0 30 * * * *", test)
|
||||||
//c.AddFunc("@hourly", test)
|
//c.AddFunc("@hourly", test)
|
||||||
c.AddFunc("@every 10s", test)
|
//c.AddFunc("@every 10s", test)
|
||||||
|
c.AddFunc("@every 60s", closeOrder)
|
||||||
|
c.AddFunc("@every 10s", queryOrder)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package common
|
||||||
const (
|
const (
|
||||||
TOKEN_PRE = "player_token_"
|
TOKEN_PRE = "player_token_"
|
||||||
TOKEN_Admin = "Admin_token_"
|
TOKEN_Admin = "Admin_token_"
|
||||||
ADMIN_V1 = "/admin/pay/api/v1"
|
ADMIN_V1 = "/pay/admin/api/v1"
|
||||||
FRONT_API_V1 = "/v1"
|
FRONT_API_V1 = "/v1"
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
|
@ -16,4 +16,16 @@ const (
|
||||||
PAY_CHANNEL_ALIPAY_WEB = 6
|
PAY_CHANNEL_ALIPAY_WEB = 6
|
||||||
PAY_CHANNEL_ALIPAY_MINI = 7
|
PAY_CHANNEL_ALIPAY_MINI = 7
|
||||||
PAY_CHANNEL_ALIPAY_JSAPI = 8
|
PAY_CHANNEL_ALIPAY_JSAPI = 8
|
||||||
|
|
||||||
|
// 统一登陆信息
|
||||||
|
ADMIN_USER_ID = "User-Id"
|
||||||
|
ADMIN_USER_NAME = "User-Name"
|
||||||
|
ADMIN_USER_INCLUDEUSERS = "Include-Users"
|
||||||
|
|
||||||
|
// '订单状态,待支付、支付中、支付成功、支付失败、订单关闭',
|
||||||
|
ORDER_STATUS_WAITPAY = 1
|
||||||
|
ORDER_STATUS_PAYING = 2
|
||||||
|
ORDER_STATUS_PAYED = 3
|
||||||
|
ORDER_STATUS_FAILED = 4
|
||||||
|
ORDER_STATUS_CLOSE = 5
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,6 +24,10 @@ const (
|
||||||
|
|
||||||
// 商户
|
// 商户
|
||||||
MerchantNotFound = 1100
|
MerchantNotFound = 1100
|
||||||
|
|
||||||
|
AppNotFound = 1200
|
||||||
|
|
||||||
|
PayChannelNotFound = 1300
|
||||||
)
|
)
|
||||||
|
|
||||||
var MsgEN = map[int]string{
|
var MsgEN = map[int]string{
|
||||||
|
@ -42,7 +46,9 @@ var MsgZH = map[int]string{
|
||||||
NotAuth: "未经授权",
|
NotAuth: "未经授权",
|
||||||
NotLogin: "未登录",
|
NotLogin: "未登录",
|
||||||
|
|
||||||
MerchantNotFound: "商户不存在",
|
MerchantNotFound: "商户不存在",
|
||||||
|
AppNotFound: "应用不存在",
|
||||||
|
PayChannelNotFound: "支付方式不存在",
|
||||||
}
|
}
|
||||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||||
|
|
||||||
|
|
|
@ -37,3 +37,7 @@ func (m *AppRepo) AppDelete(app *appmodel.App, conn builder.Cond) (int64, error)
|
||||||
func (m *AppRepo) AppUpdate(app *appmodel.App, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *AppRepo) AppUpdate(app *appmodel.App, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(app)
|
return m.repo.Where(conn).MustCols(columns...).Update(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *AppRepo) AppGet(app *appmodel.App, conn builder.Cond) (bool, error) {
|
||||||
|
return m.repo.Where(conn).Get(app)
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewOrderLogRepo(repo xorm.Interface) *OrderLogRepo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderLogRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequest, orderLogList *[]orderlogmodel.OrderLogModel) (int64, error) {
|
func (m *OrderLogRepo) OrderLogList(conn builder.Cond, pageFilter entities.PageRequest, orderLogList *[]orderlogmodel.OrderLog) (int64, error) {
|
||||||
repo := m.repo.Where(conn)
|
repo := m.repo.Where(conn)
|
||||||
if pageFilter.Page > 0 {
|
if pageFilter.Page > 0 {
|
||||||
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
||||||
|
@ -25,15 +25,15 @@ func (m *OrderLogRepo) MerchantList(conn builder.Cond, pageFilter entities.PageR
|
||||||
return repo.Desc("create_time").FindAndCount(orderLogList)
|
return repo.Desc("create_time").FindAndCount(orderLogList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderLogRepo) MerchantInsertOne(orderLog *orderlogmodel.OrderLogModel) (int64, error) {
|
func (m *OrderLogRepo) OrderLogInsertOne(orderLog *orderlogmodel.OrderLog) (int64, error) {
|
||||||
return m.repo.InsertOne(orderLog)
|
return m.repo.InsertOne(orderLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderLogRepo) MerchantDelete(orderLog *orderlogmodel.OrderLogModel, conn builder.Cond) (int64, error) {
|
func (m *OrderLogRepo) OrderLogDelete(orderLog *orderlogmodel.OrderLog, conn builder.Cond) (int64, error) {
|
||||||
return m.repo.Where(conn).Delete(orderLog)
|
return m.repo.Where(conn).Delete(orderLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
// columns 参数为要更新的字段
|
// columns 参数为要更新的字段
|
||||||
func (m *OrderLogRepo) MerchantUpdate(orderLog *orderlogmodel.OrderLogModel, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *OrderLogRepo) OrderLogUpdate(orderLog *orderlogmodel.OrderLog, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(orderLog)
|
return m.repo.Where(conn).MustCols(columns...).Update(orderLog)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewOrderRepo(repo xorm.Interface) *OrderRepo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.Orders) (int64, error) {
|
func (m *OrderRepo) OrderList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.Orders) (int64, error) {
|
||||||
repo := m.repo.Where(conn)
|
repo := m.repo.Where(conn)
|
||||||
if pageFilter.Page > 0 {
|
if pageFilter.Page > 0 {
|
||||||
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
||||||
|
@ -25,15 +25,27 @@ func (m *OrderRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequ
|
||||||
return repo.Desc("create_time").FindAndCount(orderList)
|
return repo.Desc("create_time").FindAndCount(orderList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderRepo) MerchantInsertOne(order *ordersmodel.Orders) (int64, error) {
|
func (m *OrderRepo) OrderInsertOne(order *ordersmodel.Orders) (int64, error) {
|
||||||
return m.repo.InsertOne(order)
|
return m.repo.InsertOne(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *OrderRepo) MerchantDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) {
|
func (m *OrderRepo) OrderDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) {
|
||||||
return m.repo.Where(conn).Delete(order)
|
return m.repo.Where(conn).Delete(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
// columns 参数为要更新的字段
|
// columns 参数为要更新的字段
|
||||||
func (m *OrderRepo) MerchantUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *OrderRepo) OrderUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(order)
|
return m.repo.Where(conn).MustCols(columns...).Update(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *OrderRepo) OrdersBackendList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.OrdersBackendList) (int64, error) {
|
||||||
|
repo := m.repo.Select(`orders.*, merchant.name as merchant_name, app.app_name, pay_channel.pay_name`).
|
||||||
|
Where(conn)
|
||||||
|
if pageFilter.Page > 0 {
|
||||||
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
||||||
|
}
|
||||||
|
repo = repo.Join("left", "app", "app.id = orders.app_id").
|
||||||
|
Join("left", "merchant", "merchant.id = orders.merchant_id").
|
||||||
|
Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
||||||
|
return repo.Desc("create_time").FindAndCount(orderList)
|
||||||
|
}
|
||||||
|
|
|
@ -25,15 +25,19 @@ func (m *PayChannelRepo) PayChannelList(conn builder.Cond, pageFilter entities.P
|
||||||
return repo.Desc("create_time").FindAndCount(payChannelList)
|
return repo.Desc("create_time").FindAndCount(payChannelList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PayChannelRepo) PayChannelInsertOne(merchant *paychannelmodel.PayChannel) (int64, error) {
|
func (m *PayChannelRepo) PayChannelInsertOne(payChannel *paychannelmodel.PayChannel) (int64, error) {
|
||||||
return m.repo.InsertOne(merchant)
|
return m.repo.InsertOne(payChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PayChannelRepo) PayChannelDelete(merchant *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) {
|
func (m *PayChannelRepo) PayChannelDelete(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) {
|
||||||
return m.repo.Where(conn).Delete(merchant)
|
return m.repo.Where(conn).Delete(payChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// columns 参数为要更新的字段,即使为空
|
// columns 参数为要更新的字段,即使为空
|
||||||
func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *PayChannelRepo) PayChannelUpdate(payChannel *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
return m.repo.Where(conn).MustCols(columns...).Update(payChannel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PayChannelRepo) PayChannelGet(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (bool, error) {
|
||||||
|
return m.repo.Where(conn).Get(payChannel)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
func MerchantList(c *gin.Context) {
|
func MerchantList(c *gin.Context) {
|
||||||
req, _ := controllers.GetRequest(c).(*backend.MerchantListRequest)
|
req, _ := controllers.GetRequest(c).(*backend.MerchantListRequest)
|
||||||
req.SetDefault()
|
req.SetDefault()
|
||||||
|
req.GroupInfo = controllers.GetAdminUserIncludeUsers(c)
|
||||||
merchantList, total, code := services.MerchantList(*req)
|
merchantList, total, code := services.MerchantList(*req)
|
||||||
|
|
||||||
result := make([]backend.MerchantResponse, 0, len(merchantList))
|
result := make([]backend.MerchantResponse, 0, len(merchantList))
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/http/controllers"
|
||||||
|
"PaymentCenter/app/http/entities"
|
||||||
|
"PaymentCenter/app/http/entities/backend"
|
||||||
|
"PaymentCenter/app/models/orderlogmodel"
|
||||||
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/services"
|
||||||
|
"github.com/ahmetb/go-linq/v3"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OrderList(c *gin.Context) {
|
||||||
|
req, _ := controllers.GetRequest(c).(*backend.OrderListRequest)
|
||||||
|
filter, err := req.ValidateRequest()
|
||||||
|
if err != nil {
|
||||||
|
controllers.Error(c, errorcode.ParamError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
orderList, total, code := services.OrderList(filter)
|
||||||
|
|
||||||
|
result := make([]backend.OrdersResponse, 0, len(orderList))
|
||||||
|
linq.From(orderList).SelectT(func(in ordersmodel.OrdersBackendList) (out backend.OrdersResponse) {
|
||||||
|
out.ResponseFromDb(in)
|
||||||
|
return
|
||||||
|
}).ToSlice(&result)
|
||||||
|
data := entities.PageRsp{
|
||||||
|
Total: total,
|
||||||
|
Data: result,
|
||||||
|
}
|
||||||
|
controllers.HandCodeRes(c, data, code)
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderLogsList(c *gin.Context) {
|
||||||
|
req, _ := controllers.GetRequest(c).(*backend.OrderLogsListRequest)
|
||||||
|
req.SetDefault()
|
||||||
|
orderLogList, total, code := services.OrderLogsList(*req)
|
||||||
|
|
||||||
|
result := make([]backend.OrderLogResponse, 0, len(orderLogList))
|
||||||
|
linq.From(orderLogList).SelectT(func(in orderlogmodel.OrderLog) (out backend.OrderLogResponse) {
|
||||||
|
out.ResponseFromDb(in)
|
||||||
|
return
|
||||||
|
}).ToSlice(&result)
|
||||||
|
data := entities.PageRsp{
|
||||||
|
Total: total,
|
||||||
|
Data: result,
|
||||||
|
}
|
||||||
|
controllers.HandCodeRes(c, data, code)
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/utils"
|
"PaymentCenter/app/utils"
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -17,6 +18,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"PaymentCenter/app/constants/errorcode"
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
|
||||||
|
@ -207,3 +209,24 @@ func phoneValidation(fl validator.FieldLevel) bool {
|
||||||
reg := regexp.MustCompile(phoneRegex)
|
reg := regexp.MustCompile(phoneRegex)
|
||||||
return reg.MatchString(phone)
|
return reg.MatchString(phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 管理后台,获取用户id
|
||||||
|
func GetAdminId(c *gin.Context) int {
|
||||||
|
userIdStr, _ := c.Get(common.ADMIN_USER_ID)
|
||||||
|
if userIdStr != nil {
|
||||||
|
var userId, _ = strconv.Atoi(userIdStr.(string))
|
||||||
|
return userId
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取对应数据权限中拥有用户数据ID
|
||||||
|
func GetAdminUserIncludeUsers(c *gin.Context) string {
|
||||||
|
name, _ := c.Get(common.ADMIN_USER_INCLUDEUSERS)
|
||||||
|
if name != nil {
|
||||||
|
var temp, _ = name.(string)
|
||||||
|
return temp
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppListRequest struct {
|
type AppListRequest struct {
|
||||||
MerchantId int64 `json:"merchant_id"`
|
Id int64 `json:"id" form:"id"`
|
||||||
|
MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"`
|
||||||
entities.PageRequest
|
entities.PageRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ type AppCreateRequest struct {
|
||||||
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
|
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
|
||||||
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
||||||
WhiteIp string `json:"white_ip"`
|
WhiteIp string `json:"white_ip"`
|
||||||
NotifyUrl string `json:"notify_url"`
|
NotifyUrl string `json:"notify_url" validate:"required" label:"通知地址"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
|
func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
|
||||||
|
@ -69,13 +70,12 @@ func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
|
||||||
|
|
||||||
type AppUpdateRequest struct {
|
type AppUpdateRequest struct {
|
||||||
Id int64 `json:"id" validate:"required" label:"应用ID"`
|
Id int64 `json:"id" validate:"required" label:"应用ID"`
|
||||||
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
|
AppName string `json:"app_name" label:"应用名称"`
|
||||||
AppName string `json:"app_name" validate:"required" label:"应用名称"`
|
|
||||||
AppRemark string `json:"app_remark" label:"应用备注"`
|
AppRemark string `json:"app_remark" label:"应用备注"`
|
||||||
Status int `json:"status" validate:"oneof=0 1 2" label:"应用状态"`
|
Status int `json:"status" label:"应用状态"`
|
||||||
KeyType int `json:"key_type" validate:"required" label:"应用密钥类型"`
|
KeyType int `json:"key_type" label:"应用密钥类型"`
|
||||||
PublicKey string `json:"public_key" validate:"required" label:"应用公钥"`
|
PublicKey string `json:"public_key" label:"应用公钥"`
|
||||||
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
|
PrivateKey string `json:"private_key" label:"应用私钥"`
|
||||||
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
||||||
WhiteIp string `json:"white_ip"`
|
WhiteIp string `json:"white_ip"`
|
||||||
NotifyUrl string `json:"notify_url"`
|
NotifyUrl string `json:"notify_url"`
|
||||||
|
@ -83,7 +83,6 @@ type AppUpdateRequest struct {
|
||||||
|
|
||||||
func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
|
func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
|
||||||
db.Id = a.Id
|
db.Id = a.Id
|
||||||
db.MerchantId = a.MerchantId
|
|
||||||
db.AppName = a.AppName
|
db.AppName = a.AppName
|
||||||
db.AppRemark = a.AppRemark
|
db.AppRemark = a.AppRemark
|
||||||
db.Status = a.Status
|
db.Status = a.Status
|
||||||
|
|
|
@ -7,9 +7,10 @@ import (
|
||||||
|
|
||||||
type MerchantListRequest struct {
|
type MerchantListRequest struct {
|
||||||
entities.PageRequest
|
entities.PageRequest
|
||||||
Name string `form:"name"`
|
Name string `form:"name"`
|
||||||
Contact string `form:"contact"`
|
Contact string `form:"contact"`
|
||||||
Phone string `form:"phone"`
|
Phone string `form:"phone"`
|
||||||
|
GroupInfo string
|
||||||
}
|
}
|
||||||
|
|
||||||
type MerchantResponse struct {
|
type MerchantResponse struct {
|
||||||
|
@ -35,6 +36,7 @@ type MerchantCreateRequest struct {
|
||||||
Contact string `json:"contact" validate:"required" label:"联系人"`
|
Contact string `json:"contact" validate:"required" label:"联系人"`
|
||||||
Phone string `json:"phone" validate:"required,phoneValidation" label:"联系电话"`
|
Phone string `json:"phone" validate:"required,phoneValidation" label:"联系电话"`
|
||||||
Remark string `json:"remark" label:"备注"`
|
Remark string `json:"remark" label:"备注"`
|
||||||
|
Creator int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) {
|
func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) {
|
||||||
|
@ -42,6 +44,7 @@ func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) {
|
||||||
db.Contact = m.Contact
|
db.Contact = m.Contact
|
||||||
db.Phone = m.Phone
|
db.Phone = m.Phone
|
||||||
db.Remark = m.Remark
|
db.Remark = m.Remark
|
||||||
|
db.Creator = m.Creator
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PaymentCenter/app/http/entities"
|
||||||
|
"PaymentCenter/app/models/orderlogmodel"
|
||||||
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/utils"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrderListRequest struct {
|
||||||
|
Id int64 `json:"id" form:"id"`
|
||||||
|
MerchantId int64 `json:"merchant_id" form:"merchant_id"`
|
||||||
|
PayId int64 `json:"pay_id" form:"pay_id"`
|
||||||
|
AppId int64 `json:"app_id" form:"app_id"`
|
||||||
|
MerchantOrderId string `json:"merchant_order_id" form:"merchant_order_id"`
|
||||||
|
Status int `json:"status" form:"status"`
|
||||||
|
OrderType int `json:"order_type" form:"order_type"`
|
||||||
|
StartTime string `json:"start_time" form:"start_time"`
|
||||||
|
EndTime string `json:"end_time" form:"end_time"`
|
||||||
|
entities.PageRequest
|
||||||
|
}
|
||||||
|
type OrderList struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
MerchantId int64 `json:"merchant_id"`
|
||||||
|
PayId int64 `json:"pay_id"`
|
||||||
|
AppId int64 `json:"app_id"`
|
||||||
|
MerchantOrderId string `json:"merchant_order_id"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
OrderType int `json:"order_type"`
|
||||||
|
StartTime time.Time `json:"start_time"`
|
||||||
|
EndTime time.Time `json:"end_time"`
|
||||||
|
entities.PageRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OrderListRequest) ValidateRequest() (r OrderList, err error) {
|
||||||
|
if o.StartTime != "" {
|
||||||
|
r.StartTime, err = utils.StrToTimeShanghai(o.StartTime)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "时间格式错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if o.EndTime != "" {
|
||||||
|
r.EndTime, err = utils.StrToTimeShanghai(o.EndTime)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "时间格式错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Id = o.Id
|
||||||
|
r.MerchantId = o.MerchantId
|
||||||
|
r.PayId = o.PayId
|
||||||
|
r.AppId = o.AppId
|
||||||
|
r.MerchantOrderId = o.MerchantOrderId
|
||||||
|
r.Status = o.Status
|
||||||
|
r.OrderType = o.OrderType
|
||||||
|
r.PageRequest = o.PageRequest
|
||||||
|
r.SetDefault()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrdersResponse struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
MerchantId int64 `json:"merchant_id"`
|
||||||
|
PayId int64 `json:"pay_id"`
|
||||||
|
AppId int64 `json:"app_id"`
|
||||||
|
MerchantOrderId string `json:"merchant_order_id"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
OrderType int `json:"order_type"`
|
||||||
|
Amount int `json:"amount"`
|
||||||
|
IpAddress string `json:"ip_address"`
|
||||||
|
MerchantRequest string `json:"merchant_request"`
|
||||||
|
MerchantResponse string `json:"merchant_response"`
|
||||||
|
OrderResponse string `json:"order_response"`
|
||||||
|
ExtJson string `json:"ext_json"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
UpdateTime string `json:"update_time"`
|
||||||
|
MerchantName string `json:"merchant_name"`
|
||||||
|
PayName string `json:"pay_name"`
|
||||||
|
AppName string `json:"app_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OrdersResponse) ResponseFromDb(db ordersmodel.OrdersBackendList) {
|
||||||
|
o.Id = db.Id
|
||||||
|
o.MerchantId = db.MerchantId
|
||||||
|
o.PayId = db.PayId
|
||||||
|
o.AppId = db.AppId
|
||||||
|
o.MerchantOrderId = db.MerchantOrderId
|
||||||
|
o.Status = db.Status
|
||||||
|
o.OrderType = db.OrderType
|
||||||
|
o.Amount = db.Amount
|
||||||
|
o.IpAddress = db.IpAddress
|
||||||
|
o.MerchantRequest = db.MerchantRequest
|
||||||
|
o.MerchantResponse = db.MerchantResponse
|
||||||
|
o.OrderResponse = db.OrderResponse
|
||||||
|
o.ExtJson = db.ExtJson
|
||||||
|
o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||||
|
o.UpdateTime = db.UpdateTime.Format("2006-01-02 15:04:05")
|
||||||
|
o.MerchantName = db.MerchantName
|
||||||
|
o.PayName = db.PayName
|
||||||
|
o.AppName = db.AppName
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderLogsListRequest struct {
|
||||||
|
OrderId int64 `json:"order_id" form:"order_id"`
|
||||||
|
entities.PageRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderLogResponse struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
OrderId int64 `json:"order_id"`
|
||||||
|
PayCallback string `json:"pay_callback"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
MerchantParam string `json:"merchant_param"`
|
||||||
|
MerchantCallback string `json:"merchant_callback"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OrderLogResponse) ResponseFromDb(db orderlogmodel.OrderLog) {
|
||||||
|
o.Id = db.Id
|
||||||
|
o.OrderId = db.OrderId
|
||||||
|
o.PayCallback = db.PayCallback
|
||||||
|
o.Status = db.Status
|
||||||
|
o.MerchantParam = db.MerchantParam
|
||||||
|
o.MerchantCallback = db.MerchantCallback
|
||||||
|
o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||||
|
}
|
|
@ -49,16 +49,17 @@ type PayChannelCreateRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type WechatPayChannel struct {
|
type WechatPayChannel struct {
|
||||||
MchId string `json:"mch_id"` //直连商户号
|
MchId string `json:"mch_id"` // 商户ID 或者服务商模式的 sp_mchid
|
||||||
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号
|
SerialNo string `json:"serial_no"` // 商户证书的证书序列号
|
||||||
MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥
|
ApiV3Key string `json:"api_v_3_key"` // apiV3Key,商户平台获取
|
||||||
PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径
|
PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliPayPayChannel struct {
|
type AliPayPayChannel struct {
|
||||||
AliPublicKey string `json:"ali_public_key"` //支付宝公钥
|
PrivateKey string `json:"private_key"` // 应用私钥
|
||||||
PrivateKeyPath string `json:"private_key_path"` //应用私钥
|
AppPublicCert string `json:"app_public_cert"` // 应用公钥
|
||||||
SignType string `json:"sign_type"` //商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2
|
AlipayRootCert string `json:"alipay_root_cert"` // 支付宝根证书
|
||||||
|
AlipayPublicCert string `json:"alipay_public_cert"` // 支付宝公钥
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
|
func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
|
||||||
|
@ -86,19 +87,24 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayChannelListRequest struct {
|
type PayChannelListRequest struct {
|
||||||
MerchantId int64 `json:"merchant_id"`
|
Id int64 `json:"id" form:"id" `
|
||||||
|
MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"`
|
||||||
entities.PageRequest
|
entities.PageRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayChannelUpdateRequest struct {
|
type PayChannelUpdateRequest struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
PayChannelCreateRequest
|
PayName string `json:"pay_name" validate:"required" label:"支付渠道名称"`
|
||||||
|
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
|
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
||||||
|
ExpireTime string `json:"expire_time"`
|
||||||
|
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
||||||
|
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
|
func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
|
||||||
db.Id = p.Id
|
db.Id = p.Id
|
||||||
db.PayName = p.PayName
|
db.PayName = p.PayName
|
||||||
db.MerchantId = p.MerchantId
|
|
||||||
db.ChannelType = p.ChannelType
|
db.ChannelType = p.ChannelType
|
||||||
db.AppId = p.AppId
|
db.AppId = p.AppId
|
||||||
if p.ExpireTime != "" {
|
if p.ExpireTime != "" {
|
||||||
|
|
|
@ -6,10 +6,8 @@ import (
|
||||||
"PaymentCenter/app/http/controllers"
|
"PaymentCenter/app/http/controllers"
|
||||||
"PaymentCenter/app/http/requestmapping"
|
"PaymentCenter/app/http/requestmapping"
|
||||||
"PaymentCenter/app/utils"
|
"PaymentCenter/app/utils"
|
||||||
"context"
|
"PaymentCenter/config"
|
||||||
"errors"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/qit-team/snow-core/redis"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,20 +57,42 @@ func Cors() gin.HandlerFunc {
|
||||||
|
|
||||||
func AdminAuth() gin.HandlerFunc {
|
func AdminAuth() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var token = c.GetHeader("token")
|
ip, _ := c.RemoteIP()
|
||||||
//将token放入redis
|
utils.Log(c, "请求地址RemoteIP()", ip.String(), config.GetConf().AdminGate)
|
||||||
var playerId, err = redis.GetRedis().Get(context.Background(), utils.GetRealKey(common.TOKEN_Admin+token)).Result()
|
clientIp := c.ClientIP()
|
||||||
if rs, errRedis := redis.GetRedis().SIsMember(context.Background(), "disabled_uids", playerId).Result(); errRedis == nil && rs {
|
utils.Log(c, "请求地址clientIp", clientIp)
|
||||||
err = errors.New(errorcode.GetMsg(errorcode.NotFound, ""))
|
|
||||||
redis.GetRedis().SRem(context.Background(), "disabled_uids", playerId)
|
if config.GetConf().Debug == false && !utils.SliceInStr(ip.String(), config.GetConf().AdminGate) {
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
c.Set("playerId", playerId)
|
|
||||||
c.Next()
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
controllers.HandCodeRes(c, nil, errorcode.Forbidden)
|
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
controllers.HandCodeRes(c, nil, errorcode.Forbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var userName = c.GetHeader("User-Name")
|
||||||
|
if userName != "" {
|
||||||
|
c.Set(common.ADMIN_USER_NAME, userName)
|
||||||
|
}
|
||||||
|
var IncludeUsers = c.GetHeader("Include-Users")
|
||||||
|
if IncludeUsers != "" {
|
||||||
|
c.Set(common.ADMIN_USER_INCLUDEUSERS, IncludeUsers)
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminId = c.GetHeader("User-Id")
|
||||||
|
// 测试环境直接放行
|
||||||
|
if config.GetConf().Debug == true {
|
||||||
|
c.Set(common.ADMIN_USER_ID, adminId)
|
||||||
|
c.Next()
|
||||||
|
} else {
|
||||||
|
utils.Log(c, "请求header信息", "adminId="+adminId, "IncludeUsers="+IncludeUsers)
|
||||||
|
// 正式环境校验
|
||||||
|
if adminId != "" {
|
||||||
|
c.Set(common.ADMIN_USER_ID, adminId)
|
||||||
|
c.Next()
|
||||||
|
} else {
|
||||||
|
c.Abort()
|
||||||
|
controllers.HandCodeRes(c, nil, errorcode.NotAuth)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,7 @@ var BackendRequestMap = map[string]func() interface{}{
|
||||||
common.ADMIN_V1 + "/app/list": func() interface{} { return new(backend.AppListRequest) },
|
common.ADMIN_V1 + "/app/list": func() interface{} { return new(backend.AppListRequest) },
|
||||||
common.ADMIN_V1 + "/app/delete": func() interface{} { return new(entities.IdRequest) },
|
common.ADMIN_V1 + "/app/delete": func() interface{} { return new(entities.IdRequest) },
|
||||||
common.ADMIN_V1 + "/app/decrypt": func() interface{} { return new(backend.GenerateDecryptKeyRequest) },
|
common.ADMIN_V1 + "/app/decrypt": func() interface{} { return new(backend.GenerateDecryptKeyRequest) },
|
||||||
|
// 订单
|
||||||
|
common.ADMIN_V1 + "/order/list": func() interface{} { return new(backend.OrderListRequest) },
|
||||||
|
common.ADMIN_V1 + "/order/log/list": func() interface{} { return new(backend.OrderLogsListRequest) },
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func RegisterAdminRoute(router *gin.Engine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v1 := router.Group("/admin/pay/api/v1", middlewares.ValidateRequest())
|
v1 := router.Group("/pay/admin/api/v1", middlewares.AdminAuth(), middlewares.ValidateRequest())
|
||||||
{
|
{
|
||||||
// 商户管理
|
// 商户管理
|
||||||
merchant := v1.Group("/merchant")
|
merchant := v1.Group("/merchant")
|
||||||
|
@ -46,6 +46,11 @@ func RegisterAdminRoute(router *gin.Engine) {
|
||||||
app.DELETE("/delete", backend.AppDelete) // 应用删除
|
app.DELETE("/delete", backend.AppDelete) // 应用删除
|
||||||
app.GET("/decrypt", backend.GenerateDecrypt) // 生成密钥对
|
app.GET("/decrypt", backend.GenerateDecrypt) // 生成密钥对
|
||||||
|
|
||||||
|
// 订单
|
||||||
|
order := v1.Group("/order")
|
||||||
|
order.GET("/list", backend.OrderList) // 订单列表
|
||||||
|
order.GET("/log/list", backend.OrderLogsList) // 订单日志列表
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Merchant struct {
|
||||||
Contact string `xorm:"'contact' varchar(128)"`
|
Contact string `xorm:"'contact' varchar(128)"`
|
||||||
Phone string `xorm:"'phone' varchar(11)"`
|
Phone string `xorm:"'phone' varchar(11)"`
|
||||||
Remark string `xorm:"'remark' varchar(1024)"`
|
Remark string `xorm:"'remark' varchar(1024)"`
|
||||||
|
Creator int `xorm:"'creator' int(10)"`
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ type Orders struct {
|
||||||
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
||||||
PayId int64 `xorm:"'pay_id' bigint(20)"`
|
PayId int64 `xorm:"'pay_id' bigint(20)"`
|
||||||
AppId int64 `xorm:"'app_id' bigint(20)"`
|
AppId int64 `xorm:"'app_id' bigint(20)"`
|
||||||
MerchantOrderId string `xorm:"'merchant_order_id' varchar(128)"`
|
MerchantOrderId string `xorm:"'merchant_order_id' varchar(32)"`
|
||||||
Status int `xorm:"'status' int(11)"`
|
Status int `xorm:"'status' int(11)"`
|
||||||
OrderType int `xorm:"'order_type' int(11)"`
|
OrderType int `xorm:"'order_type' int(11)"`
|
||||||
Amount int `xorm:"'amount' int(11)"`
|
Amount int `xorm:"'amount' int(11)"`
|
||||||
|
@ -30,6 +30,12 @@ type Orders struct {
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||||
}
|
}
|
||||||
|
type OrdersBackendList struct {
|
||||||
|
Orders `xorm:"extends"`
|
||||||
|
MerchantName string `xorm:"'merchant_name' varchar(128)"`
|
||||||
|
PayName string `xorm:"'pay_name' varchar(128)"`
|
||||||
|
AppName string `xorm:"'app_name' varchar(128)"`
|
||||||
|
}
|
||||||
|
|
||||||
// 表名
|
// 表名
|
||||||
func (m *Orders) TableName() string {
|
func (m *Orders) TableName() string {
|
||||||
|
|
|
@ -14,16 +14,15 @@ var (
|
||||||
// 实体
|
// 实体
|
||||||
type PayChannel struct {
|
type PayChannel struct {
|
||||||
Id int64
|
Id int64
|
||||||
PayName string `xorm:"'pay_name' varchar(128)"`
|
PayName string `xorm:"'pay_name' varchar(128)"`
|
||||||
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
||||||
ChannelType int `xorm:"'channel_type' int(11)"`
|
ChannelType int `xorm:"'channel_type' int(11)"`
|
||||||
|
AppId string `xorm:"'app_id' varchar(255)"`
|
||||||
AppId string `xorm:"'app_id' varchar(255)"`
|
ExtJson string `xorm:"'ext_json' JSON"`
|
||||||
ExtJson string `xorm:"'ext_json' JSON"`
|
ExpireTime time.Time `xorm:"'expire_time' datetime"`
|
||||||
ExpireTime time.Time `xorm:"'expire_time' datetime"`
|
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表名
|
// 表名
|
||||||
|
|
|
@ -18,6 +18,9 @@ func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, co
|
||||||
if req.MerchantId > 0 {
|
if req.MerchantId > 0 {
|
||||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||||||
}
|
}
|
||||||
|
if req.Id > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"id": req.Id})
|
||||||
|
}
|
||||||
|
|
||||||
// 调用repo
|
// 调用repo
|
||||||
appList := make([]appmodel.App, 0)
|
appList := make([]appmodel.App, 0)
|
||||||
|
@ -26,13 +29,13 @@ func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, co
|
||||||
return appList, count, code
|
return appList, count, code
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppCreate(App *appmodel.App) (code int) {
|
func AppCreate(app *appmodel.App) (code int) {
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
db := paychannelmodel.GetInstance().GetDb()
|
||||||
repo := data.NewAppRepo(db)
|
repo := data.NewAppRepo(db)
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
merchantRepo := data.NewMerchantRepo(db)
|
||||||
// 拼接查询条件
|
// 拼接查询条件
|
||||||
conn := builder.NewCond()
|
conn := builder.NewCond()
|
||||||
conn = conn.And(builder.Eq{"id": App.MerchantId})
|
conn = conn.And(builder.Eq{"id": app.MerchantId})
|
||||||
merchant := merchantmodel.Merchant{}
|
merchant := merchantmodel.Merchant{}
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,31 +45,25 @@ func AppCreate(App *appmodel.App) (code int) {
|
||||||
return errorcode.MerchantNotFound
|
return errorcode.MerchantNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = repo.AppInsertOne(App)
|
_, err = repo.AppInsertOne(app)
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppUpdate(App *appmodel.App) (code int) {
|
func AppUpdate(app *appmodel.App) (code int) {
|
||||||
|
var err error
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
db := paychannelmodel.GetInstance().GetDb()
|
||||||
repo := data.NewAppRepo(db)
|
repo := data.NewAppRepo(db)
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": App.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼接查询条件
|
// 拼接查询条件
|
||||||
uconn := builder.NewCond()
|
conn := builder.NewCond()
|
||||||
uconn = uconn.And(builder.Eq{"Id": App.Id})
|
conn = conn.And(builder.Eq{"Id": app.Id})
|
||||||
_, err = repo.AppUpdate(App, uconn, "app_remark")
|
if app.AppName != "" {
|
||||||
|
// 编辑页面更新,备注和白名单IP可更新为空
|
||||||
|
_, err = repo.AppUpdate(app, conn, "app_remark", "white_ip")
|
||||||
|
} else {
|
||||||
|
_, err = repo.AppUpdate(app, conn)
|
||||||
|
}
|
||||||
|
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
|
@ -84,3 +81,19 @@ func AppDelete(req entities.IdRequest) (code int) {
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AppGet(app *appmodel.App) (code int) {
|
||||||
|
repo := data.NewAppRepo(appmodel.GetInstance().GetDb())
|
||||||
|
// 拼接查询条件
|
||||||
|
conn := builder.NewCond()
|
||||||
|
conn = conn.And(builder.Eq{"id": app.Id})
|
||||||
|
has, err := repo.AppGet(app, conn)
|
||||||
|
if err != nil {
|
||||||
|
return handErr(err)
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
return errorcode.AppNotFound
|
||||||
|
}
|
||||||
|
code = errorcode.Success
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"PaymentCenter/app/http/entities"
|
"PaymentCenter/app/http/entities"
|
||||||
"PaymentCenter/app/http/entities/backend"
|
"PaymentCenter/app/http/entities/backend"
|
||||||
"PaymentCenter/app/models/merchantmodel"
|
"PaymentCenter/app/models/merchantmodel"
|
||||||
|
"strings"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,6 +23,9 @@ func MerchantList(req backend.MerchantListRequest) (result []merchantmodel.Merch
|
||||||
if req.Phone != "" {
|
if req.Phone != "" {
|
||||||
conn = conn.And(builder.Like{"phone", req.Phone})
|
conn = conn.And(builder.Like{"phone", req.Phone})
|
||||||
}
|
}
|
||||||
|
if req.GroupInfo != "" {
|
||||||
|
conn = conn.And(builder.In("creator", strings.Split(req.GroupInfo, ",")))
|
||||||
|
}
|
||||||
|
|
||||||
// 调用repo
|
// 调用repo
|
||||||
merchantList := make([]merchantmodel.Merchant, 0)
|
merchantList := make([]merchantmodel.Merchant, 0)
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PaymentCenter/app/data"
|
||||||
|
"PaymentCenter/app/http/entities/backend"
|
||||||
|
"PaymentCenter/app/models/orderlogmodel"
|
||||||
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
|
"xorm.io/builder"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 订单列表,后台查询
|
||||||
|
func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, total int64, code int) {
|
||||||
|
repo := data.NewOrderRepo(paychannelmodel.GetInstance().GetDb())
|
||||||
|
// 拼接查询条件
|
||||||
|
conn := builder.NewCond()
|
||||||
|
if req.Id > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"id": req.Id})
|
||||||
|
}
|
||||||
|
if req.MerchantId > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||||||
|
}
|
||||||
|
if req.PayId > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"pay_id": req.PayId})
|
||||||
|
}
|
||||||
|
if req.AppId > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"app_id": req.AppId})
|
||||||
|
}
|
||||||
|
if req.MerchantOrderId != "" {
|
||||||
|
conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId})
|
||||||
|
}
|
||||||
|
if req.Status > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"status": req.Status})
|
||||||
|
}
|
||||||
|
if req.OrderType > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"order_type": req.OrderType})
|
||||||
|
}
|
||||||
|
if !req.StartTime.IsZero() {
|
||||||
|
conn = conn.And(builder.Gte{"start_time": req.StartTime})
|
||||||
|
}
|
||||||
|
if !req.EndTime.IsZero() {
|
||||||
|
conn = conn.And(builder.Lte{"end_time": req.EndTime})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用repo
|
||||||
|
orderList := make([]ordersmodel.OrdersBackendList, 0)
|
||||||
|
count, err := repo.OrdersBackendList(conn, req.PageRequest, &orderList)
|
||||||
|
code = handErr(err)
|
||||||
|
return orderList, count, code
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrderLogsList(req backend.OrderLogsListRequest) (result []orderlogmodel.OrderLog, total int64, code int) {
|
||||||
|
repo := data.NewOrderLogRepo(paychannelmodel.GetInstance().GetDb())
|
||||||
|
conn := builder.NewCond()
|
||||||
|
if req.OrderId > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"order_id": req.OrderId})
|
||||||
|
}
|
||||||
|
// 调用repo
|
||||||
|
orderLogList := make([]orderlogmodel.OrderLog, 0)
|
||||||
|
count, err := repo.OrderLogList(conn, req.PageRequest, &orderLogList)
|
||||||
|
code = handErr(err)
|
||||||
|
|
||||||
|
return orderLogList, count, code
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ func PayChannelList(req backend.PayChannelListRequest) (result []paychannelmodel
|
||||||
if req.MerchantId > 0 {
|
if req.MerchantId > 0 {
|
||||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||||||
}
|
}
|
||||||
|
if req.Id > 0 {
|
||||||
|
conn = conn.And(builder.Eq{"id": req.Id})
|
||||||
|
}
|
||||||
|
|
||||||
// 调用repo
|
// 调用repo
|
||||||
paychannelList := make([]paychannelmodel.PayChannel, 0)
|
paychannelList := make([]paychannelmodel.PayChannel, 0)
|
||||||
|
@ -49,23 +52,11 @@ func PayChannelCreate(payChannel *paychannelmodel.PayChannel) (code int) {
|
||||||
func PayChannelUpdate(payChannel *paychannelmodel.PayChannel) (code int) {
|
func PayChannelUpdate(payChannel *paychannelmodel.PayChannel) (code int) {
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
db := paychannelmodel.GetInstance().GetDb()
|
||||||
repo := data.NewPayChannelRepo(db)
|
repo := data.NewPayChannelRepo(db)
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": payChannel.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼接查询条件
|
// 拼接查询条件
|
||||||
uconn := builder.NewCond()
|
uconn := builder.NewCond()
|
||||||
uconn = uconn.And(builder.Eq{"Id": payChannel.Id})
|
uconn = uconn.And(builder.Eq{"Id": payChannel.Id})
|
||||||
_, err = repo.PayChannelUpdate(payChannel, uconn, "white_ip")
|
_, err := repo.PayChannelUpdate(payChannel, uconn, "white_ip")
|
||||||
|
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
|
@ -83,3 +74,21 @@ func PayChannelDelete(req entities.IdRequest) (code int) {
|
||||||
code = handErr(err)
|
code = handErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PayChannelGet(payChannel *paychannelmodel.PayChannel) (code int) {
|
||||||
|
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
|
||||||
|
|
||||||
|
// 拼接查询条件
|
||||||
|
conn := builder.NewCond()
|
||||||
|
conn = conn.And(builder.Eq{"id": payChannel.Id})
|
||||||
|
has, err := repo.PayChannelGet(payChannel, conn)
|
||||||
|
if err != nil {
|
||||||
|
return handErr(err)
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
return errorcode.PayChannelNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
code = errorcode.Success
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -410,3 +410,13 @@ func ParseToken(tokenString string) (*jwt.Token, *Claims, error) {
|
||||||
})
|
})
|
||||||
return token, Claims, err
|
return token, Claims, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断切片是否包含指定字符串
|
||||||
|
func SliceInStr(s string, slice []string) bool {
|
||||||
|
for _, v := range slice {
|
||||||
|
if s == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -4,11 +4,10 @@ import (
|
||||||
"PaymentCenter/app/jobs"
|
"PaymentCenter/app/jobs"
|
||||||
"PaymentCenter/app/jobs/basejob"
|
"PaymentCenter/app/jobs/basejob"
|
||||||
"PaymentCenter/config"
|
"PaymentCenter/config"
|
||||||
"github.com/qit-team/snow-core/log/accesslogger"
|
|
||||||
|
|
||||||
"github.com/qit-team/snow-core/db"
|
"github.com/qit-team/snow-core/db"
|
||||||
"github.com/qit-team/snow-core/kernel/close"
|
"github.com/qit-team/snow-core/kernel/close"
|
||||||
"github.com/qit-team/snow-core/kernel/container"
|
"github.com/qit-team/snow-core/kernel/container"
|
||||||
|
"github.com/qit-team/snow-core/log/accesslogger"
|
||||||
"github.com/qit-team/snow-core/log/logger"
|
"github.com/qit-team/snow-core/log/logger"
|
||||||
"github.com/qit-team/snow-core/redis"
|
"github.com/qit-team/snow-core/redis"
|
||||||
)
|
)
|
||||||
|
@ -26,6 +25,8 @@ func Bootstrap(conf *config.Config) (err error) {
|
||||||
//注册db服务
|
//注册db服务
|
||||||
//第一个参数为注入别名,第二个参数为配置,第三个参数可选为是否懒加载
|
//第一个参数为注入别名,第二个参数为配置,第三个参数可选为是否懒加载
|
||||||
err = db.Pr.Register(db.SingletonMain, conf.Db)
|
err = db.Pr.Register(db.SingletonMain, conf.Db)
|
||||||
|
//cacher := caches.NewLRUCacher2(caches.NewMemoryStore(), time.Hour, 1000)
|
||||||
|
//db.GetDb().SetDefaultCacher(cacher)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -36,6 +36,7 @@ type Config struct {
|
||||||
OpenApi OpenApi `toml:"OpenApi"`
|
OpenApi OpenApi `toml:"OpenApi"`
|
||||||
Jwt Jwt `toml:"Jwt"`
|
Jwt Jwt `toml:"Jwt"`
|
||||||
AliOss AliOss `toml:"AliOss"`
|
AliOss AliOss `toml:"AliOss"`
|
||||||
|
AdminGate []string `toml:"AdminGate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliOss struct {
|
type AliOss struct {
|
||||||
|
|
Loading…
Reference in New Issue