添加支付费率扣除
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
import { fetchDemandContractDetail, demandOperate } from '../../../services/demand/fetchDemand';
|
||||
import { fetchPlatformCommissionRatio, calcActualAccount } from '../../../services/home/home';
|
||||
import { fetchIncomeRates, calcActualAccount, toPercent } from '../../../services/home/home';
|
||||
// pages/demand/contract/index.js
|
||||
Page({
|
||||
|
||||
@@ -9,9 +9,14 @@ Page({
|
||||
*/
|
||||
data: {
|
||||
demandId: 0,
|
||||
actualAccount: 0,
|
||||
androidAccount: 0,
|
||||
iosAccount: 0,
|
||||
commissionRatio: 0.1, // 平台服务费比例,来自 common/getMiniConfig
|
||||
commissionPercent: 10, // 平台服务费百分比,用于提示文案
|
||||
commissionPercent: 10,
|
||||
androidPayFeeRate: 0.01,
|
||||
iosPayFeeRate: 0.12,
|
||||
androidFeePercent: 1,
|
||||
iosFeePercent: 12,
|
||||
contract: null,
|
||||
agreementUrl: '', // 签约条款URL
|
||||
phoneError: '', // 个人联系电话错误提示
|
||||
@@ -67,13 +72,26 @@ Page({
|
||||
this.loadCommissionRatio();
|
||||
},
|
||||
|
||||
// 拉取平台服务费比例,并按新比例重算预计到手金额
|
||||
incomePreview(amount, rates) {
|
||||
const commissionRatio = rates ? rates.commissionRatio : this.data.commissionRatio;
|
||||
const androidPayFeeRate = rates ? rates.androidPayFeeRate : this.data.androidPayFeeRate;
|
||||
const iosPayFeeRate = rates ? rates.iosPayFeeRate : this.data.iosPayFeeRate;
|
||||
return {
|
||||
androidAccount: calcActualAccount(amount, commissionRatio, androidPayFeeRate),
|
||||
iosAccount: calcActualAccount(amount, commissionRatio, iosPayFeeRate),
|
||||
};
|
||||
},
|
||||
// 拉取平台服务费和支付费率,并重算预计到手金额
|
||||
async loadCommissionRatio() {
|
||||
const ratio = await fetchPlatformCommissionRatio();
|
||||
const rates = await fetchIncomeRates();
|
||||
this.setData({
|
||||
commissionRatio: ratio,
|
||||
commissionPercent: Math.round(ratio * 10000) / 100,
|
||||
actualAccount: calcActualAccount(this.data.formData?.totalCost, ratio)
|
||||
commissionRatio: rates.commissionRatio,
|
||||
commissionPercent: toPercent(rates.commissionRatio),
|
||||
androidPayFeeRate: rates.androidPayFeeRate,
|
||||
iosPayFeeRate: rates.iosPayFeeRate,
|
||||
androidFeePercent: toPercent(rates.androidPayFeeRate),
|
||||
iosFeePercent: toPercent(rates.iosPayFeeRate),
|
||||
...this.incomePreview(this.data.formData?.totalCost, rates),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -207,7 +225,7 @@ Page({
|
||||
onTotalCostChange(e) {
|
||||
this.setData({
|
||||
'formData.totalCost': e.detail.value,
|
||||
actualAccount: calcActualAccount(e.detail.value, this.data.commissionRatio)
|
||||
...this.incomePreview(e.detail.value),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -531,7 +549,7 @@ Page({
|
||||
'formData.taskContent': resData.task_content,
|
||||
'formData.needDays': resData.need_days,
|
||||
'formData.totalCost': resData.total_amount,
|
||||
actualAccount: calcActualAccount(resData.total_amount, this.data.commissionRatio),
|
||||
...this.incomePreview(resData.total_amount),
|
||||
});
|
||||
|
||||
// 客户签约时,附件展示开发者签约时上传的附件,仅可预览,不可删除和上传
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
/>
|
||||
</view>
|
||||
|
||||
<t-input label="总费用" placeholder="请输入总费用" suffix="元" align="right" type="number" tips="{{source == 'dev' ? '预计到手金额 ' + actualAccount + '元 + ' + commissionPercent + '%的平台服务费' : '总费用 = 首付款50% + 尾款50%'}}" disabled="{{source != 'dev'}}" value="{{formData.totalCost}}" bind:change="onTotalCostChange" />
|
||||
<t-input label="总费用" placeholder="请输入总费用" suffix="元" align="right" type="number" tips="{{source == 'dev' ? '预计到手 安卓' + androidAccount + '元 / iOS' + iosAccount + '元,已扣平台服务费' + commissionPercent + '%和支付费率' + androidFeePercent + '%/' + iosFeePercent + '%' : '总费用 = 首付款50% + 尾款50%'}}" disabled="{{source != 'dev'}}" value="{{formData.totalCost}}" bind:change="onTotalCostChange" />
|
||||
<t-input label="开发工期" placeholder="请输入开发工期" suffix="天" align="right" type="number" disabled="{{source != 'dev'}}" value="{{formData.needDays}}" bind:change="onDevelopmentPeriodChange" />
|
||||
</view>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// pages/demand/detail.js
|
||||
import { fetchDemandDetail, joinDemandBidding, demandOperate } from '../../../services/demand/fetchDemand';
|
||||
import { fetchPlatformCommissionRatio, calcActualAccount } from '../../../services/home/home';
|
||||
import { fetchIncomeRates, calcActualAccount, toPercent } from '../../../services/home/home';
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -11,9 +11,14 @@ Page({
|
||||
quotedPrice: '',
|
||||
needDays: '',
|
||||
remark: '',
|
||||
actualAccount: 0,
|
||||
androidAccount: 0,
|
||||
iosAccount: 0,
|
||||
commissionRatio: 0.1, // 平台服务费比例,来自 common/getMiniConfig
|
||||
commissionPercent: 10, // 平台服务费百分比,用于提示文案
|
||||
commissionPercent: 10,
|
||||
androidPayFeeRate: 0.01,
|
||||
iosPayFeeRate: 0.12,
|
||||
androidFeePercent: 1,
|
||||
iosFeePercent: 12,
|
||||
activeValues: [0, 1, 2, 3, 4],
|
||||
demandInfo: null,
|
||||
freshPage: false, // 返回本页时是否需要重新拉取详情(签约/发货/支付后置为 true)
|
||||
@@ -36,7 +41,7 @@ Page({
|
||||
const demandInfo = res.data;
|
||||
this.setData({
|
||||
demandInfo,
|
||||
actualAccount: calcActualAccount(this.getQuoteAmount(demandInfo), this.data.commissionRatio)
|
||||
...this.incomePreview(this.getQuoteAmount(demandInfo))
|
||||
}, () => resolve()); // setData 回调:页面已重新渲染
|
||||
},
|
||||
() => {
|
||||
@@ -50,13 +55,27 @@ Page({
|
||||
getQuoteAmount(demandInfo) {
|
||||
return demandInfo?.myBidding?.quoted_price || demandInfo?.demand_contracts?.total_amount || this.data.quotedPrice || 0;
|
||||
},
|
||||
// 拉取平台服务费比例,并按新比例重算预计到手金额
|
||||
// 按当前报价计算安卓、iOS 两种预计到手
|
||||
incomePreview(amount, rates) {
|
||||
const commissionRatio = rates ? rates.commissionRatio : this.data.commissionRatio;
|
||||
const androidPayFeeRate = rates ? rates.androidPayFeeRate : this.data.androidPayFeeRate;
|
||||
const iosPayFeeRate = rates ? rates.iosPayFeeRate : this.data.iosPayFeeRate;
|
||||
return {
|
||||
androidAccount: calcActualAccount(amount, commissionRatio, androidPayFeeRate),
|
||||
iosAccount: calcActualAccount(amount, commissionRatio, iosPayFeeRate),
|
||||
};
|
||||
},
|
||||
// 拉取平台服务费和支付费率,并重算预计到手金额
|
||||
async loadCommissionRatio() {
|
||||
const ratio = await fetchPlatformCommissionRatio();
|
||||
const rates = await fetchIncomeRates();
|
||||
this.setData({
|
||||
commissionRatio: ratio,
|
||||
commissionPercent: Math.round(ratio * 10000) / 100,
|
||||
actualAccount: calcActualAccount(this.getQuoteAmount(this.data.demandInfo), ratio)
|
||||
commissionRatio: rates.commissionRatio,
|
||||
commissionPercent: toPercent(rates.commissionRatio),
|
||||
androidPayFeeRate: rates.androidPayFeeRate,
|
||||
iosPayFeeRate: rates.iosPayFeeRate,
|
||||
androidFeePercent: toPercent(rates.androidPayFeeRate),
|
||||
iosFeePercent: toPercent(rates.iosPayFeeRate),
|
||||
...this.incomePreview(this.getQuoteAmount(this.data.demandInfo), rates),
|
||||
});
|
||||
},
|
||||
// 取文件扩展名对应的 openDocument 类型(默认 pdf)
|
||||
@@ -194,7 +213,7 @@ Page({
|
||||
const field = e.currentTarget.dataset.field;
|
||||
const value = e.detail.value;
|
||||
if (field == 'quotedPrice') {
|
||||
this.setData({ actualAccount: calcActualAccount(value, this.data.commissionRatio) });
|
||||
this.setData(this.incomePreview(value));
|
||||
}
|
||||
this.setData({
|
||||
[`${field}`]: value
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</t-collapse-panel>
|
||||
<t-collapse-panel header="{{opType=='quote' ? '我的报价' : '开发人员报价'}}" value="{{3}}" expandIcon>
|
||||
<view>
|
||||
<t-input style="--td-input-border-color: rgb(238, 116, 2);" placeholder="填写报价金额" suffix="元" align="right" type="number" value="{{opType=='quote' ? demandInfo.myBidding.quoted_price || demandInfo.demand_contracts.total_amount ||quotedPrice : demandInfo.winBidding.quoted_price}}" disabled="{{opType=='quote' && (!demandInfo.myBidding && !demandInfo.demand_contracts) ? false : true}}" tips="{{opType=='quote' && actualAccount > 0 ? '预计到手金额 ' + actualAccount + '元 + ' + commissionPercent + '%的平台服务费' : ''}}" data-field="quotedPrice" bindchange="onInputChange">
|
||||
<t-input style="--td-input-border-color: rgb(238, 116, 2);" placeholder="填写报价金额" suffix="元" align="right" type="number" value="{{opType=='quote' ? demandInfo.myBidding.quoted_price || demandInfo.demand_contracts.total_amount ||quotedPrice : demandInfo.winBidding.quoted_price}}" disabled="{{opType=='quote' && (!demandInfo.myBidding && !demandInfo.demand_contracts) ? false : true}}" tips="{{opType=='quote' && androidAccount > 0 ? '预计到手 安卓' + androidAccount + '元 / iOS' + iosAccount + '元,已扣平台服务费' + commissionPercent + '%和支付费率' + androidFeePercent + '%/' + iosFeePercent + '%' : ''}}" data-field="quotedPrice" bindchange="onInputChange">
|
||||
<view slot="label" class="custom-label">报价</view>
|
||||
</t-input>
|
||||
<t-input placeholder="填写预计工期" suffix="天" align="right" disabled="{{opType=='quote' && (!demandInfo.myBidding && !demandInfo.demand_contracts) ? false : true}}" type="number" value="{{opType=='quote' ? demandInfo.myBidding.need_days || demandInfo.demand_contracts.need_days || needDays : demandInfo.winBidding.need_days}}" data-field="needDays" bindchange="onInputChange">
|
||||
|
||||
@@ -3,6 +3,17 @@ import Toast from 'tdesign-miniprogram/toast/index';
|
||||
|
||||
import { confirmVirtualPay, dispatchCommitPay } from '../../../services/order/orderConfirm';
|
||||
|
||||
// iOS 单独记,其余终端按安卓支付费率
|
||||
function currentPayPlatform() {
|
||||
let platform = '';
|
||||
try {
|
||||
platform = String((wx.getSystemInfoSync() || {}).platform || '').toLowerCase();
|
||||
} catch (err) {
|
||||
platform = '';
|
||||
}
|
||||
return platform === 'ios' ? 'ios' : 'android';
|
||||
}
|
||||
|
||||
// 真实的提交支付
|
||||
export const commitPay = (params) => {
|
||||
return dispatchCommitPay({
|
||||
@@ -23,6 +34,7 @@ export const commitPay = (params) => {
|
||||
storeInfoList: params.storeInfoList, //备注信息列表
|
||||
couponList: params.couponList,
|
||||
groupInfo: params.groupInfo,
|
||||
payPlatform: currentPayPlatform(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -129,7 +141,7 @@ export const wechatPayOrder = (payOrderInfo) => {
|
||||
signature: payInfo.signature,
|
||||
mode: payInfo.mode,
|
||||
success() {
|
||||
confirmVirtualPay(payOrderInfo.tradeNo).then((res) => {
|
||||
confirmVirtualPay(payOrderInfo.tradeNo, currentPayPlatform()).then((res) => {
|
||||
if (!res || res.code !== 1) {
|
||||
payFail(payOrderInfo, (res && res.msg) || '支付结果确认失败,请稍后在订单中再次支付,不会重复扣款');
|
||||
return;
|
||||
|
||||
@@ -143,12 +143,45 @@ export async function fetchGoodsCaseView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算扣除平台服务费后的预计到手金额(保留两位小数)
|
||||
* 预计到手 = 金额 × (1 - 平台服务费 - 支付费率),保留两位小数
|
||||
* @param {number|string} amount 报价/总费用(元)
|
||||
* @param {number} ratio 平台服务费比例
|
||||
* @param {number} payFeeRate 安卓或 iOS 支付费率
|
||||
* @returns {number}
|
||||
*/
|
||||
export function calcActualAccount(amount, ratio) {
|
||||
export function calcActualAccount(amount, ratio, payFeeRate = 0) {
|
||||
const value = Number(amount) || 0;
|
||||
return Math.round(value * (1 - ratio) * 100) / 100;
|
||||
const remain = 1 - (Number(ratio) || 0) - (Number(payFeeRate) || 0);
|
||||
return Math.round(value * (remain > 0 ? remain : 0) * 100) / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台服务费和两端支付费率。费率来自 getMiniConfig,失败时用 1% / 12%
|
||||
* @returns {Promise<{commissionRatio:number, androidPayFeeRate:number, iosPayFeeRate:number}>}
|
||||
*/
|
||||
export async function fetchIncomeRates() {
|
||||
const commissionRatio = await fetchPlatformCommissionRatio();
|
||||
let androidPayFeeRate = 0.01;
|
||||
let iosPayFeeRate = 0.12;
|
||||
try {
|
||||
const res = await fetchConfig();
|
||||
if (res && res.code === 1) {
|
||||
const android = Number(res.data?.android_pay_fee_rate);
|
||||
const ios = Number(res.data?.ios_pay_fee_rate);
|
||||
if (android >= 0 && android < 1) {
|
||||
androidPayFeeRate = android;
|
||||
}
|
||||
if (ios >= 0 && ios < 1) {
|
||||
iosPayFeeRate = ios;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('fetchIncomeRates failed:', err);
|
||||
}
|
||||
return { commissionRatio, androidPayFeeRate, iosPayFeeRate };
|
||||
}
|
||||
|
||||
/** 比例转百分比,1% 显示为 1,12% 显示为 12 */
|
||||
export function toPercent(rate) {
|
||||
return Math.round((Number(rate) || 0) * 10000) / 100;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ export function dispatchCommitPay(params) {
|
||||
}
|
||||
|
||||
/** 虚拟支付收银台成功后,通知服务端查单并入账 */
|
||||
export function confirmVirtualPay(orderNo) {
|
||||
return wx.$util.request(wx.$api.OrderVirtualPayConfirm, { orderNo }, 'POST');
|
||||
export function confirmVirtualPay(orderNo, payPlatform) {
|
||||
return wx.$util.request(wx.$api.OrderVirtualPayConfirm, { orderNo, payPlatform }, 'POST');
|
||||
}
|
||||
|
||||
/* 订单操作 */
|
||||
|
||||
Reference in New Issue
Block a user