|
|
/**
|
|
|
* 0元抽奖活动
|
|
|
* @author: yyq <yanqing.yang@yoho.cn>
|
|
|
* @date: 19/07/2018
|
|
|
*/
|
|
|
const _ = require('lodash');
|
|
|
const mysqlCli = global.yoho.utils.mysqlCli;
|
|
|
|
|
|
const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product';
|
|
|
const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content';
|
|
|
const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user';
|
|
|
|
|
|
function handelResult(result) {
|
|
|
return {
|
|
|
code: 200,
|
|
|
data: result
|
|
|
};
|
|
|
}
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0元购活动列表
|
|
|
* @param status
|
|
|
* @param actId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
getList(status, actId) {
|
|
|
status = parseInt(status, 10);
|
|
|
actId = parseInt(actId, 10) || 0;
|
|
|
|
|
|
status = _.isNaN(status) ? '> 0' : `= ${status}`;
|
|
|
|
|
|
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where act_id = :actId and status ${status}`, {
|
|
|
actId
|
|
|
}).then(handelResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0元购用户参与列表
|
|
|
* @param uid
|
|
|
* @param actId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
getListMine(uid, actId) {
|
|
|
uid = parseInt(uid, 10) || 0;
|
|
|
actId = parseInt(actId, 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`, {
|
|
|
uid,
|
|
|
actId
|
|
|
}).then(handelResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0元购详情
|
|
|
* @param actPrizeId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
getContent(actPrizeId) {
|
|
|
let resData = {};
|
|
|
|
|
|
if (!actPrizeId) {
|
|
|
return Promise.resolve(handelResult(resData));
|
|
|
}
|
|
|
|
|
|
return Promise.all([
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where id = :actPrizeId limit 1`, {actPrizeId}),
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
|
|
|
where act_prize_id = :actPrizeId`, {actPrizeId})
|
|
|
]).then(result => {
|
|
|
let [product, content] = result;
|
|
|
|
|
|
if (product && product.length) {
|
|
|
resData = product[0];
|
|
|
resData.content = _.sortBy(content || [], o => {
|
|
|
return o.sort;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
}).then(handelResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0元购抽奖码最近获取记录
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
getCodeRecent() {
|
|
|
return mysqlCli.query(`select user_name, user_thumb, create_time
|
|
|
from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
order by u.create_time desc limit 10`).then(handelResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 0元购用户单个活动抽奖码
|
|
|
* @param uid
|
|
|
* @param actPrizeId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
getCodeMine(uid, actPrizeId) {
|
|
|
uid = parseInt(uid, 10) || 0;
|
|
|
actPrizeId = parseInt(actPrizeId, 10) || 0;
|
|
|
|
|
|
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
where act_prize_id = :actPrizeId and uid = :uid`, {
|
|
|
actPrizeId,
|
|
|
uid
|
|
|
}).then(handelResult);
|
|
|
}
|
|
|
}; |
...
|
...
|
|