feat(partner): 完善马豆实时动态汇率与精度自适应,支持交易数据清理与汇率重置

这个提交包含在:
chen
2026-09-18 07:59:50 +08:00
父节点 ac8c45bdad
当前提交 7c10864be2
共有 60 个文件被更改,包括 2691 次插入 和 490 次删除

查看文件

@@ -484,14 +484,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
createApp('detail', detail);
},
recharge: () => {
const { reactive, getCurrentInstance } = Vue
const { reactive, getCurrentInstance, onMounted, computed } = Vue
const recharge = {
setup() {
const { proxy } = getCurrentInstance();
const initialType = new URLSearchParams(location.search).get('type') || 'money';
const validTypes = ['money', 'score', 'madow', 'voucher'];
const defaultType = validTypes.includes(initialType) ? initialType : 'money';
const state = reactive({
type: new URLSearchParams(location.search).get('type'),
id: new URLSearchParams(location.search).get('id')
type: defaultType,
id: new URLSearchParams(location.search).get('id'),
user: null,
loading: false,
submitting: false
})
const form = reactive({
@@ -502,27 +509,146 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
memo: '',
},
rules: {
amount: [{ required: true, message: '请输入', trigger: 'blur' }],
type: [{ required: true, message: '请选择资产类型', trigger: 'change' }],
amount: [
{ required: true, message: '请输入变更数值', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value === '' || isNaN(value) || parseFloat(value) === 0) {
callback(new Error('请输入非零有效数值'));
} else {
callback();
}
},
trigger: 'blur'
}
],
},
})
// 获取会员详情与当前四大资产快照
function getUserInfo() {
if (!state.id) return;
state.loading = true;
Fast.api.ajax({
url: `shopro/user/user/detail?id=${state.id}`,
loading: false
}, function (ret, res) {
state.loading = false;
state.user = res.data || null;
}, function (ret, res) {
state.loading = false;
});
}
// 切换资产类型
function onTypeChange(val) {
state.type = val;
form.model.type = val;
}
// 资产单位与名称
const assetLabel = computed(() => {
const map = {
money: '金额',
madow: '马豆',
score: '积分',
voucher: '兑换券'
};
return map[form.model.type] || '数量';
});
const assetUnit = computed(() => {
const map = {
money: '元',
madow: '颗',
score: '积分',
voucher: '元'
};
return map[form.model.type] || '';
});
// 当前选中资产的当前持有值
const currentBalance = computed(() => {
if (!state.user) return '0';
switch (form.model.type) {
case 'money':
return state.user.money || '0.00';
case 'score':
return state.user.score || 0;
case 'madow':
return state.user.madow || '0.00000000';
case 'voucher':
return state.user.voucher_available || '0.00';
default:
return '0';
}
});
// 预计变动后数值
const previewBalance = computed(() => {
const val = parseFloat(form.model.amount);
if (isNaN(val) || val === 0) {
return null;
}
const cur = parseFloat(currentBalance.value) || 0;
const res = cur + val;
if (form.model.type === 'madow') {
return res.toFixed(8);
} else if (form.model.type === 'score') {
return Math.floor(res);
} else {
return res.toFixed(2);
}
});
// 是否超额扣除
const isOverdrawn = computed(() => {
if (previewBalance.value === null) return false;
return parseFloat(previewBalance.value) < 0;
});
function onCancel() {
Fast.api.close();
}
function onConfirm() {
proxy.$refs['formRef'].validate((valid) => {
if (valid) {
if (isOverdrawn.value) {
Fast.api.msg('扣除数额已超出当前持有量,请核对后重试');
return;
}
state.submitting = true;
Fast.api.ajax({
url: `shopro/user/user/recharge`,
type: 'POST',
data: form.model,
loading: true
}, function (ret, res) {
Fast.api.close()
}, function (ret, res) { })
state.submitting = false;
Fast.api.close();
}, function (ret, res) {
state.submitting = false;
});
}
});
}
onMounted(() => {
getUserInfo();
})
return {
state,
form,
assetLabel,
assetUnit,
currentBalance,
previewBalance,
isOverdrawn,
onTypeChange,
onCancel,
onConfirm
}
}