statis.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. res.send({
  39. status: 1,
  40. count,
  41. })
  42. }catch(err){
  43. console.log('获取所有API请求次数失败');
  44. res.send({
  45. status: 0,
  46. type: 'ERROR_GET_ALL_API_COUNT',
  47. message: '获取所有API请求次数失败'
  48. })
  49. }
  50. }
  51. async allApiRecord(req, res, next){
  52. try{
  53. const allRecord = await StatisModel.find({}, '-_id -__v')
  54. res.send(allRecord)
  55. }catch(err){
  56. console.log('获取所有API请求信息失败');
  57. res.send({
  58. status: 0,
  59. type: 'GET_ALL_API_RECORD_DATA_FAILED',
  60. message: '获取所有API请求信息失败'
  61. })
  62. }
  63. }
  64. async userCount(req, res, next){
  65. const date = req.params.date;
  66. if (!date) {
  67. console.log('参数错误')
  68. res.send({
  69. status: 0,
  70. type: 'ERROR_PARAMS',
  71. message: '参数错误'
  72. })
  73. return
  74. }
  75. try{
  76. const count = await UserInfoModel.find({registe_time: eval('/^' + date + '/gi')}).count()
  77. res.send({
  78. status: 1,
  79. count,
  80. })
  81. }catch(err){
  82. console.log('获取当天注册人数失败');
  83. res.send({
  84. status: 0,
  85. type: 'ERROR_GET_USER_REGISTE_COUNT',
  86. message: '获取当天注册人数失败'
  87. })
  88. }
  89. }
  90. async orderCount(req, res, next){
  91. const date = req.params.date;
  92. if (!date) {
  93. console.log('参数错误')
  94. res.send({
  95. status: 0,
  96. type: 'ERROR_PARAMS',
  97. message: '参数错误'
  98. })
  99. return
  100. }
  101. try{
  102. const count = await OrderModel.find({formatted_created_at: eval('/^' + date + '/gi')}).count()
  103. res.send({
  104. status: 1,
  105. count,
  106. })
  107. }catch(err){
  108. console.log('获取当天订单数量失败');
  109. res.send({
  110. status: 0,
  111. type: 'ERROR_GET_ORDER_COUNT',
  112. message: '获取当天订单数量失败'
  113. })
  114. }
  115. }
  116. }
  117. export default new Statis()