goodsJoinAct.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const gift = {
  5. type: [ 'goods', 'desc' ], // 平台商品; 赠品描述
  6. goods: { type: String, zh: '商品' },
  7. spec: { type: String, zh: '规格' },
  8. desc: { type: String, zh: '赠品描述' }, // 即使是有赠品有关联,也可以写描述,例如:200件,赠完为止
  9. };
  10. const set = {
  11. goods: { type: String, zh: '商品' },
  12. spec: { type: String, zh: '规格' },
  13. num: { type: Number, zh: '套装销售数量' },
  14. money: { type: Number, zh: '套装销售价格' },
  15. };
  16. const config = {
  17. // 1.买赠: 关联赠品/描述赠品 赠品不一定只是商品, 还可能不是登陆在平台上的商品
  18. gift: { type: [ gift ] },
  19. // 2.特价: 设置商品的活动销售价
  20. sp_price: { type: Number, zh: '特价' },
  21. // 3.加价购: 标注这个商品是 基础商品 还是 加价购置的商品
  22. goods_type: { type: [ 'basic', 'plus' ] },
  23. plus_money: { type: Number, zh: '加价金额' },
  24. // 4.套装(另加表,不这样做了): 关联商品 以及 每个商品设置的价格; 外边的goods为主商品, 只有主商品才能看到套装; 进入购物车与下单,订单时,也是套装出现
  25. set: { type: [ set ] },
  26. };
  27. // 参加平台活动商品
  28. const goodsJoinAct = {
  29. platform_act: { type: String, required: false, zh: '平台活动', ref: 'System.PlatformAct' }, //
  30. platform_act_type: { type: String, required: false, zh: '平台活动类型' }, //
  31. shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
  32. goods: { type: Object, required: false, zh: '商品' }, // 复制商品过来
  33. spec: { type: Object, required: false, zh: '规格' }, // 复制指定规格过来
  34. config: { type: Object, required: false, zh: '设置' }, // 各种设置都放这里,一个一个字段写,写不完还得总更新
  35. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:platformAct_goods_status
  36. };
  37. const schema = new Schema(goodsJoinAct, { toJSON: { getters: true, virtuals: true } });
  38. schema.index({ id: 1 });
  39. schema.index({ 'meta.createdAt': 1 });
  40. schema.index({ platform_act: 1 });
  41. schema.index({ platform_act_type: 1 });
  42. schema.index({ shop: 1 });
  43. schema.index({ 'goods._id': 1 });
  44. schema.index({ 'spec._id': 1 });
  45. schema.index({ status: 1 });
  46. schema.plugin(metaPlugin);
  47. module.exports = app => {
  48. const { mongoose } = app;
  49. return mongoose.model('GoodsJoinAct', schema, 'goodsJoinAct');
  50. };