|
@@ -111,10 +111,11 @@ class AdminService extends CrudService {
|
|
|
* @property {Array} start 开始
|
|
|
* @property {Array} end 结束
|
|
|
* @property {Array} range 指定的时间范围;如果没传,则根据type自动生成
|
|
|
+ * @property {String} status 订单状态(1为,支付单)
|
|
|
*/
|
|
|
async makeOrder(query) {
|
|
|
const pipline = [];
|
|
|
- const { type = 'week', start, end, shop } = query;
|
|
|
+ const { type = 'week', start, end, shop, status } = query;
|
|
|
let timeRange = [];
|
|
|
if (type === 'custom') {
|
|
|
const r = moment(start).isBefore(end);
|
|
@@ -125,6 +126,9 @@ class AdminService extends CrudService {
|
|
|
if (ObjectId.isValid(shop)) {
|
|
|
pipline.push({ $match: { shop } });
|
|
|
}
|
|
|
+ if (status) {
|
|
|
+ pipline.push({ $match: { status } });
|
|
|
+ }
|
|
|
// 时间格式化: create_date:日期,用来分组统计; create_time: 时间,用来过滤数据
|
|
|
pipline.push({
|
|
|
$project: {
|
|
@@ -157,7 +161,7 @@ class AdminService extends CrudService {
|
|
|
*/
|
|
|
async makeAfterSale(query) {
|
|
|
const pipline = [];
|
|
|
- const { type = 'week', start, end, shop } = query;
|
|
|
+ const { type = 'week', start, end, shop, status } = query;
|
|
|
let timeRange = [];
|
|
|
if (type === 'custom') {
|
|
|
const r = moment(start).isBefore(end);
|
|
@@ -168,6 +172,9 @@ class AdminService extends CrudService {
|
|
|
if (ObjectId.isValid(shop)) {
|
|
|
pipline.push({ $match: { shop } });
|
|
|
}
|
|
|
+ if (status) {
|
|
|
+ pipline.push({ $match: { status } });
|
|
|
+ }
|
|
|
// 时间格式化: create_date:日期,用来分组统计; create_time: 时间,用来过滤数据
|
|
|
pipline.push({
|
|
|
$project: {
|
|
@@ -194,6 +201,51 @@ class AdminService extends CrudService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询销售额
|
|
|
+ * @param {Object} query 查询条件
|
|
|
+ */
|
|
|
+ async sellTotal(query) {
|
|
|
+ const pipline = [];
|
|
|
+ const { type = 'week', start, end, shop } = query;
|
|
|
+ let timeRange = [];
|
|
|
+ if (type === 'custom') {
|
|
|
+ const r = moment(start).isBefore(end);
|
|
|
+ if (r) timeRange.push(start, end);
|
|
|
+ else timeRange.push(end, start);
|
|
|
+ } else timeRange = this.getDefaultRange(type);
|
|
|
+ // 先用商店过滤下
|
|
|
+ if (ObjectId.isValid(shop)) {
|
|
|
+ pipline.push({ $match: { shop } });
|
|
|
+ }
|
|
|
+ pipline.push({ $match: { status: '1' } });
|
|
|
+ // 时间格式化: create_date:日期,用来分组统计; create_time: 时间,用来过滤数据
|
|
|
+ pipline.push({
|
|
|
+ $project: {
|
|
|
+ create_date: { $dateToString: { date: '$meta.createdAt', ...this.pipDateFormatDateObject() } },
|
|
|
+ create_time: { $dateToString: { date: '$meta.createdAt', ...this.pipDateFormatTimeObject() } },
|
|
|
+ money: '$pay.pay_money',
|
|
|
+ },
|
|
|
+ });
|
|
|
+ pipline.push({ $match: { $and: [{ create_time: { $gte: _.head(timeRange) } }, { create_time: { $lte: _.last(timeRange) } }] } });
|
|
|
+ pipline.push({
|
|
|
+ $group: {
|
|
|
+ _id: '$create_date',
|
|
|
+ money: { $sum: '$money' },
|
|
|
+ },
|
|
|
+ });
|
|
|
+ const fs = await this.orderModel.aggregate(pipline);
|
|
|
+ const list = this.getRangeDateList(timeRange);
|
|
|
+ const result = [];
|
|
|
+ for (const d of list) {
|
|
|
+ const r = fs.find(f => f._id === d);
|
|
|
+ const obj = { date: d, money: 0 };
|
|
|
+ if (r) obj.money = r.money;
|
|
|
+ result.push(obj);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
// 聚合总数管道
|
|
|
totalPip() {
|
|
|
return {
|