platformAct.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. plus_money: { type: Number, zh: '加价购下限金额' },
  28. };
  29. // 平台活动
  30. const platformAct = {
  31. // title: { type: String, required: false, zh: '活动标题' }, // 转移到活动时间下
  32. share: { type: Array, required: false, zh: '分享图片' }, //
  33. cover: { type: Array, required: false, zh: '封面图片' }, //
  34. act_time: { type: Object, required: false, zh: '活动时间' }, // value:值;is_use:字典(is_use)是否启用
  35. content: { type: Object, required: false, zh: '活动说明' }, // 富文本;value:值;is_use:字典(is_use)是否启用,title:活动标题
  36. is_use: { type: String, required: false, default: '1', zh: '是否开启' }, // 字典:is_use,默认不开启
  37. show_index: { type: String, required: false, default: '0', zh: '是否在首页显示' }, // 字典:is_use
  38. sort: { type: Number, required: false, default: 0, zh: '排序' }, //
  39. type: { type: String, required: false, zh: '活动类型' }, // 字典:act_type
  40. config: { type: Object, required: false, zh: '设置' }, //
  41. };
  42. const schema = new Schema(platformAct, { toJSON: { getters: true, virtuals: true } });
  43. schema.index({ id: 1 });
  44. schema.index({ 'meta.createdAt': 1 });
  45. schema.index({ sort: 1 });
  46. schema.index({ is_use: 1 });
  47. schema.index({ show_index: 1 });
  48. schema.index({ type: 1 });
  49. schema.plugin(metaPlugin);
  50. module.exports = app => {
  51. const { mongoose } = app;
  52. return mongoose.model('PlatformAct', schema, 'platformAct');
  53. };