|
@@ -58,6 +58,10 @@ module.exports = class OrderController extends shopController {
|
|
|
.required()
|
|
|
.notEmpty()
|
|
|
.number(),
|
|
|
+ pid: that.ctx.rules.name('家具分类父级ID')
|
|
|
+ .required()
|
|
|
+ .notEmpty()
|
|
|
+ .number(),
|
|
|
user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
|
|
|
.number(),
|
|
|
user_remarks: that.ctx.rules.default('')
|
|
@@ -369,7 +373,8 @@ module.exports = class OrderController extends shopController {
|
|
|
* @return {[type]} [description]
|
|
|
*
|
|
|
*/
|
|
|
- async create() {
|
|
|
+
|
|
|
+ /* async create() {
|
|
|
const that = this;
|
|
|
let transaction;
|
|
|
try {
|
|
@@ -389,7 +394,7 @@ module.exports = class OrderController extends shopController {
|
|
|
await that.logs('order.js', err);
|
|
|
return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* [createV2 用户下单]
|
|
@@ -405,8 +410,8 @@ module.exports = class OrderController extends shopController {
|
|
|
const isUseMoney = data.isUseMoney ? data.isUseMoney : false;
|
|
|
that.logger.error('用户下单绑定的邀请码: %s ', inviteCode);
|
|
|
transaction = await that.app.model.transaction();
|
|
|
- const products = await that.getCartProducts(data.user_id, transaction);
|
|
|
- const orderAmount = await that.caclOrderAmountV2(products);
|
|
|
+ const products = await that.getCartProducts(data.user_id, data.pid, transaction);
|
|
|
+ const orderAmount = await that.caclOrderAmountV2(products, data.pid);
|
|
|
const result = await that.orderCreateBeforeV2(data, orderAmount, transaction, inviteCode, isUseMoney);
|
|
|
const cartIds = await that.orderProductsAfter(result.order.order_id, products, data, transaction);
|
|
|
await that.clearCartProducts(cartIds, transaction);
|
|
@@ -427,16 +432,16 @@ module.exports = class OrderController extends shopController {
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
- async caclOrderAmount(products, data = {}) {
|
|
|
+ /* async caclOrderAmount(products, data = {}) {
|
|
|
// const that = this;
|
|
|
let order_amount = 0;
|
|
|
products.forEach(item => {
|
|
|
order_amount += (Number(item.shop_price) * item.product_count);
|
|
|
});
|
|
|
return order_amount;
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- async caclOrderAmountV2(products) {
|
|
|
+ async caclOrderAmountV2(products, pid = 4) {
|
|
|
const that = this;
|
|
|
const keys = [ 'can_discount_category' ];
|
|
|
const config = await that.service.configs.getConfigMoreValue(keys);
|
|
@@ -445,13 +450,20 @@ module.exports = class OrderController extends shopController {
|
|
|
let canDiscountCategory = temB.split(',');
|
|
|
canDiscountCategory = canDiscountCategory.map(Number);
|
|
|
const orderAmount = { orderPriceCanDiscount: 0, orderPriceNotDiscount: 0 };
|
|
|
+ // 2023/10/12 todo 订单价格办公家具全场八折
|
|
|
products.forEach(item => {
|
|
|
if (!canDiscountCategory.includes(item.category_id)) {
|
|
|
- orderAmount.orderPriceNotDiscount += (Number(item.price > 0 ? item.price : item.shop_price) * item.product_count);
|
|
|
+ orderAmount.orderPriceNotDiscount += ((Number(item.price > 0 ? item.price : item.shop_price) * item.product_count) * (pid === 1 ? 0.8 : 1));
|
|
|
} else {
|
|
|
- orderAmount.orderPriceCanDiscount += (Number(item.price > 0 ? item.price : item.shop_price) * item.product_count);
|
|
|
+ orderAmount.orderPriceCanDiscount += ((Number(item.price > 0 ? item.price : item.shop_price) * item.product_count) * (pid === 1 ? 0.8 : 1));
|
|
|
}
|
|
|
});
|
|
|
+ /* console.log('orderAmount');
|
|
|
+ console.log(orderAmount);
|
|
|
+ console.log('pid');
|
|
|
+ console.log(pid);
|
|
|
+ console.log('item');
|
|
|
+ console.log(products);*/
|
|
|
return orderAmount;
|
|
|
}
|
|
|
|
|
@@ -463,7 +475,8 @@ module.exports = class OrderController extends shopController {
|
|
|
* @param inviteCode
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
- async orderCreateBefore(data = {}, order_amount = 0, transaction = null, inviteCode = -1) {
|
|
|
+
|
|
|
+ /* async orderCreateBefore(data = {}, order_amount = 0, transaction = null, inviteCode = -1) {
|
|
|
const that = this;
|
|
|
const address = await that.getUserAddress(data.user_id, transaction);
|
|
|
if (!address) throw new Error('您还没有完善收货信息,请完善后再下单吧!');
|
|
@@ -514,7 +527,7 @@ module.exports = class OrderController extends shopController {
|
|
|
payParmas: { payment_money: tmpPayMentMoney.payment_money, params: payParmas, order_id: order.order_id },
|
|
|
};
|
|
|
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
async orderCreateBeforeV2(data = {}, orderAmount = {
|
|
|
orderPriceCanDiscount: 0,
|
|
@@ -630,11 +643,11 @@ module.exports = class OrderController extends shopController {
|
|
|
* @param {Number} user_id [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
- async getCartProducts(user_id = 0, transaction = null) {
|
|
|
+ async getCartProducts(user_id = 0, pid = 4, transaction = null) {
|
|
|
const that = this;
|
|
|
const seq = that.app.Sequelize;
|
|
|
const options = {
|
|
|
- where: { user_id, is_select: 1 }, transaction, raw: true,
|
|
|
+ where: { user_id, is_select: 1, pid }, transaction, raw: true,
|
|
|
include: [
|
|
|
{ model: that.app.model.Products, as: 'products', attributes: [] },
|
|
|
],
|