368 lines
8.0 KiB
JavaScript
368 lines
8.0 KiB
JavaScript
'use strict';
|
|
const {
|
|
verify
|
|
} = require("crypto");
|
|
var CryptoJS = require("crypto-js");
|
|
var vk; // 全局vk实例
|
|
// 涉及的表名
|
|
const dbName = require("../../dao/config.js")
|
|
|
|
var db = uniCloud.database(); // 全局数据库引用
|
|
var _ = db.command; // 数据库操作符
|
|
var $ = _.aggregate; // 聚合查询操作符
|
|
/**
|
|
* 权限注意:访问以下链接查看
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#内置权限
|
|
*/
|
|
var cloudObject = {
|
|
isCloudObject: true, // 标记为云对象模式
|
|
/**
|
|
* 请求前处理,主要用于调用方法之前进行预处理,一般用于拦截器、统一的身份验证、参数校验、定义全局对象等。
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#before-预处理
|
|
*/
|
|
_before: async function() {
|
|
vk = this.vk; // 将vk定义为全局对象
|
|
// let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
|
},
|
|
/**
|
|
* 请求后处理,主要用于处理本次调用方法的返回结果或者抛出的错误
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#after-后处理
|
|
*/
|
|
_after: async function(options) {
|
|
let {
|
|
err,
|
|
res
|
|
} = options;
|
|
if (err) {
|
|
return; // 如果方法抛出错误,直接return;不处理
|
|
}
|
|
return res;
|
|
},
|
|
/**
|
|
* 获取列表
|
|
* @url client/fadada.getList 前端调用的url参数地址
|
|
*/
|
|
getList: async function(data) {
|
|
let res = {
|
|
code: 0,
|
|
msg: ''
|
|
};
|
|
let {
|
|
uid
|
|
} = this.getClientInfo(); // 获取客户端信息
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
|
|
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
},
|
|
/**
|
|
* 模板函数
|
|
* @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 user = await vk.baseDao.findByWhereJson({
|
|
dbName: "uni-id-users",
|
|
whereJson: {
|
|
fadadaCustomerId: customerId,
|
|
}
|
|
});
|
|
let res
|
|
|
|
if (user.accountType == 1) {
|
|
res = await pubFun.fadada('find_personCertInfo.api', {
|
|
verified_serialno: user.fadadaVerify.transactionNo
|
|
})
|
|
} else {
|
|
res = await pubFun.fadada('find_companyCertInfo.api', {
|
|
verified_serialno: user.fadadaVerify.transactionNo
|
|
})
|
|
}
|
|
|
|
|
|
|
|
// 认证成功
|
|
if (res.code == 1) {
|
|
await vk.baseDao.setById({
|
|
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
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
res.data = await vk.baseDao.findById({
|
|
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();
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
|
|
if (fadadaVerify) {
|
|
res.data = fadadaVerify
|
|
return res;
|
|
}
|
|
|
|
|
|
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,
|
|
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 {
|
|
verify_url_res = await pubFun.fadada('get_company_verify_url.api', {
|
|
customer_id: fadadaCustomerId,
|
|
page_modify: 1,
|
|
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('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: {
|
|
_id: uid
|
|
},
|
|
dataJson: {
|
|
fadadaVerify: {
|
|
transactionNo,
|
|
url
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
res.data = {
|
|
transactionNo,
|
|
url
|
|
}
|
|
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
|
|
},
|
|
/**
|
|
* 调用此接口将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; |