IndexModel.js
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const OrderData = require('./OrderData');
const OrderModel = require('./OrderModel');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const searchApi = global.yoho.SearchAPI;
const BrandData = require('./BrandData');
const IndexData = require('./IndexData');
const SearchData = require('./SearchData');
const HelperHome = require('./HelperHome');
const _ = require('lodash');
/**
* 个人中心——消息提示
* @param type $uid
* @param type $udid
* @return array
*/
const getInfoNumData = ($uid, $udid)=>{
let $result = [
{href: helpers.urlFormat('/home/orders'), name: '待处理订单', 'count': 0},
{href: helpers.urlFormat('/home/message'), name: '未读消息', 'count': 0},
{href: helpers.urlFormat('/home/comment'), name: '待评论商品', 'count': 0}
];
return co(function * () {
let $getPendingOrderCount = yield IndexData.getPendingOrderCount($uid);// 待处理订单
let $infoNumData = yield IndexData.infoNum($uid, $udid); // 未读消息
let $notCommentRecordCount = yield IndexData.notCommentRecordCount($uid);// 待评论商品
$result[0]['count'] = $getPendingOrderCount.data.count ? $getPendingOrderCount.data.count : 0;
$result[1]['count'] = $infoNumData.data.inbox_total ? $infoNumData.data.inbox_total : 0;
$result[2]['count'] = $notCommentRecordCount.data ? $notCommentRecordCount.data : 0;
return $result;
})();
};
/**
* 个人中心——最新订单
* @param type $uid
* @return array
*/
const latestOrders = ($uid)=>{
return co(function *() {
let $orders = yield OrderModel.getOrders($uid, 1, 2, 1);
return {
more: helpers.urlFormat('/home/orders'),
orders: $orders
};
})();
};
const homeData = ()=>{
return co(function * () {
let $result = {};
let $url = {};
$url.fav_brand = SearchData.getBrandListUrl();
$url.new = SearchData.getProductUrl({new: 'Y', viewNum: 10});
let $data = yield Promise.all([searchApi.get($url.fav_brand, {}, {cache: true}), searchApi.get($url.new, {}, {cache: true})]);
// 格式化数据
$result['brand'] = $data[0].data && $data[0].data.length > 0 ? HelperHome.formatFavBrand($data[0].data, 6) : [];
$result['new'] = $data[1].data['product_list'] && $data[1].data['product_list'].length > 0 ? HelperHome.formatNew($data[1].data['product_list']) : {};
return $result;
// $result.brand=$data.fav_brand&&!$data.fav_brand?
})();
};
/**
* 底部banner
* @param string $code
* @return mixed
*/
const getFooterBanner = ($code)=>{
$code = $code || '20110609-152143';
return co(function *() {
let result = '';
let $banner = yield BrandData.getByNodeContent($code);
if ($banner.code && $banner.data) {
result = $banner.data.replace('http://', '//');
}
return result;
})();
};
module.exports = {
getInfoNumData,
getFooterBanner,
latestOrders,
homeData
};