Commit 77078641 by 胡悦

GMV数据和商机明细 提交

1 parent ce92b964
/*
* @Author: huyue
* @Date: 2020-06-15 11:10:54
* @Last Modified by: huyue
* @Last Modified time: 2020-06-16 15:38:24
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/clues
* @Description 商机明细
*/
class cluesController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validate.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.cluesService = ctx.service.biz.clues;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @summary 查询商机明细
* @Router POST /biz/clues/findAll
* @Description 查询商机明细
* @Request pager
* @Request searcher
* @Response 200 response ok
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
const result = await this.cluesService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = cluesController;
\ No newline at end of file \ No newline at end of file
/*
* @Author: huyue
* @Date: 2020-06-16 15:38:21
* @Last Modified by: huyue
* @Last Modified time: 2020-06-18 11:13:07
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller biz/opportunity
* @Description GMV数据
*/
class opportunityController extends Controller {
constructor(ctx) {
super(ctx);
this.validate = ctx.app.validate.validate;
this.request = ctx.request;
this.helper = ctx.helper;
this.redis = ctx.app.redis;
this.opportunityService = ctx.service.biz.opportunity;
// this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @summary 查询GMV数据
* @Router POST /biz/opportunity/findAll
* @Description 查询GMV数据
* @Request pager
* @Request searcher
* @Response 200 response ok
*/
async findAll({ request: { body: { pager, searcher } } }) { //get : async findAll( {query: { pager, searcher } })
const result = await this.opportunityService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
/**
* @summary 查询GMV统计
* @Router POST /biz/opportunity/findCount
* @Description 查询GMV数据
* @Request searcher
* @Response 200 response ok
*/
async findCount({ request: { body: { searcher } } }) { //get : async findAll( {query: { pager, searcher } })
const result = await this.opportunityService.findCount({ searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = opportunityController;
/* /*
* @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: huyue
* @Last Modified time: 2020-06-15 10:07:44 * @Last Modified time: 2020-06-18 10:50:28
*/ */
module.exports = (app) => { module.exports = (app) => {
...@@ -11,4 +11,7 @@ module.exports = (app) => { ...@@ -11,4 +11,7 @@ module.exports = (app) => {
app.router.get("/biz/shop/findAll", app.controller.biz.shop.findAll); app.router.get("/biz/shop/findAll", app.controller.biz.shop.findAll);
app.router.get("/biz/record/findAll", app.controller.biz.record.findAll); app.router.get("/biz/record/findAll", app.controller.biz.record.findAll);
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/clues/findAll", app.controller.biz.clues.findAll);
app.router.get("/biz/opportunity/findAll", app.controller.biz.opportunity.findAll);
app.router.get("/biz/opportunity/findCount", app.controller.biz.opportunity.findCount);
}; };
/*
* @Author: huyue
* @Date: 2020-06-15 10:57:33
* @Last Modified by: huyue
* @Last Modified time: 2020-06-16 15:36:30
*/
const Service = require("egg").Service;
class CluesService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
GlsxBasicClues
} = this.app.model.Biz;
this.MGBC = GlsxBasicClues;
}
/**
* 绑定表关系
*/
_associate_() {}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager
const {
bizType,
isArrshop,
sn,
merchantName,
clueStartTime,
clueEndTime
} = searcher;
const offset = (current - 1) * size;
const {
Op,
col,
literal
} = this.app.Sequelize
let where = {
// is_new: 1
};
if (bizType) {
where.biz_type = bizType
}
if (isArrshop) {
if (isArrshop == '1') {
where.arrshop_time = {
[Op.not]: null
}
} else {
where.arrshop_time = {
[Op.is]: null
}
}
}
if (clueStartTime) {
if (clueEndTime) {
where.clue_time = {
[Op.and]: [{
[Op.gte]: clueStartTime
},
{
[Op.lte]: clueEndTime
}
]
}
}
}
if (sn) {
const __like = `%${sn}%`
where.sn = {
[Op.like]: __like
}
}
if (merchantName) {
const __like = `%${merchantName}%`
where.merchant_name = {
[Op.like]: __like
}
}
return await this.MGBC.findAndCountAll({
offset,
limit: +size,
where,
raw: true,
});
}
}
module.exports = CluesService;
\ No newline at end of file \ No newline at end of file
/*
* @Author: huyue
* @Date: 2020-06-16 15:36:11
* @Last Modified by: huyue
* @Last Modified time: 2020-06-18 16:17:19
*/
const Service = require("egg").Service;
class OpportunityService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
GlsxBizOpportunity,
DjSystemMerchant
} = this.app.model.Biz;
this.MGBO = GlsxBizOpportunity;
this.MDSM = DjSystemMerchant;
}
/**
* 绑定表关系
*/
_associate_() {}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 查询所有
*/
async findAll({
pager = {},
searcher = {}
}) {
const {
current = 1, size = 10
} = pager
const {
month,
merchantName
} = searcher;
const offset = (current - 1) * size;
const {
Op,
col,
literal,
fn,
set
} = this.app.Sequelize
let where = {}
let merchantWhere = {}
if (month) {
where.month = month
}
if (merchantName) {
const __like = `%${merchantName}%`
merchantWhere.merchant_name = {
[Op.like]: __like
}
}
// opportunity分页数据
return await this.MGBO.findAndCountAll({
// attributes: [fn('COUNT', col('total_gmv'))], [fn('SUM', col('maintain_crues')), 'maintainCruesSum']
attributes: {
include: [col('dj_system_merchant.merchant_name')]
},
offset,
limit: +size,
where,
raw: true,
include: [
{
model: this.MDSM,
as: 'dj_system_merchant',
attributes:[
// [col('dj_system_merchant.merchant_id'), 'merchant_id'],
// [col('merchant_name'), 'merchant_name']
],
where: merchantWhere,
associate: this.MGBO.belongsTo(this.MDSM, {foreignKey: 'merchant_id', targetKey: 'merchant_id', constraints: false})
}
]
})
}
async findCount({
searcher = {}
}) {
const { month, merchantName } = searcher
const {
Op,
col,
fn
} = this.app.Sequelize
let where = {}
let merchantWhere = {}
if (month) {
where.month = month
}
if (merchantName) {
const __like = `%${merchantName}%`
merchantWhere.merchant_name = {
[Op.like]: __like
}
}
return await this.MGBO.findAll({
attributes: [
[fn('SUM', col('total_gmv')), 'totalGMV'],
[fn('SUM', col('maintain_crues')), 'maintainCruesSum'],
[fn('SUM', col('maintain_arr')), 'maintainArrSum'],
[fn('SUM', col('maintain_gmv')), 'maintainGMVSum'],
[fn('SUM', col('loss_crues')), 'lossCruesSum'],
[fn('SUM', col('loss_arr')), 'lossArrSum'],
[fn('SUM', col('loss_gmv')), 'lossGMVSum'],
[fn('SUM', col('collision_crues')), 'collisionCruesSum'],
[fn('SUM', col('collision_arr')), 'collisionArrSum'],
[fn('SUM', col('collision_gmv')), 'collisionGMVSum'],
],
where,
raw: true,
include: [
{
model: this.MDSM,
attributes:[],
where: merchantWhere,
associate: this.MGBO.belongsTo(this.MDSM, {foreignKey: 'merchant_id', targetKey: 'merchant_id', constraints: false})
}
]
})
}
}
module.exports = OpportunityService;
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!