NGTools/uniCloud-aliyun/cloudfunctions/common/uni-stat/stat/mod/setting.js
ldeyun d572f28fad V1.0.0
微信小程序运行成功;
H5运行成功
2024-09-30 01:26:58 +08:00

45 lines
997 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @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;
}
}