|
|
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; |
...
|
...
|
|