12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- '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');
- const { pipeline } = require('stream');
- // 店铺类视图
- class ShopService extends CrudService {
- constructor(ctx) {
- super(ctx, 'shop');
- this.model = this.ctx.model.Shop.Shop;
- }
- // 微店页面查询
- async microIndex(condition, options) {
- // const pipline = [{ $sort: { 'meta.createdAt': -1 } }];
- // pipline.push({ $project: { name: 1, file: 1 } });
- // pipline.push({ $addFields: { shop_id: { $toString: '$_id' } } });
- // // 表关联
- // pipline.push({
- // $lookup: {
- // from: 'goods',
- // localField: 'shop_id',
- // foreignField: 'shop',
- // as: 'goods',
- // },
- // });
- // const list = await this.model.aggregate(pipline);
- let list = await this.ctx.service.shop.shop.query(condition, { ...options, projection: [ 'name', 'logo' ] });
- list = JSON.parse(JSON.stringify(list));
- const arr = [];
- for (const s of list) {
- const { _id: shop, name, logo } = s;
- const market_num = await this.ctx.service.shop.goods.count({ shop });
- // TODO: 收藏
- const follow_num = 0;
- // TODO:当前用户是否收藏
- const is_follow = false;
- const goodsList = await this.ctx.service.view.goods.indexGoodsList({ shop }, { skip: 0, limit: 3 });
- const obj = { _id: shop, logo, name, market_num, follow_num, is_follow, market: goodsList };
- arr.push(obj);
- }
- return arr;
- }
- }
- module.exports = ShopService;
|