feat(main): add mp-weixin
This commit is contained in:
@@ -13,7 +13,7 @@ type (
|
|||||||
PayMethod string `json:"pay_method"`
|
PayMethod string `json:"pay_method"`
|
||||||
}
|
}
|
||||||
PaymentResp {
|
PaymentResp {
|
||||||
prepayID string `json:"prepay_id"`
|
prepayData interface{} `json:"prepay_data"`
|
||||||
OrderID int64 `json:"order_id"`
|
OrderID int64 `json:"order_id"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,3 +23,13 @@ service main {
|
|||||||
get /en/:product_en (GetProductByEnRequest) returns (ProductResponse)
|
get /en/:product_en (GetProductByEnRequest) returns (ProductResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@server (
|
||||||
|
prefix: api/v1/product
|
||||||
|
group: product
|
||||||
|
middleware: SourceInterceptor
|
||||||
|
)
|
||||||
|
service main {
|
||||||
|
@handler GetProductRenderList
|
||||||
|
get /render_list/:module (GetProductRenderListRequest) returns (GetProductRenderListResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,3 +34,10 @@ type ProductResponse {
|
|||||||
Product
|
Product
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetProductRenderListRequest{
|
||||||
|
module string `path:"module"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetProductRenderListResponse {
|
||||||
|
Product []Product
|
||||||
|
}
|
||||||
@@ -44,9 +44,7 @@ type (
|
|||||||
Id string `path:"id"`
|
Id string `path:"id"`
|
||||||
}
|
}
|
||||||
QueryProvisionalOrderResp {
|
QueryProvisionalOrderResp {
|
||||||
Name string `json:"name"`
|
QueryParams map[string]interface{} `json:"query_params"`
|
||||||
IdCard string `json:"id_card"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
Product Product `json:"product"`
|
Product Product `json:"product"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -53,8 +53,6 @@ type (
|
|||||||
type (
|
type (
|
||||||
WXMiniAuthReq {
|
WXMiniAuthReq {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
IV string `json:"iv"`
|
|
||||||
EncryptedData string `json:"encryptedData"`
|
|
||||||
}
|
}
|
||||||
WXMiniAuthResp {
|
WXMiniAuthResp {
|
||||||
AccessToken string `json:"accessToken"`
|
AccessToken string `json:"accessToken"`
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ WestConfig:
|
|||||||
YushanConfig:
|
YushanConfig:
|
||||||
ApiKey: "4c566c4a4b543164535455685655316c"
|
ApiKey: "4c566c4a4b543164535455685655316c"
|
||||||
AcctID: "YSSJ843926726"
|
AcctID: "YSSJ843926726"
|
||||||
Url: "https://api.yushanshuju.com/credit-gw/service"
|
Url: "http://proxy.tianyuanapi.com/credit-gw/service"
|
||||||
Alipay:
|
Alipay:
|
||||||
AppID: "2021004165608254"
|
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"
|
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"
|
||||||
@@ -36,7 +36,8 @@ Alipay:
|
|||||||
NotifyUrl: "https://6m4685017o.goho.co/api/v1/pay/alipay/callback"
|
NotifyUrl: "https://6m4685017o.goho.co/api/v1/pay/alipay/callback"
|
||||||
ReturnURL: "http://localhost:5678/inquire"
|
ReturnURL: "http://localhost:5678/inquire"
|
||||||
Wxpay:
|
Wxpay:
|
||||||
AppID: "1682635136"
|
AppID: "wxba8424db4771cc18"
|
||||||
|
AppSecret: "89646203d7f76eb7aef0d926b9efffaa"
|
||||||
MchID: "1682635136"
|
MchID: "1682635136"
|
||||||
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
||||||
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
||||||
|
|||||||
@@ -38,13 +38,14 @@ Alipay:
|
|||||||
NotifyUrl: "https://www.quannengcha.com/api/v1/pay/alipay/callback"
|
NotifyUrl: "https://www.quannengcha.com/api/v1/pay/alipay/callback"
|
||||||
ReturnURL: "https://www.quannengcha.com/report"
|
ReturnURL: "https://www.quannengcha.com/report"
|
||||||
Wxpay:
|
Wxpay:
|
||||||
AppID: "1682635136"
|
AppID: "wxba8424db4771cc18"
|
||||||
|
AppSecret: "89646203d7f76eb7aef0d926b9efffaa"
|
||||||
MchID: "1682635136"
|
MchID: "1682635136"
|
||||||
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
||||||
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
||||||
MchPrivateKeyPath: "etc/merchant/apiclient_key.pem"
|
MchPrivateKeyPath: "etc/merchant/apiclient_key.pem"
|
||||||
NotifyUrl: "https://app.quannengcha.com/api/v1/pay/wechat/callback"
|
NotifyUrl: "https://www.quannengcha.com/api/v1/pay/wechat/callback"
|
||||||
RefundNotifyUrl: "https://app.quannengcha.com/api/v1/wechat/refund_callback"
|
RefundNotifyUrl: "https://www.quannengcha.com/api/v1/wechat/refund_callback"
|
||||||
Applepay:
|
Applepay:
|
||||||
ProductionVerifyURL: "https://api.storekit.itunes.apple.com/inApps/v1/transactions/receipt"
|
ProductionVerifyURL: "https://api.storekit.itunes.apple.com/inApps/v1/transactions/receipt"
|
||||||
SandboxVerifyURL: "https://api.storekit-sandbox.itunes.apple.com/inApps/v1/transactions/receipt"
|
SandboxVerifyURL: "https://api.storekit-sandbox.itunes.apple.com/inApps/v1/transactions/receipt"
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type AlipayConfig struct {
|
|||||||
}
|
}
|
||||||
type WxpayConfig struct {
|
type WxpayConfig struct {
|
||||||
AppID string
|
AppID string
|
||||||
|
AppSecret string
|
||||||
MchID string
|
MchID string
|
||||||
MchCertificateSerialNumber string
|
MchCertificateSerialNumber string
|
||||||
MchApiv3Key string
|
MchApiv3Key string
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package product
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/logic/product"
|
||||||
|
"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 GetProductRenderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetProductRenderListRequest
|
||||||
|
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 := product.NewGetProductRenderListLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetProductRenderList(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,6 +98,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
rest.WithPrefix("/api/v1/product"),
|
rest.WithPrefix("/api/v1/product"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.SourceInterceptor},
|
||||||
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/render_list/:module",
|
||||||
|
Handler: product.GetProductRenderListHandler(serverCtx),
|
||||||
|
},
|
||||||
|
}...,
|
||||||
|
),
|
||||||
|
rest.WithPrefix("/api/v1/product"),
|
||||||
|
)
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
|||||||
if aesEncryptErr != nil {
|
if aesEncryptErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密参数失败: %+v", aesEncryptErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密参数失败: %+v", aesEncryptErr)
|
||||||
}
|
}
|
||||||
var prepayID string
|
var prepayData interface{}
|
||||||
var outTradeNo string
|
var outTradeNo string
|
||||||
var amount float64
|
var amount float64
|
||||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userID)
|
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userID)
|
||||||
@@ -81,16 +81,17 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
|||||||
} else {
|
} else {
|
||||||
amount = product.SellPrice
|
amount = product.SellPrice
|
||||||
}
|
}
|
||||||
|
|
||||||
var createOrderErr error
|
var createOrderErr error
|
||||||
if req.PayMethod == "wechatpay" {
|
if req.PayMethod == "wechat" {
|
||||||
outTradeNo = l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
outTradeNo = l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
prepayData, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||||
} else if req.PayMethod == "alipay" {
|
} else if req.PayMethod == "alipay" {
|
||||||
outTradeNo = l.svcCtx.AlipayService.GenerateOutTradeNo()
|
outTradeNo = l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo, brand)
|
prepayData, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo, brand)
|
||||||
} else if req.PayMethod == "appleiap" {
|
} else if req.PayMethod == "appleiap" {
|
||||||
outTradeNo = l.svcCtx.ApplePayService.GenerateOutTradeNo()
|
outTradeNo = l.svcCtx.ApplePayService.GenerateOutTradeNo()
|
||||||
prepayID = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
prepayData = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
||||||
}
|
}
|
||||||
if createOrderErr != nil {
|
if createOrderErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 创建支付订单失败: %+v", createOrderErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 创建支付订单失败: %+v", createOrderErr)
|
||||||
@@ -132,5 +133,5 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
|||||||
return nil, transErr
|
return nil, transErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.PaymentResp{PrepayID: prepayID, OrderID: orderID}, nil
|
return &types.PaymentResp{PrepayData: prepayData, OrderID: orderID}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (l *WechatPayCallbackLogic) WechatPayCallback(w http.ResponseWriter, r *htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
amount := lzUtils.ToWechatAmount(order.Amount)
|
amount := lzUtils.ToWechatAmount(order.Amount)
|
||||||
if &amount != notification.Amount.Total {
|
if amount != *notification.Amount.Total {
|
||||||
logx.Errorf("微信支付回调,金额不一致")
|
logx.Errorf("微信支付回调,金额不一致")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package product
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/mr"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
|
"qnc-server/app/user/cmd/api/internal/types"
|
||||||
|
"qnc-server/app/user/model"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetProductRenderListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetProductRenderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductRenderListLogic {
|
||||||
|
return &GetProductRenderListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetProductRenderListLogic) GetProductRenderList(req *types.GetProductRenderListRequest) (resp *types.GetProductRenderListResponse, err error) {
|
||||||
|
platform, platformOk := l.ctx.Value("platform").(string)
|
||||||
|
if !platformOk || platform == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取渲染列表失败,没有相关平台信息")
|
||||||
|
}
|
||||||
|
// 从上下文中获取品牌信息
|
||||||
|
brand, brandOk := l.ctx.Value("brand").(string)
|
||||||
|
if !brandOk || brand == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取渲染列表失败,没有相关品牌信息")
|
||||||
|
}
|
||||||
|
|
||||||
|
var platformKey = brand + "_" + platform
|
||||||
|
builder := l.svcCtx.ProductRenderModel.SelectBuilder().Where(squirrel.Eq{
|
||||||
|
"platform": platformKey,
|
||||||
|
"module": req.Module,
|
||||||
|
})
|
||||||
|
productRenderModelList, err := l.svcCtx.ProductRenderModel.FindAll(l.ctx, builder, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取渲染列表失败,获取渲染列表失败%s", err.Error())
|
||||||
|
}
|
||||||
|
var productList []types.Product
|
||||||
|
mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||||
|
for _, productRender := range productRenderModelList {
|
||||||
|
if productRender.IsRendered == 1 {
|
||||||
|
source <- productRender.ProductId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, func(item interface{}, writer mr.Writer[*model.Product], cancel func(error)) {
|
||||||
|
id := item.(int64)
|
||||||
|
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, id)
|
||||||
|
if findProductErr != nil {
|
||||||
|
logx.WithContext(l.ctx).Errorf("获取渲染列表失败, 查找关联product错误: %d, err:%v", id, findProductErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if product != nil && product.Id > 0 {
|
||||||
|
product.Description = ""
|
||||||
|
product.SellPrice = 0
|
||||||
|
writer.Write(product)
|
||||||
|
}
|
||||||
|
}, func(pipe <-chan *model.Product, cancel func(error)) {
|
||||||
|
for item := range pipe {
|
||||||
|
var product types.Product
|
||||||
|
_ = copier.Copy(&product, item)
|
||||||
|
productList = append(productList, product)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return &types.GetProductRenderListResponse{
|
||||||
|
Product: productList,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -119,7 +119,6 @@ func (l *QueryDetailByOrderNoLogic) QueryDetailByOrderNo(req *types.QueryDetailB
|
|||||||
if processErr != nil {
|
if processErr != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", processErr)
|
||||||
}
|
}
|
||||||
// 复制报告数据
|
|
||||||
err = copier.Copy(&query, queryModel)
|
err = copier.Copy(&query, queryModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %+v", err)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (l *QueryProvisionalOrderLogic) QueryProvisionalOrder(req *types.QueryProvi
|
|||||||
if cacheErr != nil {
|
if cacheErr != nil {
|
||||||
return nil, cacheErr
|
return nil, cacheErr
|
||||||
}
|
}
|
||||||
var data types.QueryCache
|
var data types.QueryCacheLoad
|
||||||
err = json.Unmarshal([]byte(cache), &data)
|
err = json.Unmarshal([]byte(cache), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 解析缓存内容失败, %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 解析缓存内容失败, %+v", err)
|
||||||
@@ -54,9 +54,7 @@ func (l *QueryProvisionalOrderLogic) QueryProvisionalOrder(req *types.QueryProvi
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 用户信息结构体复制失败: %+v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取临时订单, 用户信息结构体复制失败: %+v", err)
|
||||||
}
|
}
|
||||||
return &types.QueryProvisionalOrderResp{
|
return &types.QueryProvisionalOrderResp{
|
||||||
Name: data.Name,
|
QueryParams: data.Params,
|
||||||
IdCard: data.Name,
|
|
||||||
Mobile: data.Mobile,
|
|
||||||
Product: product,
|
Product: product,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,13 +56,19 @@ var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceR
|
|||||||
"toc_IDCardTwoElements": (*QueryServiceLogic).ProcessTocIDCardTwoElementsLogic,
|
"toc_IDCardTwoElements": (*QueryServiceLogic).ProcessTocIDCardTwoElementsLogic,
|
||||||
"toc_NaturalLifeStatus": (*QueryServiceLogic).ProcessTocNaturalLifeStatusLogic,
|
"toc_NaturalLifeStatus": (*QueryServiceLogic).ProcessTocNaturalLifeStatusLogic,
|
||||||
"toc_PersonVehicleVerification": (*QueryServiceLogic).ProcessTocPersonVehicleVerificationLogic,
|
"toc_PersonVehicleVerification": (*QueryServiceLogic).ProcessTocPersonVehicleVerificationLogic,
|
||||||
"toc_BankCardBlacklist": (*QueryServiceLogic).ProcessTocBankCardBlacklistLogic,
|
|
||||||
"toc_VehiclesUnderName": (*QueryServiceLogic).ProcessTocVehiclesUnderNameLogic,
|
|
||||||
"toc_DualMarriage": (*QueryServiceLogic).ProcessTocDualMarriageLogic,
|
"toc_DualMarriage": (*QueryServiceLogic).ProcessTocDualMarriageLogic,
|
||||||
"toc_PhoneNumberRisk": (*QueryServiceLogic).ProcessTocPhoneNumberRiskLogic,
|
"toc_PhoneNumberRisk": (*QueryServiceLogic).ProcessTocPhoneNumberRiskLogic,
|
||||||
"toc_NetworkDuration": (*QueryServiceLogic).ProcessTocNetworkDurationLogic,
|
"toc_NetworkDuration": (*QueryServiceLogic).ProcessTocNetworkDurationLogic,
|
||||||
"toc_PhoneSecondaryCard": (*QueryServiceLogic).ProcessTocPhoneSecondaryCardLogic,
|
"toc_PhoneSecondaryCard": (*QueryServiceLogic).ProcessTocPhoneSecondaryCardLogic,
|
||||||
"toc_BankCardFourElements": (*QueryServiceLogic).ProcessTocBankCardFourElementsLogic,
|
"toc_BankCardFourElements": (*QueryServiceLogic).ProcessTocBankCardFourElementsLogic,
|
||||||
|
// 车辆部分
|
||||||
|
"toc_BankCardBlacklist": (*QueryServiceLogic).ProcessTocBankCardBlacklistLogic,
|
||||||
|
"toc_VehiclesUnderName": (*QueryServiceLogic).ProcessTocVehiclesUnderNameLogic,
|
||||||
|
"toc_vehicleInsuranceSummary": (*QueryServiceLogic).ProcessTocVehicleInsuranceSummaryLogic,
|
||||||
|
"toc_vehicleMaintenanceRecord": (*QueryServiceLogic).ProcessTocVehicleMaintenanceRecordLogic,
|
||||||
|
"toc_vehicleValuation": (*QueryServiceLogic).ProcessTocVehicleValuationLogic,
|
||||||
|
"toc_chassisNumberCheck": (*QueryServiceLogic).ProcessTocChassisNumberCheckLogic,
|
||||||
|
"toc_vehicleTransferCount": (*QueryServiceLogic).ProcessTocVehicleTransferCountLogic,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
||||||
@@ -852,6 +858,178 @@ func (l *QueryServiceLogic) ProcessTocPersonVehicleVerificationLogic(req *types.
|
|||||||
return &types.QueryServiceResp{Id: cacheNo}, nil
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessTocVehicleInsuranceSummaryLogic 车辆出险信息
|
||||||
|
func (l *QueryServiceLogic) ProcessTocVehicleInsuranceSummaryLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AES解密
|
||||||
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||||
|
if DecryptDataErr != nil {
|
||||||
|
return nil, DecryptDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验参数
|
||||||
|
var data types.TocCarVin
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"vin_code": data.VinCode,
|
||||||
|
}
|
||||||
|
cacheNo, cacheDataErr := l.CacheData(params, "toc_vehicleInsuranceSummary", userID)
|
||||||
|
if cacheDataErr != nil {
|
||||||
|
return nil, cacheDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessTocVehicleMaintenanceRecordLogic 车辆维保记录
|
||||||
|
func (l *QueryServiceLogic) ProcessTocVehicleMaintenanceRecordLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AES解密
|
||||||
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||||
|
if DecryptDataErr != nil {
|
||||||
|
return nil, DecryptDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验参数
|
||||||
|
var data types.TocCarVinDrivingPermit
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"vin_code": data.VinCode,
|
||||||
|
"car_driving_permit": data.CarDrivingPermit,
|
||||||
|
}
|
||||||
|
cacheNo, cacheDataErr := l.CacheData(params, "toc_vehicleMaintenanceRecord", userID)
|
||||||
|
if cacheDataErr != nil {
|
||||||
|
return nil, cacheDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessTocVehicleValuationLogic 车辆估值
|
||||||
|
func (l *QueryServiceLogic) ProcessTocVehicleValuationLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AES解密
|
||||||
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||||
|
if DecryptDataErr != nil {
|
||||||
|
return nil, DecryptDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验参数
|
||||||
|
var data types.TocCarVinLicense
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"vin_code": data.VinCode,
|
||||||
|
"car_license": data.CarLicense,
|
||||||
|
}
|
||||||
|
cacheNo, cacheDataErr := l.CacheData(params, "toc_vehicleValuation", userID)
|
||||||
|
if cacheDataErr != nil {
|
||||||
|
return nil, cacheDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessTocChassisNumberCheckLogic 车架号查车
|
||||||
|
func (l *QueryServiceLogic) ProcessTocChassisNumberCheckLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AES解密
|
||||||
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||||
|
if DecryptDataErr != nil {
|
||||||
|
return nil, DecryptDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验参数
|
||||||
|
var data types.TocCarVin
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"vin_code": data.VinCode,
|
||||||
|
}
|
||||||
|
cacheNo, cacheDataErr := l.CacheData(params, "toc_chassisNumberCheck", userID)
|
||||||
|
if cacheDataErr != nil {
|
||||||
|
return nil, cacheDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessTocVehicleTransferCountLogic 车辆过户次数查询
|
||||||
|
func (l *QueryServiceLogic) ProcessTocVehicleTransferCountLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AES解密
|
||||||
|
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||||
|
if DecryptDataErr != nil {
|
||||||
|
return nil, DecryptDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验参数
|
||||||
|
var data types.TocCarVin
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"vin_code": data.VinCode,
|
||||||
|
}
|
||||||
|
cacheNo, cacheDataErr := l.CacheData(params, "toc_vehicleTransferCount", userID)
|
||||||
|
if cacheDataErr != nil {
|
||||||
|
return nil, cacheDataErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessTocBankCardBlacklistLogic 银行卡黑名单
|
// ProcessTocBankCardBlacklistLogic 银行卡黑名单
|
||||||
func (l *QueryServiceLogic) ProcessTocBankCardBlacklistLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
func (l *QueryServiceLogic) ProcessTocBankCardBlacklistLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
|||||||
@@ -2,9 +2,19 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"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"
|
||||||
|
jwtx "qnc-server/common/jwt"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@@ -24,7 +34,117 @@ func NewWxMiniAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WxMini
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *WxMiniAuthLogic) WxMiniAuth(req *types.WXMiniAuthReq) (resp *types.WXMiniAuthResp, err error) {
|
func (l *WxMiniAuthLogic) WxMiniAuth(req *types.WXMiniAuthReq) (resp *types.WXMiniAuthResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// 1. 使用微信提供的 code 换取 session_key 和 openid
|
||||||
|
weChatResponse, err := l.exchangeCodeForSession(req.Code)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("微信登录失败"), "微信登录, code 换取 session 失败: %s, err: %+v", req.Code, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 根据 openid 查找用户
|
||||||
|
userAuth, findErr := l.svcCtx.UserAuthModel.FindOneByAuthTypeAuthKey(l.ctx, model.UserAuthTypeWxMini, weChatResponse.OpenId)
|
||||||
|
if findErr != nil && findErr != model.ErrNotFound {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "微信登录, 读取用户认证信息失败, openid: %s, err: %+v", weChatResponse.OpenId, findErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
var user *model.User
|
||||||
|
if findErr == model.ErrNotFound {
|
||||||
|
// 用户不存在,创建新用户
|
||||||
|
user = &model.User{}
|
||||||
|
|
||||||
|
if transErr := l.svcCtx.UserModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
// 插入新用户
|
||||||
|
insertResult, userInsertErr := l.svcCtx.UserModel.Insert(ctx, session, user)
|
||||||
|
if userInsertErr != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "微信登录, 数据库插入新用户失败, openid: %s, err: %+v", weChatResponse.OpenId, userInsertErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取新用户的 ID
|
||||||
|
lastId, lastInsertIdErr := insertResult.LastInsertId()
|
||||||
|
if lastInsertIdErr != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "微信登录, 获取新用户ID失败, err:%+v, user:%+v", lastInsertIdErr, user)
|
||||||
|
}
|
||||||
|
user.Id = lastId
|
||||||
|
|
||||||
|
// 创建用户认证信息
|
||||||
|
newUserAuth := &model.UserAuth{
|
||||||
|
UserId: lastId,
|
||||||
|
AuthKey: weChatResponse.OpenId,
|
||||||
|
AuthType: model.UserAuthTypeWxMini,
|
||||||
|
}
|
||||||
|
if _, userAuthInsertErr := l.svcCtx.UserAuthModel.Insert(ctx, session, newUserAuth); userAuthInsertErr != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "微信登录, 数据库插入用户认证信息失败, err:%+v", userAuthInsertErr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); transErr != nil {
|
||||||
|
return nil, transErr
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 获取用户信息
|
||||||
|
user, err = l.svcCtx.UserModel.FindOne(l.ctx, userAuth.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "微信登录, 读取用户信息失败, userId: %d, err: %+v", userAuth.UserId, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 生成 JWT 令牌
|
||||||
|
token, generateErr := jwtx.GenerateJwtToken(user.Id, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire)
|
||||||
|
if generateErr != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "微信登录, 生成token失败 : %d", user.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 获取当前时间戳
|
||||||
|
now := time.Now().Unix()
|
||||||
|
|
||||||
|
return &types.WXMiniAuthResp{
|
||||||
|
AccessToken: token,
|
||||||
|
AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire,
|
||||||
|
RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type WxLoginResp struct {
|
||||||
|
OpenId string `json:"openid"`
|
||||||
|
SessionKey string `json:"session_key"`
|
||||||
|
Unionid string `json:"unionid"`
|
||||||
|
ErrCode int `json:"errcode"`
|
||||||
|
ErrMsg string `json:"errmsg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *WxMiniAuthLogic) exchangeCodeForSession(code string) (response WxLoginResp, err error) {
|
||||||
|
|
||||||
|
// 向微信发出登录请求
|
||||||
|
baseURL := "https://api.weixin.qq.com/sns/jscode2session"
|
||||||
|
// 创建查询参数
|
||||||
|
params := url.Values{}
|
||||||
|
params.Add("appid", l.svcCtx.Config.Wxpay.AppID)
|
||||||
|
params.Add("secret", l.svcCtx.Config.Wxpay.AppSecret)
|
||||||
|
params.Add("js_code", code)
|
||||||
|
params.Add("grant_type", "authorization_code")
|
||||||
|
|
||||||
|
// 构建完整的请求 URL
|
||||||
|
requestURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())
|
||||||
|
|
||||||
|
// 发送 GET 请求
|
||||||
|
resp, err := http.Get(requestURL)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// 读取响应体
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 将响应体解析为结构体
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.ErrCode != 0 {
|
||||||
|
err = errors.New(response.ErrMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"qnc-server/app/user/cmd/api/internal/svc"
|
"qnc-server/app/user/cmd/api/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const TASKTIME = "32 * * * *"
|
const TASKTIME = "0 2 * * *"
|
||||||
|
|
||||||
type CleanQueryDataHandler struct {
|
type CleanQueryDataHandler struct {
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
@@ -20,6 +20,30 @@ func NewCleanQueryDataHandler(svcCtx *svc.ServiceContext) *CleanQueryDataHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *CleanQueryDataHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
func (l *CleanQueryDataHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
||||||
fmt.Println("企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅企鹅-ProcessTask")
|
fmt.Println(TASKTIME)
|
||||||
|
//// 计算 30 天前的时间
|
||||||
|
//threshold := time.Now().AddDate(0, 0, -30)
|
||||||
|
//
|
||||||
|
//// 1. 构造查询条件,查找创建时间小于 threshold 的记录
|
||||||
|
//// 假设表中“创建时间”字段为 create_time,且字段类型对应数据库里实际的列名
|
||||||
|
//rowBuilder := l.svcCtx.QueryModel.SelectBuilder().
|
||||||
|
// Where(squirrel.Lt{"create_time": threshold})
|
||||||
|
//
|
||||||
|
//// 2. 调用 FindAll 获取所有符合条件的记录
|
||||||
|
//// orderBy 这里可传空字符串或你想要的排序字段
|
||||||
|
//records, err := l.svcCtx.QueryModel.FindAll(ctx, rowBuilder, "")
|
||||||
|
//if err != nil {
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//// 3. 遍历记录,逐条删除
|
||||||
|
//// 假设你的 Delete 方法签名是:Delete(ctx context.Context, id int64) error
|
||||||
|
//// 并且 records[i] 中有一个字段 ID 用于表示主键
|
||||||
|
//for _, record := range records {
|
||||||
|
// if err := l.svcCtx.QueryModel.Delete(ctx, record.Id); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func NewApiRequestService(c config.Config, westDexService *WestDexService, yusha
|
|||||||
type APIResponseData struct {
|
type APIResponseData struct {
|
||||||
ApiID string `json:"apiID"`
|
ApiID string `json:"apiID"`
|
||||||
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
|
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
|
||||||
|
Sort int64 `json:"sort"`
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
@@ -59,8 +60,12 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
|||||||
return nil, findProductFeatureErr
|
return nil, findProductFeatureErr
|
||||||
}
|
}
|
||||||
var featureIDs []int64
|
var featureIDs []int64
|
||||||
|
isImportantMap := make(map[int64]int64, len(productFeatureList))
|
||||||
|
sortMap := make(map[int64]int64, len(productFeatureList)) // 新增
|
||||||
for _, pf := range productFeatureList {
|
for _, pf := range productFeatureList {
|
||||||
featureIDs = append(featureIDs, pf.FeatureId)
|
featureIDs = append(featureIDs, pf.FeatureId)
|
||||||
|
isImportantMap[pf.FeatureId] = pf.IsImportant
|
||||||
|
sortMap[pf.FeatureId] = pf.Sort // 新增
|
||||||
}
|
}
|
||||||
if len(featureIDs) == 0 {
|
if len(featureIDs) == 0 {
|
||||||
return nil, errors.New("featureIDs 是空的")
|
return nil, errors.New("featureIDs 是空的")
|
||||||
@@ -78,7 +83,8 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
|||||||
resultsCh = make(chan APIResponseData, len(featureList))
|
resultsCh = make(chan APIResponseData, len(featureList))
|
||||||
errorsCh = make(chan error, len(featureList))
|
errorsCh = make(chan error, len(featureList))
|
||||||
errorCount int32
|
errorCount int32
|
||||||
errorLimit = 1
|
errorLimit = len(featureList)
|
||||||
|
retryNum = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, feature := range featureList {
|
for i, feature := range featureList {
|
||||||
@@ -94,10 +100,28 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
|||||||
result := APIResponseData{
|
result := APIResponseData{
|
||||||
ApiID: feature.ApiId,
|
ApiID: feature.ApiId,
|
||||||
Success: false,
|
Success: false,
|
||||||
|
Sort: sortMap[feature.Id],
|
||||||
}
|
}
|
||||||
// 请求参数预处理
|
|
||||||
resp, preprocessErr := a.PreprocessRequestApi(params, feature.ApiId)
|
|
||||||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
var (
|
||||||
|
resp json.RawMessage
|
||||||
|
preprocessErr error
|
||||||
|
)
|
||||||
|
// 若 isImportantMap[feature.ID] == 1,则表示需要在出错时重试
|
||||||
|
isImportant := isImportantMap[feature.Id] == 1
|
||||||
|
tryCount := 0
|
||||||
|
for {
|
||||||
|
tryCount++
|
||||||
|
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
|
||||||
|
if preprocessErr == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if isImportant && tryCount < retryNum {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if preprocessErr != nil {
|
if preprocessErr != nil {
|
||||||
result.Timestamp = timestamp
|
result.Timestamp = timestamp
|
||||||
result.Error = preprocessErr.Error()
|
result.Error = preprocessErr.Error()
|
||||||
@@ -166,6 +190,11 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
|||||||
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
||||||
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
||||||
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
||||||
|
"CAR074": (*ApiRequestService).ProcessCAR074Request,
|
||||||
|
"CAR058": (*ApiRequestService).ProcessCAR058Request,
|
||||||
|
"CAR079": (*ApiRequestService).ProcessCAR079Request,
|
||||||
|
"CAR066": (*ApiRequestService).ProcessCAR066Request,
|
||||||
|
"CAR100": (*ApiRequestService).ProcessCAR100Request,
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreprocessRequestApi 调用指定的请求处理函数
|
// PreprocessRequestApi 调用指定的请求处理函数
|
||||||
@@ -710,6 +739,97 @@ func (a *ApiRequestService) ProcessP_C_B332Request(params []byte) ([]byte, error
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 车辆出险信息
|
||||||
|
func (a *ApiRequestService) ProcessCAR074Request(params []byte) ([]byte, error) {
|
||||||
|
vinCode := gjson.GetBytes(params, "vin_code")
|
||||||
|
if !vinCode.Exists() {
|
||||||
|
return nil, errors.New("api请求, CAR074, 获取相关参数失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := map[string]interface{}{
|
||||||
|
"vin": vinCode.String(),
|
||||||
|
}
|
||||||
|
resp, err := a.yushanService.request("CAR074", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 车辆维保记录
|
||||||
|
func (a *ApiRequestService) ProcessCAR058Request(params []byte) ([]byte, error) {
|
||||||
|
vinCode := gjson.GetBytes(params, "vin_code")
|
||||||
|
carType := gjson.GetBytes(params, "car_driving_permit")
|
||||||
|
if !vinCode.Exists() || !carType.Exists() {
|
||||||
|
return nil, errors.New("api请求, CAR058, 获取相关参数失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := map[string]interface{}{
|
||||||
|
"vin": vinCode,
|
||||||
|
"image": carType,
|
||||||
|
"notifyUrl": "",
|
||||||
|
}
|
||||||
|
resp, err := a.yushanService.request("CAR058", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 车架号查车
|
||||||
|
func (a *ApiRequestService) ProcessCAR079Request(params []byte) ([]byte, error) {
|
||||||
|
vinCode := gjson.GetBytes(params, "vin_code")
|
||||||
|
if !vinCode.Exists() {
|
||||||
|
return nil, errors.New("api请求, CAR079, 获取相关参数失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := map[string]interface{}{
|
||||||
|
"vin": vinCode.String(),
|
||||||
|
}
|
||||||
|
resp, err := a.yushanService.request("CAR079", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("车架号查车查询失败: %+v", err)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 车辆过户次数
|
||||||
|
func (a *ApiRequestService) ProcessCAR066Request(params []byte) ([]byte, error) {
|
||||||
|
vinCode := gjson.GetBytes(params, "vin_code")
|
||||||
|
if !vinCode.Exists() {
|
||||||
|
return nil, errors.New("api请求, CAR066, 获取相关参数失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := map[string]interface{}{
|
||||||
|
"vin": vinCode.String(),
|
||||||
|
}
|
||||||
|
resp, err := a.yushanService.request("CAR066", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("车辆过户次数查询失败: %+v", err)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 车辆估值
|
||||||
|
func (a *ApiRequestService) ProcessCAR100Request(params []byte) ([]byte, error) {
|
||||||
|
vinCode := gjson.GetBytes(params, "vin_code")
|
||||||
|
carLicense := gjson.GetBytes(params, "car_license")
|
||||||
|
if !vinCode.Exists() || !carLicense.Exists() {
|
||||||
|
return nil, errors.New("api请求, CAR100, 获取相关参数失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := map[string]interface{}{
|
||||||
|
"vin": vinCode.String(),
|
||||||
|
"carNumber": carLicense.String(),
|
||||||
|
"cardNo": "",
|
||||||
|
}
|
||||||
|
resp, err := a.yushanService.request("CAR100", request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("车辆估值查询失败: %+v", err)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 银行卡黑名单
|
// 银行卡黑名单
|
||||||
func (a *ApiRequestService) ProcessFIN019Request(params []byte) ([]byte, error) {
|
func (a *ApiRequestService) ProcessFIN019Request(params []byte) ([]byte, error) {
|
||||||
name := gjson.GetBytes(params, "name")
|
name := gjson.GetBytes(params, "name")
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"net/http"
|
"net/http"
|
||||||
"qnc-server/app/user/cmd/api/internal/config"
|
"qnc-server/app/user/cmd/api/internal/config"
|
||||||
|
"qnc-server/app/user/model"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
"qnc-server/pkg/lzkit/lzUtils"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -35,10 +37,11 @@ type WechatPayService struct {
|
|||||||
config config.WxpayConfig
|
config config.WxpayConfig
|
||||||
wechatClient *core.Client
|
wechatClient *core.Client
|
||||||
notifyHandler *notify.Handler
|
notifyHandler *notify.Handler
|
||||||
|
userAuthModel model.UserAuthModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWechatPayService 初始化微信支付服务
|
// NewWechatPayService 初始化微信支付服务
|
||||||
func NewWechatPayService(c config.Config) *WechatPayService {
|
func NewWechatPayService(c config.Config, userAuthModel model.UserAuthModel) *WechatPayService {
|
||||||
// 从配置中加载商户信息
|
// 从配置中加载商户信息
|
||||||
mchID := c.Wxpay.MchID
|
mchID := c.Wxpay.MchID
|
||||||
mchCertificateSerialNumber := c.Wxpay.MchCertificateSerialNumber
|
mchCertificateSerialNumber := c.Wxpay.MchCertificateSerialNumber
|
||||||
@@ -71,6 +74,7 @@ func NewWechatPayService(c config.Config) *WechatPayService {
|
|||||||
config: c.Wxpay,
|
config: c.Wxpay,
|
||||||
wechatClient: client,
|
wechatClient: client,
|
||||||
notifyHandler: notifyHandler,
|
notifyHandler: notifyHandler,
|
||||||
|
userAuthModel: userAuthModel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +108,7 @@ func (w *WechatPayService) CreateWechatAppOrder(ctx context.Context, amount floa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateWechatMiniProgramOrder 创建微信小程序支付订单
|
// CreateWechatMiniProgramOrder 创建微信小程序支付订单
|
||||||
func (w *WechatPayService) CreateWechatMiniProgramOrder(ctx context.Context, amount float64, description string, outTradeNo string, openid string) (string, error) {
|
func (w *WechatPayService) CreateWechatMiniProgramOrder(ctx context.Context, amount float64, description string, outTradeNo string, openid string) (interface{}, error) {
|
||||||
totalAmount := lzUtils.ToWechatAmount(amount)
|
totalAmount := lzUtils.ToWechatAmount(amount)
|
||||||
|
|
||||||
// 构建支付请求参数
|
// 构建支付请求参数
|
||||||
@@ -131,24 +135,32 @@ func (w *WechatPayService) CreateWechatMiniProgramOrder(ctx context.Context, amo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 返回预支付交易会话标识
|
// 返回预支付交易会话标识
|
||||||
return *resp.PrepayId, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateWechatOrder 创建微信支付订单(集成 APP、H5、小程序)
|
// CreateWechatOrder 创建微信支付订单(集成 APP、H5、小程序)
|
||||||
func (w *WechatPayService) CreateWechatOrder(ctx context.Context, amount float64, description string, outTradeNo string) (string, error) {
|
func (w *WechatPayService) CreateWechatOrder(ctx context.Context, amount float64, description string, outTradeNo string) (interface{}, error) {
|
||||||
// 根据 ctx 中的 platform 判断平台
|
// 根据 ctx 中的 platform 判断平台
|
||||||
platform := ctx.Value("platform").(string)
|
platform := ctx.Value("platform").(string)
|
||||||
|
|
||||||
var prepayId string
|
var prepayData interface{}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch platform {
|
switch platform {
|
||||||
case "mp-weixin":
|
case "mp-weixin":
|
||||||
|
userID, getUidErr := ctxdata.GetUidFromCtx(ctx)
|
||||||
|
if getUidErr != nil {
|
||||||
|
return "", fmt.Errorf("获取用户信息失败: %s", getUidErr)
|
||||||
|
}
|
||||||
|
userAuthModel, findUserAuthErr := w.userAuthModel.FindOneByUserIdAuthType(ctx, userID, "wx_mini")
|
||||||
|
if findUserAuthErr != nil {
|
||||||
|
return "", fmt.Errorf("获取用户认证信息失败: %s", findUserAuthErr)
|
||||||
|
}
|
||||||
// 如果是小程序平台,调用小程序支付订单创建
|
// 如果是小程序平台,调用小程序支付订单创建
|
||||||
prepayId, err = w.CreateWechatMiniProgramOrder(ctx, amount, description, outTradeNo, "asdasd")
|
prepayData, err = w.CreateWechatMiniProgramOrder(ctx, amount, description, outTradeNo, userAuthModel.AuthKey)
|
||||||
case "app":
|
case "app":
|
||||||
// 如果是 APP 平台,调用 APP 支付订单创建
|
// 如果是 APP 平台,调用 APP 支付订单创建
|
||||||
prepayId, err = w.CreateWechatAppOrder(ctx, amount, description, outTradeNo)
|
prepayData, err = w.CreateWechatAppOrder(ctx, amount, description, outTradeNo)
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("不支持的支付平台: %s", platform)
|
return "", fmt.Errorf("不支持的支付平台: %s", platform)
|
||||||
}
|
}
|
||||||
@@ -159,7 +171,7 @@ func (w *WechatPayService) CreateWechatOrder(ctx context.Context, amount float64
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 返回预支付ID
|
// 返回预支付ID
|
||||||
return prepayId, nil
|
return prepayData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleWechatPayNotification 处理微信支付回调
|
// HandleWechatPayNotification 处理微信支付回调
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type ServiceContext struct {
|
|||||||
ProductModel model.ProductModel
|
ProductModel model.ProductModel
|
||||||
FeatureModel model.FeatureModel
|
FeatureModel model.FeatureModel
|
||||||
ProductFeatureModel model.ProductFeatureModel
|
ProductFeatureModel model.ProductFeatureModel
|
||||||
|
ProductRenderModel model.ProductRenderModel
|
||||||
OrderModel model.OrderModel
|
OrderModel model.OrderModel
|
||||||
QueryModel model.QueryModel
|
QueryModel model.QueryModel
|
||||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||||
@@ -56,12 +57,13 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
yushanService := service.NewYushanService(c)
|
yushanService := service.NewYushanService(c)
|
||||||
productFeatureModel := model.NewProductFeatureModel(db, c.CacheRedis)
|
productFeatureModel := model.NewProductFeatureModel(db, c.CacheRedis)
|
||||||
featureModel := model.NewFeatureModel(db, c.CacheRedis)
|
featureModel := model.NewFeatureModel(db, c.CacheRedis)
|
||||||
|
userAuthModel := model.NewUserAuthModel(db, c.CacheRedis)
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
Redis: redis.MustNewRedis(redisConf),
|
Redis: redis.MustNewRedis(redisConf),
|
||||||
SourceInterceptor: middleware.NewSourceInterceptorMiddleware().Handle,
|
SourceInterceptor: middleware.NewSourceInterceptorMiddleware().Handle,
|
||||||
AlipayService: service.NewAliPayService(c),
|
AlipayService: service.NewAliPayService(c),
|
||||||
WechatPayService: service.NewWechatPayService(c),
|
WechatPayService: service.NewWechatPayService(c, userAuthModel),
|
||||||
ApplePayService: service.NewApplePayService(c),
|
ApplePayService: service.NewApplePayService(c),
|
||||||
WestDexService: westDexService,
|
WestDexService: westDexService,
|
||||||
YushanService: yushanService,
|
YushanService: yushanService,
|
||||||
@@ -70,8 +72,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel),
|
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel),
|
||||||
AsynqService: service.NewAsynqService(c),
|
AsynqService: service.NewAsynqService(c),
|
||||||
UserModel: model.NewUserModel(db, c.CacheRedis),
|
UserModel: model.NewUserModel(db, c.CacheRedis),
|
||||||
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
|
UserAuthModel: userAuthModel,
|
||||||
ProductModel: model.NewProductModel(db, c.CacheRedis),
|
ProductModel: model.NewProductModel(db, c.CacheRedis),
|
||||||
|
ProductRenderModel: model.NewProductRenderModel(db, c.CacheRedis),
|
||||||
OrderModel: model.NewOrderModel(db, c.CacheRedis),
|
OrderModel: model.NewOrderModel(db, c.CacheRedis),
|
||||||
QueryModel: model.NewQueryModel(db, c.CacheRedis),
|
QueryModel: model.NewQueryModel(db, c.CacheRedis),
|
||||||
GlobalNotificationsModel: model.NewGlobalNotificationsModel(db, c.CacheRedis),
|
GlobalNotificationsModel: model.NewGlobalNotificationsModel(db, c.CacheRedis),
|
||||||
|
|||||||
@@ -82,6 +82,17 @@ type TocPersonVehicleVerification struct {
|
|||||||
CarType string `json:"car_type" validate:"required"`
|
CarType string `json:"car_type" validate:"required"`
|
||||||
CarLicense string `json:"car_license" validate:"required"`
|
CarLicense string `json:"car_license" validate:"required"`
|
||||||
}
|
}
|
||||||
|
type TocCarVin struct {
|
||||||
|
VinCode string `json:"vin_code" validate:"required"`
|
||||||
|
}
|
||||||
|
type TocCarVinDrivingPermit struct {
|
||||||
|
VinCode string `json:"vin_code" validate:"required"`
|
||||||
|
CarDrivingPermit string `json:"car_drivingPermit" validate:"required"`
|
||||||
|
}
|
||||||
|
type TocCarVinLicense struct {
|
||||||
|
VinCode string `json:"vin_code" validate:"required"`
|
||||||
|
CarLicense string `json:"car_license" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// 银行卡黑名单
|
// 银行卡黑名单
|
||||||
type TocBankCardBlacklist struct {
|
type TocBankCardBlacklist struct {
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ type GetProductByIDRequest struct {
|
|||||||
Id int64 `path:"id"`
|
Id int64 `path:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetProductRenderListRequest struct {
|
||||||
|
Module string `path:"module"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetProductRenderListResponse struct {
|
||||||
|
Product []Product
|
||||||
|
}
|
||||||
|
|
||||||
type IapCallbackReq struct {
|
type IapCallbackReq struct {
|
||||||
OrderID int64 `json:"order_id" validate:"required"`
|
OrderID int64 `json:"order_id" validate:"required"`
|
||||||
TransactionReceipt string `json:"transaction_receipt" validate:"required"`
|
TransactionReceipt string `json:"transaction_receipt" validate:"required"`
|
||||||
@@ -63,7 +71,7 @@ type PaymentReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PaymentResp struct {
|
type PaymentResp struct {
|
||||||
PrepayID string `json:"prepay_id"`
|
PrepayData interface{} `json:"prepay_data"`
|
||||||
OrderID int64 `json:"order_id"`
|
OrderID int64 `json:"order_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +147,7 @@ type QueryProvisionalOrderReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueryProvisionalOrderResp struct {
|
type QueryProvisionalOrderResp struct {
|
||||||
Name string `json:"name"`
|
QueryParams map[string]interface{} `json:"query_params"`
|
||||||
IdCard string `json:"id_card"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
Product Product `json:"product"`
|
Product Product `json:"product"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,8 +209,6 @@ type WXH5AuthResp struct {
|
|||||||
|
|
||||||
type WXMiniAuthReq struct {
|
type WXMiniAuthReq struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
IV string `json:"iv"`
|
|
||||||
EncryptedData string `json:"encryptedData"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WXMiniAuthResp struct {
|
type WXMiniAuthResp struct {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ var (
|
|||||||
|
|
||||||
cacheQncProductFeatureIdPrefix = "cache:qnc:productFeature:id:"
|
cacheQncProductFeatureIdPrefix = "cache:qnc:productFeature:id:"
|
||||||
cacheQncProductFeatureProductIdFeatureIdPrefix = "cache:qnc:productFeature:productId:featureId:"
|
cacheQncProductFeatureProductIdFeatureIdPrefix = "cache:qnc:productFeature:productId:featureId:"
|
||||||
|
cacheQncProductFeatureProductIdSortPrefix = "cache:qnc:productFeature:productId:sort:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -36,6 +37,7 @@ type (
|
|||||||
Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||||
FindOne(ctx context.Context, id int64) (*ProductFeature, error)
|
FindOne(ctx context.Context, id int64) (*ProductFeature, error)
|
||||||
FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error)
|
FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error)
|
||||||
|
FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error)
|
||||||
Update(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
Update(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductFeature) error
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductFeature) error
|
||||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
@@ -65,6 +67,8 @@ type (
|
|||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
Version int64 `db:"version"` // 版本号
|
Version int64 `db:"version"` // 版本号
|
||||||
|
Sort int64 `db:"sort"` // 排序字段
|
||||||
|
IsImportant int64 `db:"is_important"` // 是否重要,1为重要,0为不重要
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,13 +83,14 @@ func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Se
|
|||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
|
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?)", m.table, productFeatureRowsExpectAutoSet)
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?, ?)", m.table, productFeatureRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version)
|
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version)
|
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
||||||
@@ -125,6 +130,26 @@ func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductFeatureModel) FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error) {
|
||||||
|
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, productId, sort)
|
||||||
|
var resp ProductFeature
|
||||||
|
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdSortKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_id` = ? AND `sort` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||||
|
if err := conn.QueryRowCtx(ctx, &resp, query, productId, sort, globalkey.DelStateNo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp.Id, nil
|
||||||
|
}, m.queryPrimary)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, model.ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Session, newData *ProductFeature) (sql.Result, error) {
|
func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Session, newData *ProductFeature) (sql.Result, error) {
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
data, err := m.FindOne(ctx, newData.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -132,13 +157,14 @@ func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Se
|
|||||||
}
|
}
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
|
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, productFeatureRowsWithPlaceHolder)
|
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, productFeatureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
||||||
@@ -155,13 +181,14 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
|||||||
}
|
}
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
|
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ? AND version = ? ", m.table, productFeatureRowsWithPlaceHolder)
|
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ? AND version = ? ", m.table, productFeatureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -386,13 +413,14 @@ func (m *defaultProductFeatureModel) Delete(ctx context.Context, session sqlx.Se
|
|||||||
|
|
||||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
||||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||||
|
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("DELETE FROM %s WHERE `id` = ?", m.table)
|
query := fmt.Sprintf("DELETE FROM %s WHERE `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
||||||
|
|||||||
27
app/user/model/productRenderModel.go
Normal file
27
app/user/model/productRenderModel.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ ProductRenderModel = (*customProductRenderModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// ProductRenderModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customProductRenderModel.
|
||||||
|
ProductRenderModel interface {
|
||||||
|
productRenderModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customProductRenderModel struct {
|
||||||
|
*defaultProductRenderModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewProductRenderModel returns a model for the database table.
|
||||||
|
func NewProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) ProductRenderModel {
|
||||||
|
return &customProductRenderModel{
|
||||||
|
defaultProductRenderModel: newProductRenderModel(conn, c),
|
||||||
|
}
|
||||||
|
}
|
||||||
409
app/user/model/productRenderModel_gen.go
Normal file
409
app/user/model/productRenderModel_gen.go
Normal file
@@ -0,0 +1,409 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
productRenderFieldNames = builder.RawFieldNames(&ProductRender{})
|
||||||
|
productRenderRows = strings.Join(productRenderFieldNames, ",")
|
||||||
|
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
|
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncProductRenderIdPrefix = "cache:qnc:productRender:id:"
|
||||||
|
cacheQncProductRenderPlatformModuleProductIdPrefix = "cache:qnc:productRender:platform:module:productId:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
productRenderModel interface {
|
||||||
|
Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*ProductRender, error)
|
||||||
|
FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error)
|
||||||
|
Update(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error)
|
||||||
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductRender) error
|
||||||
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
|
SelectBuilder() squirrel.SelectBuilder
|
||||||
|
DeleteSoft(ctx context.Context, session sqlx.Session, data *ProductRender) error
|
||||||
|
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||||
|
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||||
|
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*ProductRender, error)
|
||||||
|
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, error)
|
||||||
|
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, int64, error)
|
||||||
|
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ProductRender, error)
|
||||||
|
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ProductRender, error)
|
||||||
|
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultProductRenderModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
ProductRender struct {
|
||||||
|
Id int64 `db:"id"` // 主键ID
|
||||||
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||||
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
|
Version int64 `db:"version"` // 版本号
|
||||||
|
Platform string `db:"platform"` // 平台名称
|
||||||
|
Module string `db:"module"` // 模块名称
|
||||||
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
|
IsRendered int64 `db:"is_rendered"` // 是否渲染(1是,0否)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProductRenderModel {
|
||||||
|
return &defaultProductRenderModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c),
|
||||||
|
table: "`product_render`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
||||||
|
data.DelState = globalkey.DelStateNo
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, productRenderRowsExpectAutoSet)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||||
|
var resp ProductRender
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
|
})
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||||
|
var resp ProductRender
|
||||||
|
err := m.QueryRowIndexCtx(ctx, &resp, qncProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp.Id, nil
|
||||||
|
}, m.queryPrimary)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Update(ctx context.Context, session sqlx.Session, newData *ProductRender) (sql.Result, error) {
|
||||||
|
data, err := m.FindOne(ctx, newData.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRenderRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
||||||
|
|
||||||
|
oldVersion := newData.Version
|
||||||
|
newData.Version += 1
|
||||||
|
|
||||||
|
var sqlResult sql.Result
|
||||||
|
var err error
|
||||||
|
|
||||||
|
data, err := m.FindOne(ctx, newData.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRenderRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateCount, err := sqlResult.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if updateCount == 0 {
|
||||||
|
return ErrNoRowsUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *ProductRender) error {
|
||||||
|
data.DelState = globalkey.DelStateYes
|
||||||
|
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||||
|
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||||
|
return errors.Wrapf(errors.New("delete soft failed "), "ProductRenderModel delete err : %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp float64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("COUNT(" + field + ")")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, int64, error) {
|
||||||
|
|
||||||
|
total, err := m.FindCount(ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, total, nil
|
||||||
|
default:
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if preMinId > 0 {
|
||||||
|
builder = builder.Where(" id < ? ", preMinId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if preMaxId > 0 {
|
||||||
|
builder = builder.Where(" id > ? ", preMaxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||||
|
|
||||||
|
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return fn(ctx, session)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) SelectBuilder() squirrel.SelectBuilder {
|
||||||
|
return squirrel.Select().From(m.table)
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
|
data, err := m.FindOne(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, id)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, primary)
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
||||||
27
deploy/script/model/productRenderModel.go
Normal file
27
deploy/script/model/productRenderModel.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ ProductRenderModel = (*customProductRenderModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// ProductRenderModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customProductRenderModel.
|
||||||
|
ProductRenderModel interface {
|
||||||
|
productRenderModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customProductRenderModel struct {
|
||||||
|
*defaultProductRenderModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewProductRenderModel returns a model for the database table.
|
||||||
|
func NewProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) ProductRenderModel {
|
||||||
|
return &customProductRenderModel{
|
||||||
|
defaultProductRenderModel: newProductRenderModel(conn, c),
|
||||||
|
}
|
||||||
|
}
|
||||||
409
deploy/script/model/productRenderModel_gen.go
Normal file
409
deploy/script/model/productRenderModel_gen.go
Normal file
@@ -0,0 +1,409 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
productRenderFieldNames = builder.RawFieldNames(&ProductRender{})
|
||||||
|
productRenderRows = strings.Join(productRenderFieldNames, ",")
|
||||||
|
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
|
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncProductRenderIdPrefix = "cache:qnc:productRender:id:"
|
||||||
|
cacheQncProductRenderPlatformModuleProductIdPrefix = "cache:qnc:productRender:platform:module:productId:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
productRenderModel interface {
|
||||||
|
Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*ProductRender, error)
|
||||||
|
FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error)
|
||||||
|
Update(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error)
|
||||||
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductRender) error
|
||||||
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
|
SelectBuilder() squirrel.SelectBuilder
|
||||||
|
DeleteSoft(ctx context.Context, session sqlx.Session, data *ProductRender) error
|
||||||
|
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||||
|
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||||
|
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*ProductRender, error)
|
||||||
|
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, error)
|
||||||
|
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, int64, error)
|
||||||
|
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ProductRender, error)
|
||||||
|
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ProductRender, error)
|
||||||
|
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultProductRenderModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
ProductRender struct {
|
||||||
|
Id int64 `db:"id"` // 主键ID
|
||||||
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||||
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
|
Version int64 `db:"version"` // 版本号
|
||||||
|
Platform string `db:"platform"` // 平台名称
|
||||||
|
Module string `db:"module"` // 模块名称
|
||||||
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
|
IsRendered int64 `db:"is_rendered"` // 是否渲染(1是,0否)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProductRenderModel {
|
||||||
|
return &defaultProductRenderModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c),
|
||||||
|
table: "`product_render`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
||||||
|
data.DelState = globalkey.DelStateNo
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, productRenderRowsExpectAutoSet)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||||
|
var resp ProductRender
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
|
})
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||||
|
var resp ProductRender
|
||||||
|
err := m.QueryRowIndexCtx(ctx, &resp, qncProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp.Id, nil
|
||||||
|
}, m.queryPrimary)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Update(ctx context.Context, session sqlx.Session, newData *ProductRender) (sql.Result, error) {
|
||||||
|
data, err := m.FindOne(ctx, newData.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRenderRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
||||||
|
|
||||||
|
oldVersion := newData.Version
|
||||||
|
newData.Version += 1
|
||||||
|
|
||||||
|
var sqlResult sql.Result
|
||||||
|
var err error
|
||||||
|
|
||||||
|
data, err := m.FindOne(ctx, newData.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRenderRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateCount, err := sqlResult.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if updateCount == 0 {
|
||||||
|
return ErrNoRowsUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *ProductRender) error {
|
||||||
|
data.DelState = globalkey.DelStateYes
|
||||||
|
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||||
|
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||||
|
return errors.Wrapf(errors.New("delete soft failed "), "ProductRenderModel delete err : %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp float64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("COUNT(" + field + ")")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ProductRender, int64, error) {
|
||||||
|
|
||||||
|
total, err := m.FindCount(ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, total, nil
|
||||||
|
default:
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if preMinId > 0 {
|
||||||
|
builder = builder.Where(" id < ? ", preMinId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ProductRender, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(productRenderRows)
|
||||||
|
|
||||||
|
if preMaxId > 0 {
|
||||||
|
builder = builder.Where(" id > ? ", preMaxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*ProductRender
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||||
|
|
||||||
|
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return fn(ctx, session)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) SelectBuilder() squirrel.SelectBuilder {
|
||||||
|
return squirrel.Select().From(m.table)
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
|
data, err := m.FindOne(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||||
|
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||||
|
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, id)
|
||||||
|
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, primary)
|
||||||
|
}
|
||||||
|
func (m *defaultProductRenderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultProductRenderModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user