'use strict'; const { CrudService } = require('naf-framework-mongoose-free/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); // class PlatformActService extends CrudService { constructor(ctx) { super(ctx, 'platformact'); this.model = this.ctx.model.System.PlatformAct; } async query(filter, { skip = 0, limit, projection } = {}) { let condition = _.cloneDeep(filter); condition = await this.beforeQuery(condition); condition = this.dealFilter(condition); // 过滤出ref字段 const { populate } = this.getRefMods(); // 带ref查询 let rs = await this.model.find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } }).populate(populate).exec(); rs = JSON.parse(JSON.stringify(rs)); // 整理ref数据 rs = await this.afterQuery(filter, rs); return rs; } getActText(data) { const { type } = data; let text = ''; if (type === '2') { text = '赠品'; } else if (type === '3') { text = '特价'; } else if (type === '4') { text = '加价购'; } else if (type === '5') { const discount = _.get(data, 'config.discount', []); for (const i of discount) { const { limit, number } = i; text = `${text}满${limit}减${number};`; } } else if (type === '6') { const discount = _.get(data, 'config.discount', []); for (const i of discount) { const { limit, number, max } = i; text = `满${limit}打${number}折`; if (max) text = `${text}(最多减免${max}元)`; text = `${text};`; } } else if (type === '7') { text = '套装'; } return text; } } module.exports = PlatformActService;