1234567891011121314151617181920212223242526272829303132333435363738394041 |
- '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 ShopService extends CrudService {
- constructor(ctx) {
- super(ctx, 'shop');
- this.model = this.ctx.model.Shop.Shop;
- this.storeShopModel = this.ctx.model.User.StoreShop;
- }
- // 微店页面查询
- async microIndex(condition, options) {
- let list = await this.ctx.service.shop.shop.query(condition, { ...options, projection: [ 'name', 'logo' ] });
- list = JSON.parse(JSON.stringify(list));
- const customer = _.get(this.ctx, 'user._id');
- const arr = [];
- for (const s of list) {
- const { _id: shop, name, logo } = s;
- const market_num = await this.ctx.service.shop.goods.count({ shop, status: '1' });
- // 收藏
- const follow_num = await this.storeShopModel.count({ shop });
- // 当前用户是否收藏
- let is_follow = false;
- if (customer) {
- const store_num = await this.storeShopModel.count({ shop, customer });
- is_follow = store_num > 0;
- }
- const res = 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: res.list };
- arr.push(obj);
- }
- return arr;
- }
- }
- module.exports = ShopService;
|