Showing
8 changed files
with
412 additions
and
589 deletions
1 | 'use strict'; | 1 | 'use strict'; |
2 | -const serviceApi = global.yoho.ServiceAPI; | ||
3 | -const api = global.yoho.API; | ||
4 | const helpers = global.yoho.helpers; | 2 | const helpers = global.yoho.helpers; |
5 | const crypto = global.yoho.crypto; | 3 | const crypto = global.yoho.crypto; |
6 | const Promise = require('bluebird'); | 4 | const Promise = require('bluebird'); |
7 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 5 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
8 | const _ = require('lodash'); | 6 | const _ = require('lodash'); |
9 | -const productProcess = require(`${global.utils}/product-process`); | ||
10 | const stdntMrktModel = require('../models/student-market'); | 7 | const stdntMrktModel = require('../models/student-market'); |
11 | 8 | ||
12 | -const userAcquireStatus = (uid, couponIds) => { | ||
13 | - if (couponIds !== '') { | ||
14 | - return api.get('', { | ||
15 | - method: 'app.coupons.userAcquireStatus', | ||
16 | - uid: uid, | ||
17 | - couponIds: couponIds | ||
18 | - }); | ||
19 | - } | ||
20 | -}; | ||
21 | - | ||
22 | -/** | ||
23 | - * 查询商品 | ||
24 | - * @param id | ||
25 | - * @returns {*} | ||
26 | - */ | ||
27 | -const _getRelatedData = (idList) => { | ||
28 | - if (idList !== '') { | ||
29 | - return api.get('', { | ||
30 | - productSkn: idList, | ||
31 | - method: 'h5.product.batch' | ||
32 | - }).then((result) => { | ||
33 | - | ||
34 | - let goods = []; | ||
35 | - | ||
36 | - if (result && result.data && result.data.product_list && result.code === 200) { | ||
37 | - | ||
38 | - _.forEach(result.data.product_list, function(val) { | ||
39 | - | ||
40 | - if (!val.student_price) { | ||
41 | - val.student_price = val.vip2_price; | ||
42 | - } | ||
43 | - }); | ||
44 | - | ||
45 | - goods = productProcess.processProductList(result.data.product_list); | ||
46 | - | ||
47 | - return goods; | ||
48 | - } else { | ||
49 | - return {}; | ||
50 | - } | ||
51 | - }); | ||
52 | - } | ||
53 | -}; | ||
54 | - | ||
55 | exports.index = (req, res, next) => { | 9 | exports.index = (req, res, next) => { |
56 | let code = 'c9b9639ce2884b768cfbc5cf9e68a53f'; | 10 | let code = 'c9b9639ce2884b768cfbc5cf9e68a53f'; |
57 | let uid = req.__USER__.uid; | 11 | let uid = req.__USER__.uid; |
@@ -60,10 +14,7 @@ exports.index = (req, res, next) => { | @@ -60,10 +14,7 @@ exports.index = (req, res, next) => { | ||
60 | '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + | 14 | '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + |
61 | req.__USER__.http + '//m.yohobuy.com/activity/student-market"}}}'; | 15 | req.__USER__.http + '//m.yohobuy.com/activity/student-market"}}}'; |
62 | 16 | ||
63 | - return serviceApi.get('operations/api/v5/resource/get', { | ||
64 | - content_code: code, | ||
65 | - platform: 'iphone' | ||
66 | - }).then((result) => { | 17 | + return req.ctx(stdntMrktModel).index(code).then(result => { |
67 | 18 | ||
68 | let coupons = {}, | 19 | let coupons = {}, |
69 | activities, | 20 | activities, |
@@ -132,8 +83,8 @@ exports.index = (req, res, next) => { | @@ -132,8 +83,8 @@ exports.index = (req, res, next) => { | ||
132 | } | 83 | } |
133 | 84 | ||
134 | return Promise.all([ | 85 | return Promise.all([ |
135 | - userAcquireStatus(uid, couponids.join(',')), | ||
136 | - _getRelatedData(idList.join(','))]) | 86 | + req.ctx(stdntMrktModel).userAcquireStatus(uid, couponids.join(',')), |
87 | + req.ctx(stdntMrktModel)._getRelatedData(idList.join(','))]) | ||
137 | .then(datas => { | 88 | .then(datas => { |
138 | coupons.data = _.get(coupons, 'data', []).map((item)=>{ | 89 | coupons.data = _.get(coupons, 'data', []).map((item)=>{ |
139 | item.status = 1; | 90 | item.status = 1; |
@@ -195,7 +146,7 @@ exports.index = (req, res, next) => { | @@ -195,7 +146,7 @@ exports.index = (req, res, next) => { | ||
195 | * 新版学生营销页面 | 146 | * 新版学生营销页面 |
196 | */ | 147 | */ |
197 | exports.newIndex = (req, res, next) => { | 148 | exports.newIndex = (req, res, next) => { |
198 | - stdntMrktModel.getStudentGoods({ | 149 | + req.ctx(stdntMrktModel).getStudentGoods({ |
199 | limit: req.query.limit || '60', | 150 | limit: req.query.limit || '60', |
200 | stocknumber: req.query.stocknumber || '1' | 151 | stocknumber: req.query.stocknumber || '1' |
201 | }).then(result => { | 152 | }).then(result => { |
@@ -59,9 +59,8 @@ exports.index = (req, res, next) => { | @@ -59,9 +59,8 @@ exports.index = (req, res, next) => { | ||
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | - vipDayModel.getGoods(cate) | 62 | + req.ctx(vipDayModel).getGoods(cate) |
63 | .then(result => { | 63 | .then(result => { |
64 | - // console.log(result.data) | ||
65 | if (result.code !== 200) { | 64 | if (result.code !== 200) { |
66 | return Promise.reject('error'); | 65 | return Promise.reject('error'); |
67 | } | 66 | } |
@@ -86,7 +85,7 @@ exports.crazyWheel = (req, res, next) => { | @@ -86,7 +85,7 @@ exports.crazyWheel = (req, res, next) => { | ||
86 | return res.redirect('/activity/vip-day'); | 85 | return res.redirect('/activity/vip-day'); |
87 | } | 86 | } |
88 | 87 | ||
89 | - vipDayModel.getJoinNum(1).then(result => { | 88 | + req.ctx(vipDayModel).getJoinNum(1).then(result => { |
90 | let joins = result && result.data || 0; | 89 | let joins = result && result.data || 0; |
91 | 90 | ||
92 | res.render('vip-day/crazy-wheel', { | 91 | res.render('vip-day/crazy-wheel', { |
@@ -107,8 +106,8 @@ exports.crazyLuck = (req, res, next) => { | @@ -107,8 +106,8 @@ exports.crazyLuck = (req, res, next) => { | ||
107 | res.locals.width750 = true; | 106 | res.locals.width750 = true; |
108 | 107 | ||
109 | co(function* () { | 108 | co(function* () { |
110 | - let coins = yield vipDayModel.getCoins(uid); | ||
111 | - let joinNum = yield vipDayModel.getJoinNum(2); | 109 | + let coins = yield req.ctx(vipDayModel).getCoins(uid); |
110 | + let joinNum = yield req.ctx(vipDayModel).getJoinNum(2); | ||
112 | 111 | ||
113 | coins = (coins && coins.data && coins.data.total) || 0; | 112 | coins = (coins && coins.data && coins.data.total) || 0; |
114 | joinNum = (joinNum && joinNum.data) || 0; | 113 | joinNum = (joinNum && joinNum.data) || 0; |
@@ -130,7 +129,7 @@ exports.crazyLuck = (req, res, next) => { | @@ -130,7 +129,7 @@ exports.crazyLuck = (req, res, next) => { | ||
130 | exports.signin = (req, res, next) => { | 129 | exports.signin = (req, res, next) => { |
131 | let uid = req.user.uid; | 130 | let uid = req.user.uid; |
132 | 131 | ||
133 | - return vipDayModel.signin(uid) | 132 | + return req.ctx(vipDayModel).signin(uid) |
134 | .then(function(result) { | 133 | .then(function(result) { |
135 | res.json(result); | 134 | res.json(result); |
136 | }) | 135 | }) |
@@ -148,7 +147,7 @@ exports.saveMsg = (req, res, next) => { | @@ -148,7 +147,7 @@ exports.saveMsg = (req, res, next) => { | ||
148 | }) | 147 | }) |
149 | .then(nick_name => { | 148 | .then(nick_name => { |
150 | // 2. save message | 149 | // 2. save message |
151 | - return vipDayModel.saveMsg(uid, nick_name, content); | 150 | + return req.ctx(vipDayModel).saveMsg(uid, nick_name, content); |
152 | }) | 151 | }) |
153 | .then(result => { | 152 | .then(result => { |
154 | if (result.code === 200 && result.data === 1) { | 153 | if (result.code === 200 && result.data === 1) { |
@@ -164,7 +163,7 @@ exports.saveMsg = (req, res, next) => { | @@ -164,7 +163,7 @@ exports.saveMsg = (req, res, next) => { | ||
164 | exports.fetchMsg = (req, res, next) => { | 163 | exports.fetchMsg = (req, res, next) => { |
165 | let uid = req.user.uid || req.query.uid || 0; | 164 | let uid = req.user.uid || req.query.uid || 0; |
166 | 165 | ||
167 | - vipDayModel.queryLeaveWordsList(uid).then(result => { | 166 | + req.ctx(vipDayModel).queryLeaveWordsList(uid).then(result => { |
168 | return res.json(result); | 167 | return res.json(result); |
169 | }).catch(next); | 168 | }).catch(next); |
170 | }; | 169 | }; |
@@ -174,7 +173,7 @@ exports.wheelResult = (req, res, next) => { | @@ -174,7 +173,7 @@ exports.wheelResult = (req, res, next) => { | ||
174 | let uid = req.user.uid; | 173 | let uid = req.user.uid; |
175 | let prize_type = 2; | 174 | let prize_type = 2; |
176 | 175 | ||
177 | - return vipDayModel.addPrizeLog(uid, prize_type).then(result => { | 176 | + return req.ctx(vipDayModel).addPrizeLog(uid, prize_type).then(result => { |
178 | return res.json(result); | 177 | return res.json(result); |
179 | }).catch(next); | 178 | }).catch(next); |
180 | 179 | ||
@@ -188,7 +187,7 @@ exports.luckResult = (req, res, next) => { | @@ -188,7 +187,7 @@ exports.luckResult = (req, res, next) => { | ||
188 | 187 | ||
189 | let handle = co(function* (uid) { | 188 | let handle = co(function* (uid) { |
190 | // 查询用户 有货币 | 189 | // 查询用户 有货币 |
191 | - let r1 = yield vipDayModel.getCoins(uid); | 190 | + let r1 = yield req.ctx(vipDayModel).getCoins(uid); |
192 | 191 | ||
193 | if (r1.code !== 200) { | 192 | if (r1.code !== 200) { |
194 | return { | 193 | return { |
@@ -205,7 +204,7 @@ exports.luckResult = (req, res, next) => { | @@ -205,7 +204,7 @@ exports.luckResult = (req, res, next) => { | ||
205 | } | 204 | } |
206 | 205 | ||
207 | // 得出 中奖结果 | 206 | // 得出 中奖结果 |
208 | - let result = yield vipDayModel.addPrizeLog(uid, prize_type); | 207 | + let result = yield req.ctx(vipDayModel).addPrizeLog(uid, prize_type); |
209 | 208 | ||
210 | if (result.code !== 200) { | 209 | if (result.code !== 200) { |
211 | return result; | 210 | return result; |
@@ -224,7 +223,7 @@ exports.luckResultCollect = (req, res, next) => { | @@ -224,7 +223,7 @@ exports.luckResultCollect = (req, res, next) => { | ||
224 | let uid = req.user.uid; | 223 | let uid = req.user.uid; |
225 | let prize_type = 1; | 224 | let prize_type = 1; |
226 | 225 | ||
227 | - return vipDayModel.queryPrizeLog(uid, prize_type).then(result => { | 226 | + return req.ctx(vipDayModel).queryPrizeLog(uid, prize_type).then(result => { |
228 | if (result.code === 200 && result.data) { | 227 | if (result.code === 200 && result.data) { |
229 | result.data = result.data.filter(award => award.prizeValue); | 228 | result.data = result.data.filter(award => award.prizeValue); |
230 | } | 229 | } |
@@ -19,7 +19,7 @@ function humanNum_wan(num) { | @@ -19,7 +19,7 @@ function humanNum_wan(num) { | ||
19 | exports.checkIsStudent = (req, res, next) => { | 19 | exports.checkIsStudent = (req, res, next) => { |
20 | let uid = req.user.uid || req.query.uid; | 20 | let uid = req.user.uid || req.query.uid; |
21 | 21 | ||
22 | - vipDayModel.checkIsStudent(uid).then(result => { | 22 | + req.ctx(vipDayModel).checkIsStudent(uid).then(result => { |
23 | res.json(result); | 23 | res.json(result); |
24 | }).catch(next); | 24 | }).catch(next); |
25 | }; | 25 | }; |
@@ -73,13 +73,13 @@ exports.index = (req, res, next) => { | @@ -73,13 +73,13 @@ exports.index = (req, res, next) => { | ||
73 | 73 | ||
74 | // 获取学生信息 | 74 | // 获取学生信息 |
75 | if (uid) { | 75 | if (uid) { |
76 | - let result = yield vipDayModel.checkIsStudent(uid); | 76 | + let result = yield req.ctx(vipDayModel).checkIsStudent(uid); |
77 | 77 | ||
78 | result.data && Number(result.data.isStudent) === 1 && (isStudent = true); | 78 | result.data && Number(result.data.isStudent) === 1 && (isStudent = true); |
79 | } | 79 | } |
80 | 80 | ||
81 | // 获取商品信息 | 81 | // 获取商品信息 |
82 | - let goodList = yield vipDayModel.getGoods(cate); | 82 | + let goodList = yield req.ctx(vipDayModel).getGoods(cate); |
83 | 83 | ||
84 | res.render('vip-day/vip-day1028/index', { | 84 | res.render('vip-day/vip-day1028/index', { |
85 | title: '会员日活动', | 85 | title: '会员日活动', |
@@ -101,7 +101,7 @@ exports.crazyWheel = (req, res, next) => { | @@ -101,7 +101,7 @@ exports.crazyWheel = (req, res, next) => { | ||
101 | res.locals.page = 'vipday-wheel10'; | 101 | res.locals.page = 'vipday-wheel10'; |
102 | res.locals.width750 = true; | 102 | res.locals.width750 = true; |
103 | 103 | ||
104 | - vipDayModel.getJoinNum(1).then(result => { | 104 | + req.ctx(vipDayModel).getJoinNum(1).then(result => { |
105 | let joins = result && result.data || 0; | 105 | let joins = result && result.data || 0; |
106 | 106 | ||
107 | res.render('vip-day/vip-day1028/crazy-wheel', { | 107 | res.render('vip-day/vip-day1028/crazy-wheel', { |
@@ -122,8 +122,8 @@ exports.crazyLuck = (req, res, next) => { | @@ -122,8 +122,8 @@ exports.crazyLuck = (req, res, next) => { | ||
122 | res.locals.width750 = true; | 122 | res.locals.width750 = true; |
123 | 123 | ||
124 | co(function*() { | 124 | co(function*() { |
125 | - let coins = yield vipDayModel.getCoins(uid); | ||
126 | - let joinNum = yield vipDayModel.getJoinNum(2); | 125 | + let coins = yield req.ctx(vipDayModel).getCoins(uid); |
126 | + let joinNum = yield req.ctx(vipDayModel).getJoinNum(2); | ||
127 | 127 | ||
128 | coins = (coins && coins.data && coins.data.total) || 0; | 128 | coins = (coins && coins.data && coins.data.total) || 0; |
129 | joinNum = (joinNum && joinNum.data) || 0; | 129 | joinNum = (joinNum && joinNum.data) || 0; |
@@ -145,7 +145,7 @@ exports.crazyLuck = (req, res, next) => { | @@ -145,7 +145,7 @@ exports.crazyLuck = (req, res, next) => { | ||
145 | exports.signin = (req, res, next) => { | 145 | exports.signin = (req, res, next) => { |
146 | let uid = req.user.uid; | 146 | let uid = req.user.uid; |
147 | 147 | ||
148 | - return vipDayModel.signin(uid) | 148 | + return req.ctx(vipDayModel).signin(uid) |
149 | .then(function(result) { | 149 | .then(function(result) { |
150 | res.json(result); | 150 | res.json(result); |
151 | }) | 151 | }) |
@@ -156,7 +156,7 @@ exports.wheelResult = (req, res, next) => { | @@ -156,7 +156,7 @@ exports.wheelResult = (req, res, next) => { | ||
156 | let uid = req.user.uid || req.query.uid; | 156 | let uid = req.user.uid || req.query.uid; |
157 | let prize_type = 3; | 157 | let prize_type = 3; |
158 | 158 | ||
159 | - return vipDayModel.addPrizeLog(uid, prize_type).then(result => { | 159 | + return req.ctx(vipDayModel).addPrizeLog(uid, prize_type).then(result => { |
160 | return res.json(result); | 160 | return res.json(result); |
161 | }).catch(next); | 161 | }).catch(next); |
162 | 162 | ||
@@ -170,7 +170,7 @@ exports.luckResult = (req, res, next) => { | @@ -170,7 +170,7 @@ exports.luckResult = (req, res, next) => { | ||
170 | 170 | ||
171 | let handle = co(function*(uid) { | 171 | let handle = co(function*(uid) { |
172 | // 查询用户 有货币 | 172 | // 查询用户 有货币 |
173 | - let r1 = yield vipDayModel.getCoins(uid); | 173 | + let r1 = yield req.ctx(vipDayModel).getCoins(uid); |
174 | 174 | ||
175 | if (r1.code !== 200) { | 175 | if (r1.code !== 200) { |
176 | return { | 176 | return { |
@@ -187,7 +187,7 @@ exports.luckResult = (req, res, next) => { | @@ -187,7 +187,7 @@ exports.luckResult = (req, res, next) => { | ||
187 | } | 187 | } |
188 | 188 | ||
189 | // 得出 中奖结果 | 189 | // 得出 中奖结果 |
190 | - let result = yield vipDayModel.addPrizeLog(uid, prize_type); | 190 | + let result = yield req.ctx(vipDayModel).addPrizeLog(uid, prize_type); |
191 | 191 | ||
192 | if (result.code !== 200) { | 192 | if (result.code !== 200) { |
193 | return result; | 193 | return result; |
@@ -206,7 +206,7 @@ exports.luckResultCollect = (req, res, next) => { | @@ -206,7 +206,7 @@ exports.luckResultCollect = (req, res, next) => { | ||
206 | let uid = req.user.uid; | 206 | let uid = req.user.uid; |
207 | let prize_type = 3; | 207 | let prize_type = 3; |
208 | 208 | ||
209 | - return vipDayModel.queryPrizeLog(uid, prize_type).then(result => { | 209 | + return req.ctx(vipDayModel).queryPrizeLog(uid, prize_type).then(result => { |
210 | if (result.code === 200 && result.data) { | 210 | if (result.code === 200 && result.data) { |
211 | result.data = result.data.filter(award => award.prizeValue); | 211 | result.data = result.data.filter(award => award.prizeValue); |
212 | } | 212 | } |
@@ -2,70 +2,73 @@ | @@ -2,70 +2,73 @@ | ||
2 | const _ = require('lodash'); | 2 | const _ = require('lodash'); |
3 | const helpers = global.yoho.helpers; | 3 | const helpers = global.yoho.helpers; |
4 | 4 | ||
5 | -const _getProductBySkns = function(productObj, extraParams) { | ||
6 | - return this.get({ | ||
7 | - data: { | ||
8 | - productSkn: productObj.defaultSkns, | ||
9 | - method: 'h5.product.batch' | ||
10 | - }, | ||
11 | - param: { | ||
12 | - cache: true | ||
13 | - } | ||
14 | - }).then((result) => { | ||
15 | - productObj.defaultPros = []; | ||
16 | - if (result && result.data && result.data.product_list && result.code === 200) { | ||
17 | - result.data.product_list.forEach(function(val) { | ||
18 | - var obj = { | ||
19 | - producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${extraParams.from_page_name}","from_page_param":"${extraParams.from_page_param}"}}`, // eslint-disable-line | ||
20 | - productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'), | ||
21 | - productname: val.product_name, | ||
22 | - vipprice: val.vip_price, | ||
23 | - saleprice: val.sales_price, | ||
24 | - marketprice: val.sales_price === val.market_price ? '' : val.market_price, | ||
25 | - brandname: val.brand_name, | ||
26 | - product_skn: val.product_skn | ||
27 | - }; | ||
28 | - | ||
29 | - if (val.shop_id) { | ||
30 | - obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type || "1"},"is_red_shop":${val.is_red_shop || 1}}}`; // eslint-disable-line | ||
31 | - } else { | ||
32 | - obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line | ||
33 | - } | ||
34 | - | ||
35 | - productObj.defaultPros.push(obj); | ||
36 | - }); | ||
37 | - } | ||
38 | - }); | ||
39 | -}; | ||
40 | - | ||
41 | -/** | ||
42 | - * 获取店铺组店铺数据 | ||
43 | - */ | ||
44 | -const _getShopGroup = (shopRawData) => { | ||
45 | - return this.get({ | ||
46 | - data: { | ||
47 | - method: 'app.shops.batchGetShops', | ||
48 | - shop_ids: shopRawData.defaultShopIds | ||
49 | - } | ||
50 | - }).then(result => { | ||
51 | - let renderData = _.get(result, 'data', []); | 5 | +class featureModel extends global.yoho.BaseModel { |
6 | + constructor(ctx) { | ||
7 | + super(ctx); | ||
8 | + } | ||
52 | 9 | ||
53 | - _.forEach(renderData, shop => { | ||
54 | - let displayStyle = _.get(shopRawData, 'displayStyle', '0'); | 10 | + _getProductBySkns(productObj, extraParams) { |
11 | + return this.get({ | ||
12 | + data: { | ||
13 | + productSkn: productObj.defaultSkns, | ||
14 | + method: 'h5.product.batch' | ||
15 | + }, | ||
16 | + param: { | ||
17 | + cache: true | ||
18 | + } | ||
19 | + }).then((result) => { | ||
20 | + productObj.defaultPros = []; | ||
21 | + if (result && result.data && result.data.product_list && result.code === 200) { | ||
22 | + result.data.product_list.forEach(function(val) { | ||
23 | + var obj = { | ||
24 | + producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${extraParams.from_page_name}","from_page_param":"${extraParams.from_page_param}"}}`, // eslint-disable-line | ||
25 | + productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'), // eslint-disable-line | ||
26 | + productname: val.product_name, | ||
27 | + vipprice: val.vip_price, | ||
28 | + saleprice: val.sales_price, | ||
29 | + marketprice: val.sales_price === val.market_price ? '' : val.market_price, | ||
30 | + brandname: val.brand_name, | ||
31 | + product_skn: val.product_skn | ||
32 | + }; | ||
33 | + | ||
34 | + if (val.shop_id) { | ||
35 | + obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type || "1"},"is_red_shop":${val.is_red_shop || 1}}}`; // eslint-disable-line | ||
36 | + } else { | ||
37 | + obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line | ||
38 | + } | ||
55 | 39 | ||
56 | - shop.picture = displayStyle === '0' ? shop.pic_popular : shop.shop_logo; | ||
57 | - shop.href = `//m.yohobuy.com/product/shop?domain=${shop.shop_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${shop.shops_id},"shop_template_type":${shop.shop_template_type || "1"},"is_red_shop":${shop.is_red_shop || 1}}}`; // eslint-disable-line | 40 | + productObj.defaultPros.push(obj); |
41 | + }); | ||
42 | + } | ||
58 | }); | 43 | }); |
44 | + } | ||
59 | 45 | ||
60 | - shopRawData.renderData = renderData; | ||
61 | - }); | ||
62 | -}; | 46 | + /** |
47 | + * 获取店铺组店铺数据 | ||
48 | + */ | ||
49 | + _getShopGroup(shopRawData) { | ||
50 | + return this.get({ | ||
51 | + data: { | ||
52 | + method: 'app.shops.batchGetShops', | ||
53 | + shop_ids: shopRawData.defaultShopIds | ||
54 | + } | ||
55 | + }).then(result => { | ||
56 | + let renderData = _.get(result, 'data', []); | ||
63 | 57 | ||
64 | -class featureModel extends global.yoho.BaseModel { | ||
65 | - constructor(ctx) { | ||
66 | - super(ctx); | 58 | + _.forEach(renderData, shop => { |
59 | + let displayStyle = _.get(shopRawData, 'displayStyle', '0'); | ||
60 | + | ||
61 | + shop.picture = displayStyle === '0' ? shop.pic_popular : shop.shop_logo; | ||
62 | + shop.href = `//m.yohobuy.com/product/shop?domain=${shop.shop_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${shop.shops_id},"shop_template_type":${shop.shop_template_type || "1"},"is_red_shop":${shop.is_red_shop || 1}}}`; // eslint-disable-line | ||
63 | + }); | ||
64 | + | ||
65 | + shopRawData.renderData = renderData; | ||
66 | + }); | ||
67 | } | 67 | } |
68 | + | ||
68 | index(params) { | 69 | index(params) { |
70 | + let that = this; | ||
71 | + | ||
69 | return Promise.coroutine(function*() { | 72 | return Promise.coroutine(function*() { |
70 | if (!params.code) { | 73 | if (!params.code) { |
71 | return Promise.resolve({}); | 74 | return Promise.resolve({}); |
@@ -76,7 +79,7 @@ class featureModel extends global.yoho.BaseModel { | @@ -76,7 +79,7 @@ class featureModel extends global.yoho.BaseModel { | ||
76 | let shopGroups = []; | 79 | let shopGroups = []; |
77 | 80 | ||
78 | if (params.type === 'preview') { // 开发/预览模式 | 81 | if (params.type === 'preview') { // 开发/预览模式 |
79 | - data = yield this.get({ | 82 | + data = yield that.get({ |
80 | data: { | 83 | data: { |
81 | method: 'app.activity.template.ignoreCache', | 84 | method: 'app.activity.template.ignoreCache', |
82 | activity_id: params.code | 85 | activity_id: params.code |
@@ -87,7 +90,7 @@ class featureModel extends global.yoho.BaseModel { | @@ -87,7 +90,7 @@ class featureModel extends global.yoho.BaseModel { | ||
87 | }); | 90 | }); |
88 | } else { | 91 | } else { |
89 | // 生产模式 | 92 | // 生产模式 |
90 | - data = yield this.get({ | 93 | + data = yield that.get({ |
91 | data: { | 94 | data: { |
92 | method: 'app.activity.template', | 95 | method: 'app.activity.template', |
93 | activity_id: params.code | 96 | activity_id: params.code |
@@ -105,7 +108,7 @@ class featureModel extends global.yoho.BaseModel { | @@ -105,7 +108,7 @@ class featureModel extends global.yoho.BaseModel { | ||
105 | data.floors.forEach(function(f) { | 108 | data.floors.forEach(function(f) { |
106 | if (f.component && f.component[0] && | 109 | if (f.component && f.component[0] && |
107 | f.component[0].type === 'productGroup' && f.component[0].defaultSkns) { | 110 | f.component[0].type === 'productGroup' && f.component[0].defaultSkns) { |
108 | - sknsArr.push(_getProductBySkns(f.component[0], { | 111 | + sknsArr.push(that._getProductBySkns(f.component[0], { |
109 | from_page_name: params.from_page_name, | 112 | from_page_name: params.from_page_name, |
110 | from_page_param: params.from_page_param | 113 | from_page_param: params.from_page_param |
111 | })); | 114 | })); |
@@ -125,7 +128,7 @@ class featureModel extends global.yoho.BaseModel { | @@ -125,7 +128,7 @@ class featureModel extends global.yoho.BaseModel { | ||
125 | 128 | ||
126 | // 新增店铺组 | 129 | // 新增店铺组 |
127 | if (_.get(f, 'component[0].type') === 'shopGroup') { | 130 | if (_.get(f, 'component[0].type') === 'shopGroup') { |
128 | - shopGroups.push(_getShopGroup(f.component[0])); | 131 | + shopGroups.push(that._getShopGroup(f.component[0])); |
129 | } | 132 | } |
130 | 133 | ||
131 | if (_.get(f, 'type') === 'bottombar') { | 134 | if (_.get(f, 'type') === 'bottombar') { |
@@ -10,19 +10,72 @@ | @@ -10,19 +10,72 @@ | ||
10 | 10 | ||
11 | const utils = '../../../utils'; | 11 | const utils = '../../../utils'; |
12 | const productProcess = require(`${utils}/product-process`); | 12 | const productProcess = require(`${utils}/product-process`); |
13 | -const api = global.yoho.API; | ||
14 | const _ = require('lodash'); | 13 | const _ = require('lodash'); |
14 | +const serviceAPI = global.yoho.ServiceAPI; | ||
15 | 15 | ||
16 | -const getStudentGoods = (params) => { | ||
17 | - return api.get('', { | ||
18 | - method: 'app.student.aggBrand', | ||
19 | - limit: params.limit, | ||
20 | - stocknumber: params.stocknumber, | ||
21 | - }).then(result => { | ||
22 | - return productProcess.processProductList(_.get(result, 'data.product_list', [])); | ||
23 | - }); | ||
24 | -}; | 16 | +module.exports = class extends global.yoho.BaseModel { |
17 | + constructor(ctx) { | ||
18 | + super(ctx); | ||
19 | + } | ||
20 | + | ||
21 | + index(code) { | ||
22 | + return this.get({ | ||
23 | + api: serviceAPI, | ||
24 | + url: 'operations/api/v5/resource/get', | ||
25 | + data: { | ||
26 | + content_code: code, | ||
27 | + platform: 'iphone' | ||
28 | + } | ||
29 | + }); | ||
30 | + } | ||
31 | + | ||
32 | + getStudentGoods(params) { | ||
33 | + return this.get({ | ||
34 | + data: { | ||
35 | + method: 'app.student.aggBrand', | ||
36 | + limit: params.limit, | ||
37 | + stocknumber: params.stocknumber, | ||
38 | + } | ||
39 | + }).then(result => { | ||
40 | + return productProcess.processProductList(_.get(result, 'data.product_list', [])); | ||
41 | + }); | ||
42 | + } | ||
43 | + | ||
44 | + userAcquireStatus(uid, couponIds) { | ||
45 | + return this.get({ | ||
46 | + data: { | ||
47 | + method: 'app.coupons.userAcquireStatus', | ||
48 | + uid: uid, | ||
49 | + couponIds: couponIds | ||
50 | + } | ||
51 | + }); | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * 查询商品 | ||
56 | + * @param id | ||
57 | + * @returns {*} | ||
58 | + */ | ||
59 | + _getRelatedData(idList) { | ||
60 | + return this.get({ | ||
61 | + data: { | ||
62 | + productSkn: idList, | ||
63 | + method: 'h5.product.batch' | ||
64 | + } | ||
65 | + }).then(result => { | ||
66 | + | ||
67 | + if (result && result.data && result.data.product_list && result.code === 200) { | ||
68 | + | ||
69 | + _.forEach(result.data.product_list, function(val) { | ||
70 | + if (!val.student_price) { | ||
71 | + val.student_price = val.vip2_price; | ||
72 | + } | ||
73 | + }); | ||
25 | 74 | ||
26 | -module.exports = { | ||
27 | - getStudentGoods | 75 | + return productProcess.processProductList(result.data.product_list); |
76 | + } else { | ||
77 | + return {}; | ||
78 | + } | ||
79 | + }); | ||
80 | + } | ||
28 | }; | 81 | }; |
@@ -2,125 +2,154 @@ | @@ -2,125 +2,154 @@ | ||
2 | 'use strict'; | 2 | 'use strict'; |
3 | const url = require('url'); | 3 | const url = require('url'); |
4 | const _ = require('lodash'); | 4 | const _ = require('lodash'); |
5 | -const API = global.yoho.API; | ||
6 | const serviceAPI = global.yoho.ServiceAPI; | 5 | const serviceAPI = global.yoho.ServiceAPI; |
7 | const utils = require(global.utils + '/product-process'); | 6 | const utils = require(global.utils + '/product-process'); |
8 | const helpers = global.yoho.helpers; | 7 | const helpers = global.yoho.helpers; |
9 | 8 | ||
10 | -// 签到 | ||
11 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md | ||
12 | -exports.signin = (uid)=> { | ||
13 | - | ||
14 | - return serviceAPI.post('/activity/UserdaySigninController/signin', {uid}); | ||
15 | -}; | ||
16 | - | ||
17 | -// 写留言 | ||
18 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BF%9D%E5%AD%98%E7%94%A8%E6%88%B7%E7%95%99%E8%A8%80.md | ||
19 | -exports.saveMsg = (uid, nick_name, content) => { | ||
20 | - | ||
21 | - return serviceAPI.post('/activity/UserdayLeaveWordsController/addLeaveWords', { | ||
22 | - uid, | ||
23 | - nick_name, | ||
24 | - content | ||
25 | - }); | ||
26 | -}; | ||
27 | - | ||
28 | -exports.queryLeaveWordsList = (uid) => { | ||
29 | - | ||
30 | - return serviceAPI.get('/activity/UserdayLeaveWordsController/queryLeaveWordsList', {uid}); | ||
31 | -}; | 9 | +module.exports = class extends global.yoho.BaseModel { |
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + // 签到 | ||
15 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md | ||
16 | + signin(uid) { | ||
17 | + return this.get({ | ||
18 | + api: serviceAPI, | ||
19 | + url: '/activity/UserdaySigninController/signin', | ||
20 | + data: {uid} | ||
21 | + }); | ||
22 | + } | ||
23 | + | ||
24 | + // 写留言 | ||
25 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BF%9D%E5%AD%98%E7%94%A8%E6%88%B7%E7%95%99%E8%A8%80.md | ||
26 | + saveMsg(uid, nick_name, content) { | ||
27 | + return this.get({ | ||
28 | + api: serviceAPI, | ||
29 | + url: '/activity/UserdayLeaveWordsController/addLeaveWords', | ||
30 | + data: { | ||
31 | + uid, | ||
32 | + nick_name, | ||
33 | + content | ||
34 | + } | ||
35 | + }); | ||
36 | + } | ||
37 | + | ||
38 | + queryLeaveWordsList(uid) { | ||
39 | + return this.get({ | ||
40 | + api: serviceAPI, | ||
41 | + url: '/activity/UserdayLeaveWordsController/queryLeaveWordsList', | ||
42 | + data: { | ||
43 | + uid | ||
44 | + } | ||
45 | + }); | ||
46 | + } | ||
47 | + | ||
48 | + | ||
49 | + // 拼手气大转盘 抽奖 | ||
50 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md | ||
51 | + addPrizeLog(uid, prize_type) { | ||
52 | + return this.get({ | ||
53 | + api: serviceAPI, | ||
54 | + url: '/activity/UserdayPrizeLogController/addPrizeLog', | ||
55 | + data: { | ||
56 | + uid, | ||
57 | + prize_type | ||
58 | + } | ||
59 | + }); | ||
60 | + } | ||
61 | + | ||
62 | + // 查询 中奖纪录 | ||
63 | + queryPrizeLog(uid, prize_type) { | ||
64 | + return this.get({ | ||
65 | + api: serviceAPI, | ||
66 | + url: '/activity/UserdayPrizeLogController/queryPrizeLog', | ||
67 | + data: { | ||
68 | + uid, | ||
69 | + prize_type | ||
70 | + } | ||
71 | + }); | ||
72 | + } | ||
32 | 73 | ||
33 | 74 | ||
34 | -// 拼手气大转盘 抽奖 | ||
35 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md | ||
36 | -exports.addPrizeLog = (uid, prize_type) => { | 75 | + // 获取用户的有货币 |
76 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81 | ||
77 | + getCoins(uid) { | ||
78 | + return this.get({ | ||
79 | + data: { | ||
80 | + method: 'app.yohocoin.total', | ||
81 | + uid | ||
82 | + } | ||
83 | + }); | ||
84 | + } | ||
85 | + | ||
86 | + // 获取抽奖人数 | ||
87 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md | ||
88 | + getJoinNum(prize_type) { | ||
89 | + return this.get({ | ||
90 | + api: serviceAPI, | ||
91 | + url: '/activity/UserdayPrizeLogController/queryPrizeLogNum', | ||
92 | + data: { | ||
93 | + prize_type | ||
94 | + } | ||
95 | + }); | ||
96 | + } | ||
37 | 97 | ||
38 | - return serviceAPI.post('/activity/UserdayPrizeLogController/addPrizeLog', { | ||
39 | - uid, | ||
40 | - prize_type | ||
41 | - }); | ||
42 | -}; | 98 | + /** |
99 | + * cate [object Object] | ||
100 | + */ | ||
101 | + getGoods(cate) { | ||
102 | + let skns = ''; | ||
103 | + let cates = Object.keys(cate); | ||
43 | 104 | ||
44 | -// 查询 中奖纪录 | ||
45 | -exports.queryPrizeLog = (uid, prize_type) => { | 105 | + _.forEach(cate, function(val) { |
106 | + skns = skns.concat(',').concat(val.join(',')); | ||
107 | + }); | ||
46 | 108 | ||
47 | - return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLog', { | ||
48 | - uid, | ||
49 | - prize_type | ||
50 | - }); | ||
51 | -}; | 109 | + skns = skns.slice(1); |
52 | 110 | ||
111 | + return this.get({ | ||
112 | + data: { | ||
113 | + method: 'h5.product.batch', | ||
114 | + productSkn: skns | ||
115 | + } | ||
116 | + }).then(result => { | ||
117 | + if (result.code !== 200) { | ||
118 | + return { | ||
119 | + code: result.code, | ||
120 | + message: result.message | ||
121 | + }; | ||
122 | + } | ||
123 | + let productList = utils.processProductList(result.data.product_list); | ||
124 | + let data = {}; | ||
53 | 125 | ||
54 | -// 获取用户的有货币 | ||
55 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81 | ||
56 | -exports.getCoins = uid => { | ||
57 | - return API.get('', { | ||
58 | - method: 'app.yohocoin.total', | ||
59 | - uid | ||
60 | - }); | ||
61 | -}; | 126 | + productList.forEach(product=> { |
127 | + let skn = product.productSkn; | ||
128 | + let imgSrc = url.parse(product.defaultImages || ''); | ||
62 | 129 | ||
63 | -// 获取抽奖人数 | ||
64 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md | ||
65 | -exports.getJoinNum = prize_type => { | 130 | + product.defaultImages = ['//', imgSrc.hostname, imgSrc.pathname].join(''); |
66 | 131 | ||
67 | - return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLogNum', { | ||
68 | - prize_type, | ||
69 | - }); | ||
70 | -}; | 132 | + product.url = helpers.appUrlFormat(product.url, 'go.productDetail', { |
133 | + product_skn: skn | ||
134 | + }); | ||
71 | 135 | ||
72 | -/** | ||
73 | - * cate [object Object] | ||
74 | - */ | ||
75 | -exports.getGoods = cate => { | ||
76 | - let skns = ''; | ||
77 | - let cates = Object.keys(cate); | 136 | + for (let c of cates) { |
137 | + let index = cate[c].indexOf(skn); | ||
78 | 138 | ||
79 | - _.forEach(cate, function(val) { | ||
80 | - skns = skns.concat(',').concat(val.join(',')); | ||
81 | - }); | 139 | + if (index !== -1) { |
140 | + cate[c].splice(index, 1); | ||
82 | 141 | ||
83 | - skns = skns.slice(1); | 142 | + data[c] || (data[c] = []); |
143 | + data[c].push(product); | ||
144 | + break; | ||
145 | + } | ||
146 | + } | ||
147 | + }); | ||
84 | 148 | ||
85 | - return API.get('', { | ||
86 | - method: 'h5.product.batch', | ||
87 | - productSkn: skns | ||
88 | - }).then(result => { | ||
89 | - if (result.code !== 200) { | ||
90 | return { | 149 | return { |
91 | - code: result.code, | ||
92 | - message: result.message | 150 | + code: 200, |
151 | + data | ||
93 | }; | 152 | }; |
94 | - } | ||
95 | - let productList = utils.processProductList(result.data.product_list); | ||
96 | - let data = {}; | ||
97 | - | ||
98 | - productList.forEach(product=> { | ||
99 | - let skn = product.productSkn; | ||
100 | - let imgSrc = url.parse(product.defaultImages || ''); | ||
101 | - | ||
102 | - product.defaultImages = ['//', imgSrc.hostname, imgSrc.pathname].join(''); | ||
103 | - | ||
104 | - product.url = helpers.appUrlFormat(product.url, 'go.productDetail', { | ||
105 | - product_skn: skn | ||
106 | - }); | ||
107 | - | ||
108 | - for (let c of cates) { | ||
109 | - let index = cate[c].indexOf(skn); | ||
110 | - | ||
111 | - if (index !== -1) { | ||
112 | - cate[c].splice(index, 1); | ||
113 | - | ||
114 | - data[c] || (data[c] = []); | ||
115 | - data[c].push(product); | ||
116 | - break; | ||
117 | - } | ||
118 | - } | ||
119 | }); | 153 | }); |
120 | - | ||
121 | - return { | ||
122 | - code: 200, | ||
123 | - data | ||
124 | - }; | ||
125 | - }); | 154 | + } |
126 | }; | 155 | }; |
@@ -2,122 +2,152 @@ | @@ -2,122 +2,152 @@ | ||
2 | 'use strict'; | 2 | 'use strict'; |
3 | const url = require('url'); | 3 | const url = require('url'); |
4 | const _ = require('lodash'); | 4 | const _ = require('lodash'); |
5 | -const API = global.yoho.API; | ||
6 | const serviceAPI = global.yoho.ServiceAPI; | 5 | const serviceAPI = global.yoho.ServiceAPI; |
7 | const utils = require(global.utils + '/product-process'); | 6 | const utils = require(global.utils + '/product-process'); |
8 | const helpers = global.yoho.helpers; | 7 | const helpers = global.yoho.helpers; |
9 | 8 | ||
10 | -// 签到 | ||
11 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md | ||
12 | -exports.signin = (uid)=> { | ||
13 | - | ||
14 | - return serviceAPI.post('/activity/UserdaySigninController/signin', {uid}); | ||
15 | -}; | ||
16 | - | ||
17 | -exports.queryLeaveWordsList = (uid) => { | ||
18 | - | ||
19 | - return serviceAPI.get('/activity/UserdayLeaveWordsController/queryLeaveWordsList', {uid}); | ||
20 | -}; | 9 | +module.exports = class extends global.yoho.BaseModel { |
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + // 签到 | ||
15 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md | ||
16 | + signin(uid) { | ||
17 | + return this.get({ | ||
18 | + api: serviceAPI, | ||
19 | + url: '/activity/UserdaySigninController/signin', | ||
20 | + data: { | ||
21 | + uid: uid | ||
22 | + } | ||
23 | + }); | ||
24 | + } | ||
25 | + | ||
26 | + queryLeaveWordsList(uid) { | ||
27 | + return this.get({ | ||
28 | + api: serviceAPI, | ||
29 | + url: '/activity/UserdayLeaveWordsController/queryLeaveWordsList', | ||
30 | + data: { | ||
31 | + uid: uid | ||
32 | + } | ||
33 | + }); | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + // 拼手气大转盘 抽奖 | ||
38 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md | ||
39 | + addPrizeLog(uid, prize_type) { | ||
40 | + return this.get({ | ||
41 | + api: serviceAPI, | ||
42 | + url: '/activity/UserdayPrizeLogController/addPrizeLog', | ||
43 | + data: { | ||
44 | + uid, | ||
45 | + prize_type | ||
46 | + } | ||
47 | + }); | ||
48 | + } | ||
49 | + | ||
50 | + // 查询 中奖纪录 | ||
51 | + queryPrizeLog(uid, prize_type) { | ||
52 | + return this.get({ | ||
53 | + api: serviceAPI, | ||
54 | + url: '/activity/UserdayPrizeLogController/queryPrizeLog', | ||
55 | + data: { | ||
56 | + uid, | ||
57 | + prize_type | ||
58 | + } | ||
59 | + }); | ||
60 | + } | ||
21 | 61 | ||
22 | 62 | ||
23 | -// 拼手气大转盘 抽奖 | ||
24 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md | ||
25 | -exports.addPrizeLog = (uid, prize_type) => { | 63 | + // 获取用户的有货币 |
64 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81 | ||
65 | + getCoins(uid) { | ||
66 | + return this.get({ | ||
67 | + data: { | ||
68 | + method: 'app.yohocoin.total', | ||
69 | + uid | ||
70 | + } | ||
71 | + }); | ||
72 | + } | ||
73 | + | ||
74 | + // 获取抽奖人数 | ||
75 | + // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md | ||
76 | + getJoinNum(prize_type) { | ||
77 | + return this.get({ | ||
78 | + api: serviceAPI, | ||
79 | + url: '/activity/UserdayPrizeLogController/queryPrizeLogNum', | ||
80 | + data: { | ||
81 | + prize_type | ||
82 | + } | ||
83 | + }); | ||
84 | + } | ||
26 | 85 | ||
27 | - return serviceAPI.post('/activity/UserdayPrizeLogController/addPrizeLog', { | ||
28 | - uid, | ||
29 | - prize_type | ||
30 | - }); | ||
31 | -}; | 86 | + /** |
87 | + * cate [object Object] | ||
88 | + */ | ||
89 | + getGoods(cate) { | ||
90 | + let skns = ''; | ||
91 | + let cates = Object.keys(cate); | ||
32 | 92 | ||
33 | -// 查询 中奖纪录 | ||
34 | -exports.queryPrizeLog = (uid, prize_type) => { | 93 | + _.forEach(cate, function(val) { |
94 | + skns = skns.concat(',').concat(val.join(',')); | ||
95 | + }); | ||
35 | 96 | ||
36 | - return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLog', { | ||
37 | - uid, | ||
38 | - prize_type | ||
39 | - }); | ||
40 | -}; | 97 | + skns = skns.slice(1); |
41 | 98 | ||
99 | + return this.get({ | ||
100 | + data: { | ||
101 | + method: 'h5.product.batch', | ||
102 | + productSkn: skns | ||
103 | + } | ||
104 | + }).then(result => { | ||
105 | + if (result.code !== 200) { | ||
106 | + return { | ||
107 | + code: result.code, | ||
108 | + message: result.message | ||
109 | + }; | ||
110 | + } | ||
111 | + let productList = utils.processProductList(result.data.product_list); | ||
112 | + let data = {}; | ||
42 | 113 | ||
43 | -// 获取用户的有货币 | ||
44 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81 | ||
45 | -exports.getCoins = uid => { | ||
46 | - return API.get('', { | ||
47 | - method: 'app.yohocoin.total', | ||
48 | - uid | ||
49 | - }); | ||
50 | -}; | 114 | + productList.forEach(product=> { |
115 | + let skn = product.product_skn; | ||
116 | + let imgSrc = url.parse(product.default_images || ''); | ||
51 | 117 | ||
52 | -// 获取抽奖人数 | ||
53 | -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md | ||
54 | -exports.getJoinNum = prize_type => { | 118 | + product.default_images = ['//', imgSrc.hostname, imgSrc.pathname].join(''); |
55 | 119 | ||
56 | - return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLogNum', { | ||
57 | - prize_type, | ||
58 | - }); | ||
59 | -}; | 120 | + product.url = helpers.appUrlFormat(product.url, 'go.productDetail', { |
121 | + product_skn: skn | ||
122 | + }); | ||
60 | 123 | ||
61 | -/** | ||
62 | - * cate [object Object] | ||
63 | - */ | ||
64 | -exports.getGoods = cate => { | ||
65 | - let skns = ''; | ||
66 | - let cates = Object.keys(cate); | 124 | + for (let c of cates) { |
125 | + let index = cate[c].indexOf(skn); | ||
67 | 126 | ||
68 | - _.forEach(cate, function(val) { | ||
69 | - skns = skns.concat(',').concat(val.join(',')); | ||
70 | - }); | 127 | + if (index !== -1) { |
128 | + cate[c].splice(index, 1); | ||
71 | 129 | ||
72 | - skns = skns.slice(1); | 130 | + data[c] || (data[c] = []); |
131 | + data[c].push(product); | ||
132 | + break; | ||
133 | + } | ||
134 | + } | ||
135 | + }); | ||
73 | 136 | ||
74 | - return API.get('', { | ||
75 | - method: 'h5.product.batch', | ||
76 | - productSkn: skns | ||
77 | - }).then(result => { | ||
78 | - if (result.code !== 200) { | ||
79 | return { | 137 | return { |
80 | - code: result.code, | ||
81 | - message: result.message | 138 | + code: 200, |
139 | + data | ||
82 | }; | 140 | }; |
83 | - } | ||
84 | - let productList = utils.processProductList(result.data.product_list); | ||
85 | - let data = {}; | ||
86 | - | ||
87 | - productList.forEach(product=> { | ||
88 | - let skn = product.product_skn; | ||
89 | - let imgSrc = url.parse(product.default_images || ''); | ||
90 | - | ||
91 | - product.default_images = ['//', imgSrc.hostname, imgSrc.pathname].join(''); | ||
92 | - | ||
93 | - product.url = helpers.appUrlFormat(product.url, 'go.productDetail', { | ||
94 | - product_skn: skn | ||
95 | - }); | ||
96 | - | ||
97 | - for (let c of cates) { | ||
98 | - let index = cate[c].indexOf(skn); | ||
99 | - | ||
100 | - if (index !== -1) { | ||
101 | - cate[c].splice(index, 1); | ||
102 | - | ||
103 | - data[c] || (data[c] = []); | ||
104 | - data[c].push(product); | ||
105 | - break; | ||
106 | - } | 141 | + }); |
142 | + } | ||
143 | + | ||
144 | + // 判断是否学生 | ||
145 | + checkIsStudent(uid) { | ||
146 | + return this.get({ | ||
147 | + data: { | ||
148 | + method: 'app.student.checkIsStudent', | ||
149 | + uid: uid, | ||
107 | } | 150 | } |
108 | }); | 151 | }); |
109 | - | ||
110 | - return { | ||
111 | - code: 200, | ||
112 | - data | ||
113 | - }; | ||
114 | - }); | ||
115 | -}; | ||
116 | - | ||
117 | -// 判断是否学生 | ||
118 | -exports.checkIsStudent = uid => { | ||
119 | - return API.get('', { | ||
120 | - method: 'app.student.checkIsStudent', | ||
121 | - uid: uid, | ||
122 | - }); | 152 | + } |
123 | }; | 153 | }; |
1 | -/** | ||
2 | - * 新品到着 models | ||
3 | - * @author: wsl<shuiling.wang@yoho.cn> | ||
4 | - * @date: 2016/7/28 | ||
5 | - */ | ||
6 | - | ||
7 | -'use strict'; | ||
8 | -const utils = '../../../utils'; | ||
9 | -const logger = global.yoho.logger; | ||
10 | -const _ = require('lodash'); | ||
11 | -const contentCode = require('../../../config/content-code'); | ||
12 | -const resourcesProcess = require(`${utils}/resources-process`); | ||
13 | -const searchProcess = require(`${utils}/search-process`); | ||
14 | -const productProcess = require(`${utils}/product-process`); | ||
15 | -const serviceAPI = global.yoho.ServiceAPI; | ||
16 | -const api = global.yoho.API; | ||
17 | - | ||
18 | -module.exports = class extends global.yoho.BaseModel { | ||
19 | - constructor(ctx) { | ||
20 | - super(ctx); | ||
21 | - } | ||
22 | - | ||
23 | - /** | ||
24 | - * TODO: remove | ||
25 | - * 商品搜索接口请求 | ||
26 | - * @param {[object]} params | ||
27 | - * @return {[array]} | ||
28 | - */ | ||
29 | - _searchGoods(params) { | ||
30 | - let method = 'app.search.newProduct'; | ||
31 | - | ||
32 | - // 排除基本筛选项默认值为0的对象 | ||
33 | - for (let str in params) { | ||
34 | - if (str !== 'order' && params[str] === '0' || params[str] === null) { | ||
35 | - delete params[str]; | ||
36 | - } | ||
37 | - } | ||
38 | - | ||
39 | - params.yh_channel = searchProcess.getChannelType(params.channel); | ||
40 | - | ||
41 | - delete params.channel; | ||
42 | - | ||
43 | - params = _.assign({ | ||
44 | - limit: '60' | ||
45 | - }, params); | ||
46 | - | ||
47 | - params.order = params.order === '0' ? 's_t_desc' : 's_t_asc'; | ||
48 | - | ||
49 | - return api.get('', _.assign({ | ||
50 | - method: method | ||
51 | - }, params), { | ||
52 | - cache: true | ||
53 | - }); | ||
54 | - } | ||
55 | - | ||
56 | - /** | ||
57 | - * 获取新品到着的焦点图资源数据 | ||
58 | - */ | ||
59 | - getNewFocus(channel) { | ||
60 | - return serviceAPI.get('operations/api/v5/resource/get', { | ||
61 | - content_code: contentCode.new[channel] | ||
62 | - }, { | ||
63 | - cache: true | ||
64 | - }).then((result) => { | ||
65 | - if (result && result.code === 200) { | ||
66 | - return resourcesProcess(result.data); | ||
67 | - } else { | ||
68 | - logger.error('get newGoods banner return code is not 200'); | ||
69 | - return []; | ||
70 | - } | ||
71 | - }); | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * TODO remove | ||
76 | - * 获取商品数据 | ||
77 | - */ | ||
78 | - getSearchData(params) { | ||
79 | - return this._searchGoods(params).then((result) => { | ||
80 | - if (result && result.code === 200) { | ||
81 | - let newList = {}; | ||
82 | - | ||
83 | - newList.list = productProcess.processProductList(result.data.product_list || [], { | ||
84 | - showTags: true, | ||
85 | - showSimilar: true | ||
86 | - }); | ||
87 | - | ||
88 | - if (parseInt(params.page, 10) === 1) { | ||
89 | - newList.total = result.data.total; | ||
90 | - } | ||
91 | - | ||
92 | - return newList; | ||
93 | - } else { | ||
94 | - logger.error('get product search api return code is not 200'); | ||
95 | - return []; | ||
96 | - } | ||
97 | - }); | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | - * TODO remove | ||
102 | - * 获取筛选数据 | ||
103 | - * @param {[object]} params | ||
104 | - * @return {[array]} | ||
105 | - */ | ||
106 | - getFilterData(params) { | ||
107 | - return this._searchGoods(params).then((result) => { | ||
108 | - if (result && result.code === 200) { | ||
109 | - return productProcess.processFilter(result.data.filter || []); | ||
110 | - } else { | ||
111 | - logger.error('get filter data api return code is not 200'); | ||
112 | - return []; | ||
113 | - } | ||
114 | - }); | ||
115 | - } | ||
116 | - | ||
117 | - /** | ||
118 | - * method=app.newproduct.recshop 推荐店铺 | ||
119 | - * http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md | ||
120 | - */ | ||
121 | - indexData(uid, channel, limit, page) { | ||
122 | - let yh_channel = searchProcess.getChannelType(channel); | ||
123 | - | ||
124 | - limit = limit || 20; | ||
125 | - page = page || 1; | ||
126 | - | ||
127 | - let params = { | ||
128 | - method: 'app.newproduct.recshop', | ||
129 | - yh_channel, | ||
130 | - contentCode: contentCode.newV2[channel], | ||
131 | - limit, | ||
132 | - page, | ||
133 | - uid | ||
134 | - }; | ||
135 | - | ||
136 | - return api.get('', params, {cache: true}) | ||
137 | - .then(result=> { | ||
138 | - let shopData = _.get(result, 'data', {}); | ||
139 | - | ||
140 | - return shopData; | ||
141 | - }) | ||
142 | - .catch(() => {}); | ||
143 | - } | ||
144 | - | ||
145 | - | ||
146 | - /** | ||
147 | - * method=app.newproduct.recbrand 推荐品牌 | ||
148 | - * http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md | ||
149 | - */ | ||
150 | - recbrand(uid, channel, limit, page) { | ||
151 | - let yh_channel = searchProcess.getChannelType(channel); | ||
152 | - | ||
153 | - limit = limit || 20; | ||
154 | - page = page || 1; | ||
155 | - | ||
156 | - let params = { | ||
157 | - method: 'app.newproduct.recbrand', | ||
158 | - yh_channel, | ||
159 | - limit, | ||
160 | - page, | ||
161 | - uid | ||
162 | - }; | ||
163 | - | ||
164 | - return api.get('', params, {cache: true}) | ||
165 | - .then(result => { | ||
166 | - let data = _.get(result, 'data', {}); | ||
167 | - | ||
168 | - return data; | ||
169 | - }) | ||
170 | - .catch(() => {}); | ||
171 | - } | ||
172 | - | ||
173 | - newGoodsAPI(params) { | ||
174 | - let method = 'app.newproduct.reclist'; | ||
175 | - | ||
176 | - // 排除基本筛选项默认值为0的对象 | ||
177 | - for (let str in params) { | ||
178 | - if ((str !== 'order' && params[str] === '0') || params[str] === null) { | ||
179 | - delete params[str]; | ||
180 | - } | ||
181 | - } | ||
182 | - | ||
183 | - params.yh_channel = searchProcess.getChannelType(params.channel); | ||
184 | - | ||
185 | - delete params.channel; | ||
186 | - | ||
187 | - params = _.assign({ | ||
188 | - limit: '60' | ||
189 | - }, params); | ||
190 | - | ||
191 | - return api.get('', _.assign({ | ||
192 | - method: method | ||
193 | - }, params), { | ||
194 | - cache: true | ||
195 | - }); | ||
196 | - } | ||
197 | - | ||
198 | - /** | ||
199 | - * method:app.newproduct.reclist 新品上架 | ||
200 | - * http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md | ||
201 | - */ | ||
202 | - reclist(uid, channel, searchOptions) { | ||
203 | - let params = Object.assign({}, {uid, channel}, searchOptions); | ||
204 | - | ||
205 | - return this.newGoodsAPI(params).then(result => { | ||
206 | - if (result && result.code === 200) { | ||
207 | - let newList = { | ||
208 | - channel: channel | ||
209 | - }; | ||
210 | - | ||
211 | - newList.list = productProcess.processProductList(result.data.product_list || [], {showTags: true}); | ||
212 | - | ||
213 | - if (parseInt(params.page, 10) === 1) { | ||
214 | - newList.total = result.data.total; | ||
215 | - newList.pageTotal = result.data.page_total; | ||
216 | - } | ||
217 | - | ||
218 | - return newList; | ||
219 | - } else { | ||
220 | - logger.error('get product search api return code is not 200'); | ||
221 | - return []; | ||
222 | - } | ||
223 | - }); | ||
224 | - } | ||
225 | - | ||
226 | - reclistFilter(uid, channel) { | ||
227 | - let params = Object.assign({}, {uid, channel}); | ||
228 | - | ||
229 | - return this.newGoodsAPI(params).then(result => { | ||
230 | - if (result && result.code === 200) { | ||
231 | - return productProcess.processFilter(result.data.filter || []); | ||
232 | - } else { | ||
233 | - logger.error('get filter data api return code is not 200'); | ||
234 | - return []; | ||
235 | - } | ||
236 | - }); | ||
237 | - } | ||
238 | - | ||
239 | - filterDataApi(params) { | ||
240 | - return this._searchGoods(params); | ||
241 | - } | ||
242 | -}; |
-
Please register or login to post a comment