This commit is contained in:
duyu 2024-09-29 12:04:36 +08:00
parent 2c34d56302
commit dda6943c50
6 changed files with 104 additions and 19 deletions

View File

@ -1,22 +1,22 @@
# # 使用官方Go镜像作为构建环境 # 使用官方Go镜像作为构建环境
# FROM golang AS builder FROM golang:alpine AS builder
# # 设置工作目录 # 设置工作目录
# WORKDIR /app WORKDIR /app
# # 复制项目源码 # 复制项目源码
# COPY . . COPY . .
# # 复制go模块依赖文件 # 复制go模块依赖文件
# COPY go.mod go.sum ./ COPY go.mod go.sum ./
# # 安装go模块依赖 # 安装go模块依赖
# RUN go env -w GOPROXY=https://goproxy.cn,direct RUN go env -w GOPROXY=https://goproxy.cn,direct
# RUN go mod tidy RUN go mod tidy
# # 编译Go应用程序生成静态链接的二进制文件 # 编译Go应用程序生成静态链接的二进制文件
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .
# 创建最终镜像用于运行编译后的Go程序 # 创建最终镜像用于运行编译后的Go程序
FROM alpine FROM alpine
@ -27,9 +27,17 @@ ENV server = "admin"
WORKDIR /app WORKDIR /app
# 将编译好的二进制文件从构建阶段复制到运行阶段 # 将编译好的二进制文件从构建阶段复制到运行阶段
COPY /server . COPY --from=builder /app/server .
#COPY --from=builder /app/server . #COPY --from=builder /app/server .
COPY .env . COPY .env .
# 设置容器启动时运行的命令 # 设置容器启动时运行的命令
ENTRYPOINT ["/app/server", "-a", "$server"] ENTRYPOINT ["/app/server", "-a", "$server"]
# docker build . -t auto-monitor
# docker save -o auto-monitor.tar auto-monitor
# docker load -i auto-monitor.tar
#docker run -itd --name auto_monitor --network default_network -v /home/project/auto_monitor/logs:/app/logs -v /etc/localtime:/etc/localtime:ro -p 8999:8999 auto-monitor -a api

View File

@ -122,6 +122,78 @@ func GetOrderFromQueue(c *gin.Context) {
common.Success(c, response) common.Success(c, response)
} }
func GetOrderFromQueues(c *gin.Context) {
request := new(transEnt.GetOrderFromQueuesReq)
err := common.GenRequest(c, request)
if err != nil {
common.Error(c, 400, err.Error())
return
}
var queue_nos []int64
if len(request.QueueNos) > 0 {
queue_nos = request.QueueNos
} else {
common.Error(c, 400, "队列号不能为空")
return
}
var item *orderMod.Orders
for _, ord := range queue_nos {
//队列里取出一个订单
item, err = transServ.ReadGroup(ord)
if err != nil {
continue
}
//标记订单已经去除
err = orderMod.GetInstance().OrderOutQueue(item.Id)
if err != nil {
common.Error(c, 400, err.Error())
return
}
break
}
if err != nil {
common.Error(c, 400, err.Error())
return
}
var response *transEnt.GetOrderResp = nil
//获取产品信息
product, err := proServ.GetById(item.ProductId)
if err != nil {
common.Error(c, 400, "产品不存在")
return
}
if item != nil {
response = &transEnt.GetOrderResp{
Id: item.Id,
OrderNo: item.OrderNo,
MerchantId: item.MerchantId,
ProductId: item.ProductId,
ProductUrl: product.ProductUrl,
QueueNo: item.QueueNo,
OutTradeNo: item.OutTradeNo,
RechargeAccount: item.RechargeAccount,
AccountType: item.AccountType,
Number: item.Number,
NotifyUrl: item.NotifyUrl,
ExtendParameter: item.ExtendParameter,
Status: item.Status,
TransferStatus: item.TransferStatus,
FailReason: item.FailReason,
CreatedAt: item.CreatedAt.Format(time.RFC3339),
}
} else {
c.JSON(500, gin.H{
"code": 500,
"message": "no data",
})
return
}
common.Success(c, response)
}
func FinishOrder(c *gin.Context) { func FinishOrder(c *gin.Context) {
request := new(transEnt.FinishOrderReq) request := new(transEnt.FinishOrderReq)
err := common.GenRequest(c, request) err := common.GenRequest(c, request)

View File

@ -27,6 +27,10 @@ type GetOrderFromQueueReq struct {
QueueNo int64 `json:"queue_no"` QueueNo int64 `json:"queue_no"`
} }
type GetOrderFromQueuesReq struct {
QueueNos []int64 `json:"queue_nos"`
}
type FinishOrderReq struct { type FinishOrderReq struct {
Id int64 `json:"id" validate:"required"` Id int64 `json:"id" validate:"required"`
OrderNo string `json:"order_no" validate:"required"` OrderNo string `json:"order_no" validate:"required"`

View File

@ -126,6 +126,7 @@ func RegisterRoute(router *gin.Engine) {
{ {
transfersys.GET("/recharge/get_order", transCon.GetOrder) transfersys.GET("/recharge/get_order", transCon.GetOrder)
transfersys.POST("/recharge/get_queue_order", transCon.GetOrderFromQueue) transfersys.POST("/recharge/get_queue_order", transCon.GetOrderFromQueue)
transfersys.POST("/recharge/get_queues_order", transCon.GetOrderFromQueues)
transfersys.POST("/recharge/finish", transCon.FinishOrder) transfersys.POST("/recharge/finish", transCon.FinishOrder)
transfersys.POST("/recharge/set_order_mobile", transCon.SetOrderMobile) transfersys.POST("/recharge/set_order_mobile", transCon.SetOrderMobile)
} }

View File

@ -452,8 +452,8 @@ func (m *ordersModel) GetTimeoutOrder(
sql := "1=1" sql := "1=1"
var args []interface{} var args []interface{}
sql += " and transfer_status not in (1,2,4,5,6)" sql += " and transfer_status not in (1,2,4,5,6)"
// sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)" sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)"
sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 3 MINUTE)" // sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 3 MINUTE)"
err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders)
return return
} }
@ -466,8 +466,8 @@ func (m *ordersModel) GetRechargeTimeoutOrder(
var args []interface{} var args []interface{}
sql += " and transfer_status = 2" sql += " and transfer_status = 2"
sql += " and (fail_reason = '' or fail_reason IS NULL)" sql += " and (fail_reason = '' or fail_reason IS NULL)"
// sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)" sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)"
sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 MINUTE)" // sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 MINUTE)"
err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders)
return return
} }

BIN
auto-monitor.tar Normal file

Binary file not shown.