Merge branch 'main' of http://1.117.67.95:3000/team/hm-server
This commit is contained in:
@@ -61,6 +61,7 @@ type (
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
Disable int64 `json:"disable"` // 封禁状态 0-可用 1-禁用
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
@@ -77,6 +78,7 @@ type (
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
Disable int64 `json:"disable"` // 封禁状态 0-可用 1-禁用
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
@@ -103,6 +105,7 @@ type (
|
||||
Nickname *string `json:"nickname,optional"` // 昵称
|
||||
Info *string `json:"info,optional"` // 备注信息
|
||||
Inside *int64 `json:"inside,optional"` // 是否内部用户 1-是 0-否
|
||||
Disable *int64 `json:"disable,optional"` // 封禁状态 0-可用 1-禁用
|
||||
}
|
||||
|
||||
// 更新响应
|
||||
|
||||
@@ -47,7 +47,7 @@ type (
|
||||
PaymentReq {
|
||||
Id string `json:"id"`
|
||||
PayMethod string `json:"pay_method"`
|
||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip"`
|
||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade"`
|
||||
}
|
||||
PaymentResp {
|
||||
PrepayData interface{} `json:"prepay_data"`
|
||||
|
||||
@@ -41,13 +41,13 @@ Alipay:
|
||||
|
||||
Wxpay:
|
||||
AppID: "wxa581992dc74d860e"
|
||||
MchID: "1682635136"
|
||||
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
||||
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
||||
MchPrivateKeyPath: "etc/merchant/apiclient_key.pem"
|
||||
MchPublicKeyID: "PUB_KEY_ID_0116826351362025060900382267001601"
|
||||
MchPublicKeyPath: "etc/merchant/pub_key.pem"
|
||||
MchPlatformRAS: "1FFEC3F62E31885FAB4C91ADCB8D7557E9488781"
|
||||
MchID: "1687993434"
|
||||
MchCertificateSerialNumber: "241E4BCF5B69AAAC48451DB2C7ED794EF8B3A3D3"
|
||||
MchApiv3Key: "aB3cD5eF7gH9iJ1kL2mN4oP6qR8sT0uV"
|
||||
MchPrivateKeyPath: "etc/merchant/wxpay/1687993434_20260210_cert/apiclient_key.pem"
|
||||
MchPublicKeyID: "PUB_KEY_ID_0116879934342025120200181745004208"
|
||||
MchPublicKeyPath: "etc/merchant/wxpay/1687993434_20260210_cert/pub_key.pem"
|
||||
MchPlatformRAS: "5630D013C88EA348BF66E642B6C39AA0180D4B15"
|
||||
NotifyUrl: "https://6m4685017o.goho.co/api/v1/pay/wechat/callback"
|
||||
RefundNotifyUrl: "https://6m4685017o.goho.co/api/v1/wechat/refund_callback"
|
||||
Applepay:
|
||||
|
||||
@@ -42,13 +42,13 @@ Alipay:
|
||||
ReturnURL: "https://www.tianyuandb.com/payment/result"
|
||||
Wxpay:
|
||||
AppID: "wxa581992dc74d860e"
|
||||
MchID: "1682635136"
|
||||
MchCertificateSerialNumber: "5369B8AEEBDCF7AF274510252E6A8C0659C30F61"
|
||||
MchApiv3Key: "e3ea4cf0765f1e71b01bb387dfcdbc9f"
|
||||
MchPrivateKeyPath: "etc/merchant/apiclient_key.pem"
|
||||
MchPublicKeyID: "PUB_KEY_ID_0116826351362025060900382267001601"
|
||||
MchPublicKeyPath: "etc/merchant/pub_key.pem"
|
||||
MchPlatformRAS: "1FFEC3F62E31885FAB4C91ADCB8D7557E9488781"
|
||||
MchID: "1687993434"
|
||||
MchCertificateSerialNumber: "241E4BCF5B69AAAC48451DB2C7ED794EF8B3A3D3"
|
||||
MchApiv3Key: "aB3cD5eF7gH9iJ1kL2mN4oP6qR8sT0uV"
|
||||
MchPrivateKeyPath: "etc/merchant/wxpay/1687993434_20260210_cert/apiclient_key.pem"
|
||||
MchPublicKeyID: "PUB_KEY_ID_0116879934342025120200181745004208"
|
||||
MchPublicKeyPath: "etc/merchant/wxpay/1687993434_20260210_cert/pub_key.pem"
|
||||
MchPlatformRAS: "5630D013C88EA348BF66E642B6C39AA0180D4B15"
|
||||
NotifyUrl: "https://www.tianyuandb.com/api/v1/pay/wechat/callback"
|
||||
RefundNotifyUrl: "https://www.tianyuandb.com/api/v1/wechat/refund_callback"
|
||||
Applepay:
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAh8YNl16EkVKW
|
||||
IHDiPyx5Zz93osD4n2E7oJXPEOSGpumhsAMjXsRd32JulYDtD/B/phA/mxQiEf84
|
||||
Um4VKC16pNAEtpEyrO7ZZRhrPk2AMck6Jm81nXLoppttuS0B3VkOE/1UuvAbIz1y
|
||||
VliRLDTiIbuSM8p1rMfpsJGo4CoLaerJgzXL6MHZA0+Fhn4PQLkLIt57jC0Jh2Dg
|
||||
ayH7Ru/wgwgq6upXb7rXj0ZzMer5kkA446mLis9P6Nz1GiTUMyUy+tnORK1EpWLg
|
||||
tUifsfXsKBLlUcOrNyG1+TyeMOuY2p592Au8J2eZbwyXKRDvK2oJzsDQW04pGyJc
|
||||
oW1vObmLAgMBAAECggEAPc0XgRNezrULSo99TNK0hv/iepeu09/tSUOh8wbcJHD9
|
||||
u94RE9B+vhdPtGmfKfmc3IzE2HYCP3GBeGXVWks8VgsDjw+/igHC5duyu/IS1Jym
|
||||
mFjwB8jTsuSQLedsEBYqWP+HqSQcoMluFv6qjWcgTpo/aI3hZmahAV2hVBEozeKR
|
||||
Va+EssjI46k894Kr6s9rb9nk8hCORuLuqDXfWJdxT+UixMeYftrgmHXk6CCUb2Ct
|
||||
EjMuxi66KyfVu9w5wS0DuE583mDIgTKmD+deJWxcVyJJMJDCULY4fotWhQb2ro9L
|
||||
qndaCgBC+sOAB/PrO31E40hZhjgdToSq5SvUWgjUCQKBgQD6/zSzEGJYzjS3544l
|
||||
PWF92WT3aFJxT3+Mgd/BrTWaY2LykbDoioM/Kp+5D1bB446k534xO6uwr3LuDCOE
|
||||
jZGy/6+HQeDHSLfDZ+LgWQdEbakbniR57HXG293x3Mp5jTlZOXc8ryGURXaCP8Sy
|
||||
xwIiZPUgpo4xA0Myt/CnjW9OhwKBgQDEXjkc4tyVTsgcVevxBjT4o3g2ihYouCdt
|
||||
ClDr6iZ8Mi5A0vCcuy1A3uI5BZnax11AIwqapgjOdWgWEtyjQJ84bhesyI7km/Ya
|
||||
AeaelsgSf+mAfFgTarWb+KpD5l0jxJAlX/1PAQU6vXuUPdA4PtBbKyUKHLY0kMXr
|
||||
wE4vbPpZ3QKBgQDGvwpFt/WICFAqR0qBJmdqNZgDaDHP03lWEwjQ3YySYZxaIw8I
|
||||
M5XVkLTE3uZ9xOiQn1WHOo6q62KAKFB/h3IVYOzmlz2bz3LjYgF+UEC26HZ9je2o
|
||||
NZrVCghmmcQiF7ePdTd7b9mRBKfgXwor3fVMstB/OCNjoAe3w3rl0dKPRQKBgQC2
|
||||
oIbvdZH/DqkPqV1o6QPk5muMFbrsHfEU+U4vSrKGOUlJIqWCrpY0ydWNgMcJcPcq
|
||||
Ciz3jUmNciXeuaYX8qbiHYnJOTGkLeShZXktrz/d7Lamt35WeJz0tTztL1caR9pj
|
||||
2DVG/8T0T3uacC6x0MGIuMSW9gMDOk3Ipy5P70OaxQKBgQDFzgdJxU9Ra6AzbyBL
|
||||
hcaKb+moNEo+peKCImwY1n3FeRM6XZ59qQaGV1lYu5KPUj9T/SVaJm6DCYFKqM0r
|
||||
T1prq2LeR69nB7Dpsr2TKp57L86DoCqbxOBnWxZ/6Em65hoRYe7CAtn3yFQGKm9T
|
||||
+EdUfn1gf7AWjQAgo3bis3TaMQ==
|
||||
-----END PRIVATE KEY-----
|
||||
@@ -0,0 +1,9 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4el5skKyhhV+lFP/lx2x
|
||||
MIQ14WFzoywBmy7Jd/UnKp5i8g85rwsFKvkMD9QqdQgoUPdnKKpvKiJeQqwUeXUC
|
||||
ogVZxedg+wCj4FuOmctHTJVwWaqZ07uom78nvDJhgRCsgWR7UBRq8v9MymbPC4p7
|
||||
IkGuq+lLkYPyJFMGpk33fAua4NkKxBseyLHbB9t3vSlUFh8x2JlIYxC531362qbS
|
||||
+L2m0B2stMyQEdYxpYCtS3nsEG+ib2Du3GiT+5pAmXxZ6DGyr4jAlAWDnljwJZEf
|
||||
xJPECXSlcAsHdI6ugkC+9DwPjLs1mrEQ/BevmTT2o0wPigCRNi9xZf178L1sptYy
|
||||
DwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -43,6 +43,7 @@ func (l *AdminGetPlatformUserDetailLogic) AdminGetPlatformUserDetail(req *types.
|
||||
Nickname: "",
|
||||
Info: user.Info,
|
||||
Inside: user.Inside,
|
||||
Disable: user.Disable,
|
||||
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
@@ -30,8 +30,14 @@ func NewAdminGetPlatformUserListLogic(ctx context.Context, svcCtx *svc.ServiceCo
|
||||
|
||||
func (l *AdminGetPlatformUserListLogic) AdminGetPlatformUserList(req *types.AdminGetPlatformUserListReq) (resp *types.AdminGetPlatformUserListResp, err error) {
|
||||
builder := l.svcCtx.UserModel.SelectBuilder()
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
if req.Mobile != "" {
|
||||
builder = builder.Where("mobile = ?", req.Mobile)
|
||||
// 数据库存密文,搜索时把明文手机号加密后再查询
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, secretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "手机号加密失败: %v", err)
|
||||
}
|
||||
builder = builder.Where("mobile = ?", encryptedMobile)
|
||||
}
|
||||
if req.Nickname != "" {
|
||||
builder = builder.Where("nickname = ?", req.Nickname)
|
||||
@@ -55,7 +61,6 @@ func (l *AdminGetPlatformUserListLogic) AdminGetPlatformUserList(req *types.Admi
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户分页失败: %v", err)
|
||||
}
|
||||
var items []types.PlatformUserListItem
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
|
||||
for _, user := range users {
|
||||
mobile := user.Mobile
|
||||
@@ -72,6 +77,7 @@ func (l *AdminGetPlatformUserListLogic) AdminGetPlatformUserList(req *types.Admi
|
||||
Nickname: "",
|
||||
Info: user.Info,
|
||||
Inside: user.Inside,
|
||||
Disable: user.Disable,
|
||||
CreateTime: user.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: user.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
@@ -52,6 +52,12 @@ func (l *AdminUpdatePlatformUserLogic) AdminUpdatePlatformUser(req *types.AdminU
|
||||
}
|
||||
user.Inside = *req.Inside
|
||||
}
|
||||
if req.Disable != nil {
|
||||
if *req.Disable != 1 && *req.Disable != 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "封禁状态错误: %d,0-可用 1-禁用", *req.Disable)
|
||||
}
|
||||
user.Disable = *req.Disable
|
||||
}
|
||||
if req.Password != nil {
|
||||
user.Password = sql.NullString{String: *req.Password, Valid: *req.Password != ""}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,10 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "代理申请, 注册用户失败: %+v", err)
|
||||
}
|
||||
} else {
|
||||
// 被封禁用户禁止登录/申请
|
||||
if user.Disable == 1 {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
if claims != nil && claims.UserType == model.UserTypeTemp {
|
||||
// 临时用户,转为正式用户
|
||||
err = l.svcCtx.UserService.TempUserBindUser(l.ctx, session, user.Id)
|
||||
|
||||
@@ -48,7 +48,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
|
||||
l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
switch req.PayType {
|
||||
case "agent_vip":
|
||||
case "agent_vip", "agent_upgrade":
|
||||
paymentTypeResp, err = l.AgentVipOrderPayment(req, session)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -59,6 +59,9 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
err = errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "不支持的支付类型: %s", req.PayType)
|
||||
return err
|
||||
}
|
||||
|
||||
// 开发环境测试支付模式:仅当 pay_method=test 时跳过实际支付,直接返回 test_payment_success
|
||||
|
||||
@@ -64,6 +64,10 @@ func (l *BindMobileLogic) BindMobile(req *types.BindMobileReq) (resp *types.Bind
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "绑定手机号, %v", err)
|
||||
}
|
||||
if user != nil {
|
||||
// 被封禁用户禁止绑定/登录
|
||||
if user.Disable == 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
// 进行平台绑定
|
||||
if claims != nil {
|
||||
if req.Mobile != "18889793585" {
|
||||
|
||||
@@ -33,6 +33,14 @@ func (l *GetTokenLogic) GetToken() (resp *types.MobileCodeLoginResp, err error)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, %v", err)
|
||||
}
|
||||
// 被封禁用户禁止刷新 token
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, claims.UserId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, %v", err)
|
||||
}
|
||||
if user.Disable == 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, claims.UserId, claims.UserType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, %v", err)
|
||||
|
||||
@@ -64,6 +64,10 @@ func (l *MobileCodeLoginLogic) MobileCodeLogin(req *types.MobileCodeLoginReq) (r
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "手机登录, 注册用户失败: %+v", err)
|
||||
}
|
||||
} else {
|
||||
// 被封禁用户禁止登录
|
||||
if user.Disable == 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
userID = user.Id
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
|
||||
@@ -49,7 +49,14 @@ func (l *WxH5AuthLogic) WxH5Auth(req *types.WXH5AuthReq) (resp *types.WXH5AuthRe
|
||||
var userID int64
|
||||
var userType int64
|
||||
if userAuth != nil {
|
||||
// 已存在用户,直接登录
|
||||
// 已存在用户,直接登录(被封禁用户禁止登录)
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userAuth.UserId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户失败: %v", err)
|
||||
}
|
||||
if user.Disable == 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
userID = userAuth.UserId
|
||||
userType = model.UserTypeNormal
|
||||
} else {
|
||||
|
||||
@@ -48,7 +48,14 @@ func (l *WxMiniAuthLogic) WxMiniAuth(req *types.WXMiniAuthReq) (resp *types.WXMi
|
||||
var userID int64
|
||||
var userType int64
|
||||
if userAuth != nil {
|
||||
// 已存在用户,直接登录
|
||||
// 已存在用户,直接登录(被封禁用户禁止登录)
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userAuth.UserId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户失败: %v", err)
|
||||
}
|
||||
if user.Disable == 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_DISABLED), "账号已被封禁")
|
||||
}
|
||||
userID = userAuth.UserId
|
||||
userType = model.UserTypeNormal
|
||||
} else {
|
||||
|
||||
@@ -1,33 +1,60 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tydata-server/app/main/model"
|
||||
"tydata-server/common/ctxdata"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/common/xerr"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 用户封禁状态:0 可用,1 禁用
|
||||
const userDisableStatus = 1
|
||||
|
||||
type UserAuthInterceptorMiddleware struct {
|
||||
UserModel model.UserModel
|
||||
}
|
||||
|
||||
func NewUserAuthInterceptorMiddleware() *UserAuthInterceptorMiddleware {
|
||||
return &UserAuthInterceptorMiddleware{}
|
||||
func NewUserAuthInterceptorMiddleware(userModel model.UserModel) *UserAuthInterceptorMiddleware {
|
||||
return &UserAuthInterceptorMiddleware{UserModel: userModel}
|
||||
}
|
||||
|
||||
func (m *UserAuthInterceptorMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
claims, err := ctxdata.GetClaimsFromCtx(r.Context())
|
||||
if err != nil {
|
||||
httpx.Error(w, errors.Wrapf(xerr.NewErrCode(ErrCodeUnauthorized), "token解析失败: %v", err))
|
||||
m.writeErrorResponse(w, http.StatusUnauthorized, errors.Wrapf(xerr.NewErrCode(ErrCodeUnauthorized), "token解析失败: %v", err))
|
||||
return
|
||||
}
|
||||
if claims.UserType == model.UserTypeTemp {
|
||||
httpx.Error(w, errors.Wrapf(xerr.NewErrCode(xerr.USER_NEED_BIND_MOBILE), "token解析失败: %v", err))
|
||||
m.writeErrorResponse(w, http.StatusUnauthorized, errors.Wrapf(xerr.NewErrCode(xerr.USER_NEED_BIND_MOBILE), "请先绑定手机号"))
|
||||
return
|
||||
}
|
||||
// 封禁校验:用户已被禁用则直接拒绝
|
||||
user, err := m.UserModel.FindOne(r.Context(), claims.UserId)
|
||||
if err != nil {
|
||||
m.writeErrorResponse(w, http.StatusUnauthorized, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败: %v", err))
|
||||
return
|
||||
}
|
||||
if user.Disable == userDisableStatus {
|
||||
m.writeErrorResponse(w, http.StatusForbidden, xerr.NewErrCode(xerr.USER_DISABLED))
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// writeErrorResponse 统一返回 code + msg,便于前端展示提示信息
|
||||
func (m *UserAuthInterceptorMiddleware) writeErrorResponse(w http.ResponseWriter, statusCode int, err error) {
|
||||
errcode := xerr.SERVER_COMMON_ERROR
|
||||
errmsg := xerr.MapErrMsg(errcode)
|
||||
if e, ok := errors.Cause(err).(*xerr.CodeError); ok {
|
||||
errcode = e.GetErrCode()
|
||||
errmsg = e.GetErrMsg()
|
||||
}
|
||||
httpx.WriteJson(w, statusCode, result.Error(errcode, errmsg))
|
||||
}
|
||||
|
||||
@@ -206,8 +206,35 @@ func (w *WechatPayService) CreateWechatMiniProgramOrder(ctx context.Context, amo
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("微信支付订单创建失败: %v, 状态码: %d", err, result.Response.StatusCode)
|
||||
}
|
||||
// 返回预支付交易会话标识
|
||||
return resp, nil
|
||||
// 显式转为 map,确保小程序 uni.requestPayment 能正确解析(避免指针序列化问题)
|
||||
return jsapiRespToMap(resp), nil
|
||||
}
|
||||
|
||||
// jsapiRespToMap 将 PrepayWithRequestPaymentResponse 转为 map,供小程序/JSAPI 调起支付
|
||||
func jsapiRespToMap(resp *jsapi.PrepayWithRequestPaymentResponse) map[string]string {
|
||||
m := make(map[string]string)
|
||||
if resp == nil {
|
||||
return m
|
||||
}
|
||||
if resp.Appid != nil {
|
||||
m["appId"] = *resp.Appid
|
||||
}
|
||||
if resp.TimeStamp != nil {
|
||||
m["timeStamp"] = *resp.TimeStamp
|
||||
}
|
||||
if resp.NonceStr != nil {
|
||||
m["nonceStr"] = *resp.NonceStr
|
||||
}
|
||||
if resp.Package != nil {
|
||||
m["package"] = *resp.Package
|
||||
}
|
||||
if resp.SignType != nil {
|
||||
m["signType"] = *resp.SignType
|
||||
}
|
||||
if resp.PaySign != nil {
|
||||
m["paySign"] = *resp.PaySign
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateWechatH5Order 创建微信H5支付订单
|
||||
@@ -237,8 +264,7 @@ func (w *WechatPayService) CreateWechatH5Order(ctx context.Context, amount float
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("微信支付订单创建失败: %v, 状态码: %d", err, result.Response.StatusCode)
|
||||
}
|
||||
// 返回预支付交易会话标识
|
||||
return resp, nil
|
||||
return jsapiRespToMap(resp), nil
|
||||
}
|
||||
|
||||
// CreateWechatOrder 创建微信支付订单(集成 APP、H5、小程序)
|
||||
|
||||
@@ -223,7 +223,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
Config: c,
|
||||
Redis: redisClient,
|
||||
AuthInterceptor: middleware.NewAuthInterceptorMiddleware(c).Handle,
|
||||
UserAuthInterceptor: middleware.NewUserAuthInterceptorMiddleware().Handle,
|
||||
UserAuthInterceptor: middleware.NewUserAuthInterceptorMiddleware(userModel).Handle,
|
||||
AdminAuthInterceptor: middleware.NewAdminAuthInterceptorMiddleware(c,
|
||||
adminUserModel, adminUserRoleModel, adminRoleModel, adminApiModel, adminRoleApiModel).Handle,
|
||||
|
||||
|
||||
@@ -568,6 +568,7 @@ type AdminGetPlatformUserDetailResp struct {
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
Disable int64 `json:"disable"` // 封禁状态 0-可用 1-禁用
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
@@ -949,6 +950,7 @@ type AdminUpdatePlatformUserReq struct {
|
||||
Nickname *string `json:"nickname,optional"` // 昵称
|
||||
Info *string `json:"info,optional"` // 备注信息
|
||||
Inside *int64 `json:"inside,optional"` // 是否内部用户 1-是 0-否
|
||||
Disable *int64 `json:"disable,optional"` // 封禁状态 0-可用 1-禁用
|
||||
}
|
||||
|
||||
type AdminUpdatePlatformUserResp struct {
|
||||
@@ -1839,7 +1841,7 @@ type PaymentCheckResp struct {
|
||||
type PaymentReq struct {
|
||||
Id string `json:"id"`
|
||||
PayMethod string `json:"pay_method"`
|
||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip"`
|
||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade"`
|
||||
}
|
||||
|
||||
type PaymentResp struct {
|
||||
@@ -1854,6 +1856,7 @@ type PlatformUserListItem struct {
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
Disable int64 `json:"disable"` // 封禁状态 0-可用 1-禁用
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheHmUserIdPrefix = "cache:tydata:user:id:"
|
||||
cacheHmUserMobilePrefix = "cache:tydata:user:mobile:"
|
||||
cacheTydataUserIdPrefix = "cache:tydata:user:id:"
|
||||
cacheTydataUserMobilePrefix = "cache:tydata:user:mobile:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -68,6 +68,7 @@ type (
|
||||
Nickname sql.NullString `db:"nickname"`
|
||||
Info string `db:"info"`
|
||||
Inside int64 `db:"inside"`
|
||||
Disable int64 `db:"disable"` // 0可用 1禁用
|
||||
}
|
||||
)
|
||||
|
||||
@@ -80,21 +81,21 @@ func newUserModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserModel {
|
||||
|
||||
func (m *defaultUserModel) Insert(ctx context.Context, session sqlx.Session, data *User) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
hmUserIdKey := fmt.Sprintf("%s%v", cacheHmUserIdPrefix, data.Id)
|
||||
hmUserMobileKey := fmt.Sprintf("%s%v", cacheHmUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, userRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside, data.Disable)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
}, hmUserIdKey, hmUserMobileKey)
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside, data.Disable)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) {
|
||||
hmUserIdKey := fmt.Sprintf("%s%v", cacheHmUserIdPrefix, id)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, id)
|
||||
var resp User
|
||||
err := m.QueryRowCtx(ctx, &resp, hmUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -109,9 +110,9 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOneByMobile(ctx context.Context, mobile sql.NullString) (*User, error) {
|
||||
hmUserMobileKey := fmt.Sprintf("%s%v", cacheHmUserMobilePrefix, mobile)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, mobile)
|
||||
var resp User
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, hmUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `mobile` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, mobile, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -133,15 +134,15 @@ func (m *defaultUserModel) Update(ctx context.Context, session sqlx.Session, new
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hmUserIdKey := fmt.Sprintf("%s%v", cacheHmUserIdPrefix, data.Id)
|
||||
hmUserMobileKey := fmt.Sprintf("%s%v", cacheHmUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Disable, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
}, hmUserIdKey, hmUserMobileKey)
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Disable, newData.Id)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *User) error {
|
||||
@@ -156,15 +157,15 @@ func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.S
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hmUserIdKey := fmt.Sprintf("%s%v", cacheHmUserIdPrefix, data.Id)
|
||||
hmUserMobileKey := fmt.Sprintf("%s%v", cacheHmUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Disable, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
}, hmUserIdKey, hmUserMobileKey)
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Disable, newData.Id, oldVersion)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -387,19 +388,19 @@ func (m *defaultUserModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
hmUserIdKey := fmt.Sprintf("%s%v", cacheHmUserIdPrefix, id)
|
||||
hmUserMobileKey := fmt.Sprintf("%s%v", cacheHmUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
_, 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)
|
||||
}, hmUserIdKey, hmUserMobileKey)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheHmUserIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserModel) 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", userRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user