拆约:绑定放宽——同名同分舵多候选选择 + uid 直绑;师傅改师父
This commit is contained in:
@@ -93,8 +93,8 @@ const getChaishuBranches = () => {
|
||||
* @param {string} branch - 分舵名称
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const bindChaishu = (name, branch) => {
|
||||
return post('/chaishu/bind', { name, branch });
|
||||
const bindChaishu = (name, branch, uid) => {
|
||||
return post('/chaishu/bind', uid ? { uid } : { name, branch });
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -105,6 +105,24 @@ Page({
|
||||
wx.showToast({ title: '绑定成功', icon: 'success' });
|
||||
this.setData({ chaishuName: '' });
|
||||
this.loadProfile();
|
||||
} else if (res.code === 'MULTI_MATCH' && Array.isArray(res.candidates) && res.candidates.length > 0) {
|
||||
// 同名同分舵:展示候选让用户选择自己的身份
|
||||
const items = res.candidates.map((c) => {
|
||||
const parts = [];
|
||||
if (c.level2) parts.push(`二级-${c.level2}`);
|
||||
if (c.level3) parts.push(`三级-${c.level3}`);
|
||||
if (c.shifuName) parts.push(`师父:${c.shifuName}`);
|
||||
return parts.length ? `${c.name}(${parts.join(' / ')})` : c.name;
|
||||
});
|
||||
const self = this;
|
||||
wx.showActionSheet({
|
||||
itemList: items.slice(0, 6),
|
||||
success: (sheet) => {
|
||||
self.bindByUid(res.candidates[sheet.tapIndex].uid);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
wx.showToast({ title: res.message || '绑定失败', icon: 'none' });
|
||||
}
|
||||
} catch (err) {
|
||||
wx.showToast({
|
||||
@@ -116,6 +134,24 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async bindByUid(uid) {
|
||||
this.setData({ binding: true });
|
||||
try {
|
||||
const res = await bindChaishu(null, null, uid);
|
||||
if (res.success) {
|
||||
wx.showToast({ title: '绑定成功', icon: 'success' });
|
||||
this.setData({ chaishuName: '' });
|
||||
this.loadProfile();
|
||||
} else {
|
||||
wx.showToast({ title: res.message || '绑定失败', icon: 'none' });
|
||||
}
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '绑定失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ binding: false });
|
||||
}
|
||||
},
|
||||
|
||||
async handleChooseAvatar() {
|
||||
try {
|
||||
const [tempFilePath] = await chooseImages(1);
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<text class="chaishu-val">{{chaishu.level2 ? '二级-' + chaishu.level2 : ''}}{{chaishu.level3 ? (chaishu.level2 ? ' / ' : '') + '三级-' + chaishu.level3 : ''}}</text>
|
||||
</view>
|
||||
<view class="chaishu-row" wx:if="{{chaishu.shifuName}}">
|
||||
<text class="chaishu-key">师傅</text>
|
||||
<text class="chaishu-key">师父</text>
|
||||
<text class="chaishu-val">{{chaishu.shifuName}}</text>
|
||||
</view>
|
||||
<view class="chaishu-row" wx:if="{{chaishu.tags.length}}">
|
||||
@@ -153,7 +153,7 @@
|
||||
<button class="chaishu-bind-btn" loading="{{binding}}" bindtap="handleBindChaishu">
|
||||
{{binding ? '绑定中...' : '绑定拆书帮身份'}}
|
||||
</button>
|
||||
<text class="chaishu-tip">绑定后将在个人主页展示拆书帮分舵与师承信息;如遇同名会员无法绑定,请联系客服 ikoning365</text>
|
||||
<text class="chaishu-tip">绑定后将在个人主页展示拆书帮分舵与师承信息;同名会员可从列表中选择自己的身份</text>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
-- 插入测试用户
|
||||
INSERT INTO users (id, openid, nickname, avatar_url, phone, position, industry, hometown, email, expertise) VALUES
|
||||
('user-1', 'openid_001', '陈昊韬', '', '13538859781', '产品经理', '互联网', '广东广州', 'example@email.com', '产品规划、用户体验'),
|
||||
('user-1', 'openid_001', '杨辉', '', '13611414319', '拆书家', 'AI', '广东广州', 'kenyanghui@example.com', '拆书法、AI 智能体'),
|
||||
('user-2', 'openid_002', '张三', '', '13800138001', '技术专家', '互联网', '广东深圳', 'zhangsan@email.com', '前端开发、架构设计'),
|
||||
('user-3', 'openid_003', '李四', '', '13800138002', '运营总监', '电商', '北京', 'lisi@email.com', '用户增长、数据分析'),
|
||||
('user-4', 'openid_004', '王五', '', '13800138003', '设计师', '互联网', '上海', 'wangwu@email.com', 'UI设计、品牌设计'),
|
||||
|
||||
@@ -1455,23 +1455,42 @@ app.get('/chaishu/tags', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定拆书帮身份(按姓名+分舵精确匹配唯一记录)
|
||||
// 绑定拆书帮身份(姓名+分舵匹配;支持 uid 直绑用于多候选选择)
|
||||
app.post('/chaishu/bind', (req, res) => {
|
||||
try {
|
||||
const userId = req.headers['x-user-id'];
|
||||
if (!userId) {
|
||||
return res.json({ success: false, message: '未登录' });
|
||||
}
|
||||
const { name, branch } = req.body;
|
||||
const { name, branch, uid } = req.body;
|
||||
// uid 直绑:多候选时前端选中后二次提交
|
||||
if (uid) {
|
||||
const member = db.prepare('SELECT uid, name, branch FROM chaishu_members WHERE uid = ?').get(uid);
|
||||
if (!member) {
|
||||
return res.json({ success: false, message: '会员不存在' });
|
||||
}
|
||||
db.prepare('UPDATE users SET chaishu_uid = ?, chaishu_verified = 1 WHERE id = ?').run(member.uid, userId);
|
||||
return res.json({ success: true, data: member });
|
||||
}
|
||||
if (!name || !branch) {
|
||||
return res.json({ success: false, message: '姓名和分舵不能为空' });
|
||||
}
|
||||
const matches = db.prepare('SELECT uid, name, branch FROM chaishu_members WHERE name = ? AND branch = ?').all(name, branch);
|
||||
const matches = db.prepare('SELECT uid, name, branch, level2, level3, shifu_name FROM chaishu_members WHERE name = ? AND branch = ?').all(name, branch);
|
||||
if (matches.length === 0) {
|
||||
return res.json({ success: false, message: '未找到匹配的拆书帮会员,请确认姓名与分舵' });
|
||||
}
|
||||
if (matches.length > 1) {
|
||||
return res.json({ success: false, message: '该分舵下存在同名会员,请联系客服人工核实' });
|
||||
// 同名同分舵:返回候选列表让用户选择
|
||||
return res.json({
|
||||
success: false,
|
||||
code: 'MULTI_MATCH',
|
||||
message: '该分舵下存在同名会员,请选择您的身份',
|
||||
candidates: matches.map(m => ({
|
||||
uid: m.uid, name: m.name, branch: m.branch,
|
||||
level2: m.level2 || '', level3: m.level3 || '',
|
||||
shifuName: m.shifu_name || '',
|
||||
})),
|
||||
});
|
||||
}
|
||||
const member = matches[0];
|
||||
db.prepare('UPDATE users SET chaishu_uid = ?, chaishu_verified = 1 WHERE id = ?').run(member.uid, userId);
|
||||
|
||||
Reference in New Issue
Block a user