From 0040faba5243d2fb5122651edc7a51d3e0b6b088 Mon Sep 17 00:00:00 2001 From: 陈峰 <feng.chen@yoho.cn> Date: Fri, 10 Mar 2017 09:55:27 +0800 Subject: [PATCH] 移除serviceApi --- apps/cart/controllers/order.js | 4 ++-- apps/cart/models/address.js | 40 ++++++++++++++++++++++++++++++++++++++++ apps/cart/models/cart.js | 2 +- apps/cart/models/shopping.js | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ apps/cart/models/user.js | 30 ++++++++++++++++++++++++++++++ apps/serverAPI/order/shopping.js | 289 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- apps/serverAPI/user/address.js | 40 ---------------------------------------- apps/serverAPI/user/index.js | 30 ------------------------------ 8 files changed, 362 insertions(+), 362 deletions(-) create mode 100644 apps/cart/models/address.js create mode 100644 apps/cart/models/shopping.js create mode 100644 apps/cart/models/user.js delete mode 100644 apps/serverAPI/order/shopping.js delete mode 100644 apps/serverAPI/user/address.js delete mode 100644 apps/serverAPI/user/index.js diff --git a/apps/cart/controllers/order.js b/apps/cart/controllers/order.js index 4e58fba..0d9af7a 100644 --- a/apps/cart/controllers/order.js +++ b/apps/cart/controllers/order.js @@ -4,8 +4,8 @@ const helpers = global.yoho.helpers; const co = require('bluebird').coroutine; const cartModel = require('../models/cart'); const headerModel = require('../../../doraemon/models/header'); -const userModel = require('../../serverAPI/user'); -const addressModel = require('../../serverAPI/user/address'); +const userModel = require('../models/user'); +const addressModel = require('../models/address'); const orderModel = require('../models/order'); const crypto = global.yoho.crypto; const authcode = require(global.utils + '/authcode'); diff --git a/apps/cart/models/address.js b/apps/cart/models/address.js new file mode 100644 index 0000000..2df5b11 --- /dev/null +++ b/apps/cart/models/address.js @@ -0,0 +1,40 @@ +'use strict'; + +// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; + +const api = global.yoho.API; +const crypto = global.yoho.crypto; + +/** + * 地址数据 + * @param uid + * @return + */ +exports.addressData = (uid) => { + let params = { + method: 'app.address.gethidden', + uid + }; + + let options = { + cache: false + }; + + return api.get('', params, options) + .then( + result => { + if (result.code === 200) { + // 加密address_id + result.data.forEach(address => { + address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); + }); + } + + return result; + } + , + () => { + return {code: 500, data: [], message: '地址获取失败'}; + } + ); +}; diff --git a/apps/cart/models/cart.js b/apps/cart/models/cart.js index ff7c4c7..21e0544 100644 --- a/apps/cart/models/cart.js +++ b/apps/cart/models/cart.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const helpers = global.yoho.helpers; const paymentProcess = require(global.utils + '/payment-process'); -const shoppingAPI = require('../../serverAPI/order/shopping'); +const shoppingAPI = require('./shopping'); const logger = global.yoho.logger; /** diff --git a/apps/cart/models/shopping.js b/apps/cart/models/shopping.js new file mode 100644 index 0000000..09623c5 --- /dev/null +++ b/apps/cart/models/shopping.js @@ -0,0 +1,289 @@ +'use strict'; +const _ = require('lodash'); +const api = global.yoho.API; + +const privateKeyList = { + android: 'fd4ad5fcfa0de589ef238c0e7331b585', + iphone: 'a85bb0674e08986c6b115d5e3a4884fa', + ipad: 'ad9fcda2e679cf9229e37feae2cdcf80', + web: '0ed29744ed318fd28d2c07985d3ba633', + h5: 'fd4ad5fcfa0de589ef238c0e7331b585' +}; + +/** + * 购物车结算 + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md + * @param int $uid 用户ID + * @param string $cartType 购物车类型,ordinary表示普通购物车 + * @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用 + * @param string $skuList 购买限购商品时需要传递的参数 + * @return see doc + */ +exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => { + if (!activityInfo) { + activityInfo = null; + } + + let param = { + method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment', + enable_red_envelopes: 0, // h5不返回红包 + cart_type: cartType, + yoho_coin_mode: isUseYohoCoin, + uid: uid + }; + + // 购买限购商品时需要传递product_sku_list参数 + if (!_.isEmpty(skuList)) { + param.product_sku_list = JSON.stringify(skuList); + } + + // 购买套装和量贩商品时数据处理 + if (activityInfo) { + param.activity_id = activityInfo.activity_id; + param.product_sku_list = JSON.stringify(activityInfo.product_sku_list); + } + + return api.get('', param, {cache: false}); +}; + +/** + * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理 + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md + * @param int $uid 用户ID + * @param string $cartType 购物车类型,ordinary表示普通购物车 + * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 + * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 + * @param string $couponCode 优惠券码 + * @param mixed $yohoCoin 使用的有货币数量 + * @param string $skuList 购买限购商品时需要传递的参数 + * @return see doc + * + * + * Note: + * 1. 大多数情况下,调用完此接口,请显示的调用 utils/payment-process.js@yohoCoinCompute; + * 2. 除非同时调用app.Shopping.payment 与该接口,用改接口的data值替换app.Shopping.payment相关值, + * 显示调用utils/payment-process.js@tranformPayment(他会帮你调yohoCoinCompute)处理payment的data; + */ +exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => { + if (!activityInfo) { + activityInfo = null; + } + + let param = { + method: activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute', + cart_type: cartType, + delivery_way: deliveWay, + payment_type: paymentType, + uid: uid + }; + + if (couponCode) { + param.coupon_code = couponCode; + } + + if (yohoCoin) { + param.use_yoho_coin = yohoCoin; + } + + if (!_.isEmpty(skuList) && !activityInfo) { + param.product_sku_list = JSON.stringify(skuList); + } + + // 购买套餐商品需要的数据 + if (activityInfo) { + param.activity_id = activityInfo.activity_id; + param.product_sku_list = JSON.stringify(activityInfo.product_sku_list); + } + + return api.get('', param, {code: 200}); +}; + +/** + * 校验电子票 + * @param int $uid + * @param int $productSku + * @param int $buyNumber + * @param int $useYohoCoin + * @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币 + * @return array + * @author sefon 2016-7-2 18:12:30 + */ +exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) => { + if (!useYohoCoin) { + useYohoCoin = 0; + } + + if (!yohoCoinMode) { + yohoCoinMode = true; + } + + let params = { + method: 'app.shopping.ticket', + uid: uid, + product_sku: productSku, + buy_number: buyNumber, + use_yoho_coin: useYohoCoin + }; + + if (!yohoCoinMode) { + _.assign(params, { + yoho_coin_mode: 0 + }); + } + + return api.get('', params, {code: 200}); +}; + +/** + * 购物车结算--提交结算信息 + * + * @param int $uid 用户ID + * @param int $addressId 地址ID + * @param int $cartType 购物车类型ID + * @param int $deliveryTime 寄送时间ID + * @param int $deliveryWay 寄送方式ID + * @param array $invoices 发票参数数组 + * @param int $paymentId 支付方式ID + * @param int $paymentType 支付类型ID + * @param string $remark 留言 + * @param string $couponCode 优惠券码 + * @param mixed $yohoCoin 使用的有货币数量或为空 + * @param string $skuList 购买限购商品时需要传递的参数 + * @param string $qhyUnion 友盟有关信息 + * @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息 + * @param $times + * @param null $activityInfo 套餐信息 + * @param isWechat 是否是微信商城 + * @return array 接口返回的数据 + */ +exports.orderSub = (uid, addressId, cartType, deliveryTime, + deliveryWay, invoices, paymentId, paymentType, remark, couponCode, + yohoCoin, skuList, qhyUnion, userAgent, times, activityInfo, ip, isWechat) => { + if (!activityInfo) { + activityInfo = null; + } + + let params = { + private_key: privateKeyList.h5, + method: activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit', + address_id: addressId, + cart_type: cartType, + delivery_time: deliveryTime, + delivery_way: deliveryWay, + payment_id: paymentId, + payment_type: paymentType, + remark: remark, + uid: uid + }; + + /* tar add 161130 结算优化 */ + if (times === 2 || times === '2') { + params.is_continue_buy = 'Y'; + } else { + params.is_continue_buy = 'N'; + } + + if (invoices.invoices_type_id) { + // 发票内容id--图书:1 + params.invoice_content = invoices.invoices_type_id; + } + + if (invoices.invoices_type) { + // 数字类型 发票类型 纸质 1 ,电子 2 + params.invoices_type = invoices.invoices_type; + } + + if (invoices.receiverMobile) { + // 发票人手机 + params.receiverMobile = invoices.receiverMobile; + } + + if (invoices.invoices_title) { + // 发票抬头 OR 填写单位名称,这二个是一个意思,只是叫法不一样 + params.invoices_title = invoices.invoices_title; + } + + if (couponCode) { + params.coupon_code = couponCode; + } + + if (yohoCoin) { + params.use_yoho_coin = yohoCoin; + } + + // 购买限购商品时需要传递product_sku_list参数 + if (skuList && !activityInfo) { + params.product_sku_list = JSON.stringify(skuList); + } + + // 购买套餐商品需要的数据 + if (activityInfo) { + params.activity_id = activityInfo.activity_id; + params.product_sku_list = JSON.stringify(activityInfo.product_sku_list); // TODO 检查 JSON 是否正常 + } + + // 友盟有关信息的传递 + if (qhyUnion) { + params.qhy_union = qhyUnion; + } + + // 是否是微信商城 + if (isWechat) { + params.client_type = 'wechat'; + } + + return api.post('', params, { + headers: { + 'X-Forwarded-For': ip || '', + 'User-Agent': userAgent + } + }); +}; + + +/** + * 获取用户可用的优惠券张数 + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md + * @param uid int 用户uid + * @return see doc + */ +exports.getValidCouponCount = uid => { + let param = { + method: 'app.Shopping.countUsableCoupon', + uid + }; + + return api.get('', param); +}; + + +/** + * 获取用户优惠券列表,可用和不可用 + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md + * @param uid int 用户uid + * @return see doc + */ +exports.listCoupon = uid => { + let param = { + method: 'app.Shopping.listCoupon', + uid + }; + + return api.get('', param); +}; + +/** + * 购物车结算--使用优惠券 + * @param uid int 用户uid + * @param couponCode string 优惠券代码 + * @return + */ +exports.useCoupon = (uid, couponCode) => { + let param = { + method: 'app.Shopping.useCoupon', + coupon_code: couponCode, + uid + }; + + return api.get('', param); +}; diff --git a/apps/cart/models/user.js b/apps/cart/models/user.js new file mode 100644 index 0000000..4145683 --- /dev/null +++ b/apps/cart/models/user.js @@ -0,0 +1,30 @@ +'use strict'; +const api = global.yoho.API; + + + +/** + * 获取用户信息 + * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/addUserprofile.md + * @param uid 用户id + * @return + */ +exports.queryProfile = (uid) => { + let params = { + method: 'app.passport.profile', + uid + }; + + let options = { + cache: true + }; + + return api.get('', params, options); +}; + +exports.addressTextData = (uid) => { + return api.get('', { + method: 'app.address.get', + uid: uid + }); +}; diff --git a/apps/serverAPI/order/shopping.js b/apps/serverAPI/order/shopping.js deleted file mode 100644 index 09623c5..0000000 --- a/apps/serverAPI/order/shopping.js +++ /dev/null @@ -1,289 +0,0 @@ -'use strict'; -const _ = require('lodash'); -const api = global.yoho.API; - -const privateKeyList = { - android: 'fd4ad5fcfa0de589ef238c0e7331b585', - iphone: 'a85bb0674e08986c6b115d5e3a4884fa', - ipad: 'ad9fcda2e679cf9229e37feae2cdcf80', - web: '0ed29744ed318fd28d2c07985d3ba633', - h5: 'fd4ad5fcfa0de589ef238c0e7331b585' -}; - -/** - * 购物车结算 - * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md - * @param int $uid 用户ID - * @param string $cartType 购物车类型,ordinary表示普通购物车 - * @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用 - * @param string $skuList 购买限购商品时需要传递的参数 - * @return see doc - */ -exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => { - if (!activityInfo) { - activityInfo = null; - } - - let param = { - method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment', - enable_red_envelopes: 0, // h5不返回红包 - cart_type: cartType, - yoho_coin_mode: isUseYohoCoin, - uid: uid - }; - - // 购买限购商品时需要传递product_sku_list参数 - if (!_.isEmpty(skuList)) { - param.product_sku_list = JSON.stringify(skuList); - } - - // 购买套装和量贩商品时数据处理 - if (activityInfo) { - param.activity_id = activityInfo.activity_id; - param.product_sku_list = JSON.stringify(activityInfo.product_sku_list); - } - - return api.get('', param, {cache: false}); -}; - -/** - * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理 - * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md - * @param int $uid 用户ID - * @param string $cartType 购物车类型,ordinary表示普通购物车 - * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 - * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 - * @param string $couponCode 优惠券码 - * @param mixed $yohoCoin 使用的有货币数量 - * @param string $skuList 购买限购商品时需要传递的参数 - * @return see doc - * - * - * Note: - * 1. 大多数情况下,调用完此接口,请显示的调用 utils/payment-process.js@yohoCoinCompute; - * 2. 除非同时调用app.Shopping.payment 与该接口,用改接口的data值替换app.Shopping.payment相关值, - * 显示调用utils/payment-process.js@tranformPayment(他会帮你调yohoCoinCompute)处理payment的data; - */ -exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => { - if (!activityInfo) { - activityInfo = null; - } - - let param = { - method: activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute', - cart_type: cartType, - delivery_way: deliveWay, - payment_type: paymentType, - uid: uid - }; - - if (couponCode) { - param.coupon_code = couponCode; - } - - if (yohoCoin) { - param.use_yoho_coin = yohoCoin; - } - - if (!_.isEmpty(skuList) && !activityInfo) { - param.product_sku_list = JSON.stringify(skuList); - } - - // 购买套餐商品需要的数据 - if (activityInfo) { - param.activity_id = activityInfo.activity_id; - param.product_sku_list = JSON.stringify(activityInfo.product_sku_list); - } - - return api.get('', param, {code: 200}); -}; - -/** - * 校验电子票 - * @param int $uid - * @param int $productSku - * @param int $buyNumber - * @param int $useYohoCoin - * @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币 - * @return array - * @author sefon 2016-7-2 18:12:30 - */ -exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) => { - if (!useYohoCoin) { - useYohoCoin = 0; - } - - if (!yohoCoinMode) { - yohoCoinMode = true; - } - - let params = { - method: 'app.shopping.ticket', - uid: uid, - product_sku: productSku, - buy_number: buyNumber, - use_yoho_coin: useYohoCoin - }; - - if (!yohoCoinMode) { - _.assign(params, { - yoho_coin_mode: 0 - }); - } - - return api.get('', params, {code: 200}); -}; - -/** - * 购物车结算--提交结算信息 - * - * @param int $uid 用户ID - * @param int $addressId 地址ID - * @param int $cartType 购物车类型ID - * @param int $deliveryTime 寄送时间ID - * @param int $deliveryWay 寄送方式ID - * @param array $invoices 发票参数数组 - * @param int $paymentId 支付方式ID - * @param int $paymentType 支付类型ID - * @param string $remark 留言 - * @param string $couponCode 优惠券码 - * @param mixed $yohoCoin 使用的有货币数量或为空 - * @param string $skuList 购买限购商品时需要传递的参数 - * @param string $qhyUnion 友盟有关信息 - * @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息 - * @param $times - * @param null $activityInfo 套餐信息 - * @param isWechat 是否是微信商城 - * @return array 接口返回的数据 - */ -exports.orderSub = (uid, addressId, cartType, deliveryTime, - deliveryWay, invoices, paymentId, paymentType, remark, couponCode, - yohoCoin, skuList, qhyUnion, userAgent, times, activityInfo, ip, isWechat) => { - if (!activityInfo) { - activityInfo = null; - } - - let params = { - private_key: privateKeyList.h5, - method: activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit', - address_id: addressId, - cart_type: cartType, - delivery_time: deliveryTime, - delivery_way: deliveryWay, - payment_id: paymentId, - payment_type: paymentType, - remark: remark, - uid: uid - }; - - /* tar add 161130 结算优化 */ - if (times === 2 || times === '2') { - params.is_continue_buy = 'Y'; - } else { - params.is_continue_buy = 'N'; - } - - if (invoices.invoices_type_id) { - // 发票内容id--图书:1 - params.invoice_content = invoices.invoices_type_id; - } - - if (invoices.invoices_type) { - // 数字类型 发票类型 纸质 1 ,电子 2 - params.invoices_type = invoices.invoices_type; - } - - if (invoices.receiverMobile) { - // 发票人手机 - params.receiverMobile = invoices.receiverMobile; - } - - if (invoices.invoices_title) { - // 发票抬头 OR 填写单位名称,这二个是一个意思,只是叫法不一样 - params.invoices_title = invoices.invoices_title; - } - - if (couponCode) { - params.coupon_code = couponCode; - } - - if (yohoCoin) { - params.use_yoho_coin = yohoCoin; - } - - // 购买限购商品时需要传递product_sku_list参数 - if (skuList && !activityInfo) { - params.product_sku_list = JSON.stringify(skuList); - } - - // 购买套餐商品需要的数据 - if (activityInfo) { - params.activity_id = activityInfo.activity_id; - params.product_sku_list = JSON.stringify(activityInfo.product_sku_list); // TODO 检查 JSON 是否正常 - } - - // 友盟有关信息的传递 - if (qhyUnion) { - params.qhy_union = qhyUnion; - } - - // 是否是微信商城 - if (isWechat) { - params.client_type = 'wechat'; - } - - return api.post('', params, { - headers: { - 'X-Forwarded-For': ip || '', - 'User-Agent': userAgent - } - }); -}; - - -/** - * 获取用户可用的优惠券张数 - * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md - * @param uid int 用户uid - * @return see doc - */ -exports.getValidCouponCount = uid => { - let param = { - method: 'app.Shopping.countUsableCoupon', - uid - }; - - return api.get('', param); -}; - - -/** - * 获取用户优惠券列表,可用和不可用 - * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md - * @param uid int 用户uid - * @return see doc - */ -exports.listCoupon = uid => { - let param = { - method: 'app.Shopping.listCoupon', - uid - }; - - return api.get('', param); -}; - -/** - * 购物车结算--使用优惠券 - * @param uid int 用户uid - * @param couponCode string 优惠券代码 - * @return - */ -exports.useCoupon = (uid, couponCode) => { - let param = { - method: 'app.Shopping.useCoupon', - coupon_code: couponCode, - uid - }; - - return api.get('', param); -}; diff --git a/apps/serverAPI/user/address.js b/apps/serverAPI/user/address.js deleted file mode 100644 index 2df5b11..0000000 --- a/apps/serverAPI/user/address.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; - -const api = global.yoho.API; -const crypto = global.yoho.crypto; - -/** - * 地址数据 - * @param uid - * @return - */ -exports.addressData = (uid) => { - let params = { - method: 'app.address.gethidden', - uid - }; - - let options = { - cache: false - }; - - return api.get('', params, options) - .then( - result => { - if (result.code === 200) { - // 加密address_id - result.data.forEach(address => { - address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); - }); - } - - return result; - } - , - () => { - return {code: 500, data: [], message: '地址获取失败'}; - } - ); -}; diff --git a/apps/serverAPI/user/index.js b/apps/serverAPI/user/index.js deleted file mode 100644 index 4145683..0000000 --- a/apps/serverAPI/user/index.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; -const api = global.yoho.API; - - - -/** - * 获取用户信息 - * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/addUserprofile.md - * @param uid 用户id - * @return - */ -exports.queryProfile = (uid) => { - let params = { - method: 'app.passport.profile', - uid - }; - - let options = { - cache: true - }; - - return api.get('', params, options); -}; - -exports.addressTextData = (uid) => { - return api.get('', { - method: 'app.address.get', - uid: uid - }); -}; -- libgit2 0.24.0