share.js
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const _ = require('lodash');
const moment = require('moment');
const logger = global.yoho.logger;
const mysqlCli = global.yoho.utils.mysqlCli;
class ShareModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
async collect({uid, fid}) {
return mysqlCli.update('UPDATE `user_share_log` SET `uid` = :uid, `tick` = `tick` + 1 WHERE `id` = :fid', {
uid,
fid,
});
}
async preshare({fid, eventName, shareUrl, ip}) {
let level = -1;
if (fid) {
const find = await mysqlCli.query('SELECT * FROM `user_share_log` WHERE `id` = :fid', {
fid
});
if (find && find[0]) {
level = find[0].level;
}
}
return mysqlCli.insert('INSERT INTO `user_share_log` (`event_name`, `uid`, `from_id`, `share_url`, `level`, `share_time`, `ip`) VALUES (:eventName, :uid, :fromId, :shareUrl, :level, :shareTime, :ip)', {
eventName,
uid: 0,
fromId: fid || 0,
shareUrl,
level: level + 1,
shareTime: parseInt(new Date().getTime() / 1000, 10),
ip
});
}
}
module.exports = ShareModel;