'use strict'; const Schema = require('mongoose').Schema; const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin'); // 店铺流水 // 如果是入账,则有抽成比例,总金额.出账则不需要抽成比例和总金额 const shopInBill = { shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, // cut: { type: Number, required: false, zh: '抽成比例' }, // time: { type: String, required: false, zh: '流水时间' }, // source: { type: String, required: false, zh: '来源' }, // 字典:cashBack_source source_id: { type: String, required: false, zh: '来源id' }, // }; const schema = new Schema(shopInBill, { toJSON: { getters: true, virtuals: true } }); schema.index({ id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.index({ shop: 1 }); schema.index({ source: 1 }); schema.index({ source_id: 1 }); schema.plugin(metaPlugin); schema.plugin(MoneyPlugin({ zh: '总金额', required: false, key: 'total' })); schema.plugin(MoneyPlugin({ zh: '净金额', required: false, key: 'receipts' })); module.exports = app => { const { mongoose } = app; return mongoose.model('ShopInBill', schema, 'shopInBill'); };