Authored by huangyi

领券

... ... @@ -9,7 +9,7 @@ const guochaoController = {
list: async function(req, res) {
let list = await req.ctx(guoChaoModel).list();
let list = await req.ctx(guoChaoModel).list(req.body);
return res.json(list);
... ...
... ... @@ -6,12 +6,20 @@ class GuochaoModel extends global.yoho.BaseModel {
super(ctx);
}
list() {
return actGuochaoShop.findAll({order: [['sort', 'desc']]});
list(obj) {
if (!obj.order.length) {
obj.order = ['sort', 'desc'];
}
return actGuochaoShop.findAll({where: obj.where, order: [obj.order]});
}
update(obj) {
return actGuochaoShop.update({ url: obj.url, sort: obj.sort, place: obj.place }, {where: {id: obj.id}});
let where = {id: obj.id};
delete obj.id;
return actGuochaoShop.update(obj, {where: where});
}
findById(id) {
... ...
... ... @@ -55,7 +55,7 @@ router.post('/api/login', admin.login);
router.post('/api/logout', admin.logout);
// 国潮排行[page]
router.get('/api/guochao/list', guochao.list);
router.post('/api/guochao/list', guochao.list);
router.post('/api/guochao/update', guochao.update);
// 活动管理[ajax]
... ...
... ... @@ -5,7 +5,17 @@
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
</div>
<a class="btn btn-primary btn_up_query">查询上半部</a>
<a class="btn btn-primary btn_down_query">查询下半部</a>
<a class="btn btn-primary btn_collect_desc">收藏数倒叙查询</a>
<div class="col-md-3">
<div class="input-group">
<input type="text" class="form-control shop_name" placeholder="输入品牌名">
<span class="input-group-btn">
<button class="btn btn-default btn_name_query" type="button">品牌名查询</button>
</span>
</div></div></div>
<div class="x_content">
<div class="table-responsive">
<table class="table table-bordered">
... ...
... ... @@ -30,6 +30,25 @@ const guochaoController = {
}
},
checkFav: async function(req, res, next) {
let param = req.body;
let sessionKey = param.sessionKey;
let uid = {
toString: () => {
return _.parseInt(req.body.uid);
},
sessionKey,
};
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];
try {
let result = await req.ctx(GuochaoModel).checkFavs(uid, ids, 'shop');
res.json(result);
} catch (e) {
next;
}
},
list: async function(req, res, next) {
try {
let result = await req.ctx(GuochaoModel).list();
... ...
/* eslint-disable array-callback-return */
const { actGuochaoShop } = require('../../../db');
const {actGuochaoShop} = require('../../../db');
class Guochao extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
async checkFavs(uid, ids, type) {
console.log({uid, ids, type});
try {
let result = await this.get({
method: 'app.favorite.batchCheckIsFavorite',
favIds: ids,
uid: uid,
type: type
});
return Promise.resolve({code: 200, result: true, data: result});
} catch (e) {
console.log(e.toString());
return Promise.resolve({code: 202, result: false, errorMsg: e});
}
}
async addFavAsync(uid, id, type) {
console.log({uid, id, type});
try {
await this.get({ data: {
method: 'app.favorite.add',
let checkFlag = await this.get({ data: {
method: 'app.favorite.isFavorite',
id: id,
uid: uid,
type: type
}});
if (checkFlag.data) {
return Promise.resolve({code: 203, result: true, data: '已经收藏过'});
}
await this.get({
data: {
method: 'app.favorite.add',
id: id,
uid: uid,
type: type
}
});
let item = await actGuochaoShop.findOne({where: {shop_id: id}});
let result = await item.increment('collect_count');
return Promise.resolve({code: 200, result: true, data: result});
} catch (e) {
console.log(e.toString());
return Promise.resolve({code: 202, result: false, errorMsg: e});
}
}
... ...
... ... @@ -55,6 +55,7 @@ router.get('/coupon/couponUserOwner', coupon.couponUserOwner);
// guochao
router.post('/guochao/addFav', guochao.addFav);
router.get('/guochao/list', guochao.list);
router.post('/guochao/checkFav', guochao.checkFav);
// 图片处理git
router.get('/shoes/getBase64ImageData', shoes.getImageData);
... ...
... ... @@ -3,12 +3,16 @@ require('admin/user.page.css');
require('bootpag/lib/jquery.bootpag.min');
const _ = require('lodash');
let obj = {where: {}, order: []};
function bind_table_pagination() {
const $ul = $('.guochao-list');
const fetchRender = () => {
$.ajax({
url: '/admin/api/guochao/list',
method: 'post',
contentType: 'application/json',
data: JSON.stringify(obj)
}).then(result => {
const list = result;
... ... @@ -20,24 +24,81 @@ function bind_table_pagination() {
} else {
item.placeText = '上';
}
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>`;
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class=""><img src="${item.logo}" style="background: #000000" width="100" height="50"/></td>
<td class="">${item.shop_name}</td>
<td class="">${item.sort}</td>
<td class=""><input class="sort" data-id="${item.id}" value="${item.sort}"/></td>
<td class="">${item.placeText}</td>
<td class="">${item.collect_count}</td>
<td class="">
<a class="btn btn-info btn-update" href="/admin/guochao/update?id=${item.id}">修改</a>
${str}
</td>
</tr>`;
});
$ul.html(html);
$('.sort').blur(function() {
let num = parseInt($(this).val());
if (typeof num != 'number') {
return alert('请输入数字');
}
$.ajax({
method: 'post',
url: '/admin/api/guochao/update',
contentType: 'application/json',
data: JSON.stringify({id: $(this).attr('data-id'), sort: $(this).val()})
}).then(() => {
fetchRender();
});
});
$('.btn-place-up').click(function() {
$.ajax({
method: 'post',
contentType: 'application/json',
url: '/admin/api/guochao/update',
data: JSON.stringify({id: $(this).attr('data-id'), place: 0})
}).then(() => {
fetchRender();
});
});
$('.btn-place-down').click(function() {
$.ajax({
method: 'post',
url: '/admin/api/guochao/update',
contentType: 'application/json',
data: JSON.stringify({id: $(this).attr('data-id'), place: 1})
}).then(() => {
fetchRender();
});
});
});
};
$('.btn_collect_desc').click(function() {
obj.order = ['collect_count', 'desc'];
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_up_query').click(function() {
obj.where = {place: 0};
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_down_query').click(function() {
obj.where = {place: 1};
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_name_query').click(function() {
obj.where = {shop_name: $('.shop_name').val()};
fetchRender();
obj = {where: {}, order: []};
});
fetchRender();
}
... ...