platformAct.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. //
  7. class PlatformActService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'platformact');
  10. this.model = this.ctx.model.System.PlatformAct;
  11. }
  12. async query(filter, { skip = 0, limit, projection } = {}) {
  13. let condition = _.cloneDeep(filter);
  14. condition = await this.beforeQuery(condition);
  15. condition = this.dealFilter(condition);
  16. // 过滤出ref字段
  17. const { populate } = this.getRefMods();
  18. // 带ref查询
  19. let rs = await this.model.find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } }).populate(populate).exec();
  20. rs = JSON.parse(JSON.stringify(rs));
  21. // 整理ref数据
  22. rs = await this.afterQuery(filter, rs);
  23. return rs;
  24. }
  25. getActText(data) {
  26. const { type } = data;
  27. let text = '';
  28. if (type === '2') {
  29. text = '赠品';
  30. } else if (type === '3') {
  31. text = '特价';
  32. } else if (type === '4') {
  33. text = '加价购';
  34. } else if (type === '5') {
  35. const discount = _.get(data, 'config.discount', []);
  36. for (const i of discount) {
  37. const { limit, number } = i;
  38. text = `${text}满${limit}减${number};`;
  39. }
  40. } else if (type === '6') {
  41. const discount = _.get(data, 'config.discount', []);
  42. for (const i of discount) {
  43. const { limit, number, max } = i;
  44. text = `满${limit}打${number}折`;
  45. if (max) text = `${text}(最多减免${max}元)`;
  46. text = `${text};`;
  47. }
  48. } else if (type === '7') {
  49. text = '套装';
  50. }
  51. return text;
  52. }
  53. }
  54. module.exports = PlatformActService;