lrf 2 anni fa
parent
commit
ac970a85eb
1 ha cambiato i file con 7 aggiunte e 4 eliminazioni
  1. 7 4
      app/service/view/shop.js

+ 7 - 4
app/service/view/shop.js

@@ -9,20 +9,23 @@ 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 });
-      // TODO: 收藏
-      const follow_num = 0;
-      // TODO:当前用户是否收藏
-      const is_follow = false;
+      // 收藏
+      const follow_num = await this.storeShopModel.count({ shop });
+      // 当前用户是否收藏
+      const store_num = await this.storeShopModel.count({ shop, customer });
+      const 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);