setting.js 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @class Version 应用版本模型
  3. */
  4. const BaseMod = require('./base')
  5. const {
  6. DateTime
  7. } = require('../lib')
  8. module.exports = class Setting extends BaseMod {
  9. constructor() {
  10. super()
  11. this.tableName = 'opendb-tempdata'
  12. this.tablePrefix = false
  13. this.settingKey = "uni-stat-setting"
  14. }
  15. /**
  16. * 获取统计云端配置
  17. */
  18. async getSetting() {
  19. const res = await this.getCollection(this.tableName).doc(this.settingKey).get();
  20. if (res.data && res.data[0] && res.data[0].value) {
  21. return res.data[0].value;
  22. } else {
  23. return {
  24. mode: "open",
  25. day: 7
  26. };
  27. }
  28. }
  29. /**
  30. * 检测N天内是否有设备访问记录,如果有,则返回true,否则返回false
  31. */
  32. async checkAutoRun(obj = {}) {
  33. let {
  34. day = 7
  35. } = obj;
  36. const _ = this.dbCmd;
  37. let nowTime = Date.now();
  38. const res = await this.getCollection("uni-stat-session-logs").where({
  39. create_time: _.gte(nowTime - 1000 * 3600 * 24 * day)
  40. }).count();
  41. return res.total > 0 ? true : false;
  42. }
  43. }