Authored by xuqi

order submit

... ... @@ -46,13 +46,33 @@ const index = (req, res, next) => {
}).catch(next);
};
// 订单金额计算
const compute = (req, res, next) => {
orderModel.compute('8050484', req.query.coin).then(result => {
res.send(result);
}).catch(next);
};
// 订单提交
const orderSub = (req, res, next) => {
var other = req.body;
// 参数校验
if (!other.address_id) {
res.send({
code: 500,
message: '配送地址不能为空'
});
return;
}
orderModel.submit('8050484', other).then(result => {
res.send(result);
}).catch(next);
};
module.exports = {
index,
compute
compute,
orderSub
};
... ...
... ... @@ -89,13 +89,44 @@ const compute = (uid, yohoCoin) => {
coin = yohoCoin / 100;
}
return _computeApi(uid, deliveryWay, paymentType, coin).then(result => {
console.log(result);
return result;
});
return _computeApi(uid, deliveryWay, paymentType, coin).then(result => result);
};
/**
* 提交订单
* @param number uid user id
* @param number address_id 地址id
* @param number yohoCoin 使用的有货币
* @param string invoiceTitle 发票抬头
* @param int invoiceId 发票类型
* @param string remark 备注
* @param boolean isPrintPrice 是否打印价格
*/
const _submit = (uid, address, yohoCoin, invoiceTitle, invoiceId, remark, isPrintPrice) => api.get('', {
method: 'app.Shopping.submit',
uid: uid,
address_id: address,
yohoCoin: yohoCoin,
invoiceTitle: invoiceTitle,
invoiceId: invoiceId,
remark: remark,
isPrintPrice: isPrintPrice
});
const submit = (uid, other) => {
let coin = other.coin;
// 有货币稀释
if (coin) {
coin = coin / 100;
}
return _submit(
uid, other.address_id, coin, other.remark, other.isPrintPrice).then(result => result);
};
module.exports = {
index,
compute
compute,
submit
};
... ...
... ... @@ -24,5 +24,6 @@ router.post('/cart/add', cartCtrl.addToCart);
// 结算
router.get('/order', order.index);
router.get('/order/compute', order.compute);
router.post('/order/submit', order.orderSub);
module.exports = router;
... ...
... ... @@ -145,7 +145,7 @@
</p>
<div class="content hide">
<textarea id="remark-content" class="remark-content" placeholder="声明:备注中有关收货人信息、支付方式、配送方式、发票信息等购买要求一律以上面的选择为准,备注无效"></textarea>
<div class="print-price">
<div id="print-price" class="print-price">
是否打印价格:
<div class="print-price-radio-group">
{{#each printPriceRadio}}
... ... @@ -189,7 +189,7 @@
<span id="balance-cost" class="balance-cost" data-cost="{{last_order_amount}}">¥<em>{{last_order_amount}}</em></span>
</li>
<li>
<span class="btn submit-order">提交订单</span>
<span id="submit-order" class="btn submit-order">提交订单</span>
</li>
</ul>
{{/ shopping_cart_data}}
... ...
... ... @@ -7,6 +7,8 @@
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var Alert = require('../plugins/dialog').Alert;
var minusPlus = {
minus: '&#xe630;',
plus: '&#xe639;'
... ... @@ -28,6 +30,10 @@ var $coin = $('#input-coin'),
var $balanceCost = $('#balance-cost'),
$balanceCoin = $('#balance-coin');
var $printPrice = $('#print-price');
var $invoice = $('#invoice-content');
require('../plugins/check'); // before 地址和发票
require('./order/address'); // 地址
... ... @@ -127,16 +133,20 @@ function compute(coin) {
});
}
$coinSure.click(function() {
var coin;
// 获取已使用的有货币
function getCoinUsed() {
var coin = $coinUsed.text();
return coin === '' ? 0 : parseInt(coin, 10); // 使用parseInt可以排除异常情况的转化影响
}
$coinSure.click(function() {
if ($coinSure.hasClass('disable')) {
return;
}
// 切换显示
coin = $coinUsed.text();
compute(coin === '' ? 0 : parseInt(coin, 10)); // 使用parseInt可以排除异常情况的转化影响
compute(getCoinUsed());
toggleCoinPanel();
});
... ... @@ -158,7 +168,48 @@ $('.used-coin').on('click', '.modify', function() {
});
// 添加备注-是否打印价格
$printPrice.printPrice = true; //默认为true
$('.print-price-radio').check({
type: 'radio',
group: 'print-price'
group: 'print-price',
onChange: function(el, checked, value) {
if (checked) {
$printPrice.isPrintPrice = value === 1 ? true : false;
}
}
});
// 订单提交
$('#submit-order').click(function() {
var reqParam = {
address_id: $('.address.focus').data('id'),
yohoCoin: getCoinUsed(),
remark: $('#remark-content').val(),
isPrintPrice: $printPrice.printPrice
};
var $invoiceDetail;
// 发票信息
if ($invoice.find('.checked').length > 0) {
$invoiceDetail = $invoice.find('.invoice-detail');
$.extend(reqParam, {
invoiceTitle: $invoiceDetail.data('title'),
invoiceId: $invoiceDetail.data('content')
});
}
$.ajax({
type: 'POST',
url: '/shopping/order/submit',
data: reqParam
}).then(function(data) {
if (data.code === 200) {
location.href = data.data.payUrl;
} else {
new Alert(data.message).show();
}
});
});
... ...