Commit f4b9d914 by zhaoxiqing

gsb

parent e7ed0bd2
...@@ -2,158 +2,256 @@ const system = require("../../../system"); ...@@ -2,158 +2,256 @@ const system = require("../../../system");
const ServiceBase = require("../../svems.base") const ServiceBase = require("../../svems.base")
class AuthService extends ServiceBase { class AuthService extends ServiceBase {
constructor() { constructor() {
super(); super();
this.feeSve = system.getObject("service.fee.feeSve"); this.feeSve = system.getObject("service.fee.feeSve");
this.orderSve = system.getObject("service.order.orderSve"); this.orderSve = system.getObject("service.order.orderSve");
this.orderauthlogSve = system.getObject("service.order.orderauthlogSve"); this.orderauthlogSve = system.getObject("service.order.orderauthlogSve");
this.enginesignSve = system.getObject("service.engine.enginesignSve"); this.enginesignSve = system.getObject("service.engine.enginesignSve");
this.tradelogDao = system.getObject("db.common.tradelogDao"); this.tradelogDao = system.getObject("db.common.tradelogDao");
}
async createAccount(params) {
try {
params.apiName = "sign@";
params.isFee = false;
// 验证参数
let idName = this.trim(params.idName);
let idNo = this.trim(params.idNo).toUpperCase();
let mobile = this.trim(params.mobile);
if (!idName) {
return system.getResultFail(1000000, "姓名错误");
}
if (!idNo) {
return system.getResultFail(1000000, "身份证错误");
}
return this.operatorSign(params, async (p) => {
// 调用创建账户API
let validRes = await this.enginesignSve.createAccount({
id_name: idName,
id_no: idNo,
mobile: mobile,
channel: p.orderProduct.channel,
});
return validRes;
});
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async createTemplate(params) {
try {
params.apiName = "sign@";
params.isFee = false;
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
} }
}
async handSign(params) { async createAccount(params) {
try { try {
params.apiName = "sign@hand"; params.apiName = "sign@";
params.isFee = true; params.isFee = false;
// 验证参数
let idName = this.trim(params.idName);
let idNo = this.trim(params.idNo).toUpperCase();
let mobile = this.trim(params.mobile);
if (!idName) {
return system.getResultFail(1000000, "姓名错误");
}
if (!idNo) {
return system.getResultFail(1000000, "身份证错误");
}
return this.operatorSign(params, async (p) => {
// 调用创建账户API
let validRes = await this.enginesignSve.createAccount({
id_name: idName,
id_no: idNo,
mobile: mobile,
channel: p.orderProduct.channel,
});
return validRes;
});
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
} catch (error) { async createTemplate(params) {
return system.getResult(null, `系统错误 错误信息 ${error}`); try {
params.apiName = "sign@";
params.isFee = false;
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
} }
}
async autosign(params) {
params.apiName = "sign@auto"; async createEntSeal(params) {
params.isFee = true; try {
params.apiName = "sign@";
try { params.isFee = false;
} catch (error) { // 验证参数
return system.getResult(null, `系统错误 错误信息 ${error}`); let accountId = this.trim(params.accountId);
let sealAlias = this.trim(params.sealAlias);
if (!accountId) {
return system.getResultFail(1000000, "账户ID不能为空");
}
if (!sealAlias) {
return system.getResultFail(1000000, "印章名称不能为空");
}
return this.operatorSign(params, async (p) => {
// 调用创建账户API
let validRes = await this.enginesignSve.organize({
accountId: accountId,
channel: p.orderProduct.channel,
color: 1,
sealAlias: sealAlias,
templateType: 1,
text: sealAlias,
});
return validRes;
});
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
} }
}
async operatorSign(params, operatorMethod) {
let app = params.app;
let merchantId = app.merchant_id;
let isFee = params.isFee;
// 获取订单产品 async handSign(params) {
let orderProduct = await this.orderSve.getMerchantOrderProduct(merchantId, params.apiName); try {
if (orderProduct.status !== 0) { params.apiName = "sign@hand";
return orderProduct; params.isFee = true;
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
} }
orderProduct = orderProduct.data;
params.orderProduct = orderProduct; /**
// 扣费 *
let tradeLog; * {
let trade; "action_process": "test",
if (isFee) { "action_type": "autoSign",
let tres = await this.trade(params); "action_body": {
if (tres.status !== 0) { "appId":"12167897412000190",
return tres; "nonceStr":"12312312312312",
} "sign":"EE63140753238BB2E4D79ABCDFB07732",
trade = tres.data.trade; "accountId": "c4a5a57bad9b4d4ab5dbbe2362d86f77",
"channel": 1,
"contractName": "测试",
"entSealId": 63,
"noticeUrl": "",
"perSealId": "",
"redirectUrl": "",
"sealType": null,
"signPlatform": null,
"simpleFormFields": {
"nameA":"甲方",
"nameB":"个人",
"unit":"测试测试测试",
"signDateA":"2020-07-04",
"signDateB":"2020-07-04"
},
"templateId": "10512"
} }
// 2. 调用签约引擎接口 }
let res = await operatorMethod(params); */
async autoSign(params) {
if (isFee) { params.apiName = "sign@auto";
// 生成订单 params.isFee = true;
// let logres = await this.orderauthlogSve.saveEorderAuthLog({
// order_id: orderProduct.id, // 验证参数
// product_id: orderProduct.product_id, let accountId = this.trim(params.accountId);
// platform_name: app.name, let entSealId = this.trim(params.entSealId);
// platform_id: app.id, let contractName = this.trim(params.contractName);
// spended_num: trade.trade_amt, let templateId = this.trim(params.templateId);
// user_name: params.idName, // 使用方 let simpleFormFields = params.simpleFormFields;
// actual_spend_name: app.merchant_name,// 实际使用方
// engine_trade_id: trade.id, if (!accountId) {
// pass: pass ? 1 : 0 return system.getResultFail(1000000, "账户ID不能为空");
// }); }
// console.log(logres); if (!entSealId) {
return system.getResultFail(1000000, "印章ID不能为空");
}
if (!contractName) {
return system.getResultFail(1000000, "合同名称不能为空");
}
if (!templateId) {
return system.getResultFail(1000000, "模板ID不能为空");
}
if (!simpleFormFields) {
return system.getResultFail(1000000, "文本域不能为空");
}
return this.operatorSign(params, async (p) => {
// 调用创建账户API
let validRes = await this.enginesignSve.autoSign({
accountId: accountId,
entSealId: entSealId,
contractName: contractName,
templateId: templateId,
simpleFormFields: simpleFormFields,
channel: p.orderProduct.channel,
});
return system.getResultSuccess(validRes.contract);
});
try {
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
} }
// 4. 返回认证结果
return system.getResultSuccess(res.data, res.msg);
}
// 交易 async operatorSign(params, operatorMethod) {
async trade(params) { let app = params.app;
let orderProduct = params.orderProduct; let merchantId = app.merchant_id;
let isFee = params.isFee;
let trade_amt = 1; // 获取订单产品
if (orderProduct == 2) { let orderProduct = await this.orderSve.getMerchantOrderProduct(merchantId, params.apiName);
trade_amt = Number(orderProduct.price); if (orderProduct.status !== 0) {
return orderProduct;
}
orderProduct = orderProduct.data;
params.orderProduct = orderProduct;
// 扣费
let tradeLog;
let trade;
if (isFee) {
let tres = await this.trade(params);
if (tres.status !== 0) {
return tres;
}
trade = tres.data.trade;
}
// 2. 调用签约引擎接口
let res = await operatorMethod(params);
if (isFee) {
// 生成订单
// let logres = await this.orderauthlogSve.saveEorderAuthLog({
// order_id: orderProduct.id,
// product_id: orderProduct.product_id,
// platform_name: app.name,
// platform_id: app.id,
// spended_num: trade.trade_amt,
// user_name: params.idName, // 使用方
// actual_spend_name: app.merchant_name,// 实际使用方
// engine_trade_id: trade.id,
// pass: pass ? 1 : 0
// });
// console.log(logres);
}
// 4. 返回认证结果
return system.getResultSuccess(res.data, res.msg);
} }
let tradeLog = await this.tradelogDao.create({ // 交易
requestid: params.requestid, async trade(params) {
merchant_id: orderProduct.merchant_id, let orderProduct = params.orderProduct;
product_id: orderProduct.product_id,
trade_amt: trade_amt, let trade_amt = 1;
result: 0, if (orderProduct == 2) {
}); trade_amt = Number(orderProduct.price);
}
let tradeRes = await this.feeSve.trade({ let tradeLog = await this.tradelogDao.create({
account_id: orderProduct.engine_account_id, requestid: params.requestid,
trade_amt: trade_amt, merchant_id: orderProduct.merchant_id,
trade_no: tradeLog.id, product_id: orderProduct.product_id,
trade_desc: "二要素验证", trade_amt: trade_amt,
}); result: 0,
if (tradeRes.status !== 0) { });
tradeLog.result = 2;
tradeLog.fee = 0;
tradeLog.fee_remark = "扣费失败," + tradeRes.msg; let tradeRes = await this.feeSve.trade({
await tradeLog.save(); account_id: orderProduct.engine_account_id,
return system.getResultFail(1002001, "扣费失败," + tradeRes.msg); trade_amt: trade_amt,
} else { trade_no: tradeLog.id,
tradeLog.result = 1; trade_desc: "二要素验证",
tradeLog.fee = 1; });
tradeLog.fee_remark = "扣费成功"; if (tradeRes.status !== 0) {
await tradeLog.save(); tradeLog.result = 2;
tradeLog.fee = 0;
tradeLog.fee_remark = "扣费失败," + tradeRes.msg;
await tradeLog.save();
return system.getResultFail(1002001, "扣费失败," + tradeRes.msg);
} else {
tradeLog.result = 1;
tradeLog.fee = 1;
tradeLog.fee_remark = "扣费成功";
await tradeLog.save();
}
return system.getResultSuccess({
tradeLog: tradeLog,
trade: tradeRes.data
})
} }
return system.getResultSuccess({
tradeLog: tradeLog,
trade: tradeRes.data
})
}
} }
module.exports = AuthService; module.exports = AuthService;
\ No newline at end of file
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