Browse Source

resturants count api

maguohua 8 years ago
parent
commit
88601917f9
4 changed files with 31 additions and 16 deletions
  1. 12 12
      API.md
  2. 0 2
      README.md
  3. 17 1
      controller/shopping/shop.js
  4. 2 1
      routes/shopping.js

+ 12 - 12
API.md

@@ -810,15 +810,15 @@ POST
 
 |参数|是否必选|类型|说明|
 |:-----|:-------:|:-----|:-----|
-|type      |Y       |string  |shop:商铺图片,  food:食品图片, avatar:头像 |
+|type      |Y       |string  |shop:商铺图片,food:食品图片,avatar:头像 |
 
 #### 返回示例:
 
 ```javascript
 {
   status: 1,
-  image_path: '/img/shop/15bfafa418322.jpeg'  
-  // 对应的全部地址为: http://cangdu.org:8001/img/shop/15bfafa418322.jpeg
+  image_path: '15bfafa418322.jpeg'  
+  // 图片保存至七牛,图片全部地址为, http://images.cangdu.org/15bfafa418322.jpeg
 }
 ```
 
@@ -953,7 +953,7 @@ http://cangdu.org:8001/shopping/v2/menu
 
 #### 示例:
 
-[http://cangdu.org:8001/shopping/v2/menu?restaurant_id=3](http://cangdu.org:8001/shopping/v2/menu?restaurant_id=3)
+[http://cangdu.org:8001/shopping/v2/menu?restaurant_id=1](http://cangdu.org:8001/shopping/v2/menu?restaurant_id=1)
 
 
 #### 请求方式:
@@ -1057,7 +1057,7 @@ http://cangdu.org:8001/ugc/v2/restaurants/:restaurant_id/ratings
 
 #### 示例:
 
-[http://cangdu.org:8001/ugc/v2/restaurants/3/ratings?offset=0&limit=10](http://cangdu.org:8001/ugc/v2/restaurants/3/ratings?offset=0&limit=10)
+[http://cangdu.org:8001/ugc/v2/restaurants/1/ratings?offset=0&limit=10](http://cangdu.org:8001/ugc/v2/restaurants/1/ratings?offset=0&limit=10)
 
 
 #### 请求方式:
@@ -1119,7 +1119,7 @@ http://cangdu.org:8001/ugc/v2/restaurants/:restaurant_id/ratings/scores
 
 #### 示例:
 
-[http://cangdu.org:8001/ugc/v2/restaurants/3/ratings/scores](http://cangdu.org:8001/ugc/v2/restaurants/3/ratings/scores)
+[http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/scores](http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/scores)
 
 
 #### 请求方式:
@@ -1158,7 +1158,7 @@ http://cangdu.org:8001/ugc/v2/restaurants/:restaurant_id/ratings/tags
 
 #### 示例:
 
-[http://cangdu.org:8001/ugc/v2/restaurants/3/ratings/tags](http://cangdu.org:8001/ugc/v2/restaurants/3/ratings/tags)
+[http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/tags](http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/tags)
 
 
 #### 请求方式:
@@ -1271,7 +1271,7 @@ http://cangdu.org:8001/v1/carts/:cart_id/remarks
 
 #### 示例:
 
-[http://cangdu.org:8001/v1/carts/3/remarks](http://cangdu.org:8001/v1/carts/3/remarks)
+[http://cangdu.org:8001/v1/carts/1/remarks](http://cangdu.org:8001/v1/carts/1/remarks)
 
 
 #### 请求方式:
@@ -1677,7 +1677,7 @@ http://cangdu.org:8001/bos/v2/users/:user_id/orders
 
 #### 示例:
 
-[http://cangdu.org:8001/bos/v2/users/3/orders?limit=10&offset=0](http://cangdu.org:8001/bos/v2/users/3/orders?limit=10&offset=0)
+[http://cangdu.org:8001/bos/v2/users/1/orders?limit=10&offset=0](http://cangdu.org:8001/bos/v2/users/1/orders?limit=10&offset=0)
 
 
 #### 请求方式:
@@ -1784,7 +1784,7 @@ http://cangdu.org:8001/bos/v1/users/:user_id/orders/:order_id/snapshot
 
 #### 示例:
 
-[http://cangdu.org:8001/bos/v1/users/3/orders/1/snapshot](http://cangdu.org:8001/bos/v1/users/3/orders/1/snapshot)
+[http://cangdu.org:8001/bos/v1/users/1/orders/1/snapshot](http://cangdu.org:8001/bos/v1/users/1/orders/1/snapshot)
 
 
 #### 请求方式:
@@ -1938,7 +1938,7 @@ http://cangdu.org:8001/promotion/v2/users/:user_id/hongbaos
 
 #### 示例:
 
-[http://cangdu.org:8001/promotion/v2/users/3/hongbaos?limit=20&offset=0](http://cangdu.org:8001/promotion/v2/users/3/hongbaos?limit=20&offset=0)
+[http://cangdu.org:8001/promotion/v2/users/1/hongbaos?limit=20&offset=0](http://cangdu.org:8001/promotion/v2/users/1/hongbaos?limit=20&offset=0)
 
 
 #### 请求方式:
@@ -1995,7 +1995,7 @@ http://cangdu.org:8001/promotion/v2/users/:user_id/expired_hongbaos
 
 #### 示例:
 
-[http://cangdu.org:8001/promotion/v2/users/3/expired_hongbaos?limit=20&offset=0](http://cangdu.org:8001/promotion/v2/users/3/expired_hongbaos?limit=20&offset=0)
+[http://cangdu.org:8001/promotion/v2/users/1/expired_hongbaos?limit=20&offset=0](http://cangdu.org:8001/promotion/v2/users/1/expired_hongbaos?limit=20&offset=0)
 
 
 #### 请求方式:

+ 0 - 2
README.md

@@ -15,8 +15,6 @@
 
 >  部署环境 阿里云 CentOS 7.2 64位
 
->  此项目只用做nodejs的学习,请不要用于商业用途,正常下单请选择饿了么官方客户端。
-
 >  如有问题请直接在 Issues 中提,或者您发现问题并有非常好的解决方案,欢迎 PR 👍
 
 >  传送门:[前端项目地址](https://github.com/bailicangdu/vue2-elm)  、 [后台管理系统地址](https://github.com/bailicangdu/back-manage)  、 [原生APP项目地址](https://github.com/bailicangdu/RN-elm)

+ 17 - 1
controller/shopping/shop.js

@@ -68,7 +68,7 @@ class Shop extends AddressComponent{
 				opening_hours: [opening_hours],
 				phone: fields.phone,
 				promotion_info: fields.promotion_info || "欢迎光临,用餐高峰请提前下单,谢谢",
-				rating: (Math.random()*5).toFixed(1),
+				rating: (3 + Math.random()*2).toFixed(1),
 				rating_count: Math.ceil(Math.random()*1000),
 				recent_order_num: Math.ceil(Math.random()*1000),
 				status: Math.round(Math.random()),
@@ -354,6 +354,22 @@ class Shop extends AddressComponent{
 			})
 		}
 	}
+	async getShopCount(req, res, next){
+		try{
+			const count = await ShopModel.count();
+			res.send({
+				status: 1,
+				count,
+			})
+		}catch(err){
+			console.log('获取餐馆数量失败', err);
+			res.send({
+				status: 0,
+				type: 'ERROR_TO_GET_COUNT',
+				message: '获取餐馆数量失败'
+			})
+		}
+	}
 }
 
 export default new Shop()

+ 2 - 1
routes/shopping.js

@@ -7,7 +7,8 @@ import Category from '../controller/shopping/category'
 const router = express.Router();
 
 router.post('/addshop', Shop.addShop);
-router.get('/restaurants', Shop.getRestaurants)
+router.get('/restaurants', Shop.getRestaurants);
+router.get('/allrestaurants', Shop.getShopCount);
 router.post('/addfood', Food.addFood);
 router.get('/getcategory/:restaurant_id', Food.getCategory);
 router.post('/addcategory', Food.addCategory);