statis.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. import AdminModel from '../../models/admin/admin'
  7. class Statis {
  8. constructor(){
  9. }
  10. async apiCount(req, res, next){
  11. const date = req.params.date;
  12. if (!date) {
  13. console.log('参数错误')
  14. res.send({
  15. status: 0,
  16. type: 'ERROR_PARAMS',
  17. message: '参数错误'
  18. })
  19. return
  20. }
  21. try{
  22. const count = await StatisModel.find({date}).count()
  23. res.send({
  24. status: 1,
  25. count,
  26. })
  27. }catch(err){
  28. console.log('获取当天API请求次数失败');
  29. res.send({
  30. status: 0,
  31. type: 'ERROR_GET_TODAY_API_COUNT',
  32. message: '获取当天API请求次数失败'
  33. })
  34. }
  35. }
  36. async apiAllCount(req, res, next){
  37. try{
  38. const count = await StatisModel.count()
  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 adminCount(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 AdminModel.find({registe_time: 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_ADMIN_REGISTE_COUNT',
  113. message: '获取当天注册管理员人数失败'
  114. })
  115. }
  116. }
  117. async orderCount(req, res, next){
  118. const date = req.params.date;
  119. if (!date) {
  120. console.log('参数错误')
  121. res.send({
  122. status: 0,
  123. type: 'ERROR_PARAMS',
  124. message: '参数错误'
  125. })
  126. return
  127. }
  128. try{
  129. const count = await OrderModel.find({formatted_created_at: eval('/^' + date + '/gi')}).count()
  130. res.send({
  131. status: 1,
  132. count,
  133. })
  134. }catch(err){
  135. console.log('获取当天订单数量失败');
  136. res.send({
  137. status: 0,
  138. type: 'ERROR_GET_ORDER_COUNT',
  139. message: '获取当天订单数量失败'
  140. })
  141. }
  142. }
  143. }
  144. export default new Statis()