statistic.js 699 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. import AddressComponent from '../prototype/addressComponent'
  3. import StatisModel from '../models/statis/statis'
  4. import dtime from 'time-formater'
  5. class Statistic extends AddressComponent {
  6. constructor(){
  7. super()
  8. this.apiRecord = this.apiRecord.bind(this)
  9. }
  10. async apiRecord(req, res, next){
  11. try{
  12. const address = await this.guessPosition(req);
  13. const statis_id = await this.getId('statis_id')
  14. const apiInfo = {
  15. date: dtime().format('YYYY-MM-DD'),
  16. origin: req.headers.origin,
  17. id: statis_id,
  18. address: address.city,
  19. }
  20. StatisModel.create(apiInfo)
  21. }catch(err){
  22. console.log('API记录出错', err);
  23. }
  24. next()
  25. }
  26. }
  27. export default new Statistic()