Browse Source

1、区分办公家具/民用家具结算(待完善);

Lawsun_M 1 year ago
parent
commit
6547d00d54
4 changed files with 49 additions and 20 deletions
  1. 14 3
      app/controller/home/cart.js
  2. 26 13
      app/controller/home/order.js
  3. 5 0
      app/models/mysql/carts.js
  4. 4 4
      app/routers/home/shop.js

+ 14 - 3
app/controller/home/cart.js

@@ -24,6 +24,9 @@ module.exports = class CartController extends shopController {
       category_id: that.ctx.rules.name('商品分类ID')
         .required()
         .number(),
+      pid: that.ctx.rules.name('商品分类父级ID')
+        .required()
+        .number(),
       user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
         .number(),
       product_count: that.ctx.rules.default(1)
@@ -78,6 +81,10 @@ module.exports = class CartController extends shopController {
         .number(),
       is_select: that.ctx.rules.default(0)
         .number(),
+      pid: that.ctx.rules.name('商品分类父级ID')
+        .default(4)
+        .required()
+        .number(),
     };
   }
 
@@ -90,6 +97,10 @@ module.exports = class CartController extends shopController {
     return {
       user_id: that.ctx.rules.default(0)
         .number(),
+      pid: that.ctx.rules.name('商品分类父级ID')
+        .default(4)
+        .required()
+        .number(),
     };
   }
 
@@ -189,7 +200,7 @@ module.exports = class CartController extends shopController {
       const data = await that.ctx.validate(that.selectValidate, await that.ctx.getParse());
       const seq = that.app.Sequelize;
       const options = {
-        where: { user_id: data.user_id },
+        where: { user_id: data.user_id, pid: data.pid },
         include: [
           { model: that.app.model.Products, as: 'products', attributes: [] },
         ],
@@ -198,7 +209,7 @@ module.exports = class CartController extends shopController {
           [ seq.col('products.product_image'), 'product_image' ],
           [ seq.col('products.shop_price'), 'shop_price' ],
           [ seq.col('products.market_price'), 'market_price' ],
-          'product_id', 'product_count', 'is_select', 'category_id', 'volume', 'price', 'cart_id',
+          'product_id', 'product_count', 'is_select', 'category_id', 'volume', 'price', 'cart_id', 'pid',
         ],
       };
       if (data.is_select) options.where.is_select = 1;
@@ -220,7 +231,7 @@ module.exports = class CartController extends shopController {
       const data = await that.ctx.validate(that.cartTotalValidate, await that.ctx.getParse());
       if (that.ctx.request.header.weblogintoken) {
         data.user_id = await that.service.shop.getWebUserId();
-        const total = await that.useModel.count({ where: { user_id: data.user_id } });
+        const total = await that.useModel.count({ where: { user_id: data.user_id, pid: data.pid } });
         return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', total, false));
       }
       return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', 0, false));

+ 26 - 13
app/controller/home/order.js

@@ -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: [] },
       ],

+ 5 - 0
app/models/mysql/carts.js

@@ -1,5 +1,6 @@
 /* indent size: 2 */
 
+// eslint-disable-next-line strict
 module.exports = app => {
   const DataTypes = app.Sequelize;
 
@@ -18,6 +19,10 @@ module.exports = app => {
       type: DataTypes.INTEGER(10).UNSIGNED,
       allowNull: true,
     },
+    pid: {
+      type: DataTypes.INTEGER(4).UNSIGNED,
+      allowNull: true,
+    },
     product_count: {
       type: DataTypes.INTEGER(10).UNSIGNED,
       allowNull: true,

+ 4 - 4
app/routers/home/shop.js

@@ -49,10 +49,10 @@ module.exports = app => {
   subRouter.put('/address', webLogin, shops.address.update);
   // 删除用户收货地址操作接口
   subRouter.delete('/address', webLogin, shops.address.delete);
-  // 用户下单接口
-  subRouter.post('/order', webLogin, shops.order.create);
-  // 获取订单列表
-  subRouter.get('/order', webLogin, shops.order.select);
+  // // 用户下单接口
+  // subRouter.post('/order', webLogin, shops.order.create);
+  // // 获取订单列表
+  // subRouter.get('/order', webLogin, shops.order.select);
   // 用户下单接口v2
   subRouter.post('/v2/order', webLogin, shops.order.createV2);
   // 获取订单列表v2