签章流程
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
const { verify } = require("crypto");
|
||||
const {
|
||||
verify
|
||||
} = require("crypto");
|
||||
var CryptoJS = require("crypto-js");
|
||||
var vk; // 全局vk实例
|
||||
// 涉及的表名
|
||||
const dbName = {
|
||||
//test: "vk-test", // 测试表
|
||||
};
|
||||
const dbName = require("../../dao/config.js")
|
||||
|
||||
var db = uniCloud.database(); // 全局数据库引用
|
||||
var _ = db.command; // 数据库操作符
|
||||
@@ -29,7 +29,10 @@ var cloudObject = {
|
||||
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#after-后处理
|
||||
*/
|
||||
_after: async function(options) {
|
||||
let { err, res } = options;
|
||||
let {
|
||||
err,
|
||||
res
|
||||
} = options;
|
||||
if (err) {
|
||||
return; // 如果方法抛出错误,直接return;不处理
|
||||
}
|
||||
@@ -40,11 +43,16 @@ var cloudObject = {
|
||||
* @url client/fadada.getList 前端调用的url参数地址
|
||||
*/
|
||||
getList: async function(data) {
|
||||
let res = { code: 0, msg: '' };
|
||||
let { uid } = this.getClientInfo(); // 获取客户端信息
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
},
|
||||
@@ -53,120 +61,231 @@ var cloudObject = {
|
||||
* @url client/fadada.test 前端调用的url参数地址
|
||||
*/
|
||||
test: async function(data) {
|
||||
|
||||
|
||||
},
|
||||
/**
|
||||
* 实名认证异步通知回调
|
||||
* @param {Object} data
|
||||
*/
|
||||
async pub_verifyNotify(data) {
|
||||
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
||||
const {customerId} = data;
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
const {
|
||||
customerId
|
||||
} = data;
|
||||
// 查询认证结果
|
||||
let user = await vk.baseDao.findByWhereJson({
|
||||
dbName:"uni-id-users",
|
||||
whereJson:{
|
||||
fadadaCustomerId: customerId,
|
||||
}
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
fadadaCustomerId: customerId,
|
||||
}
|
||||
});
|
||||
let res
|
||||
|
||||
if(user.accountType == 1) {
|
||||
|
||||
if (user.accountType == 1) {
|
||||
res = await pubFun.fadada('find_personCertInfo.api', {
|
||||
verified_serialno: user.fadadaVerify.transactionNo
|
||||
})
|
||||
}else {
|
||||
} else {
|
||||
res = await pubFun.fadada('find_companyCertInfo.api', {
|
||||
verified_serialno: user.fadadaVerify.transactionNo
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 认证成功
|
||||
if(res.code == 1) {
|
||||
if (res.code == 1) {
|
||||
await vk.baseDao.setById({
|
||||
dbName:"fadada-verify-record",
|
||||
dataJson:{
|
||||
_id: user._id,
|
||||
...res.data
|
||||
}
|
||||
dbName: "fadada-verify-record",
|
||||
dataJson: {
|
||||
_id: user._id,
|
||||
...res.data
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName:"uni-id-users",
|
||||
id: user._id,
|
||||
dataJson:{
|
||||
person: res.data.person,
|
||||
company: res.data.company,
|
||||
manager: res.data.manager,
|
||||
BankCard: res.data.BankCard,
|
||||
fadadaConfirm: true
|
||||
}
|
||||
dbName: "uni-id-users",
|
||||
id: user._id,
|
||||
dataJson: {
|
||||
person: res.data.person,
|
||||
company: res.data.company,
|
||||
manager: res.data.manager,
|
||||
BankCard: res.data.BankCard,
|
||||
fadadaConfirm: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return res
|
||||
},
|
||||
/**
|
||||
* 合同签署回调处理
|
||||
* @param {Object} data
|
||||
*/
|
||||
async pub_contractNotify(data) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
// 开启事务
|
||||
const transaction = await vk.baseDao.startTransaction();
|
||||
|
||||
const {
|
||||
transaction_id,
|
||||
contract_id,
|
||||
timestamp,
|
||||
result_code,
|
||||
download_url,
|
||||
viewpdf_url
|
||||
} = data
|
||||
try {
|
||||
if (result_code == '3000') {
|
||||
// 获取用户信息
|
||||
const userContract = await vk.daoCenter.userContractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
transactionId: transaction_id,
|
||||
sign: false
|
||||
},
|
||||
dataJson: {
|
||||
sign: true
|
||||
}
|
||||
})
|
||||
|
||||
let contract = await vk.daoCenter.contractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
_id: userContract.contractId,
|
||||
status: 1,
|
||||
|
||||
},
|
||||
dataJson: {
|
||||
signCount: _.inc(1),
|
||||
contractHistory: _.push(download_url)
|
||||
}
|
||||
})
|
||||
|
||||
if (contract.signCount == contract.partyCount) {
|
||||
contract = await vk.daoCenter.contractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
_id: userContract.contractId,
|
||||
status: 1
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
await transaction.commit();
|
||||
} catch (e) {
|
||||
await transaction.rollback();
|
||||
return false
|
||||
}
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* 获取用户认证结果
|
||||
*/
|
||||
async getVerifyResult() {
|
||||
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
||||
let res = { code: 0, msg: '' };
|
||||
let { uid } = this.getClientInfo(); // 获取客户端信息
|
||||
let {accountType,fadadaCustomerId} = await this.getUserInfo();
|
||||
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
let {
|
||||
accountType,
|
||||
fadadaCustomerId
|
||||
} = await this.getUserInfo();
|
||||
|
||||
res.data = await vk.baseDao.findById({
|
||||
dbName:"fadada-verify-record",
|
||||
id: uid
|
||||
dbName: "fadada-verify-record",
|
||||
id: uid
|
||||
});
|
||||
|
||||
|
||||
|
||||
return res
|
||||
},
|
||||
/**
|
||||
* 获取实名认证地址
|
||||
*/
|
||||
async getVerifyUrl() {
|
||||
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
||||
let res = { code: 0, msg: '' };
|
||||
let { uid } = this.getClientInfo(); // 获取客户端信息
|
||||
let {accountType,fadadaCustomerId, fadadaVerify} = await this.getUserInfo();
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
let {
|
||||
accountType,
|
||||
fadadaCustomerId,
|
||||
fadadaVerify
|
||||
} = await this.getUserInfo();
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
if(fadadaVerify) {
|
||||
|
||||
if (fadadaVerify) {
|
||||
res.data = fadadaVerify
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
let verify_url_res ;
|
||||
|
||||
if(accountType === 1) {
|
||||
|
||||
|
||||
let verify_url_res;
|
||||
|
||||
if (accountType === 1) {
|
||||
verify_url_res = await pubFun.fadada('get_person_verify_url.api', {
|
||||
customer_id: fadadaCustomerId,
|
||||
verified_way: 2,
|
||||
page_modify: 1,
|
||||
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify'
|
||||
|
||||
cert_flag: 1,
|
||||
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify',
|
||||
return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/user/user?menu=fadada'
|
||||
|
||||
})
|
||||
}else {
|
||||
} else {
|
||||
verify_url_res = await pubFun.fadada('get_company_verify_url.api', {
|
||||
customer_id: fadadaCustomerId,
|
||||
page_modify: 1,
|
||||
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify'
|
||||
cert_flag: 1,
|
||||
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify',
|
||||
return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/user/user?menu=fadada'
|
||||
})
|
||||
console.log(': ',);
|
||||
console.log(': ', );
|
||||
}
|
||||
|
||||
console.log('verify_url_res: ',verify_url_res);
|
||||
let {transactionNo, url} = verify_url_res.data
|
||||
|
||||
console.log('verify_url_res: ', verify_url_res);
|
||||
let {
|
||||
transactionNo,
|
||||
url
|
||||
} = verify_url_res.data
|
||||
var parsedWordArray = CryptoJS.enc.Base64.parse(url);
|
||||
url = parsedWordArray.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
|
||||
await vk.baseDao.update({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
@@ -179,18 +298,71 @@ var cloudObject = {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
res.data = {
|
||||
transactionNo,
|
||||
url
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = cloudObject;
|
||||
},
|
||||
/**
|
||||
* 调用此接口将customer_id与实名交易号进行绑定,
|
||||
* 绑定成功后该customer_id无法再次绑定其它不同主体认证交易号。
|
||||
* 必须绑定成功后续才可发起签署
|
||||
*/
|
||||
async applyCert({
|
||||
customerId,
|
||||
transactionNo
|
||||
}) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
},
|
||||
async generateContract() {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
const contract_id = vk.pubfn.createOrderNo("Contract", 25);
|
||||
const parameter_map = {
|
||||
saler: '网宿科技'
|
||||
};
|
||||
const dynamic_tables = [{
|
||||
headers: ["采购商品", "采购数量", "商品单位"], //表头,
|
||||
datas: [
|
||||
["螺纹钢", "200", "米"]
|
||||
],
|
||||
pageBegin: -1
|
||||
}]
|
||||
const params = {
|
||||
template_id: 'sale',
|
||||
doc_title: '测试买卖合同',
|
||||
contract_id: contract_id,
|
||||
fill_type: 0, // 填充类型 0 pdf 模板、1 在线填充模板
|
||||
parameter_map: JSON.stringify(parameter_map), //填充内容
|
||||
dynamic_tables: JSON.stringify(dynamic_tables), //填充表格
|
||||
}
|
||||
console.log(params);
|
||||
res.data = await pubFun.fadada('generate_contract.api', params)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = cloudObject;
|
||||
Reference in New Issue
Block a user