123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 'use strict'
- import StatisModel from '../../models/statis/statis'
- import UserInfoModel from '../../models/v2/userInfo'
- import OrderModel from '../../models/bos/order'
- import dtime from 'time-formater'
- class Statis {
- constructor(){
- }
- async apiCount(req, res, next){
- const date = req.params.date;
- if (!date) {
- console.log('参数错误')
- res.send({
- status: 0,
- type: 'ERROR_PARAMS',
- message: '参数错误'
- })
- return
- }
- try{
- const count = await StatisModel.find({date}).count()
- res.send({
- status: 1,
- count,
- })
- }catch(err){
- console.log('获取当天API请求次数失败');
- res.send({
- status: 0,
- type: 'ERROR_GET_TODAY_API_COUNT',
- message: '获取当天API请求次数失败'
- })
- }
- }
- async apiAllCount(req, res, next){
- try{
- const count = await StatisModel.count()
- res.send({
- status: 1,
- count,
- })
- }catch(err){
- console.log('获取所有API请求次数失败');
- res.send({
- status: 0,
- type: 'ERROR_GET_ALL_API_COUNT',
- message: '获取所有API请求次数失败'
- })
- }
- }
- async allApiRecord(req, res, next){
- try{
- const allRecord = await StatisModel.find({}, '-_id -__v')
- res.send(allRecord)
- }catch(err){
- console.log('获取所有API请求信息失败');
- res.send({
- status: 0,
- type: 'GET_ALL_API_RECORD_DATA_FAILED',
- message: '获取所有API请求信息失败'
- })
- }
- }
- async userCount(req, res, next){
- const date = req.params.date;
- if (!date) {
- console.log('参数错误')
- res.send({
- status: 0,
- type: 'ERROR_PARAMS',
- message: '参数错误'
- })
- return
- }
- try{
- const count = await UserInfoModel.find({registe_time: eval('/^' + date + '/gi')}).count()
- res.send({
- status: 1,
- count,
- })
- }catch(err){
- console.log('获取当天注册人数失败');
- res.send({
- status: 0,
- type: 'ERROR_GET_USER_REGISTE_COUNT',
- message: '获取当天注册人数失败'
- })
- }
- }
- async orderCount(req, res, next){
- const date = req.params.date;
- if (!date) {
- console.log('参数错误')
- res.send({
- status: 0,
- type: 'ERROR_PARAMS',
- message: '参数错误'
- })
- return
- }
- try{
- const count = await OrderModel.find({formatted_created_at: eval('/^' + date + '/gi')}).count()
- res.send({
- status: 1,
- count,
- })
- }catch(err){
- console.log('获取当天订单数量失败');
- res.send({
- status: 0,
- type: 'ERROR_GET_ORDER_COUNT',
- message: '获取当天订单数量失败'
- })
- }
- }
- }
- export default new Statis()
|