Authored by htoooth

merge ghw

/**
* 个人中心二维码 controller
* @author: weiqingting<qingting.wei@yoho.cn>
* @date: 2016/05/16
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const CurrencyModel = require('../models/CurrencyModel');
const moment = require('moment');
const convertUnitTime = (src) => {
return moment.unix(src).format('YYYY-MM-DD');
};
const index = (req, res, next)=>{
let $uid = '8041246';
let $condition = {
page: req.query.page || 1,
queryType: req.query.type || 0,
beginTime: req.query.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90)
};
co(function*() {
let data = yield CurrencyModel.currencyData($uid, $condition);
res.render('currency', {
content: data
});
})().catch(next);
};
module.exports = {
index
};
... ... @@ -4,67 +4,15 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
let CouponsModel = require('../models/CouponsModel');
const helpers = global.yoho.helpers;
let couponsModel = require('../models/coupons-model');
const index = (req, res, next)=>{
let uid = '8041246';
let type = req.query.type || CouponsModel.UNUSED;
let page = '';
let limit = '';
co(function*() {
let coupons = yield CouponsModel.getCouponsList(uid, type, page, limit);
let data = {};
data.pager = {
hasCheckAll: false,
count: coupons.pager.total || 0,
curPage: coupons.pager.page || 0,
totalPages: coupons.pager.pageTotal || 0
};
if (type === CouponsModel.UNUSED) {
if (!coupons.list.length) {
data.unUseCoupons = {empty: '您没有优惠券'};
} else {
data.unUseCoupons = coupons.list;
}
data.unUse = true;
} else if (type === CouponsModel.USED) {
if (!coupons.list.length) {
data.usedCoupons = {empty: '您没有优惠券'};
} else {
data.usedCoupons = coupons.list;
}
data.used = true;
}
else if (type === CouponsModel.INVALID) {
if (!coupons.list.length) {
data.noValidCoupons = {empty: '您没有优惠券'};
} else {
data.noValidCoupons = coupons.list;
}
data.noValid = true;
}
data.tabs = [
{
active: type === CouponsModel.UNUSED ? true : false,
url: helpers.urlFormat('/home/coupons', {type: CouponsModel.UNUSED}),
name: '未使用优惠券'
},
{
ctive: type === CouponsModel.USED ? true : false,
url: helpers.urlFormat('/home/coupons', {type: CouponsModel.USED}),
name: '已使用优惠券'
},
{
ctive: type === CouponsModel.INVALID ? true : false,
url: helpers.urlFormat('/home/coupons', {type: CouponsModel.INVALID}),
name: '已失效优惠券'
}
];
res.render('coupons', data);
})();
couponsModel.couponsData(uid, req.query).then(result => {
res.render('coupons', result);
}).catch(next);
};
module.exports = {
... ...
/**
* 个人中心我的有货币 controller
* @author: weiqingting<qingting.wei@yoho.cn>
* @date: 2016/05/16
*/
'use strict';
const currencyModel = require('../models/currency-model');
const index = (req, res, next)=>{
let uid = '8041246';
currencyModel.currencyData(uid, req.query).then(result => {
res.render('currency', {
content: result
});
}).catch(next);
};
module.exports = {
index
};
... ...
/**
* 个人中心---兑换礼品卡
* @author gaohongwei <hongwei.gao@yoho.cn>
* @date: 2016/9/7
*/
'use strict';
const mRoot = '../models';
const giftService = require(`${mRoot}/gift-service`); // user model
/**
* 礼品卡页面
*/
exports.index = (req, res, next) => {
let uid = req.user.uid;
let responseData = {
module: 'home',
page: 'gift'
};
// 真实数据输出
giftService.index(req.query, uid).then(result => {
responseData.meGiftPage = true;
Object.assign(responseData, result);
res.render('gift', responseData);
}).catch(next);
};
/**
* 个人中心-兑换礼品卡提交返回信息
*/
exports.exchange = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
giftService.exchange(req, req.body, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const RedenvelopesModel = require('../models/RedenvelopesModel');
const redenvelopesModel = require('../models/redenvelopes-model');
const index = (req, res, next)=>{
let $uid = '8041246';// req.user.uid;
let $udid = 'abcdrf';// req.sessionID;
let uid = '8040274';
co(function*() {
let result = yield RedenvelopesModel.redenvelopesList($uid);
res.render('Redenvelopes', {
redenvelopesModel.redenvelopesList(uid).then(result => {
res.render('redenvelopes', {
meRedEnvelopes: result
});
})().catch(next);
}).catch(next);
};
module.exports = {
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const UserData = require('../models/UserData');
const moment = require('moment');
const helpers = global.yoho.helpers;
const vipModel = require('../models/vip-service');
const index = (req, res, next)=>{
let uid = '8041246';// req.user.uid;
co(function*() {
let vipInfo = yield UserData.getVIPInfoByUid(uid);
let data = vipInfo.data, proportion = '0%';
if (+data.next_need_cost != 0) {
proportion = data.current_year_cost * 100 / data.next_need_cost;
proportion = proportion > 100 ? 100 : proportion;
proportion = proportion + '%';
}
let remainDays = Math.floor((Date.now() - (+data.vip_end_time) * 1000) / 86400);
// let preferences={};
// enjoyPreferences=data.enjoy_preferential;
if (data.enjoy_preferential) {
data.enjoy_preferential = data.enjoy_preferential.map(function(item, inex) {
return {
id: item.id,
favTxt: item.title,
imgType: helpers.https(item.pic),
description: item.description
};
});
}
let vip = {
title: data.current_vip_title,
level: data.current_vip_level,
totalCost: (+data.current_total_cost).toFixed(2),
nextTitle: data.next_vip_title,
nextLevel: data.next_vip_level,
nextCost: data.next_need_cost,
enjoyPreferences: data.enjoy_preferential,
yearCost: data.current_year_cost,
upgradeCost: data.upgrade_need_cost,
proportion: proportion,
reach: moment(data.vip_reach_time * 1000).format('YYYY-MM-DD'),
start: moment(data.vip_start_time * 1000).format('YYYY-MM-DD'),
end: moment(data.vip_end_time * 1000).format('YYYY-MM-DD'),
remainDays: remainDays,
platinum: data.upgrade_need_cost > 0 ? false : true,
isVip: data.current_vip_level > 0 ? true : false
};
res.render('vip', vip);
let uid = req.user.uid;
})().catch(next);
vipModel.vipIndex(uid).then(result => {
res.render('vip', result);
}).catch(next);
};
module.exports = {
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const UserData = require('./UserData');
const helpers = global.yoho.helpers;
const UNUSED = 'notuse';
const USED = 'use';
const INVALID = 'overtime';
const getCouponsList = (uid, type, page, limit)=>{
return co(function*() {
let couponsInfo = yield UserData.getCouponsList(uid, type, page, limit);
let result = [];
if (!couponsInfo.data.couponList) {
return result;
}
let coupons = couponsInfo.data.couponList;
if (coupons) {
coupons.forEach(function(item, i) {
result[i] = {};
result[i].id = item.couponId;
result[i].code = item.couponCode;
// 格式化有效日期 "couponValidity": "2016.03.15-2016.03.31"
let dates = item.couponValidity.split('-');
result[i].beginTime = dates[0].replace('.', '-');
result[i].endTime = dates[1].replace('.', '-');
if (!item.couponImageUrl) {
result[i].img = '//static.yohobuy.com/images/v2/activity/default_coupon.jpg';
} else {
result[i].img = item.couponImageUrl;
}
if ((item.overTime - Date.now()) < 259200) {
result[i].endSoon = true;
} else {
result[i].endSoon = false;
}
result[i].value = item.couponValue.toFixed(2);
result[i].validity = item.couponValidity;
result[i].useRemark = item.couponDetailInfomation;
if (type === USED) {
result[i].orderNum = item.orderCode ? item.orderCode : '';
result[i].orderDetailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: item.orderCode || ''});
result[i].orderSum = item.orderPrice.toFixed(2) ? item.orderPrice : 0;
result[i].payment = item.actuallyPaid.toFixed(2) ? item.actuallyPaid : 0;
let data = result[i].usedTime ? moment(result[i].usedTime).format('YYYY-MM-DD') : 0;
if (data) {
result[i].useTime = new Date(date).getTime();
} else {
result[i].useTime = '';
}
} else {
result[i].status = item.isValidity ? '可使用' : '已过期';
}
if (item.couponType) {
result[i].type = item.couponType;
if (item.couponType == 5) {
result[i].value = '免邮';
}
}
});
}
return {list: result, pager: {
total: couponsInfo.data.total,
pageTotal: couponsInfo.data.totalPageNum,
page: page
}};
})();
};
module.exports = {
getCouponsList,
UNUSED,
USED,
INVALID
};
... ... @@ -67,6 +67,9 @@
},
{
key: 'areaCode'
},
{
key: 'streets'
}
]
}, {
... ... @@ -143,7 +146,7 @@
let query = {
uid: uid,
address: _.trim(params.address || ''),
area_code: _.trim(params.areaCode || ''),
area_code: _.trim(params.streets || ''),
consignee: _.trim(params.addressName || ''),
email: _.trim(params.email || ''),
id: params.addrId === '0' ? null : params.addrId,
... ... @@ -152,8 +155,11 @@
zip_code: _.trim(params.zipCode || '')
};
let streets = _.trim(params.streets || '');
query.area_code = streets === 'all' ? _.trim(params.areaCode || '') : streets;
if (query.uid === '' || query.address === '' ||
query.area_code === '' || query.consignee === '' ||
query.area_code.length < 6 || query.consignee === '' ||
query.email === '' || query.zip_code === '') {
return {
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const UserData = require('./user-data');
const helpers = global.yoho.helpers;
const path = require('path');
const _ = require('lodash');
const moment = require('moment');
// 使用 product中的分页逻辑
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
const pager = require(pagerPath).handlePagerData;
const UNUSED = 'notuse';
const USED = 'use';
const INVALID = 'overtime';
const getCouponsList = (uid, type, page, limit)=>{
return co(function*() {
let couponsInfo = yield UserData.getCouponsList(uid, type, page, limit);
let result = [],
coupons = _.get(couponsInfo, 'data.couponList');
if (!coupons) {
return {
list: result
};
}
if (coupons) {
coupons.forEach(function(item, i) {
result[i] = {};
result[i].id = item.couponId;
result[i].code = item.couponCode;
// 格式化有效日期 "couponValidity": "2016.03.15-2016.03.31"
let dates = item.couponValidity.split('-');
result[i].beginTime = _.replace(dates[0], /\./g, '-');
result[i].endTime = _.replace(dates[1], /\./g, '-');
if (!item.couponImageUrl) {
result[i].img = '//static.yohobuy.com/images/v2/activity/default_coupon.jpg';
} else {
result[i].img = item.couponImageUrl;
}
// 3天之内即将要过期
if ((item.overTime - Date.now()) < 259200) {
result[i].endSoon = true;
} else {
result[i].endSoon = false;
}
result[i].value = item.couponValue.toFixed(2);
result[i].validity = item.couponValidity;
result[i].useRemark = item.couponDetailInfomation;
if (type === USED) {
result[i].orderNum = _.get(item, 'orderCode', '');
result[i].orderDetailUrl = helpers.urlFormat('/home/orders/detail',
{orderCode: item.orderCode || ''});
result[i].orderSum = _.get(item, 'orderPrice', 0).toFixed(2);
result[i].payment = _.get(item, 'actuallyPaid', 0).toFixed(2);
let date = item.usedTime ? moment(item.usedTime).format('YYYY-MM-DD H:m') : 0;
if (date) {
result[i].useTime = date;
} else {
result[i].useTime = '';
}
} else {
result[i].status = item.isValidity ? '可使用' : '已过期';
}
if (item.couponType) {
result[i].type = item.couponType;
if (Number(item.couponType) === 5) {
result[i].value = '免邮';
}
}
});
}
let pageNum = pager(couponsInfo.data.total, {
page: page,
limit: limit,
type: type
});
return {
list: result,
pager: Object.assign({
count: couponsInfo.data.total || 0,
curPage: page,
totalPages: couponsInfo.data.totalPageNum
}, pageNum)
};
})();
};
const couponsData = (uid, params)=>{
let type = params.type || UNUSED;
let page = params.page || 1;
let limit = params.limit || 10;
return co(function*() {
let coupons = yield getCouponsList(uid, type, page, limit);
let data = {};
if (type === UNUSED) {
data.unUseCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
data.unUse = true;
} else if (type === USED) {
data.usedCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
data.used = true;
} else if (type === INVALID) {
data.noValidCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
data.noValid = true;
}
data.tabs = [
{
active: type === UNUSED ? true : false,
url: helpers.urlFormat('/home/coupons', {type: UNUSED}),
name: '未使用优惠券'
},
{
active: type === USED ? true : false,
url: helpers.urlFormat('/home/coupons', {type: USED}),
name: '已使用优惠券'
},
{
active: type === INVALID ? true : false,
url: helpers.urlFormat('/home/coupons', {type: INVALID}),
name: '已失效优惠券'
}
];
data.pager = coupons.pager;
return data;
})();
};
module.exports = {
couponsData
};
... ...
... ... @@ -2,8 +2,6 @@
* @author: weiqingting<qingting.wei@yoho.cn>
*/
'use strict';
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const yohoCoinList = (uid, condition)=>{
... ... @@ -14,6 +12,7 @@ const yohoCoinList = (uid, condition)=>{
page: 1,
limit: 15
};
Object.assign(options, condition);
return api.get('', options);
};
... ... @@ -23,10 +22,22 @@ const yohoCoinTotal = uid=>{
method: 'app.yoho.yohocoin',
uid: uid
};
return api.get('', options);
};
const getProduct = (skn, limit)=>{
let options = {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
};
return api.get('', options);
};
module.exports = {
yohoCoinList,
yohoCoinTotal
yohoCoinTotal,
getProduct
};
... ...
... ... @@ -8,11 +8,8 @@ const co = Promise.coroutine;
const path = require('path');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const _ = require('lodash');
const Image = require('../../../utils/images');
const CurrencyData = require('./CurrencyData');
const SearchData = require('./SearchData');
const currencyApi = require('./currency-data');
// 使用 product中的分页逻辑
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
... ... @@ -24,109 +21,132 @@ const convertUnitTime = (src) => {
return moment.unix(src).format('YYYY-MM-DD');
};
const currencyData = (uid, condition)=>{
return co(function*() {
let result = {};
let yohoCoinInfo = yield CurrencyData.yohoCoinTotal(uid);
console.log(yohoCoinInfo);
if (yohoCoinInfo.code && yohoCoinInfo.code == 200) {
let yohoCoinInfoData = yohoCoinInfo.data;
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
if (yohoCoinInfoData.nearExpCoinNum && yohoCoinInfoData.nearExpCoinNum > 0) {
result.tip.count = yohoCoinInfoData.nearExpCoinNum;
result.tip.date = 'Y年12月31日';
}
const currencyTabs = (type)=>{
let tabs = ['全部明细', '全部收入', '全部支出'],
result = [];
tabs.forEach(function(val, key) {
result.push({
active: key === parseInt(type, 10) ? true : false,
url: helpers.urlFormat('/home/currency', {type: key}),
name: val
});
});
return result;
};
const currencyOptions = (condition)=>{
let result = [], paramUrl = {};
let tabs = {90: '最近3个月明细', 180: '最近半年明细', 360: '最近一年明细'};
for (let name in tabs) {
if (condition.queryType) {
paramUrl.type = condition.queryType;
}
let currency = yield currencyList(uid, condition);
result.currency = currency.list;
result.pager = currency.pager;
result.coinHelperUrl = '//www.yohobuy.com/help/detail?id=105';// yoho币帮助
result.tabs = currencyTabs(condition.queryType);
result.options = currencyOptions(condition);
return result;
})();
paramUrl.beginTime = convertUnitTime(new Date() / 1000 - parseInt(name, 10) * 3600 * 24);
result.push({
url: helpers.urlFormat('/home/currency', paramUrl),
name: tabs[name],
selected: condition.beginTime && paramUrl.beginTime === condition.beginTime ? true : false
});
}
return result;
};
const currencyList = (uid, condition)=>{
return co(function*() {
let result = {'list': [], 'pager': []};
let result = {list: [], pager: []};
condition.limit = condition.limit || 15;
let data = yield CurrencyData.yohoCoinList(uid, condition);
let data = yield currencyApi.yohoCoinList(uid, condition);
if (_.get(data, 'code') === 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
if (data.code && data.code == 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
// data.data.coinlist.forEach(function(val,key){
for (let key = 0; key < data.data.coinlist.length; key++) {
let val = data.data.coinlist[key];
result.list[key] = {
date: val['date'],
desc: val['message'],
date: val.date,
desc: val.message,
isIncome: true
};
// 2:订单取消退还,9:下单使用,10:退货退还
if ([2, 9, 10].indexOf(val.type) > -1 && val.key) {
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val['key']});
}
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val.key});
} else if (Number(val.type) === 14 && val.key) { // 晒单奖励
let product = yield currencyApi.getProduct(Number(val.key), 1);
if (_.get(product, 'code') === 200 &&
!_.isEmpty(product.data.product_list) &&
!_.isEmpty(product.data.product_list[0].goods_list)) {
let productId = _.get(product, 'data.product_list[0].product_id');
let goodsId = _.get(product, 'data.product_list[0].goods_list[0].goods_id');
let alphabet = _.get(product, 'data.product_list[0].cn_alphabet');
// 晒单奖励
else if (val.type == 14 && val.key) {
let product = yield SearchData.searchAll({query: Number(val.key), viewNum: 1});
if (product.code && product.code == 200 && !_.isEmpty(product.data.product_list) && !_.isEmpty(product.data.product_list[0].goods_list)) {
productId = product.data.product_list[0].product_id;
goodsId = product.data.product_list[0].goods_list[0].goods_id;
result.list[key].detailUrl = helpers.getUrlBySkc(productId, goodsId, product.data.product_list[0].cn_alphabet);
result.list[key].detailUrl = helpers.getUrlBySkc(productId, goodsId, alphabet);
}
}
if (Number(val['num']) < 0) {
if (Number(val.num) < 0) {
result.list[key].isIncome = false;
}
result.list[key].value = val['num'] > 0 ? '+' + val['num'] : val['num'];
result.list[key].value = val.num > 0 ? '+' + val.num : val.num;
}
// 分页
let total = data.data.total;
let pagerObj = pager(total, {
page: data['data']['page'],
limit: condition['limit']
});
// result['pager']={};
// result['pager']['hasCheckAll'] = false;
// result['pager']['count'] = data['data']['total'];
// result['pager']['curPage'] = data['data']['page'];
// result['pager']['totalPages'] = Math.ceil(data['data']['total'] / condition['limit']);
// result['pager']['pagerHtml'] = HelperSearch::pager(data['data']['total'], condition['limit']);
result.pager = Object.assign({
count: data.data.total,
curPage: data.data.page,
totalPages: Math.ceil(data.data.total / condition.limit)
}, pager(data.data.total, {
page: condition.page,
limit: condition.limit,
type: condition.queryType,
beginTime: condition.beginTime
}));
}
return result;
})();
};
const currencyTabs = (type)=>{
let result = ['全部明细', '全部收入', '全部支出'];
result = result.forEach(function(val, key) {
return {
active: key == type ? true : false,
url: helpers.urlFormat('/home/currency', {type: key})
};
});
return result;
};
const currencyOptions = (condition)=>{
let result = [], paramUrl = {};
let tabs = {'90': '最近3个月明细', '180': '最近半年明细', '360': '最近一年明细'};
for (let name in tabs) {
if (condition.queryType) {
paramUrl.type = condition.queryType;
const currencyData = (uid, prama)=>{
let condition = {
page: prama.page || 1,
queryType: prama.type || 0,
beginTime: prama.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90)
};
return co(function*() {
let result = {};
let yohoCoinInfo = yield currencyApi.yohoCoinTotal(uid);
if (_.get(yohoCoinInfo, 'code') === 200) {
let yohoCoinInfoData = yohoCoinInfo.data;
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
if (_.get(yohoCoinInfoData, 'nearExpCoinNum') > 0) {
result.tip = {
count: yohoCoinInfoData.nearExpCoinNum,
date: new Date().getFullYear() + '年12月31日'
};
}
}
paramUrl.beginTime = convertUnitTime(new Date() / 1000 - 3600 * 24);
result.push({
url: helpers.urlFormat('/home/currency', paramUrl),
name: tabs[name],
selected: condition.beginTime && paramUrl.beginTime == condition.beginTime ? true : false
let currency = yield currencyList(uid, condition);
Object.assign(result, {
currency: currency.list,
pager: currency.pager,
coinHelperUrl: '//www.yohobuy.com/help/detail?id=105', // yoho币帮助
tabs: currencyTabs(condition.queryType),
options: currencyOptions(condition)
});
}
return result;
return result;
})();
};
module.exports = {
... ...
/**
* 个人中心---兑换礼品卡
* @author gaohongwei <hongwei.gao@yoho.cn>
* @date: 2016/9/7
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const userApi = require('./user-api');
const currencyApi = require('./currency-data');
/**
* 礼品卡页面
*/
exports.index = (params, uid) => {
return co(function*() {
let respData = {},
type = params.type || '',
yohoCoinResult;
if (type !== '') {
yohoCoinResult = yield currencyApi.yohoCoinTotal(uid);
let yohoCoinInfo = yohoCoinResult.data;
if (yohoCoinInfo) {
respData.gift = {
resultInfo: {
success: (Number(type) === 1) ? true : false,
yohoCoin: yohoCoinInfo.yohocoin_num ? yohoCoinInfo.yohocoin_num : 0
}
};
}
} else {
respData.gift = {
resultInfo: false
};
}
return respData;
})();
};
/**
* 个人中心-兑换礼品卡提交返回信息
*/
exports.exchange = (req, params, uid) => {
return co(function*() {
let data = {};
data.giftCardCode1 = _.trim(params.giftCardCode1 || '');
data.giftCardCode2 = _.trim(params.giftCardCode2 || '');
data.giftCardCode3 = _.trim(params.giftCardCode3 || '');
data.captchaCode = _.trim(params.verifyCode || '').toLowerCase();
if (data.captchaCode && data.captchaCode !== req.session.captcha) {
return {
code: 400,
message: '图形验证码不正确'
};
}
let respData = yield userApi.exchangeGift(data, uid);
return respData;
})();
};
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const RedenvelopesData = require('./RedenvelopesData.js');
const _ = require('lodash');
const redenvelopesData = require('./redenvelopes-data.js');
const redenvelopesList = uid=>{
return co(function*() {
let result = {};
let data = yield RedenvelopesData.getRedenvelopesTotal(uid);
if (data.code && data.code == 200 && data.data.redpacket_num) {
result.money = data.data.redpacket_num;
result.termOfValidity = data.data.useable_time;
let data = yield redenvelopesData.getRedenvelopesTotal(uid);
if (_.get(data, 'code') === 200 && _.get(data, 'data.redpacket_num')) {
result.money = _.get(data, 'data.redpacket_num');
result.termOfValidity = _.get(data, 'data.useable_time');
}
result.useRemark = '1.红包活动,全场通用(预售商品除外);<br>2.结算时折抵现金使用,可以和优惠券叠加使用;<br>3.限有效期内使用,过期清零';
return [result];
result.useRemark = '1.红包活动,全场通用(预售商品除外);<br>' +
'2.结算时折抵现金使用,可以和优惠券叠加使用;<br>' +
'3.限有效期内使用,过期清零';
return {redEnvelopes: [result]};
})();
};
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const userData = require('./user-data');
const moment = require('moment');
const helpers = global.yoho.helpers;
const vipIndex = (uid)=>{
return co(function*() {
let vipInfo = yield userData.getVIPInfoByUid(uid);
let data = vipInfo.data, proportion = '0%';
if (+data.next_need_cost !== 0) {
proportion = data.current_year_cost * 100 / data.next_need_cost;
proportion = proportion > 100 ? 100 : proportion;
proportion = proportion + '%';
}
let remainDays = Math.ceil(((data.vip_end_time) * 1000 - Date.now()) / 86400000);
let preferences = [];
if (data.enjoy_preferential) {
preferences = data.enjoy_preferential.map(function(item) {
return {
id: item.id,
favTxt: item.title,
imgType: helpers.https(item.pic),
description: item.description
};
});
}
let isVip = data.current_vip_level > 0 ? true : false;
let vip = {
title: data.current_vip_title,
nextTitle: data.next_vip_title,
nextLevel: data.next_vip_level,
yearCost: Number(data.current_year_cost).toFixed(2),
totalCost: (+data.current_total_cost).toFixed(2),
list: preferences,
level: data.current_vip_level,
platinum: data.upgrade_need_cost > 0 ? false : true,
nextCost: Number(data.next_need_cost).toFixed(2),
balan: Number(data.upgrade_need_cost).toFixed(2),
proportion: proportion,
vipLevel: data.next_vip_title,
reach: moment(data.vip_reach_time * 1000).format('YYYY.MM.DD'),
valid: moment(data.vip_start_time * 1000).format('YYYY.MM.DD'),
end: moment(data.vip_end_time * 1000).format('YYYY.MM.DD'),
remainDays: remainDays,
doubtLevel: isVip,
commonVip: !isVip,
morePreferences: helpers.urlFormat('/help', {category_id: 91})
};
return vip;
})();
};
module.exports = {
vipIndex
};
... ...
... ... @@ -21,12 +21,15 @@ const commentController = require(`${cRoot}/comment`);
const messageController = require(`${cRoot}/message`);
// const returnsController = require(`${cRoot}/returns`);
// const CurrencyController = require(`${cRoot}/Currency`);
// const IndexController = require(`${cRoot}/index`);
const currencyController = require(`${cRoot}/currency`);
const personalController = require(`${cRoot}/qrcode`);
// const RedenvelopesController = require(`${cRoot}/Redenvelopes`);
// const VipController = require(`${cRoot}/vip`);
// const CouponsController = require(`${cRoot}/coupons`);
const redenvelopesController = require(`${cRoot}/redenvelopes`);
const vipController = require(`${cRoot}/vip`);
// const FavoriteController = require(`${cRoot}/favorite`);
const couponsController = require(`${cRoot}/coupons`);
const UserController = require(`${cRoot}/user`);
const bindController = require(`${cRoot}/3party-bind`);
... ... @@ -35,8 +38,9 @@ const AccountController = require(`${cRoot}/account`);
const favoriteController = require(`${cRoot}/favorite`);
const ordersController = require(`${cRoot}/orders`);
// const AddressController = require(`${cRoot}/address`);
// const GiftController = require(`${cRoot}/gift`);
const AddressController = require(`${cRoot}/address`);
const giftController = require(`${cRoot}/gift`);
const homeNav = (req) => {
return [
... ... @@ -227,19 +231,19 @@ router.get('/message/pickCoupon', messageController.pickCoupon);
// router.get('/exchange/detail', returnsController.refundDetail);
// router.get('/returns/success', returnsController.index);
// // 地址管理
// router.get('address', addressController.index);
// router.get('address/area', addressController.area);
// router.get('/index', [getCommonHeader, getHomeNav], IndexController.index);
// router.get('/currency', CurrencyController.index);
/* 我的YOHO币 */
router.get('/currency', [getCommonHeader, getHomeNav], currencyController.index);
/* 我的红包*/
// router.get('/redenvelopes', RedenvelopesController.index);
/* 我的红包 */
router.get('/redenvelopes', [getCommonHeader, getHomeNav], redenvelopesController.index);
/* 我的VIP*/
/* 我的VIP */
router.get('/vip', [getCommonHeader, getHomeNav], vipController.index);
/* 我的优惠卷 */
router.get('/coupons', [getCommonHeader, getHomeNav], couponsController.index);
// router.get('/vip', VipController.index);
/********************************* 我的收藏开始 *****************************************/
... ... @@ -335,22 +339,7 @@ router.get('/bind/renren/callback', bindController.renren.callback);
router.post('/cancelbind/:type', bindController.cancelBind);
//
// router.get('/address/area', UserController.getProviceList);
//
// router.get('/account', [getCommonHeader, getHomeNav], AccountController.index);
//
// router.get('/account/userpwd', [getCommonHeader, getHomeNav], AccountController.userPwd);
//
// router.get('/account/email', [getCommonHeader, getHomeNav], AccountController.userEmail);
//
// router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.userMobile);
//
// router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode);
//
// router.post('/account/checkpassword', [getCommonHeader, getHomeNav], AccountController.checkPassword);
//
// 账号安全
router.get('/account', [getCommonHeader, getHomeNav], AccountController.index);
router.get('/account/userpwd', [getCommonHeader, getHomeNav], AccountController.userPwd);
... ... @@ -385,19 +374,24 @@ router.post('/account/sendmobilemsg', AccountController.sendMobileMsg);
router.post('/account/modifymobile', AccountController.modifyMobile);
//
// router.get('/address', [getCommonHeader, getHomeNav], AddressController.index);
//
// router.get('/address/editAddress', AddressController.editAddress);
//
// router.post('/address/saveAddress', AddressController.saveAddress);
//
// router.get('/address/delAddress', AddressController.delAddress);
//
// router.get('/address/defaultAddress', AddressController.defaultAddress);
//
// router.get('/gift', [getCommonHeader, getHomeNav], GiftController.index);
//
// router.post('/gift/exchange', GiftController.exchange);
// 地址管理
router.get('/address', [getCommonHeader, getHomeNav], AddressController.index);
router.get('/address/area', UserController.getProviceList);
router.get('/address/editAddress', AddressController.editAddress);
router.post('/address/saveAddress', AddressController.saveAddress);
router.get('/address/delAddress', AddressController.delAddress);
router.get('/address/defaultAddress', AddressController.defaultAddress);
// 兑换礼品卡
router.get('/gift', [getCommonHeader, getHomeNav], giftController.index);
router.post('/gift/exchange', giftController.exchange);
module.exports = router;
... ...
<div class="me-coupons-page me-page yoho-page clearfix">
{{> path}}
{{> navigation}}
<div class="me-main">
<div class="coupons{{#if unUse}} un-use-coupons{{/if}}{{#if used}} used-coupons{{/if}}{{#if noValid}} no-valid-coupons{{/if}} block">
<h2 class="title">优惠券</h2>
... ... @@ -121,7 +117,6 @@
{{/unless}}
{{/if}}
</div>
{{> help-us}}
</div>
</div>
... ...
<div class="me-currency-page me-page yoho-page clearfix">
{{> path}}
{{> navigation}}
<div class="me-main">
{{# content}}
<div class="currencies block">
... ... @@ -49,12 +47,9 @@
</li>
{{/ currency}}
</ul>
{{#with ../pager}}
{{> common/foot-pager footPager=this}}
{{/with}}
{{> pager}}
</div>
{{/ content}}
{{> help-us}}
</div>
</div>
... ...
{{> layout/header}}
<div class="user-me-page me-page yoho-page clearfix">
{{> path}}
{{> navigation}}
{{# gift}}
{{> path}}
{{> navigation}}
<div class="me-main">
<div class="gift block">
<div class="title">
... ... @@ -32,12 +31,9 @@
<span class="gift-error"></span>
</li>
<li class="captchaCode">
请输入验证码:
<input type="text" value="" name="verifyCode" id="captchaCode" class="gift-input" />
<img src="" id="imgcode"/>
看不清楚?
<a href="#" class="check-img">换一张</a>
<span class="gift-error"></span>
<!--<input type="text" value="" name="verifyCode" id="captchaCode" class="gift-input" />-->
<div class="captcha-img" ></div>
<!--<span class="gift-error"></span>-->
</li>
<li>
<input type="button" class="btn-b1" id="sub-gift" value="确认兑换"/>
... ... @@ -48,7 +44,4 @@
</div>
</div>
{{/ gift}}
{{> help-us}}
</div>
{{> layout/footer}}
... ...
{{> layout/header}}
<div class="user-me-page me-page yoho-page clearfix">
{{> path}}
{{> navigation}}
{{# address}}
{{> path}}
{{> navigation}}
<div class="me-main">
<div class="address block">
<div class="title">
... ... @@ -85,7 +85,4 @@
</div>
</div>
{{/ address}}
{{> help-us}}
</div>
{{> layout/footer}}
... ...
<div class="red-envelopes-page me-page yoho-page clearfix">
{{> path}}
{{> navigation}}
{{# meRedEnvelopes}}
{{> path}}
{{> navigation}}
<div class="me-main">
<div class="red-envelopes block">
<h2 class="title">我的红包</h2>
... ... @@ -31,8 +29,6 @@
{{/each}}
</ul>
</div>
{{> help-us}}
</div>
{{/ meRedEnvelopes}}
</div>
... ...
... ... @@ -98,6 +98,5 @@
</div>
</div>
{{> help-us}}
</div>
</div>
... ...
... ... @@ -14,7 +14,7 @@ const cachePage = {
'/lifestyle/': 30 * SECOND,
// 商品详情页
//'/product/\\/pro_([\\d]+)_([\\d]+)\\/(.*)/': 30 * MINUTE,
// '/product/\\/pro_([\\d]+)_([\\d]+)\\/(.*)/': 30 * MINUTE,
'/product/\\/p([\\d]+)(.*)/': 30 * MINUTE,
// 逛
... ...
... ... @@ -36,6 +36,7 @@ var address = {
$('#province').val(0);
$('#city').val(0);
$('#areaCode').val(0).hide();
$('#streets').val(0).hide();
$('#btn-reset').hide();
$('#form-status').html('添加新地址');
},
... ... @@ -96,7 +97,7 @@ var address = {
oldLi.removeClass('preferred');
oldBtn.html('<span>设为常用地址</span>');
curBtn.attr('class', 'btn-c2 default-btn');
oldBtn.html('<span>设为常用地址</span>');
curBtn.html('<span>已设为常用地址</span>');
curLi.addClass('preferred');
} else {
active = new Alert('设置失败');
... ... @@ -221,13 +222,9 @@ function blurAction(opt) {
}
if (opt.inputName === 'mobile') {
regular = /^1[3|4|5|8|7][0-9]{9}$/;
regular = /^[0-9]{1,}$/;
if (opt.len !== 11) {
msg = '手机号码必须是11位的,请确认';
res = false;
domClass = 'form-info form-error';
} else if (regular.test(opt.val) === false) {
if (regular.test(opt.val) === false) {
msg = '您输入的手机号格式不正确';
res = false;
domClass = 'form-info form-error';
... ... @@ -353,8 +350,10 @@ $(document).ready(function() {
{
provinceDomId: 'province',
cityDomId: 'city',
areaDomId: 'areaCode'
}
areaDomId: 'areaCode',
streetsDomId: 'streets'
},
true
);
address.clearAddrForm();
... ...
... ... @@ -19,6 +19,9 @@ var address = {
// 地区的控件ID
areaDomId: 'areaCode',
// 乡镇、街道的控件ID
streetsDomId: 'streetsCode',
initDomIds: function(domOptions) {
var the = this;
... ... @@ -31,10 +34,13 @@ var address = {
if (domOptions.areaDomId !== undefined) {
the.areaDomId = domOptions.areaDomId;
}
if (domOptions.streetsDomId !== undefined) {
the.streetsDomId = domOptions.streetsDomId;
}
},
// 初始化地址数据
loadAreaData: function(pCode, toDomId, defaultValue, allCode) {
loadAreaData: function(pCode, toDomId, defaultValue, allCode, isAll) {
var the = this,
$toDom = $('#' + toDomId),
i = 0,
... ... @@ -43,7 +49,8 @@ var address = {
var active,
val,
nId,
selecter;
selecter,
selectAll;
$toDom.empty();
... ... @@ -67,10 +74,15 @@ var address = {
}
$toDom.append('<option value="0">' + defaultValue + '</option>');
if (toDomId === the.streetsDomId) {
allCode.length === 6 && isAll ? selectAll = 'selected' : selectAll = '';
$toDom.append('<option value="all"' + selectAll +'>*全部</option>');
}
for (i in jsonData.options) {
if (jsonData.options[i]) {
val = jsonData.options[i];
point = (toDomId === the.areaDomId && val.is_support === 'Y') ? '*' : '';
point = (toDomId === the.streetsDomId && val.is_support === 'Y') ? '*' : '';
nId = val.value;
selecter = '';
... ... @@ -101,6 +113,7 @@ var address = {
the.loadAreaData(pCode, the.cityDomId, '请选择城市', pCode);
$('#' + the.areaDomId).hide();
$('#' + the.streetsDomId).hide().empty();
the.showAreaSel(domOptions.dispDomId);
});
... ... @@ -113,10 +126,19 @@ var address = {
the.loadAreaData(pCode, the.areaDomId, '请选择区县', pCode);
$('#' + the.areaDomId).show();
$('#' + the.streetsDomId).hide().empty();
the.showAreaSel(domOptions.dispDomId);
});
$('#' + the.areaDomId).change(function() {
var pCode = $('#' + the.areaDomId).val();
if (pCode === '0') {
return;
}
the.loadAreaData(pCode, the.streetsDomId, '请选择乡镇/街道', pCode);
$('#' + the.streetsDomId).show();
the.showAreaSel(domOptions.dispDomId);
});
... ... @@ -149,12 +171,12 @@ var address = {
}
},
loadAllData: function(areaCode, domOptions) {
var the = this;
loadAllData: function(areaCode, domOptions, isInit) {
var the = this,
isAll = isInit ? false : true;
the.initDomIds(domOptions);
areaCode += '';
if (areaCode < 91) {
the.loadAreaData(0, the.provinceDomId, '请选择省份', '');
$('#' + the.areaDomId).hide();
... ... @@ -168,9 +190,21 @@ var address = {
the.loadAreaData(0, the.provinceDomId, '请选择省份', areaCode);
the.loadAreaData(areaCode.substr(0, 2), the.cityDomId, '请选择城市', areaCode);
the.loadAreaData(areaCode.substr(0, 4), the.areaDomId, '请选择区县', areaCode);
the.loadAreaData(areaCode.substr(0, 6), the.streetsDomId, '请选择乡镇/街道', areaCode, isAll);
$('#' + this.areaDomId).show();
$('#' + this.streetsDomId).show();
} else if (areaCode.length === 9) {
the.loadAreaData(0, the.provinceDomId, '请选择省份', areaCode);
the.loadAreaData(areaCode.substr(0, 2), the.cityDomId, '请选择城市', areaCode);
the.loadAreaData(areaCode.substr(0, 4), the.areaDomId, '请选择区县', areaCode);
the.loadAreaData(areaCode.substr(0, 6), the.streetsDomId, '请选择乡镇/街道', areaCode);
$('#' + this.areaDomId).show();
$('#' + this.streetsDomId).show();
}
if (isInit) {
the.bindAreaChange(domOptions);
}
the.bindAreaChange(domOptions);
}
};
... ...
/**
* 个人中心页-兑换礼品卡
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/02/22
*/
var $ = require('yoho-jquery'),
Captcha = require('../plugins/captcha');
var dialog = require('../common/dialog');
var Alert = dialog.Alert;
var $giftError = $('.giftCardCode').find('.gift-error'),
reg = /^[0-9a-zA-Z]{4,4}$/,
code = '',
i = 1;
var active;
var Gift = {
suc: [
false,
false,
false,
false
],
checkCard: function(num) {
if (!reg.test($('#giftCardCode' + num).val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
Gift.suc[num - 1] = false;
} else {
for (i = 1; i <= 3; i++) {
if (!reg.test($('#giftCardCode' + i).val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
Gift.suc[i] = false;
} else {
$giftError.html('');
Gift.suc[i] = true;
}
}
if (num !== 3) {
$('#giftCardCode' + (num + 1)).focus();
}
}
},
bindGiftCardForm: function() {
$('#giftCardCode1').bind('blur keyup', function() {
Gift.checkCard(1);
});
$('#giftCardCode2').bind('blur keyup', function() {
Gift.checkCard(2);
});
$('#giftCardCode3').bind('blur keyup', function() {
Gift.checkCard(3);
});
},
checkForm: function() {
if (!reg.test($('#giftCardCode1').val()) || !reg.test($('#giftCardCode2').val()) ||
!reg.test($('#giftCardCode3').val())) {
$giftError.html('您输入的兑换码有误,兑换码必须为数字或字母,每个文本框里只能输入四个兑换码!');
return $.Deferred().reject().promise();
}
return captcha.check();
}
};
var captcha = new Captcha('.captcha-img').init();
captcha.refresh();
require('../common');
// 更换验证码
function refreshCaptcha() {
var dt = new Date();
$('#imgcode').attr('src', '/passport/imagesNode?t=' + dt.getTime());
return false;
}
$('#sub-gift').on('click', function() {
Gift.checkForm().then(function () {
$.post('/home/gift/exchange', $('#giftCardForm').serialize(), function(data) {
if (data.code === 200) {
window.location.href = '/home/gift?type=1';
} else if (data.code === 400) {
active = new Alert(data.message);
active.show();
refreshCaptcha();
} else {
window.location.href = '/home/gift?type=2';
}
}, 'json');
})
});
$(document).on('click', '#imgcode,.check-img', function() {
refreshCaptcha();
});
$(function() {
refreshCaptcha();
Gift.bindGiftCardForm();
});
... ...
/**
* Created by DELL on 2017.2.10.
*/
require('../common');
... ...
/**
* Created by DELL on 2017.2.10.
*/
require('../common');
... ...
... ... @@ -566,6 +566,15 @@
cursor: pointer;
}
.captcha-img {
display: inline-block;
position: relative;
.img-check-tip {
top: 120px;
}
}
.check-img {
color: #468fa2;
text-decoration: underline;
... ... @@ -635,7 +644,12 @@
}
.form-group {
width: 130%;
width: 100%;
}
.form-group {
height: auto;
padding: 4px 0;
}
.add-address-detail {
... ...