Authored by ccbikai

增加收藏文章功能

@@ -6,9 +6,11 @@ @@ -6,9 +6,11 @@
6 'use strict'; 6 'use strict';
7 7
8 const mRoot = '../models'; 8 const mRoot = '../models';
  9 +const library = '../../../library';
9 const _ = require('lodash'); 10 const _ = require('lodash');
10 const headerModel = require('../../../doraemon/models/header'); 11 const headerModel = require('../../../doraemon/models/header');
11 const starModel = require(`${mRoot}/star`); 12 const starModel = require(`${mRoot}/star`);
  13 +const helpers = require(`${library}/helpers`);
12 14
13 const headTab = [ 15 const headTab = [
14 { 16 {
@@ -110,7 +112,7 @@ exports.collocation = (req, res) => { @@ -110,7 +112,7 @@ exports.collocation = (req, res) => {
110 */ 112 */
111 exports.collocationList = (req, res) => { 113 exports.collocationList = (req, res) => {
112 let params = req.query; 114 let params = req.query;
113 - let uid = 9239279 || req.user.uid || 0; 115 + let uid = req.user.uid || 0;
114 116
115 starModel.getCollocationListData(params, uid).then((result) => { 117 starModel.getCollocationListData(params, uid).then((result) => {
116 res.render('star/list', _.assign({ 118 res.render('star/list', _.assign({
@@ -123,6 +125,26 @@ exports.collocationList = (req, res) => { @@ -123,6 +125,26 @@ exports.collocationList = (req, res) => {
123 }; 125 };
124 126
125 /** 127 /**
  128 + * 收藏文章
  129 + * @param {[type]} req [description]
  130 + * @param {[type]} res [description]
  131 + * @return {[type]}
  132 + */
  133 +exports.setFavorite = (req, res) => {
  134 + let params = req.body;
  135 + let uid = req.user.uid || 0;
  136 +
  137 + starModel.setFavorite(params, uid).then((result) => {
  138 + if (result.code === 401) {
  139 + result.data = helpers.urlFormat('/signin.html', {
  140 + refer: req.get('Referer') || '/guang/star/collocation'
  141 + });
  142 + }
  143 + res.json(result);
  144 + });
  145 +};
  146 +
  147 +/**
126 * 明星文章专区 148 * 明星文章专区
127 * @param {[object]} req 149 * @param {[object]} req
128 * @param {[object]} res 150 * @param {[object]} res
@@ -190,3 +190,19 @@ exports.getCollocationListData = (params, uid) => { @@ -190,3 +190,19 @@ exports.getCollocationListData = (params, uid) => {
190 } 190 }
191 }); 191 });
192 }; 192 };
  193 +
  194 +exports.setFavorite = (params, uid) => {
  195 + if (!uid) {
  196 + return Promise.resolve({
  197 + code: 401,
  198 + message: '未登录'
  199 + });
  200 + }
  201 +
  202 + return api.get('', sign.apiSign({
  203 + method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
  204 + client_type: 'h5',
  205 + article_id: params.articleId,
  206 + uid: uid
  207 + }));
  208 +};
@@ -19,4 +19,6 @@ router.get('/star/special', star.special); // 星潮教室星专题 @@ -19,4 +19,6 @@ router.get('/star/special', star.special); // 星潮教室星专题
19 router.get('/star/collocation', star.collocation); // 星潮教室星搭配 19 router.get('/star/collocation', star.collocation); // 星潮教室星搭配
20 router.get('/star/collocation/list', star.collocationList); // 星潮教室星搭配文章请求 20 router.get('/star/collocation/list', star.collocationList); // 星潮教室星搭配文章请求
21 21
  22 +router.post('/star/setFavorite', star.setFavorite); // 收藏文章
  23 +
22 module.exports = router; 24 module.exports = router;
@@ -25,7 +25,7 @@ $(document).on('click', '.collection', function() { @@ -25,7 +25,7 @@ $(document).on('click', '.collection', function() {
25 25
26 $.ajax({ 26 $.ajax({
27 type: 'POST', 27 type: 'POST',
28 - url: '/guang/starclass/setFavorite', 28 + url: '/guang/star/setFavorite',
29 data: { 29 data: {
30 articleId: $that.parents('li').attr('articleId'), 30 articleId: $that.parents('li').attr('articleId'),
31 type: type 31 type: type
@@ -42,7 +42,7 @@ $(document).on('click', '.collection', function() { @@ -42,7 +42,7 @@ $(document).on('click', '.collection', function() {
42 42
43 } 43 }
44 44
45 - if (code === 201) { 45 + if (code === 401) {
46 if ($('#collocation-link').length <= 0) { 46 if ($('#collocation-link').length <= 0) {
47 $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' + 47 $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
48 '<span class="collocation-link"></span></a>'); 48 '<span class="collocation-link"></span></a>');