Selaa lähdekoodia

促销部分修改

lrf 2 vuotta sitten
vanhempi
commit
77d5d184d8

+ 9 - 7
app/controller/shop/config/.goodsJoinAct.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['platformAct', 'shop', 'goods', 'status'],
+    requestBody: ['platform_act', 'spec', 'platform_act_type', 'shop', 'goods', 'config', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['platformAct', 'shop', 'goods', 'status'],
+    requestBody: ['platform_act', 'platform_act_type', 'shop', 'config', 'status'],
   },
   show: {
     parameters: {
@@ -21,20 +21,22 @@ module.exports = {
       query: {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
-        platformAct: 'platformAct',
+        platform_act: 'platform_act',
+        platform_act_type: 'platform_act_type',
         shop: 'shop',
-        goods: 'goods',
+        goods: '%goods.goods.name%',
         status: 'status',
-        goods_name: 'goods_name',
-        shop_name: 'shop_name',
       },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
     },
     service: 'query',
     options: {
       query: ['skip', 'limit'],
       sort: ['meta.createdAt'],
       desc: true,
-      count: false,
+      count: true,
     },
   },
 };

+ 3 - 2
app/controller/system/config/.platformAct.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['show_index', 'share', 'cover', 'act_time', 'content', 'is_use', 'sort'],
+    requestBody: ['type', 'config', 'show_index', 'share', 'cover', 'act_time', 'content', 'is_use', 'sort'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['show_index', 'share', 'cover', 'act_time', 'content', 'is_use', 'sort'],
+    requestBody: ['type', 'config', 'show_index', 'share', 'cover', 'act_time', 'content', 'is_use', 'sort'],
   },
   show: {
     parameters: {
@@ -24,6 +24,7 @@ module.exports = {
         is_use: 'is_use',
         show_index: 'show_index',
         title: '%act_time.title%',
+        type: 'type',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 38 - 4
app/model/shop/goodsJoinAct.js

@@ -2,19 +2,53 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
+const gift = {
+  type: [ 'goods', 'desc' ], // 平台商品; 赠品描述
+  goods: { type: String, zh: '商品' },
+  spec: { type: String, zh: '规格' },
+  desc: { type: String, zh: '赠品描述' }, // 即使是有赠品有关联,也可以写描述,例如:200件,赠完为止
+};
+
+const set = {
+  goods: { type: String, zh: '商品' },
+  spec: { type: String, zh: '规格' },
+  num: { type: Number, zh: '套装销售数量' },
+  money: { type: Number, zh: '套装销售价格' },
+};
+
+const config = {
+  // 1.买赠: 关联赠品/描述赠品 赠品不一定只是商品, 还可能不是登陆在平台上的商品
+  gift: { type: [ gift ] },
+
+  // 2.特价: 设置商品的活动销售价
+  sp_price: { type: Number, zh: '特价' },
+
+  // 3.加价购: 标注这个商品是 基础商品 还是 加价购置的商品
+  goods_type: { type: [ 'basic', 'plus' ] },
+  plus_money: { type: Number, zh: '加价金额' },
+  // 4.套装: 关联商品 以及 每个商品设置的价格; 外边的goods为主商品, 只有主商品才能看到套装; 进入购物车与下单,订单时,也是套装出现
+  set: { type: [ set ] },
+};
+
+
 // 参加平台活动商品
 const goodsJoinAct = {
-  platformAct: { type: String, required: false, zh: '平台活动', ref: 'System.PlatformAct' }, //
+  platform_act: { type: String, required: false, zh: '平台活动', ref: 'System.PlatformAct' }, //
+  platform_act_type: { type: String, required: false, zh: '平台活动类型' }, //
   shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
-  goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
+  goods: { type: Object, required: false, zh: '商品' }, // 复制商品过来
+  spec: { type: Object, required: false, zh: '规格' }, // 复制指定规格过来
+  config: { type: Object, required: false, zh: '设置' }, // 各种设置都放这里,一个一个字段写,写不完还得总更新
   status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:platformAct_goods_status
 };
 const schema = new Schema(goodsJoinAct, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
-schema.index({ platformAct: 1 });
+schema.index({ platform_act: 1 });
+schema.index({ platform_act_type: 1 });
 schema.index({ shop: 1 });
-schema.index({ goods: 1 });
+schema.index({ 'goods._id': 1 });
+schema.index({ 'spec._id': 1 });
 schema.index({ status: 1 });
 
 schema.plugin(metaPlugin);

+ 23 - 0
app/model/system/platformAct.js

@@ -7,6 +7,26 @@ const act_time = {
   is_use: { type: String, zh: '是否使用' }, // 字典:is_use
   title: { type: String, zh: '活动标题' },
 };
+
+
+// 满折
+const manZhe = {
+  limit: { type: Number, zh: '消费金额下限----x' },
+  number: { type: Number, zh: '减免折扣----y' },
+  max: { type: Number, zh: '优惠上限' },
+};
+
+// 满减设置
+const manJian = {
+  limit: { type: Number, zh: '消费金额下限----x' },
+  number: { type: Number, zh: '减免金额----y' },
+};
+const config = {
+  time_start: { type: String, zh: '开始时间' },
+  time_end: { type: String, zh: '结束时间' },
+  // 满减部分, 只有满减和满折在平台活动设置,剩下的都是和商品有关的
+  discount: { type: [ manJian ] || [ manZhe ], zh: '满减档位' },
+};
 // 平台活动
 const platformAct = {
   // title: { type: String, required: false, zh: '活动标题' }, // 转移到活动时间下
@@ -17,6 +37,8 @@ const platformAct = {
   is_use: { type: String, required: false, default: '1', zh: '是否开启' }, // 字典:is_use,默认不开启
   show_index: { type: String, required: false, default: '0', zh: '是否在首页显示' }, // 字典:is_use
   sort: { type: Number, required: false, default: 0, zh: '排序' }, //
+  type: { type: String, required: false, zh: '活动类型' }, // 字典:act_type
+  config: { type: Object, required: false, zh: '设置' }, //
 };
 const schema = new Schema(platformAct, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
@@ -24,6 +46,7 @@ schema.index({ 'meta.createdAt': 1 });
 schema.index({ sort: 1 });
 schema.index({ is_use: 1 });
 schema.index({ show_index: 1 });
+schema.index({ type: 1 });
 
 schema.plugin(metaPlugin);
 

+ 23 - 9
app/service/shop/goodsJoinAct.js

@@ -9,12 +9,26 @@ class GoodsJoinActService extends CrudService {
   constructor(ctx) {
     super(ctx, 'goodsjoinact');
     this.model = this.ctx.model.Shop.GoodsJoinAct;
+    this.goodsModel = this.ctx.model.Shop.Goods;
+    this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
   }
-  async beforeCreate(data) {
-    const { goods, shop, platformAct } = data;
-    const num = await this.model.count({ goods, shop, platformAct });
+  async create(data) {
+    assert(data);
+    const { goods, spec, shop, platform_act } = data;
+    const query = { 'goods._id': goods, 'spec._id': spec, shop, platform_act };
+    const num = await this.model.count(query);
     if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该商品已添加进当前活动中');
-    return data;
+    // 将商品和规格 变为 快照数据
+    const goodsInfo = await this.goodsModel.findById(goods);
+    if (!goodsInfo) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到商品信息');
+    data.goods = JSON.parse(JSON.stringify(goodsInfo));
+    if (spec) {
+      const specInfo = await this.goodsSpecModel.findById(spec);
+      if (!specInfo) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到商品规格信息');
+      data.spec = JSON.parse(JSON.stringify(specInfo));
+    }
+    const res = await this.model.create(data);
+    return res;
   }
 
   async query(filter, { skip = 0, limit, sort, desc, projection } = {}) {
@@ -27,11 +41,11 @@ class GoodsJoinActService extends CrudService {
     let condition = _.cloneDeep(filter);
     condition = await this.beforeQuery(condition);
     condition = this.dealFilter(condition);
-    const { shop, status, platformAct, goods, goods_name, shop_name } = condition;
-    const fMatch = { };
-    if (shop)fMatch.shop = shop;
-    if (platformAct) fMatch.platformAct = platformAct;
-    if (goods)fMatch.goods = goods;
+    const { shop, status, platform_act, goods, goods_name, shop_name } = condition;
+    const fMatch = {};
+    if (shop) fMatch.shop = shop;
+    if (platform_act) fMatch.platform_act = platform_act;
+    if (goods) fMatch.goods = goods;
     if (status) fMatch.status = status;
     const pipeline = [];
     if (Object.keys(fMatch).length > 0) {