diff --git a/src/views/miniapp/MiniappConfig.vue b/src/views/miniapp/MiniappConfig.vue index 9e1783d..707189a 100644 --- a/src/views/miniapp/MiniappConfig.vue +++ b/src/views/miniapp/MiniappConfig.vue @@ -177,7 +177,7 @@ :closable="false" show-icon class="shop-hint" - title="仅影响用户「收款」发起的微信商家转账。按优先级从小到大尝试;某号失败(余额不足/限额等)自动换下一号。发起成功后打款单会强制记录 mch_id,回调按该记录处理。" + title="仅影响用户「收款」。未绑定用户按优先级发起;仅当微信官方返回「超出商户单日/单月转账额度」且查单确认未建单时才静默换下一号。个人受限/余额不足等不换号。下方可给指定用户绑定固定商户(绑定后强制只用该号)。已发出待确认单不会因改绑新建第二笔。" />
@@ -333,6 +404,111 @@ const mchForm = reactive({ platform_pub_key_path: '', }) +const bindLoading = ref(false) +const bindSaving = ref(false) +const bindList = ref([]) +const bindFilterYonghuid = ref('') +const bindDialogVisible = ref(false) +const bindForm = reactive({ + id: null, + yonghuid: '', + mch_id: '', + enabled: true, + remark: '', +}) + +const loadBindList = async () => { + bindLoading.value = true + try { + const res = await request.post('/peizhi/wxmchUserLb', { + username: username.value, + yonghuid: bindFilterYonghuid.value || '', + page: 1, + limit: 100, + }) + if (res.code === 403) { + hasPermission.value = false + return + } + if (res.code === 0 && res.data) { + bindList.value = res.data.list || [] + } else { + ElMessage.error(res.msg || '加载用户绑定失败') + } + } catch { + ElMessage.error('网络错误') + } finally { + bindLoading.value = false + } +} + +const openBindDialog = (row) => { + if (row) { + Object.assign(bindForm, { + id: row.id, + yonghuid: row.yonghuid, + mch_id: row.mch_id, + enabled: !!row.enabled, + remark: row.remark || '', + }) + } else { + Object.assign(bindForm, { + id: null, + yonghuid: '', + mch_id: mchList.value.find((m) => m.enabled)?.mch_id || '', + enabled: true, + remark: '', + }) + } + bindDialogVisible.value = true +} + +const saveBind = async () => { + if (!bindForm.yonghuid || !bindForm.mch_id) { + ElMessage.warning('请填写用户ID并选择商户号') + return + } + bindSaving.value = true + try { + const res = await request.post('/peizhi/wxmchUserBj', { + username: username.value, + id: bindForm.id, + yonghuid: String(bindForm.yonghuid).trim(), + mch_id: bindForm.mch_id, + enabled: bindForm.enabled, + remark: bindForm.remark, + }) + if (res.code === 0) { + ElMessage.success(res.msg || '保存成功') + bindDialogVisible.value = false + await loadBindList() + } else { + ElMessage.error(res.msg || '保存失败') + } + } catch { + ElMessage.error('网络错误') + } finally { + bindSaving.value = false + } +} + +const deleteBind = async (row) => { + try { + const res = await request.post('/peizhi/wxmchUserSc', { + username: username.value, + id: row.id, + }) + if (res.code === 0) { + ElMessage.success('已删除') + await loadBindList() + } else { + ElMessage.error(res.msg || '删除失败') + } + } catch { + ElMessage.error('网络错误') + } +} + const loadMchList = async () => { mchLoading.value = true try { @@ -604,6 +780,7 @@ onMounted(() => { loadSysConfig() loadAssets() loadMchList() + loadBindList() })