lrf 2 роки тому
батько
коміт
3b854ab7c0
3 змінених файлів з 29 додано та 4 видалено
  1. 6 0
      app/model/trade/cart.js
  2. 12 1
      app/service/system/platformAct.js
  3. 11 3
      app/service/trade/cart.js

+ 6 - 0
app/model/trade/cart.js

@@ -1,13 +1,19 @@
 'use strict';
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+const act = {
+  // 套装: 需要找到套装的商品,统一归为一个商品
+  platform_act: { type: String, zh: '活动id' },
+  set_id: { type: String, zh: '参加套装活动的商品组合数据id' },
 
+};
 // 购物车
 const cart = {
   customer: { type: String, required: false, zh: '顾客', ref: 'User.User' }, //
   shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
   goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
   goodsSpec: { type: String, required: false, zh: '商品规格', ref: 'Shop.GoodsSpec' }, //
+  act: { type: Array, zh: '活动相关' },
   num: { type: Number, required: false, zh: '数量' }, //
 };
 const schema = new Schema(cart, { toJSON: { getters: true, virtuals: true } });

+ 12 - 1
app/service/system/platformAct.js

@@ -9,6 +9,7 @@ class PlatformActService extends CrudService {
   constructor(ctx) {
     super(ctx, 'platformact');
     this.model = this.ctx.model.System.PlatformAct;
+    this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
   }
   async query(filter, { skip = 0, limit, projection } = {}) {
     let condition = _.cloneDeep(filter);
@@ -17,7 +18,10 @@ class PlatformActService extends CrudService {
     // 过滤出ref字段
     const { populate } = this.getRefMods();
     // 带ref查询
-    let rs = await this.model.find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } }).populate(populate).exec();
+    let rs = await this.model
+      .find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } })
+      .populate(populate)
+      .exec();
     rs = JSON.parse(JSON.stringify(rs));
     // 整理ref数据
     rs = await this.afterQuery(filter, rs);
@@ -56,6 +60,13 @@ class PlatformActService extends CrudService {
     return { tag, text };
   }
 
+  async beforeUpdate(filter, update) {
+    const id = _.get(filter, 'id');
+    const num = await this.gjaModel.count({ platform_act: id });
+    // 如果活动已经有商品关联了.那就不能修改活动类型了
+    if (num > 0) delete update.type;
+    return { filter, update };
+  }
 }
 
 module.exports = PlatformActService;

+ 11 - 3
app/service/trade/cart.js

@@ -14,6 +14,10 @@ class CartService extends CrudService {
 
   /**
    * 返回购物车需要的数据格式
+   ** 添加促销部分:
+   ** 买赠,特价,加价购: 需要查询每个商品是否参与了这三项活动,需要给出对应数据
+   ** 满减/折:不需要在购物车出现
+   ** 套装:将套装数据拿出来,归为主商品的商品下
    * @param {Object} query 查询条件
    * @param query.customer 顾客id
    * @return {Array}
@@ -65,9 +69,13 @@ class CartService extends CrudService {
   }
 
   /**
-   * 创建购物车信息,若找到该店的该商品规格.进行库存校验
-   * 数量进行合并;
-   * 反之创建
+   ** 创建购物车信息,若找到该店的该商品规格.进行库存校验
+   ** 数量进行合并;
+   ** 反之创建
+   ** 添加促销活动部分:
+   ** 买赠,特价,加价购: 不需要在创建时处理,而是在查询时实时处理,显示相关信息
+   ** 满减/折:不需要在购物车出现
+   ** 套装:只有套装需要记录在购物车中,以同一商品形式出现
    * @param {Object} body 请求参数
    * @param body.num 数量
    */