Authored by 陈峰

Merge branch 'release/6.9.5' into 'master'

增加分享接口



See merge request !101
const shareModel = require('../models/share');
const shareController = {
collect(req, res, next) {
const {uid, fid} = req.query;
if (!uid || !fid) {
return res.status(200).end();
}
req.ctx(shareModel).collect({uid, fid});
return res.status(200).end();
},
async preshare(req, res, next) {
const {fid, eventName, shareUrl} = req.query;
if (!eventName || !shareUrl) {
return res.status(200).end();
}
try {
const id = await req.ctx(shareModel).preshare({fid, eventName, shareUrl, ip: req.yoho.clientIp});
return res.jsonp({
preid: id
});
} catch (error) {
return next(error);
}
}
};
module.exports = shareController;
... ...
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;
... ...
... ... @@ -21,6 +21,7 @@ const common = require('./controllers/common');
const mutilpartMiddleware = multipart();
const yohoActivitys = require('./controllers/yoho-activitys');
const dailyCheckIn = require('./controllers/daily-check-in');
const share = require('./controllers/share');
router.get('/gettoken', qiniu.getToken);
router.get('/share/getSignPackage', wechat.getSignPackage);
... ... @@ -105,4 +106,6 @@ router.post('/activity/checkIn/saveUserInfo', dailyCheckIn.saveUserInfo); // 保
router.get('/activity/checkIn/getWinnerList', dailyCheckIn.getWinnerList); // 获取实物奖品中奖用户
router.get('/activity/checkIn/getUserInfo', dailyCheckIn.getUserInfo); // 获取用户信息
router.get('/share/collect', share.collect); // 分享
router.get('/share/preshare', share.preshare); // 分享
module.exports = router;
... ...
CREATE TABLE IF NOT EXISTS user_share_log (
`id` INT(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`event_name` VARCHAR(100) NOT NULL,
`uid` VARCHAR(50) NOT NULL,
`from_id` VARCHAR(50) NOT NULL DEFAULT '',
`share_url` VARCHAR(500) NOT NULL DEFAULT '',
`level` INT(8) NOT NULL DEFAULT 0,
`tick` INT(8) NOT NULL DEFAULT 0,
`share_time` INT(10) NOT NULL ,
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8mb4;
ALTER TABLE user_share_log ADD INDEX INDEX_EVENT_NAME (`event_name`);
ALTER TABLE user_share_log ADD INDEX INDEX_UID (`uid`);
ALTER TABLE user_share_log ADD INDEX INDEX_FROM_ID (`from_id`);
ALTER TABLE user_share_log ADD INDEX INDEX_SHARE_URL (`share_url`);
\ No newline at end of file
... ...