Initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
const dbName = {
|
||||
uniIdUsers: 'uni-id-users', // 支付订单明细表
|
||||
uniPayOrders: 'uni-pay-orders', // 支付订单明细表
|
||||
uniStatPayResult: 'uni-stat-pay-result', // 统计结果存储表
|
||||
uniStatSessionLogs: 'uni-stat-session-logs', // 设备会话日志表(主要用于统计访问设备数)
|
||||
uniStatUserSessionLogs: 'uni-stat-user-session-logs', // 用户会话日志表(主要用于统计访问人数)
|
||||
};
|
||||
|
||||
module.exports = dbName;
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
module.exports = {
|
||||
uniIdUsers: require('./uniIdUsers'),
|
||||
uniPayOrders: require('./uniPayOrders'),
|
||||
uniStatPayResult: require('./uniStatPayResult'),
|
||||
uniStatSessionLogs: require('./uniStatSessionLogs'),
|
||||
uniStatUserSessionLogs: require('./uniStatUserSessionLogs'),
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
const dbName = require("./config");
|
||||
|
||||
let db = uniCloud.database();
|
||||
let _ = db.command;
|
||||
let $ = _.aggregate;
|
||||
|
||||
class Dao {
|
||||
async count(whereJson) {
|
||||
let dbRes = await db.collection(dbName.uniIdUsers).where(whereJson).count()
|
||||
return dbRes && dbRes.total ? dbRes.total : 0;
|
||||
}
|
||||
|
||||
async countNewUserOrder(obj) {
|
||||
let {
|
||||
whereJson,
|
||||
status
|
||||
} = obj;
|
||||
let dbRes = await db.collection(dbName.uniIdUsers).aggregate()
|
||||
.match(whereJson)
|
||||
.lookup({
|
||||
from: dbName.uniPayOrders,
|
||||
let: {
|
||||
user_id: '$_id',
|
||||
},
|
||||
pipeline: $.pipeline()
|
||||
.match(_.expr($.and([
|
||||
$.eq(['$user_id', '$$user_id']),
|
||||
$.in(['$status', status])
|
||||
])))
|
||||
.limit(1)
|
||||
.done(),
|
||||
as: 'order',
|
||||
})
|
||||
.unwind({
|
||||
path: '$order',
|
||||
})
|
||||
.group({
|
||||
_id: null,
|
||||
count: {
|
||||
$addToSet: '$_id'
|
||||
},
|
||||
})
|
||||
.addFields({
|
||||
count: {
|
||||
$size: '$count'
|
||||
}
|
||||
})
|
||||
.end()
|
||||
try {
|
||||
return dbRes.data[0].count;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = new Dao();
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
const BaseMod = require('../../base');
|
||||
const dbName = require("./config");
|
||||
|
||||
class Dao extends BaseMod {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.tablePrefix = false; // 不使用表前缀
|
||||
}
|
||||
|
||||
async group(data) {
|
||||
let {
|
||||
start_time,
|
||||
end_time,
|
||||
status: status_str
|
||||
} = data;
|
||||
let status;
|
||||
if (status_str === "已下单") {
|
||||
|
||||
} else if (status_str === "已付款") {
|
||||
status = {
|
||||
$gt: 0
|
||||
}
|
||||
} else if (status_str === "已退款") {
|
||||
status = {
|
||||
$in: [2, 3]
|
||||
}
|
||||
}
|
||||
const dbRes = await this.aggregate(dbName.uniPayOrders, {
|
||||
match: {
|
||||
create_date: {
|
||||
$gte: start_time,
|
||||
$lte: end_time
|
||||
},
|
||||
status
|
||||
},
|
||||
group: {
|
||||
_id: {
|
||||
appid: '$appid',
|
||||
version: '$stat_data.app_version',
|
||||
platform: '$stat_data.platform',
|
||||
channel: '$stat_data.channel',
|
||||
},
|
||||
status: {
|
||||
$first: '$status'
|
||||
},
|
||||
// 支付金额
|
||||
total_fee: {
|
||||
$sum: '$total_fee'
|
||||
},
|
||||
// 退款金额
|
||||
refund_fee: {
|
||||
$sum: '$refund_fee'
|
||||
},
|
||||
// 支付笔数
|
||||
order_count: {
|
||||
$sum: 1
|
||||
},
|
||||
// 支付人数(去重复)
|
||||
user_count: {
|
||||
$addToSet: '$user_id'
|
||||
},
|
||||
// 支付设备数(去重复)
|
||||
device_count: {
|
||||
$addToSet: '$device_id'
|
||||
},
|
||||
|
||||
create_date: {
|
||||
$min: '$create_date'
|
||||
}
|
||||
},
|
||||
addFields: {
|
||||
user_count: {
|
||||
$size: '$user_count'
|
||||
},
|
||||
device_count: {
|
||||
$size: '$device_count'
|
||||
}
|
||||
},
|
||||
// 按创建时间排序
|
||||
sort: {
|
||||
create_date: 1
|
||||
},
|
||||
getAll: true
|
||||
});
|
||||
|
||||
let list = dbRes.data;
|
||||
list.map((item) => {
|
||||
item.status_str = status_str;
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = new Dao();
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
const BaseMod = require('../../base');
|
||||
const dbName = require("./config");
|
||||
|
||||
class Dao extends BaseMod {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.tablePrefix = false; // 不使用表前缀
|
||||
}
|
||||
|
||||
async list(data) {
|
||||
let {
|
||||
whereJson,
|
||||
} = data;
|
||||
const dbRes = await this.getCollection(dbName.uniStatPayResult).where(whereJson).get();
|
||||
return dbRes.data;
|
||||
}
|
||||
|
||||
async del(data) {
|
||||
let {
|
||||
whereJson
|
||||
} = data;
|
||||
const dbRes = await this.delete(dbName.uniStatPayResult, whereJson);
|
||||
return dbRes.deleted;
|
||||
}
|
||||
|
||||
async adds(saveList) {
|
||||
return await this.batchInsert(dbName.uniStatPayResult, saveList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = new Dao();
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
const BaseMod = require('../../base');
|
||||
const dbName = require("./config");
|
||||
|
||||
class Dao extends BaseMod {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.tablePrefix = false; // 不使用表前缀
|
||||
}
|
||||
|
||||
async group(data) {
|
||||
let {
|
||||
whereJson,
|
||||
} = data;
|
||||
const dbRes = await this.aggregate(dbName.uniStatSessionLogs, {
|
||||
match: whereJson,
|
||||
group: {
|
||||
_id: {
|
||||
appid: '$appid',
|
||||
version: '$version',
|
||||
platform: '$platform',
|
||||
channel: '$channel',
|
||||
},
|
||||
// 设备数(去重复)
|
||||
device_count: {
|
||||
$addToSet: '$device_id'
|
||||
},
|
||||
|
||||
create_time: {
|
||||
$min: '$create_time'
|
||||
}
|
||||
},
|
||||
addFields: {
|
||||
device_count: {
|
||||
$size: '$device_count'
|
||||
}
|
||||
},
|
||||
// 按创建时间排序
|
||||
sort: {
|
||||
create_time: 1
|
||||
},
|
||||
getAll: true
|
||||
});
|
||||
|
||||
return dbRes.data;
|
||||
}
|
||||
|
||||
async groupCount(whereJson) {
|
||||
const dbRes = await this.aggregate(dbName.uniStatSessionLogs, {
|
||||
match: whereJson,
|
||||
group: {
|
||||
_id: null,
|
||||
// 设备数(去重复)
|
||||
count: {
|
||||
$addToSet: '$device_id'
|
||||
},
|
||||
},
|
||||
addFields: {
|
||||
count: {
|
||||
$size: '$count'
|
||||
}
|
||||
},
|
||||
getAll: true
|
||||
});
|
||||
try {
|
||||
return dbRes.data[0].count;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = new Dao();
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 数据库操作
|
||||
*/
|
||||
const BaseMod = require('../../base');
|
||||
const dbName = require("./config");
|
||||
|
||||
class Dao extends BaseMod {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.tablePrefix = false; // 不使用表前缀
|
||||
}
|
||||
|
||||
async group(data) {
|
||||
let {
|
||||
whereJson
|
||||
} = data;
|
||||
const dbRes = await this.aggregate(dbName.uniStatUserSessionLogs, {
|
||||
match: whereJson,
|
||||
group: {
|
||||
_id: {
|
||||
appid: '$appid',
|
||||
version: '$version',
|
||||
platform: '$platform',
|
||||
channel: '$channel',
|
||||
},
|
||||
// 用户数(去重复)
|
||||
user_count: {
|
||||
$addToSet: '$uid'
|
||||
},
|
||||
|
||||
create_time: {
|
||||
$min: '$create_time'
|
||||
}
|
||||
},
|
||||
addFields: {
|
||||
user_count: {
|
||||
$size: '$user_count'
|
||||
}
|
||||
},
|
||||
// 按创建时间排序
|
||||
sort: {
|
||||
create_time: 1
|
||||
},
|
||||
getAll: true
|
||||
});
|
||||
|
||||
let list = dbRes.data;
|
||||
return list;
|
||||
}
|
||||
|
||||
async groupCount(whereJson) {
|
||||
const dbRes = await this.aggregate(dbName.uniStatUserSessionLogs, {
|
||||
match: whereJson,
|
||||
group: {
|
||||
_id: null,
|
||||
// 设备数(去重复)
|
||||
count: {
|
||||
$addToSet: '$uid'
|
||||
},
|
||||
},
|
||||
addFields: {
|
||||
count: {
|
||||
$size: '$count'
|
||||
}
|
||||
},
|
||||
getAll: true
|
||||
});
|
||||
try {
|
||||
return dbRes.data[0].count;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = new Dao();
|
||||
Reference in New Issue
Block a user