Commit 1fa7059a by Sxy

feat:启服通商机面板

parent 23696c1c
const CtlBase = require("../../ctl.base");
var system = require("../../../system");
class StatisticsCtl extends CtlBase {
constructor() {
super("qifutong", CtlBase.getServiceName(StatisticsCtl));
}
// 获取 渠道信息
async getAllChannels(pobj, qobj, req) {
try {
const rs = await this.service.getAllChannels(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
// 获取 产品信息
async getAllProducts(pobj, qobj, req) {
try {
const rs = await this.service.getAllProducts(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
// 需求渠道分析
async getStatisticsByUappId(pobj, qobj, req) {
try {
const rs = await this.service.getStatisticsByUappId(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
// 需求漏斗图
async getNeedFunnelStatistics(pobj, qobj, req) {
try {
const rs = await this.service.getNeedFunnelStatistics(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
// 需求产品分析
async getStatisticsByProduct(pobj, qobj, req) {
try {
const rs = await this.service.getStatisticsByProduct(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
}
module.exports = StatisticsCtl;
const ToQiFuTong = require('../../../utils/qifutong/baseClient').getInstance();
class StatisticsService {
async getAllChannels(pobj) {
return ToQiFuTong.getAllChannels();
}
async getAllProducts(pobj) {
return ToQiFuTong.getAllProducts();
}
async getStatisticsByUappId(pobj) {
const data = await ToQiFuTong.getStatisticsByUappId({
start: pobj.start,
end: pobj.end,
type_code: pobj.type_code,
status: pobj.status
});
const dates = ToQiFuTong.getAllDate(pobj.start, pobj.end);
return {
x: dates,
data
};
}
async getStatisticsByProduct(pobj) {
const data = await ToQiFuTong.getStatisticsByProduct({
start: pobj.start,
end: pobj.end,
type_code: pobj.type_code,
});
let result = []; // 基础数据
let channels = new Set(); //渠道
let productList = []; //产品
for (let val of data) {
let productCount = 0;
for (let info of val.data) {
productCount += info.count;
channels.add(info.uapp_id.toString());
result.push({
uapp_id: info.uapp_id.toString(),
count: info.count,
type_code: val.type_code
})
}
productList.push({
count: productCount,
type_code: val.type_code
})
}
productList = productList.sort(function (a, b) { return a.count - b.count });
return {
channelList: [...channels],
productList: productList.map((item) => { return item.type_code }),
data: result
};
}
async getNeedFunnelStatistics(pobj) {
return ToQiFuTong.getNeedFunnelStatistics({
start: pobj.start,
end: pobj.end,
type_code: pobj.type_code,
uapp_id: pobj.uapp_id
});
}
}
module.exports = StatisticsService;
\ No newline at end of file
const axios = require("axios");
const settings = require("../../../config/settings");
const Moment = require("moment");
const centerChannelUrl = settings.QIFUTONG.centerChannelUrl();
const qifutongUrl = settings.QIFUTONG.qifutongUrl();
const { appKey, secret } = settings.QIFUTONG;
class BaseClient {
constructor() {
this.appKey = appKey;
this.secret = secret;
this.instance = null;
}
static getInstance() {
if (!this.instance) {
this.instance = new BaseClient();
}
return this.instance;
}
/**
* 推送到 启服通
* @param {*} user
* @param {*} data
*/
async pushQiFuTong(url, data, user = 'center-manage',) {
const header = await this.getLoginByUserName(user);
return await this.postRequest(`${qifutongUrl}${url}`, data, header);
}
async getLoginByUserName(user) {
const token = await this.getAppTokenByAppKey(this.appKey, this.secret);
const data = await this.postRequest(`${centerChannelUrl}/api/opreceive/accessAuth/springBoard`, {
"actionType": "getLoginByUserName",
"actionBody": {
"channelUserId": user,
"user": user,
"userName": user
}
}, {
token
});
return {
token,
userpin: data.userpin
}
}
async getAppTokenByAppKey(appKey, secret) {
const data = await this.postRequest(`${centerChannelUrl}/api/opreceive/accessAuth/getAppTokenByAppKey`, {
"actionType": "getAppTokenByAppKey",
"actionBody": {
"appkey": appKey,
"secret": secret
}
});
return data.token
}
async postRequest(url, data, headers = {}) {
try {
console.log(` ${url} : 请求信息 ------- `);
console.log(JSON.stringify(data))
console.log(JSON.stringify(headers))
let result = await axios.post(`${url}`, data, {
headers: {
'Content-Type': 'application/json',
...headers
}
});
result = result.data;
console.log(` ${url} : 返回信息 ------- `);
console.log(result);
if (result.status === 0) {
return result.data
} else {
throw new Error(result.msg)
}
} catch (err) {
console.log(` ${url} : 返回错误信息 ------- `);
console.log(err)
throw (err)
}
}
async getAllChannels() {
const data = await this.pushQiFuTong('/web/auth/accessAuth/springBoard', {
"actionType": "getAllChannels",
"actionBody": {
}
});
return data;
}
async getAllProducts() {
const data = await this.pushQiFuTong('/web/action/product/springBoard', {
"actionType": "getAllProducts",
"actionBody": {
}
});
return data;
}
async getStatisticsByUappId(pobj) {
const data = await this.pushQiFuTong('/web/action/opNeed/springBoard', {
"actionType": "getStatisticsByUappId",
"actionBody": pobj
});
return data;
}
async getNeedFunnelStatistics(pobj) {
const data = await this.pushQiFuTong('/web/action/opNeed/springBoard', {
"actionType": "getNeedFunnelStatistics",
"actionBody": pobj
});
return data;
}
async getStatisticsByProduct(pobj) {
const data = await this.pushQiFuTong('/web/action/opNeed/springBoard', {
"actionType": "getStatisticsByProduct",
"actionBody": pobj
});
return data;
}
// 获取一段时间内的所有日期
getAllDate(begin, end) {
let data = [];
begin = Moment(begin).format("YYYY-MM-DD");
end = Moment(end).format("YYYY-MM-DD");
if (begin == end) {
return [begin]
}
if ((new Date(end).getTime() - new Date(begin).getTime()) == 86400000) {
return [begin, end]
}
let ab = begin.split("-");
let ae = end.split("-");
let db = new Date();
db.setUTCFullYear(ab[0], ab[1] - 1, ab[2]);
let de = new Date();
de.setUTCFullYear(ae[0], ae[1] - 1, ae[2]);
let unixDb = db.getTime();
let unixDe = de.getTime();
data.push(begin);
for (let k = unixDb + 24 * 60 * 60 * 1000; k < unixDe;) {
data.push(Moment(new Date(parseInt(k))).format("YYYY-MM-DD"));
k = k + 24 * 60 * 60 * 1000;
}
data.push(end);
return data;
}
}
module.exports = BaseClient;
\ No newline at end of file
......@@ -75,6 +75,24 @@ var settings = {
return "http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard";
}
},
QIFUTONG: {
appKey: "202003231118",
secret: "7cbb846246874167b5c7e01cd0016c99",
centerChannelUrl: () => { //---------center-channel
if (ENVINPUT.APP_ENV == "dev") {
return "http://alitm.qifu-dev.gongsibao.com";
} else {
return "http://center-channel-service.chaolai";
}
},
qifutongUrl: () => { //---------center-channel
if (ENVINPUT.APP_ENV == "dev") {
return "http://gsbweb.qifu-dev.gongsibao.com";
} else {
return "https://fqgsbweb.gongsibao.com";
}
},
},
pmappname: "center-app",
pmappid: 1,
pmcompanyid: 1,
......
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