Commit a484205f by 蒋勇

d

parent 48567aef
const system = require("../system"); const system = require("../system");
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const settings = require("../../config/settings"); const settings = require("../../config/settings");
class APIBase{ class APIBase {
constructor() { constructor() {
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
}
async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"] ? req.headers["x-consumetag"].split("|") : null;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req.xctx = {
appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色
companyid: custtags ? custtags[0].split("_")[1] : null,
password: custtags ? custtags[1].split("_")[1] : null,
username: req.headers["x-consumer-username"],
userid: req.headers["x-consumer-custom-id"],
credid: req.headers["x-credential-identifier"],
companykey: req.headers["x-company-key"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
opath: req.headers['xopath'],
ptags: req.headers['xptags'],
} }
async setContextParams(pobj, qobj, req) { //添加组织结构路径,如果是上级,取上级
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null; if (req.xctx.ptags && req.xctx.ptags != "") {
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值 pobj.opath = req.xctx.ptags
req.xctx = { } else {
appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色 pobj.opath = req.xctx.opath
companyid: custtags?custtags[0].split("_")[1]:null, }
password: custtags?custtags[1].split("_")[1]:null, if (req.xctx.userid) {//在请求传递数据对象注入公司id
username: req.headers["x-consumer-username"], pobj.userid = req.xctx.userid;
credid: req.headers["x-credential-identifier"], pobj.username= req.xctx.username
companykey:req.headers["x-company-key"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司 }
} 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.appkey);
let app=await this.cacheManager["AppCache"].cache(req.xctx.appkey); // req.xctx.appid = app.id;
req.xctx.appid=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.companykey) {
if(!req.xctx.companyid && req.xctx.companykey){ let comptmp = await this.cacheManager["CompanyCache"].cache(req.xctx.companykey);
let comptmp=await this.cacheManager["CompanyCache"].cache(req.xctx.companykey); 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; }
} }
async doexec(gname, methodname, pobj, query, req) {
try {
let xarg = await this.setContextParams(pobj, query, req);
if (xarg && xarg[0] < 0) {
return system.getResultFail(...xarg);
} }
async doexec(gname, methodname, pobj, query, req) {
try { var rtn = await this[methodname](pobj, query, req);
let xarg=await this.setContextParams(pobj, query, req); return rtn;
if(xarg && xarg[0]<0){ } catch (e) {
return system.getResultFail(...xarg); console.log(e.stack, "api调用异常--error...................");
} var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员");
return rtnerror;
var rtn = await this[methodname](pobj, query, req);
return rtn;
} catch (e) {
console.log(e.stack, "api调用异常--error...................");
var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员");
return rtnerror;
}
} }
}
} }
module.exports = APIBase; module.exports = APIBase;
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class BizChanceAPI extends APIBase {
constructor() {
super();
this.bizChanceS=system.getObject("service.bizchance.bizoptSve")
}
/**
* 待处理商机beforeSubmission
* 处理中商机 beforeConfirmation
*累计处理商机 包括成单和关闭
* @param {*} p
* @param {*} q
* @param {*} req
*/
async statBizChance(p,q,req){
let companyId=p.company_id
let userid=p.userid
let username=p.username
let opath=p.opath
let rtn=await this.bizChanceS.statBizChance(companyId,opath,username,userid)
return system.getResult(rtn)
}
classDesc() {
return {
groupName: "auth",
groupDesc: "认证相关的包",
name: "AccessAuthAPI",
desc: "关于认证的类",
exam: `
post http://p.apps.com/api/auth/accessAuth/getAccessKey
{
appKey:xxxxx,
secret:yyyyyy
}
`,
};
}
methodDescs() {
return [
{
methodDesc: "生成访问token,访问地址:http://......../api/auth/accessAuth/getAccessKey,访问token需要放置到后续API方法调用的请求头中",
methodName: "getAccessKey",
paramdescs: [
{
paramDesc: "访问appkey",
paramName: "appkey",
paramType: "string",
defaultValue: "",
},
{
paramDesc: "访问secret",
paramName: "secret",
paramType: "string",
defaultValue: "",
}
],
rtnTypeDesc: "返回JSON对象字符串",
rtnType: "json object {accessKey: xxxxxx, app: {xxx:xxx}},注意app,是当前app信息,详细见后面示例"
},
];
}
exam() {
return ``
}
}
module.exports = BizChanceAPI;
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class BizDeliverAPI extends APIBase {
constructor() {
super();
this.bizDeliveryS=system.getObject("service.bizchance.deliverybillSve")
}
/**
* 待处理商机beforeSubmission
* 处理中商机 beforeConfirmation
*累计处理商机 包括成单和关闭
* @param {*} p
* @param {*} q
* @param {*} req
*/
async statBizDelivery(p,q,req){
let companyId=p.company_id
let userid=p.userid
let username=p.username
let opath=p.opath
let rtn=await this.bizDeliveryS.statBizDelivery(companyId,opath,username,userid)
return system.getResult(rtn)
}
classDesc() {
return {
groupName: "auth",
groupDesc: "认证相关的包",
name: "AccessAuthAPI",
desc: "关于认证的类",
exam: `
post http://p.apps.com/api/auth/accessAuth/getAccessKey
{
appKey:xxxxx,
secret:yyyyyy
}
`,
};
}
methodDescs() {
return [
{
methodDesc: "生成访问token,访问地址:http://......../api/auth/accessAuth/getAccessKey,访问token需要放置到后续API方法调用的请求头中",
methodName: "getAccessKey",
paramdescs: [
{
paramDesc: "访问appkey",
paramName: "appkey",
paramType: "string",
defaultValue: "",
},
{
paramDesc: "访问secret",
paramName: "secret",
paramType: "string",
defaultValue: "",
}
],
rtnTypeDesc: "返回JSON对象字符串",
rtnType: "json object {accessKey: xxxxxx, app: {xxx:xxx}},注意app,是当前app信息,详细见后面示例"
},
];
}
exam() {
return ``
}
}
module.exports = BizDeliverAPI;
...@@ -6,6 +6,36 @@ class BizOptService extends ServiceBase { ...@@ -6,6 +6,36 @@ class BizOptService extends ServiceBase {
constructor() { constructor() {
super("bizchance", ServiceBase.getDaoName(BizOptService)); super("bizchance", ServiceBase.getDaoName(BizOptService));
} }
/**
* 公司id,平台公司ID为1
* @param {*} companyId
* @param {*} opath
* @param {*} username
* @param {*} userid
*/
async statBizChance(companyId,opath,username,userid){
//如果当前登录人是平台,返回所有商机
let waittoHandledCount=0
let handlingCount=0
let finishedCount=0
let closedCount=0
if(companyId==1){
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission'}})
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation'}})
finishedCount=await this.dao.findCount({where:{business_status:'isFinished'}})
closedCount=await this.dao.findCount({where:{business_status:'isClosed'}})
}else{
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission',salesman_opcode:opath}})
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation',salesman_opcode:opath}})
finishedCount=await this.dao.findCount({where:{business_status:'isFinished',salesman_opcode:opath}})
closedCount=await this.dao.findCount({where:{business_status:'isClosed',salesman_opcode:opath}})
}
//成单率
let allChance=waittoHandledCount+handlingCount+finishedCount+closedCount
let successRadio=Math.ceil((finishedCount/allChance) * 100)
//如果当前登录人不是平台,那么需要按照opath查询
return {waittoHandledCount:waittoHandledCount,handlingCount:handlingCount,finishedCount:finishedCount,closedCount:closedCount,successRadio:successRadio}
}
async findAndCountAll(obj) { async findAndCountAll(obj) {
var self = this; var self = this;
const apps = await this.dao.findAndCountAll(obj); const apps = await this.dao.findAndCountAll(obj);
......
...@@ -6,6 +6,59 @@ class DeliverybillService extends ServiceBase { ...@@ -6,6 +6,59 @@ class DeliverybillService extends ServiceBase {
constructor() { constructor() {
super("bizchance", ServiceBase.getDaoName(DeliverybillService)); super("bizchance", ServiceBase.getDaoName(DeliverybillService));
} }
async statBizDelivery(companyId,opath,username,userid){
//如果当前登录人是平台,返回所有商机
let waittoHandledCount=0//received
let handlingCount=0
let finishedCount=0//success
let closedCount=0//closed
let toSettle=0
let toSettleAmount=0
let settling=0
let settlingAmount=0
let settled=0
let settledAmount=0
if(companyId==1){
waittoHandledCount=await this.dao.findCount({where:{delivery_status:'received'}})
handlingCount=await this.dao.findCount({where:{delivery_status:{[this.db.Op.notIn]:['received','success','closed']}}})
finishedCount=await this.dao.findCount({where:{delivery_status:'success'}})
closedCount=await this.dao.findCount({where:{delivery_status:'closed'}})
toSettle=await this.dao.findCount({where:{settle_status:'waittosettle'}})
toSettleAmount=await this.dao.findSum('cost_price',{where:{settle_status:'waittosettle'}})
settling=await this.dao.findCount({where:{settle_status:'settling'}})
settlingAmount=await this.dao.findSum('cost_price',{where:{settle_status:'settling'}})
settled=await this.dao.findCount({where:{settle_status:'settled'}})
settledAmount=await this.dao.findSum('cost_price',{where:{settle_status:'settled'}})
}else{
waittoHandledCount=await this.dao.findCount({where:{delivery_status:'received',salesman_opcode:opath}})
handlingCount=await this.dao.findCount({where:{delivery_status:{[this.db.Op.notIn]:['received','success','closed']},salesman_opcode:opath}})
finishedCount=await this.dao.findCount({where:{delivery_status:'success',salesman_opcode:opath}})
closedCount=await this.dao.findCount({where:{delivery_status:'closed',salesman_opcode:opath}})
toSettle=await this.dao.findCount({where:{settle_status:'waittosettle',salesman_opcode:opath}})
toSettleAmount=await this.dao.findSum('cost_price',{where:{settle_status:'waittosettle',salesman_opcode:opath}})
settling=await this.dao.findCount({where:{settle_status:'settling',salesman_opcode:opath}})
settlingAmount=await this.dao.findSum('cost_price',{where:{settle_status:'settling',salesman_opcode:opath}})
settled=await this.dao.findCount({where:{settle_status:'settled',salesman_opcode:opath}})
settledAmount=await this.dao.findSum('cost_price',{where:{settle_status:'settled',salesman_opcode:opath}})
}
//成单率
let allHandled=finishedCount+closedCount
//如果当前登录人不是平台,那么需要按照opath查询
return {
waittoHandledCount:waittoHandledCount,
handlingCount:handlingCount,
finishedCount:finishedCount,
closedCount:closedCount,
allHandled:allHandled,
toSettle:toSettle,
toSettleAmount:toSettleAmount?toSettleAmount:0,
settling:settling,
settlingAmount:settlingAmount?settlingAmount:0,
settled:settled,
settledAmount:settledAmount?settledAmount:0
}
}
async settleApply(ids,uid,uname){ async settleApply(ids,uid,uname){
var self=this var self=this
return this.db.transaction(async function (t){ return this.db.transaction(async function (t){
......
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