Showing
15 changed files
with
216 additions
and
71 deletions
apps/home/controllers/Currency.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const Promise = require('bluebird'); | ||
4 | +const co = Promise.coroutine; | ||
5 | + | ||
6 | +const CurrencyModel = require('../models/CurrencyModel'); | ||
7 | +const moment = require('moment'); | ||
8 | + | ||
9 | +const convertUnitTime = (src) => { | ||
10 | + return moment.unix(src).format('YYYY-MM-DD'); | ||
11 | +}; | ||
12 | + | ||
13 | +const index=(req, res, next)=>{ | ||
14 | + let $uid='8041246' | ||
15 | + let $condition={ | ||
16 | + page:req.query.page||1, | ||
17 | + queryType:req.query.type||0, | ||
18 | + beginTime:req.query.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90) | ||
19 | + } | ||
20 | + co(function*(){ | ||
21 | + let data=yield CurrencyModel.currencyData($uid, $condition); | ||
22 | + res.render('currency',{ | ||
23 | + content:data | ||
24 | + }); | ||
25 | + })().catch(next) | ||
26 | +} | ||
27 | + | ||
28 | +module.exports={ | ||
29 | + index | ||
30 | +} |
apps/home/controllers/Favorite.js
0 → 100644
@@ -14,7 +14,7 @@ const index = (req, res, next)=>{ | @@ -14,7 +14,7 @@ const index = (req, res, next)=>{ | ||
14 | co(function * () { | 14 | co(function * () { |
15 | let pall = yield Promise.all([OrderData.closeReasons(), IndexModel.getInfoNumData($uid, $udid), IndexModel.getFooterBanner(), IndexModel.latestOrders($uid), IndexModel.homeData()]); | 15 | let pall = yield Promise.all([OrderData.closeReasons(), IndexModel.getInfoNumData($uid, $udid), IndexModel.getFooterBanner(), IndexModel.latestOrders($uid), IndexModel.homeData()]); |
16 | let $cancelReason = pall[0].data ? pall[0].data : ''; | 16 | let $cancelReason = pall[0].data ? pall[0].data : ''; |
17 | - res.render('home/index/index', { | 17 | + res.render('index', { |
18 | cancelReason: $cancelReason, | 18 | cancelReason: $cancelReason, |
19 | content: [ | 19 | content: [ |
20 | {messages: pall[1]}, | 20 | {messages: pall[1]}, |
apps/home/models/CurrencyData.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const helpers = global.yoho.helpers; | ||
4 | +const api = global.yoho.API; | ||
5 | + | ||
6 | +const yohoCoinList=($uid, $condition)=>{ | ||
7 | + $condition=$condition||{}; | ||
8 | + let options = { | ||
9 | + method: 'app.yohocoin.lists', | ||
10 | + uid: $uid, | ||
11 | + page: 1, | ||
12 | + limit: 15 | ||
13 | + }; | ||
14 | + Object.assign(options,$condition); | ||
15 | + return api.get('', options); | ||
16 | +} | ||
17 | + | ||
18 | +const yohoCoinTotal=uid=>{ | ||
19 | + let options = { | ||
20 | + method: 'app.yoho.yohocoin', | ||
21 | + uid: uid | ||
22 | + }; | ||
23 | + return api.get('', options); | ||
24 | +} | ||
25 | + | ||
26 | +module.exports = { | ||
27 | + yohoCoinList, | ||
28 | + yohoCoinTotal | ||
29 | +}; |
apps/home/models/CurrencyModel.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const Promise = require('bluebird'); | ||
4 | +const co = Promise.coroutine; | ||
5 | + | ||
6 | +const path=require('path'); | ||
7 | +const helpers = global.yoho.helpers; | ||
8 | +const api = global.yoho.API; | ||
9 | +const _ = require('lodash'); | ||
10 | +const Image = require('../../../utils/images'); | ||
11 | +const CurrencyData=require('./CurrencyData'); | ||
12 | +const SearchData=require('./SearchData'); | ||
13 | + | ||
14 | +// 使用 product中的分页逻辑 | ||
15 | +const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js'); | ||
16 | +const pager = require(pagerPath).handlePagerData; | ||
17 | + | ||
18 | +const moment = require('moment'); | ||
19 | + | ||
20 | +const convertUnitTime = (src) => { | ||
21 | + return moment.unix(src).format('YYYY-MM-DD'); | ||
22 | +}; | ||
23 | + | ||
24 | +const currencyData=($uid, $condition)=>{ | ||
25 | + return co(function*(){ | ||
26 | + let $result={}; | ||
27 | + let $yohoCoinInfo=yield CurrencyData.yohoCoinTotal($uid); | ||
28 | + console.log($yohoCoinInfo); | ||
29 | + if($yohoCoinInfo.code&& $yohoCoinInfo.code == 200){ | ||
30 | + let $yohoCoinInfoData=$yohoCoinInfo.data; | ||
31 | + $result.myCurrency = $yohoCoinInfoData.yohocoin_num ? $yohoCoinInfoData.yohocoin_num : 0; | ||
32 | + if ($yohoCoinInfoData.nearExpCoinNum && $yohoCoinInfoData.nearExpCoinNum > 0) { | ||
33 | + $result.tip.count =$yohoCoinInfoData.nearExpCoinNum; | ||
34 | + $result.tip.date ='Y年12月31日'; | ||
35 | + } | ||
36 | + } | ||
37 | + let $currency =yield currencyList($uid, $condition); | ||
38 | + $result.currency = $currency.list; | ||
39 | + $result.pager = $currency.pager; | ||
40 | + $result.coinHelperUrl = '//www.yohobuy.com/help/?category_id=87';//yoho币帮助 | ||
41 | + $result.tabs = currencyTabs($condition.queryType); | ||
42 | + $result.options = currencyOptions($condition); | ||
43 | + return $result; | ||
44 | + })(); | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +const currencyList=($uid,$condition)=>{ | ||
49 | + return co(function*(){ | ||
50 | + let $result={'list':[], 'pager':[]}; | ||
51 | + $condition.limit=$condition.limit||15; | ||
52 | + | ||
53 | + let $data = yield CurrencyData.yohoCoinList($uid, $condition); | ||
54 | + | ||
55 | + if ($data.code&& $data.code ==200 && $data.data.coinlist && !_.isEmpty($data.data.coinlist)) { | ||
56 | + // $data.data.coinlist.forEach(function($val,$key){ | ||
57 | + for(let $key=0;$key<$data.data.coinlist.length;$key++){ | ||
58 | + let $val=$data.data.coinlist[$key]; | ||
59 | + $result.list[$key]={ | ||
60 | + date:$val['date'], | ||
61 | + desc:$val['message'], | ||
62 | + isIncome:true | ||
63 | + } | ||
64 | + //2:订单取消退还,9:下单使用,10:退货退还 | ||
65 | + if ([2,9,10].indexOf($val.type)>-1 && $val.key) { | ||
66 | + $result.list[$key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode:$val['key']}); | ||
67 | + } | ||
68 | + //晒单奖励 | ||
69 | + else if ($val.type == 14 && $val.key) { | ||
70 | + let $product = yield SearchData.searchAll({query:Number($val.key),viewNum:1}); | ||
71 | + if ($product.code && $product.code== 200 && !_.isEmpty($product.data.product_list) && !_.isEmpty($product.data.product_list[0].goods_list)) { | ||
72 | + $productId = $product.data.product_list[0].product_id; | ||
73 | + $goodsId = $product.data.product_list[0].goods_list[0].goods_id; | ||
74 | + $result.list[$key].detailUrl = helpers.getUrlBySkc($productId, $goodsId, $product.data.product_list[0].cn_alphabet); | ||
75 | + } | ||
76 | + } | ||
77 | + if (Number($val['num']) < 0) { | ||
78 | + $result.list[$key].isIncome = false; | ||
79 | + } | ||
80 | + $result.list[$key].value = $val['num'] > 0 ? '+'+$val['num'] : $val['num'] ; | ||
81 | + } | ||
82 | + //分页 | ||
83 | + let total = $data.data.total; | ||
84 | + let pagerObj = pager(total, { | ||
85 | + page: $data['data']['page'], | ||
86 | + limit: $condition['limit'] | ||
87 | + }); | ||
88 | + // $result['pager']={}; | ||
89 | + // $result['pager']['hasCheckAll'] = false; | ||
90 | + // $result['pager']['count'] = $data['data']['total']; | ||
91 | + // $result['pager']['curPage'] = $data['data']['page']; | ||
92 | + // $result['pager']['totalPages'] = Math.ceil($data['data']['total'] / $condition['limit']); | ||
93 | + // $result['pager']['pagerHtml'] = HelperSearch::pager($data['data']['total'], $condition['limit']); | ||
94 | + } | ||
95 | + return $result; | ||
96 | + })(); | ||
97 | +} | ||
98 | +const currencyTabs=($type)=>{ | ||
99 | + let $result=['全部明细', '全部收入', '全部支出']; | ||
100 | + $result=$result.forEach(function($val,$key){ | ||
101 | + return { | ||
102 | + active:$key == $type ? true : false, | ||
103 | + url:helpers.urlFormat('/home/currency',{type:$key}) | ||
104 | + } | ||
105 | + }); | ||
106 | + return $result; | ||
107 | +} | ||
108 | +const currencyOptions=($condition)=>{ | ||
109 | + let $result=[],$paramUrl={}; | ||
110 | + let $tabs={'90':'最近3个月明细','180':'最近半年明细','360':'最近一年明细'}; | ||
111 | + for(let name in $tabs){ | ||
112 | + if($condition.queryType){ | ||
113 | + $paramUrl.type = $condition.queryType; | ||
114 | + } | ||
115 | + $paramUrl.beginTime = convertUnitTime(new Date() / 1000 - 3600 * 24 ); | ||
116 | + $result.push({ | ||
117 | + url:helpers.urlFormat('/home/currency',$paramUrl), | ||
118 | + name:$tabs[name], | ||
119 | + selected:$condition.beginTime&&$paramUrl.beginTime == $condition.beginTime ? true : false | ||
120 | + }); | ||
121 | + } | ||
122 | + return $result; | ||
123 | +} | ||
124 | + | ||
125 | +module.exports = { | ||
126 | + currencyData | ||
127 | +}; |
1 | 'use strict'; | 1 | 'use strict'; |
2 | + | ||
2 | const querystring = require('querystring'); | 3 | const querystring = require('querystring'); |
4 | +const searchApi=global.yoho.SearchAPI; | ||
3 | 5 | ||
4 | 6 | ||
5 | const getUrl = ($type)=>{ | 7 | const getUrl = ($type)=>{ |
@@ -62,11 +64,16 @@ const getProductUrl = ($condition, $type)=>{ | @@ -62,11 +64,16 @@ const getProductUrl = ($condition, $type)=>{ | ||
62 | if (!$condition) { | 64 | if (!$condition) { |
63 | $param += $condition; | 65 | $param += $condition; |
64 | } | 66 | } |
65 | - console.log(JSON.stringify($param)); | ||
66 | return getUrl($type) + '?' + querystring.stringify($param);// searchApi.get(getUrl($type), $param,{cache:true}); | 67 | return getUrl($type) + '?' + querystring.stringify($param);// searchApi.get(getUrl($type), $param,{cache:true}); |
67 | }; | 68 | }; |
68 | 69 | ||
70 | +const searchAll = ($param)=>{ | ||
71 | + $param=$param||{}; | ||
72 | + return searchApi.get(getUrl($type), $param,{cache:true}); | ||
73 | +} | ||
74 | + | ||
69 | module.exports = { | 75 | module.exports = { |
70 | getProductUrl, | 76 | getProductUrl, |
71 | - getBrandListUrl | 77 | + getBrandListUrl, |
78 | + searchAll | ||
72 | }; | 79 | }; |
@@ -91,7 +91,7 @@ const sessionEffective = (req, res, next) => { | @@ -91,7 +91,7 @@ const sessionEffective = (req, res, next) => { | ||
91 | // 查看二维码 | 91 | // 查看二维码 |
92 | router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode); | 92 | router.get('/QRcode', [getCommonHeader, getHomeNav], personalController.QRcode); |
93 | 93 | ||
94 | -let Index = require(`${cRoot}/Index`); | 94 | + |
95 | 95 | ||
96 | // 我的评论 | 96 | // 我的评论 |
97 | router.get('/comment', commentController.index); | 97 | router.get('/comment', commentController.index); |
@@ -107,6 +107,10 @@ router.get('/returns', returnsController.index); | @@ -107,6 +107,10 @@ router.get('/returns', returnsController.index); | ||
107 | // router.get('address', addressController.index); | 107 | // router.get('address', addressController.index); |
108 | // router.get('address/area', addressController.area); | 108 | // router.get('address/area', addressController.area); |
109 | 109 | ||
110 | +let Index = require(`${cRoot}/Index`); | ||
110 | router.get('/index', [getCommonHeader, getHomeNav], Index.index); | 111 | router.get('/index', [getCommonHeader, getHomeNav], Index.index); |
111 | 112 | ||
113 | +let Currency = require(`${cRoot}/Currency`); | ||
114 | +router.get('/currency', Currency.index); | ||
115 | + | ||
112 | module.exports = router; | 116 | module.exports = router; |
1 | -{{> layout/header}} | ||
2 | -<div class="me-currency-page me-page yoho-page clearfix"> | ||
3 | - {{# meCurrency}} | ||
4 | - {{> path}} | ||
5 | - | ||
6 | - {{> navigation}} | ||
7 | - | ||
8 | - <div class="me-main"> | ||
9 | - <div class="currencies block"> | ||
10 | - <h2 class="title"></h2> | ||
11 | - | ||
12 | - <h1 class="my-currency">目前可用YOHO币:<em>{{myCurrency}}</em>个</h1> | ||
13 | - | ||
14 | - <div class="tab-wrap"> | ||
15 | - {{> tabs}} | ||
16 | - | ||
17 | - <div class="options-helper"> | ||
18 | - <select class="filter-select"> | ||
19 | - {{# options}} | ||
20 | - <option value="{{url}}">{{name}}</option> | ||
21 | - {{/ options}} | ||
22 | - </select> | ||
23 | - <a class="coin-helper" href="{{coinHelperUrl}}">[ 什么是YOHO币?]</a> | ||
24 | - </div> | ||
25 | - </div> | ||
26 | - | ||
27 | - <p class="currency-header clearfix"> | ||
28 | - <span class="date">日期</span> | ||
29 | - <span class="income-expenditure">收入/支出</span> | ||
30 | - <span class="remark">详细说明</span> | ||
31 | - </p> | ||
32 | - | ||
33 | - <ul class="currency"> | ||
34 | - {{# currency}} | ||
35 | - <li> | ||
36 | - <span class="date">{{date}}</span> | ||
37 | - <span class="income-expenditure{{#if isIncome}} income{{/if}}"> | ||
38 | - {{#if isIncome}} | ||
39 | - + | ||
40 | - {{^}} | ||
41 | - - | ||
42 | - {{/if}} | ||
43 | - {{value}} | ||
44 | - </span> | ||
45 | - <p class="remark"> | ||
46 | - {{desc}} | ||
47 | - {{#if detailUrl}} | ||
48 | - <a href="{{detailUrl}}">查看详情</a> | ||
49 | - {{/if}} | ||
50 | - </p> | ||
51 | - </li> | ||
52 | - {{/ currency}} | ||
53 | - </ul> | ||
54 | - | ||
55 | - {{> pager}} | ||
56 | - </div> | ||
57 | - | ||
58 | - {{> help-us}} | ||
59 | - </div> | ||
60 | - {{/ meCurrency}} | ||
61 | -</div> |
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | * @date: 2016/3/22 | 4 | * @date: 2016/3/22 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | -var $ = require('yoho.jquery'); | 7 | +var $ = require('yoho-jquery'); |
8 | 8 | ||
9 | $('.filter-select').change(function() { | 9 | $('.filter-select').change(function() { |
10 | location.href = $(this).val(); | 10 | location.href = $(this).val(); |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | font-size: 12px; | 2 | font-size: 12px; |
3 | 3 | ||
4 | .currencies > .title { | 4 | .currencies > .title { |
5 | - background-image: resolve(/home/currency.png); | 5 | + background-image: resolve(img/home/currency.png); |
6 | } | 6 | } |
7 | 7 | ||
8 | .my-currency { | 8 | .my-currency { |
@@ -144,4 +144,4 @@ | @@ -144,4 +144,4 @@ | ||
144 | color: #e10049; | 144 | color: #e10049; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | -} | ||
147 | +} |
@@ -256,11 +256,10 @@ | @@ -256,11 +256,10 @@ | ||
256 | @import "comment"; | 256 | @import "comment"; |
257 | @import "consult"; | 257 | @import "consult"; |
258 | @import "returns"; | 258 | @import "returns"; |
259 | - | 259 | +@import "currency"; |
260 | /* | 260 | /* |
261 | @import "red-envelopes"; | 261 | @import "red-envelopes"; |
262 | @import "coupons"; | 262 | @import "coupons"; |
263 | -@import "currency"; | ||
264 | @import "favorite"; | 263 | @import "favorite"; |
265 | @import "user-info"; | 264 | @import "user-info"; |
266 | @import "returns-detail"; | 265 | @import "returns-detail"; |
-
Please register or login to post a comment