You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
canteen/uniCloud-aliyun/cloudfunctions/common/uni-stat/stat/mod/setting.js

45 lines
997 B

/**
* @class Version 应用版本模型
*/
const BaseMod = require('./base')
const {
DateTime
} = require('../lib')
module.exports = class Setting extends BaseMod {
constructor() {
super()
this.tableName = 'opendb-tempdata'
this.tablePrefix = false
this.settingKey = "uni-stat-setting"
}
/**
* 获取统计云端配置
*/
async getSetting() {
const res = await this.getCollection(this.tableName).doc(this.settingKey).get();
if (res.data && res.data[0] && res.data[0].value) {
return res.data[0].value;
} else {
return {
mode: "open",
day: 7
};
}
}
/**
* 检测N天内是否有设备访问记录如果有则返回true否则返回false
*/
async checkAutoRun(obj = {}) {
let {
day = 7
} = obj;
const _ = this.dbCmd;
let nowTime = Date.now();
const res = await this.getCollection("uni-stat-session-logs").where({
create_time: _.gte(nowTime - 1000 * 3600 * 24 * day)
}).count();
return res.total > 0 ? true : false;
}
}