Authored by 郝肖肖

'虚拟门票'

... ... @@ -21,7 +21,7 @@ const ticketEnsure = (req, res, next) => {
let buyNumber = req.query.buyNumber || 0;
let skn = req.query.productSkn || 0;
ticketService.addTicket(uid, sku, buyNumber).then(result => {
req.ctx(ticketService).addTicket(uid, sku, buyNumber).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
result.stepper = stepper;
... ... @@ -51,7 +51,7 @@ const ticketSubmit = (req, res, next) => {
});
}
ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
req.ctx(ticketService).submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
return res.json(result);
}).catch(next);
};
... ... @@ -62,7 +62,7 @@ const ticketCompute = (req, res, next) => {
let buyNumber = req.body.count || 0;
let yohoCoin = req.body.coin || 0;
ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
req.ctx(ticketService).addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return res.json({
code: 401,
... ...
... ... @@ -6,11 +6,9 @@
'use strict';
const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ...
... ... @@ -2,55 +2,54 @@
* Created by TaoHuang on 2017/6/22.
*/
const api = global.yoho.API;
/**
* 电子票下单
* @param uid 用户id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
function submit(uid, sku, count, mobile, yohoCoin) {
let params = {
method: 'app.shopping.submitTicket',
uid,
product_sku: sku,
buy_number: count,
mobile: mobile
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return api.get('', params);
}
/**
* 电子票添加和查询
* @param uid 用户 id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
function add(uid, sku, count, yohoCoin) {
let params = {
method: 'app.shopping.ticket',
uid,
product_sku: sku,
buy_number: count
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
/**
* 电子票下单
* @param uid 用户id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
submit(uid, sku, count, mobile, yohoCoin) {
let params = {
method: 'app.shopping.submitTicket',
uid,
product_sku: sku,
buy_number: count,
mobile: mobile
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return this.get({data: params});
}
return api.get('', params);
}
module.exports = {
submit,
add
/**
* 电子票添加和查询
* @param uid 用户 id
* @param sku 商品sku
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
add(uid, sku, count, yohoCoin) {
let params = {
method: 'app.shopping.ticket',
uid,
product_sku: sku,
buy_number: count
};
if (yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
return this.get({data: params});
}
};
... ...
... ... @@ -3,79 +3,82 @@
*/
const api = require('./ticket-api');
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const _handleUseYhoCoin = require('./order-ensure-handle').handleUseYohoCoin;
const OrderEnsureHandle = require('./order-ensure-handle');
function _handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
function _handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
const addTicket = co(function * (uid, sku, count, yohoCoin) {
let ticketInfo = yield api.add(uid, sku, count, yohoCoin);
let result = {};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (_.isEmpty(ticketInfo)) {
return {
last_order_amount: 0,
error: '人太多啦,稍后再试!'
};
_handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
if (ticketInfo.code !== 200) {
return {
last_order_amount: 0,
error: ticketInfo.message
};
_handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
result.virtualGood = true;
result.goodsList = _handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = _handleAmount(ticketInfo);
Object.assign(result, _handleUseYhoCoin(_.get(ticketInfo, 'data.shopping_cart_data', {})));
addTicket(uid, sku, count, yohoCoin) {
return api.add(uid, sku, count, yohoCoin).then(ticketInfo => {
let result = {};
return result;
});
if (_.isEmpty(ticketInfo)) {
return {
last_order_amount: 0,
error: '人太多啦,稍后再试!'
};
}
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin);
if (ticketInfo.code !== 200) {
return {
last_order_amount: 0,
error: ticketInfo.message
};
}
if (_.isEmpty(result)) {
return {
code: 500,
message: '人太多啦,稍后再试!'
};
}
result.virtualGood = true;
result.goodsList = this._handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = this._handleAmount(ticketInfo);
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
Object.assign(result, new OrderEnsureHandle(this.ctx).handleUseYohoCoin(
_.get(ticketInfo, 'data.shopping_cart_data', {}
)));
return result;
});
}
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
submitTicket(uid, sku, count, mobile, yohoCoin) {
return api.submit(uid, sku, count, mobile, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return {
code: 500,
message: '人太多啦,稍后再试!'
};
}
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
}
module.exports = {
addTicket,
submitTicket
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
}
};
... ...