selfShop.js 973 B

1234567891011121314151617181920212223242526272829
  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 SelfShopService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'selfshop');
  10. this.model = this.ctx.model.Shop.Shop;
  11. }
  12. async index() {
  13. const data = await this.model.findOne({ user: { $exists: false } });
  14. return data;
  15. }
  16. async goods(query, options) {
  17. const selfShop = await this.index();
  18. const shop = _.get(selfShop, '_id');
  19. if (!shop) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到自营店铺信息,请联系开发人员');
  20. query.shop = shop;
  21. const data = await this.ctx.service.shop.goods.query(query, options);
  22. const total = await this.ctx.service.shop.goods.count(query, options);
  23. return { data, total };
  24. }
  25. }
  26. module.exports = SelfShopService;