Commit e8d5b87f by 兰国旗

Merge branch 'igirl-channel-gateway' of gitlab.gongsibao.com:jiangyong/zhichan…

Merge branch 'igirl-channel-gateway' of gitlab.gongsibao.com:jiangyong/zhichan into igirl-channel-gateway
parents 845f1863 b39b091e
node_modules/ node_modules/
.idea/
.idea
.idea/*
\ No newline at end of file
// const { TmInsideLog, ServiceOrder, IgserviceOrder, StageRecord, CommPayment, PaymentItem, CommPayway, CommSetofbooks } = require("../../model");
const aliRpcClient = require('../utils/AliRpc');
class springboard {
constructor(body) {
this.body = body;
// this.tmInsideLogModel = TmInsideLog.model();
// this.igserviceOrderModel = IgserviceOrder.model();
// this.stageRecordModel = StageRecord.model();
// this.paymentModel = CommPayment.model();
// this.paymentItemModel = PaymentItem.model();
// this.paywayModel = CommPayway.model();
// this.setofbooksModel = CommSetofbooks.model();
this.isAddPay = false;
this.paymentids = [];
this.topic = require("../../utils").topic;
}
/**
* 中转请求
*/
async transferRequest() {
let _this = this;
// await _this.isRequest();
if (_this.result) {
return _this.result;
}
// await _this.getSource();
await _this.addLog();
await _this.requestAli();
await _this.addOkLog();
return _this.result;
}
// async getSource() {
// let _this = this;
// if (_this.body.ActionBody.serviceOrderNo) {
// _this.source = await _this.igserviceOrderModel.findOne({ "no": _this.body.ActionBody.serviceOrderNo }).lean();
// }
// }
/**
* 是否已经请求
* TODO: 新建请求日志表
*/
// async isRequest() {
// let _this = this;
// if (_this.body.ActionBody.reqOnlyCode) {
// let tmInsideLog = await _this.tmInsideLogModel.findOne({ "body.ActionBody.reqOnlyCode": _this.body.ActionBody.reqOnlyCode, "result": { "$exists": true } }).lean();
// if (tmInsideLog) {
// _this.result = tmInsideLog.result;
// }
// }
// }
/**
* 请求阿里
*/
async requestAli() {
let _this = this;
_this.serviceOrderNo = _this.body.ActionBody.serviceOrderNo;
delete _this.body.ActionBody.serviceOrderNo;
delete _this.body.ActionBody.reqOnlyCode;
let aliClient = new aliRpcClient(_this.body.apiVersion).getClient();
_this.result = await aliClient.request(_this.body.ActionType, _this.body.ActionBody, { timeout: 20000 });
}
/**
* 添加日志
* TODO: 新建请求日志表
*/
async addLog() {
// let _this = this;
// let sourceParam = {};
// if (_this.source && JSON.stringify(_this.source) != "{}") {
// sourceParam.orgid = _this.source.orgid;
// sourceParam.source_id = _this.source._id;
// sourceParam.createdby_name = _this.source.createdby_name;
// if (_this.source.createdby) {
// sourceParam.createdby = _this.source.createdby;
// }
// }
// let _log = await new _this.tmInsideLogModel(Object.assign({
// body: _this.body,
// state: "draft",
// action_process: _this.body.ActionProcess || "",
// action_type: _this.body.ActionType || "",
// ation_body: _this.body.AtionBody || {},
// createdat: new Date()
// }, sourceParam)).save();
// _this.logid = _log._id;
}
/**
* 添加成功日志
* TODO: 新建请求日志表
*/
async addOkLog() {
// let _this = this;
// console.log("------_this.logid", _this.logid);
// if (_this.logid) {
// await _this.tmInsideLogModel.updateOne({ "_id": _this.logid }, { "$set": { state: "closed", "result": _this.result } });
// }
}
/**
* 添加错误日志
* TODO: 新建请求日志表
*/
async addErrorLog(error) {
// let _this = this;
// console.log("------_this.logid", _this.logid);
// if (_this.logid) {
// await _this.tmInsideLogModel.updateOne({ "_id": _this.logid }, { "$set": { state: "error", "error": error.stack || error.message } });
// }
}
}
module.exports = springboard
\ No newline at end of file
const config = require('../../config/aliRpc');
const RPCClient = require('@alicloud/pop-core').RPCClient;
class AliRpc {
constructor(apiVersion) {
this.apiVersion = apiVersion || config.apiVersion;
}
getClient() {
return new RPCClient({
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
endpoint: config.endpoint,
apiVersion: this.apiVersion
});
}
}
module.exports = AliRpc;
\ No newline at end of file
/**
* 统一阿里返回结果
*/
class CtxBody {
static success(res, data = {}) {
const body = {
requestId: ctx.context.requestId || '',
success: true,
data,
Code: data.Code || "200",
errorCode: 'OK',
errorMsg: '操作成功',
}
res.status(200).send(body);
}
static error(res, error) {
let errorCode = error.code || 'UNKNOWN.EXCEPTION';
let errorMsg = error.message || '发生未知异常';
const body = {
requestId: ctx.context.requestId || '',
success: false,
data: {},
errorCode: errorCode,
errorMsg: errorMsg,
}
res.status(200).send(body);
}
}
module.exports = CtxBody;
\ No newline at end of file
/**
* 参数异常
*/
class ErrorParamException extends Error{
constructor(err){
super(err)
this.code = 'PARAMETER.ILLEGAL';
this.message = err;
this.name = 'ErrorParamException'
}
}
module.exports = ErrorParamException;
\ No newline at end of file
const iz = require('iz')
const ErrorParamException = require('./exception/ErrorParamException');
const validators = require('iz/lib/validators');
iz.register(validators);
iz.register({
required2: require('./required')
});
const Verify = function(){};
/**
* 判断是否为 true
*/
Verify.isTrue = (bool,message)=>{
if(!bool){
throw new ErrorParamException(message);
}
};
Verify.notNull = (data,message)=>{
if(!iz(data).required2().valid){
throw new ErrorParamException(message);
}
};
Verify.notEmpty = (collections,message)=>{
Verify.notNull(collections,message);
if(iz(collections).empty().valid){
throw new ErrorParamException(message);
}
};
module.exports = {Verify,iz};
\ No newline at end of file
module.exports = {
accessKeyId: "LTAI1pJs7KQizBe2",
accessKeySecret: "MMNibebAPqR9AnX5YWHnSL2tHMSIoL",
endpoint:"https://trademark.aliyuncs.com",
apiVersion:"2018-07-24"
};
var url = require("url");
var system = require("../../base/system");
const verify = require("../../base/utils/verify").Verify;
const CtxBody = require("../../base/utils/CtxBody");
const tmSpringboard = require("../../base/controller/tm.springboard");
// var userCtl = system.getObject("web.auth.userCtl");
module.exports = function (app) {
app.post('/tm/springboard', async function(req, res) {
let body = req.body || {};
let _tmSpringboard = new tmSpringboard(body);
try {
verify.notNull(body.ActionProcess, 'ActionProcess 不能为空!');
verify.notNull(body.ActionType, 'ActionType 不能为空!');
verify.notNull(body.ActionBody, 'ActionBody 不能为空!');
let data = await _tmSpringboard.transferRequest();
CtxBody.success(res, data);
console.log("----返回成功");
} catch (error) {
console.error("------error", error);
await _tmSpringboard.addErrorLog(error);
CtxBody.error(res, error);
}
});
};
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"author": "jy", "author": "jy",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@alicloud/pop-core": "^1.7.10",
"MD5": "^1.3.0", "MD5": "^1.3.0",
"after": "^0.8.2", "after": "^0.8.2",
"ali-oss": "^4.12.2", "ali-oss": "^4.12.2",
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
"express-session": "^1.15.6", "express-session": "^1.15.6",
"glob": "^7.1.6", "glob": "^7.1.6",
"gm": "^1.23.1", "gm": "^1.23.1",
"iz": "^3.0.0",
"marked": "^0.7.0", "marked": "^0.7.0",
"method-override": "^2.3.10", "method-override": "^2.3.10",
"moment": "^2.24.0", "moment": "^2.24.0",
......
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