Authored by 邱骏

修改product调用

... ... @@ -143,8 +143,9 @@ const userController = {
prizeUsersList(req, res, next) {
const pageNo = req.query.pageNo || 1;
const pageSize = req.query.pageSize || 20;
const actId = req.query.actId || 25;
req.ctx(UserModel).prizeUsersList(pageNo, pageSize).then(list => {
req.ctx(UserModel).prizeUsersList(pageNo, pageSize, actId).then(list => {
let result = [];
... ... @@ -158,7 +159,7 @@ const userController = {
});
return result;
}).then(list => {
req.ctx(UserModel).allInfoUsersNum().then(totalCount => {
req.ctx(UserModel).allPrizeUsersNum(actId).then(totalCount => {
res.json({
code: 200,
data: list,
... ...
... ... @@ -50,12 +50,14 @@ class UserModel extends global.yoho.BaseModel {
/**
* 中奖用户信息列表
*/
prizeUsersList(pageNo, pageSize) {
let strSql = `select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1
prizeUsersList(pageNo, pageSize, actId) {
let strSql = `select * from ${TABLE_USER_PRIZE_LOG} where is_get > 0
and act_id = :actId
order by create_time desc
limit :start, :page;`;
return mysqlCli.query(strSql, {
actId: actId,
start: (pageNo - 1) * pageSize,
page: _.parseInt(pageSize)
});
... ... @@ -88,10 +90,12 @@ class UserModel extends global.yoho.BaseModel {
/**
* 中奖用户总数
*/
allPrizeUsersNum() {
let strSql = `select count(*) as total from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`;
allPrizeUsersNum(actId) {
let strSql = `select count(*) as total from ${TABLE_USER_PRIZE_LOG} where is_get > 0 and act_id = :actId;`;
return mysqlCli.query(strSql)
return mysqlCli.query(strSql, {
actId: actId
})
.then(res => {
return res[0].total;
});
... ... @@ -121,9 +125,11 @@ class UserModel extends global.yoho.BaseModel {
* 导出中奖用户列表
* @returns {*}
*/
exportPrizeUserList() {
exportPrizeUserList(actId) {
return mysqlCli.query(
`select * from ${TABLE_USER_PRIZE_LOG} where is_get = 1;`
`select * from ${TABLE_USER_PRIZE_LOG} where is_get > 0 and act_id = :actId;`, {
actId
}
);
}
... ...
... ... @@ -5,7 +5,7 @@
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<button class="btn btn-primary btn-export-user-list" data-id="{{id}}">导出用户列表</button>
<button class="btn btn-primary btn-export-user-list" data-id="{{actId}}">导出用户列表</button>
<div class="clearfix"></div>
</div>
<div class="x_content">
... ... @@ -14,10 +14,11 @@
<thead>
<tr class="headings">
<th width="10%" class="column-title">ID</th>
<th width="15%" class="column-title">奖品等级</th>
<th width="15%" class="column-title">昵称</th>
<th width="15%" class="column-title">手机号</th>
<th width="30%" class="column-title">地址</th>
<th width="10%" class="column-title">鞋码</th>
<th width="25%" class="column-title">地址</th>
<th width="10%" class="column-title">尺码</th>
<th width="20%" class="column-title">操作</th>
</tr>
</thead>
... ...
... ... @@ -41,7 +41,7 @@ const prize = {
getPrize(req, res, next) {
let query = req.body;
let actId = query.actId;
let z = query.z || 5; // 中奖概率设置,
let z = query.z || 5; // 中奖概率设置,z:中,
let bz = query.bz || 95;
let userPhone = query.phone;
... ... @@ -80,6 +80,130 @@ const prize = {
},
/**
* 抽奖并先写入用户的手机号码防止重复抽奖, 4月9日新抽奖规则
* @param req
* @param res
* @param next
*/
async getNewPrize(req, res, next) {
let query = req.body;
let actId = query.actId;
let z = query.z || 4;
let bz = query.bz || 196;
let userPhone = query.phone;
console.log(actId, userPhone);
let baseArr = [];
let prizeArr = [];
if (!actId || !userPhone || userPhone.length !== 11) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
for (let i = 0; i < z; i++) {
baseArr.push(1);
}
for (let i = 0; i < bz; i++) {
prizeArr.push(0);
}
baseArr.forEach(item => { // 随机往prizeArr中插入一个中奖数字1
let rand = Math.floor(Math.random() * prizeArr.length);
prizeArr.splice(rand, 0, item);
});
let isGet = prizeArr[Math.floor(Math.random() * prizeArr.length)]; // 随机抽取一个,如果是1就中奖,0就不中
const userPrizeCount = await req.ctx(PrizeModel).checkUserPrize(actId, userPhone);
console.log('isGet=' + isGet, 'userPrizeCount=' + userPrizeCount);
if (isGet) {
console.log(userPrizeCount);
if (userPrizeCount === 0) {
let result;
let prizeNum_3 = await req.ctx(PrizeModel).checkPrizeNums(actId, 3);
console.log('prizeNum_3', prizeNum_3);
if (prizeNum_3 < 20) { // 先判断三等奖是否被抽完
result = await req.ctx(PrizeModel).addNewPrize(actId, userPhone, 3);
res.json({
code: 200,
prize: 3,
data: result,
message: '恭喜您中了三等奖!'
});
} else {
let prizeNum_2 = await req.ctx(PrizeModel).checkPrizeNums(actId, 2);
console.log('prizeNum_2', prizeNum_2);
if (prizeNum_2 < 10) { // 然后判断二等奖是否被抽完
result = await req.ctx(PrizeModel).addNewPrize(actId, userPhone, 2);
res.json({
code: 200,
prize: 2,
data: result,
message: '恭喜您中了二等奖!'
});
} else {
let prizeNum_1 = await req.ctx(PrizeModel).checkPrizeNums(actId, 1);
console.log('prizeNum_1', prizeNum_1);
if (prizeNum_1 < 1) { // 最后判断一等奖是否被抽完
result = await req.ctx(PrizeModel).addNewPrize(actId, userPhone, 1);
res.json({
code: 200,
prize: 1,
data: result,
mesage: '恭喜您中了一等奖'
});
} else { // 奖品全部领完的情况
result = await req.ctx(PrizeModel).addNewPrize(actId, userPhone, 0);
res.json({
code: 204,
prize: 0,
data: result,
message: '奖品已领取完'
});
}
}
}
} else {
res.json({
code: 203,
message: '请勿重复抽奖'
});
}
} else {
if (userPrizeCount === 0) {
let result = await req.ctx(PrizeModel).addNewPrize(actId, userPhone, 0);
res.json({
code: 200,
prize: 0,
data: result,
message: '很抱歉,您没有中奖'
});
} else {
res.json({
code: 203,
message: '请勿重复抽奖'
});
}
}
},
/**
* 中奖用户更新自己的用户信息
* @param req
* @param res
... ... @@ -93,6 +217,8 @@ const prize = {
let userName = decodeURIComponent(query.name);
let userSize = query.size;
console.log(req.body);
if (!actId || !userPhone || !userAddress || !userName || !userSize) {
return res.json({
code: 400,
... ...
... ... @@ -53,7 +53,7 @@ let getTicket = function(accessToken, appId, secret, prefix) { // 获取ticket
});
};
let calcSigature = function (ticket_res) { // 计算signature
let calcSigature = function(ticket_res) { // 计算signature
let appID = ticket_res.appID;
let ticket = ticket_res.access_ticket;
let nonceStr = Math.random().toString(36).substr(2, 15);
... ...
... ... @@ -47,6 +47,62 @@ class PrizeModel extends global.yoho.BaseModel {
}
/**
* 查询用户是否参与抽奖
* @param actId
* @param userPhone
* @returns {Promise.<*>}
*/
async checkUserPrize(actId, userPhone) {
let strFindSql = `SELECT COUNT(*) AS user_prize_count FROM ${TABLE_PRIZE}
WHERE act_id = :actId
AND user_phone = :userPhone;`;
return mySqlCli.query(strFindSql, {
actId,
userPhone
}).then(ret => {
return ret[0].user_prize_count || 0;
});
}
/**
* 查看已中奖的奖品数量
* @param actId
* @param isGet
* @returns {Promise.<*>}
*/
async checkPrizeNums(actId, isGet) {
let strSql = `SELECT COUNT(*) AS total_prize_count FROM ${TABLE_PRIZE}
WHERE act_id = :actId
AND is_get = :isGet;`;
return mySqlCli.query(strSql, {
actId,
isGet
}).then(ret => {
return ret[0].total_prize_count || 0;
});
}
/**
* 插入新的中奖信息
* @param actId
* @param userPhone
* @param isGet
* @returns {Promise.<*>}
*/
async addNewPrize(actId, userPhone, isGet) {
let strInsertSql = `INSERT INTO ${TABLE_PRIZE} (act_id, user_phone, is_get)
VALUES(:actId, :userPhone, :isGet)`;
return mySqlCli.insert(strInsertSql, {
actId,
userPhone,
isGet
});
}
/**
* 检查并添加中奖者基础信息
* @param actId
* @param userPhone
... ... @@ -119,9 +175,11 @@ class PrizeModel extends global.yoho.BaseModel {
user_address=:address,
user_shoes_size=:shoesSize
WHERE user_phone=:userPhone
AND is_get=1
AND is_get > 0
AND act_id=:actId`;
return mySqlCli.update(strSql, {
actId,
userPhone,
... ...
... ... @@ -17,6 +17,7 @@ router.get('/gettoken', qiniu.getToken);
router.get('/share/getSignPackage', wechat.getSignPackage);
router.get('/prize/checkPrize', prize.checkPrize);
router.post('/prize/getPrize', prize.getPrize);
router.post('/prize/getNewPrize', prize.getNewPrize);
router.post('/prize/updatePrize', prize.updatePrize);
router.post('/info/saveUserInfo', prize.saveUserInfo);
... ...
... ... @@ -153,8 +153,7 @@ class Y100Model extends global.yoho.BaseModel {
data: {
method: 'h5.product.batch',
limit: product_skns.split(',').length,
productSkn: product_skns,
contain_all: 'Y'
productSkn: product_skns
},
param: {
cache: true
... ... @@ -165,8 +164,7 @@ class Y100Model extends global.yoho.BaseModel {
data: {
method: 'h5.product.batch',
limit: recommend_skns.split(',').length,
productSkn: recommend_skns,
contain_all: 'Y'
productSkn: recommend_skns
},
param: {
cache: true
... ...
... ... @@ -58,7 +58,7 @@
<ul class="nav child_menu">
<li><a href="/admin/user/list">用户列表</a></li>
<li><a href="/admin/user/users_list">用户信息收集</a></li>
<li><a href="/admin/user/prize_users_list">中奖用户信息</a></li>
<li><a href="/admin/user/prize_users_list?actId=25">中奖用户信息</a></li>
<li><a href="/admin/user/login-log">用户登录日志</a></li>
</ul>
</li>
... ...
No preview for this file type
... ... @@ -51,11 +51,14 @@ function bind_table_pagination() {
let html = '';
_.each(list, item => {
item.userBirthday = moment(item.userBirthday).format('YYYY-MM-DD');
item.userGender = ['男', '女'][item.userGender];
if (item.userShoesSize < 5) {
item.userShoesSize = {1: 'S', 2: 'M', 3: 'L', 4: 'XL'}[item.userShoesSize]
}
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class="">${item.isGet}</td>
<td class="">${item.userName}</td>
<td class="">${item.userPhone}</td>
<td class="">${item.userAddress}</td>
... ...