diff --git a/Dockerfile b/Dockerfile index b3a2e5b..71ae4a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,22 @@ -# # 使用官方Go镜像作为构建环境 -# FROM golang AS builder +# 使用官方Go镜像作为构建环境 +FROM golang:alpine AS builder -# # 设置工作目录 -# WORKDIR /app +# 设置工作目录 +WORKDIR /app -# # 复制项目源码 -# COPY . . +# 复制项目源码 +COPY . . -# # 复制go模块依赖文件 -# COPY go.mod go.sum ./ +# 复制go模块依赖文件 +COPY go.mod go.sum ./ -# # 安装go模块依赖 -# RUN go env -w GOPROXY=https://goproxy.cn,direct -# RUN go mod tidy +# 安装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应用程序,生成静态链接的二进制文件 +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server . # 创建最终镜像,用于运行编译后的Go程序 FROM alpine @@ -27,9 +27,17 @@ ENV server = "admin" WORKDIR /app # 将编译好的二进制文件从构建阶段复制到运行阶段 -COPY /server . +COPY --from=builder /app/server . #COPY --from=builder /app/server . COPY .env . # 设置容器启动时运行的命令 -ENTRYPOINT ["/app/server", "-a", "$server"] \ No newline at end of file +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 \ No newline at end of file diff --git a/app/http/controllers/transfersys/transfersys.go b/app/http/controllers/transfersys/transfersys.go index 40f06b7..4c8937c 100644 --- a/app/http/controllers/transfersys/transfersys.go +++ b/app/http/controllers/transfersys/transfersys.go @@ -122,6 +122,78 @@ func GetOrderFromQueue(c *gin.Context) { 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) { request := new(transEnt.FinishOrderReq) err := common.GenRequest(c, request) diff --git a/app/http/entities/transfersys/transfersys.go b/app/http/entities/transfersys/transfersys.go index c04e76e..e74f7dd 100644 --- a/app/http/entities/transfersys/transfersys.go +++ b/app/http/entities/transfersys/transfersys.go @@ -27,6 +27,10 @@ type GetOrderFromQueueReq struct { QueueNo int64 `json:"queue_no"` } +type GetOrderFromQueuesReq struct { + QueueNos []int64 `json:"queue_nos"` +} + type FinishOrderReq struct { Id int64 `json:"id" validate:"required"` OrderNo string `json:"order_no" validate:"required"` diff --git a/app/http/routes/route.go b/app/http/routes/route.go index d140639..10213d8 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -126,6 +126,7 @@ func RegisterRoute(router *gin.Engine) { { transfersys.GET("/recharge/get_order", transCon.GetOrder) 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/set_order_mobile", transCon.SetOrderMobile) } diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index 5f44cd9..efa67e2 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -452,8 +452,8 @@ func (m *ordersModel) GetTimeoutOrder( sql := "1=1" var args []interface{} 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(DATE_ADD(NOW(),INTERVAL 8 HOUR), 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)" err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) return } @@ -466,8 +466,8 @@ func (m *ordersModel) GetRechargeTimeoutOrder( var args []interface{} sql += " and transfer_status = 2" 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(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 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)" err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) return } diff --git a/auto-monitor.tar b/auto-monitor.tar new file mode 100644 index 0000000..651e714 Binary files /dev/null and b/auto-monitor.tar differ