Authored by weiqingting

yoho币

'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
}
... ...
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const index=(req, res, next)=>{
}
... ...
... ... @@ -14,7 +14,7 @@ const index = (req, res, next)=>{
co(function * () {
let pall = yield Promise.all([OrderData.closeReasons(), IndexModel.getInfoNumData($uid, $udid), IndexModel.getFooterBanner(), IndexModel.latestOrders($uid), IndexModel.homeData()]);
let $cancelReason = pall[0].data ? pall[0].data : '';
res.render('home/index/index', {
res.render('index', {
cancelReason: $cancelReason,
content: [
{messages: pall[1]},
... ...
'use strict';
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const yohoCoinList=($uid, $condition)=>{
$condition=$condition||{};
let options = {
method: 'app.yohocoin.lists',
uid: $uid,
page: 1,
limit: 15
};
Object.assign(options,$condition);
return api.get('', options);
}
const yohoCoinTotal=uid=>{
let options = {
method: 'app.yoho.yohocoin',
uid: uid
};
return api.get('', options);
}
module.exports = {
yohoCoinList,
yohoCoinTotal
};
... ...
'use strict';
const Promise = require('bluebird');
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');
// 使用 product中的分页逻辑
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
const pager = require(pagerPath).handlePagerData;
const moment = require('moment');
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日';
}
}
let $currency =yield currencyList($uid, $condition);
$result.currency = $currency.list;
$result.pager = $currency.pager;
$result.coinHelperUrl = '//www.yohobuy.com/help/?category_id=87';//yoho币帮助
$result.tabs = currencyTabs($condition.queryType);
$result.options = currencyOptions($condition);
return $result;
})();
}
const currencyList=($uid,$condition)=>{
return co(function*(){
let $result={'list':[], 'pager':[]};
$condition.limit=$condition.limit||15;
let $data = yield CurrencyData.yohoCoinList($uid, $condition);
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'],
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']});
}
//晒单奖励
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);
}
}
if (Number($val['num']) < 0) {
$result.list[$key].isIncome = false;
}
$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']);
}
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;
}
$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
});
}
return $result;
}
module.exports = {
currencyData
};
... ...
'use strict';
const querystring = require('querystring');
const searchApi=global.yoho.SearchAPI;
const getUrl = ($type)=>{
... ... @@ -62,11 +64,16 @@ const getProductUrl = ($condition, $type)=>{
if (!$condition) {
$param += $condition;
}
console.log(JSON.stringify($param));
return getUrl($type) + '?' + querystring.stringify($param);// searchApi.get(getUrl($type), $param,{cache:true});
};
const searchAll = ($param)=>{
$param=$param||{};
return searchApi.get(getUrl($type), $param,{cache:true});
}
module.exports = {
getProductUrl,
getBrandListUrl
getBrandListUrl,
searchAll
};
... ...
... ... @@ -91,7 +91,7 @@ const sessionEffective = (req, res, next) => {
// 查看二维码
router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode);
let Index = require(`${cRoot}/Index`);
// 我的评论
router.get('/comment', commentController.index);
... ... @@ -107,6 +107,10 @@ router.get('/returns', returnsController.index);
// router.get('address', addressController.index);
// router.get('address/area', addressController.area);
let Index = require(`${cRoot}/Index`);
router.get('/index', [getCommonHeader, getHomeNav], Index.index);
let Currency = require(`${cRoot}/Currency`);
router.get('/currency', Currency.index);
module.exports = router;
... ...
... ... @@ -50,7 +50,9 @@
{{/ currency}}
</ul>
{{> pager}}
{{#with ../pager}}
{{> common/foot-pager footPager=this}}
{{/with}}
</div>
{{/ content}}
{{> help-us}}
... ...
{{> layout/header}}
<div class="me-currency-page me-page yoho-page clearfix">
{{# meCurrency}}
{{> path}}
{{> navigation}}
<div class="me-main">
<div class="currencies block">
<h2 class="title"></h2>
<h1 class="my-currency">目前可用YOHO币:<em>{{myCurrency}}</em></h1>
<div class="tab-wrap">
{{> tabs}}
<div class="options-helper">
<select class="filter-select">
{{# options}}
<option value="{{url}}">{{name}}</option>
{{/ options}}
</select>
<a class="coin-helper" href="{{coinHelperUrl}}">[ 什么是YOHO币?]</a>
</div>
</div>
<p class="currency-header clearfix">
<span class="date">日期</span>
<span class="income-expenditure">收入/支出</span>
<span class="remark">详细说明</span>
</p>
<ul class="currency">
{{# currency}}
<li>
<span class="date">{{date}}</span>
<span class="income-expenditure{{#if isIncome}} income{{/if}}">
{{#if isIncome}}
+
{{^}}
-
{{/if}}
{{value}}
</span>
<p class="remark">
{{desc}}
{{#if detailUrl}}
<a href="{{detailUrl}}">查看详情</a>
{{/if}}
</p>
</li>
{{/ currency}}
</ul>
{{> pager}}
</div>
{{> help-us}}
</div>
{{/ meCurrency}}
</div>
... ... @@ -4,7 +4,7 @@
* @date: 2016/3/22
*/
var $ = require('yoho.jquery');
var $ = require('yoho-jquery');
$('.filter-select').change(function() {
location.href = $(this).val();
... ...
... ... @@ -2,7 +2,7 @@
font-size: 12px;
.currencies > .title {
background-image: resolve(/home/currency.png);
background-image: resolve(img/home/currency.png);
}
.my-currency {
... ... @@ -144,4 +144,4 @@
color: #e10049;
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -256,11 +256,10 @@
@import "comment";
@import "consult";
@import "returns";
@import "currency";
/*
@import "red-envelopes";
@import "coupons";
@import "currency";
@import "favorite";
@import "user-info";
@import "returns-detail";
... ...