This commit is contained in:
2026-02-12 15:16:54 +08:00
parent 07bf234b30
commit ca6dcc1b24
21 changed files with 2594 additions and 111 deletions

View File

@@ -26,6 +26,8 @@ import (
pay "tyc-server/app/main/api/internal/handler/pay"
product "tyc-server/app/main/api/internal/handler/product"
query "tyc-server/app/main/api/internal/handler/query"
tianyuan "tyc-server/app/main/api/internal/handler/tianyuan"
upload "tyc-server/app/main/api/internal/handler/upload"
user "tyc-server/app/main/api/internal/handler/user"
"tyc-server/app/main/api/internal/svc"
@@ -770,7 +772,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
Method: http.MethodGet,
@@ -810,7 +812,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
Method: http.MethodPost,
@@ -830,7 +832,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
Method: http.MethodGet,
@@ -880,7 +882,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor, serverCtx.UserDisableInterceptor},
[]rest.Middleware{serverCtx.AuthInterceptor},
[]rest.Route{
{
Method: http.MethodPost,
@@ -987,7 +989,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
Method: http.MethodPost,
@@ -1039,7 +1041,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor, serverCtx.UserDisableInterceptor},
[]rest.Middleware{serverCtx.AuthInterceptor},
[]rest.Route{
{
// query service agent
@@ -1059,7 +1061,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
// query service
@@ -1075,7 +1077,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.UserDisableInterceptor, serverCtx.UserAuthInterceptor},
[]rest.Middleware{serverCtx.UserAuthInterceptor},
[]rest.Route{
{
// 生成分享链接
@@ -1148,6 +1150,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 天远车辆类接口异步回调
Method: http.MethodPost,
Path: "/tianyuan/vehicle/callback",
Handler: tianyuan.VehicleCallbackHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 访问已上传文件(供第三方或前端通过返回的 URL 拉取)
Method: http.MethodGet,
Path: "/upload/file/:fileName",
Handler: upload.ServeUploadedFileHandler(serverCtx),
},
{
// 上传图片,返回可访问 URL如行驶证限制 3MB
Method: http.MethodPost,
Path: "/upload/image",
Handler: upload.UploadImageHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
@@ -1179,7 +1211,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor, serverCtx.UserDisableInterceptor},
[]rest.Middleware{serverCtx.AuthInterceptor},
[]rest.Route{
{
// 绑定手机号

View File

@@ -0,0 +1,33 @@
package tianyuan
import (
"net/http"
tianyuanlogic "tyc-server/app/main/api/internal/logic/tianyuan"
"tyc-server/app/main/api/internal/svc"
"tyc-server/common/result"
"github.com/zeromicro/go-zero/rest/httpx"
)
// VehicleCallbackHandler 天远车辆类接口异步回调入口
// 约定:第三方在回调 URL 上携带 order_no / api_id 等标识,例如:/api/v1/tianyuan/vehicle/callback?order_no=Q_xxx&api_id=QCXG1U4U
// 回调 Body 为该接口最终的 JSON 结果。
func VehicleCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := tianyuanlogic.NewVehicleCallbackLogic(r.Context(), svcCtx)
if err := l.Handle(r); err != nil {
// 对第三方尽量返回 200避免无限重试这里使用统一 result 封装错误
result.HttpResult(r, w, map[string]interface{}{
"code": 500,
"msg": "fail",
}, err)
return
}
httpx.OkJson(w, map[string]interface{}{
"code": 200,
"msg": "success",
})
}
}

View File

@@ -0,0 +1,47 @@
package upload
import (
"net/http"
"os"
"tyc-server/app/main/api/internal/logic/upload"
"tyc-server/app/main/api/internal/svc"
"tyc-server/app/main/api/internal/types"
"tyc-server/common/result"
"tyc-server/pkg/lzkit/validator"
"github.com/zeromicro/go-zero/rest/httpx"
)
func ServeUploadedFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ServeUploadedFileReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err := validator.Validate(req); err != nil {
result.ParamValidateErrorResult(r, w, err)
return
}
l := upload.NewServeUploadedFileLogic(r.Context(), svcCtx)
resp, err := l.ServeUploadedFile(&req)
if err != nil {
result.HttpResult(r, w, nil, err)
return
}
if resp != nil && resp.FilePath != "" {
f, openErr := os.Open(resp.FilePath)
if openErr != nil {
result.HttpResult(r, w, nil, openErr)
return
}
defer f.Close()
w.Header().Set("Content-Type", resp.ContentType)
w.WriteHeader(http.StatusOK)
_, _ = f.WriteTo(w)
return
}
httpx.OkJson(w, resp)
}
}

View File

@@ -0,0 +1,29 @@
package upload
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"tyc-server/app/main/api/internal/logic/upload"
"tyc-server/app/main/api/internal/svc"
"tyc-server/app/main/api/internal/types"
"tyc-server/common/result"
"tyc-server/pkg/lzkit/validator"
)
func UploadImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UploadImageReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err := validator.Validate(req); err != nil {
result.ParamValidateErrorResult(r, w, err)
return
}
l := upload.NewUploadImageLogic(r.Context(), svcCtx)
resp, err := l.UploadImage(&req)
result.HttpResult(r, w, resp, err)
}
}