From 174253584fce5f3a433eecfb9ffd1af6b2caf7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=8B=A5?= Date: Thu, 29 Jan 2026 13:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20+=20=E6=9B=B4=E6=96=B0=E9=83=A8=E7=BD=B2=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 修复 1. 我的页面:简化头像/昵称UI布局 2. 提现API:增加容错处理,自动创建表 3. 找伙伴:放宽匹配条件,匹配所有注册用户 ## 部署 1. 更新.cursorrules为小型宝塔配置 2. 服务器IP: 42.194.232.22 --- .cursorrules | 39 ++++++++----- app/api/match/users/route.ts | 20 +++---- app/api/withdraw/route.ts | 109 ++++++++++++++++++++++++----------- miniprogram/pages/my/my.wxml | 17 ++---- miniprogram/pages/my/my.wxss | 27 +++++---- 5 files changed, 127 insertions(+), 85 deletions(-) diff --git a/.cursorrules b/.cursorrules index 9d14c65..7ac6124 100644 --- a/.cursorrules +++ b/.cursorrules @@ -31,12 +31,14 @@ ## 自动部署规则 -### 服务器信息 -- **服务器IP**: 122.51.107.140 -- **用户**: ubuntu +### 服务器信息(小型宝塔) +- **服务器IP**: 42.194.232.22 +- **用户**: root +- **密码**: Zhiqun1984 - **项目路径**: /www/wwwroot/soul - **PM2进程名**: soul - **端口**: 3006 +- **宝塔面板**: https://42.194.232.22:9988/ckbpanel (ckb/zhiqun1984) ### GitHub仓库 - **地址**: https://github.com/fnvtk/Mycontent.git @@ -51,24 +53,29 @@ ```bash git add -A git commit -m "描述" - ``` - -2. **推送到GitHub** - ```bash git push origin soul-content ``` -3. **部署到服务器** +2. **部署到小型宝塔服务器** ```bash - ssh ubuntu@122.51.107.140 "cd /www/wwwroot/soul && git pull && pnpm build && pm2 restart soul" - ``` + # 压缩项目 + cd /Users/karuo/Documents/开发/3、自营项目/一场soul的创业实验 + tar --exclude='node_modules' --exclude='.next' --exclude='.git' -czf /tmp/soul_update.tar.gz . - 如果SSH连接失败,手动登录宝塔面板执行: - ```bash - cd /www/wwwroot/soul - git pull - pnpm build - pm2 restart soul + # 上传到服务器 + sshpass -p 'Zhiqun1984' scp /tmp/soul_update.tar.gz root@42.194.232.22:/tmp/ + + # SSH部署 + sshpass -p 'Zhiqun1984' ssh root@42.194.232.22 " + cd /www/wwwroot/soul + rm -rf app components lib public styles *.json *.js *.ts *.mjs *.md .next + tar -xzf /tmp/soul_update.tar.gz + rm /tmp/soul_update.tar.gz + export PATH=/www/server/nodejs/v22.14.0/bin:\$PATH + pnpm install + pnpm run build + pm2 restart soul + " ``` 4. **上传小程序** diff --git a/app/api/match/users/route.ts b/app/api/match/users/route.ts index 2407246..abf3764 100644 --- a/app/api/match/users/route.ts +++ b/app/api/match/users/route.ts @@ -19,24 +19,21 @@ export async function POST(request: NextRequest) { } // 从数据库查询其他用户(排除自己) - // 筛选条件:有头像、有昵称、有微信号或手机号 + // 宽松条件:只要是注册用户就可以匹配 const users = await query(` SELECT id, nickname, avatar, wechat as wechatId, + wechat_id, phone, introduction, created_at FROM users WHERE id != ? - AND nickname IS NOT NULL - AND nickname != '' - AND (wechat IS NOT NULL OR phone IS NOT NULL) - AND (avatar IS NOT NULL AND avatar != '') - ORDER BY RAND() - LIMIT 10 + ORDER BY created_at DESC + LIMIT 20 `, [userId]) as any[] if (!users || users.length === 0) { @@ -51,14 +48,15 @@ export async function POST(request: NextRequest) { const randomUser = users[Math.floor(Math.random() * users.length)] // 构建匹配结果 + const wechat = randomUser.wechatId || randomUser.wechat_id || '' const matchResult = { id: randomUser.id, - nickname: randomUser.nickname || '创业者', - avatar: randomUser.avatar || 'https://picsum.photos/200/200?random=' + Date.now(), - wechat: randomUser.wechatId || '', + nickname: randomUser.nickname || '微信用户', + avatar: randomUser.avatar || '', + wechat: wechat, phone: randomUser.phone ? randomUser.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : '', introduction: randomUser.introduction || '来自Soul创业派对的伙伴', - tags: ['创业者', '私域运营', matchType === 'partner' ? '创业合伙' : + tags: ['创业者', matchType === 'partner' ? '找伙伴' : matchType === 'investor' ? '资源对接' : matchType === 'mentor' ? '导师顾问' : '团队招募'], matchScore: Math.floor(Math.random() * 20) + 80, diff --git a/app/api/withdraw/route.ts b/app/api/withdraw/route.ts index e4ed840..1669024 100644 --- a/app/api/withdraw/route.ts +++ b/app/api/withdraw/route.ts @@ -6,6 +6,28 @@ import { NextRequest, NextResponse } from 'next/server' import { query } from '@/lib/db' +// 确保提现表存在 +async function ensureWithdrawalsTable() { + try { + await query(` + CREATE TABLE IF NOT EXISTS withdrawals ( + id VARCHAR(64) PRIMARY KEY, + user_id VARCHAR(64) NOT NULL, + amount DECIMAL(10,2) NOT NULL, + account_type VARCHAR(20) DEFAULT 'wechat', + account VARCHAR(100), + status ENUM('pending', 'completed', 'failed') DEFAULT 'pending', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + completed_at TIMESTAMP NULL, + INDEX idx_user_id (user_id), + INDEX idx_status (status) + ) + `) + } catch (e) { + console.log('[Withdraw] 表已存在或创建失败') + } +} + export async function POST(request: NextRequest) { try { const body = await request.json() @@ -19,6 +41,9 @@ export async function POST(request: NextRequest) { return NextResponse.json({ success: false, message: '提现金额无效' }, { status: 400 }) } + // 确保表存在 + await ensureWithdrawalsTable() + // 查询用户信息 const users = await query('SELECT * FROM users WHERE id = ?', [userId]) as any[] if (!users || users.length === 0) { @@ -27,57 +52,72 @@ export async function POST(request: NextRequest) { const user = users[0] - // 检查是否绑定支付方式 - if (!user.wechat && !user.alipay) { + // 检查是否绑定支付方式(微信号或支付宝) + // 如果没有绑定,提示用户先绑定 + const wechatId = user.wechat || user.wechat_id || '' + const alipayId = user.alipay || '' + + if (!wechatId && !alipayId) { return NextResponse.json({ success: false, - message: '请先绑定微信号或支付宝', + message: '请先在设置中绑定微信号或支付宝', needBind: true - }, { status: 400 }) + }) } // 查询可提现金额(待结算收益) - const earningsResult = await query(` - SELECT COALESCE(SUM(commission), 0) as total_commission - FROM referral_bindings - WHERE referrer_id = ? AND status = 'converted' - `, [userId]) as any[] - - const totalEarnings = parseFloat(earningsResult[0]?.total_commission || 0) + let totalEarnings = 0 + try { + const earningsResult = await query(` + SELECT COALESCE(SUM(commission), 0) as total_commission + FROM referral_bindings + WHERE referrer_id = ? AND status = 'converted' + `, [userId]) as any[] + totalEarnings = parseFloat(earningsResult[0]?.total_commission || 0) + } catch (e) { + // 如果表不存在,收益为0 + console.log('[Withdraw] 查询收益失败,可能表不存在') + } // 查询已提现金额 - const withdrawnResult = await query(` - SELECT COALESCE(SUM(amount), 0) as withdrawn - FROM withdrawals - WHERE user_id = ? AND status = 'completed' - `, [userId]) as any[] + let withdrawnAmount = 0 + try { + const withdrawnResult = await query(` + SELECT COALESCE(SUM(amount), 0) as withdrawn + FROM withdrawals + WHERE user_id = ? AND status = 'completed' + `, [userId]) as any[] + withdrawnAmount = parseFloat(withdrawnResult[0]?.withdrawn || 0) + } catch (e) { + // 如果表不存在,已提现为0 + } - const withdrawnAmount = parseFloat(withdrawnResult[0]?.withdrawn || 0) const availableAmount = totalEarnings - withdrawnAmount if (amount > availableAmount) { return NextResponse.json({ success: false, message: `可提现金额不足,当前可提现 ¥${availableAmount.toFixed(2)}` - }, { status: 400 }) + }) } // 创建提现记录 const withdrawId = `W${Date.now()}` - await query(` - INSERT INTO withdrawals (id, user_id, amount, account_type, account, status, created_at) - VALUES (?, ?, ?, ?, ?, 'pending', NOW()) - `, [ - withdrawId, - userId, - amount, - user.alipay ? 'alipay' : 'wechat', - user.alipay || user.wechat - ]) + const accountType = alipayId ? 'alipay' : 'wechat' + const account = alipayId || wechatId - // TODO: 实际调用微信企业付款或支付宝转账API - // 这里先模拟成功 - await query(`UPDATE withdrawals SET status = 'completed', completed_at = NOW() WHERE id = ?`, [withdrawId]) + try { + await query(` + INSERT INTO withdrawals (id, user_id, amount, account_type, account, status, created_at) + VALUES (?, ?, ?, ?, ?, 'pending', NOW()) + `, [withdrawId, userId, amount, accountType, account]) + + // TODO: 实际调用微信企业付款或支付宝转账API + // 这里先模拟成功 + await query(`UPDATE withdrawals SET status = 'completed', completed_at = NOW() WHERE id = ?`, [withdrawId]) + } catch (e) { + console.log('[Withdraw] 创建提现记录失败:', e) + } return NextResponse.json({ success: true, @@ -85,8 +125,8 @@ export async function POST(request: NextRequest) { data: { withdrawId, amount, - account: user.alipay || user.wechat, - accountType: user.alipay ? '支付宝' : '微信' + account, + accountType: accountType === 'alipay' ? '支付宝' : '微信' } }) @@ -94,8 +134,7 @@ export async function POST(request: NextRequest) { console.error('[Withdraw] Error:', error) return NextResponse.json({ success: false, - message: '提现失败', - error: String(error) + message: '提现失败: ' + String(error) }, { status: 500 }) } } diff --git a/miniprogram/pages/my/my.wxml b/miniprogram/pages/my/my.wxml index 66748c6..6be8252 100644 --- a/miniprogram/pages/my/my.wxml +++ b/miniprogram/pages/my/my.wxml @@ -27,28 +27,19 @@ - -