Authored by yyq

del use less

1 -'use strict';  
2 -  
3 -  
4 -const Promise = require('bluebird');  
5 -const co = Promise.coroutine;  
6 -  
7 -const UserData = require('./user-data');  
8 -const helpers = global.yoho.helpers;  
9 -const path = require('path');  
10 -const _ = require('lodash');  
11 -const moment = require('moment');  
12 -  
13 -// 使用 product中的分页逻辑  
14 -const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');  
15 -const pager = require(pagerPath).handlePagerData;  
16 -  
17 -const UNUSED = 'notuse';  
18 -const USED = 'use';  
19 -const INVALID = 'overtime';  
20 -  
21 -  
22 -module.exports = class extends global.yoho.BaseModel {  
23 - constructor(ctx) {  
24 - super(ctx);  
25 - }  
26 -  
27 - getCouponsList(uid, type, page, limit) {  
28 - let userDataModel = new UserData(this.ctx);  
29 -  
30 - return co(function*() {  
31 - let couponsInfo = yield userDataModel.getCouponsList(uid, type, page, limit);  
32 - let result = [],  
33 - coupons = _.get(couponsInfo, 'data.couponList');  
34 -  
35 - if (!coupons) {  
36 - return {  
37 - list: result  
38 - };  
39 - }  
40 -  
41 - if (coupons) {  
42 - coupons.forEach(function(item, i) {  
43 - result[i] = {};  
44 - result[i].id = item.couponId;  
45 - result[i].code = item.couponCode;  
46 - result[i].couponType = Number(item.couponType);  
47 -  
48 - // 格式化有效日期 "couponValidity": "2016.03.15-2016.03.31"  
49 - let dates = item.couponValidity.split('-'),  
50 - extra = ['秒杀', '限定', '境外', '预售'],  
51 - limits = _.get(item, 'shopPriceLimits', '');  
52 -  
53 - result[i].beginTime = dates[0];  
54 - result[i].endTime = dates[1];  
55 -  
56 - if (!item.couponImageUrl) {  
57 - result[i].img = '//static.yohobuy.com/images/v2/activity/default_coupon.jpg';  
58 - } else {  
59 - result[i].img = item.couponImageUrl;  
60 - }  
61 -  
62 - result[i].value = item.couponValue;  
63 - result[i].validity = item.couponValidity;  
64 - result[i].useRemark = item.couponDetailInfomation;  
65 -  
66 - if (limits.indexOf('1') >= 0) {  
67 - extra.push('3折以下');  
68 - }  
69 - if (limits.indexOf('2') >= 0) {  
70 - extra.push('限量');  
71 - }  
72 - result[i].notes = item.notes;  
73 - result[i].proListUrl = helpers.urlFormat('', {cpc_id: item.couponId, coupon_code: item.couponCode,  
74 - phrase: encodeURIComponent('以下商品可使用 【' + item.couponDetailInfomation + '】优惠券')}, 'list');  
75 - result[i].rule = item.rule4ShortName || '';  
76 - result[i].overState = item.overState || '';  
77 -  
78 - if (type === USED) {  
79 - result[i].orderNum = _.get(item, 'orderCode', '');  
80 - result[i].orderDetailUrl = helpers.urlFormat('/home/orders/detail',  
81 - {orderCode: item.orderCode || ''});  
82 - result[i].orderSum = _.get(item, 'orderPrice', 0).toFixed(2);  
83 - result[i].payment = _.get(item, 'actuallyPaid', 0).toFixed(2);  
84 - let date = item.usedTime ? moment(item.usedTime).format('YYYY-MM-DD H:m') : 0;  
85 -  
86 - if (date) {  
87 - result[i].useTime = date;  
88 - } else {  
89 - result[i].useTime = '';  
90 - }  
91 - } else {  
92 - result[i].status = item.isValidity ? '可使用' : '已过期';  
93 - }  
94 -  
95 - if (item.couponType) {  
96 - result[i].type = item.couponType;  
97 - }  
98 - });  
99 - }  
100 -  
101 - let pageNum = pager(couponsInfo.data.total, {  
102 - page: page,  
103 - limit: limit,  
104 - type: type  
105 - });  
106 -  
107 - return {  
108 - list: result,  
109 - pager: Object.assign({  
110 - count: couponsInfo.data.total || 0,  
111 - curPage: page,  
112 - totalPages: couponsInfo.data.totalPageNum  
113 - }, pageNum)  
114 - };  
115 - })();  
116 - }  
117 -  
118 - couponsData(uid, params) {  
119 - let type = params.type || UNUSED;  
120 - let page = params.page || 1;  
121 - let limit = params.limit || 10;  
122 - let _this = this;  
123 -  
124 - return co(function*() {  
125 - let coupons = yield _this.getCouponsList(uid, type, page, limit);  
126 - let data = {};  
127 -  
128 - if (type === UNUSED) {  
129 - data.unUseCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;  
130 - data.unUse = true;  
131 - } else if (type === USED) {  
132 - data.usedCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;  
133 - data.used = true;  
134 - } else if (type === INVALID) {  
135 - data.noValidCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;  
136 - data.noValid = true;  
137 - }  
138 -  
139 - data.tabs = [  
140 - {  
141 - active: type === UNUSED ? true : false,  
142 - url: helpers.urlFormat('/home/coupons', {type: UNUSED}),  
143 - name: '未使用优惠券'  
144 - },  
145 - {  
146 - active: type === USED ? true : false,  
147 - url: helpers.urlFormat('/home/coupons', {type: USED}),  
148 - name: '已使用优惠券'  
149 - },  
150 - {  
151 - active: type === INVALID ? true : false,  
152 - url: helpers.urlFormat('/home/coupons', {type: INVALID}),  
153 - name: '已失效优惠券'  
154 - }  
155 - ];  
156 -  
157 - data.pager = coupons.pager;  
158 -  
159 - return data;  
160 - })();  
161 - }  
162 -};  
@@ -39,20 +39,4 @@ module.exports = class extends global.yoho.BaseModel { @@ -39,20 +39,4 @@ module.exports = class extends global.yoho.BaseModel {
39 39
40 return this.get({data: Object.assign(options, params)}); 40 return this.get({data: Object.assign(options, params)});
41 } 41 }
42 -  
43 - getCouponsList(uid, type, page, limit) {  
44 - page = page || 1;  
45 - type = type || 'notuse';  
46 - limit = limit || 10;  
47 -  
48 - let options = {  
49 - method: 'app.coupons.lists',  
50 - uid: uid,  
51 - type: type,  
52 - page: page,  
53 - limit: limit  
54 - };  
55 -  
56 - return this.get({data: options});  
57 - }  
58 }; 42 };
1 -<div class="me-coupons-page me-page yoho-page clearfix">  
2 - {{> path}}  
3 - {{> navigation}}  
4 - <div class="me-main">  
5 - <div class="coupons{{#if unUse}} un-use-coupons{{/if}}{{#if used}} used-coupons{{/if}}{{#if noValid}} no-valid-coupons{{/if}} block">  
6 - <h2 class="title">优惠券</h2>  
7 -  
8 - {{> tabs}}  
9 - <div class="coupons-wrap">  
10 - <p class="coupons-header clearfix">  
11 - <span class="coupons-name">优惠券名称</span>  
12 - <span class="coupons-info">详细说明</span>  
13 - {{#if unUse}}  
14 - <span class="coupons-opt">操作</span>  
15 - {{/if}}  
16 - {{#if used}}  
17 - <span class="coupons-opt">订单号</span>  
18 - {{/if}}  
19 - {{#if noValid}}  
20 - <span class="coupons-opt">状态</span>  
21 - {{/if}}  
22 - </p>  
23 -  
24 - {{# unUseCoupons}}  
25 - {{#unless empty}}  
26 - <div class="coupon" data-couponId="{{id}}">  
27 - <div class="coupons-card{{#isEqual couponType 5}} coupons-freight{{/isEqual}}">  
28 - <div class="coupons-card-header">  
29 - <p class="left-title">{{useRemark}}</p>  
30 - </div>  
31 - <div class="coupons-card-content">  
32 - <div class="coupons-card-row">  
33 - <div class="coupons-sht">  
34 - <p class="coupons-price">{{value}}</p>  
35 - {{#if rule}}  
36 - <p class="coupons-full" title="{{rule}}">{{rule}}</p>  
37 - {{/if}}  
38 - </div>  
39 - <div class="coupons-dtl">  
40 - <p>{{beginTime}} - {{endTime}}</p>  
41 - {{#if overState}}  
42 - <p class="red">({{overState}})</p>  
43 - {{/if}}  
44 - </div>  
45 - </div>  
46 - </div>  
47 - </div>  
48 -  
49 - <div class="coupons-info">  
50 - <div class="coupons-text">  
51 - {{notes}}  
52 - </div>  
53 - </div>  
54 -  
55 - <div class="coupons-opt">  
56 - <a class="btn use-btn" id="coupon-use" href="{{proListUrl}}" target="_black">立即使用</a>  
57 - </div>  
58 - </div>  
59 - {{/unless}}  
60 - {{/ unUseCoupons}}  
61 -  
62 - {{# usedCoupons}}  
63 - {{#unless empty}}  
64 - <div class="coupon" data-couponId="{{id}}">  
65 - <div class="coupons-card coupons-use{{#isEqual couponType 5}} coupons-freight{{/isEqual}}">  
66 - <div class="coupons-card-header">  
67 - <p class="left-title">{{useRemark}}</p>  
68 - </div>  
69 - <div class="coupons-card-content">  
70 - <div class="coupons-card-row">  
71 - <div class="coupons-sht">  
72 - <p class="coupons-price">{{value}}</p>  
73 - {{#if rule}}  
74 - <p class="coupons-full" title="{{rule}}">{{rule}}</p>  
75 - {{/if}}  
76 - </div>  
77 - <div class="coupons-dtl">{{beginTime}} - {{endTime}}</div>  
78 - </div>  
79 - </div>  
80 - </div>  
81 - <div class="coupons-info">  
82 - <div class="coupons-text">  
83 - {{#categorys}}<p>限品类:{{.}}</p>{{/categorys}}  
84 - {{#brands}}<p>限品牌:{{.}}</p>{{/brands}}  
85 - {{#if isNoLimit}}<p>全场通用</p>{{/if}}  
86 - <p>特例商品({{extraPro}}等特例商品)暂不支持使用优惠券。</p>  
87 - {{#explains}}<p>说明:{{.}}</p>{{/explains}}  
88 - </div>  
89 - </div>  
90 - <div class="coupons-opt">  
91 - <a href="{{orderDetailUrl}}">  
92 - <p>{{orderNum}}</p>  
93 - <p>{{useTime}}</p>  
94 - </a>  
95 - </div>  
96 - </div>  
97 - {{/unless}}  
98 - {{/ usedCoupons}}  
99 -  
100 - {{# noValidCoupons}}  
101 - {{#unless empty}}  
102 - <div class="coupon" data-couponId="{{id}}">  
103 - <div class="coupons-card coupons-invalid">  
104 - <div class="coupons-card-header">  
105 - <p class="left-title">{{useRemark}}</p>  
106 - </div>  
107 - <div class="coupons-card-content">  
108 - <div class="coupons-card-row">  
109 - <div class="coupons-sht">  
110 - <p class="coupons-price">{{value}}</p>  
111 - {{#if rule}}  
112 - <p class="coupons-full" title="{{rule}}">{{rule}}</p>  
113 - {{/if}}  
114 - </div>  
115 - <div class="coupons-dtl">{{beginTime}} - {{endTime}}</div>  
116 - </div>  
117 - </div>  
118 - </div>  
119 - <div class="coupons-info">  
120 - <div class="coupons-text">  
121 - {{#categorys}}<p>限品类:{{.}}</p>{{/categorys}}  
122 - {{#brands}}<p>限品牌:{{.}}</p>{{/brands}}  
123 - {{#if isNoLimit}}<p>全场通用</p>{{/if}}  
124 - <p>特例商品({{extraPro}}等特例商品)暂不支持使用优惠券。</p>  
125 - {{#explains}}<p>说明:{{.}}</p>{{/explains}}  
126 - </div>  
127 - </div>  
128 - <div class="coupons-opt">  
129 - <a class="btn overtime-btn">过期</a>  
130 - </div>  
131 - </div>  
132 - {{/unless}}  
133 - {{/ noValidCoupons}}  
134 - </div>  
135 - {{#if unUseCoupons}}  
136 - {{#unless unUseCoupons.empty}}  
137 - {{> pager}}  
138 - {{^}}  
139 - {{#with unUseCoupons}}  
140 - {{> empty}}  
141 - {{/with}}  
142 - {{/unless}}  
143 - {{/if}}  
144 -  
145 - {{#if usedCoupons}}  
146 - {{#unless usedCoupons.empty}}  
147 - {{> pager}}  
148 - {{^}}  
149 - {{#with usedCoupons}}  
150 - {{> empty}}  
151 - {{/with}}  
152 - {{/unless}}  
153 - {{/if}}  
154 -  
155 - {{#if noValidCoupons}}  
156 - {{#unless noValidCoupons.empty}}  
157 - {{> pager}}  
158 - {{^}}  
159 - {{#with noValidCoupons}}  
160 - {{> empty}}  
161 - {{/with}}  
162 - {{/unless}}  
163 - {{/if}}  
164 - </div>  
165 - </div>  
166 -  
167 -</div>