Authored by 毕凯

Merge branch 'feature/context-api' into 'release/6.6'

Feature/context api

以下接口上下文调用修改
/operations/api/v5/webshare/getShare
app.coupons.couponsSend
app.search.newPromotion
app.query.bundleSkn

See merge request !1366
@@ -22,7 +22,7 @@ const _getPname = (req) => { @@ -22,7 +22,7 @@ const _getPname = (req) => {
22 }; 22 };
23 23
24 exports.index = function(req, res, next) { 24 exports.index = function(req, res, next) {
25 - model.index({ 25 + req.ctx(model).index({
26 code: req.params.code, 26 code: req.params.code,
27 type: stringProcess.paramsFilter(req.query.type), 27 type: stringProcess.paramsFilter(req.query.type),
28 from_page_name: _getPname(req), 28 from_page_name: _getPname(req),
@@ -53,7 +53,7 @@ exports.index = function(req, res, next) { @@ -53,7 +53,7 @@ exports.index = function(req, res, next) {
53 }; 53 };
54 54
55 exports.sidebar = function(req, res, next) { 55 exports.sidebar = function(req, res, next) {
56 - model.index({ 56 + req.ctx(model).index({
57 code: req.params.code 57 code: req.params.code
58 }).then((result) => { 58 }).then((result) => {
59 if (!result) { 59 if (!result) {
@@ -68,7 +68,7 @@ exports.sidebar = function(req, res, next) { @@ -68,7 +68,7 @@ exports.sidebar = function(req, res, next) {
68 68
69 69
70 exports.bottombar = function(req, res, next) { 70 exports.bottombar = function(req, res, next) {
71 - model.index({ 71 + req.ctx(model).index({
72 code: req.params.code 72 code: req.params.code
73 }).then((result) => { 73 }).then((result) => {
74 if (!result) { 74 if (!result) {
@@ -117,7 +117,7 @@ exports.couponSend = (req, res, next) => { @@ -117,7 +117,7 @@ exports.couponSend = (req, res, next) => {
117 return res.jsonp(resultData); 117 return res.jsonp(resultData);
118 } 118 }
119 119
120 - model.couponSend(uid, token).then(result => { 120 + req.ctx(model).couponSend(uid, token).then(result => {
121 res.set({ 121 res.set({
122 'Cache-Control': 'no-cache', 122 'Cache-Control': 'no-cache',
123 Pragma: 'no-cache', 123 Pragma: 'no-cache',
@@ -15,7 +15,7 @@ exports.productLst = function(req, res, next) { @@ -15,7 +15,7 @@ exports.productLst = function(req, res, next) {
15 let getProductList; 15 let getProductList;
16 16
17 if (req.query.maybeLike) { 17 if (req.query.maybeLike) {
18 - getProductList = model.maybeLikeList(Object.assign({ 18 + getProductList = req.ctx(model).maybeLikeList(Object.assign({
19 uid: uid, 19 uid: uid,
20 udid: udid, 20 udid: udid,
21 yh_channel: req.query.yh_channel || (req.cookies._Channel && channels[req.cookies._Channel]) || 1, 21 yh_channel: req.query.yh_channel || (req.cookies._Channel && channels[req.cookies._Channel]) || 1,
@@ -58,7 +58,7 @@ exports.productLst = function(req, res, next) { @@ -58,7 +58,7 @@ exports.productLst = function(req, res, next) {
58 } 58 }
59 } 59 }
60 60
61 - getProductList = model.productLst(params); 61 + getProductList = req.ctx(model).productLst(params);
62 } 62 }
63 63
64 getProductList.then((result) => { 64 getProductList.then((result) => {
@@ -93,7 +93,7 @@ exports.coupon = function(req, res, next) { @@ -93,7 +93,7 @@ exports.coupon = function(req, res, next) {
93 }); 93 });
94 } 94 }
95 95
96 - model.getCoupon({ 96 + req.ctx(model).getCoupon({
97 activity_template_id, 97 activity_template_id,
98 uid 98 uid
99 }).then((result) => { 99 }).then((result) => {
@@ -3,9 +3,8 @@ @@ -3,9 +3,8 @@
3 * Created by yoho on 2016/10/19. 3 * Created by yoho on 2016/10/19.
4 */ 4 */
5 'use strict'; 5 'use strict';
6 -const mRoot = '../models';  
7 -const share = require(`${mRoot}/share`);  
8 const _ = require('lodash'); 6 const _ = require('lodash');
  7 +const shareModel = require('../models/share');
9 8
10 exports.getShareContent = (req, res, next) => { 9 exports.getShareContent = (req, res, next) => {
11 if (!req.query.shareId) { 10 if (!req.query.shareId) {
@@ -22,7 +21,7 @@ exports.getShareContent = (req, res, next) => { @@ -22,7 +21,7 @@ exports.getShareContent = (req, res, next) => {
22 }); 21 });
23 } 22 }
24 23
25 - share.getShareContent({ 24 + req.ctx(shareModel).getShareContent({
26 shareId: req.query.shareId 25 shareId: req.query.shareId
27 }).then(result => { 26 }).then(result => {
28 res.jsonp(result); 27 res.jsonp(result);
@@ -57,8 +57,11 @@ const _getShopGroup = (shopRawData) => { @@ -57,8 +57,11 @@ const _getShopGroup = (shopRawData) => {
57 }); 57 });
58 }; 58 };
59 59
60 -module.exports = {  
61 - index: function(params) { 60 +class featureModel extends global.yoho.BaseModel {
  61 + constructor(ctx) {
  62 + super(ctx);
  63 + }
  64 + index(params) {
62 return Promise.coroutine(function*() { 65 return Promise.coroutine(function*() {
63 if (!params.code) { 66 if (!params.code) {
64 return Promise.resolve({}); 67 return Promise.resolve({});
@@ -134,7 +137,7 @@ module.exports = { @@ -134,7 +137,7 @@ module.exports = {
134 137
135 return data; 138 return data;
136 })(); 139 })();
137 - }, 140 + }
138 141
139 /** 142 /**
140 * 领取优惠券 143 * 领取优惠券
@@ -157,7 +160,7 @@ module.exports = { @@ -157,7 +160,7 @@ module.exports = {
157 }; 160 };
158 } 161 }
159 162
160 - return api.get('', data).then(result => { 163 + return this.get({data}).then(result => {
161 164
162 if (!result) { 165 if (!result) {
163 result.code = 404; 166 result.code = 404;
@@ -167,4 +170,7 @@ module.exports = { @@ -167,4 +170,7 @@ module.exports = {
167 return result; 170 return result;
168 }); 171 });
169 } 172 }
170 -}; 173 +
  174 +}
  175 +
  176 +module.exports = featureModel;
1 'use strict'; 1 'use strict';
2 2
3 -const api = global.yoho.API;  
4 -  
5 let _getProduct = function(o) { 3 let _getProduct = function(o) {
6 return { 4 return {
7 small_sort_id: o.small_sort_id, 5 small_sort_id: o.small_sort_id,
@@ -30,12 +28,16 @@ const gender = { @@ -30,12 +28,16 @@ const gender = {
30 2: '2,3' 28 2: '2,3'
31 }; 29 };
32 30
33 -module.exports = {  
34 - productLst: function(params) {  
35 - return api.get('', Object.assign({ 31 +class individuationModel extends global.yoho.BaseModel {
  32 + constructor(ctx) {
  33 + super(ctx);
  34 + }
  35 + productLst(params) {
  36 + return this.get({
  37 + data: Object.assign({
36 method: 'app.search.newPromotion' 38 method: 'app.search.newPromotion'
37 - }, params), {  
38 - cache: true 39 + }, params),
  40 + param: {cache: true}
39 }).then(res => { 41 }).then(res => {
40 var data = [], 42 var data = [],
41 lst = (res && res.data && res.data.product_list) || []; 43 lst = (res && res.data && res.data.product_list) || [];
@@ -45,9 +47,10 @@ module.exports = { @@ -45,9 +47,10 @@ module.exports = {
45 }); 47 });
46 return data; 48 return data;
47 }); 49 });
48 - },  
49 - maybeLikeList: function(params) {  
50 - return api.get('', { 50 + }
  51 + maybeLikeList(params) {
  52 + return this.get({
  53 + data: {
51 method: 'app.home.newPreference', 54 method: 'app.home.newPreference',
52 uid: params.uid || 0, 55 uid: params.uid || 0,
53 udid: params.udid || 0, 56 udid: params.udid || 0,
@@ -56,8 +59,8 @@ module.exports = { @@ -56,8 +59,8 @@ module.exports = {
56 need_filter: 'null', 59 need_filter: 'null',
57 rec_pos: '100053', 60 rec_pos: '100053',
58 gender: params.gender || gender[params.yh_channel] 61 gender: params.gender || gender[params.yh_channel]
59 - }, {  
60 - cache: true 62 + },
  63 + param: {cache: true}
61 }).then(res => { 64 }).then(res => {
62 var data = [], 65 var data = [],
63 lst = (res && res.data && res.data.product_list) || []; 66 lst = (res && res.data && res.data.product_list) || [];
@@ -67,12 +70,16 @@ module.exports = { @@ -67,12 +70,16 @@ module.exports = {
67 }); 70 });
68 return data; 71 return data;
69 }); 72 });
70 - },  
71 - getCoupon: function(params) {  
72 - return api.get('', Object.assign({ 73 + }
  74 + getCoupon(params) {
  75 + return this.get({
  76 + data: Object.assign({
73 method: 'app.coupons.personalCoupons' 77 method: 'app.coupons.personalCoupons'
74 - }, params), {  
75 - cache: true 78 + }, params),
  79 + param: {cache: true}
76 }); 80 });
77 } 81 }
78 -}; 82 +
  83 +}
  84 +
  85 +module.exports = individuationModel;
1 -/**  
2 - * Created by yoho on 2016/10/19.  
3 - */  
4 'use strict'; 1 'use strict';
5 -const serviceApi = global.yoho.ServiceAPI;  
6 2
7 -/** 3 +class shareModel extends global.yoho.BaseModel {
  4 + constructor(ctx) {
  5 + super(ctx);
  6 + }
  7 +
  8 + /**
8 * 从接口获取 share 内容 9 * 从接口获取 share 内容
9 * @returns {*|Promise.<TResult>} 10 * @returns {*|Promise.<TResult>}
10 */ 11 */
11 -const getShareContent = (params) => {  
12 - return serviceApi.get('operations/api/v5/webshare/getShare', {  
13 - share_id: params.shareId 12 + getShareContent(params) {
  13 + return this.get({
  14 + url: 'operations/api/v5/webshare/getShare',
  15 + data: {share_id: params.shareId},
  16 + api: global.yoho.ServiceAPI,
14 }).then(result => { 17 }).then(result => {
15 return result; 18 return result;
16 }); 19 });
17 -}; 20 + }
  21 +
  22 +}
18 23
19 -module.exports = {  
20 - getShareContent  
21 -}; 24 +module.exports = shareModel;
@@ -15,7 +15,7 @@ const bundleModel = require(`${mRoot}/bundle`); @@ -15,7 +15,7 @@ const bundleModel = require(`${mRoot}/bundle`);
15 * @param next 15 * @param next
16 */ 16 */
17 exports.detail = (req, res, next) => { 17 exports.detail = (req, res, next) => {
18 - bundleModel.detail(req.query, req.yoho.isApp).then(result => { 18 + req.ctx(bundleModel).detail(req.query, req.yoho.isApp).then(result => {
19 if (!result.bundleDatas) { 19 if (!result.bundleDatas) {
20 return next(); 20 return next();
21 } 21 }
@@ -40,7 +40,7 @@ exports.detail = (req, res, next) => { @@ -40,7 +40,7 @@ exports.detail = (req, res, next) => {
40 exports.addToCart = (req, res, next) => { 40 exports.addToCart = (req, res, next) => {
41 let shoppingKey = req.cookies._SPK || ''; 41 let shoppingKey = req.cookies._SPK || '';
42 42
43 - bundleModel.addToCart({ 43 + req.ctx(bundleModel).addToCart({
44 uid: req.user.uid, 44 uid: req.user.uid,
45 activity_id: req.body.activity_id, 45 activity_id: req.body.activity_id,
46 product_sku_list: req.body.product_sku_list, 46 product_sku_list: req.body.product_sku_list,
@@ -4,36 +4,43 @@ @@ -4,36 +4,43 @@
4 'use strict'; 4 'use strict';
5 const utils = '../../../utils'; 5 const utils = '../../../utils';
6 const _ = require('lodash'); 6 const _ = require('lodash');
7 -const api = global.yoho.API;  
8 const helpers = global.yoho.helpers; 7 const helpers = global.yoho.helpers;
9 const productProcess = require(`${utils}/product-process`); 8 const productProcess = require(`${utils}/product-process`);
10 9
11 -/** 10 +class bundleModel extends global.yoho.BaseModel {
  11 + constructor(ctx) {
  12 + super(ctx);
  13 + }
  14 +
  15 + /**
12 * 从接口获取套装数据 16 * 从接口获取套装数据
13 * @private 17 * @private
14 */ 18 */
15 -const getBundleBySkn = (productSkn) => {  
16 - return api.get('', { 19 + getBundleBySkn(productSkn) {
  20 + return this.get({
  21 + data: {
17 method: 'app.query.bundleSkn', 22 method: 'app.query.bundleSkn',
18 product_skn: productSkn 23 product_skn: productSkn
19 - }, {cache: false}).then(result => { 24 + },
  25 + param: {cache: false}
  26 + }).then(result => {
20 return result; 27 return result;
21 }); 28 });
22 -}; 29 + }
23 30
24 -/** 31 + /**
25 * 套装详情页数据 32 * 套装详情页数据
26 * @param params 33 * @param params
27 * @returns {*} 34 * @returns {*}
28 */ 35 */
29 -const detail = (params, isApp) => { 36 + detail(params, isApp) {
30 if (!params.skn && !params.bundle_skn) { 37 if (!params.skn && !params.bundle_skn) {
31 return Promise.resolve({}); 38 return Promise.resolve({});
32 } 39 }
33 let bundleIndex = (params.index || 1); 40 let bundleIndex = (params.index || 1);
34 41
35 --bundleIndex; 42 --bundleIndex;
36 - return getBundleBySkn(params.skn || params.bundle_skn).then(result => { 43 + return this.getBundleBySkn(params.skn || params.bundle_skn).then(result => {
37 if (_.has(result, `data[${bundleIndex}]`)) { 44 if (_.has(result, `data[${bundleIndex}]`)) {
38 let shareInfo = _.get(result, 'data[0].shareInfo', {}); 45 let shareInfo = _.get(result, 'data[0].shareInfo', {});
39 46
@@ -58,18 +65,19 @@ const detail = (params, isApp) => { @@ -58,18 +65,19 @@ const detail = (params, isApp) => {
58 url: shareInfo.url 65 url: shareInfo.url
59 }, 66 },
60 bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}), 67 bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
61 - productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, [])) 68 + productList: productProcess.processProductList(
  69 + _.get(result, `data[${bundleIndex}].productList`, []))
62 }; 70 };
63 } 71 }
64 return {}; 72 return {};
65 }); 73 });
66 -}; 74 + }
67 75
68 -/** 76 + /**
69 * 套餐加入购物车 77 * 套餐加入购物车
70 * @param {*} params 78 * @param {*} params
71 */ 79 */
72 -const addToCart = (params) => { 80 + addToCart(params) {
73 let skuList = params.product_sku_list; 81 let skuList = params.product_sku_list;
74 let finalParams = { 82 let finalParams = {
75 method: 'app.Shopping.addBundle', 83 method: 'app.Shopping.addBundle',
@@ -84,15 +92,15 @@ const addToCart = (params) => { @@ -84,15 +92,15 @@ const addToCart = (params) => {
84 }); 92 });
85 } 93 }
86 94
87 - return api.post('', finalParams, { 95 + return this.post({
  96 + data: finalParams,
  97 + param: {
88 headers: { 98 headers: {
89 'User-Agent': params.userAgent 99 'User-Agent': params.userAgent
90 } 100 }
  101 + }
91 }); 102 });
92 -}; 103 + }
  104 +}
93 105
94 -module.exports = {  
95 - getBundleBySkn,  
96 - detail,  
97 - addToCart  
98 -}; 106 +module.exports = bundleModel;
@@ -241,7 +241,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -241,7 +241,7 @@ module.exports = class extends global.yoho.BaseModel {
241 }), 241 }),
242 this._getCommonConsult(), // eslint-disable-line 242 this._getCommonConsult(), // eslint-disable-line
243 comment.getConsults(result.product_id, 1, 2), 243 comment.getConsults(result.product_id, 1, 2),
244 - bundle.getBundleBySkn(result.product_skn) 244 + this.ctx.req.ctx(bundle).getBundleBySkn(result.product_skn)
245 ]).then((info) => { 245 ]).then((info) => {
246 finalResult = _detailDataPkg(result, data.ua); // eslint-disable-line 246 finalResult = _detailDataPkg(result, data.ua); // eslint-disable-line
247 finalResult.enterStore = info[0]; 247 finalResult.enterStore = info[0];
@@ -728,7 +728,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -728,7 +728,7 @@ module.exports = class extends global.yoho.BaseModel {
728 ]; 728 ];
729 729
730 if (data.bundleType) { 730 if (data.bundleType) {
731 - apiArray.push(bundle.getBundleBySkn(data.productSkn)); 731 + apiArray.push(this.ctx.req.ctx(bundle).getBundleBySkn(data.productSkn));
732 } 732 }
733 733
734 return Promise.all(apiArray).then((res) => { 734 return Promise.all(apiArray).then((res) => {
@@ -112,7 +112,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -112,7 +112,7 @@ module.exports = class extends global.yoho.BaseModel {
112 ]; 112 ];
113 113
114 if (params.bundleType) { 114 if (params.bundleType) {
115 - apiArray.push(bundle.getBundleBySkn(skn)); 115 + apiArray.push(this.ctx.req.ctx(bundle).getBundleBySkn(skn));
116 } 116 }
117 117
118 return Promise.all(apiArray).then(info => { 118 return Promise.all(apiArray).then(info => {