Authored by yyq

订单参数校验

... ... @@ -66,10 +66,10 @@ const submit = (req, res, next) => {
let uid = req.user.uid;
let remoteIp = req.ip;
if (!req.body.addressId) {
if (!req.body.addressId || !req.body.paymentType || !req.body.deliveryWay) {
res.send({
code: 500,
message: '配送地址不能为空'
message: '订单参数不完整'
});
return;
}
... ...

608 Bytes | W: | H:

42.6 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -127,6 +127,29 @@ function compute(coin, cb) {
});
}
function validateOrderInfo(info) {
var errTip = '';
if (!errTip && !info.addressId) {
errTip = '请填写配送地址';
}
if (!errTip && !info.paymentType) {
errTip = '请选择支付方式';
}
if (!errTip && !info.deliveryWay) {
errTip = '请选择配送方式';
}
if (errTip) {
new dialog.Alert(errTip).show();
return false;
}
return true;
}
// 支付方式
payWay = {
$allType: $('.pay-wrap > p'),
... ... @@ -167,7 +190,7 @@ payWay = {
$this.addClass('checked');
// 更新订单支付数据
that.updateOrder($this.data());
that.updateOrder(pt);
// 重新计算订单价格
compute();
... ... @@ -230,11 +253,11 @@ payWay = {
return;
}
if (info.id) {
if (info.hasOwnProperty('id')) {
order.paymentId = info.id;
}
if (info.type) {
if (info.hasOwnProperty('type')) {
order.paymentType = info.type;
}
}
... ... @@ -692,6 +715,11 @@ $('#order-submit').click(function() {
$.extend(order, invoiceInfo);
}
// 订单参数校验
if (!validateOrderInfo(order)) {
return;
}
$.ajax({
type: 'POST',
url: '/cart/ensure/submit',
... ...