statis.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 'use strict'
  2. import StatisModel from '../../models/statis/statis'
  3. import UserInfoModel from '../../models/v2/userInfo'
  4. import OrderModel from '../../models/bos/order'
  5. import dtime from 'time-formater'
  6. class Statis {
  7. constructor(){
  8. }
  9. async apiCount(req, res, next){
  10. const date = req.params.date;
  11. if (!date) {
  12. console.log('参数错误')
  13. res.send({
  14. status: 0,
  15. type: 'ERROR_PARAMS',
  16. message: '参数错误'
  17. })
  18. return
  19. }
  20. try{
  21. const count = await StatisModel.find({date}).count()
  22. res.send({
  23. status: 1,
  24. count,
  25. })
  26. }catch(err){
  27. console.log('获取当天API请求次数失败');
  28. res.send({
  29. status: 0,
  30. type: 'ERROR_GET_TODAY_API_COUNT',
  31. message: '获取当天API请求次数失败'
  32. })
  33. }
  34. }
  35. async apiAllCount(req, res, next){
  36. try{
  37. const count = await StatisModel.count()
  38. console.log(count.toString())
  39. res.send({
  40. status: 1,
  41. count,
  42. })
  43. }catch(err){
  44. console.log('获取所有API请求次数失败');
  45. res.send({
  46. status: 0,
  47. type: 'ERROR_GET_ALL_API_COUNT',
  48. message: '获取所有API请求次数失败'
  49. })
  50. }
  51. }
  52. async allApiRecord(req, res, next){
  53. try{
  54. const allRecord = await StatisModel.find({}, '-_id -__v')
  55. res.send(allRecord)
  56. }catch(err){
  57. console.log('获取所有API请求信息失败');
  58. res.send({
  59. status: 0,
  60. type: 'GET_ALL_API_RECORD_DATA_FAILED',
  61. message: '获取所有API请求信息失败'
  62. })
  63. }
  64. }
  65. async userCount(req, res, next){
  66. const date = req.params.date;
  67. if (!date) {
  68. console.log('参数错误')
  69. res.send({
  70. status: 0,
  71. type: 'ERROR_PARAMS',
  72. message: '参数错误'
  73. })
  74. return
  75. }
  76. try{
  77. const count = await UserInfoModel.find({registe_time: eval('/^' + date + '/gi')}).count()
  78. res.send({
  79. status: 1,
  80. count,
  81. })
  82. }catch(err){
  83. console.log('获取当天注册人数失败');
  84. res.send({
  85. status: 0,
  86. type: 'ERROR_GET_USER_REGISTE_COUNT',
  87. message: '获取当天注册人数失败'
  88. })
  89. }
  90. }
  91. async orderCount(req, res, next){
  92. const date = req.params.date;
  93. if (!date) {
  94. console.log('参数错误')
  95. res.send({
  96. status: 0,
  97. type: 'ERROR_PARAMS',
  98. message: '参数错误'
  99. })
  100. return
  101. }
  102. try{
  103. const count = await OrderModel.find({formatted_created_at: eval('/^' + date + '/gi')}).count()
  104. res.send({
  105. status: 1,
  106. count,
  107. })
  108. }catch(err){
  109. console.log('获取当天订单数量失败');
  110. res.send({
  111. status: 0,
  112. type: 'ERROR_GET_ORDER_COUNT',
  113. message: '获取当天订单数量失败'
  114. })
  115. }
  116. }
  117. }
  118. export default new Statis()