feat(user): 该更支付模式,查询模式
This commit is contained in:
parent
1604950f31
commit
014940d86d
@ -7,12 +7,15 @@ info (
|
|||||||
email: "2440983361@qq.com"
|
email: "2440983361@qq.com"
|
||||||
version: "v1"
|
version: "v1"
|
||||||
)
|
)
|
||||||
|
import (
|
||||||
|
"pay/pay.api"
|
||||||
|
)
|
||||||
@server (
|
@server (
|
||||||
prefix: api/v1
|
prefix: api/v1
|
||||||
group: pay
|
group: pay
|
||||||
)
|
)
|
||||||
service main {
|
service main {
|
||||||
|
|
||||||
// 微信支付回调
|
// 微信支付回调
|
||||||
@handler WechatPayCallback
|
@handler WechatPayCallback
|
||||||
post /pay/wechat/callback
|
post /pay/wechat/callback
|
||||||
@ -26,3 +29,13 @@ service main {
|
|||||||
post /pay/wechat/refund_callback
|
post /pay/wechat/refund_callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@server (
|
||||||
|
prefix: api/v1
|
||||||
|
group: pay
|
||||||
|
jwt: JwtAuth
|
||||||
|
)
|
||||||
|
service main {
|
||||||
|
// 支付
|
||||||
|
@handler Payment
|
||||||
|
post /pay/payment (PaymentReq) returns (PaymentResp)
|
||||||
|
}
|
22
app/user/cmd/api/desc/pay/pay.api
Normal file
22
app/user/cmd/api/desc/pay/pay.api
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info (
|
||||||
|
title: "产品支付服务"
|
||||||
|
desc: "产品支付服务"
|
||||||
|
author: "Liangzai"
|
||||||
|
email: "2440983361@qq.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
PaymentReq {
|
||||||
|
Id string `json:"id"`
|
||||||
|
PayMethod string `json:"pay_method"`
|
||||||
|
}
|
||||||
|
PaymentResp {
|
||||||
|
prepayID string `json:"prepay_id"`
|
||||||
|
OrderID int64 `json:"order_id"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,6 +60,10 @@ service main {
|
|||||||
jwt: JwtAuth
|
jwt: JwtAuth
|
||||||
)
|
)
|
||||||
service main {
|
service main {
|
||||||
|
@doc "获取查询临时订单"
|
||||||
|
@handler queryProvisionalOrder
|
||||||
|
get /query/provisional_order/:id (QueryProvisionalOrderReq) returns (QueryProvisionalOrderResp)
|
||||||
|
|
||||||
@doc "查询示例"
|
@doc "查询示例"
|
||||||
@handler queryExample
|
@handler queryExample
|
||||||
get /query/example (QueryExampleReq) returns (QueryExampleResp)
|
get /query/example (QueryExampleReq) returns (QueryExampleResp)
|
||||||
@ -79,6 +83,4 @@ service main {
|
|||||||
@doc "重试查询"
|
@doc "重试查询"
|
||||||
@handler queryRetry
|
@handler queryRetry
|
||||||
post /query/retry/:id (QueryRetryReq) returns (QueryRetryResp)
|
post /query/retry/:id (QueryRetryReq) returns (QueryRetryResp)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ type (
|
|||||||
Data string `json:"data" validate:"required"`
|
Data string `json:"data" validate:"required"`
|
||||||
}
|
}
|
||||||
QueryResp {
|
QueryResp {
|
||||||
prepayID string `json:"prepay_id"`
|
id string `json:"id"`
|
||||||
OrderID int64 `json:"order_id"`
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,6 +27,19 @@ type Query {
|
|||||||
QueryState string `json:"query_state"` // 查询状态
|
QueryState string `json:"query_state"` // 查询状态
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取查询临时订单
|
||||||
|
type (
|
||||||
|
QueryProvisionalOrderReq {
|
||||||
|
Id string `path:"id"`
|
||||||
|
}
|
||||||
|
QueryProvisionalOrderResp {
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCard string `json:"id_card"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Product Product `json:"product"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
QueryListReq {
|
QueryListReq {
|
||||||
Page int64 `form:"page"` // 页码
|
Page int64 `form:"page"` // 页码
|
||||||
|
42
app/user/cmd/api/etc/user.dev.yaml
Normal file
42
app/user/cmd/api/etc/user.dev.yaml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
Name: user
|
||||||
|
Host: 0.0.0.0
|
||||||
|
Port: 8888
|
||||||
|
DataSource: "qnc:5vg67b3UNHu8@tcp(127.0.0.1:20001)/qnc?charset=utf8mb4&parseTime=True&loc=Local"
|
||||||
|
CacheRedis:
|
||||||
|
- Host: "127.0.0.1:20002"
|
||||||
|
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
||||||
|
Type: "node" # 单节点模式
|
||||||
|
JwtAuth:
|
||||||
|
AccessSecret: "WUvoIwL-FK0qnlxhvxR9tV6SjfOpeJMpKmY2QvT99lA"
|
||||||
|
AccessExpire: 86400 # JWT过期时间
|
||||||
|
RefreshAfter: 43200 # 更新时间
|
||||||
|
VerifyCode:
|
||||||
|
AccessKeyID: "LTAI5tKGB3TVJbMHSoZN3yr9"
|
||||||
|
AccessKeySecret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
|
||||||
|
EndpointURL: "dysmsapi.aliyuncs.com"
|
||||||
|
SignName: "天远数据"
|
||||||
|
TemplateCode: "SMS_474525324"
|
||||||
|
ValidTime: 300
|
||||||
|
Encrypt:
|
||||||
|
SecretKey: "ff83609b2b24fc73196aac3d3dfb874f"
|
||||||
|
WestConfig:
|
||||||
|
Url: "http://proxy.tianyuanapi.com/api/invoke"
|
||||||
|
Key: "121a1e41fc1690dd6b90afbcacd80cf4"
|
||||||
|
SecretId: "449159"
|
||||||
|
SecretSecondId: "296804"
|
||||||
|
Alipay:
|
||||||
|
AppID: "2021004165608254"
|
||||||
|
PrivateKey: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvo8TmTNnVguKwMYrX0z01PfUlSS+AqwwCH1+/P39q6No+09yO1bjhy4LowtDfwKX8F+IZLl5Cx06f1M8KzPvjQliBAfMJ1FuTEOOXPmtE1YLAYIUMLbltR6Crnp16T28eF41Uo0PUo2ple/oSjWhYgsTJjyBMXY04f6HM2uZlHOhG2aOUz2CDNbvkEhNddazuPMgo8Xl7vwENGDFTPa85HmSSoDppFowLdYfAw2Jl1ilKNg4sOPc6d507nXdgpMlUguwZxol6OQ2hBS6v9OjII5cJ1tyR/klJRapnIPmFaPvhDozYwjU6Z3jMvcbrByl0qNpLrbEFS4pn9hfRo4YrAgMBAAECggEAZAi0Ri6TCqXnEk7FMzMec0p8auYJ5hCFYFgaIkS5/1vroUjtH3TePcu5HXSHnkiMwM2hepIMIaB+SU3dNduVwtOwsJk5oOmP1m0SErv8QFISjBrs7AjGyVS4T8ahDl5bfRoQ5pmuMld4a6B2x0Y+ndqs1ddsn9HQctNOhexOuFsSjX1N3PZxFzfRTmGzxf7kwZGlXMN7G1r3Rp4koylYHVpqjXIK34Anc8SVljxFVkFOk62QvBdYcCucepymHNl0pYwPDCCylPH8OpIXOErmPldTflmoLRc+ywu9rw4I8UvkoPgTe+16he+jdi/N7cwbMTfixq+/Aeadjv2AgMuwkQKBgQDgLS3dRFAc6FMSJIA0FKgv5D/R3NZgWilbOAF11PtnE4AX4i0yZryGtLq+3NWCWYQF8iI60lIy3rEf9zWncwfadhWTEDUBjjrqqU46N2ddTzHsDw09I56TT2vrEwCdmJ2vh1hxPfgE3fSDnKbP4Wkl77JCTH7v0rA1jb65Plt8TwKBgQDIkrXqe/pVHDdxswoPL6em32TnKiaJ/R/UDDio20mgGG7FWEJAY5yYtu0y9Ug7W8PjJE7/cJ2/dwDSvHZm8R0iq8d6XkzN03Z+uvzGnMdUraXJZHSPZ5L/2ofysXjt/OtpA1Sox5++1+obiq6CZ6IYORLSxSf+it1JUbKXsNcVZQKBgQCTPzm7984DXtqJtS38h4D9jBgbWcn6Gd7GSuAyrIXBa76ccXSsgWzdskJjcZxQdUnRufyf1Fwni7yeOXullFoZNazwHxoh/nFWh4SZmqCrWoR5AF36xbW4HtfM3XtvCLqye90s7L5HPB8Kf8/WBcJSJ8JX5/UMw7/4PTWEaaAf4wKBgQCEXu7YVgIccYbV7wdQhm7q3rxFI7hTkU6UL4ylRDQPCJDyhREUValf0DozS1XkdueM3MWWJ8i0N+G/MsohnjdQTnZT+DBQFqM5eEai/Y1AAWpMw5N5oS2O1barIR1iU2053QzeZwCyfuTuUFRjk+mSevhFSgDfKN5qKRTor7kDUQKBgB3fC6jO8XCwimPvpsiGnuddNAq/w8iqSjSwuSvbI0Q7Lq6rvAIw2AmkC5t4kW4JcZLUgDvAs4GFoPDYhoL73vc1e2c35VTNck6IxZSQzzQ9pfXFiLtTe6eqggN4EOPGHKLd92CMAgoeySsp3NydpGSx2N/NUqp8BkoFLQ/k2W9o"
|
||||||
|
AlipayPublicKey: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2CqoCp95w/JV3RT/gzF4/8QmVT1HQNaeW7yUp+mA7x9AbjvlTW/+eRn6oGAL/XhZLjvHD0XjKLVKX0MJVS1aUQHEHEbOJN4Eu8II45OavD4iZISa7Kp9V6AM+i4qTyaeV2wNDnGxHQBaLVUGCfMR+56EK2YpORdE1H9uy72SSQseVb3bmpsV9EW/IJNmcVL/ut3uA1JWAoRmzlQ7ekxg7p8AYXzYPEHQr1tl7W+M4zv9wO9GKZCxIqMA8U3RP5npPfRaCfIRGzXzCqFEEUvWuidOB7frsvN4jiPD07qpL2Bi9LM1X/ee2kC/oM8Uhd7ERZhG8MbZfijZKxgrsDKBcwIDAQAB"
|
||||||
|
IsProduction: true
|
||||||
|
NotifyUrl: "https://6m4685017o.goho.co/api/v1/pay/alipay/callback"
|
||||||
|
Wxpay:
|
||||||
|
AppID: "1682635136"
|
||||||
|
MchID: "1682635136"
|
||||||
|
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
||||||
|
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
||||||
|
MchPrivateKeyPath: "etc/merchant/apiclient_key.pem"
|
||||||
|
NotifyUrl: "https://6m4685017o.goho.co/api/v1/pay/wechat/callback"
|
||||||
|
RefundNotifyUrl: "https://6m4685017o.goho.co/api/v1/wechat/refund_callback"
|
||||||
|
Ali:
|
||||||
|
Code: "d55b58829efb41c8aa8e86769cba4844"
|
29
app/user/cmd/api/internal/handler/pay/paymenthandler.go
Normal file
29
app/user/cmd/api/internal/handler/pay/paymenthandler.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package pay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/logic/pay"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PaymentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PaymentReq
|
||||||
|
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 := pay.NewPaymentLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.Payment(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/logic/query"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func QueryProvisionalOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.QueryProvisionalOrderReq
|
||||||
|
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 := query.NewQueryProvisionalOrderLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.QueryProvisionalOrder(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
rest.WithPrefix("/api/v1"),
|
rest.WithPrefix("/api/v1"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/pay/payment",
|
||||||
|
Handler: pay.PaymentHandler(serverCtx),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
|
||||||
|
rest.WithPrefix("/api/v1"),
|
||||||
|
)
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
@ -140,6 +152,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/query/orderId/:order_id",
|
Path: "/query/orderId/:order_id",
|
||||||
Handler: query.QueryDetailByOrderIdHandler(serverCtx),
|
Handler: query.QueryDetailByOrderIdHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// 获取查询临时订单
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/query/provisional_order/:id",
|
||||||
|
Handler: query.QueryProvisionalOrderHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// 重试查询
|
// 重试查询
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
|
101
app/user/cmd/api/internal/logic/pay/paymentlogic.go
Normal file
101
app/user/cmd/api/internal/logic/pay/paymentlogic.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package pay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
|
"qnc-server/app/user/model"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PaymentLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLogic {
|
||||||
|
return &PaymentLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp, err error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
redisKey := fmt.Sprintf("%d:%s", userID, req.Id)
|
||||||
|
cache, cacheErr := l.svcCtx.Redis.GetCtx(l.ctx, redisKey)
|
||||||
|
if cacheErr != nil {
|
||||||
|
return nil, cacheErr
|
||||||
|
}
|
||||||
|
var data types.QueryCache
|
||||||
|
err = json.Unmarshal([]byte(cache), &data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 解析缓存内容失败, %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
product, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, data.Product)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 查找产品错误: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var prepayID string
|
||||||
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
|
var createOrderErr error
|
||||||
|
if req.PayMethod == "wechatpay" {
|
||||||
|
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
||||||
|
} else {
|
||||||
|
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
||||||
|
}
|
||||||
|
if createOrderErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 创建支付订单失败: %+v", createOrderErr)
|
||||||
|
}
|
||||||
|
var orderID int64
|
||||||
|
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
order := model.Order{
|
||||||
|
OrderNo: outTradeNo,
|
||||||
|
UserId: userID,
|
||||||
|
ProductId: product.Id,
|
||||||
|
PaymentPlatform: req.PayMethod,
|
||||||
|
PaymentScene: "app",
|
||||||
|
Amount: product.SellPrice,
|
||||||
|
Status: "pending",
|
||||||
|
}
|
||||||
|
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
||||||
|
if insertOrderErr != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 保存订单失败: %+v", insertOrderErr)
|
||||||
|
}
|
||||||
|
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
||||||
|
if lastInsertIdErr != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
||||||
|
}
|
||||||
|
orderID = insertedOrderID
|
||||||
|
query := model.Query{
|
||||||
|
OrderId: orderID,
|
||||||
|
UserId: userID,
|
||||||
|
ProductId: product.Id,
|
||||||
|
QueryParams: cache,
|
||||||
|
QueryState: "pending",
|
||||||
|
}
|
||||||
|
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
||||||
|
if insertQueryErr != nil {
|
||||||
|
return insertQueryErr
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if transErr != nil {
|
||||||
|
return nil, transErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.PaymentResp{PrepayID: prepayID, OrderID: orderID}, nil
|
||||||
|
}
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,24 @@ func (l *BackgroundCheckLogic) BackgroundCheck(req *types.QueryReq) (resp *types
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "人事背调, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "人事背调, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "backgroundcheck")
|
|
||||||
if findProductErr != nil {
|
// 缓存
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 查找婚姻产品错误: %+v", findProductErr)
|
queryCache := types.QueryCache{
|
||||||
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "backgroundcheck",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "backgroundcheck", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,23 @@ func (l *CompanyInfoLogic) CompanyInfo(req *types.QueryReq) (resp *types.QueryRe
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "企业报告, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "企业报告, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "companyinfo")
|
// 缓存
|
||||||
if findProductErr != nil {
|
queryCache := types.QueryCache{
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 查找婚姻产品错误: %+v", findProductErr)
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "companyinfo",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "companyinfo", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,23 @@ func (l *HomeServiceLogic) HomeService(req *types.QueryReq) (resp *types.QueryRe
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "家政服务, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "家政服务, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "homeservice")
|
// 缓存
|
||||||
if findProductErr != nil {
|
queryCache := types.QueryCache{
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 查找婚姻产品错误: %+v", findProductErr)
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "homeservice",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "homeservice", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,14 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MarriageLogic struct {
|
type MarriageLogic struct {
|
||||||
@ -86,68 +85,24 @@ func (l *MarriageLogic) Marriage(req *types.QueryReq) (resp *types.QueryResp, er
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "婚恋评估, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "婚恋评估, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, MERRIAGE)
|
|
||||||
if findProductErr != nil {
|
// 缓存
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 查找婚姻产品错误: %+v", findProductErr)
|
queryCache := types.QueryCache{
|
||||||
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: MERRIAGE,
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", MERRIAGE, userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,23 @@ func (l *PreLoanBackgroundCheckLogic) PreLoanBackgroundCheck(req *types.QueryReq
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "贷前背调, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "贷前背调, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "preloanbackgroundcheck")
|
// 缓存
|
||||||
if findProductErr != nil {
|
queryCache := types.QueryCache{
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 查找婚姻产品错误: %+v", findProductErr)
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "preloanbackgroundcheck",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "preloanbackgroundcheck", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type QueryProvisionalOrderLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQueryProvisionalOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryProvisionalOrderLogic {
|
||||||
|
return &QueryProvisionalOrderLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *QueryProvisionalOrderLogic) QueryProvisionalOrder(req *types.QueryProvisionalOrderReq) (resp *types.QueryProvisionalOrderResp, err error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
redisKey := fmt.Sprintf("%d:%s", userID, req.Id)
|
||||||
|
cache, cacheErr := l.svcCtx.Redis.GetCtx(l.ctx, redisKey)
|
||||||
|
if cacheErr != nil {
|
||||||
|
return nil, cacheErr
|
||||||
|
}
|
||||||
|
var data types.QueryCache
|
||||||
|
err = json.Unmarshal([]byte(cache), &data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 解析缓存内容失败, %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
productModel, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, data.Product)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 查找产品错误: %+v", err)
|
||||||
|
}
|
||||||
|
var product types.Product
|
||||||
|
err = copier.Copy(&product, productModel)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 用户信息结构体复制失败: %+v", err)
|
||||||
|
}
|
||||||
|
return &types.QueryProvisionalOrderResp{
|
||||||
|
Name: data.Name,
|
||||||
|
IdCard: data.Name,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: product,
|
||||||
|
}, nil
|
||||||
|
}
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,23 @@ func (l *RentalInfoLogic) RentalInfo(req *types.QueryReq) (resp *types.QueryResp
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "租赁服务, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "租赁服务, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "rentalinfo")
|
// 缓存
|
||||||
if findProductErr != nil {
|
queryCache := types.QueryCache{
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 查找婚姻产品错误: %+v", findProductErr)
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "rentalinfo",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "rentalinfo", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"qnc-server/app/user/cmd/api/internal/service"
|
"qnc-server/app/user/cmd/api/internal/service"
|
||||||
"qnc-server/app/user/model"
|
|
||||||
"qnc-server/common/ctxdata"
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
"qnc-server/pkg/lzkit/crypto"
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
"qnc-server/pkg/lzkit/validator"
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
"time"
|
||||||
|
|
||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
"qnc-server/app/user/cmd/api/internal/types"
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
@ -86,68 +85,23 @@ func (l *RiskAssessmentLogic) RiskAssessment(req *types.QueryReq) (resp *types.Q
|
|||||||
if !verification.Passed {
|
if !verification.Passed {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "个人风险, 二要素验证不通过: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "个人风险, 二要素验证不通过: %+v", err)
|
||||||
}
|
}
|
||||||
product, findProductErr := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, "riskassessment")
|
// 缓存
|
||||||
if findProductErr != nil {
|
queryCache := types.QueryCache{
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 查找婚姻产品错误: %+v", findProductErr)
|
Name: data.Name,
|
||||||
|
IDCard: data.IDCard,
|
||||||
|
Mobile: data.Mobile,
|
||||||
|
Product: "riskassessment",
|
||||||
}
|
}
|
||||||
jsonData, marshalErr := json.Marshal(data)
|
jsonData, marshalErr := json.Marshal(queryCache)
|
||||||
if marshalErr != nil {
|
if marshalErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 序列化参数失败: %+v", marshalErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 序列化参数失败: %+v", marshalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
redisKey := fmt.Sprintf("%s:%d:%s", "riskassessment", userID, outTradeNo)
|
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), 1800)
|
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepayID string
|
return &types.QueryResp{Id: outTradeNo}, nil
|
||||||
var createOrderErr error
|
|
||||||
if data.PayMethod == "wechatpay" {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatAppOrder(l.ctx, product.SellPrice, product.Description, outTradeNo)
|
|
||||||
} else {
|
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayAppOrder(product.SellPrice, product.Description, outTradeNo)
|
|
||||||
}
|
|
||||||
if createOrderErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 创建支付订单失败: %+v", createOrderErr)
|
|
||||||
}
|
|
||||||
var orderID int64
|
|
||||||
transErr := l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
order := model.Order{
|
|
||||||
OrderNo: outTradeNo,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
PaymentPlatform: data.PayMethod,
|
|
||||||
PaymentScene: "app",
|
|
||||||
Amount: product.SellPrice,
|
|
||||||
Status: "pending",
|
|
||||||
}
|
|
||||||
orderInsertResult, insertOrderErr := l.svcCtx.OrderModel.Insert(ctx, session, &order)
|
|
||||||
if insertOrderErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 保存订单失败: %+v", insertOrderErr)
|
|
||||||
}
|
|
||||||
insertedOrderID, lastInsertIdErr := orderInsertResult.LastInsertId()
|
|
||||||
if lastInsertIdErr != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
|
||||||
}
|
|
||||||
orderID = insertedOrderID
|
|
||||||
query := model.Query{
|
|
||||||
OrderId: orderID,
|
|
||||||
UserId: userID,
|
|
||||||
ProductId: product.Id,
|
|
||||||
QueryParams: req.Data,
|
|
||||||
QueryState: "pending",
|
|
||||||
}
|
|
||||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
|
||||||
if insertQueryErr != nil {
|
|
||||||
return insertQueryErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if transErr != nil {
|
|
||||||
return nil, transErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.QueryResp{PrepayID: prepayID, OrderID: orderID}, nil
|
|
||||||
}
|
}
|
||||||
|
8
app/user/cmd/api/internal/types/cache.go
Normal file
8
app/user/cmd/api/internal/types/cache.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type QueryCache struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
IDCard string `json:"id_card"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Product string `json:"product_id"`
|
||||||
|
}
|
@ -1,61 +1,54 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type MarriageReq struct {
|
type MarriageReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
type HomeServiceReq struct {
|
type HomeServiceReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RiskAssessment 查询请求结构
|
// RiskAssessment 查询请求结构
|
||||||
type RiskAssessmentReq struct {
|
type RiskAssessmentReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompanyInfo 查询请求结构
|
// CompanyInfo 查询请求结构
|
||||||
type CompanyInfoReq struct {
|
type CompanyInfoReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RentalInfo 查询请求结构
|
// RentalInfo 查询请求结构
|
||||||
type RentalInfoReq struct {
|
type RentalInfoReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreLoanBackgroundCheck 查询请求结构
|
// PreLoanBackgroundCheck 查询请求结构
|
||||||
type PreLoanBackgroundCheckReq struct {
|
type PreLoanBackgroundCheckReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackgroundCheck 查询请求结构
|
// BackgroundCheck 查询请求结构
|
||||||
type BackgroundCheckReq struct {
|
type BackgroundCheckReq struct {
|
||||||
Name string `json:"name" validate:"required,name"`
|
Name string `json:"name" validate:"required,name"`
|
||||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
PayMethod string `json:"pay_method" validate:"required,payMethod"`
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,16 @@ type MobileLoginResp struct {
|
|||||||
RefreshAfter int64 `json:"refreshAfter"`
|
RefreshAfter int64 `json:"refreshAfter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PaymentReq struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
PayMethod string `json:"pay_method"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaymentResp struct {
|
||||||
|
PrepayID string `json:"prepay_id"`
|
||||||
|
OrderID int64 `json:"order_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type Product struct {
|
type Product struct {
|
||||||
ProductName string `json:"product_name"`
|
ProductName string `json:"product_name"`
|
||||||
ProductEn string `json:"product_en"`
|
ProductEn string `json:"product_en"`
|
||||||
@ -95,13 +105,23 @@ type QueryListResp struct {
|
|||||||
List []Query `json:"list"` // 查询列表
|
List []Query `json:"list"` // 查询列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryProvisionalOrderReq struct {
|
||||||
|
Id string `path:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryProvisionalOrderResp struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
IdCard string `json:"id_card"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Product Product `json:"product"`
|
||||||
|
}
|
||||||
|
|
||||||
type QueryReq struct {
|
type QueryReq struct {
|
||||||
Data string `json:"data" validate:"required"`
|
Data string `json:"data" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryResp struct {
|
type QueryResp struct {
|
||||||
PrepayID string `json:"prepay_id"`
|
Id string `json:"id"`
|
||||||
OrderID int64 `json:"order_id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryRetryReq struct {
|
type QueryRetryReq struct {
|
||||||
|
@ -15,9 +15,21 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/user.yaml", "the config file")
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// 读取环境变量 ENV,默认为 "prod"
|
||||||
|
env := os.Getenv("ENV")
|
||||||
|
if env == "" {
|
||||||
|
env = "production"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据 ENV 加载不同的配置文件
|
||||||
|
var defaultConfigFile string
|
||||||
|
if env == "development" {
|
||||||
|
defaultConfigFile = "etc/user.dev.yaml" // 开发环境配置
|
||||||
|
} else {
|
||||||
|
defaultConfigFile = "etc/user.yaml" // 生产环境配置
|
||||||
|
}
|
||||||
|
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var c config.Config
|
var c config.Config
|
||||||
|
Loading…
Reference in New Issue
Block a user