Pārlūkot izejas kodu

增加添加商品接口

maguohua 8 gadi atpakaļ
vecāks
revīzija
df5e3d8829
8 mainītis faili ar 179 papildinājumiem un 31 dzēšanām
  1. 2 2
      README.md
  2. 1 1
      config/default.js
  3. 80 0
      controller/shopping/shop.js
  4. 0 11
      models/food.js
  5. 75 0
      models/shopping/shop.js
  6. 13 16
      routes/home.js
  7. 2 0
      routes/index.js
  8. 6 1
      routes/shopping.js

+ 2 - 2
README.md

@@ -49,11 +49,11 @@ npm run dev
 - [x] 城市列表
 - [x] 搜索地址
 - [ ] 添加商铺
+- [ ] 添加食品
 - [ ] 搜索美食,餐馆
 - [ ] 餐馆排序
-- [ ] 添加食品列表
 - [ ] 购物车功能
-- [ ] 店铺评价
+- [ ] 评价
 - [ ] 食品详情
 - [ ] 商家详情
 - [ ] 登录、注册

+ 1 - 1
config/default.js

@@ -2,7 +2,7 @@
 
 module.exports = {
 	port: 8001,
-	url: 'mongodb://139.224.234.213:27017/elm',
+	url: 'mongodb://localhost:27017/elm',
 	session: {
 		name: 'elm',
 		secret: 'elm',

+ 80 - 0
controller/shopping/shop.js

@@ -0,0 +1,80 @@
+'use strict';
+
+import ShopModel from '../../models/shopping/shop';
+import BaseComponent from '../../prototype/baseComponent'
+
+class Shop extends BaseComponent{
+	constructor(){
+		super()
+	}
+	async addShop(req, res, next){
+		const ifHas = await ShopModel.findOne();
+		if (ifHas) {
+			res.send(ifHas)
+			return
+		}
+		const newShop = new ShopModel({
+			name: "萨伦意大利冰淇淋",
+			address: "上海市闵行区颛桥镇鑫都路2508号302-1",
+			description: '',
+			float_delivery_fee: 5,
+			float_minimum_order_amount: 20,
+			id: 1825954,
+			is_premium: false,
+			is_new: false,
+			latitude: 31.056997,
+			longitude: 121.396113,
+			opening_hours: ["10:30/20:30"],
+			phone: "15921357769",
+			promotion_info: "欢迎光临,用餐高峰请提前下单,谢谢",
+			rating: 4.8,
+			rating_count: 34,
+			recent_order_num: 61,
+			status: 0,
+			image_path: "287de218d8026a725bda5a00e274db7cjpeg",
+			piecewise_agent_fee: {
+				tips: "配送费约¥5"
+			},
+			delivery_mode: {
+				color: "57A9FF",
+				id: 1,
+				is_solid: true,
+				text: "蜂鸟专送"
+			},
+			activities: [{
+				description: '满30减5,满60减8',
+				icon_color: "f07373",
+				icon_name: "减",
+				id: 26393397,
+				name: "满减优惠",
+			}],
+			supports: [{
+				description: "已加入“外卖保”计划,食品安全有保障",
+				icon_color: "999999",
+				icon_name: "保",
+				id: 7,
+				name: "外卖保"
+			}],
+			license: {
+				business_license_image: "3c982023d49d68caf61f41a156626426jpeg",
+				catering_service_license_image: "db299ee4218ed72c188bf59ba306868ejpeg",
+			},
+			identification: {
+				company_name: "上海市闵行区茹琪饮品店",
+				identificate_agency: "",
+				identificate_date: "2016-10-10T00:00:00+0800",
+				legal_person: "",
+				licenses_date: "",
+				licenses_number: "JY23101120002977",
+				licenses_scope: "",
+				operation_period: "",
+				registered_address: "上海市闵行区鑫都路2508号302-1",
+				registered_number: "",
+			},
+		});
+		const saveData = await newShop.save();
+		res.send(saveData)
+	}
+}
+
+export default new Shop()

+ 0 - 11
models/food.js

@@ -1,11 +0,0 @@
-'use strict';
-
-import mongoose from 'mongoose'
-
-const foodSchema = new mongoose.Schema({
-	name: String
-})
-
-const Food = mongoose.model('Food', foodSchema)
-
-export default Food

+ 75 - 0
models/shopping/shop.js

@@ -0,0 +1,75 @@
+'use strict';
+
+import mongoose from 'mongoose'
+
+const shopSchema = new mongoose.Schema({
+	activities: [{
+		description: String,
+		icon_color: String,
+		icon_name: String,
+		id: Number,
+		name: String,
+	}],
+	address: String,
+	delivery_mode: {
+		color: String,
+		id: Number,
+		is_solid: { type: Boolean, default: true },
+		text: String
+	},
+	description: { type: String, default: "" },
+	float_delivery_fee: Number,
+	float_minimum_order_amount: Number,
+	id: Number,
+	identification: {
+		company_name: { type: String, default: "" },
+		identificate_agency: { type: String, default: "" },
+		identificate_date: { type: Date, default: Date.now },
+		legal_person: { type: String, default: "" },
+		licenses_date: { type: String, default: "" },
+		licenses_number: { type: String, default: "" },
+		licenses_scope: { type: String, default: "" },
+		operation_period: { type: String, default: "" },
+		registered_address: { type: String, default: "" },
+		registered_number: { type: String, default: "" },
+	},
+	image_path: { type: String, default: "" },
+	is_premium: { type: Boolean, default: false },
+	is_new: { type: Boolean, default: false },
+	latitude: Number,
+	longitude: Number,
+	license: {
+		business_license_image: String,
+		catering_service_license_image: String,
+	},
+	name: {
+        type: String,
+        required: true 
+    },
+	opening_hours: Array,
+	phone: {
+        type: String,
+        required: true 
+    },
+	piecewise_agent_fee: {
+		tips: String
+	},
+	promotion_info: { type: String, default: "欢迎光临,用餐高峰请提前下单,谢谢" },
+	rating: { type: Number, default: 0 },
+	rating_count: { type: Number, default: 0 },
+	recent_order_num: { type: Number, default: 0 },
+	status: { type: Number, default: 0 },
+	supports: [{
+		description: String,
+		icon_color: String,
+		icon_name: String,
+		id: Number,
+		name: String
+	}],
+});
+
+shopSchema.index({ id: 1 });
+
+const Shop = mongoose.model('Shop', shopSchema);
+
+export default Shop

+ 13 - 16
routes/home.js

@@ -1,26 +1,23 @@
 'use strict';
 
 import express from 'express';
-import Food from '../models/food.js';
+// import Food from '../models/food.js';
 const router = express.Router();
 
 router.get('/', async (req, res) => {
-	
-	let foods = await Food.findOne();
-	if(!foods){
-		const test = new Food({name: '测试'});
-		try{
-			await test.save();
-			foods = await Food.findOne();
-		}catch(err){
-			throw new Error(err);
-		}
-	}
-	res.send(foods.toString());
+	res.send('home')
+	// let foods = await Food.findOne();
+	// if(!foods){
+	// 	const test = new Food({name: '测试'});
+	// 	try{
+	// 		await test.save();
+	// 		foods = await Food.findOne();
+	// 	}catch(err){
+	// 		throw new Error(err);
+	// 	}
+	// }
+	// res.send(foods.toString());
 	
 });
 
-router.get('/a', (req, res, next) => {
-	res.json({a: 1111})
-})
 export default router;

+ 2 - 0
routes/index.js

@@ -2,6 +2,7 @@
 
 import home from './home';
 import v1 from './v1'
+import shopping from './shopping'
 
 export default app => {
 	app.get('/', (req, res, next) => {
@@ -9,4 +10,5 @@ export default app => {
 	});
 	app.use('/home', home);
 	app.use('/v1', v1);
+	app.use('/shopping', shopping);
 }

+ 6 - 1
routes/shopping.js

@@ -1,4 +1,9 @@
 'use strict';
 
 import express from 'express';
-const router = express.Router();
+import Shop from '../controller/shopping/shop'
+const router = express.Router();
+
+router.get('/addshop', Shop.addShop);
+
+export default router