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