Authored by yyq

handle list

... ... @@ -19,7 +19,7 @@ module.exports = {
.then(res.json).catch(next);
},
listMine(req, res, next) {
req.ctx(zerobuyModel).getListMine(req.query.uid)
req.ctx(zerobuyModel).getListMine(req.query.uid, req.query)
.then(res.json).catch(next);
},
listRecommend(req, res, next) {
... ...
... ... @@ -16,6 +16,8 @@ const PRODUCT_CACHE_TIMES = MINUTE_TIMES * 5; // 商品(列表&详情)缓存
const RECENT_CODE_CACHE_TIME = MINUTE_TIMES; // 最近获取记录缓存时间
const MAX_JOIN_TIMES = 5; // 最大活动参与次数
const PAGE_SIZE = 10;
const userTimesCache = new MemoryCache();
function handelResult(result) {
... ... @@ -50,6 +52,20 @@ function getActivityStatus(info = {}, num, now) {
return resStatus;
}
function handelActivityList(list, nums) {
let now = new Date().getTime() / 1000;
list = _.concat([], list);
nums = _.concat([], nums);
_.forEach(list, (value, index) => {
value.price = '¥' + value.price.toFixed(2);
value.status = getActivityStatus(value, nums[index], now);
});
return list;
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -63,12 +79,11 @@ module.exports = class extends global.yoho.BaseModel {
* @returns {*}
*/
getList(page, extra = {}) {
const pageSize = 10;
const actId = parseInt(extra.actId, 10) || 0;
page = parseInt(page, 10) || 1;
let limit = `${(page - 1) * pageSize},${page * pageSize}`;
let limit = `${(page - 1) * PAGE_SIZE},${PAGE_SIZE}`;
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
where act_id = :actId and status > 0
... ... @@ -76,7 +91,9 @@ module.exports = class extends global.yoho.BaseModel {
actId
}, {
cache: PRODUCT_CACHE_TIMES
}).then(handelResult);
}).then(result => {
return handelResult(handelActivityList(result));
});
}
/**
... ... @@ -87,17 +104,22 @@ module.exports = class extends global.yoho.BaseModel {
*/
getListMine(uid, extra = {}) {
const actId = parseInt(extra.actId, 10) || 0;
const page = parseInt(extra.page, 10) || 1;
let limit = `${(page - 1) * PAGE_SIZE},${PAGE_SIZE}`;
uid = parseInt(uid, 10) || 0;
return mysqlCli.query(`select u.*, p.name, p.price, p.status, p.cover_img from
${TABLE_ACT_PRIZE_PRODUCT_USER} u left join
${TABLE_ACT_PRIZE_PRODUCT} p on u.act_prize_id = p.id
where u.act_id = :actId and u.uid = :uid
order by u.create_time desc`, {
where u.act_id = :actId and u.uid = :uid and p.status ${extra.type ? '=' : '<'} 2
order by u.create_time desc limit ${limit}`, {
uid,
actId
}).then(handelResult);
}).then(result => {
return handelResult(handelActivityList(result));
});
}
/**
... ... @@ -118,7 +140,9 @@ module.exports = class extends global.yoho.BaseModel {
actPrizeId: actPrizeId - 3
}, {
cache: PRODUCT_CACHE_TIMES
}).then(handelResult);
}).then(result => {
return handelResult(handelActivityList(result));
});
}
/**
... ... @@ -166,6 +190,7 @@ module.exports = class extends global.yoho.BaseModel {
let joinNum = _.get(count, 'join_num', 0);
resData.price = '¥' + _.ceil(resData.price, 2);
resData.joinNum = joinNum;
resData.status = getActivityStatus(resData, joinNum);
resData.myCodeNum = _.get(result, '[3][0].code_num', 0);
... ... @@ -189,9 +214,7 @@ module.exports = class extends global.yoho.BaseModel {
actId
}, {
cache: RECENT_CODE_CACHE_TIME
}).then(result => {
return handelResult(result);
});
}).then(handelResult);
}
/**
... ...