Index.js
16.5 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const OrderData=require('./OrderData');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
// class IndexModel extends global.mClass{
const getPendingOrderCount=($uid)=>{
let options={
method:'web.SpaceOrders.getPendingOrderCount',
uid:$uid
};
return api.get('', options);
}
const infoNum=($uid, $udid)=>{
let options={
method:'app.home.getInfoNum',
uid:$uid,
udid:$udid
}
return api.get('', options);
}
const notCommentRecordCount=($uid)=>{
let options={
method:'show.notCommentRecordCount',
uid:$uid
}
return api.get('', options);
}
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 getPendingOrderCount($uid);//待处理订单
console.log($getPendingOrderCount);
let $infoNumData = yield infoNum($uid, $udid); //未读消息
let $notCommentRecordCount = yield 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;
})();
}
const getByNodeContent=($node, $mode)=>{
$mode=$mode||'release';
let options={
method:'web.html.content',
mode:$mode,
node:$node
};
return api.get('', options);
}
const getFooterBanner=($code)=>{
$code=$code||'20110609-152143';
return co(function *(){
let result="";
let $banner=yield getByNodeContent($code);
if($banner.code&&$banner.data){
result=$banner.data.replace('http://','//');
}
return result;
})()
}
/**
* 订单状态
* @param type $isCancel
* @param type $status
* @param type $payType
* @param type $payStatus
* @return string
*/
// const getOrderStatus=($isCancel, $status, $payType, $payStatus)=>{
// //初始化:未取消,待付款
// let $ret={cancel:false,keyName:'noPay',statusStr:'待付款'};
// if ($isCancel == 'Y') {
// $ret = {cancel:true,statusStr:'已取消'};
// }else{
// switch ($status) {
// case 0:
// //'订单已成功,等待付款'
// if ($payType != 2 && $payStatus == 'N') {
// $ret['keyName'] = 'noPay';
// $ret['statusStr'] = '待付款';
// }
// //'订单已付款,等待备货中'
// else if ($payType != 2 && $payStatus == 'Y') {
// $ret['keyName'] = 'paid';
// $ret['statusStr'] = '备货中';
// }
// //'订单已成功,等待备货中'-货到付款
// else if ($payType == 2 && $payStatus == 'N') {
// $ret['keyName'] = 'complete';
// $ret['statusStr'] = '备货中';
// }
// break;
// case 1:
// case 2:
// case 3:
// //'订单已付款,等待备货中'
// $ret['keyName'] = 'paid';
// $ret['statusStr'] = '备货中';
// break;
// case 4:
// case 5:
// //'订单已发货'
// $ret['keyName'] = 'shipped';
// $ret['statusStr'] = '待收货';
// break;
// case 6:
// //'交易完成';
// $ret['keyName'] = 'reback';
// $ret['statusStr'] = '交易完成';
// break;
// }
// }
// return $ret;
// }
// const getExpressInfo=($orderCode, $uid, $paymetType, $createTime, $isDetail)=>{
// $isDetail=$isDetail||false;
// let $result={};
// $result['logisticsUrl'] = '';
// $result['logisticsImg'] = '';
// $result['logisticsCompany'] = '';
// $result['courierNumbe'] = '';
// if ($paymetType == 1) {
// if ($isDetail) {
// $result['logistics'] = [new Date($createTime), ' ', '您的订单已提交,等待付款'];
// }
// else {
// $result['logistics'] = new Date($createTime) + ' ' + '您的订单已提交,等待付款';
// }
// }
// if ($paymetType == 2) {
// if ($isDetail) {
// $result['logistics'] = [new Date($createTime), ' ', '您的订单已提交,等待审核'];
// }
// else {
// $result['logistics'] = new Date($createTime) +' ' + '您的订单已提交,等待审核';
// }
// }
// //有物流
// if ($orderCode && typeof _.isNumber($uid)) {
// let $logistics = yield OrderData.getLogisticsData($orderCode, $uid);
// if ($logistics['data']) {
// $result['logisticsUrl'] = $logistics['data']['url'] ? this.helper.getUrlSafe($logistics['data']['url']) : '';
// $result['logisticsImg'] = $logistics['data']['logo'] ? $logistics['data']['logo'] : '';
// $result['logisticsCompany'] = $logistics['data']['caption'] ? $logistics['data']['caption'] : '';
// $result['courierNumbe'] = $logistics['data']['express_number']? $logistics['data']['express_number'] : '';
// let $expressDetail = $logistics['data']['express_detail'] ? $logistics['data']['express_detail'] : {};
// if ($expressDetail) {
// $logisticsTmp = $result['logistics'][0]; //暂存
// $result['logistics'] = array();
// foreach ($expressDetail as $value) {
// $pos =$value['accept_address'].indexOf(' ') / 3;
// $city = $value['accept_address'].substr(0,$pos);
// $exInfo = $value['accept_address'].substr($pos);
// if ($isDetail) {
// $result['logistics'] = [$value['acceptTime'], $city, $exInfo];
// }
// else {
// $result['logistics'] = $value['acceptTime'] + $city + $exInfo;
// }
// }
// //把最初的处理放最后
// $result['logistics'] = $logisticsTmp;
// }
// }
// }
// return $result;
// }
/**
* 商品属性标签
* @param type $attribute
* @param type $goodsType
* @return string
*/
// const getGoodsTag=($attribute, $goodsType)=>{
// let $goodsTagName = '';
// switch ($goodsType) {
// //赠品
// case 'gift':
// $goodsTagName = 'freebie';
// break;
// //加价购
// case 'price_gift':
// $goodsTagName = 'advanceBuy';
// break;
// //预售
// case 'advance':
// $goodsTagName = 'preSaleGood';
// break;
// //outlet
// case 'outlet':
// $goodsTagName = '';
// break;
// //免单
// case 'free':
// $goodsTagName = '';
// break;
// //电子
// case 'ticket':
// $goodsTagName = '';
// break;
// default:
// break;
// }
// //虚拟
// if ($attribute == 3) {
// $goodsTagName = 'virtualGood';
// }
// return $goodsTagName;
// }
/**
* 获取我的订单列表数据-分页
* @param type $uid
* @param type $page
* @param type $limit
* @param type $type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
*/
// const getOrders=($uid, $page, $limit, $type, $isPage)=>{
// return co(function *(){
// $isPage=$isPage||false;
// let getOrderDescStr={
// 1:'您还没有任何订单',
// 5:'您目前还没有成功的订单',
// 7:'您还没有任何取消的订单'
// }
// let $descStr=getOrderDescStr[$type]||'';
// let $orders={empty:$descStr};
// let $orderInfo=yield OrderData.getUserOrders($uid, $page, $limit, $type);
// if($orderInfo.data&&$orderInfo.data.order_list){
// $orders={};
// $orderInfo.data.order_list.forEach(function($orderV,$orderK){
// $orders[$orderK]['orderNum'] = $orderV['order_code']; //订单标识
// $orders[$orderK]['orderTime'] = new Date($orderV['create_time']);
// let $statusInfo = getOrderStatus($orderV['is_cancel'], $orderV['status'], $orderV['payment_type'], $orderV['payment_status']);
// //订单状态
// if ($statusInfo['cancel']) {
// $orders[$orderK]['cancel'] = $statusInfo['cancel'];
// }
// else {
// if ($statusInfo['keyName']) {
// $orders[$orderK][$statusInfo['keyName']] = true;
// //已发货,物流信息
// if ($statusInfo['keyName'] == 'shipped') {
// let $expressInfo = getExpressInfo($orderV['order_code'], $uid, $orderV['payment_type'], $orderV['create_time']);
// $orders[$orderK]['logistics'] = $expressInfo['logistics'];
// }
// }
// }
// //订单商品相关信息
// let $opRefundStatus = true; //订单不可操作退换货
// if ($orderV['order_goods'] && $orderV['order_goods']) {
// let $goods={},$refundFlag={};
// $orderV['order_goods'].forEach(function($goval,$gokey){
// $goods[$gokey]['href'] = helpers.getUrlBySkc($goval['product_id'], $goval['goods_id'], $goval['cn_alphabet']);
// $goods[$gokey]['thumb'] = $goval['goods_image'] && $goval['goods_image'] ? global.utils.getImageUrl($goval['goods_image'], 100, 100) : '';
// $goods[$gokey]['name'] = $goval['product_name'];
// $goods[$gokey]['color'] = $goval['color_name'];
// $goods[$gokey]['size'] = $goval['size_name'];
// $goods[$gokey]['price'] = $goval['goods_price'];
// let $buyNum = Number($goval['buy_number']);
// let $refundNum = Number($goval['refund_num']);
// $goods[$gokey]['count'] = $buyNum;
// $refundStatus = ($refundNum > 0) ? true : false; //只要发生一件退换,退换过的标记
// $goods[$gokey]['refundStatus'] = $refundStatus;
// $refundFlag = (($buyNum == $refundNum) && $refundNum > 0) ? 'finished' : 'unfinished'; //某一件商品全部退换结束
// $goods[$gokey]['arrivalDate'] = $goval['expect_arrival_time'];
// let $goodsTagName = self::getGoodsTag($orderV['attribute'], $goval['goods_type']);
// if ($goodsTagName) {
// $goods[$gokey][$goodsTagName] = true;
// }
// $orders[$orderK]['goods'] = $goods;
// });
// if($refundFlag.indexOf('unfinished')){
// $opRefundStatus = false;
// }
// $orders[$orderK]['pay'] = $orderV['amount']; //付款数
// $orders[$orderK]['fregit'] = $orderV['shipping_cost']; //邮费
// }
// //操作
// $orders[$orderK]['operation'] = getOperateInfo($orderV['attribute'], $orderV['is_cancel'], $orderV['status'], $orderV['payment_status'], $orderV['update_time'], $orderV['order_type'], $orderV['refund_status'], $orderV['payment_type'], $orderV['order_code'], $opRefundStatus);
// });
// if ($isPage) {
// $orders['pager']['total'] = $orderInfo['data']['total'];
// $orders['pager']['pageTotal'] = $orderInfo['data']['page_total'];
// $orders['pager']['page'] = $orderInfo['data']['page'];
// }
// return $orders;
// }
// })();
// }
// const latestOrders=($uid)=>{
// return co(function *(){
// let $orders=yield getOrders($uid, 1, 2, 1)
// return {
// more : helpers.url('/home/orders'),
// orders:$orders
// }
// })();
// }
module.exports = {
getInfoNumData,
getFooterBanner
};
// getBrandListUrl(){
// return this.SearchAPI.get('/yohosearch/brand/list.json', {},{cache:true});
// }
// getProductUrl($condition, $type = ''){
// let $orderMaps={
// s_t_desc:'shelve_time:desc',
// s_t_asc:'shelve_time:asc',
// s_p_asc:'sales_price:asc',
// s_p_desc:'sales_price:desc',
// p_d_desc:'discount:desc',
// p_d_asc:'discount:asc',
// skn_desc:'product_skn:desc',
// skn_asc:'product_skn:asc',
// activities_desc:'activities.order_by:desc',
// activities_asc:'activities.order_by:asc',
// s_n_asc:'sales_num:asc',
// s_n_desc:'sales_num:desc',
// activities_id_desc:'activities.activity_id:desc',
// activities_id_asc:'activities.activity_id:asc',
// brand_desc:'brand_weight:desc'
// }
// $param={
// status:1,
// sales:'Y',
// outlets:2,
// stocknumber:1,
// attribute_not:2
// };
// if(!$condition.order){
// $param.order=$orderMaps.s_t_desc;
// }else{
// $param.order=$orderMaps[$condition.order]?$orderMaps[$condition.order]:'';
// }
// if(!$condition.page){
// $param.page=1;
// }
// if(!$condition.viewNum){
// $param.viewNum=$condition.viewNum;
// }else if(!$condition.limit){
// $param.viewNum=60;
// }else{
// $param.viewNum=$condition.limit;
// delete $condition.limit;
// }
// if(!$condition){
// $param += $condition;
// }
// return this.SearchAPI.get($type, $param,{cache:true});
// }
// formatFavBrand($brandInfo, $i = 10){
// $hotBrands=[];
// if($brandInfo){
// $brandInfo.forEach(function($value){
// if ($value.is_hot && $value.is_hot == 'Y') {
// $hotBrands.push({
// 'href' : Helpers::url('', '', $value['brand_domain']),
// 'logo' : Images::getSourceUrl($value['brand_ico'], 'brandLogo'),
// 'name' : $value.brand_name,
// });
// }
// });
// }
// return $hotBrands;
// }
// homeData(){
//
// return co(function * (){
// let $result = {};
// let $url={};
// $url.fav_brand =yield that.getBrandListUrl();
// $url.new=yield that.getProductUrl({new:'Y',viewNum:10});
// console.log($url);
// return $url;
// // $result.brand=$data.fav_brand&&!$data.fav_brand?
// }();
// }
// }
// module.exports = IndexModel;