...
|
...
|
@@ -10,13 +10,18 @@ const _ = require('lodash'); |
|
|
const helper = global.yoho.helpers;
|
|
|
const crypto = global.yoho.crypto;
|
|
|
|
|
|
const easypayApi = require('./easypay-api');
|
|
|
const addressApi = require('./address-api');
|
|
|
const ensureApi = require('./order-ensure-api');
|
|
|
const EasypayApi = require('./easypay-api');
|
|
|
const AddressApi = require('./address-api');
|
|
|
const EnsureApi = require('./order-ensure-api');
|
|
|
|
|
|
const ensureHandle = require('./order-ensure-handle');
|
|
|
const EnsureHandle = require('./order-ensure-handle');
|
|
|
|
|
|
const _getLimitProductData = (params) => {
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
_getLimitProductData(params) {
|
|
|
let resList = [];
|
|
|
|
|
|
if (params.limitcode && params.sku && params.skn) {
|
...
|
...
|
@@ -40,25 +45,25 @@ const _getLimitProductData = (params) => { |
|
|
}
|
|
|
|
|
|
return resList.length ? JSON.stringify(resList) : false;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 获取结算信息
|
|
|
const getEasypayOrderData = (params, uid) => {
|
|
|
// 获取结算信息
|
|
|
getEasypayOrderData(params, uid) {
|
|
|
let resData = {};
|
|
|
let strInfo = _getLimitProductData(params);
|
|
|
let strInfo = this._getLimitProductData(params);
|
|
|
let bundle = params.bundle ? parseInt(params.bundle, 10) : false;
|
|
|
|
|
|
return Promise.all([
|
|
|
easypayApi.getEasyPaymentAsync(uid, strInfo, bundle),
|
|
|
addressApi.getAddressListAsync(uid),
|
|
|
ensureApi.getUserProfileAsync(uid)
|
|
|
new EasypayApi(this.ctx).getEasyPaymentAsync(uid, strInfo, bundle),
|
|
|
new AddressApi(this.ctx).getAddressListAsync(uid),
|
|
|
new EnsureApi(this.ctx).getUserProfileAsync(uid)
|
|
|
]).then(result => {
|
|
|
let data = _.get(result, '[0].data', false);
|
|
|
let address = _.get(result, '[1].data', []);
|
|
|
let receiver = _.get(result, '[2].data.mobile', '');
|
|
|
|
|
|
if (data) {
|
|
|
Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), {
|
|
|
Object.assign(resData, new EnsureHandle(this.ctx).handlePaymentInfo(data, address), {
|
|
|
receiverMobile: receiver,
|
|
|
hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
|
|
|
});
|
...
|
...
|
@@ -66,35 +71,40 @@ const getEasypayOrderData = (params, uid) => { |
|
|
|
|
|
return resData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 价格计算
|
|
|
const getOrderComputeData = (uid, cartType, params) => {
|
|
|
params.productSkuList = _getLimitProductData(params);
|
|
|
// 价格计算
|
|
|
getOrderComputeData(uid, cartType, params) {
|
|
|
params.productSkuList = this._getLimitProductData(params);
|
|
|
|
|
|
return easypayApi.getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
|
|
|
return new EasypayApi(this.ctx).getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
|
|
|
if (result.code === 200) {
|
|
|
let ensureHandleModel = new EnsureHandle(this.ctx);
|
|
|
|
|
|
if (_.has(result, 'data.last_order_amount')) {
|
|
|
result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
|
|
|
}
|
|
|
|
|
|
if (_.has(result, 'data.promotion_formula_list')) {
|
|
|
ensureHandle.handleViewPrice(result.data.promotion_formula_list);
|
|
|
ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
|
|
|
}
|
|
|
|
|
|
result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data));
|
|
|
result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
|
|
|
}
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 订单提交
|
|
|
const easypayOrderSubmit = (uid, cartType, params, remoteIp) => {
|
|
|
// 订单提交
|
|
|
easypayOrderSubmit(uid, cartType, params, remoteIp) {
|
|
|
params.addressId = crypto.decrypt('', params.addressId);
|
|
|
params.productSkuList = _getLimitProductData(params);
|
|
|
params.productSkuList = this._getLimitProductData(params);
|
|
|
|
|
|
return easypayApi.easypayOrderSubmitAsync(uid, cartType, params.addressId, params.deliveryTime,
|
|
|
params.deliveryWay, params.paymentType, params.paymentId, params.printPrice, params, remoteIp).then(result => {
|
|
|
return new EasypayApi(this.ctx).easypayOrderSubmitAsync(
|
|
|
uid, cartType, params.addressId, params.deliveryTime,
|
|
|
params.deliveryWay, params.paymentType, params.paymentId,
|
|
|
params.printPrice, params, remoteIp
|
|
|
).then(result => {
|
|
|
if (result.code === 200) {
|
|
|
let d = result.data;
|
|
|
|
...
|
...
|
@@ -103,12 +113,6 @@ const easypayOrderSubmit = (uid, cartType, params, remoteIp) => { |
|
|
});
|
|
|
}
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
);
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getEasypayOrderData,
|
|
|
getOrderComputeData,
|
|
|
easypayOrderSubmit
|
|
|
}; |
...
|
...
|
|