Commit c67f3efe by 赵庆

gsb

parent 949f56c4
# Default ignored files
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/bpo-web.iml" filepath="$PROJECT_DIR$/.idea/bpo-web.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -2,1263 +2,1269 @@ var system = require("../../system") ...@@ -2,1263 +2,1269 @@ var system = require("../../system")
const md5 = require("MD5"); const md5 = require("MD5");
const logCtl = system.getObject("web.oplogCtl"); const logCtl = system.getObject("web.oplogCtl");
const moment = require("moment"); const moment = require("moment");
class EcontractApi { class EcontractApi {
constructor() { constructor() {
this.ecompanySve = system.getObject("service.ecompanySve"); this.ecompanySve = system.getObject("service.ecompanySve");
this.econtractSve = system.getObject("service.econtractSve"); this.econtractSve = system.getObject("service.econtractSve");
this.etemplateSve = system.getObject("service.etemplateSve"); this.etemplateSve = system.getObject("service.etemplateSve");
this.utilesignbaoSve = system.getObject("service.utilesignbaoSve"); this.utilesignbaoSve = system.getObject("service.utilesignbaoSve");
this.ecompanybusiSve = system.getObject("service.ecompanybusiSve");
this.ecompanywxuserSve = system.getObject("service.ecompanywxuserSve");
this.ecompanybpoSve = system.getObject("service.ecompanybpoSve");
this.usereaccountSve = system.getObject("service.usereaccountSve");
this.wxSve = system.getObject("service.wxSve");
this.esettleSve = system.getObject("service.esettleSve");
this.bankthreelogSve = system.getObject("service.bankthreelogSve");
this.bankthreelog2Sve = system.getObject("service.bankthreelog2Sve");
this.restClient = system.getObject("util.restClient");
this.smsS = system.getObject("util.smsClient");
}
async syncSignedFile() {
this.econtractSve.downloadCompleteUrl();
return "start success"
}
async importECompany(obj) {
console.log(obj, "===================>>>>>>>>>>>>>>>>>>>>>");
var names = obj.companyNames;
var nameA = obj.nameA || '智信云(天津)科技有限公司';
var encryptkey = obj.encryptkey;
var posturl = obj.posturl;
var etemplate = await this.etemplateSve.findById(Number(obj.etemplateId || 0));
if (!etemplate) {
return 0;
}
for (var name of names) { this.ecompanybusiSve = system.getObject("service.ecompanybusiSve");
try {
console.log("========== import ecompany : " + name); this.ecompanywxuserSve = system.getObject("service.ecompanywxuserSve");
let rs = await this.ecompanySve.importCompany(name, nameA, encryptkey, posturl, etemplate); this.ecompanybpoSve = system.getObject("service.ecompanybpoSve");
} catch (e) {
console.log(e); this.usereaccountSve = system.getObject("service.usereaccountSve");
}
}
return 1;
}
async testpushContract(obj, req) {
var ids = obj.ids || [];
for (var id of ids) {
// this.econtractSve.syncSign(67854);
await this.econtractSve.syncSign(id);
}
}
async pushwxuser(obj, req) {
var ids = obj.ids || [];
var result = [];
for (var id of ids) {
// this.econtractSve.syncSign(67854);
try {
var rs = await this.ecompanywxuserSve.pushwxuser(id);
result.push(rs);
} catch (error) {
result.push(error.msg);
}
}
return result;
}
async validContract(obj, req) {
// 验证合法性
var companyName = obj.companyName;
var idCardList = obj.idCardList;
var sign = md5("companyName=" + companyName + "&nonceStr=" + obj.nonceStr + "&key=wxf616c0a459d66081").toUpperCase();
if (sign != obj.sign) {
return {
code: 1,
msg: "签名失败"
};
}
//日志记录 this.wxSve = system.getObject("service.wxSve");
if (!idCardList || idCardList.length == 0) { this.esettleSve = system.getObject("service.esettleSve");
return {
code: 0, this.bankthreelogSve = system.getObject("service.bankthreelogSve");
msg: "success", this.bankthreelog2Sve = system.getObject("service.bankthreelog2Sve");
signedList: [],
unSignList: [] this.restClient = system.getObject("util.restClient");
}; this.smsS = system.getObject("util.smsClient");
} }
var ecompany = await this.ecompanySve.findOne({ async syncSignedFile() {
name: companyName this.econtractSve.downloadCompleteUrl();
}); return "start success"
if (!ecompany) {
return {
code: 1,
msg: "公司不存在"
};
} }
try { async importECompany(obj) {
var signedList = await this.econtractSve.fiterSignedCards(ecompany.id, idCardList); console.log(obj, "===================>>>>>>>>>>>>>>>>>>>>>");
var unSignList = []; var names = obj.companyNames;
for (var ic of idCardList) { var nameA = obj.nameA || '智信云(天津)科技有限公司';
if (signedList.indexOf(ic) == -1) { var encryptkey = obj.encryptkey;
unSignList.push(ic); var posturl = obj.posturl;
var etemplate = await this.etemplateSve.findById(Number(obj.etemplateId || 0));
if (!etemplate) {
return 0;
} }
}
var result = { for (var name of names) {
code: 0, try {
msg: "success", console.log("========== import ecompany : " + name);
}; let rs = await this.ecompanySve.importCompany(name, nameA, encryptkey, posturl, etemplate);
result.signedList = signedList; } catch (e) {
result.unSignList = unSignList; console.log(e);
return result; }
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
async transferNotify(obj, req) {
this.econtractSve.testtransfer(obj);
}
async contractcb(obj, req) {
this.econtractSve.updateCallbackStatus(obj);
}
async synctemplate(obj, req) {
for (var id = 1; id <= 514; id++) {
try {
var template = await this.etemplateSve.findById(id);
if (!template) {
continue;
} }
template.qrcodeurl = await this.wxSve.makeQrWithScene("wxf616c0a459d66081", template.id); return 1;
await template.save();
} catch (error) {
console.log(error);
}
} }
for (var id = 10000; id <= 10100; id++) { async testpushContract(obj, req) {
try { var ids = obj.ids || [];
var template = await this.etemplateSve.findById(id); for (var id of ids) {
if (!template) { // this.econtractSve.syncSign(67854);
continue; await this.econtractSve.syncSign(id);
} }
template.qrcodeurl = await this.wxSve.makeQrWithScene("wxf616c0a459d66081", template.id);
await template.save();
} catch (error) {
console.log(error);
}
}
}
async sinedUsers(obj, req) {
// 验证合法性
var appId = obj.appId;
var nonceStr = obj.nonceStr;
var idNo = obj.idNo;
var startId = obj.startId || 0;
var userId = obj.userId || "";
var userCode = obj.userCode || "";
var branchCode = obj.branchCode || "";
var pageSize = 20;
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
} }
var signArr = []; async pushwxuser(obj, req) {
signArr.push("appId=" + appId); var ids = obj.ids || [];
signArr.push("branchCode=" + branchCode); var result = [];
signArr.push("idNo=" + idNo); for (var id of ids) {
signArr.push("nonceStr=" + nonceStr); // this.econtractSve.syncSign(67854);
signArr.push("startId=" + startId); try {
signArr.push("userCode=" + userCode); var rs = await this.ecompanywxuserSve.pushwxuser(id);
signArr.push("userId=" + userId); result.push(rs);
signArr.push("key=" + busi.key); } catch (error) {
result.push(error.msg);
var sign = md5(signArr.join("&")).toUpperCase(); }
if (sign != obj.sign) { }
return { return result;
code: 1001001,
msg: "签名失败"
};
} }
var params = {
ecompanyId: busi.ecompany_id,
startId: startId,
idNo: idNo,
pageSize: pageSize,
userId3rd: userId,
userCode3rd: userCode,
branchCode3rd: branchCode,
};
try { async validContract(obj, req) {
var userList = await this.econtractSve.findSignedUses4Push(params); // 验证合法性
var companyName = obj.companyName;
var result = { var idCardList = obj.idCardList;
code: 0,
msg: "success", var sign = md5("companyName=" + companyName + "&nonceStr=" + obj.nonceStr + "&key=wxf616c0a459d66081").toUpperCase();
}; if (sign != obj.sign) {
result.data = userList; return {
return result; code: 1,
} catch (e) { msg: "签名失败"
var result = { };
code: 500, }
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
async sinedUsers3rd(obj, req) {
// 验证合法性
var appId = obj.appId;
var nonceStr = obj.nonceStr;
var idNo = obj.idNo;
var startId = obj.startId || 0;
var userId = obj.userId || "";
var pageSize = 20;
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
}
var signArr = []; //日志记录
signArr.push("appId=" + appId); if (!idCardList || idCardList.length == 0) {
signArr.push("idNo=" + idNo); return {
signArr.push("nonceStr=" + nonceStr); code: 0,
signArr.push("startId=" + startId); msg: "success",
signArr.push("userId=" + userId); signedList: [],
signArr.push("key=" + busi.key); unSignList: []
};
var sign = md5(signArr.join("&")).toUpperCase(); }
if (sign != obj.sign) {
return {
code: 1001001,
msg: "签名失败"
};
}
var params = {
ecompanyId: busi.ecompany_id,
startId: startId,
idNo: idNo,
pageSize: pageSize,
userId3rd: userId,
};
try { var ecompany = await this.ecompanySve.findOne({
var userList = await this.econtractSve.findSignedUses4Push(params); name: companyName
});
var result = { if (!ecompany) {
code: 0, return {
msg: "success", code: 1,
}; msg: "公司不存在"
result.data = userList; };
return result; }
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
async sinedList(obj, req) {
// 验证合法性
var companyName = obj.companyName;
var startId = obj.startId || 0;
var pageSize = obj.pageSize || 20;
var sign = md5("companyName=" + companyName + "&nonceStr=" + obj.nonceStr + "&startId=" + startId + "&key=wxf616c0a459d66081").toUpperCase();
if (sign != obj.sign) {
return {
code: 1,
msg: "签名失败"
};
}
var ecompany = await this.ecompanySve.findOne({ try {
name: companyName var signedList = await this.econtractSve.fiterSignedCards(ecompany.id, idCardList);
}); var unSignList = [];
if (!ecompany) { for (var ic of idCardList) {
return { if (signedList.indexOf(ic) == -1) {
code: 1, unSignList.push(ic);
msg: "公司不存在" }
}; }
var result = {
code: 0,
msg: "success",
};
result.signedList = signedList;
result.unSignList = unSignList;
return result;
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
} }
try { async transferNotify(obj, req) {
var userList = await this.econtractSve.findSignedUsers(ecompany.id, startId, pageSize); this.econtractSve.testtransfer(obj);
var result = {
code: 0,
msg: "success",
};
result.data = userList;
return result;
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
async bankthreeItem(item) {
var bankthreelog2 = {
idName: item.idName,
idNo: item.idNo,
bankno: item.bankno,
pass: false,
} }
try {
var bankthreeParams = {
name: item.idName, //姓名 必填
idno: item.idNo, //身份证 必填
cardno: item.bankno //银行卡 必填
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "econtractapi.bankthreeBatch") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
if (tt.code == 1) {
bankthreelog2.pass = true;
} else if (tt.code == -110) {
bankthreelog2.remark = tt.message;
} else {
bankthreelog2.remark = "银行三要素验证失败";
}
} catch (error) {
bankthreelog2.remark = "接口异常";
}
await this.bankthreelog2Sve.create(bankthreelog2);
}
async bankthreeBatch(obj, req) { async contractcb(obj, req) {
var list = obj || []; this.econtractSve.updateCallbackStatus(obj);
for (var item of list) {
await this.bankthreeItem(item);
} }
}
async bankthree(obj, req) {
try {
var appId = obj.appId;
var userName = obj.userName || "";
var userIdNo = obj.userIdNo || "";
var userBankNo = obj.userBankNo || "";
var nonceStr = obj.nonceStr || "";
var sign = obj.sign || "";
var btl = await this.bankthreelogSve.create({
appId: appId,
userName: userName,
userIdNo: userIdNo,
userBankNo: userBankNo,
nonceStr: nonceStr,
sign: sign,
use_esign: false,
result: false,
});
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
}
var signArr = [];
signArr.push("appId=" + appId);
signArr.push("nonceStr=" + nonceStr);
signArr.push("userBankNo=" + userBankNo);
signArr.push("userIdNo=" + userIdNo);
signArr.push("userName=" + userName);
signArr.push("key=" + busi.key);
var calcSign = md5(signArr.join("&")).toUpperCase();
if (sign != calcSign) {
return {
code: 1,
msg: "签名失败"
};
}
// 验证电子签 async synctemplate(obj, req) {
var list = await this.econtractSve.findSinedByThree(userName, userIdNo, userBankNo); for (var id = 1; id <= 514; id++) {
if (list.length > 0) { try {
btl.result = true; var template = await this.etemplateSve.findById(id);
btl.save(); if (!template) {
return { continue;
code: 0, }
msg: "success" template.qrcodeurl = await this.wxSve.makeQrWithScene("wxf616c0a459d66081", template.id);
}; await template.save();
} } catch (error) {
console.log(error);
var bankthreeParams = { }
name: userName, //姓名 必填 }
idno: userIdNo, //身份证 必填
cardno: userBankNo //银行卡 必填 for (var id = 10000; id <= 10100; id++) {
}; try {
var template = await this.etemplateSve.findById(id);
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "econtractapi.bankthree") || {}; if (!template) {
// {"code":-110,"message":"手机号格式错误","data":{}} continue;
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试! }
console.log("tt-----------------------------", tt); template.qrcodeurl = await this.wxSve.makeQrWithScene("wxf616c0a459d66081", template.id);
btl.use_esign = true; await template.save();
if (tt.code == 1) { } catch (error) {
btl.result = true; console.log(error);
btl.save(); }
return { }
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message
};
} else {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: "银行三要素验证失败"
};
}
} catch (error) {
return {
code: 500,
msg: "接口异常"
};
} }
}
async sinedUsers(obj, req) {
async bankfour(obj, req) { // 验证合法性
try { var appId = obj.appId;
var appId = obj.appId; var nonceStr = obj.nonceStr;
var userName = obj.userName || ""; var idNo = obj.idNo;
var userIdNo = obj.userIdNo || ""; var startId = obj.startId || 0;
var userBankNo = obj.userBankNo || ""; var userId = obj.userId || "";
var userMobile = obj.userMobile || ""; var userCode = obj.userCode || "";
var nonceStr = obj.nonceStr || ""; var branchCode = obj.branchCode || "";
var pageSize = 20;
var sign = obj.sign || "";
var btl = await this.bankthreelogSve.create({ var busi = await this.ecompanybusiSve.findOne({
appId: appId, appId: appId
userName: userName, });
userIdNo: userIdNo, if (!busi) {
userBankNo: userBankNo, return {
userMobile: userMobile, code: 1001003,
nonceStr: nonceStr, msg: "配置信息错误,请联系薪必果人员进行配置"
sign: sign, };
use_esign: false, }
result: false,
}); var signArr = [];
signArr.push("appId=" + appId);
var busi = await this.ecompanybusiSve.findOne({ signArr.push("branchCode=" + branchCode);
appId: appId signArr.push("idNo=" + idNo);
}); signArr.push("nonceStr=" + nonceStr);
if (!busi) { signArr.push("startId=" + startId);
return { signArr.push("userCode=" + userCode);
code: 1001003, signArr.push("userId=" + userId);
msg: "配置信息错误,请联系薪必果人员进行配置" signArr.push("key=" + busi.key);
};
} var sign = md5(signArr.join("&")).toUpperCase();
if (sign != obj.sign) {
var signArr = []; return {
signArr.push("appId=" + appId); code: 1001001,
signArr.push("nonceStr=" + nonceStr); msg: "签名失败"
signArr.push("userBankNo=" + userBankNo); };
signArr.push("userIdNo=" + userIdNo); }
signArr.push("userMobile=" + userMobile); var params = {
signArr.push("userName=" + userName); ecompanyId: busi.ecompany_id,
signArr.push("key=" + busi.key); startId: startId,
var calcSign = md5(signArr.join("&")).toUpperCase(); idNo: idNo,
if (sign != calcSign) { pageSize: pageSize,
return { userId3rd: userId,
code: 1, userCode3rd: userCode,
msg: "签名失败" branchCode3rd: branchCode,
};
}
var bankParams = {
name: userName, //姓名 必填
idno: userIdNo, //身份证 必填
cardno: userBankNo, //银行卡 必填
mobile: userMobile,
};
var tt = await this.utilesignbaoSve.bankfour(bankParams, "econtractapi.bankthree") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
btl.use_esign = true;
if (tt.code == 1) {
btl.result = true;
btl.save();
return {
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message
};
} else {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message || "银行四要素验证失败"
}; };
}
} catch (error) { try {
return { var userList = await this.econtractSve.findSignedUses4Push(params);
code: 500,
msg: "接口异常" var result = {
}; code: 0,
msg: "success",
};
result.data = userList;
return result;
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
} }
}
async sinedUsers3rd(obj, req) {
async bankfourTest(obj, req) { // 验证合法性
try { var appId = obj.appId;
var appId = obj.appId; var nonceStr = obj.nonceStr;
var userName = obj.userName || ""; var idNo = obj.idNo;
var userIdNo = obj.userIdNo || ""; var startId = obj.startId || 0;
var userBankNo = obj.userBankNo || ""; var userId = obj.userId || "";
var userMobile = obj.userMobile || ""; var pageSize = 20;
var nonceStr = obj.nonceStr || "";
var busi = await this.ecompanybusiSve.findOne({
var sign = obj.sign || ""; appId: appId
var btl = await this.bankthreelogSve.create({ });
appId: appId, if (!busi) {
userName: userName, return {
userIdNo: userIdNo, code: 1001003,
userBankNo: userBankNo, msg: "配置信息错误,请联系薪必果人员进行配置"
userMobile: userMobile, };
nonceStr: nonceStr, }
sign: sign,
use_esign: false, var signArr = [];
result: false, signArr.push("appId=" + appId);
}); signArr.push("idNo=" + idNo);
signArr.push("nonceStr=" + nonceStr);
var busi = await this.ecompanybusiSve.findOne({ signArr.push("startId=" + startId);
appId: appId signArr.push("userId=" + userId);
}); signArr.push("key=" + busi.key);
if (!busi) {
return { var sign = md5(signArr.join("&")).toUpperCase();
code: 1001003, if (sign != obj.sign) {
msg: "配置信息错误,请联系薪必果人员进行配置" return {
}; code: 1001001,
} msg: "签名失败"
};
var signArr = []; }
signArr.push("appId=" + appId); var params = {
signArr.push("nonceStr=" + nonceStr); ecompanyId: busi.ecompany_id,
signArr.push("userBankNo=" + userBankNo); startId: startId,
signArr.push("userIdNo=" + userIdNo); idNo: idNo,
signArr.push("userMobile=" + userMobile); pageSize: pageSize,
signArr.push("userName=" + userName); userId3rd: userId,
signArr.push("key=" + busi.key);
var calcSign = md5(signArr.join("&")).toUpperCase();
if (sign != calcSign) {
return {
code: 1,
msg: "签名失败"
}; };
}
var bankParams = {
name: userName, //姓名 必填
idno: userIdNo, //身份证 必填
cardno: userBankNo, //银行卡 必填
mobile: userMobile,
};
// var tt = await this.utilesignbaoSve.bankfour(bankParams, "econtractapi.bankthree") || {};
var tt = {code: 1};
return {
code: 0,
msg: "success"
};
} catch (error) {
return {
code: 500,
msg: "接口异常"
};
}
}
async dosync(obj, req) {
// TODO 需要验证一下合法
this.econtractSve.syncAllSigners();
return 1;
}
async dosync(obj, req) {
// TODO 需要验证一下合法
this.econtractSve.syncAllSigners();
return 1;
}
async testinsure() {
this.econtractSve.sendInsure(61094);
}
async ydsignnumber() {
return this.econtractSve.ydsignnumber();
}
returnjson(code, msg, data) {
return {
code: code,
msg: msg,
data: data || null
}
}
async autoSign(pobj) {
// 处理参数
var param = {
ecid: this.trim(pobj.ecid),
appId: this.trim(pobj.appId),
userId: this.trim(pobj.userId),
idName: this.trim(pobj.idName),
mobile: this.trim(pobj.mobile),
idNo: this.trim(pobj.idNo),
bankno: this.trim(pobj.bankno),
nonceStr: this.trim(pobj.nonceStr),
sign: this.trim(pobj.sign)
}
if (!param.ecid) { try {
return this.returnjson(-1, "请传入薪必果提供的ecid") var userList = await this.econtractSve.findSignedUses4Push(params);
}
if (!param.appId) { var result = {
return this.returnjson(-1, "请传入薪必果提供的appId") code: 0,
} msg: "success",
if (!param.userId) { };
return this.returnjson(-1, "请提供该用户的userId") result.data = userList;
} return result;
if (!param.idName) { } catch (e) {
return this.returnjson(-1, "请提供该用户姓名") var result = {
} code: 500,
if (!param.idNo) { msg: "接口异常"
return this.returnjson(-1, "请提供该用户身份证号") };
} console.log(e.stack);
if (!param.bankno) { //日志记录
return this.returnjson(-1, "请提供该用户银行卡号") logCtl.error({
} optitle: "校验是否签约error",
if (!param.nonceStr) { op: "api/econtractApi/validContract",
return this.returnjson(-1, "请提供随机码") content: e.stack,
clientIp: req.clientIp
});
return result;
}
} }
// 查appId关联key async sinedList(obj, req) {
var busi = await this.ecompanybusiSve.findOne({ // 验证合法性
appId: param.appId var companyName = obj.companyName;
}); var startId = obj.startId || 0;
if (!busi || !busi.key) { var pageSize = obj.pageSize || 20;
return this.returnjson(1001003, "配置信息错误,请联系薪必果人员进行配置");
} var sign = md5("companyName=" + companyName + "&nonceStr=" + obj.nonceStr + "&startId=" + startId + "&key=wxf616c0a459d66081").toUpperCase();
if (sign != obj.sign) {
return {
code: 1,
msg: "签名失败"
};
}
// 签名 var ecompany = await this.ecompanySve.findOne({
var signArr = []; name: companyName
var keys = Object.keys(param).sort(); });
for (var i = 0; i < keys.length; i++) { if (!ecompany) {
var k = keys[i]; return {
var v = param[k]; code: 1,
if (!k || !v || k == 'sign') { msg: "公司不存在"
continue; };
} }
signArr.push(k + "=" + v);
}
var signStr = signArr.join("&") + "&key=" + busi.key;
var sign = md5(signStr).toUpperCase();
if (param.sign != sign) {
return this.returnjson(1001001, "签名错误");
}
try { try {
var result = await this.econtractSve.autoSign(param); var userList = await this.econtractSve.findSignedUsers(ecompany.id, startId, pageSize);
return result;
} catch (error) { var result = {
console.log(error); code: 0,
} msg: "success",
} };
result.data = userList;
async autoSignTest(pobj) { return result;
// 处理参数 } catch (e) {
var param = { var result = {
ecid: this.trim(pobj.ecid), code: 500,
appId: this.trim(pobj.appId), msg: "接口异常"
userId: this.trim(pobj.userId), };
idName: this.trim(pobj.idName), console.log(e.stack);
mobile: this.trim(pobj.mobile), //日志记录
idNo: this.trim(pobj.idNo), logCtl.error({
bankno: this.trim(pobj.bankno), optitle: "校验是否签约error",
nonceStr: this.trim(pobj.nonceStr), op: "api/econtractApi/validContract",
sign: this.trim(pobj.sign) content: e.stack,
clientIp: req.clientIp
});
return result;
}
} }
if (!param.ecid) { async bankthreeItem(item) {
return this.returnjson(-1, "请传入薪必果提供的ecid") var bankthreelog2 = {
} idName: item.idName,
if (!param.appId) { idNo: item.idNo,
return this.returnjson(-1, "请传入薪必果提供的appId") bankno: item.bankno,
} pass: false,
if (!param.userId) { }
return this.returnjson(-1, "请提供该用户的userId") try {
} var bankthreeParams = {
if (!param.idName) { name: item.idName, //姓名 必填
return this.returnjson(-1, "请提供该用户姓名") idno: item.idNo, //身份证 必填
cardno: item.bankno //银行卡 必填
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "econtractapi.bankthreeBatch") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
if (tt.code == 1) {
bankthreelog2.pass = true;
} else if (tt.code == -110) {
bankthreelog2.remark = tt.message;
} else {
bankthreelog2.remark = "银行三要素验证失败";
}
} catch (error) {
bankthreelog2.remark = "接口异常";
}
await this.bankthreelog2Sve.create(bankthreelog2);
} }
if (!param.idNo) {
return this.returnjson(-1, "请提供该用户身份证号") async bankthreeBatch(obj, req) {
var list = obj || [];
for (var item of list) {
await this.bankthreeItem(item);
}
} }
if (!param.bankno) {
return this.returnjson(-1, "请提供该用户银行卡号") async bankthree(obj, req) {
try {
var appId = obj.appId;
var userName = obj.userName || "";
var userIdNo = obj.userIdNo || "";
var userBankNo = obj.userBankNo || "";
var nonceStr = obj.nonceStr || "";
var sign = obj.sign || "";
var btl = await this.bankthreelogSve.create({
appId: appId,
userName: userName,
userIdNo: userIdNo,
userBankNo: userBankNo,
nonceStr: nonceStr,
sign: sign,
use_esign: false,
result: false,
});
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
}
var signArr = [];
signArr.push("appId=" + appId);
signArr.push("nonceStr=" + nonceStr);
signArr.push("userBankNo=" + userBankNo);
signArr.push("userIdNo=" + userIdNo);
signArr.push("userName=" + userName);
signArr.push("key=" + busi.key);
var calcSign = md5(signArr.join("&")).toUpperCase();
if (sign != calcSign) {
return {
code: 1,
msg: "签名失败"
};
}
// 验证电子签
var list = await this.econtractSve.findSinedByThree(userName, userIdNo, userBankNo);
if (list.length > 0) {
btl.result = true;
btl.save();
return {
code: 0,
msg: "success"
};
}
var bankthreeParams = {
name: userName, //姓名 必填
idno: userIdNo, //身份证 必填
cardno: userBankNo //银行卡 必填
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "econtractapi.bankthree") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
btl.use_esign = true;
if (tt.code == 1) {
btl.result = true;
btl.save();
return {
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message
};
} else {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: "银行三要素验证失败"
};
}
} catch (error) {
return {
code: 500,
msg: "接口异常"
};
}
} }
if (!param.nonceStr) {
return this.returnjson(-1, "请提供随机码") async bankfour(obj, req) {
try {
var appId = obj.appId;
var userName = obj.userName || "";
var userIdNo = obj.userIdNo || "";
var userBankNo = obj.userBankNo || "";
var userMobile = obj.userMobile || "";
var nonceStr = obj.nonceStr || "";
var sign = obj.sign || "";
var btl = await this.bankthreelogSve.create({
appId: appId,
userName: userName,
userIdNo: userIdNo,
userBankNo: userBankNo,
userMobile: userMobile,
nonceStr: nonceStr,
sign: sign,
use_esign: false,
result: false,
});
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
}
var signArr = [];
signArr.push("appId=" + appId);
signArr.push("nonceStr=" + nonceStr);
signArr.push("userBankNo=" + userBankNo);
signArr.push("userIdNo=" + userIdNo);
signArr.push("userMobile=" + userMobile);
signArr.push("userName=" + userName);
signArr.push("key=" + busi.key);
var calcSign = md5(signArr.join("&")).toUpperCase();
if (sign != calcSign) {
return {
code: 1,
msg: "签名失败"
};
}
var bankParams = {
name: userName, //姓名 必填
idno: userIdNo, //身份证 必填
cardno: userBankNo, //银行卡 必填
mobile: userMobile,
};
var tt = await this.utilesignbaoSve.bankfour(bankParams, "econtractapi.bankthree") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
btl.use_esign = true;
if (tt.code == 1) {
btl.result = true;
btl.save();
return {
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message
};
} else {
btl.result = false;
btl.save();
return {
code: 1002002,
msg: tt.message || "银行四要素验证失败"
};
}
} catch (error) {
return {
code: 500,
msg: "接口异常"
};
}
} }
// 查appId关联key async bankfourTest(obj, req) {
var busi = await this.ecompanybusiSve.findOne({ try {
appId: param.appId var appId = obj.appId;
}); var userName = obj.userName || "";
if (!busi || !busi.key) { var userIdNo = obj.userIdNo || "";
return this.returnjson(1001003, "配置信息错误,请联系薪必果人员进行配置"); var userBankNo = obj.userBankNo || "";
var userMobile = obj.userMobile || "";
var nonceStr = obj.nonceStr || "";
var sign = obj.sign || "";
var btl = await this.bankthreelogSve.create({
appId: appId,
userName: userName,
userIdNo: userIdNo,
userBankNo: userBankNo,
userMobile: userMobile,
nonceStr: nonceStr,
sign: sign,
use_esign: false,
result: false,
});
var busi = await this.ecompanybusiSve.findOne({
appId: appId
});
if (!busi) {
return {
code: 1001003,
msg: "配置信息错误,请联系薪必果人员进行配置"
};
}
var signArr = [];
signArr.push("appId=" + appId);
signArr.push("nonceStr=" + nonceStr);
signArr.push("userBankNo=" + userBankNo);
signArr.push("userIdNo=" + userIdNo);
signArr.push("userMobile=" + userMobile);
signArr.push("userName=" + userName);
signArr.push("key=" + busi.key);
var calcSign = md5(signArr.join("&")).toUpperCase();
if (sign != calcSign) {
return {
code: 1,
msg: "签名失败"
};
}
var bankParams = {
name: userName, //姓名 必填
idno: userIdNo, //身份证 必填
cardno: userBankNo, //银行卡 必填
mobile: userMobile,
};
// var tt = await this.utilesignbaoSve.bankfour(bankParams, "econtractapi.bankthree") || {};
var tt = {code: 1};
return {
code: 0,
msg: "success"
};
} catch (error) {
return {
code: 500,
msg: "接口异常"
};
}
} }
// 签名 async dosync(obj, req) {
var signArr = []; // TODO 需要验证一下合法
var keys = Object.keys(param).sort(); this.econtractSve.syncAllSigners();
for (var i = 0; i < keys.length; i++) { return 1;
var k = keys[i];
var v = param[k];
if (!k || !v || k == 'sign') {
continue;
}
signArr.push(k + "=" + v);
} }
var signStr = signArr.join("&") + "&key=" + busi.key;
var sign = md5(signStr).toUpperCase(); async dosync(obj, req) {
if (param.sign != sign) { // TODO 需要验证一下合法
return this.returnjson(1001001, "签名错误"); this.econtractSve.syncAllSigners();
return 1;
} }
try { async testinsure() {
var result = await this.econtractSve.autoSignTest(param); this.econtractSve.sendInsure(61094);
return result;
} catch (error) {
console.log(error);
} }
}
async formateTime(inputTime) { async ydsignnumber() {
if (!inputTime) { return this.econtractSve.ydsignnumber();
return '';
} }
var date = new Date(inputTime);
var y = date.getFullYear(); returnjson(code, msg, data) {
var m = date.getMonth() + 1; return {
m = m < 10 ? ('0' + m) : m; code: code,
var d = date.getDate(); msg: msg,
d = d < 10 ? ('0' + d) : d; data: data || null
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + '' + m + '' + d + '' + h + '' + minute + '' + second;
};
async formateSimpTime() {
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
minute = minute < 10 ? ('0' + minute) : minute;
return y + '年' + m + '月' + d + '日' + ' ' + h + ':' + minute;
};
async getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [],
i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
} }
}
} }
return uuid.join('');
}
trim(o) { async autoSign(pobj) {
if (!o) { // 处理参数
return ""; var param = {
ecid: this.trim(pobj.ecid),
appId: this.trim(pobj.appId),
userId: this.trim(pobj.userId),
idName: this.trim(pobj.idName),
mobile: this.trim(pobj.mobile),
idNo: this.trim(pobj.idNo),
bankno: this.trim(pobj.bankno),
nonceStr: this.trim(pobj.nonceStr),
userCode: this.trim(pobj.userCode),//用户code-韵达
branchCode: this.trim(pobj.branchCode),//韵达分公司ID
sign: this.trim(pobj.sign)
};
if (!param.ecid) {
return this.returnjson(-1, "请传入薪必果提供的ecid")
}
if (!param.appId) {
return this.returnjson(-1, "请传入薪必果提供的appId")
}
if (!param.userId) {
return this.returnjson(-1, "请提供该用户的userId")
}
if (!param.idName) {
return this.returnjson(-1, "请提供该用户姓名")
}
if (!param.idNo) {
return this.returnjson(-1, "请提供该用户身份证号")
}
if (!param.bankno) {
return this.returnjson(-1, "请提供该用户银行卡号")
}
if (!param.nonceStr) {
return this.returnjson(-1, "请提供随机码")
}
// 查appId关联key
var busi = await this.ecompanybusiSve.findOne({
appId: param.appId
});
if (!busi || !busi.key) {
return this.returnjson(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
// 签名
var signArr = [];
var keys = Object.keys(param).sort();
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var v = param[k];
if (!k || !v || k == 'sign') {
continue;
}
signArr.push(k + "=" + v);
}
var signStr = signArr.join("&") + "&key=" + busi.key;
var sign = md5(signStr).toUpperCase();
if (param.sign != sign) {
return this.returnjson(1001001, "签名错误");
}
try {
var result = await this.econtractSve.autoSign(param);
return result;
} catch (error) {
console.log(error);
}
} }
return o.toString().trim();
} async autoSignTest(pobj) {
// 处理参数
async validateUser(obj, req) { var param = {
// 验证合法性 ecid: this.trim(pobj.ecid),
var idName = this.trim(obj.idName); appId: this.trim(pobj.appId),
var idNo = this.trim(obj.idNo); userId: this.trim(pobj.userId),
var accNo = this.trim(obj.accNo); idName: this.trim(pobj.idName),
var nonceStr = obj.nonceStr; mobile: this.trim(pobj.mobile),
var sign = obj.sign; idNo: this.trim(pobj.idNo),
if (!idName) { bankno: this.trim(pobj.bankno),
return { nonceStr: this.trim(pobj.nonceStr),
code: 1002001, sign: this.trim(pobj.sign)
msg: "参数错误, 姓名不存在" }
};
if (!param.ecid) {
return this.returnjson(-1, "请传入薪必果提供的ecid")
}
if (!param.appId) {
return this.returnjson(-1, "请传入薪必果提供的appId")
}
if (!param.userId) {
return this.returnjson(-1, "请提供该用户的userId")
}
if (!param.idName) {
return this.returnjson(-1, "请提供该用户姓名")
}
if (!param.idNo) {
return this.returnjson(-1, "请提供该用户身份证号")
}
if (!param.bankno) {
return this.returnjson(-1, "请提供该用户银行卡号")
}
if (!param.nonceStr) {
return this.returnjson(-1, "请提供随机码")
}
// 查appId关联key
var busi = await this.ecompanybusiSve.findOne({
appId: param.appId
});
if (!busi || !busi.key) {
return this.returnjson(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
// 签名
var signArr = [];
var keys = Object.keys(param).sort();
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var v = param[k];
if (!k || !v || k == 'sign') {
continue;
}
signArr.push(k + "=" + v);
}
var signStr = signArr.join("&") + "&key=" + busi.key;
var sign = md5(signStr).toUpperCase();
if (param.sign != sign) {
return this.returnjson(1001001, "签名错误");
}
try {
var result = await this.econtractSve.autoSignTest(param);
return result;
} catch (error) {
console.log(error);
}
} }
if (!idNo) {
return { async formateTime(inputTime) {
code: 1002001, if (!inputTime) {
msg: "参数错误, 身份证不存在" return '';
}; }
var date = new Date(inputTime);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + '' + m + '' + d + '' + h + '' + minute + '' + second;
};
async formateSimpTime() {
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
minute = minute < 10 ? ('0' + minute) : minute;
return y + '年' + m + '月' + d + '日' + ' ' + h + ':' + minute;
};
async getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [],
i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
} }
if (!accNo) {
return { trim(o) {
code: 1002001, if (!o) {
msg: "参数错误, 银行卡号不存在" return "";
}; }
return o.toString().trim();
} }
var sign = md5("accNo=" + accNo + "&idName=" + idName + "&idNo=" + idNo + "&nonceStr=" + obj.nonceStr + "&key=wxf616c0a459d66081").toUpperCase(); async validateUser(obj, req) {
if (sign != obj.sign) { // 验证合法性
return { var idName = this.trim(obj.idName);
code: 1001001, var idNo = this.trim(obj.idNo);
msg: "签名失败" var accNo = this.trim(obj.accNo);
}; var nonceStr = obj.nonceStr;
var sign = obj.sign;
if (!idName) {
return {
code: 1002001,
msg: "参数错误, 姓名不存在"
};
}
if (!idNo) {
return {
code: 1002001,
msg: "参数错误, 身份证不存在"
};
}
if (!accNo) {
return {
code: 1002001,
msg: "参数错误, 银行卡号不存在"
};
}
var sign = md5("accNo=" + accNo + "&idName=" + idName + "&idNo=" + idNo + "&nonceStr=" + obj.nonceStr + "&key=wxf616c0a459d66081").toUpperCase();
if (sign != obj.sign) {
return {
code: 1001001,
msg: "签名失败"
};
}
try {
var list = await this.econtractSve.findSinedByThree(idName, idNo, accNo);
if (list.length > 0) {
return {
code: 0,
msg: "success"
};
}
var nonceStr = obj.nonceStr;
var bankthreeParams = {
name: idName, //姓名 必填
idno: idNo, //身份证 必填
cardno: accNo //银行卡 必填
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "bankinfoAuth") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
if (tt.code == 1) {
return {
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
return {
code: 1002002,
msg: tt.message
};
} else {
return {
code: 1002002,
msg: "银行三要素验证失败"
};
}
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
} }
try { //发薪完,通知消息
var list = await this.econtractSve.findSinedByThree(idName, idNo, accNo); async notifyMssage(obj, req) {
if (list.length > 0) { var resultNotify = {
return { code: 1,
code: 0, message: "success"
msg: "success"
}; };
}
var nonceStr = obj.nonceStr;
var bankthreeParams = { try {
name: idName, //姓名 必填 this.econtractSve.testtransfer(JSON.stringify(obj));
idno: idNo, //身份证 必填 } catch (error) {
cardno: accNo //银行卡 必填 }
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "bankinfoAuth") || {}; var regexNumber = /^[0-9]*$/;
// {"code":-110,"message":"手机号格式错误","data":{}} var wechatNoticeList = [] //微信通知列表
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试! var notifyTime = await this.formateSimpTime();
console.log("tt-----------------------------", tt); var errorItems = [];
if (tt.code == 1) { //循环参数
return { for (var item in obj.sendList) {
code: 0, var rowItem = Number(item) + 1;
msg: "success" var orderItemId = obj.sendList[item]['orderItemId'] || "";
};
} else if (tt.code == -110) {
return {
code: 1002002,
msg: tt.message
};
} else {
return {
code: 1002002,
msg: "银行三要素验证失败"
};
}
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
//发薪完,通知消息 var orderItem = await this.esettleSve.findOrderItemById(orderItemId);
async notifyMssage(obj, req) { if (!orderItem) {
var resultNotify = { errorItems.push("orderItem" + orderItem + "不存在");
code: 1, continue;
message: "success" }
}; if (orderItem.busi_id = '1152195411663171585') {
continue;
}
var idNo = orderItem.id_no || "";
var amt = orderItem.amt || 0;
var mobile = orderItem.mobile || "";
notifyTime = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY年MM月DD日 HH:mm");
var notifyTimeStr = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY-MM-DD HH:mm:ss");
//添加支付记录
var incomeTax = parseFloat((Number(orderItem.income_tax) / 100).toFixed(2));
var notifyUrl = "https://bpohhr.gongsibao.com/paynotify?id=" + orderItemId;
var notifyObj = {
fromid: mobile,
username: orderItem.id_name || "",
flag: 0,
amount: amt,
status: 0,
notifyTime: notifyTimeStr,
orderItemId: orderItemId,
income_tax: orderItem.income_tax
}
try { //为空验证
this.econtractSve.testtransfer(JSON.stringify(obj)); if (!idNo) {
} catch (error) {} errorItems.push("第" + rowItem + "项-参数错误, 身份证为空");
continue;
var regexNumber = /^[0-9]*$/; }
var wechatNoticeList = [] //微信通知列表 if (!amt) {
var notifyTime = await this.formateSimpTime(); errorItems.push("第" + rowItem + "项-参数错误, 实发金额为空");
var errorItems = []; continue;
//循环参数
for (var item in obj.sendList) {
var rowItem = Number(item) + 1;
var orderItemId = obj.sendList[item]['orderItemId'] || "";
var orderItem = await this.esettleSve.findOrderItemById(orderItemId);
if (!orderItem) {
errorItems.push("orderItem" + orderItem + "不存在");
continue;
}
if (orderItem.busi_id = '1152195411663171585') {
continue;
}
var idNo = orderItem.id_no || "";
var amt = orderItem.amt || 0;
var mobile = orderItem.mobile || "";
notifyTime = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY年MM月DD日 HH:mm");
var notifyTimeStr = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY-MM-DD HH:mm:ss");
//添加支付记录
var incomeTax = parseFloat((Number(orderItem.income_tax) / 100).toFixed(2));
var notifyUrl = "https://bpohhr.gongsibao.com/paynotify?id=" + orderItemId;
var notifyObj = {
fromid: mobile,
username: orderItem.id_name || "",
flag: 0,
amount: amt,
status: 0,
notifyTime: notifyTimeStr,
orderItemId: orderItemId,
income_tax: orderItem.income_tax
}
//为空验证
if (!idNo) {
errorItems.push("第" + rowItem + "项-参数错误, 身份证为空");
continue;
}
if (!amt) {
errorItems.push("第" + rowItem + "项-参数错误, 实发金额为空");
continue;
}
amt = parseFloat((Number(amt) / 100).toFixed(2));
var message = notifyTime + " 您收到报酬费" + amt + "元, 查看详细内容" + notifyUrl;
try {
var list = await this.econtractSve.findOpenIdByNo("2", idNo);
if (list.length > 0) {
var sendItem;
var sendMobile;
for (var item of list) {
if (item.openId.indexOf('oEl') === 0) {
sendItem = item;
break;
} }
if (item.mobile) {
sendMobile = item.mobile;
// 手机号通知 amt = parseFloat((Number(amt) / 100).toFixed(2));
notifyObj.username = item.userName; var message = notifyTime + " 您收到报酬费" + amt + "元, 查看详细内容" + notifyUrl;
notifyObj.fromid = mobile || sendMobile;
try {
var list = await this.econtractSve.findOpenIdByNo("2", idNo);
if (list.length > 0) {
var sendItem;
var sendMobile;
for (var item of list) {
if (item.openId.indexOf('oEl') === 0) {
sendItem = item;
break;
}
if (item.mobile) {
sendMobile = item.mobile;
// 手机号通知
notifyObj.username = item.userName;
notifyObj.fromid = mobile || sendMobile;
}
}
if (sendItem) {
// 微信消息模板通知
var wechatParam = {
url: notifyUrl,
first: "您有一个报酬发放通知!",
keyword1: sendItem.userName,
keyword2: "已发放",
keyword3: amt + "元",
keyword4: notifyTime + ' 您的报酬已到帐,请查收!',
openid: sendItem.openId
}
wechatNoticeList.push(wechatParam);
// 通知参数
notifyObj.username = item.userName;
notifyObj.fromid = sendItem.openId;
notifyObj.flag = 1;
await this.econtractSve.addPayNotify(notifyObj);
} else if (mobile || sendMobile) {
// 手机号码通知
// await this.smsS.sendMsg(mobile || sendMobile, message);
await this.econtractSve.addPayNotify(notifyObj);
}
} else {
if (mobile) {
// await this.smsS.sendMsg(mobile, message);
await this.econtractSve.addPayNotify(notifyObj);
} else {
errorItems.push("第" + rowItem + "项-根据身份证获取数据为空");
}
continue;
}
} catch (e) {
resultNotify.code = 500;
resultNotify.message = "接口异常";
//日志记录
logCtl.error({
optitle: "发薪通知error",
op: "api/econtractApi/notifyMssage",
content: e.stack,
clientIp: req.clientIp
});
} }
} }
if (sendItem) { if (wechatNoticeList.length > 0) {
// 微信消息模板通知 await this.wxPushMssage(wechatNoticeList);
var wechatParam = { }
url: notifyUrl, if (errorItems.length > 0) {
first: "您有一个报酬发放通知!", var errors = "";
keyword1: sendItem.userName, for (var item of errorItems) {
keyword2: "已发放", errors += item + "、";
keyword3: amt + "元",
keyword4: notifyTime + ' 您的报酬已到帐,请查收!',
openid: sendItem.openId
} }
wechatNoticeList.push(wechatParam); return system.getErrResult2(errors.substr(0, errors.length - 1));
// 通知参数
notifyObj.username = item.userName;
notifyObj.fromid = sendItem.openId;
notifyObj.flag = 1;
await this.econtractSve.addPayNotify(notifyObj);
} else if (mobile || sendMobile) {
// 手机号码通知
// await this.smsS.sendMsg(mobile || sendMobile, message);
await this.econtractSve.addPayNotify(notifyObj);
}
} else {
if (mobile) {
// await this.smsS.sendMsg(mobile, message);
await this.econtractSve.addPayNotify(notifyObj);
} else {
errorItems.push("第" + rowItem + "项-根据身份证获取数据为空");
}
continue;
} }
} catch (e) {
resultNotify.code = 500;
resultNotify.message = "接口异常";
//日志记录 return resultNotify;
logCtl.error({
optitle: "发薪通知error",
op: "api/econtractApi/notifyMssage",
content: e.stack,
clientIp: req.clientIp
});
}
}
if (wechatNoticeList.length > 0) {
await this.wxPushMssage(wechatNoticeList);
} }
if (errorItems.length > 0) {
var errors = ""; //微信通知消息
for (var item of errorItems) { async wxPushMssage(wechatNoticeList) {
errors += item + "、"; try {
} //微信处理
return system.getErrResult2(errors.substr(0, errors.length - 1)); var data = null;
//添加支付记录
var wxParam = null;
for (var i = 0; i < wechatNoticeList.length; i++) {
var wechatItem = wechatNoticeList[i];
//发送通知
data = {
first: wechatItem.first,
keyword1: {
value: wechatItem.keyword1
},
keyword2: {
value: wechatItem.keyword2
},
keyword3: {
value: wechatItem.keyword3
},
keyword4: {
value: wechatItem.keyword4
}
};
this.wxSve.sendTmplMsg(wechatItem.openid, "khPLingFFTVQM2t7SVm1q1o9MvS2WgqUvIjCPkLcqAY", wechatItem.url || "", data, "wxf616c0a459d66081");
}
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "微信发薪通知error",
op: "api/econtractApi/wxPushMssage",
content: e.stack,
clientIp: req.clientIp
});
}
return result;
} }
return resultNotify;
}
//微信通知消息
async wxPushMssage(wechatNoticeList) {
try {
//微信处理
var data = null;
//添加支付记录
var wxParam = null;
for (var i = 0; i < wechatNoticeList.length; i++) {
var wechatItem = wechatNoticeList[i];
//发送通知
data = {
first: wechatItem.first,
keyword1: {
value: wechatItem.keyword1
},
keyword2: {
value: wechatItem.keyword2
},
keyword3: {
value: wechatItem.keyword3
},
keyword4: {
value: wechatItem.keyword4
}
};
this.wxSve.sendTmplMsg(wechatItem.openid, "khPLingFFTVQM2t7SVm1q1o9MvS2WgqUvIjCPkLcqAY", wechatItem.url || "", data, "wxf616c0a459d66081"); async checkSign(obj, req) {
} // 验证合法性
} catch (e) { var mtchId = obj.mtchId;
var result = { var userList = obj.userList;
code: 500, try {
msg: "接口异常" if (!mtchId) {
}; return {
console.log(e.stack); code: 1,
//日志记录 msg: "请传入商户id信息"
logCtl.error({ };
optitle: "微信发薪通知error", }
op: "api/econtractApi/wxPushMssage",
content: e.stack,
clientIp: req.clientIp
});
}
return result;
}
if (!userList || userList.length == 0) {
return {
code: 1,
msg: "请传入用户身份信息"
};
}
async checkSign(obj, req) { // 1 处理用户姓名和身份证参数
// 验证合法性 var idNoList = [];
var mtchId = obj.mtchId; var idNameList = [];
var userList = obj.userList; for (var u of userList) {
try { idNoList.push(u.idNo);
if (!mtchId) { idNameList.push(u.idName);
return { }
code: 1,
msg: "请传入商户id信息"
};
}
if (!userList || userList.length == 0) { // 2 查公司
return { var companybpo = await this.ecompanybpoSve.findOne({
code: 1, mtchId: mtchId
msg: "请传入用户身份信息" });
}; if (!companybpo) {
} return {
code: 1,
// 1 处理用户姓名和身份证参数 msg: "电子签企业未录入当前商户ID"
var idNoList = []; };
var idNameList = []; }
for (var u of userList) {
idNoList.push(u.idNo);
idNameList.push(u.idName);
}
// 2 查公司
var companybpo = await this.ecompanybpoSve.findOne({
mtchId: mtchId
});
if (!companybpo) {
return {
code: 1,
msg: "电子签企业未录入当前商户ID"
};
}
if (!companybpo.mainId) { if (!companybpo.mainId) {
return { return {
code: 1, code: 1,
msg: "请更新电子签企业" msg: "请更新电子签企业"
}; };
} }
// 3 查签约模板 // 3 查签约模板
var templateIds = await this.etemplateSve.findIdsByCompanyIdAndMainId(companybpo.ecompany_id, companybpo.mainId); var templateIds = await this.etemplateSve.findIdsByCompanyIdAndMainId(companybpo.ecompany_id, companybpo.mainId);
if (!templateIds || templateIds.length == 0) { if (!templateIds || templateIds.length == 0) {
return { return {
code: 1, code: 1,
msg: "电子签模板签约主体设置错误,请到bpo后台重新设置" msg: "电子签模板签约主体设置错误,请到bpo后台重新设置"
}; };
} }
var signList = []; var signList = [];
var unSignList = []; var unSignList = [];
// 4 查签约用户 // 4 查签约用户
var accounts = await this.usereaccountSve.getSignAccounts(templateIds, idNoList, idNameList); var accounts = await this.usereaccountSve.getSignAccounts(templateIds, idNoList, idNameList);
var accountMap = {}; var accountMap = {};
for (var signer of accounts) { for (var signer of accounts) {
accountMap[signer.userName + "_" + signer.personsSign] = 1; accountMap[signer.userName + "_" + signer.personsSign] = 1;
} }
// 5 比对用户是否签约 // 5 比对用户是否签约
for (var u of userList) { for (var u of userList) {
if (accountMap[u.idName + "_" + u.idNo]) { if (accountMap[u.idName + "_" + u.idNo]) {
signList.push(u); signList.push(u);
} else { } else {
unSignList.push(u); unSignList.push(u);
} }
} }
return { return {
code: 0, code: 0,
msg: "", msg: "",
data: { data: {
signList: signList, signList: signList,
unSignList: unSignList unSignList: unSignList
}
};
} catch (error) {
var result = {
code: 1,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验签约error",
op: "api/econtractApi/checkSign",
content: e.stack,
clientIp: req.clientIp
});
return result;
} }
};
} catch (error) {
var result = {
code: 1,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验签约error",
op: "api/econtractApi/checkSign",
content: e.stack,
clientIp: req.clientIp
});
return result;
} }
}
} }
module.exports = EcontractApi; module.exports = EcontractApi;
\ No newline at end of file
var system = require("../../system")
const md5 = require("MD5");
const logCtl = system.getObject("web.oplogCtl");
const moment = require("moment");
class EcontractApi {
constructor() {
this.ecompanySve = system.getObject("service.ecompanySve");
this.econtractSve = system.getObject("service.econtractSve");
this.etemplateSve = system.getObject("service.etemplateSve");
this.utilesignbaoSve = system.getObject("service.utilesignbaoSve");
this.ecompanybusiSve = system.getObject("service.ecompanybusiSve");
this.ecompanywxuserSve = system.getObject("service.ecompanywxuserSve");
this.ecompanybpoSve = system.getObject("service.ecompanybpoSve");
this.usereaccountSve = system.getObject("service.usereaccountSve");
this.wxSve = system.getObject("service.wxSve");
this.esettleSve = system.getObject("service.esettleSve");
this.bankthreelogSve = system.getObject("service.bankthreelogSve");
this.bankthreelog2Sve = system.getObject("service.bankthreelog2Sve");
this.restClient = system.getObject("util.restClient");
this.smsS = system.getObject("util.smsClient");
}
async autoSign(pobj) {
// 处理参数
var param = {
ecid: this.trim(pobj.ecid),
appId: this.trim(pobj.appId),
userId: this.trim(pobj.userId),
idName: this.trim(pobj.idName),
mobile: this.trim(pobj.mobile),
idNo: this.trim(pobj.idNo),
bankno: this.trim(pobj.bankno),
nonceStr: this.trim(pobj.nonceStr),
sign: this.trim(pobj.sign)
}
if (!param.ecid) {
return this.returnjson(-1, "请传入薪必果提供的ecid")
}
if (!param.appId) {
return this.returnjson(-1, "请传入薪必果提供的appId")
}
if (!param.userId) {
return this.returnjson(-1, "请提供该用户的userId")
}
if (!param.idName) {
return this.returnjson(-1, "请提供该用户姓名")
}
if (!param.idNo) {
return this.returnjson(-1, "请提供该用户身份证号")
}
if (!param.bankno) {
return this.returnjson(-1, "请提供该用户银行卡号")
}
if (!param.nonceStr) {
return this.returnjson(-1, "请提供随机码")
}
// 查appId关联key
var busi = await this.ecompanybusiSve.findOne({
appId: param.appId
});
if (!busi || !busi.key) {
return this.returnjson(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
// 签名
var signArr = [];
var keys = Object.keys(param).sort();
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var v = param[k];
if (!k || !v || k == 'sign') {
continue;
}
signArr.push(k + "=" + v);
}
var signStr = signArr.join("&") + "&key=" + busi.key;
var sign = md5(signStr).toUpperCase();
if (param.sign != sign) {
return this.returnjson(1001001, "签名错误");
}
try {
var result = await this.econtractSve.autoSign(param);
return result;
} catch (error) {
console.log(error);
}
}
async merchantAutoSign_yz() {
}
async merchantAutoSign_yd() {
}
async formateTime(inputTime) {
if (!inputTime) {
return '';
}
var date = new Date(inputTime);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + '' + m + '' + d + '' + h + '' + minute + '' + second;
};
async formateSimpTime() {
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
minute = minute < 10 ? ('0' + minute) : minute;
return y + '年' + m + '月' + d + '日' + ' ' + h + ':' + minute;
};
async getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [],
i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
trim(o) {
if (!o) {
return "";
}
return o.toString().trim();
}
async validateUser(obj, req) {
// 验证合法性
var idName = this.trim(obj.idName);
var idNo = this.trim(obj.idNo);
var accNo = this.trim(obj.accNo);
var nonceStr = obj.nonceStr;
var sign = obj.sign;
if (!idName) {
return {
code: 1002001,
msg: "参数错误, 姓名不存在"
};
}
if (!idNo) {
return {
code: 1002001,
msg: "参数错误, 身份证不存在"
};
}
if (!accNo) {
return {
code: 1002001,
msg: "参数错误, 银行卡号不存在"
};
}
var sign = md5("accNo=" + accNo + "&idName=" + idName + "&idNo=" + idNo + "&nonceStr=" + obj.nonceStr + "&key=wxf616c0a459d66081").toUpperCase();
if (sign != obj.sign) {
return {
code: 1001001,
msg: "签名失败"
};
}
try {
var list = await this.econtractSve.findSinedByThree(idName, idNo, accNo);
if (list.length > 0) {
return {
code: 0,
msg: "success"
};
}
var nonceStr = obj.nonceStr;
var bankthreeParams = {
name: idName, //姓名 必填
idno: idNo, //身份证 必填
cardno: accNo //银行卡 必填
};
var tt = await this.utilesignbaoSve.bankthree(bankthreeParams, "bankinfoAuth") || {};
// {"code":-110,"message":"手机号格式错误","data":{}}
//1成功,-110提示验证信息有误,-120亲,提供的信息不正确,请验证后再试!
console.log("tt-----------------------------", tt);
if (tt.code == 1) {
return {
code: 0,
msg: "success"
};
} else if (tt.code == -110) {
return {
code: 1002002,
msg: tt.message
};
} else {
return {
code: 1002002,
msg: "银行三要素验证失败"
};
}
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验是否签约error",
op: "api/econtractApi/validContract",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
//发薪完,通知消息
async notifyMssage(obj, req) {
var resultNotify = {
code: 1,
message: "success"
};
try {
this.econtractSve.testtransfer(JSON.stringify(obj));
} catch (error) {}
var regexNumber = /^[0-9]*$/;
var wechatNoticeList = [] //微信通知列表
var notifyTime = await this.formateSimpTime();
var errorItems = [];
//循环参数
for (var item in obj.sendList) {
var rowItem = Number(item) + 1;
var orderItemId = obj.sendList[item]['orderItemId'] || "";
var orderItem = await this.esettleSve.findOrderItemById(orderItemId);
if (!orderItem) {
errorItems.push("orderItem" + orderItem + "不存在");
continue;
}
if (orderItem.busi_id = '1152195411663171585') {
continue;
}
var idNo = orderItem.id_no || "";
var amt = orderItem.amt || 0;
var mobile = orderItem.mobile || "";
notifyTime = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY年MM月DD日 HH:mm");
var notifyTimeStr = moment(orderItem.pay_complete_time).add(-8, "hours").format("YYYY-MM-DD HH:mm:ss");
//添加支付记录
var incomeTax = parseFloat((Number(orderItem.income_tax) / 100).toFixed(2));
var notifyUrl = "https://bpohhr.gongsibao.com/paynotify?id=" + orderItemId;
var notifyObj = {
fromid: mobile,
username: orderItem.id_name || "",
flag: 0,
amount: amt,
status: 0,
notifyTime: notifyTimeStr,
orderItemId: orderItemId,
income_tax: orderItem.income_tax
}
//为空验证
if (!idNo) {
errorItems.push("第" + rowItem + "项-参数错误, 身份证为空");
continue;
}
if (!amt) {
errorItems.push("第" + rowItem + "项-参数错误, 实发金额为空");
continue;
}
amt = parseFloat((Number(amt) / 100).toFixed(2));
var message = notifyTime + " 您收到报酬费" + amt + "元, 查看详细内容" + notifyUrl;
try {
var list = await this.econtractSve.findOpenIdByNo("2", idNo);
if (list.length > 0) {
var sendItem;
var sendMobile;
for (var item of list) {
if (item.openId.indexOf('oEl') === 0) {
sendItem = item;
break;
}
if (item.mobile) {
sendMobile = item.mobile;
// 手机号通知
notifyObj.username = item.userName;
notifyObj.fromid = mobile || sendMobile;
}
}
if (sendItem) {
// 微信消息模板通知
var wechatParam = {
url: notifyUrl,
first: "您有一个报酬发放通知!",
keyword1: sendItem.userName,
keyword2: "已发放",
keyword3: amt + "元",
keyword4: notifyTime + ' 您的报酬已到帐,请查收!',
openid: sendItem.openId
}
wechatNoticeList.push(wechatParam);
// 通知参数
notifyObj.username = item.userName;
notifyObj.fromid = sendItem.openId;
notifyObj.flag = 1;
await this.econtractSve.addPayNotify(notifyObj);
} else if (mobile || sendMobile) {
// 手机号码通知
// await this.smsS.sendMsg(mobile || sendMobile, message);
await this.econtractSve.addPayNotify(notifyObj);
}
} else {
if (mobile) {
// await this.smsS.sendMsg(mobile, message);
await this.econtractSve.addPayNotify(notifyObj);
} else {
errorItems.push("第" + rowItem + "项-根据身份证获取数据为空");
}
continue;
}
} catch (e) {
resultNotify.code = 500;
resultNotify.message = "接口异常";
//日志记录
logCtl.error({
optitle: "发薪通知error",
op: "api/econtractApi/notifyMssage",
content: e.stack,
clientIp: req.clientIp
});
}
}
if (wechatNoticeList.length > 0) {
await this.wxPushMssage(wechatNoticeList);
}
if (errorItems.length > 0) {
var errors = "";
for (var item of errorItems) {
errors += item + "、";
}
return system.getErrResult2(errors.substr(0, errors.length - 1));
}
return resultNotify;
}
//微信通知消息
async wxPushMssage(wechatNoticeList) {
try {
//微信处理
var data = null;
//添加支付记录
var wxParam = null;
for (var i = 0; i < wechatNoticeList.length; i++) {
var wechatItem = wechatNoticeList[i];
//发送通知
data = {
first: wechatItem.first,
keyword1: {
value: wechatItem.keyword1
},
keyword2: {
value: wechatItem.keyword2
},
keyword3: {
value: wechatItem.keyword3
},
keyword4: {
value: wechatItem.keyword4
}
};
this.wxSve.sendTmplMsg(wechatItem.openid, "khPLingFFTVQM2t7SVm1q1o9MvS2WgqUvIjCPkLcqAY", wechatItem.url || "", data, "wxf616c0a459d66081");
}
} catch (e) {
var result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "微信发薪通知error",
op: "api/econtractApi/wxPushMssage",
content: e.stack,
clientIp: req.clientIp
});
}
return result;
}
async checkSign(obj, req) {
// 验证合法性
var mtchId = obj.mtchId;
var userList = obj.userList;
try {
if (!mtchId) {
return {
code: 1,
msg: "请传入商户id信息"
};
}
if (!userList || userList.length == 0) {
return {
code: 1,
msg: "请传入用户身份信息"
};
}
// 1 处理用户姓名和身份证参数
var idNoList = [];
var idNameList = [];
for (var u of userList) {
idNoList.push(u.idNo);
idNameList.push(u.idName);
}
// 2 查公司
var companybpo = await this.ecompanybpoSve.findOne({
mtchId: mtchId
});
if (!companybpo) {
return {
code: 1,
msg: "电子签企业未录入当前商户ID"
};
}
if (!companybpo.mainId) {
return {
code: 1,
msg: "请更新电子签企业"
};
}
// 3 查签约模板
var templateIds = await this.etemplateSve.findIdsByCompanyIdAndMainId(companybpo.ecompany_id, companybpo.mainId);
if (!templateIds || templateIds.length == 0) {
return {
code: 1,
msg: "电子签模板签约主体设置错误,请到bpo后台重新设置"
};
}
var signList = [];
var unSignList = [];
// 4 查签约用户
var accounts = await this.usereaccountSve.getSignAccounts(templateIds, idNoList, idNameList);
var accountMap = {};
for (var signer of accounts) {
accountMap[signer.userName + "_" + signer.personsSign] = 1;
}
// 5 比对用户是否签约
for (var u of userList) {
if (accountMap[u.idName + "_" + u.idNo]) {
signList.push(u);
} else {
unSignList.push(u);
}
}
return {
code: 0,
msg: "",
data: {
signList: signList,
unSignList: unSignList
}
};
} catch (error) {
var result = {
code: 1,
msg: "接口异常"
};
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "校验签约error",
op: "api/econtractApi/checkSign",
content: e.stack,
clientIp: req.clientIp
});
return result;
}
}
}
module.exports = EcontractApi;
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment