platformAct.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // content同下
  5. const act_time = {
  6. value: { type: String, zh: '对应的值' },
  7. is_use: { type: String, zh: '是否使用' }, // 字典:is_use
  8. title: { type: String, zh: '活动标题' },
  9. };
  10. // 满折
  11. const manZhe = {
  12. limit: { type: Number, zh: '消费金额下限----x' },
  13. number: { type: Number, zh: '减免折扣----y' },
  14. max: { type: Number, zh: '优惠上限' },
  15. };
  16. // 满减设置
  17. const manJian = {
  18. limit: { type: Number, zh: '消费金额下限----x' },
  19. number: { type: Number, zh: '减免金额----y' },
  20. };
  21. const config = {
  22. time_start: { type: String, zh: '开始时间' }, // 死信机制,用来限时关闭活动
  23. time_end: { type: String, zh: '结束时间' }, // 死信机制,用来限时关闭活动
  24. // 满减部分, 只有满减和满折在平台活动设置,剩下的都是和商品有关的
  25. discount: { type: [ manJian ] || [ manZhe ], zh: '满减档位' },
  26. };
  27. // 平台活动
  28. const platformAct = {
  29. // title: { type: String, required: false, zh: '活动标题' }, // 转移到活动时间下
  30. share: { type: Array, required: false, zh: '分享图片' }, //
  31. cover: { type: Array, required: false, zh: '封面图片' }, //
  32. act_time: { type: Object, required: false, zh: '活动时间' }, // value:值;is_use:字典(is_use)是否启用
  33. content: { type: Object, required: false, zh: '活动说明' }, // 富文本;value:值;is_use:字典(is_use)是否启用,title:活动标题
  34. is_use: { type: String, required: false, default: '1', zh: '是否开启' }, // 字典:is_use,默认不开启
  35. show_index: { type: String, required: false, default: '0', zh: '是否在首页显示' }, // 字典:is_use
  36. sort: { type: Number, required: false, default: 0, zh: '排序' }, //
  37. type: { type: String, required: false, zh: '活动类型' }, // 字典:act_type
  38. config: { type: Object, required: false, zh: '设置' }, //
  39. };
  40. const schema = new Schema(platformAct, { toJSON: { getters: true, virtuals: true } });
  41. schema.index({ id: 1 });
  42. schema.index({ 'meta.createdAt': 1 });
  43. schema.index({ sort: 1 });
  44. schema.index({ is_use: 1 });
  45. schema.index({ show_index: 1 });
  46. schema.index({ type: 1 });
  47. schema.plugin(metaPlugin);
  48. module.exports = app => {
  49. const { mongoose } = app;
  50. return mongoose.model('PlatformAct', schema, 'platformAct');
  51. };