shop.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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 ShopService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'shop');
  10. this.model = this.ctx.model.Shop.Shop;
  11. }
  12. // 微店页面查询
  13. async microIndex(condition, options) {
  14. let list = await this.ctx.service.shop.shop.query(condition, { ...options, projection: [ 'name', 'logo' ] });
  15. list = JSON.parse(JSON.stringify(list));
  16. const arr = [];
  17. for (const s of list) {
  18. const { _id: shop, name, logo } = s;
  19. const market_num = await this.ctx.service.shop.goods.count({ shop });
  20. // TODO: 收藏
  21. const follow_num = 0;
  22. // TODO:当前用户是否收藏
  23. const is_follow = false;
  24. const res = await this.ctx.service.view.goods.indexGoodsList({ shop }, { skip: 0, limit: 3 });
  25. const obj = { _id: shop, logo, name, market_num, follow_num, is_follow, market: res.list };
  26. arr.push(obj);
  27. }
  28. return arr;
  29. }
  30. }
  31. module.exports = ShopService;