264 lines
8.9 KiB
JavaScript
264 lines
8.9 KiB
JavaScript
//<editor-fold desc="新建订单计算扣减金额和计算冻结金额 --- aiYouHog dev">
|
||
//#region 新建订单计算扣减金额和计算冻结金额 --- aiYouHog dev
|
||
|
||
let config = {
|
||
query: {
|
||
channelField: "qdbh"
|
||
},
|
||
condition: {
|
||
//条件字段
|
||
fieldName: "fkzt",
|
||
//满足条件值
|
||
value: "0"
|
||
},
|
||
bindFields: {
|
||
//渠道字段
|
||
channelField: "qdbh",
|
||
},
|
||
|
||
calculate: {
|
||
// 合同金额字段
|
||
contractAmount: "htje",
|
||
//信用金额字段
|
||
creditAmount: "dqxyed",
|
||
//扣减后金额字段
|
||
contractBalance: "kjhje",
|
||
//扣减后信用金额字段
|
||
creditBalance: "kchxyed",
|
||
//订单金额字段
|
||
orderAmount: "ddje",
|
||
//冻结渠道金额字段
|
||
frozenContractAmount: "djzje",
|
||
// 冻结信用额度字段
|
||
frozenCreditAmount: "xyeddjzje"
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 请求方法
|
||
* @param url 请求地址
|
||
* @param type 请求类心
|
||
* @param data 请求参数
|
||
* @param isAsync 是否异步请求
|
||
* @param success 成功回调参数
|
||
* @param error 失败回调方法
|
||
* @param complete 完成回调方法
|
||
* @param contentType 请求参数类型
|
||
* @param beforeSend 发送前回调
|
||
* @returns {*}
|
||
*/
|
||
const request = (url, type = "GET", data, isAsync = true,
|
||
success = () => {
|
||
}, error = () => {
|
||
}, complete = () => {
|
||
},
|
||
contentType = 'application/json',
|
||
beforeSend = () => {
|
||
}) => {
|
||
let options = {
|
||
url,
|
||
type,
|
||
dataType: "json",
|
||
contentType,
|
||
async: isAsync,
|
||
data,
|
||
beforeSend,
|
||
success,
|
||
error,
|
||
complete,
|
||
}
|
||
if (contentType === 'application/json') {
|
||
options.data = JSON.stringify(data)
|
||
}
|
||
return $.ajax(options)
|
||
}
|
||
|
||
|
||
/**
|
||
* 转换字段名为字段id
|
||
* @param fieldName 字段名
|
||
* @param detail 表
|
||
* @returns {*} 字段id
|
||
*/
|
||
function convertField2Id(fieldName, detail = "main") {
|
||
return WfForm.convertFieldNameToId(fieldName, detail)
|
||
}
|
||
|
||
/**
|
||
* 绑定字段改变触发
|
||
* @param fieldId 字段ID
|
||
* @param func 处理方法
|
||
*/
|
||
function bindEvent(fieldId, func) {
|
||
WfForm.bindFieldChangeEvent(fieldId, func);
|
||
}
|
||
|
||
/**
|
||
* 更具字段名获取字段值
|
||
* @param fieldName 字段名
|
||
* @param detail 明细表
|
||
* @returns {*}
|
||
*/
|
||
function getValue(fieldName, detail = "main") {
|
||
return WfForm.getFieldValue(convertField2Id(fieldName))
|
||
}
|
||
|
||
|
||
async function getCurrentAmount() {
|
||
let baseInfo = WfForm.getBaseInfo();
|
||
// let dbInfo = WfForm.getFieldInfo(convertField2Id(config.bindFields.channelField).replace("field",""))
|
||
let params = {
|
||
workflowId: baseInfo.workflowid,
|
||
modelTable: "uf_htyetz",
|
||
channelId: getValue(config.query.channelField),
|
||
modelContractAmount: "htje",
|
||
modelCreditAmount: "xyed",
|
||
modelChannelField: "qdbh"
|
||
}
|
||
let result = await request("/api/frozen-calcula/current-amount", "POST", params, false)
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 判断是否需要进行计算口款冻结等操作
|
||
* @param config 配置
|
||
* @returns {boolean}
|
||
*/
|
||
function isNeedCalculate(config) {
|
||
let currentValue = getValue(config.fieldName)
|
||
if (currentValue == config.value) {
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
|
||
/**
|
||
* 判断是否能通过扣款
|
||
* @param config 配置对象
|
||
* @param callback 回调方法
|
||
* @returns {boolean}
|
||
*/
|
||
function isThroughDeduction(config, callback = undefined) {
|
||
let contractAmountValue = getValue(config.contractAmount)
|
||
let creditAmountValue = getValue(config.creditAmount)
|
||
let orderAmountValue = getValue(config.orderAmount)
|
||
let contractAmountNum = parseFloat(contractAmountValue === '' ? '0' : contractAmountValue)
|
||
let creditAmountNum = parseFloat(creditAmountValue === '' ? '0' : creditAmountValue)
|
||
let orderAmountNum = parseFloat(orderAmountValue === '' ? '0' : orderAmountValue)
|
||
if (orderAmountNum > (contractAmountNum + creditAmountNum)) {
|
||
WfForm.showConfirm("请及时充值渠道账户余额和缴纳信用额度!", function () {
|
||
// alert("点击确认调用的事件");
|
||
}, function () {
|
||
// alert("点击取消调用的事件");
|
||
}, {
|
||
title: "余额不足提示!",
|
||
okText: "确认",
|
||
cancelText: "知道了"
|
||
});
|
||
return false
|
||
}
|
||
if (typeof callback === "function") {
|
||
callback()
|
||
} else {
|
||
return true
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 计算金额扣减
|
||
* @param config 配置
|
||
* @param condition 条件配置
|
||
*/
|
||
function calculate(config, condition) {
|
||
if (!isNeedCalculate(condition)) {
|
||
let contractAmountValue = getValue(config.contractAmount)
|
||
let creditAmountValue = getValue(config.creditAmount)
|
||
// 对扣减后字段和冻结字段还原
|
||
WfForm.changeFieldValue(convertField2Id(config.contractBalance), {value: contractAmountValue})
|
||
WfForm.changeFieldValue(convertField2Id(config.creditBalance), {value: creditAmountValue})
|
||
WfForm.changeFieldValue(convertField2Id(config.frozenContractAmount), {value: "0"})
|
||
WfForm.changeFieldValue(convertField2Id(config.frozenCreditAmount), {value: "0"})
|
||
return;
|
||
}
|
||
if (isThroughDeduction(config)) {
|
||
let contractAmountValue = getValue(config.contractAmount)
|
||
let creditAmountValue = getValue(config.creditAmount)
|
||
let orderAmountValue = getValue(config.orderAmount)
|
||
let contractAmountNum = parseFloat(contractAmountValue === '' ? '0' : contractAmountValue)
|
||
let creditAmountNum = parseFloat(creditAmountValue === '' ? '0' : creditAmountValue)
|
||
let orderAmountNum = parseFloat(orderAmountValue === '' ? '0' : orderAmountValue)
|
||
if (contractAmountNum >= orderAmountNum) {
|
||
// TODO 合同金额大于订单金额,直接扣除合同金额
|
||
let otherContractAmountNum = contractAmountNum - orderAmountNum
|
||
// 设置扣减后金额
|
||
WfForm.changeFieldValue(convertField2Id(config.contractBalance), {value: otherContractAmountNum + ""})
|
||
// 设置冻结渠道金额
|
||
WfForm.changeFieldValue(convertField2Id(config.frozenContractAmount), {value: orderAmountNum + ""})
|
||
if (otherContractAmountNum === 0) {
|
||
WfForm.showConfirm("请及时充值渠道账户!", function () {
|
||
// alert("点击确认调用的事件");
|
||
}, function () {
|
||
// alert("点击取消调用的事件");
|
||
}, {
|
||
title: "余额充值提示!",
|
||
okText: "确认",
|
||
cancelText: "知道了"
|
||
});
|
||
}
|
||
return
|
||
}
|
||
// 合同扣款金额不满足扣款,需要使用到信用额度
|
||
// 合同金额剩余0元,给出提,并设置扣减后金额
|
||
WfForm.changeFieldValue(convertField2Id(config.contractBalance), {value: "0"})
|
||
// 设置冻结渠道金额
|
||
WfForm.changeFieldValue(convertField2Id(config.frozenContractAmount), {value: contractAmountNum + ""})
|
||
WfForm.showConfirm("请及时充值渠道账户!", function () {
|
||
// alert("点击确认调用的事件");
|
||
}, function () {
|
||
// alert("点击取消调用的事件");
|
||
}, {
|
||
title: "余额充值提示!",
|
||
okText: "确认",
|
||
cancelText: "知道了"
|
||
});
|
||
let otherOrderAmountNum = orderAmountNum - contractAmountNum
|
||
let otherCreditAmountNum = creditAmountNum - otherOrderAmountNum
|
||
// 设置扣减后信用额度
|
||
WfForm.changeFieldValue(convertField2Id(config.creditBalance), {value: otherCreditAmountNum + ""})
|
||
//设置信用冻结额度
|
||
WfForm.changeFieldValue(convertField2Id(config.frozenCreditAmount), {value: otherOrderAmountNum + ""})
|
||
if (otherCreditAmountNum === 0) {
|
||
// 信用金额余额为0,给出提示
|
||
WfForm.showConfirm("请及时充值渠道账户!", function () {
|
||
// alert("点击确认调用的事件");
|
||
}, function () {
|
||
// alert("点击取消调用的事件");
|
||
}, {
|
||
title: "余额充值提示!",
|
||
okText: "确认",
|
||
cancelText: "知道了"
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
$(() => {
|
||
let fieldIds = convertField2Id(config.calculate.orderAmount)
|
||
fieldIds = fieldIds + "," + convertField2Id(config.bindFields.channelField)
|
||
fieldIds = fieldIds + "," + convertField2Id(config.condition.fieldName)
|
||
bindEvent(fieldIds, (obj, id, value) => {
|
||
calculate(config.calculate, config.condition)
|
||
})
|
||
if (isNeedCalculate(config.condition)) {
|
||
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, function (callback) {
|
||
isThroughDeduction(config.calculate, callback)
|
||
});
|
||
}
|
||
})
|
||
|
||
|
||
//#endregion
|
||
// </editor-fold>(╰_╯)#(╰_╯)#
|