Commit e5db0b29 by 胡悦

Merge branch 'master' of 192.168.3.233:glsx-serivce/glsx-insurance-server

2 parents ae08443b 886f5a0a
/*
* @Author: chenwq
* @Date: 2020-06-17 11:12:15
* @Last Modified by: chenwq
* @Last Modified time: 2020-06-19 13:51:10
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller delivery
* @Description 出货统计
*/
class deliveryController 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.deliveryServices = ctx.service.biz.delivery;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @summary 查询所有出货信息
* @Router POST /biz/delivery/findAll
* @Description 查询所有出货信息
* @Request searcher
* @Response 200 response ok
*/
async findAll({ request: { body: { searcher }}}) {
// get请求获取参数
// searcher = this.ctx.query
const result = await this.deliveryServices.findAll({ searcher });
// const result = await this.deliveryServices.findAll({ pager, searcher });
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;
\ No newline at end of file \ No newline at end of file
/*
* @Author: chenwq
* @Date: 2020-06-16 10:40:02
* @Last Modified by: chenwq
* @Last Modified time: 2020-06-16 15:41:19
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller devices
* @Description 设备信息
*/
class devicesController 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.devicesService = ctx.service.biz.devices;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @summary 查询所有设备信息
* @Router POST /biz/devices/findAll
* @Description 查询所有设备信息
* @Request pager
* @Request searcher
* @Response 200 response ok
*/
async findAll({ request: { body: { pager, searcher } } }) {
const result = await this.devicesService.findAll({ pager, searcher });
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = devicesController;
\ No newline at end of file \ No newline at end of file
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
* @Author: chenwq * @Author: chenwq
* @Date: 2020-06-12 14:30:26 * @Date: 2020-06-12 14:30:26
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-12 17:17:26 * @Last Modified time: 2020-06-17 11:14:33
*/ */
"use strict"; "use strict";
const Controller = require("egg").Controller; const Controller = require("egg").Controller;
/** /**
* @Controller biz/merchant * @Controller merchant
* @Description 商户信息 * @Description 商户信息
*/ */
......
/* /*
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:19:15 * @Date: 2019-11-21 11:19:15
* @Last Modified by: huyue * @Last Modified by: chenwq
* @Last Modified time: 2020-06-18 10:50:28 * @Last Modified time: 2020-06-19 11:45:09
*/ */
module.exports = (app) => { module.exports = (app) => {
...@@ -11,6 +11,9 @@ module.exports = (app) => { ...@@ -11,6 +11,9 @@ 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/devices/findAll", app.controller.biz.devices.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);
......
/*
* @Author: chenwq
* @Date: 2020-06-16 10:02:28
* @Last Modified by: chenwq
* @Last Modified time: 2020-06-19 13:51:21
* 出货统计
*/
const Service = require("egg").Service;
class deliveryServices extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
GlsxBizDelivery,
DjSystemMerchant
} = this.app.model.Biz;
this.GBDL = GlsxBizDelivery;
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,
merchantId,
shopMerchantId,
bizType,
deviceType
} = searcher;
const offset = (current - 1) * size;
const {
Op,
col
} = 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]
}
})
let date = await this.GBDL.findAndCountAll({
offset,
limit: +size,
where,
raw: true
});
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;
\ No newline at end of file \ No newline at end of file
/*
* @Author: chenwq
* @Date: 2020-06-16 10:02:39
* @Last Modified by: chenwq
* @Last Modified time: 2020-06-18 17:52:25
* 设备信息
*/
const Service = require("egg").Controller;
class DevicesService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_()
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
GlsxBasicDevices,
DjSystemMerchant
} = this.app.model.Biz;
this.GBDE = GlsxBasicDevices;
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 {
sn,
deviceType,
bizType,
outStorageTime,
activeTime,
latestGpstime
} = searcher;
const offset = (current - 1) * size;
const {
Op,
col
} = this.app.Sequelize;
let where = {};
if (sn) {
where.sn = {
[Op.like]: `%${sn}%`
}
}
let andDateArr = [{
name: 'outStorageTime',
sqlName: 'out_storage_time'
}, {
name: 'activeTime',
sqlName: 'active_time'
}, {
name: 'latestGpstime',
sqlName: 'latest_gpstime'
}]
let equalArr = [{
name: 'deviceType',
sqlName: 'device_type'
}, {
name: 'bizType',
sqlName: 'biz_type'
}]
andDateArr.map(item => {
if (searcher[item.name]) {
where[item.sqlName] = {
[Op.and]: [{
[Op.gt]: searcher[item.name]
}, {
[Op.lt]: new Date(new Date(searcher[item.name]).getTime() + 24 * 60 * 60 * 1000).toLocaleDateString()
}]
}
}
})
equalArr.map(item => {
if (searcher[item.name]) {
where[item.sqlName] = searcher[item.name]
}
})
return await this.GBDE.findAndCountAll({
attributes: {
include: [
[col('dj_system_merchant.merchant_name'), 'shop_merchant_name']
]
},
offset,
limit: +size,
where,
raw: true,
include: [{
model: this.MDSM,
as: 'dj_system_merchant',
attributes: [],
associate: this.GBDE.belongsTo(this.MDSM, {
foreignKey: 'shop_merchant_id',
targetKey: 'merchant_id'
})
}]
})
}
}
module.exports = DevicesService;
\ No newline at end of file \ No newline at end of file
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
* @Author: chenwq * @Author: chenwq
* @Date: 2020-06-12 15:19:31 * @Date: 2020-06-12 15:19:31
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-12 18:03:58 * @Last Modified time: 2020-06-18 11:29:42
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
class MerchantService extends Service { class MerchantService extends Service {
...@@ -43,9 +42,9 @@ class MerchantService extends Service { ...@@ -43,9 +42,9 @@ class MerchantService extends Service {
const { const {
merchantId, merchantId,
merchantName, merchantName,
channel, channelId,
provinceId, provinceId,
distributor parentMerchantName
} = searcher; } = searcher;
const offset = (current - 1) * size; const offset = (current - 1) * size;
const { const {
...@@ -54,8 +53,34 @@ class MerchantService extends Service { ...@@ -54,8 +53,34 @@ class MerchantService extends Service {
literal literal
} = this.app.Sequelize; } = this.app.Sequelize;
let where = { let where = {
// is_new: 1
}; };
let likeArr = [{
name: 'merchantId',
sqlName: 'merchant_id'
}, {
name: 'merchantName',
sqlName: 'merchant_name'
}, {
name: 'parentMerchantName',
sqlName: 'parent_merchant_name'
}]
let equalArr = [{
name: 'channelId',
sqlName: 'channel_id'
}, {
name: 'provinceId',
sqlName: 'province_id'
}]
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.MDSM.findAndCountAll({ return await this.MDSM.findAndCountAll({
offset, offset,
limit: +size, limit: +size,
......
/* /*
* @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;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:26:53 * @Date: 2019-11-16 09:26:53
* @Last Modified by: chenwq * @Last Modified by: chenwq
* @Last Modified time: 2020-06-12 15:08:29 * @Last Modified time: 2020-06-18 14:13:05
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -98,7 +98,7 @@ module.exports = app => { ...@@ -98,7 +98,7 @@ module.exports = app => {
define: { define: {
freezeTableName: true, // 禁止修改表名,默认情况下,sequelize将自动将所有传递的模型名称(define的第一个参数)转换为复数 freezeTableName: true, // 禁止修改表名,默认情况下,sequelize将自动将所有传递的模型名称(define的第一个参数)转换为复数
// 但是为了安全着想,复数的转换可能会发生变化,所以禁止该行为 // 但是为了安全着想,复数的转换可能会发生变化,所以禁止该行为
timestamps: false, // 不自动维护时间戳 [ created_at、updated_at ] timestamps: false // 不自动维护时间戳 [ created_at、updated_at ]
}, },
dialectOptions: { dialectOptions: {
dateStrings: true, //格式化datetime dateStrings: true, //格式化datetime
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!