Files
soul-yongping/开发文档/8、部署/分销中心设置功能说明.md
2026-02-09 15:09:29 +08:00

7.7 KiB
Raw Blame History

分销中心设置功能说明

一、功能概述

分销中心右上角设置按钮提供两个功能:

  1. 自动提现设置 - 配置自动提现功能
  2. 收益通知设置 - 配置收益通知提醒

二、自动提现设置

功能说明

目的:方便用户自动提现,无需手动操作

工作流程

  1. 用户设置自动提现阈值例如¥50
  2. 开启自动提现
  3. 当可提现金额 ≥ 阈值时,自动发起提现申请

使用方法

1. 开启自动提现

点击设置 → 自动提现设置 → 开启

弹窗内容

  • 当前状态:已关闭/已开启
  • 自动提现阈值¥XX
  • 说明文字
  • 按钮:开启/关闭、修改阈值

2. 设置阈值

点击设置 → 自动提现设置 → 修改阈值

输入要求

  • 最低金额等于系统配置的最低提现金额默认¥10
  • 必须是数字
  • 小数点后最多2位

示例

  • 10
  • 50.5
  • 100.00
  • 5低于最低金额
  • abc不是数字

3. 自动提现触发

触发时机

  • 用户开启自动提现后,立即检查当前金额
  • 每次收到新佣金时检查
  • 用户进入分销中心时检查

触发流程

检测到 可提现金额 ≥ 阈值
  ↓
弹窗确认:是否立即提现?
  ↓
用户确认 → 调用提现接口

数据存储

存储位置:微信本地存储(wx.setStorageSync

存储格式

// 自动提现开关
`autoWithdraw_${userId}`: boolean

// 自动提现阈值
`autoWithdrawThreshold_${userId}`: number

示例

// 用户ID为 user_123
autoWithdraw_user_123: true
autoWithdrawThreshold_user_123: 50

代码实现

主要函数

// 显示自动提现设置
showAutoWithdrawSettings()

// 切换自动提现开关
toggleAutoWithdraw(enabled, threshold)

// 设置自动提现阈值
setAutoWithdrawThreshold(currentEnabled, currentThreshold)

调用流程

点击设置按钮
  
showSettings() - 显示菜单
  
选择"自动提现设置"
  
showAutoWithdrawSettings() - 显示设置弹窗
  
用户选择
  ├─ 开启/关闭  toggleAutoWithdraw()
  └─ 修改阈值  setAutoWithdrawThreshold()

三、收益通知设置

功能说明

目的:及时通知用户有新的收益入账

通知时机

  • 有新用户付款,获得佣金时
  • 有用户续费,获得佣金时
  • 提现成功时

使用方法

1. 开启通知

点击设置 → 收益通知设置 → 开启通知

弹窗内容

  • 当前状态:已开启/已关闭
  • 说明文字
  • 按钮:开启通知/关闭通知

2. 授权通知权限

开启通知后会自动请求微信订阅消息权限

订阅消息模板

模板ID需在微信公众平台配置
模板内容:
- 收益金额¥XX
- 收益来源用户XXX购买XXX
- 收益时间XXXX-XX-XX XX:XX

数据存储

存储位置:微信本地存储

存储格式

// 收益通知开关默认true
`earningsNotify_${userId}`: boolean

代码实现

// 显示收益通知设置
showNotificationSettings()

四、完整代码

JS部分 (miniprogram/pages/referral/referral.js)

// 显示设置
showSettings() {
  wx.showActionSheet({
    itemList: ['自动提现设置', '收益通知设置'],
    success: (res) => {
      if (res.tapIndex === 0) {
        this.showAutoWithdrawSettings()
      } else {
        this.showNotificationSettings()
      }
    }
  })
},

// 自动提现设置
async showAutoWithdrawSettings() {
  const app = getApp()
  const { userInfo } = app.globalData
  
  if (!userInfo) {
    wx.showToast({ title: '请先登录', icon: 'none' })
    return
  }

  // 获取当前设置
  let autoWithdrawEnabled = wx.getStorageSync(`autoWithdraw_${userInfo.id}`) || false
  let autoWithdrawThreshold = wx.getStorageSync(`autoWithdrawThreshold_${userInfo.id}`) || this.data.minWithdrawAmount || 10

  wx.showModal({
    title: '自动提现设置',
    content: `当前状态:${autoWithdrawEnabled ? '已开启' : '已关闭'}\n自动提现阈值¥${autoWithdrawThreshold}\n\n开启后当可提现金额达到阈值时将自动发起提现申请。`,
    confirmText: autoWithdrawEnabled ? '关闭' : '开启',
    cancelText: '修改阈值',
    success: (res) => {
      if (res.confirm) {
        this.toggleAutoWithdraw(!autoWithdrawEnabled, autoWithdrawThreshold)
      } else if (res.cancel) {
        this.setAutoWithdrawThreshold(autoWithdrawEnabled, autoWithdrawThreshold)
      }
    }
  })
},

// ... 其他函数 ...

五、扩展功能(未来)

1. 服务器端自动提现

当前:本地存储,小程序内检测

优化

  • 将设置保存到服务器
  • 服务器定时任务检测
  • 自动发起提现,无需用户确认

实现方案

-- 添加用户设置表
CREATE TABLE user_settings (
  user_id VARCHAR(64) PRIMARY KEY,
  auto_withdraw_enabled BOOLEAN DEFAULT FALSE,
  auto_withdraw_threshold DECIMAL(10,2) DEFAULT 10.00,
  earnings_notify_enabled BOOLEAN DEFAULT TRUE,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
// 后端API
POST /api/user/settings
GET /api/user/settings

// 定时任务(每小时执行)
async function autoWithdrawTask() {
  // 查询所有开启自动提现的用户
  const users = await query(`
    SELECT u.id, u.pending_earnings, s.auto_withdraw_threshold
    FROM users u
    JOIN user_settings s ON u.id = s.user_id
    WHERE s.auto_withdraw_enabled = TRUE
      AND u.pending_earnings >= s.auto_withdraw_threshold
  `)
  
  // 为每个用户发起提现
  for (const user of users) {
    await processWithdraw(user.id, user.pending_earnings)
  }
}

2. 多种通知方式

当前:小程序订阅消息

扩展

  • 公众号模板消息
  • 短信通知
  • 邮件通知

3. 更多设置项

  • 提现到账通知
  • 绑定用户提醒
  • 即将过期提醒
  • 每日收益汇总

六、注意事项

1. 自动提现限制

  • ⚠️ 需要用户手动确认,不是完全自动
  • ⚠️ 仍需满足最低提现金额要求
  • ⚠️ 受提现次数限制(如有)

2. 通知权限

  • 需要用户授权订阅消息
  • 模板消息需要在微信公众平台配置
  • 用户可以随时关闭通知

3. 数据安全

  • 本地存储数据可能丢失(卸载小程序、清除缓存)
  • 建议未来同步到服务器

七、测试用例

自动提现测试

场景 操作 预期结果
开启自动提现 可提现金额 < 阈值 正常开启,不弹窗
开启自动提现 可提现金额 ≥ 阈值 弹窗询问是否提现
修改阈值 输入小于最低金额 提示错误
修改阈值 输入非数字 提示错误
修改阈值 输入合法金额 保存成功

通知设置测试

场景 操作 预期结果
开启通知 首次开启 请求订阅消息权限
开启通知 已授权 直接开启
关闭通知 点击关闭 立即关闭,不再提醒

八、用户体验优化建议

  1. 引导用户使用

    • 首次进入分销中心时,引导设置自动提现
    • 可提现金额达到阈值时,提示开启自动提现
  2. 智能推荐阈值

    • 根据用户历史提现金额推荐合适的阈值
    • 例如平均提现金额为¥80推荐阈值为¥50-¥100
  3. 状态反馈

    • 在分销中心显示自动提现状态(已开启/已关闭)
    • 显示下次自动提现预计金额

创建时间2026-02-04
功能状态 已实现
适用版本:小程序 v1.0+