Commit 886f5a0a by cwq0219

出货统计

1 parent fced1a7f
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: chenwq * @Author: chenwq
* @Date: 2020-06-17 11:12:15 * @Date: 2020-06-17 11:12:15
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-18 10:18:15 * @Last Modified time: 2020-06-19 13:51:10
*/ */
"use strict"; "use strict";
...@@ -29,16 +29,28 @@ ...@@ -29,16 +29,28 @@
* @summary 查询所有出货信息 * @summary 查询所有出货信息
* @Router POST /biz/delivery/findAll * @Router POST /biz/delivery/findAll
* @Description 查询所有出货信息 * @Description 查询所有出货信息
* @Request pager
* @Request searcher * @Request searcher
* @Response 200 response ok * @Response 200 response ok
*/ */
async findAll({ request: { body: { pager, searcher }}}) { async findAll({ request: { body: { searcher }}}) {
// get请求获取参数 // get请求获取参数
// searcher = this.ctx.query // searcher = this.ctx.query
const result = await this.deliveryServices.findAll({ pager, searcher }); const result = await this.deliveryServices.findAll({ searcher });
// const result = await this.deliveryServices.findAll({ pager, searcher }); // const result = await this.deliveryServices.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result); this.ctx.body = this.ServerResponse.Success(result);
} }
/**
* @summary 查询所有出货统计
* @Router POST /biz/delivery/findCount
* @Description 查询所有出货统计
* @Request pager
* @Request searcher
* @Response 200 response ok
*/
async findCount({ request: {body: { searcher }}}) {
const result = await this.deliveryServices.findCount({ searcher });
this.ctx.body = this.ServerResponse.Success(result[0]);
}
} }
module.exports = deliveryController; module.exports = deliveryController;
\ No newline at end of file \ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:19:15 * @Date: 2019-11-21 11:19:15
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-19 10:45:07 * @Last Modified time: 2020-06-19 11:45:09
*/ */
module.exports = (app) => { module.exports = (app) => {
...@@ -13,6 +13,7 @@ module.exports = (app) => { ...@@ -13,6 +13,7 @@ module.exports = (app) => {
app.router.get("/biz/merchant/findAll", app.controller.biz.merchant.findAll); app.router.get("/biz/merchant/findAll", app.controller.biz.merchant.findAll);
app.router.get("/biz/devices/findAll", app.controller.biz.devices.findAll); app.router.get("/biz/devices/findAll", app.controller.biz.devices.findAll);
app.router.get("/biz/delivery/findAll", app.controller.biz.delivery.findAll); app.router.get("/biz/delivery/findAll", app.controller.biz.delivery.findAll);
app.router.get("/biz/delivery/findCount", app.controller.biz.delivery.findCount);
app.router.get("/biz/clues/findAll", app.controller.biz.clues.findAll); app.router.get("/biz/clues/findAll", app.controller.biz.clues.findAll);
app.router.get("/biz/opportunity/findAll", app.controller.biz.opportunity.findAll); app.router.get("/biz/opportunity/findAll", app.controller.biz.opportunity.findAll);
app.router.get("/biz/opportunity/findCount", app.controller.biz.opportunity.findCount); app.router.get("/biz/opportunity/findCount", app.controller.biz.opportunity.findCount);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: chenwq * @Author: chenwq
* @Date: 2020-06-16 10:02:28 * @Date: 2020-06-16 10:02:28
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-18 17:54:00 * @Last Modified time: 2020-06-19 13:51:21
* 出货统计 * 出货统计
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
...@@ -107,5 +107,76 @@ class deliveryServices extends Service { ...@@ -107,5 +107,76 @@ class deliveryServices extends Service {
}); });
return date; return date;
} }
// 计算总数
async findCount({
searcher = {}
}) {
const {
month,
merchantId,
shopMerchantId,
bizType,
deviceType
} = searcher;
const {
Op,
col,
fn
} = this.app.Sequelize
let where = {};
let andDateArr = [{
name: 'month',
sqlName: 'month'
}]
let likeArr = [{
name: 'merchantName',
sqlName: 'merchant_name'
}, {
name: 'shopMerchantName',
sqlName: 'merchant_name'
}]
let equalArr = [{
name: 'deviceType',
sqlName: 'device_type'
}, {
name: 'bizType',
sqlName: 'biz_type'
}]
andDateArr.map(item => {
if (searcher[item.name]) {
let nextDate = new Date(searcher[item.name])
new Date(nextDate.setMonth(nextDate.getMonth() + 1))
let nextMonth = nextDate.getMonth() > 8 ? (nextDate.getMonth() + 1) : ('0' + (nextDate.getMonth() + 1))
where[item.sqlName] = {
[Op.and]: [{
[Op.gte]: searcher[item.name]
}, {
[Op.lt]: nextDate.getFullYear() + '-' + nextMonth
}]
}
}
})
likeArr.map(item => {
if (searcher[item.name]) {
where[item.sqlName] = {
[Op.like]: `%${searcher[item.name]}%`
}
}
})
equalArr.map(item => {
if (searcher[item.name]) {
where[item.sqlName] = searcher[item.name]
}
})
return await this.GBDL.findAll({
attributes: [
[fn('SUM', col('delivery_total')), 'deliveryTotal'],
[fn('SUM', col('active_total')), 'activeTotal']
],
where,
raw: true
})
}
} }
module.exports = deliveryServices; module.exports = deliveryServices;
\ No newline at end of file \ No newline at end of file
/* /*
* @Author: huyue * @Author: huyue
* @Date: 2020-06-16 15:36:11 * @Date: 2020-06-16 15:36:11
* @Last Modified by: huyue * @Last Modified by: chenwq
* @Last Modified time: 2020-06-18 16:17:19 * @Last Modified time: 2020-06-19 11:40:03
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!