Browse Source

1、订单查询显示邀请人信息;2、商品删除接口实现;

Lawsun_M 1 year ago
parent
commit
e47491d237

+ 4 - 1
app/controller/manager/shops/orders.js

@@ -111,9 +111,11 @@ module.exports = class OrdersController extends ManagerController {
   async selectInfo(order_id) {
     const that = this;
     const options = {
-      where: { order_id }, include: [
+      where: { order_id },
+      include: [
         { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
         { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ] },
+        { model: that.app.model.Users, as: 'inviter', attributes: [ 'account_name', 'nickname' ] },
         {
           model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
             exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],
@@ -144,6 +146,7 @@ module.exports = class OrdersController extends ManagerController {
       offset: (data.page - 1) * data.limit, limit: data.limit, where: {}, include: [
         { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
         { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ], where: userWhere },
+        { model: that.app.model.Users, as: 'inviter', attributes: [ 'account_name', 'nickname' ] },
         {
           model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
             exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],

+ 49 - 0
app/controller/manager/shops/products.js

@@ -196,6 +196,25 @@ module.exports = class ProductsController extends ManagerController {
     };
   }
 
+  /**
+   * 删除商品验证器
+   * @date:2023/10/16
+   */
+  get delValidate() {
+    const that = this;
+    return {
+      product_id: that.ctx.rules.default(0)
+        .required()
+        .name('商品ID')
+        .number(),
+      carousel_id: that.ctx.rules.default(0)
+        .number(),
+      content_id: that.ctx.rules.default(0)
+        .number(),
+    };
+  }
+
+
   /**
    * [desctionValidate 查询商品详情验证器]
    * @return {[type]} [description]
@@ -297,6 +316,36 @@ module.exports = class ProductsController extends ManagerController {
     }
   }
 
+  /**
+   * [update 删除商品]
+   * @return {[type]} [description]
+   */
+  async delete() {
+    const that = this;
+    let transaction;
+    try {
+      const data = await that.ctx.validate(that.delValidate, await that.ctx.anyParse());
+      transaction = await that.app.model.transaction();
+      const deleteProduct = await that.app.comoBean.instance(data, {
+        where: { product_id: data.product_id }, transaction,
+      });
+      const deleteContent = await that.app.comoBean.instance(data, {
+        where: { content_id: data.content_id }, transaction,
+      });
+      const deleteCarousel = await that.app.comoBean.instance(data, {
+        where: { carousel_id: data.carousel_id }, transaction,
+      });
+      await that.service.manager.delete(deleteProduct, that.useModel, '商品删除失败,请稍候重试');
+      await that.service.manager.delete(deleteContent, that.useContentModel, '商品详情删除失败,请稍候重试');
+      await that.service.manager.delete(deleteCarousel, that.useCarouseModel, '商品相册删除失败,请稍候重试');
+      await transaction.commit();
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', '成功删除选中商品', false));
+    } catch (err) {
+      if (transaction) transaction.rollback();
+      return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
+    }
+  }
+
   /**
    * [select 查询商品列表]
    * @return {[type]} [description]

+ 1 - 0
app/models/mysql/orders.js

@@ -142,6 +142,7 @@ module.exports = app => {
   Model.associate = function() {
     // 关联用户表
     Model.belongsTo(app.model.Users, { foreignKey: 'user_id', targetKey: 'user_id', as: 'users' });
+    Model.belongsTo(app.model.Users, { foreignKey: 'inviter_id', targetKey: 'user_id', as: 'inviter' });
     // 关联订单商品表
     Model.hasMany(app.model.OrdersProducts, { foreignKey: 'order_id', targetKey: 'order_id', as: 'orders_products' });
     // 关闭支付类型表