Commit b05ec69a by linboxuan

lin add order/need statistics

parent d6ebca55
...@@ -146,6 +146,24 @@ class StatisticsCtl extends CtlBase { ...@@ -146,6 +146,24 @@ class StatisticsCtl extends CtlBase {
} }
} }
// 渠道订单统计
async getChannelOrderStatistics(pobj, qobj, req) {
try {
const rs = await this.service.getChannelOrderStatistics(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
async getChannelNeedStatistics(pobj, qobj, req) {
try {
const rs = await this.service.getChannelNeedStatistics(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
} }
module.exports = StatisticsCtl; module.exports = StatisticsCtl;
const ToQiFuTong = require('../../../utils/qifutong/baseClient').getInstance(); const ToQiFuTong = require('../../../utils/qifutong/baseClient').getInstance();
const _ = require("lodash"); const _ = require("lodash");
class StatisticsService { class StatisticsService {
async getAllChannels(pobj) { async getAllChannels(pobj) {
return ToQiFuTong.getAllChannels(); return ToQiFuTong.getAllChannels();
}
async getAllService(pobj) {
return ToQiFuTong.getAllService();
}
async getAllProducts(pobj) {
return ToQiFuTong.getAllProducts();
}
async getPathName(pobj) {
return ToQiFuTong.getPathName();
}
async getStatisticsByUappId(pobj) {
const data = await ToQiFuTong.getStatisticsByUappId({
start: pobj.start,
end: pobj.end,
type_name: pobj.type_code,
status: pobj.status
});
const dates = ToQiFuTong.getAllDate(pobj.start, pobj.end);
return {
x: dates,
data
};
}
async getOrderStatisticsByUappId(pobj) {
const data = await ToQiFuTong.getOrderStatisticsByUappId({
start: pobj.start,
end: pobj.end,
pathName: 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,
// status: pobj.status,
});
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 ? info.uapp_id.toString() : "");
result.push({
uapp_id: info.uapp_id ? info.uapp_id.toString() : "",
count: info.count,
type_code: val.type_code
})
}
productList.push({
count: productCount,
type_code: val.type_code
})
} }
async getAllService(pobj) { productList = productList.sort(function (a, b) { return a.count - b.count });
return ToQiFuTong.getAllService(); return {
channelList: [...channels],
productList: productList.map((item) => { return item.type_code }),
data: result
};
}
async getOrderStatisticsByProduct(pobj) {
const data = await ToQiFuTong.getOrderStatisticsByProduct({
start: pobj.start,
end: pobj.end,
// status: pobj.status,
});
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 ? info.uapp_id.toString() : "");
result.push({
uapp_id: info.uapp_id ? info.uapp_id.toString() : "",
count: info.count,
type_code: val.pathName.split("/")[1] + " - " + val.pathName.split("/")[2]
})
}
productList.push({
count: productCount,
type_code: val.pathName.split("/")[1] + " - " + val.pathName.split("/")[2]
})
} }
async getAllProducts(pobj) { productList = productList.sort(function (a, b) { return a.count - b.count });
return ToQiFuTong.getAllProducts(); return {
} channelList: [...channels],
async getPathName(pobj) { productList: productList.map((item) => { return item.type_code }),
return ToQiFuTong.getPathName(); data: result
} };
async getStatisticsByUappId(pobj) { }
const data = await ToQiFuTong.getStatisticsByUappId({
start: pobj.start, async getNeedFunnelStatistics(pobj) {
end: pobj.end, return ToQiFuTong.getNeedFunnelStatistics({
type_name: pobj.type_code, start: pobj.start,
status: pobj.status end: pobj.end,
}); type_name: pobj.type_code,
const dates = ToQiFuTong.getAllDate(pobj.start, pobj.end); uapp_id: pobj.uapp_id
return { });
x: dates, }
data
}; async getStatisticsByArea(pobj) {
} const data = await ToQiFuTong.getStatisticsByArea({
async getOrderStatisticsByUappId(pobj) { start: pobj.start,
const data = await ToQiFuTong.getOrderStatisticsByUappId({ end: pobj.end,
start: pobj.start, type_name: pobj.type_code,
end: pobj.end, uapp_id: pobj.uapp_id
pathName: pobj.type_code, });
status: pobj.status let result = {};
}); for (let val of data) {
const dates = ToQiFuTong.getAllDate(pobj.start, pobj.end); const region = val.province.replace(/(.*)(市|省)$/, '$1');
return { let sum = 0
x: dates, for (let info of val.data) {
data sum += info.count;
}; }
} if (result[region]) {
async getStatisticsByProduct(pobj) { let productInfo = _.groupBy([...val.data, ...result[region].data], "type_code");
const data = await ToQiFuTong.getStatisticsByProduct({ let productInfoList = [];
start: pobj.start, for (let key in productInfo) {
end: pobj.end, let count = 0;
// status: pobj.status, for (let info of productInfo[key]) {
}); count += info.count;
let result = []; // 基础数据 }
let channels = new Set(); //渠道 productInfoList.push({
let productList = []; //产品 count,
for (let val of data) { type_code: key
let productCount = 0; });
for (let info of val.data) {
productCount += info.count;
channels.add(info.uapp_id ? info.uapp_id.toString() : "");
result.push({
uapp_id: info.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 }); result[region] = {
return { sum: result[region].sum + sum,
channelList: [...channels], data: productInfoList
productList: productList.map((item) => { return item.type_code }), }
data: result } else {
}; result[region] = {
} sum: sum,
async getOrderStatisticsByProduct(pobj) { data: val.data
const data = await ToQiFuTong.getOrderStatisticsByProduct({
start: pobj.start,
end: pobj.end,
// status: pobj.status,
});
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 ? info.uapp_id.toString() : "");
result.push({
uapp_id: info.uapp_id ? info.uapp_id.toString() : "",
count: info.count,
type_code: val.pathName.split("/")[1] + " - " + val.pathName.split("/")[2]
})
}
productList.push({
count: productCount,
type_code: val.pathName.split("/")[1] + " - " + val.pathName.split("/")[2]
})
} }
productList = productList.sort(function (a, b) { return a.count - b.count }); }
return {
channelList: [...channels],
productList: productList.map((item) => { return item.type_code }),
data: result
};
} }
return result;
}
async getNeedFunnelStatistics(pobj) { async getNeedComparison(pobj) {
return ToQiFuTong.getNeedFunnelStatistics({ const data = await ToQiFuTong.getNeedComparison({
start: pobj.start, startNow: pobj.startNow,
end: pobj.end, endNow: pobj.endNow,
type_name: pobj.type_code, startLast: pobj.startLast,
uapp_id: pobj.uapp_id endLast: pobj.endLast,
}); type_name: pobj.type_code,
} uapp_id: pobj.uapp_id
});
return {
businessStatistics: {
sum: data.now.total,
lastSum: data.last.total,
type: ToQiFuTong.judgeSize(data.now.total, data.last.total),
contrast: (data.last.total === 0 ? (data.now.total === 0 ? 0 : 100) : ((data.now.total - data.last.total) / data.last.total * 100)).toFixed(2)
async getStatisticsByArea(pobj) { },
const data = await ToQiFuTong.getStatisticsByArea({ businessToOrderStatistics: {
start: pobj.start, sum: data.now.order,
end: pobj.end, lastSum: data.last.order,
type_name: pobj.type_code, type: ToQiFuTong.judgeSize(data.now.order, data.last.order),
uapp_id: pobj.uapp_id contrast: (data.last.order === 0 ? (data.now.order === 0 ? 0 : 100) : ((data.now.order - data.last.order) / data.last.order * 100)).toFixed(2)
});
let result = {};
for (let val of data) {
const region = val.province.replace(/(.*)(市|省)$/, '$1');
let sum = 0
for (let info of val.data) {
sum += info.count;
}
if (result[region]) {
let productInfo = _.groupBy([...val.data, ...result[region].data], "type_code");
let productInfoList = [];
for (let key in productInfo) {
let count = 0;
for (let info of productInfo[key]) {
count += info.count;
}
productInfoList.push({
count,
type_code: key
});
}
result[region] = {
sum: result[region].sum + sum,
data: productInfoList
}
} else {
result[region] = {
sum: sum,
data: val.data
}
}
}
return result;
}
async getNeedComparison(pobj) { }
const data = await ToQiFuTong.getNeedComparison({ };
startNow: pobj.startNow, }
endNow: pobj.endNow, async getOrdersComparison(pobj) {
startLast: pobj.startLast, const data = await ToQiFuTong.getOrdersComparison({
endLast: pobj.endLast, startNow: pobj.startNow,
type_name: pobj.type_code, endNow: pobj.endNow,
uapp_id: pobj.uapp_id startLast: pobj.startLast,
}); endLast: pobj.endLast,
return { pathName: pobj.type_code,
businessStatistics: { uapp_id: pobj.uapp_id
sum: data.now.total, });
lastSum: data.last.total, return {
type: ToQiFuTong.judgeSize(data.now.total, data.last.total), orderStatistics: {
contrast: (data.last.total === 0 ? (data.now.total === 0 ? 0 : 100) : ((data.now.total - data.last.total) / data.last.total * 100)).toFixed(2) sum: data.now.total,
lastSum: data.last.total,
type: ToQiFuTong.judgeSize(data.now.total, data.last.total),
contrast: (data.last.total === 0 ? (data.now.total === 0 ? 0 : 100) : ((data.now.total - data.last.total) / data.last.total * 100)).toFixed(2)
}, }
businessToOrderStatistics: { };
sum: data.now.order, }
lastSum: data.last.order,
type: ToQiFuTong.judgeSize(data.now.order, data.last.order),
contrast: (data.last.order === 0 ? (data.now.order === 0 ? 0 : 100) : ((data.now.order - data.last.order) / data.last.order * 100)).toFixed(2)
} async getStatisticsList(pobj) {
}; const data = await ToQiFuTong.getStatisticsList({
} start: pobj.start,
async getOrdersComparison(pobj) { end: pobj.end,
const data = await ToQiFuTong.getOrdersComparison({ uapp_id: pobj.uapp_id,
startNow: pobj.startNow, type_code: pobj.type_code,
endNow: pobj.endNow, type_name: pobj.type_code,
startLast: pobj.startLast, pathName: pobj.type_code,
endLast: pobj.endLast, pageIndex: pobj.pageNum || 1,
pathName: pobj.type_code, pageSize: pobj.pageSize || 10,
uapp_id: pobj.uapp_id listType: pobj.listType,
}); fuzzy_code: pobj.fuzzy_code,
return { status: pobj.status
orderStatistics: { });
sum: data.now.total, return data;
lastSum: data.last.total, }
type: ToQiFuTong.judgeSize(data.now.total, data.last.total),
contrast: (data.last.total === 0 ? (data.now.total === 0 ? 0 : 100) : ((data.now.total - data.last.total) / data.last.total * 100)).toFixed(2)
} async importTxNeeds(pobj) {
}; const data = await ToQiFuTong.importTxNeeds(pobj);
} return data;
}
async getNeedProductType(pobj) {
const data = await ToQiFuTong.getNeedProductType(pobj);
return data;
}
async getStatisticsList(pobj) { async getChannelOrderStatistics(pobj) {
const data = await ToQiFuTong.getStatisticsList({ const data = await ToQiFuTong.getChannelOrderStatistics(pobj);
start: pobj.start, return data;
end: pobj.end, }
uapp_id: pobj.uapp_id,
type_code: pobj.type_code,
type_name: pobj.type_code,
pathName: pobj.type_code,
pageIndex: pobj.pageNum || 1,
pageSize: pobj.pageSize || 10,
listType: pobj.listType,
fuzzy_code: pobj.fuzzy_code,
status: pobj.status
});
return data;
}
async importTxNeeds(pobj) { async getChannelNeedStatistics(pobj) {
const data = await ToQiFuTong.importTxNeeds(pobj); const data = await ToQiFuTong.getChannelNeedStatistics(pobj);
return data; return data;
} }
async getNeedProductType(pobj) {
const data = await ToQiFuTong.getNeedProductType(pobj);
return data;
}
} }
module.exports = StatisticsService; module.exports = StatisticsService;
\ No newline at end of file
...@@ -219,6 +219,22 @@ class BaseClient { ...@@ -219,6 +219,22 @@ class BaseClient {
return data; return data;
} }
async getChannelOrderStatistics(pobj) {
const data = await this.pushQiFuTong('/web/opaction/order/springBoard', {
"actionType": "getOrderStatisticsByChannel",
"actionBody": pobj
});
return data;
}
async getChannelNeedStatistics(pobj) {
const data = await this.pushQiFuTong('/web/action/opNeed/springBoard', {
"actionType": "getStatisticsByChannel",
"actionBody": pobj
});
return data;
}
async importTxNeeds(pobj) { async importTxNeeds(pobj) {
let url; let url;
let query; let query;
......
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