Authored by shuaiguo

Merge branch 'release/yohood-lottrey' into 'master'

Release/yohood lottrey

YOHOOD球鞋抽奖

See merge request !104
... ... @@ -152,3 +152,4 @@ nbproject/*
dist
test.js
public/docs/*.txt
Data
... ...
... ... @@ -410,11 +410,12 @@ module.exports = class extends global.yoho.BaseModel {
isShareTake: false,
actName: productInfo.name,
actStartTime: productInfo.start_time,
actEndTime: productInfo.end_time
actEndTime: productInfo.end_time,
channel: productInfo.channel
})).then(response => {
if (+response.code === 200) {
if (shareUid) {
this.sendPrizeCode(shareUid, actPrizeId, {isShareTake: true});
this.sendPrizeCode(shareUid, actPrizeId, {isShareTake: true, channel: productInfo.channel });
}
// 参与人数满时更新活动状态
... ... @@ -575,8 +576,13 @@ module.exports = class extends global.yoho.BaseModel {
* @param actPrizeId
* @param extra
* @returns {*}
* CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
*/
sendWechatMessage(uid, actPrizeId, extra = {}) {
if (extra.channel === 2) {
this.sendYohoodWechatMessage(uid, actPrizeId, extra);
return;
}
let info = {};
let baseUri = 'pages/zeroSell/detail';
... ... @@ -601,4 +607,44 @@ module.exports = class extends global.yoho.BaseModel {
logger.error(e);
});
}
/**
* 向用户发送获得抽奖码消息
* @param uid
* @param actPrizeId
* @param extra
* @returns {*}
* CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
*/
sendYohoodWechatMessage(uid, actPrizeId, extra = {}) {
const { actStartTime, actEndTime, miniAppType, actName } = extra;
const activityTime = `${moment.unix(actStartTime).format('YYYY.MM.DD HH:mm:ss')} - ${moment.unix(actEndTime).format('YYYY.MM.DD HH:mm:ss')}`;
logger.info(`sendYohoodWechatMessage extra: ${JSON.stringify(extra)}`);
const data = {
method: 'wechat.message.send',
sendScene: 'MINI_ACTIVITY_JOIN',
miniAppType: +miniAppType === 63 ? +miniAppType : 29,
params: JSON.stringify({
activityTitle: actName || '',
activityTime,
pageUrl: `pages/zeroSell/originalPriceSell?actPrizeId=${actPrizeId}`
}),
uidList: [uid]
};
logger.info(`sendYohoodWechatMessage param: ${JSON.stringify(data)}`);
return this.get({
data
}).then(result => {
if (result.code !== 200) {
logger.info(`zerobuy_join_notice send fail uid: ${uid}`);
}
})
.catch(e => {
logger.error(e);
});
}
};
... ...
... ... @@ -13,6 +13,8 @@ const DO_SUCCESS = '操作成功';
const DO_FAILED = '操作失败!';
const GET_SUCCESS = '获取成功';
const INVALID_PARAMS = '参数错误';
const INVALID_PRICE_CODE = '开奖码不存在';
const logger = global.yoho.logger;
const timeFormat = (time) => {
if (_.isNumber(time)) {
... ... @@ -22,6 +24,7 @@ const timeFormat = (time) => {
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
const zeroBuy = {
zeroBuyList(req, res, next) {
let params = req.query;
... ... @@ -33,6 +36,14 @@ const zeroBuy = {
{name: '已开奖', status: 2},
];
// 渠道
const channelList = [
{name: '全部', value: ''},
{name: 'yoluck渠道', value: 0},
{name: 'UFO渠道', value: 1},
{name: 'YOHOOD渠道', value: 2},
];
req.ctx(ActivityModel).getZerobuyList(req.query).then(result => {
_.forEach(statusList, value => {
if (params.status === `${value.status}`) {
... ... @@ -40,17 +51,23 @@ const zeroBuy = {
}
});
if (!_.find(statusList, 'active')) {
statusList[0].active = true;
_.forEach(channelList, channel => {
if (params.channel === `${channel.value}`) {
channel.active = true;
}
});
res.render('activity/zero-buy-list', Object.assign(result, {
bodyClass: 'nav-md',
module: 'admin',
page: 'zero-buy',
qsQuery: params.query,
qsStatus: params.status,
statusList
qsStatus: _.isUndefined(params.status) ? -1 : params.status,
qsChannel: _.isUndefined(params.channel) ? -1 : params.channel,
isSelectChannel: !_.isUndefined(params.channel),
isSelectStatus: !_.isUndefined(params.status),
statusList,
channelList
}));
}).catch(next);
},
... ... @@ -59,6 +76,7 @@ const zeroBuy = {
.then(res.json).catch(next);
},
zeroBuyPublish(req, res, next) {
let ctx = req.ctx(ActivityModel);
let id = req.body.id;
let channel = req.body.channel;
... ... @@ -112,6 +130,31 @@ const zeroBuy = {
zeroBuyUserJoinNum(req, res, next) {
req.ctx(ActivityModel).getUserJoinNum(req.body.id)
.then(res.json).catch(next);
},
fetchYOHOODActivityTimes(req, res, next) {
req.ctx(ActivityModel).fetchYOHOODActivityTimes()
.then(res.json).catch(next);
},
yohoodPublish(req, res, next) {
const {id, channel, code} = req.body;
req.ctx(ActivityModel).fetchPriceCodeInfo(code, id).then((result)=> {
if (_.isEmpty(result)) {
return res.json({
code: 400,
message: INVALID_PRICE_CODE
});
} else {
req.ctx(ActivityModel).setZeroBuyPublish(id).then(result => {
if (result.code === 200) {
req.ctx(ActivityModel).sendWechatMessage(id, channel, code);
}
return res.json(result);
}).catch(function(e) {
throw e;
});
}
}).catch(next);
}
};
... ...
... ... @@ -394,6 +394,7 @@ class AdminModel extends global.yoho.BaseModel {
* 获取0元购活动列表
* @param params
* @returns {*}
* CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
*/
getZerobuyList(params) {
const actId = 0;
... ... @@ -410,6 +411,11 @@ class AdminModel extends global.yoho.BaseModel {
where.push('status = :status');
}
// 增加筛选条件 渠道
if (!_.isNaN(parseInt(params.channel, 10))) {
where.push('channel = :channel');
}
return Promise.all([
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
where ${where.join(' and ')} order by id desc
... ... @@ -418,13 +424,15 @@ class AdminModel extends global.yoho.BaseModel {
start: (page - 1) * pageSize,
end: page * pageSize,
query: `%${params.query}%`,
status: params.status
status: params.status,
channel: params.channel
}),
mysqlCli.query(`select count(*) as total from ${TABLE_ACT_PRIZE_PRODUCT}
where ${where.join(' and ')}`, {
actId,
query: `%${params.query}%`,
status: params.status
status: params.status,
channel: params.channel
}),
]).then(result => {
let resData = {};
... ... @@ -589,9 +597,14 @@ class AdminModel extends global.yoho.BaseModel {
});
}
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
getZerobuyContent(id) {
let resData = {
isYohood: false // 是否为YOHOOD渠道
};
if (!id) {
return Promise.resolve({});
return Promise.resolve(resData);
}
return Promise.all([
... ... @@ -600,7 +613,6 @@ class AdminModel extends global.yoho.BaseModel {
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
where act_prize_id = :id;`, {id})
]).then(result => {
let resData = {};
let [product, content] = result;
if (product && product.length) {
... ... @@ -608,6 +620,7 @@ class AdminModel extends global.yoho.BaseModel {
resData.content = _.sortBy(content || [], o => {
return o.sort;
});
resData.isYohood = +resData.channel === 2;
resData.time = `${timeFormat(resData.start_time)} - ${timeFormat(resData.end_time)}`;
}
... ... @@ -629,14 +642,15 @@ class AdminModel extends global.yoho.BaseModel {
limit: params.limit,
startTime: Date.parse(new Date(_.trim(times[0]).replace(/-/g, '/'))) / 1000,
endTime: Date.parse(new Date(_.trim(times[1]).replace(/-/g, '/'))) / 1000,
channel: params.channel || 0
channel: params.channel || 0,
lotteryPrice: params.lotteryPrice || 0
};
if (params.id) {
sqls.push(mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set
name = :name, price = :price, \`limit\` = :limit,
cover_img = :cover, sort = :sort,
start_time = :startTime, end_time = :endTime, channel = :channel
start_time = :startTime, end_time = :endTime, channel = :channel, lottery_price = :lotteryPrice
where id = :id`, proParams));
// 更新楼层
... ... @@ -687,9 +701,8 @@ class AdminModel extends global.yoho.BaseModel {
}
} else {
sqls.push(mysqlCli.insert(`insert into ${TABLE_ACT_PRIZE_PRODUCT} (
name, price, \`limit\`, sort, cover_img, start_time, end_time, channel) values (
:name, :price, :limit, :sort, :cover, :startTime, :endTime, :channel
)`, proParams));
name, price, \`limit\`, sort, cover_img, start_time, end_time, channel, lottery_price) values (
:name, :price, :limit, :sort, :cover, :startTime, :endTime, :channel, :lotteryPrice)`, proParams));
}
return Promise.all(sqls).then(result => {
... ... @@ -770,13 +783,21 @@ class AdminModel extends global.yoho.BaseModel {
* @param id
* @returns {*}
*/
async sendWechatMessage(id, channel = 0) {
let info = await Promise.all([
async sendWechatMessage(id, channel = 0, code = '') {
const promises = [
mysqlCli.query(`select name from ${TABLE_ACT_PRIZE_PRODUCT}
where id = :id limit 1`, {id}),
mysqlCli.query(`select distinct uid from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :id`, {id})
]);
];
if (code) {
promises.push(mysqlCli.query(`select distinct uid from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :id and prize_code = :code`, {id, code}));
} else {
promises.push(mysqlCli.query(`select distinct uid from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :id`, {id}));
}
let info = await Promise.all(promises);
let productInfo = _.get(info, '[0][0]');
let userList = [];
... ... @@ -785,6 +806,7 @@ class AdminModel extends global.yoho.BaseModel {
userList.push(value.uid);
});
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
let msgApi = [];
let msgData = {
method: 'wechat.message.send',
... ... @@ -793,10 +815,25 @@ class AdminModel extends global.yoho.BaseModel {
params: JSON.stringify({
activityTitle: productInfo.name,
activityTime: moment().format('YYYY-MM-DD HH:mm') + ':00',
pageUrl: 'pages/zeroSell/detail?actPrizeId=' + id
pageUrl: `pages/zeroSell/detail?actPrizeId=${id}`
})
};
logger.info(`wechat.message.send params:${msgData}`);
if (+channel === 2) {
msgData = {
method: 'wechat.message.send',
sendScene: 'YOHOOD_WINNING_NOTICE',
miniAppType: 29,
params: JSON.stringify({
productName: productInfo.name,
actPrizeId: id,
pageUrl: `pages/zeroSell/originalPriceSell?actPrizeId=${id}`
})
};
}
_.forEach(_.chunk(userList, NOTICE_BATCH_SEND_USER_NUM), value => {
value = _.compact(value);
... ... @@ -828,6 +865,25 @@ class AdminModel extends global.yoho.BaseModel {
return Promise.all(_.take(apis, NOTICE_BATCH_SEND_API_NUM).map(rp => rp()));
}
/**
* 获取yohood活动时间列表
*/
fetchYOHOODActivityTimes() {
const now = new Date().getTime() / 1000;
return mysqlCli.query(
`select start_time as startTime, end_time as endTime, name, id from ${TABLE_ACT_PRIZE_PRODUCT}
where channel = 2 and end_time > ${now} and not status = 2`);
}
/**
* 查询yohood开奖码信息
*/
fetchPriceCodeInfo(code, id) {
return mysqlCli.query(
`select * from ${TABLE_ACT_PRIZE_PRODUCT_USER} where prize_code = :code and act_prize_id = :id`, {code, id});
}
}
module.exports = AdminModel;
... ...
... ... @@ -39,6 +39,8 @@ router.get('/activity/zerobuy/edit', activity.zeroBuyEdit);
router.post('/activity/zerobuy/save', activity.zeroBuySave);
router.post('/activity/zerobuy/notice', activity.zeroBuyNoticeEdit);
router.post('/activity/zerobuy/joinnum', activity.zeroBuyUserJoinNum);
router.get('/activity/yohood/times', activity.fetchYOHOODActivityTimes); // yohood活动时间列表
router.post('/activity/yohood/publish', activity.yohoodPublish); // yohood活动开奖
// 用户管理[page]
router.get('/user/list', user.userListPage);
... ...
... ... @@ -9,18 +9,25 @@
<form id="createForm" class="form-horizontal form-label-left">
<input class="form-imput" type="hidden" data-type="id" value="{{id}}">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actChannel">渠道<span
class="required">*</span>
</label>
<div class="col-md-2 col-sm-2 col-xs-12">
<select {{#if id}}disabled{{/if}} class="form-control col-md-2 form-imput" data-type="channel" name="actChannel"
form="createForm">
<option value="0" {{#isEqualOr channel 0}} selected {{/isEqualOr}}>yoluck渠道</option>
<option value="1" {{#isEqualOr channel 1}} selected {{/isEqualOr}}>UFO渠道</option>
<option value="2" {{#isEqualOr channel 2}} selected {{/isEqualOr}}>YOHOOD渠道</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">
商品名称<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12 form-imput"
data-type="name"
data-toggle="tooltip"
data-placement="bottom"
title="商品名称不能为空"
name="actName"
type="text"
maxlength="50"
<input class="form-control col-md-7 col-xs-12 form-imput" data-type="name" data-toggle="tooltip"
data-placement="bottom" title="商品名称不能为空" name="actName" type="text" maxlength="50"
value="{{name}}">
</div>
</div>
... ... @@ -31,7 +38,18 @@
<div class="col-md-6 col-sm-6 col-xs-12">
<img src="{{cover_img}}" class="col-md-6 product-thumb {{#unless cover_img}}hide{{/unless}}">
<button type="button" class="btn btn-primary btn-upload-thumb" data-cover="{{cover_img}}">上传</button>
<button type="button" class="btn btn-primary btn-upload-thumb"
data-cover="{{cover_img}}">上传</button>
</div>
</div>
<div class="item form-group lottery-price {{#unless isYohood}}hide{{/unless}}">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">
抽奖价<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12 form-imput" data-type="lotteryPrice"
data-toggle="tooltip" data-placement="bottom" title="抽奖价不能为空" name="actName" type="text"
maxlength="10" value="{{lottery_price}}">
</div>
</div>
<div class="item form-group">
... ... @@ -39,15 +57,9 @@
商品价格<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12 form-imput"
data-type="price"
data-toggle="tooltip"
data-placement="bottom"
title="商品价格不能为空"
name="actName"
type="text"
maxlength="10"
value="{{price}}">
<input class="form-control col-md-7 col-xs-12 form-imput" data-type="price"
data-toggle="tooltip" data-placement="bottom" title="商品价格不能为空" name="actName" type="text"
maxlength="10" value="{{price}}">
</div>
</div>
<div class="item form-group">
... ... @@ -59,10 +71,8 @@
<span class="add-on input-group-addon"><i
class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>
<input type="text" name="activityTime" id="activityTime"
class="form-control col-md-7 col-xs-12 form-imput"
data-type="time"
placeholder="开始时间 - 结束时间"
value="{{time}}"/>
class="form-control col-md-7 col-xs-12 form-imput" data-type="time"
placeholder="开始时间 - 结束时间" value="{{time}}" />
</div>
</div>
</div>
... ... @@ -71,41 +81,23 @@
class="required">*</span>
</label>
<div class="col-md-2 col-sm-2 col-xs-12">
<input id="actVoteLimit" class="form-control col-md-2 form-imput"
data-type="limit"
data-toggle="tooltip" data-placement="bottom" title="开奖需要人数"
name="actVoteLimit"
type="text"
maxlength="10"
value="9999999">
<input id="actVoteLimit" class="form-control col-md-2 form-imput" data-type="limit"
data-toggle="tooltip" data-placement="bottom" title="开奖需要人数" name="actVoteLimit" type="text"
maxlength="10" value="9999999">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">排序<span
<div class="item form-group sort {{#isEqualOr channel 2}}hide{{/isEqualOr}}">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="sort">排序<span
class="required">*</span>
</label>
<div class="col-md-2 col-sm-2 col-xs-12">
<input id="actVoteLimit" class="form-control col-md-2 form-imput"
data-type="sort"
data-toggle="tooltip" data-placement="bottom" title="排序"
name="actVoteLimit"
type="text"
maxlength="10"
value="{{sort}}">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actChannel">渠道<span
class="required">*</span>
</label>
<div class="col-md-2 col-sm-2 col-xs-12">
<select class="form-control col-md-2 form-imput" data-type="channel" name="actChannel" form="createForm">
<option value="0" {{#isEqualOr channel 0}} selected {{/isEqualOr}}>yoluck渠道</option>
<option value="1"{{#isEqualOr channel 1}} selected {{/isEqualOr}}>UFO渠道</option>
</select>
<input id="sort" class="form-control col-md-2 form-imput" data-type="sort"
data-toggle="tooltip" data-placement="bottom" title="排序" name="sort" type="text"
maxlength="10" value="{{sort}}">
</div>
</div>
</form>
<div class="content-detail {{#isEqualOr channel 2}}hide{{/isEqualOr}}">
<div class="x_title">
<h2>详情内容</h2>
<div class="clearfix"></div>
... ... @@ -114,20 +106,12 @@
<div class="col-md-6 col-md-offset-3 floor-view-box">
{{# content}}
{{#if floor_type}}
<div class="floor-item"
data-id="{{id}}"
data-sort="{{sort}}"
data-content="{{content}}"
{{#isEqualOr floor_type 1}}
data-type="text">
<div class="floor-item" data-id="{{id}}" data-sort="{{sort}}" data-content="{{content}}"
{{#isEqualOr floor_type 1}} data-type="text">
<p class="item-content">{{content}}</p
{{/isEqualOr}}
{{#isEqualOr floor_type 2}}
<p class="item-content">{{content}}</p {{/isEqualOr}} {{#isEqualOr floor_type 2}}
data-type="img">
<img src="{{content}}" class="item-content"
{{/isEqualOr}}
{{#isEqualOr floor_type 3}}
<img src="{{content}}" class="item-content" {{/isEqualOr}} {{#isEqualOr floor_type 3}}
data-type="video">
<video src="{{content}}" class="item-content">
您的浏览器不支持 video 标签。
... ... @@ -149,10 +133,13 @@
<button type="button" class="btn btn-primary btn-add-floor" data-type="img">图片</button>
<button type="button" class="btn btn-primary btn-add-floor" data-type="video">视频</button>
</div>
</div>
</div>
<div class="col-md-2 col-md-offset-10 action-wrap">
<button type="button" class="btn btn-primary btn-save-activity">保存</button>
</div>
</div>
<a id="upload-btn"></a>
{{/ content}}
... ...
... ... @@ -9,20 +9,62 @@
<div class="search-wrap">
<input type="text" id="search-key" class="form-control" value="{{qsQuery}}">
<div class="btn-group">
<button type="button" id="status-switch" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-status="{{qsStatus}}"><span class="btn-text">
<button
type="button"
id="status-switch"
class="btn btn-default dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
data-status="{{qsStatus}}">
<span class="btn-text">
{{#if isSelectStatus}}
{{# statusList}}
{{#if active}}{{name}}{{/if}}
{{/ statusList}}
</span> <span class="caret"></span></button>
{{else}}请选择活动状态
{{/if}}
</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{{# statusList}}
<li><a href="javascript:;" class="status-switch" data-status="{{status}}">{{name}}</a></li>
{{/ statusList}}
</ul>
</div>
<div class="btn-group">
<button
type="button"
id="channel-switch"
class="btn btn-default dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
data-channel="{{qsChannel}}">
<span class="btn-text">
{{#if isSelectChannel}}
{{# channelList}}
{{#if active}}{{name}}{{/if}}
{{/ channelList}}
{{else}}请选择活动渠道
{{/if}}
</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{{# channelList}}
<li><a href="javascript:;" class="channel-switch" data-channel="{{value}}">{{name}}</a></li>
{{/ channelList}}
</ul>
</div>
<div class="action-wrapper">
<button type="button" id="search-btn" class="btn btn-primary">筛选</button>
<a href="/admin/activity/zerobuy" class="btn btn-primary">全部</a>
</div>
</div>
</div>
<table class="table table-bordered">
... ... @@ -52,6 +94,7 @@
<td class="text-center">
{{#isEqualOr channel 0}} yoluck渠道 {{/isEqualOr}}
{{#isEqualOr channel 1}} UFO渠道 {{/isEqualOr}}
{{#isEqualOr channel 2}} YOHOOD渠道 {{/isEqualOr}}
</td>
<td class="text-center">
<image src="{{cover_img}}" class="cover-img">
... ... @@ -296,4 +339,29 @@
</div>
</div>
<div id='yohood-confirm-model' class="modal fade in" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>确认开奖</h3>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<div class="col-md-9 col-sm-6 col-xs-12">
<input type="text" class="form-control" name="price-code" placeholder="请输入抽奖码">
<div class="error-message"></div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<a class="btn btn-success" data-dismiss="modal">取消</a>
<a class="btn btn-success sure-yohood-publish-btn">确定</a>
</div>
</div>
</div>
</div>
<!-- /page content -->
... ...
... ... @@ -4,6 +4,7 @@ require('bootstrap-daterangepicker');
const _ = require('lodash');
const $alert = $('#alert-modal');
const $confirm = $('#confirm-modal');
const $yohoodConfirm = $('#yohood-confirm-model');
$alert.showMsg = function(msg) {
this.find('.modal-text').text(msg);
... ... @@ -13,6 +14,7 @@ $alert.showMsg = function(msg) {
function bindListPageEvent() {
const $searchKey = $('#search-key');
const $statusSwitch = $('#status-switch');
const $channelSwitch = $('#channel-switch');
const $publishForm = $('#publish-form');
const $noticeModal = $('#notice-modal');
const $noticeForm = $noticeModal.find('#notice-form');
... ... @@ -20,15 +22,23 @@ function bindListPageEvent() {
const searchFn = function() {
let val = $searchKey.val();
let status = $statusSwitch.data('status');
let channel = $channelSwitch.data('channel');
let qs = [];
if (val) {
qs.push(val ? 'query=' + val : '');
}
if (status === '' || _.isNumber(+status)) {
if (status >= 0) {
qs.push(`status=${status}`);
}
}
if (!_.isNaN(+status)) {
qs.push('status=' + status);
if (channel === '' || _.isNumber(+channel)) {
if (channel >= 0) {
qs.push(`channel=${channel}`);
}
}
location.href = `?${qs.join('&')}`;
... ... @@ -40,6 +50,13 @@ function bindListPageEvent() {
$statusSwitch.data('status', $this.data('status')).children('.btn-text').text($this.text());
};
// 渠道
const channelFn = function() {
let $this = $(this);
$channelSwitch.data('channel', $this.data('channel')).children('.btn-text').text($this.text());
};
const editFn = function() {
window.open('/admin/activity/zerobuy/edit?id=' +
$(this).data('id'), '_blank');
... ... @@ -198,18 +215,30 @@ function bindListPageEvent() {
$('#search-btn').on('click', searchFn);
$('.status-switch').on('click', statusFn);
$('.channel-switch').on('click', channelFn);
$('.btn-edit').on('click', editFn);
$('.btn-switch-open').on('click', switchFn);
$('.btn-switch-close').on('click', switchFn);
$('.btn-export').on('click', exportFn);
$('.btn-publish').on('click', function() {
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
const channel = $(this).data('channel');
if (+channel === 2) {
$('input', $yohoodConfirm).val('');
$('.error-message').text('');
$yohoodConfirm.modal('show');
$yohoodConfirm.data('id', $(this).data('id'));
$yohoodConfirm.data('channel', channel);
} else {
$('input', $confirm).val('');
$('select', $confirm).val(0).change();
$confirm.data('id', $(this).data('id'));
$confirm.data('channel', $(this).data('channel'));
$confirm.modal('show');
$confirm.data('id', $(this).data('id'));
$confirm.data('channel', channel);
}
});
$('.btn-notice').on('click', function() {
let notice = $(this).parent().data('notice') || {};
... ... @@ -233,6 +262,33 @@ function bindListPageEvent() {
$('.sure-publish-btn').on('click', publishFn);
$('.sure-notice-btn').on('click', noticeFn);
$('.sure-yohood-publish-btn').on('click', function() {
const code = $('input[name="price-code"]', $yohoodConfirm).val();
if (code) {
$.ajax({
method: 'post',
url: '/admin/activity/yohood/publish',
data: {
id: $yohoodConfirm.data('id'),
channel: $yohoodConfirm.data('channel'),
code,
}
}).then(res=> {
if (res.code === 200) {
$('.error-message').text('');
$yohoodConfirm.modal('hide');
$alert.find('.modal-text').text('开奖成功,已提醒用户领奖');
$alert.modal('show');
$alert.on('hide.bs.modal', function() {
location.reload();
});
} else {
$('.error-message').text(res.message);
}
});
}
});
$('.notice-btn-select').change(noticeBtnTypeChangeFn);
}
... ... @@ -303,9 +359,47 @@ function generateCid(id) {
return Math.floor(Date.now() + Math.random() * 10000000000 * (id + 1));
}
/**
* 获取yohood活动时间列表,用于判断活动时间是否重叠
*/
function YOHOODActivityApiGenerator() {
let isFetch = false;
let yohoodActivityTimeList = [];
function fetchTimeList() {
if (isFetch) {
return;
}
$.ajax({
method: 'get',
url: '/admin/activity/yohood/times',
}).then(function(res) {
isFetch = true;
yohoodActivityTimeList = res || [];
}).catch(()=> {
alert('获取yohood活动时间列表失败');
});
}
return {
fetchTimeList,
getList: function() {
return yohoodActivityTimeList;
}
};
}
function bindEditPageEvent() {
initUpload();
// 获取yohood活动时间列表
const id = $('input[data-type="id"]').val();
const channel = $('select[name="actChannel"]').val();
const yohoodApi = YOHOODActivityApiGenerator();
if (!!id && +channel === 2) {
yohoodApi.fetchTimeList();
}
let $floorBox = $('.floor-view-box');
let floorContent = {};
const typeName = {
... ... @@ -324,16 +418,62 @@ function bindEditPageEvent() {
let resData = {};
let error;
/**
* 选择“YOHOOD渠道”带出如下字段:
* 商品名称(现有)、商品图⽚片(现 有)、抽奖价(新增)、商品价格(现有)、
* 活动有效时间(YOHOOD活动创建 提交时不不可以重叠,其他渠道不不影响),
* 排序(隐藏,默认为0)、详情内容 (隐藏,不不需要填写);
* CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
*/
const selectedChannel = $('select[name="actChannel"]').val();
$('.form-imput').each(function() {
let $this = $(this);
let val = $this.val();
let data = $this.data();
if (!val && !error && data.type !== 'id') {
if (+selectedChannel === 2) {
if (data.type !== 'sort') {
error = data.empty || `请填写${data.type}`;
}
} else {
if (data.type !== 'lotteryPrice') {
error = data.empty || `请填写${data.type}`;
}
}
}
if (+selectedChannel === 2) {
if (data.type !== 'sort') {
resData[data.type] = val;
}
if (data.type === 'time') {
const [startTime, endTime] = val.split(' - ');
const startTimeInSeconds = new Date(startTime).getTime() / 1000;
const endTimeInSeconds = new Date(endTime).getTime() / 1000;
// 时间段不能重叠
for (const timeInfo of yohoodApi.getList()) {
const {startTime: st, endTime: et, id: actId} = timeInfo;
if (+id !== +actId) {
if (startTimeInSeconds >= st && startTimeInSeconds <= et ||
endTimeInSeconds >= st && endTimeInSeconds <= et ||
startTimeInSeconds <= st && endTimeInSeconds >= et) {
error = new Error('YOHOOD活动时间重叠');
break;
}
}
}
}
} else {
if (data.type !== 'lotteryPrice') {
resData[data.type] = val;
}
}
});
if (error) {
... ... @@ -447,7 +587,7 @@ function bindEditPageEvent() {
if (typeof ($.fn.daterangepicker) !== 'undefined') {
$('#activityTime').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
timePickerIncrement: 5,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
... ... @@ -579,6 +719,22 @@ function bindEditPageEvent() {
}
});
});
// CHANNELTYPE: {'yoluck渠道': 0, 'UFO渠道': 1,'YOHOOD渠道': 2}
// YOHOOD渠道
$('select[name="actChannel"]').on('change', function(e) {
if (+e.target.value === 2) {
// 获取yohood活动时间列表
yohoodApi.fetchTimeList();
$('.content-detail').addClass('hide');
$('.sort').addClass('hide');
$('.lottery-price').removeClass('hide');
} else {
$('.content-detail').removeClass('hide');
$('.sort').removeClass('hide');
$('.lottery-price').addClass('hide');
}
});
}
if ($('.zerobuy-list-page').length) {
... ...
... ... @@ -4,6 +4,13 @@
padding-bottom: 20px;
}
.action-wrapper .btn {
margin-top: 5px;
}
.error-message {
margin-top: 5px;
color: #f5222d;
}
.search-wrap > * {
display: inline-block;
max-width: 50%;
... ...