Authored by zhangxiaoru

yohocoin

/**
* 个人中心我的有货币
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/08/16
*/
'use strict';
const myCurrencyModel = require('../models/myCurrency');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const myCurrency = (req, res, next) => {
let uid = req.user.uid || 8039759;
myCurrencyModel.myCurrency(uid).then(result => {
res.render('currency-new', {
module: 'home',
page: 'currency',
pageHeader: headerModel.setNav({
navTitle: '有货币'
}),
title: '有货币',
pageFooter: true,
yohoCoin: result
});
}).catch(next);
};
const currencyDetail = (req, res, next) => {
let uid = req.user.uid || 8039759;
let page = 1;
let limit = 10;
myCurrencyModel.currencyDetail(uid, page, limit).then(result => {
res.render('currency-detail', {
module: 'home',
page: 'currency-detail',
pageHeader: headerModel.setNav({
navTitle: '有货币明细'
}),
title: '有货币明细',
pageFooter: true,
money: result.money
});
}).catch(next);
};
let ajaxCurrencyDetail = (req, res, next) => {
let uid = req.user.uid || 8039759;
let page = req.body.page || 1;
let limit = 10;
myCurrencyModel.currencyDetail(uid, page, limit).then((result) => {
res.render('ajax-currency-detail', {
layout: false,
coinlist: result.coinlist
});
}).catch(next);
};
module.exports = {
myCurrency,
currencyDetail,
ajaxCurrencyDetail
};
... ...
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const myCurrency = (uid) => {
return api.get('', {
method: 'app.yoho.yohocoin',
uid: uid
}).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data);
} else {
logger.error('youho币总数 cood 不是 200');
}
});
};
// const banner = (CODE_YOHOCOIN_BANNER) => {
// return api.get('', {
// content_code: 'CODE_YOHOCOIN_BANNER',
// }).then((result) => {
// console.log(content_code)
// if(result && result.code === 200) {
// return camelCase(result.data);
// } else {
// logger.error('youho币总数 cood 不是 200');
// }
// })
// };
const currencyDetail = (uid, page, limit) => {
return api.get('', {
method: 'app.yohocoin.lists',
uid: uid,
page: page,
limit: limit
}).then((result) => {
// console.log(result)
if (result && result.code === 200) {
let total = parseInt(result.data.page_total, 10) + 1;
if (page && page < total) {
return myCurrency(uid).then(list => {
if (list.yohocoinNum && list.yohocoinNum === 0) {
result.data = _.assign(result.data, {
money: false
});
} else {
result.data = _.assign(result.data, {
money: true
});
}
return result.data;
});
} else {
return;
}
} else {
logger.error('youho币列表 cood 不是 200');
}
});
};
module.exports = {
myCurrency,
currencyDetail
};
... ...
... ... @@ -16,6 +16,7 @@ const addressController = require(`${cRoot}/address`);
const favorite = require(`${cRoot}/favorite`);
const orderController = require(`${cRoot}/order`);
const orderDetailController = require(`${cRoot}/orderDetail`);
const currencyController = require(`${cRoot}/myCurrency`);
// const myDetail = require(`${cRoot}/myDetail);
... ... @@ -41,7 +42,10 @@ router.get('/cancelOrder', orderDetailController.cancelOrder); // 取消订单
router.get('/', homeController.index); // 个人中心首页
router.get('/mydetails', homeController.myDetails); // 个人基本资料页面
router.get('/record', homeController.record); // 浏览记录
router.get('/mycurrency', currencyController.myCurrency); // yoho币总数
router.get('/currencyDetail', currencyController.currencyDetail); // yoho币列表
router.post('/ajaxCurrencyDetail', currencyController.ajaxCurrencyDetail); // yoho币列表
// 我的收藏
router.get('/favorite', favorite.favorite);
... ...
{{# coinlist}}
<li>
<div class="detail-item">
<p class="title">{{message}}</p>
<p class="time">{{date}}</p>
<div class="count">
+{{num}}
</div>
</div>
</li>
{{/ coinlist}}
\ No newline at end of file
... ...
<div class="yoho-coin-detail-page yoho-page">
{{#unless money}}
<div class="money">你拥有的有货币:<span>0</span></div>
{{/unless}}
<ul class="coin-detail"></ul>
</div>
\ No newline at end of file
... ...
<div class="yoho-coin-new-page yoho-page">
<div class="coin">
{{# yohoCoin}}
<p class="coin-num">
{{yohocoinNum}}
</p>
<p class="info">
<span class="dollar"></span>
个YOHO币
</p>
<a href="/home/currencyDetail" class="more">查看明细</a>
{{#if notice}}
<div class="coin-tip">
<span class="icon">!</span>
{{notice}}
</div>
{{/if}}
{{/ yohoCoin}}
</div>
<div class="banner">
{{#banner}}
<a href="{{url}}">
<img src="{{img}}" alt="img">
</a>
{{/banner}}
</div>
{{!-- {{> home/maybe_like}} --}}
</div>
\ No newline at end of file
... ...
... ... @@ -567,7 +567,7 @@ let _getRefundExchange = (skn) => {
method: 'app.product.refundExchange',
product_skn: _.toString(skn)
}).then((result) => {
console.log(result)
// console.log(result)
if (result.code === 200) {
let limit;
let productSkn = _.toString(skn);
... ...
var $ = require('yoho-jquery'),
loading = require('../plugin/loading');
var page = 1;
var flag = true;
loading.showLoadingMask();
function ajaxCurrencyDetail(curPage) {
flag = false;
$.ajax({
type: 'post',
url: '/home/ajaxCurrencyDetail',
dataType: 'html',
data: {
page: curPage
},
success: function(data) {
$('.coin-detail').append(data);
flag = true;
}
});
}
function scrollHandler() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100 && flag) {
page++;
ajaxCurrencyDetail(page);
return;
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
ajaxCurrencyDetail(page);
$(document).ready(loading.hideLoadingMask);
... ...