|
@@ -15,222 +15,223 @@ const _ = require('lodash'); |
|
@@ -15,222 +15,223 @@ const _ = require('lodash'); |
15
|
const config = global.yoho.config;
|
15
|
const config = global.yoho.config;
|
16
|
const helpers = global.yoho.helpers;
|
16
|
const helpers = global.yoho.helpers;
|
17
|
|
17
|
|
18
|
-const favProduct = (uid, page, limit) => {
|
|
|
19
|
-
|
|
|
20
|
- return api.get('', {
|
|
|
21
|
- method: 'app.favorite.product',
|
|
|
22
|
- uid: uid,
|
|
|
23
|
- page: page,
|
|
|
24
|
- limit: limit
|
|
|
25
|
- }).then((result) => {
|
|
|
26
|
-
|
|
|
27
|
- let resu = {
|
|
|
28
|
- hasFavProduct: []
|
|
|
29
|
- };
|
18
|
+class favoriteIndexModel extends global.yoho.BaseModel {
|
|
|
19
|
+ constructor(ctx) {
|
|
|
20
|
+ super(ctx);
|
|
|
21
|
+ }
|
30
|
|
22
|
|
31
|
- if (result && result.code === 200) {
|
23
|
+ favProduct(uid, page, limit) {
|
32
|
|
24
|
|
33
|
- let list = camelCase(result);
|
25
|
+ return api.get('', {
|
|
|
26
|
+ method: 'app.favorite.product',
|
|
|
27
|
+ uid: uid,
|
|
|
28
|
+ page: page,
|
|
|
29
|
+ limit: limit
|
|
|
30
|
+ }).then((result) => {
|
34
|
|
31
|
|
35
|
- if (page > 1 && list === []) {
|
|
|
36
|
- resu.end = true;
|
|
|
37
|
- }
|
32
|
+ let resu = {
|
|
|
33
|
+ hasFavProduct: []
|
|
|
34
|
+ };
|
38
|
|
35
|
|
39
|
- if (list.data.total === 0) {
|
|
|
40
|
- resu.total = 0;
|
|
|
41
|
- }
|
36
|
+ if (result && result.code === 200) {
|
42
|
|
37
|
|
43
|
- if (page <= list.data.pageTotal) {
|
|
|
44
|
- list.data.productList = _.filter(list.data.productList, function(n) {
|
|
|
45
|
- return n.productSkn > 0;
|
|
|
46
|
- });
|
|
|
47
|
- _.forEach(list.data.productList, function(val) {
|
|
|
48
|
- let obj = {};
|
38
|
+ let list = camelCase(result);
|
49
|
|
39
|
|
50
|
- // if (empty(val.productSkn)) {
|
|
|
51
|
- // continue;
|
|
|
52
|
- // }
|
40
|
+ if (page > 1 && list === []) {
|
|
|
41
|
+ resu.end = true;
|
|
|
42
|
+ }
|
53
|
|
43
|
|
54
|
- if (val.goodsId && val.cnAlphabet) {
|
|
|
55
|
- obj = _.assign(obj, {
|
|
|
56
|
- link: config.siteUrl + '/product/' + val.productSkn + '.html' // 商品url改版
|
|
|
57
|
- });
|
|
|
58
|
- } else {
|
|
|
59
|
- obj = _.assign(obj, {
|
|
|
60
|
- link: ''
|
|
|
61
|
- });
|
|
|
62
|
- }
|
44
|
+ if (list.data.total === 0) {
|
|
|
45
|
+ resu.total = 0;
|
|
|
46
|
+ }
|
63
|
|
47
|
|
64
|
- if (val.image) {
|
|
|
65
|
- obj = _.assign(obj, {
|
|
|
66
|
- imgUrl: val.image
|
|
|
67
|
- });
|
|
|
68
|
- } else {
|
|
|
69
|
- obj = _.assign(obj, {
|
|
|
70
|
- imgUrl: ''
|
|
|
71
|
- });
|
|
|
72
|
- }
|
|
|
73
|
-
|
|
|
74
|
- if (val.marketPrice - val.salesPrice > 0) {
|
|
|
75
|
- obj = _.assign(obj, {
|
|
|
76
|
- discountPrice: '¥' + Number(val.salesPrice).toFixed(2)
|
|
|
77
|
- });
|
|
|
78
|
- }
|
|
|
79
|
-
|
|
|
80
|
- if (val.priceDown > 0) {
|
|
|
81
|
- obj = _.assign(obj, {
|
|
|
82
|
- savePrice: '¥' + Number(val.priceDown).toFixed(2)
|
|
|
83
|
- });
|
|
|
84
|
- } else {
|
|
|
85
|
- obj = _.assign(obj, {
|
|
|
86
|
- savePrice: false
|
|
|
87
|
- });
|
|
|
88
|
- }
|
48
|
+ if (page <= list.data.pageTotal) {
|
|
|
49
|
+ list.data.productList = _.filter(list.data.productList, function(n) {
|
|
|
50
|
+ return n.productSkn > 0;
|
|
|
51
|
+ });
|
|
|
52
|
+ _.forEach(list.data.productList, function(val) {
|
|
|
53
|
+ let obj = {};
|
|
|
54
|
+
|
|
|
55
|
+ // if (empty(val.productSkn)) {
|
|
|
56
|
+ // continue;
|
|
|
57
|
+ // }
|
|
|
58
|
+
|
|
|
59
|
+ if (val.goodsId && val.cnAlphabet) {
|
|
|
60
|
+ obj = _.assign(obj, {
|
|
|
61
|
+ link: config.siteUrl + '/product/' + val.productSkn + '.html' // 商品url改版
|
|
|
62
|
+ });
|
|
|
63
|
+ } else {
|
|
|
64
|
+ obj = _.assign(obj, {
|
|
|
65
|
+ link: ''
|
|
|
66
|
+ });
|
|
|
67
|
+ }
|
|
|
68
|
+
|
|
|
69
|
+ if (val.image) {
|
|
|
70
|
+ obj = _.assign(obj, {
|
|
|
71
|
+ imgUrl: val.image
|
|
|
72
|
+ });
|
|
|
73
|
+ } else {
|
|
|
74
|
+ obj = _.assign(obj, {
|
|
|
75
|
+ imgUrl: ''
|
|
|
76
|
+ });
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ if (val.marketPrice - val.salesPrice > 0) {
|
|
|
80
|
+ obj = _.assign(obj, {
|
|
|
81
|
+ discountPrice: '¥' + Number(val.salesPrice).toFixed(2)
|
|
|
82
|
+ });
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ if (val.priceDown > 0) {
|
|
|
86
|
+ obj = _.assign(obj, {
|
|
|
87
|
+ savePrice: '¥' + Number(val.priceDown).toFixed(2)
|
|
|
88
|
+ });
|
|
|
89
|
+ } else {
|
|
|
90
|
+ obj = _.assign(obj, {
|
|
|
91
|
+ savePrice: false
|
|
|
92
|
+ });
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ if (val.storage <= 0) {
|
|
|
96
|
+ obj = _.assign(obj, {
|
|
|
97
|
+ sellOut: true
|
|
|
98
|
+ });
|
|
|
99
|
+ }
|
89
|
|
100
|
|
90
|
- if (val.storage <= 0) {
|
|
|
91
|
obj = _.assign(obj, {
|
101
|
obj = _.assign(obj, {
|
92
|
- sellOut: true
|
102
|
+ favId: val.productId,
|
|
|
103
|
+ title: val.productName,
|
|
|
104
|
+ price: '¥' + Number(val.marketPrice).toFixed(2),
|
|
|
105
|
+ invalidGoods: val.status === 0
|
93
|
});
|
106
|
});
|
94
|
- }
|
|
|
95
|
|
107
|
|
96
|
- obj = _.assign(obj, {
|
|
|
97
|
- favId: val.productId,
|
|
|
98
|
- title: val.productName,
|
|
|
99
|
- price: '¥' + Number(val.marketPrice).toFixed(2),
|
|
|
100
|
- invalidGoods: val.status === 0
|
108
|
+ resu.hasFavProduct.push(obj);
|
101
|
});
|
109
|
});
|
102
|
|
110
|
|
103
|
- resu.hasFavProduct.push(obj);
|
|
|
104
|
- });
|
111
|
+ } else {
|
|
|
112
|
+ resu.more = true;
|
|
|
113
|
+ }
|
105
|
|
114
|
|
|
|
115
|
+ return resu;
|
106
|
} else {
|
116
|
} else {
|
107
|
- resu.more = true;
|
117
|
+ logger.error('fav goods code no 200');
|
|
|
118
|
+ return {
|
|
|
119
|
+ total: 0
|
|
|
120
|
+ };
|
108
|
}
|
121
|
}
|
|
|
122
|
+ });
|
|
|
123
|
+ }
|
109
|
|
124
|
|
110
|
- return resu;
|
|
|
111
|
- } else {
|
|
|
112
|
- logger.error('fav goods code no 200');
|
|
|
113
|
- return {
|
|
|
114
|
- total: 0
|
|
|
115
|
- };
|
|
|
116
|
- }
|
|
|
117
|
- });
|
|
|
118
|
-};
|
125
|
+ favfavBrand(uid, page, limit) {
|
|
|
126
|
+ return api.get('', {
|
|
|
127
|
+ method: 'app.favorite.brand',
|
|
|
128
|
+ uid: uid,
|
|
|
129
|
+ page: page,
|
|
|
130
|
+ limit: limit
|
|
|
131
|
+ }).then((result) => {
|
119
|
|
132
|
|
120
|
-const favfavBrand = (uid, page, limit) => {
|
133
|
+ let resu = {
|
|
|
134
|
+ hasFavBrand: []
|
|
|
135
|
+ };
|
121
|
|
136
|
|
122
|
- return api.get('', {
|
|
|
123
|
- method: 'app.favorite.brand',
|
|
|
124
|
- uid: uid,
|
|
|
125
|
- page: page,
|
|
|
126
|
- limit: limit
|
|
|
127
|
- }).then((result) => {
|
137
|
+ if (result && result.code === 200) {
|
|
|
138
|
+ let list = camelCase(result);
|
128
|
|
139
|
|
129
|
- let resu = {
|
|
|
130
|
- hasFavBrand: []
|
|
|
131
|
- };
|
140
|
+ if (page > 1 && list === []) {
|
|
|
141
|
+ resu.end = true;
|
|
|
142
|
+ }
|
132
|
|
143
|
|
133
|
- if (result && result.code === 200) {
|
|
|
134
|
- let list = camelCase(result);
|
144
|
+ if (list.data.total === 0) {
|
|
|
145
|
+ resu.total = 0;
|
|
|
146
|
+ }
|
135
|
|
147
|
|
136
|
- if (page > 1 && list === []) {
|
|
|
137
|
- resu.end = true;
|
|
|
138
|
- }
|
148
|
+ if (page <= list.data.pageTotal) {
|
139
|
|
149
|
|
140
|
- if (list.data.total === 0) {
|
|
|
141
|
- resu.total = 0;
|
|
|
142
|
- }
|
150
|
+ _.forEach(list.data.brandList, function(val) {
|
|
|
151
|
+ let obj = {
|
|
|
152
|
+ productList: []
|
|
|
153
|
+ };
|
143
|
|
154
|
|
144
|
- if (page <= list.data.pageTotal) {
|
155
|
+ // if (empty(val.productSkn)) {
|
|
|
156
|
+ // continue;
|
|
|
157
|
+ // }
|
|
|
158
|
+ if (val.brandOrShopType === 'brandOrShopType') {
|
|
|
159
|
+ obj = _.assign(obj, {
|
|
|
160
|
+ link: helpers.urlFormat('/product/index/brand', {
|
|
|
161
|
+ shop_id: val.shopId
|
|
|
162
|
+ })
|
|
|
163
|
+ });
|
|
|
164
|
+ } else {
|
|
|
165
|
+ obj = _.assign(obj, {
|
|
|
166
|
+ link: helpers.urlFormat('', {}, val.brandDomain)
|
145
|
|
167
|
|
146
|
- _.forEach(list.data.brandList, function(val) {
|
|
|
147
|
- let obj = {
|
|
|
148
|
- productList: []
|
|
|
149
|
- };
|
168
|
+ });
|
|
|
169
|
+ }
|
150
|
|
170
|
|
151
|
- // if (empty(val.productSkn)) {
|
|
|
152
|
- // continue;
|
|
|
153
|
- // }
|
|
|
154
|
- if (val.brandOrShopType === 'brandOrShopType') {
|
|
|
155
|
obj = _.assign(obj, {
|
171
|
obj = _.assign(obj, {
|
156
|
- link: helpers.urlFormat('/product/index/brand', {
|
|
|
157
|
- shop_id: val.shopId
|
|
|
158
|
- })
|
172
|
+ id: val.brandId,
|
|
|
173
|
+ brandName: val.brandName,
|
|
|
174
|
+ updata: val.newProductNum,
|
|
|
175
|
+ discount: val.productDiscountNum,
|
|
|
176
|
+ brandImg: val.brandIco,
|
|
|
177
|
+ update: val.newProductNum
|
159
|
});
|
178
|
});
|
160
|
- } else {
|
|
|
161
|
- obj = _.assign(obj, {
|
|
|
162
|
- link: helpers.urlFormat('', {}, val.brandDomain)
|
|
|
163
|
|
179
|
|
|
|
180
|
+ _.forEach(val.newProduct, function(data, key) {
|
|
|
181
|
+ obj.productList.push({
|
|
|
182
|
+ link: '/product/' + data.productSkn + '.html', // 商品url改版
|
|
|
183
|
+ imgUrl: data.defaultImages,
|
|
|
184
|
+ price: '¥' + Number(data.marketPrice).toFixed(2),
|
|
|
185
|
+ discount: data.marketPrice > data.salesPrice ? '¥' +
|
|
|
186
|
+ Number(data.salesPrice).toFixed(2) : false,
|
|
|
187
|
+ top3: key < 3 ? 1 : 0
|
|
|
188
|
+ });
|
164
|
});
|
189
|
});
|
165
|
- }
|
|
|
166
|
-
|
|
|
167
|
- obj = _.assign(obj, {
|
|
|
168
|
- id: val.brandId,
|
|
|
169
|
- brandName: val.brandName,
|
|
|
170
|
- updata: val.newProductNum,
|
|
|
171
|
- discount: val.productDiscountNum,
|
|
|
172
|
- brandImg: val.brandIco,
|
|
|
173
|
- update: val.newProductNum
|
|
|
174
|
- });
|
|
|
175
|
|
190
|
|
176
|
- _.forEach(val.newProduct, function(data, key) {
|
|
|
177
|
- obj.productList.push({
|
|
|
178
|
- link: '/product/' + data.productSkn + '.html', // 商品url改版
|
|
|
179
|
- imgUrl: data.defaultImages,
|
|
|
180
|
- price: '¥' + Number(data.marketPrice).toFixed(2),
|
|
|
181
|
- discount: data.marketPrice > data.salesPrice ? '¥' +
|
|
|
182
|
- Number(data.salesPrice).toFixed(2) : false,
|
|
|
183
|
- top3: key < 3 ? 1 : 0
|
|
|
184
|
- });
|
191
|
+ resu.hasFavBrand.push(obj);
|
185
|
});
|
192
|
});
|
186
|
|
193
|
|
187
|
- resu.hasFavBrand.push(obj);
|
|
|
188
|
- });
|
194
|
+ } else {
|
|
|
195
|
+ resu.more = true;
|
|
|
196
|
+ }
|
189
|
|
197
|
|
|
|
198
|
+ return resu;
|
190
|
} else {
|
199
|
} else {
|
191
|
- resu.more = true;
|
200
|
+ logger.error('fav brand code no 200');
|
|
|
201
|
+ return {
|
|
|
202
|
+ total: 0
|
|
|
203
|
+ };
|
192
|
}
|
204
|
}
|
|
|
205
|
+ });
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ favoriteDelete(uid, type, favId) {
|
|
|
209
|
+
|
|
|
210
|
+ return api.get('', {
|
|
|
211
|
+ method: 'app.favorite.cancel',
|
|
|
212
|
+ uid: uid,
|
|
|
213
|
+ type: type,
|
|
|
214
|
+ fav_id: favId
|
|
|
215
|
+ });
|
|
|
216
|
+ }
|
193
|
|
217
|
|
194
|
- return resu;
|
218
|
+ index(uid, page, limit, isbrand) {
|
|
|
219
|
+ if (isbrand) {
|
|
|
220
|
+ return this.favfavBrand(uid, page, limit).then(result=> {
|
|
|
221
|
+ if (result.total === 0) {
|
|
|
222
|
+ result = {nobrandData: 1};
|
|
|
223
|
+ }
|
|
|
224
|
+ return result;
|
|
|
225
|
+ });
|
195
|
} else {
|
226
|
} else {
|
196
|
- logger.error('fav brand code no 200');
|
|
|
197
|
- return {
|
|
|
198
|
- total: 0
|
|
|
199
|
- };
|
227
|
+ return this.favProduct(uid, page, limit).then(result=> {
|
|
|
228
|
+ if (result.total === 0) {
|
|
|
229
|
+ result = {noproductData: 1};
|
|
|
230
|
+ }
|
|
|
231
|
+ return result;
|
|
|
232
|
+ });
|
200
|
}
|
233
|
}
|
201
|
- });
|
|
|
202
|
-};
|
|
|
203
|
-
|
|
|
204
|
-const favoriteDelete = (uid, type, favId) => {
|
|
|
205
|
-
|
|
|
206
|
- return api.get('', {
|
|
|
207
|
- method: 'app.favorite.cancel',
|
|
|
208
|
- uid: uid,
|
|
|
209
|
- type: type,
|
|
|
210
|
- fav_id: favId
|
|
|
211
|
- });
|
|
|
212
|
-};
|
|
|
213
|
-const index = (uid, page, limit, isbrand) => {
|
|
|
214
|
- if (isbrand) {
|
|
|
215
|
- return favfavBrand(uid, page, limit).then(result=> {
|
|
|
216
|
- if (result.total === 0) {
|
|
|
217
|
- result = {nobrandData: 1};
|
|
|
218
|
- }
|
|
|
219
|
- return result;
|
|
|
220
|
- });
|
|
|
221
|
- } else {
|
|
|
222
|
- return favProduct(uid, page, limit).then(result=> {
|
|
|
223
|
- if (result.total === 0) {
|
|
|
224
|
- result = {noproductData: 1};
|
|
|
225
|
- }
|
|
|
226
|
- return result;
|
|
|
227
|
- });
|
|
|
228
|
}
|
234
|
}
|
229
|
-};
|
|
|
230
|
-
|
|
|
231
|
-module.exports = {
|
|
|
232
|
- favProduct,
|
|
|
233
|
- favfavBrand,
|
|
|
234
|
- favoriteDelete,
|
|
|
235
|
- index
|
|
|
236
|
-}; |
235
|
+}
|
|
|
236
|
+
|
|
|
237
|
+module.exports = favoriteIndexModel; |