Commit 29df0a1f by sxy

fix: 去掉 appkey验证 修改 sysytem getObject

parent 854d8b12
...@@ -30,58 +30,58 @@ class CtlBase { ...@@ -30,58 +30,58 @@ class CtlBase {
return system.getResult(rs); return system.getResult(rs);
} }
async refQuery(pobj, qobj, req) { async refQuery(pobj, qobj, req) {
pobj.refwhere.app_id=pobj.app_id; pobj.refwhere.app_id = pobj.app_id;
pobj.refwhere.company_id=pobj.company_id; pobj.refwhere.company_id = pobj.company_id;
let rtn=await this.service.refQuery(pobj); let rtn = await this.service.refQuery(pobj);
return rtn return rtn
} }
async setContextParams(pobj, qobj, req) { async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null; let custtags = req.headers["x-consumetag"] ? req.headers["x-consumetag"].split("|") : null;
let lastindex=custtags?custtags.length-1:0; let lastindex = custtags ? custtags.length - 1 : 0;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值 //当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req.xctx = { req.xctx = {
appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色 appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色
fromappkey:req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同 fromappkey: req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同
companyid: custtags?custtags[0].split("_")[1]:null, companyid: custtags ? custtags[0].split("_")[1] : null,
fromcompanykey:req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司 fromcompanykey: req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
password: custtags?custtags[lastindex].split("_")[1]:null, password: custtags ? custtags[lastindex].split("_")[1] : null,
username: req.headers["x-consumer-username"], username: req.headers["x-consumer-username"],
userid:req.headers["x-consumer-custom-id"], userid: req.headers["x-consumer-custom-id"],
credid: req.headers["x-credential-identifier"], credid: req.headers["x-credential-identifier"],
regrole:req.headers["xregrole"], regrole: req.headers["xregrole"],
bizpath:req.headers["xbizpath"], bizpath: req.headers["xbizpath"],
} }
if(!req.xctx.appkey){ if (!req.xctx.appkey) {
return [-200,"请求头缺少应用x-app-key"] return [-200, "请求头缺少应用x-app-key"]
}else{ } else {
let app=await this.cacheManager["AppCache"].cache(req.xctx.fromappkey); // let app=await this.cacheManager["AppCache"].cache(req.xctx.fromappkey);
req.xctx.appid=app.id; // req.xctx.appid=app.id;
if(!pobj.app_id){ // if(!pobj.app_id){
pobj.app_id=app.id;//传递参数对象里注入app_id // pobj.app_id=app.id;//传递参数对象里注入app_id
} // }
} }
//平台注册时,companyid,companykey都为空 //平台注册时,companyid,companykey都为空
//自由注册时,companykey不能为空 //自由注册时,companykey不能为空
// if(!req.xctx.companyid && !req.xctx.companykey){ // if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"] // return [-200,"请求头缺少应用x-app-key"]
// } // }
if(!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey!="null"){ if (!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey != "null") {
let comptmp=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey); let comptmp = await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid=comptmp.id; req.xctx.companyid = comptmp.id;
} }
if(req.xctx.companyid){//在请求传递数据对象注入公司id if (req.xctx.companyid) {//在请求传递数据对象注入公司id
pobj.company_id=req.xctx.companyid; pobj.company_id = req.xctx.companyid;
} }
if(req.xctx.userid){//在请求传递数据对象注入公司id if (req.xctx.userid) {//在请求传递数据对象注入公司id
pobj.userid=req.xctx.userid; pobj.userid = req.xctx.userid;
} }
pobj.bizpath=req.xctx.bizpath; pobj.bizpath = req.xctx.bizpath;
} }
async doexec(methodname, pobj, query, req) { async doexec(methodname, pobj, query, req) {
try { try {
let xarg=await this.setContextParams(pobj, query, req); let xarg = await this.setContextParams(pobj, query, req);
if(xarg && xarg[0]<0){ if (xarg && xarg[0] < 0) {
return system.getResultFail(...xarg); return system.getResultFail(...xarg);
} }
//从请求头里面取appkey_consumename //从请求头里面取appkey_consumename
// var consumeName=req.headers[""] // var consumeName=req.headers[""]
......
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
class BizOptCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(BizOptCtl));
}
}
module.exports = BizOptCtl;
...@@ -64,8 +64,8 @@ class DbFactory { ...@@ -64,8 +64,8 @@ class DbFactory {
this.db.models.plugin.belongsTo(this.db.models.app, { constraints: false, }); this.db.models.plugin.belongsTo(this.db.models.app, { constraints: false, });
// 商机表 1:1 方案表 // 商机表 1:1 方案表
this.db.models.scheme.belongsTo(this.db.models.bussiness_opportunity, { constraints: false, }); this.db.models.scheme.belongsTo(this.db.models.bizopt, { constraints: false, });
this.db.models.bussiness_opportunity.hasOne(this.db.models.scheme, { constraints: false, }); this.db.models.bizopt.hasOne(this.db.models.scheme, { constraints: false, });
} }
//async getCon(){,用于使用替换table模型内字段数据使用 //async getCon(){,用于使用替换table模型内字段数据使用
......
...@@ -5,7 +5,7 @@ const appconfig = system.getSysConfig(); ...@@ -5,7 +5,7 @@ const appconfig = system.getSysConfig();
* 商机表 * 商机表
*/ */
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("bussiness_opportunity", { return db.define("bizopt", {
demand_code: { // 需求编码 demand_code: { // 需求编码
allowNull: false, allowNull: false,
type: DataTypes.STRING type: DataTypes.STRING
......
...@@ -16,55 +16,55 @@ class System { ...@@ -16,55 +16,55 @@ class System {
} }
} }
} }
static async delReq(url,qdata){ static async delReq(url, qdata) {
let rtn={} let rtn = {}
let promise=new Promise(function(resv,rej){ let promise = new Promise(function (resv, rej) {
request.del({ request.del({
url: url, url: url,
qs: qdata qs: qdata
}, function(error, response, body) { }, function (error, response, body) {
rtn.statusCode=response.statusCode rtn.statusCode = response.statusCode
if (!error) { if (!error) {
if(body){ if (body) {
let data=JSON.parse(body) let data = JSON.parse(body)
rtn.data=data rtn.data = data
}else{ } else {
rtn.data=null rtn.data = null
} }
resv(rtn); resv(rtn);
}else{ } else {
rej(error) rej(error)
} }
}); });
}) })
return promise; return promise;
} }
static async getReq(url,qdata){ static async getReq(url, qdata) {
let rtn={} let rtn = {}
let promise=new Promise(function(resv,rej){ let promise = new Promise(function (resv, rej) {
request.get({ request.get({
url: url, url: url,
json: true, json: true,
qs: qdata qs: qdata
}, function(error, response, body) { }, function (error, response, body) {
rtn.statusCode=response.statusCode; rtn.statusCode = response.statusCode;
if (!error) { if (!error) {
if(body){ if (body) {
rtn.data=body rtn.data = body
}else{ } else {
rtn.data=null rtn.data = null
}
resv(rtn);
}else{
rej(error);
} }
}); resv(rtn);
} else {
rej(error);
}
});
}) })
return promise; return promise;
} }
static async postJsonTypeReq(url,data,md="POST"){ static async postJsonTypeReq(url, data, md = "POST") {
let rtn={} let rtn = {}
let promise=new Promise(function(resv,rej){ let promise = new Promise(function (resv, rej) {
request({ request({
url: url, url: url,
method: md, method: md,
...@@ -73,54 +73,54 @@ class System { ...@@ -73,54 +73,54 @@ class System {
"content-type": "application/json", "content-type": "application/json",
}, },
body: data body: data
}, function(error, response, body) { }, function (error, response, body) {
console.log(error) console.log(error)
rtn.statusCode=response.statusCode rtn.statusCode = response.statusCode
if (!error) { if (!error) {
if(body){ if (body) {
rtn.data=body rtn.data = body
}else{ } else {
rtn.data=null rtn.data = null
} }
resv(rtn); resv(rtn);
}else{ } else {
rej(error) rej(error)
} }
}); });
}) })
return promise; return promise;
} }
static async post3wFormTypeReq(url,data){ static async post3wFormTypeReq(url, data) {
let rtn={} let rtn = {}
let promise=new Promise(function(resv,rej){ let promise = new Promise(function (resv, rej) {
request.post({ request.post({
url: url, url: url,
form: data form: data
}, function(error, response, body) { }, function (error, response, body) {
rtn.statusCode=response.statusCode rtn.statusCode = response.statusCode
if (!error) { if (!error) {
let data=JSON.parse(body) let data = JSON.parse(body)
rtn.data=data rtn.data = data
resv(rtn); resv(rtn);
}else{ } else {
rej(error) rej(error)
} }
}); });
}) })
return promise; return promise;
} }
static async postMpFormTypeReq(url,formdata){ static async postMpFormTypeReq(url, formdata) {
let promise=new Promise(function(resv,rej){ let promise = new Promise(function (resv, rej) {
request.post({ request.post({
url: url, url: url,
formData: formdata formData: formdata
}, function(error, response, body) { }, function (error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
resv(body); resv(body);
}else{ } else {
rej(error) rej(error)
} }
}); });
}) })
return promise; return promise;
} }
...@@ -176,11 +176,16 @@ class System { ...@@ -176,11 +176,16 @@ class System {
data: data, data: data,
}; };
} }
static register(key, ClassObj,groupName,filename) { static register(key, ClassObj, groupName, filename) {
if (System.objTable[key] != null) { if (System.objTable[key] != null) {
throw new Error("相同key的对象已经存在"); throw new Error("相同key的对象已经存在");
} else { } else {
let obj = new ClassObj(groupName,filename); let obj;
if (ClassObj.name === "ServiceBase") {
obj = new ClassObj(groupName, filename.replace("Sve", "Dao"));
} else {
obj = new ClassObj(groupName, filename);
}
System.objTable[key] = obj; System.objTable[key] = obj;
} }
...@@ -204,29 +209,29 @@ class System { ...@@ -204,29 +209,29 @@ class System {
//判断文件的存在性 //判断文件的存在性
//如果不存在,需要查看packageName //如果不存在,需要查看packageName
//如果packageName=web.service,dao //如果packageName=web.service,dao
if (System.objTable[objabspath] != null) { if (System.objTable[objabspath] != null) {
return System.objTable[objabspath]; return System.objTable[objabspath];
} else { } else {
var ClassObj =null; var ClassObj = null;
try{ try {
ClassObj = require(objabspath); ClassObj = require(objabspath);
}catch(e){ } catch (e) {
// console.log(e) // console.log(e)
let fname=objsettings[packageName+"base"]; let fname = objsettings[packageName + "base"];
ClassObj = require(fname); ClassObj = require(fname);
} }
if(ClassObj.name=="Dao"){ if (ClassObj.name == "Dao") {
let modelname=filename.substring(0,filename.lastIndexOf("Dao")) let modelname = filename.substring(0, filename.lastIndexOf("Dao"))
return System.register(objabspath, ClassObj,modelname); return System.register(objabspath, ClassObj, modelname);
} }
if(ClassObj.name.indexOf("Ctl")>=0){ if (ClassObj.name.indexOf("Ctl") >= 0) {
console.log(ClassObj.name); console.log(ClassObj.name);
} }
return System.register(objabspath, ClassObj,groupName,filename); return System.register(objabspath, ClassObj, groupName, filename);
} }
} }
static getSysConfig() { static getSysConfig() {
var configPath = settings.basepath + "/app/base/db/metadata/index.js"; var configPath = settings.basepath + "/app/base/db/metadata/index.js";
// if(settings.env=="dev"){ // if(settings.env=="dev"){
...@@ -251,7 +256,7 @@ class System { ...@@ -251,7 +256,7 @@ class System {
} }
}; };
} }
Date.prototype.Format = function (fmt) { //author: meizz Date.prototype.Format = function (fmt) { //author: meizz
var o = { var o = {
......
var settings = { var settings = {
redis: { redis: {
host: "192.168.4.119", host: "43.247.184.32",
port: 6379, port: 8967,
password: "Gongsibao2018", password: "Gongsibao2018",
db: 9, db: 9,
}, },
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"description": "h5framework", "description": "h5framework",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "jy", "author": "jy",
...@@ -63,4 +64,4 @@ ...@@ -63,4 +64,4 @@
"imagemin-pngquant": "^8.0.0", "imagemin-pngquant": "^8.0.0",
"merge-stream": "^2.0.0" "merge-stream": "^2.0.0"
} }
} }
\ 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