Showing
8 changed files
with
143 additions
and
13 deletions
@@ -9,7 +9,7 @@ const guochaoController = { | @@ -9,7 +9,7 @@ const guochaoController = { | ||
9 | 9 | ||
10 | list: async function(req, res) { | 10 | list: async function(req, res) { |
11 | 11 | ||
12 | - let list = await req.ctx(guoChaoModel).list(); | 12 | + let list = await req.ctx(guoChaoModel).list(req.body); |
13 | 13 | ||
14 | return res.json(list); | 14 | return res.json(list); |
15 | 15 |
@@ -6,12 +6,20 @@ class GuochaoModel extends global.yoho.BaseModel { | @@ -6,12 +6,20 @@ class GuochaoModel extends global.yoho.BaseModel { | ||
6 | super(ctx); | 6 | super(ctx); |
7 | } | 7 | } |
8 | 8 | ||
9 | - list() { | ||
10 | - return actGuochaoShop.findAll({order: [['sort', 'desc']]}); | 9 | + list(obj) { |
10 | + | ||
11 | + if (!obj.order.length) { | ||
12 | + obj.order = ['sort', 'desc']; | ||
13 | + } | ||
14 | + | ||
15 | + return actGuochaoShop.findAll({where: obj.where, order: [obj.order]}); | ||
11 | } | 16 | } |
12 | 17 | ||
13 | update(obj) { | 18 | update(obj) { |
14 | - return actGuochaoShop.update({ url: obj.url, sort: obj.sort, place: obj.place }, {where: {id: obj.id}}); | 19 | + let where = {id: obj.id}; |
20 | + | ||
21 | + delete obj.id; | ||
22 | + return actGuochaoShop.update(obj, {where: where}); | ||
15 | } | 23 | } |
16 | 24 | ||
17 | findById(id) { | 25 | findById(id) { |
@@ -55,7 +55,7 @@ router.post('/api/login', admin.login); | @@ -55,7 +55,7 @@ router.post('/api/login', admin.login); | ||
55 | router.post('/api/logout', admin.logout); | 55 | router.post('/api/logout', admin.logout); |
56 | 56 | ||
57 | // 国潮排行[page] | 57 | // 国潮排行[page] |
58 | -router.get('/api/guochao/list', guochao.list); | 58 | +router.post('/api/guochao/list', guochao.list); |
59 | router.post('/api/guochao/update', guochao.update); | 59 | router.post('/api/guochao/update', guochao.update); |
60 | 60 | ||
61 | // 活动管理[ajax] | 61 | // 活动管理[ajax] |
@@ -5,7 +5,17 @@ | @@ -5,7 +5,17 @@ | ||
5 | <div class="col-md-12 col-sm-12 col-xs-12"> | 5 | <div class="col-md-12 col-sm-12 col-xs-12"> |
6 | <div class="x_panel"> | 6 | <div class="x_panel"> |
7 | <div class="x_title"> | 7 | <div class="x_title"> |
8 | - </div> | 8 | + <a class="btn btn-primary btn_up_query">查询上半部</a> |
9 | + <a class="btn btn-primary btn_down_query">查询下半部</a> | ||
10 | + <a class="btn btn-primary btn_collect_desc">收藏数倒叙查询</a> | ||
11 | + <div class="col-md-3"> | ||
12 | + | ||
13 | + <div class="input-group"> | ||
14 | + <input type="text" class="form-control shop_name" placeholder="输入品牌名"> | ||
15 | + <span class="input-group-btn"> | ||
16 | + <button class="btn btn-default btn_name_query" type="button">品牌名查询</button> | ||
17 | + </span> | ||
18 | + </div></div></div> | ||
9 | <div class="x_content"> | 19 | <div class="x_content"> |
10 | <div class="table-responsive"> | 20 | <div class="table-responsive"> |
11 | <table class="table table-bordered"> | 21 | <table class="table table-bordered"> |
@@ -30,6 +30,25 @@ const guochaoController = { | @@ -30,6 +30,25 @@ const guochaoController = { | ||
30 | } | 30 | } |
31 | 31 | ||
32 | }, | 32 | }, |
33 | + checkFav: async function(req, res, next) { | ||
34 | + let param = req.body; | ||
35 | + let sessionKey = param.sessionKey; | ||
36 | + let uid = { | ||
37 | + toString: () => { | ||
38 | + return _.parseInt(req.body.uid); | ||
39 | + }, | ||
40 | + sessionKey, | ||
41 | + }; | ||
42 | + let ids = [1292, 282, 3082, 3372, 3548, 25, 3350, 1898, 1330, 1306, 1482, 992, 1474, 1472, 97, 1298, 1248, 3520, 2642, 964, 990, 1262, 1494, 292, 3146, 369, 720, 1282, 2312, 1878, 3210, 3576, 468, 3196, 1938, 3012]; | ||
43 | + | ||
44 | + try { | ||
45 | + let result = await req.ctx(GuochaoModel).checkFavs(uid, ids, 'shop'); | ||
46 | + | ||
47 | + res.json(result); | ||
48 | + } catch (e) { | ||
49 | + next; | ||
50 | + } | ||
51 | + }, | ||
33 | list: async function(req, res, next) { | 52 | list: async function(req, res, next) { |
34 | try { | 53 | try { |
35 | let result = await req.ctx(GuochaoModel).list(); | 54 | let result = await req.ctx(GuochaoModel).list(); |
1 | /* eslint-disable array-callback-return */ | 1 | /* eslint-disable array-callback-return */ |
2 | -const { actGuochaoShop } = require('../../../db'); | 2 | +const {actGuochaoShop} = require('../../../db'); |
3 | 3 | ||
4 | class Guochao extends global.yoho.BaseModel { | 4 | class Guochao extends global.yoho.BaseModel { |
5 | constructor(ctx) { | 5 | constructor(ctx) { |
6 | super(ctx); | 6 | super(ctx); |
7 | } | 7 | } |
8 | 8 | ||
9 | + async checkFavs(uid, ids, type) { | ||
10 | + console.log({uid, ids, type}); | ||
11 | + try { | ||
12 | + let result = await this.get({ | ||
13 | + method: 'app.favorite.batchCheckIsFavorite', | ||
14 | + favIds: ids, | ||
15 | + uid: uid, | ||
16 | + type: type | ||
17 | + }); | ||
18 | + | ||
19 | + return Promise.resolve({code: 200, result: true, data: result}); | ||
20 | + | ||
21 | + } catch (e) { | ||
22 | + console.log(e.toString()); | ||
23 | + return Promise.resolve({code: 202, result: false, errorMsg: e}); | ||
24 | + } | ||
25 | + | ||
26 | + } | ||
27 | + | ||
9 | async addFavAsync(uid, id, type) { | 28 | async addFavAsync(uid, id, type) { |
10 | - console.log({uid, id, type}); | ||
11 | try { | 29 | try { |
12 | - await this.get({ data: { | ||
13 | - method: 'app.favorite.add', | 30 | + |
31 | + let checkFlag = await this.get({ data: { | ||
32 | + method: 'app.favorite.isFavorite', | ||
14 | id: id, | 33 | id: id, |
15 | uid: uid, | 34 | uid: uid, |
16 | type: type | 35 | type: type |
17 | }}); | 36 | }}); |
18 | 37 | ||
38 | + if (checkFlag.data) { | ||
39 | + return Promise.resolve({code: 203, result: true, data: '已经收藏过'}); | ||
40 | + } | ||
41 | + | ||
42 | + await this.get({ | ||
43 | + data: { | ||
44 | + method: 'app.favorite.add', | ||
45 | + id: id, | ||
46 | + uid: uid, | ||
47 | + type: type | ||
48 | + } | ||
49 | + }); | ||
50 | + | ||
19 | let item = await actGuochaoShop.findOne({where: {shop_id: id}}); | 51 | let item = await actGuochaoShop.findOne({where: {shop_id: id}}); |
20 | let result = await item.increment('collect_count'); | 52 | let result = await item.increment('collect_count'); |
21 | 53 | ||
22 | return Promise.resolve({code: 200, result: true, data: result}); | 54 | return Promise.resolve({code: 200, result: true, data: result}); |
23 | } catch (e) { | 55 | } catch (e) { |
24 | - console.log(e.toString()); | ||
25 | return Promise.resolve({code: 202, result: false, errorMsg: e}); | 56 | return Promise.resolve({code: 202, result: false, errorMsg: e}); |
26 | } | 57 | } |
27 | } | 58 | } |
@@ -55,6 +55,7 @@ router.get('/coupon/couponUserOwner', coupon.couponUserOwner); | @@ -55,6 +55,7 @@ router.get('/coupon/couponUserOwner', coupon.couponUserOwner); | ||
55 | // guochao | 55 | // guochao |
56 | router.post('/guochao/addFav', guochao.addFav); | 56 | router.post('/guochao/addFav', guochao.addFav); |
57 | router.get('/guochao/list', guochao.list); | 57 | router.get('/guochao/list', guochao.list); |
58 | +router.post('/guochao/checkFav', guochao.checkFav); | ||
58 | 59 | ||
59 | // 图片处理git | 60 | // 图片处理git |
60 | router.get('/shoes/getBase64ImageData', shoes.getImageData); | 61 | router.get('/shoes/getBase64ImageData', shoes.getImageData); |
@@ -3,12 +3,16 @@ require('admin/user.page.css'); | @@ -3,12 +3,16 @@ require('admin/user.page.css'); | ||
3 | require('bootpag/lib/jquery.bootpag.min'); | 3 | require('bootpag/lib/jquery.bootpag.min'); |
4 | 4 | ||
5 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
6 | +let obj = {where: {}, order: []}; | ||
6 | 7 | ||
7 | function bind_table_pagination() { | 8 | function bind_table_pagination() { |
8 | const $ul = $('.guochao-list'); | 9 | const $ul = $('.guochao-list'); |
9 | const fetchRender = () => { | 10 | const fetchRender = () => { |
10 | $.ajax({ | 11 | $.ajax({ |
11 | url: '/admin/api/guochao/list', | 12 | url: '/admin/api/guochao/list', |
13 | + method: 'post', | ||
14 | + contentType: 'application/json', | ||
15 | + data: JSON.stringify(obj) | ||
12 | }).then(result => { | 16 | }).then(result => { |
13 | const list = result; | 17 | const list = result; |
14 | 18 | ||
@@ -20,24 +24,81 @@ function bind_table_pagination() { | @@ -20,24 +24,81 @@ function bind_table_pagination() { | ||
20 | } else { | 24 | } else { |
21 | item.placeText = '上'; | 25 | item.placeText = '上'; |
22 | } | 26 | } |
27 | + let str = item.place ? `<a class="btn btn-info btn-update btn-place-up" data-id="${item.id}">更变到上方</a>` : `<a class="btn btn-info btn-success btn-place-down" data-id="${item.id}">更变到下方</a>`; | ||
23 | 28 | ||
24 | html += ` | 29 | html += ` |
25 | <tr class="even pointer"> | 30 | <tr class="even pointer"> |
26 | <td class="">${item.id}</td> | 31 | <td class="">${item.id}</td> |
27 | <td class=""><img src="${item.logo}" style="background: #000000" width="100" height="50"/></td> | 32 | <td class=""><img src="${item.logo}" style="background: #000000" width="100" height="50"/></td> |
28 | <td class="">${item.shop_name}</td> | 33 | <td class="">${item.shop_name}</td> |
29 | - <td class="">${item.sort}</td> | 34 | + <td class=""><input class="sort" data-id="${item.id}" value="${item.sort}"/></td> |
30 | <td class="">${item.placeText}</td> | 35 | <td class="">${item.placeText}</td> |
31 | <td class="">${item.collect_count}</td> | 36 | <td class="">${item.collect_count}</td> |
32 | <td class=""> | 37 | <td class=""> |
33 | - <a class="btn btn-info btn-update" href="/admin/guochao/update?id=${item.id}">修改</a> | 38 | + ${str} |
34 | </td> | 39 | </td> |
35 | </tr>`; | 40 | </tr>`; |
36 | }); | 41 | }); |
37 | $ul.html(html); | 42 | $ul.html(html); |
43 | + | ||
44 | + $('.sort').blur(function() { | ||
45 | + let num = parseInt($(this).val()); | ||
46 | + | ||
47 | + if (typeof num != 'number') { | ||
48 | + return alert('请输入数字'); | ||
49 | + } | ||
50 | + $.ajax({ | ||
51 | + method: 'post', | ||
52 | + url: '/admin/api/guochao/update', | ||
53 | + contentType: 'application/json', | ||
54 | + data: JSON.stringify({id: $(this).attr('data-id'), sort: $(this).val()}) | ||
55 | + }).then(() => { | ||
56 | + fetchRender(); | ||
57 | + }); | ||
58 | + }); | ||
59 | + $('.btn-place-up').click(function() { | ||
60 | + $.ajax({ | ||
61 | + method: 'post', | ||
62 | + contentType: 'application/json', | ||
63 | + url: '/admin/api/guochao/update', | ||
64 | + data: JSON.stringify({id: $(this).attr('data-id'), place: 0}) | ||
65 | + }).then(() => { | ||
66 | + fetchRender(); | ||
67 | + }); | ||
68 | + }); | ||
69 | + $('.btn-place-down').click(function() { | ||
70 | + $.ajax({ | ||
71 | + method: 'post', | ||
72 | + url: '/admin/api/guochao/update', | ||
73 | + contentType: 'application/json', | ||
74 | + data: JSON.stringify({id: $(this).attr('data-id'), place: 1}) | ||
75 | + }).then(() => { | ||
76 | + fetchRender(); | ||
77 | + }); | ||
78 | + }); | ||
38 | }); | 79 | }); |
39 | }; | 80 | }; |
40 | 81 | ||
82 | + $('.btn_collect_desc').click(function() { | ||
83 | + obj.order = ['collect_count', 'desc']; | ||
84 | + fetchRender(); | ||
85 | + obj = {where: {}, order: []}; | ||
86 | + }); | ||
87 | + $('.btn_up_query').click(function() { | ||
88 | + obj.where = {place: 0}; | ||
89 | + fetchRender(); | ||
90 | + obj = {where: {}, order: []}; | ||
91 | + }); | ||
92 | + $('.btn_down_query').click(function() { | ||
93 | + obj.where = {place: 1}; | ||
94 | + fetchRender(); | ||
95 | + obj = {where: {}, order: []}; | ||
96 | + }); | ||
97 | + $('.btn_name_query').click(function() { | ||
98 | + obj.where = {shop_name: $('.shop_name').val()}; | ||
99 | + fetchRender(); | ||
100 | + obj = {where: {}, order: []}; | ||
101 | + }); | ||
41 | fetchRender(); | 102 | fetchRender(); |
42 | 103 | ||
43 | } | 104 | } |
-
Please register or login to post a comment