Browse Source

add explain hongbao api

maguohua 8 years ago
parent
commit
7e7564a8ec

File diff suppressed because it is too large
+ 16 - 0
InitData/explain.js


+ 425 - 0
InitData/hongbao.js

@@ -0,0 +1,425 @@
+export default [
+{
+id: 7160761341773,
+sn: "201705211244186655961161757573",
+user_id: 186655961,
+amount: 2,
+sum_condition: 40,
+name: "分享红包",
+phone: "13681711254",
+begin_date: "2017-05-21",
+end_date: "2017-05-23",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "剩3日",
+validity_periods: "2017-05-23到期",
+sum_condition: "满 40 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 1,
+share_status: 0,
+schema: "eleme://restaurants?target_name=%E9%99%84%E8%BF%91%E5%95%86%E5%AE%B6&target=%7B%7D"
+},
+{
+id: 7160771283789,
+sn: "201705211244186655961313417766",
+user_id: 186655961,
+amount: 1,
+sum_condition: 20,
+name: "分享红包",
+phone: "13681711254",
+begin_date: "2017-05-21",
+end_date: "2017-05-23",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "剩3日",
+validity_periods: "2017-05-23到期",
+sum_condition: "满 20 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 1,
+share_status: 0,
+schema: "eleme://restaurants?target_name=%E9%99%84%E8%BF%91%E5%95%86%E5%AE%B6&target=%7B%7D"
+},
+{
+id: 7160754582349,
+sn: "201705211243186655961753696656",
+user_id: 186655961,
+amount: 4.5,
+sum_condition: 30,
+name: "分享红包",
+phone: "13681711254",
+begin_date: "2017-05-21",
+end_date: "2017-05-23",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "剩3日",
+validity_periods: "2017-05-23到期",
+sum_condition: "满 30 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:快餐便当、特色菜系、小吃夜宵、甜品饮品、异国料理"
+},
+status: 0,
+present_status: 1,
+share_status: 0,
+schema: "eleme://restaurants?target_name=%E5%BF%AB%E9%A4%90%E4%BE%BF%E5%BD%93%E7%89%B9%E8%89%B2%E8%8F%9C%E7%B3%BB%E5%B0%8F%E5%90%83%E5%A4%9C%E5%AE%B5%E7%94%9C%E5%93%81%E9%A5%AE%E5%93%81%E5%BC%82%E5%9B%BD%E6%96%99%E7%90%86&target=%7B%22category_schema%22%3A%7B%22is_show_all_category%22%3Atrue%2C%22complex_category_ids%22%3A%5B207%2C220%2C233%2C239%2C260%5D%2C%22category_name%22%3A%22%5Cu5feb%5Cu9910%5Cu4fbf%5Cu5f53%5Cu7279%5Cu8272%5Cu83dc%5Cu7cfb%5Cu5c0f%5Cu5403%5Cu591c%5Cu5bb5%5Cu751c%5Cu54c1%5Cu996e%5Cu54c1%5Cu5f02%5Cu56fd%5Cu6599%5Cu7406%22%7D%7D"
+},
+{
+id: 7114345941837,
+sn: "201705180135186655961227785920",
+user_id: 186655961,
+amount: 5,
+sum_condition: 24,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-18",
+end_date: "2017-05-20",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-3天后可用",
+validity_periods: "2017-05-20到期",
+sum_condition: "满 24 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 7114345943885,
+sn: "201705180135186655961682785933",
+user_id: 186655961,
+amount: 4,
+sum_condition: 18,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-18",
+end_date: "2017-05-20",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-3天后可用",
+validity_periods: "2017-05-20到期",
+sum_condition: "满 18 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:果蔬生鲜、商店超市"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 7114345944909,
+sn: "201705180135186655961379164125",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-18",
+end_date: "2017-05-20",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-3天后可用",
+validity_periods: "2017-05-20到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:小吃夜宵",
+time_periods: "限时段:21:00 - 02:00"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6988252000077,
+sn: "201705110124186655961361787430",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-11",
+end_date: "2017-05-13",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-10天后可用",
+validity_periods: "2017-05-13到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6988252001101,
+sn: "201705110124186655961722477791",
+user_id: 186655961,
+amount: 4,
+sum_condition: 18,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-11",
+end_date: "2017-05-13",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-10天后可用",
+validity_periods: "2017-05-13到期",
+sum_condition: "满 18 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:果蔬生鲜、商店超市"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6988252002125,
+sn: "201705110124186655961378209054",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-11",
+end_date: "2017-05-13",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-10天后可用",
+validity_periods: "2017-05-13到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:小吃夜宵",
+time_periods: "限时段:21:00 - 23:59"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6826679667533,
+sn: "201705040218186655961404756960",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-04",
+end_date: "2017-05-06",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-17天后可用",
+validity_periods: "2017-05-06到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6826679668557,
+sn: "201705040218186655961625497972",
+user_id: 186655961,
+amount: 4,
+sum_condition: 18,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-04",
+end_date: "2017-05-06",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-17天后可用",
+validity_periods: "2017-05-06到期",
+sum_condition: "满 18 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:果蔬生鲜"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6826679669581,
+sn: "201705040218186655961724208735",
+user_id: 186655961,
+amount: 4,
+sum_condition: 20,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-04",
+end_date: "2017-05-06",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-17天后可用",
+validity_periods: "2017-05-06到期",
+sum_condition: "满 20 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:超市便利店"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6776347937613,
+sn: "201705020237186655961587770680",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-02",
+end_date: "2017-05-04",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-19天后可用",
+validity_periods: "2017-05-04到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6776347939661,
+sn: "201705020237186655961281037962",
+user_id: 186655961,
+amount: 4,
+sum_condition: 20,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-02",
+end_date: "2017-05-04",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-19天后可用",
+validity_periods: "2017-05-04到期",
+sum_condition: "满 20 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:果蔬生鲜"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6776347942733,
+sn: "201705020237186655961580452097",
+user_id: 186655961,
+amount: 4,
+sum_condition: 28,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-05-02",
+end_date: "2017-05-04",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-19天后可用",
+validity_periods: "2017-05-04到期",
+sum_condition: "满 28 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:超市便利店"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6635705093965,
+sn: "201704250238186655961834564160",
+user_id: 186655961,
+amount: 5,
+sum_condition: 25,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-04-25",
+end_date: "2017-04-27",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-26天后可用",
+validity_periods: "2017-04-27到期",
+sum_condition: "满 25 元可用"
+},
+limit_map: { },
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6635705096013,
+sn: "201704250238186655961925708910",
+user_id: 186655961,
+amount: 4,
+sum_condition: 20,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-04-25",
+end_date: "2017-04-27",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-26天后可用",
+validity_periods: "2017-04-27到期",
+sum_condition: "满 20 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:果蔬生鲜"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+},
+{
+id: 6635705097037,
+sn: "201704250238186655961400865908",
+user_id: 186655961,
+amount: 4,
+sum_condition: 28,
+name: "普通红包",
+phone: "13681711254",
+begin_date: "2017-04-25",
+end_date: "2017-04-27",
+description_map: {
+phone: "限收货手机号为 13681711254",
+online_paid_only: "限在线支付使用",
+validity_delta: "-26天后可用",
+validity_periods: "2017-04-27到期",
+sum_condition: "满 28 元可用"
+},
+limit_map: {
+restaurant_flavor_ids: "限品类:超市便利店"
+},
+status: 0,
+present_status: 4,
+share_status: 0
+}
+]

+ 3 - 3
README.md

@@ -66,9 +66,9 @@ npm run dev (需开启本地mongodb,如果没有安装mongodb,可以运行 n
 - [x] 订单列表
 - [x] 订单详情
 - [x] 下载App
-- [ ] 帐户信息
-- [ ] 服务中心
-- [ ] 红包
+- [x] 帐户信息
+- [x] 服务中心
+- [x] 红包
 - [ ] 后台管理系统
 - [ ] 前后台同构,美化路由地址
 - [ ] 部署上线

+ 53 - 0
controller/promotion/hongbao.js

@@ -0,0 +1,53 @@
+'use strict'
+
+import HongbaoModel from '../../models/promotion/hongbao'
+import BaseComponent from '../../prototype/baseComponent'
+
+class Hongbao extends BaseComponent{
+	constructor(){
+		super()
+		this.getHongbao = this.getHongbao.bind(this);
+		this.getExpiredHongbao = this.getExpiredHongbao.bind(this);
+	}
+	async getHongbao(req, res, next){
+		this.hongbaoHandle(req, res, 'intime')
+	}
+	async getExpiredHongbao(req, res, next){
+		this.hongbaoHandle(req, res, 'expired')
+	}
+	async hongbaoHandle(req, res, type){
+		const present_status = type == 'intime'? 1 : 4;
+		const user_id = req.params.user_id;
+		const {limit = 0, offset = 0} = req.query;
+		try{
+			if(!user_id || !Number(user_id)){
+				throw new Error('user_id参数错误')
+			}else if(!Number(limit)){
+				throw new Error('limit参数错误')
+			}else if(typeof Number(offset) !== 'number'){
+				throw new Error('offset参数错误')
+			}
+		}catch(err){
+			console.log(err.message, err);
+			res.send({
+				status: 0,
+				type: 'ERROR_PARAMS',
+				message: err.message
+			})
+			return 
+		}
+		try{
+			const hongbaos = await HongbaoModel.find({present_status}, '-_id').limit(Number(limit)).skip(Number(offset));
+			res.send(hongbaos)
+		}catch(err){
+			console.log('获取红包数据失败');
+			res.send({
+				status: 0,
+				type: 'ERROR_TO_GET_HONGBAO_DATA',
+				message: '获取红包数据失败'
+			})
+		}
+	}
+}
+
+export default new Hongbao()

+ 24 - 0
controller/v3/explain.js

@@ -0,0 +1,24 @@
+'use strict';
+
+import ExplainModel from '../../models/v3/explain'
+
+class Explain {
+	constructor(){
+
+	}
+	async getExpalin(req, res, next){
+		try{
+			const explain = await ExplainModel.findOne();
+			res.send(explain.data)
+		}catch(err){
+			console.log('获取服务中心数据失败', err);
+			res.send({
+				status: 0,
+				type: 'ERROR_GET_SERVER_DATA',
+				message: '获取服务中心数据失败'
+			})
+		}
+	}
+}
+
+export default new Explain()

+ 43 - 0
models/promotion/hongbao.js

@@ -0,0 +1,43 @@
+'use strict'
+
+import mongoose from 'mongoose'
+import hongbaoData from '../../InitData/hongbao'
+
+const Schema = mongoose.Schema;
+
+const hongbaoSchema = new Schema({
+	id: Number,
+	sn: String,
+	user_id: Number,
+	amount: Number,
+	sum_condition: Number,
+	name: String,
+	phone: String,
+	begin_date: String,
+	end_date: String,
+	description_map: {
+		phone: String,
+		online_paid_only: String,
+		validity_delta: String,
+		validity_periods: String,
+		sum_condition: String
+	},
+	limit_map: {},
+	status: Number,
+	present_status: Number,
+	share_status: Number,
+})
+
+hongbaoSchema.index({id: 1});
+
+const Hongbao = mongoose.model('Hongbao', hongbaoSchema);
+
+Hongbao.findOne((err, data) => {
+	if (!data) {
+		hongbaoData.forEach(item => {
+			Hongbao.create(item)
+		})
+	}
+})
+
+export default  Hongbao

+ 20 - 0
models/v3/explain.js

@@ -0,0 +1,20 @@
+'use strict';
+
+import mongoose from 'mongoose'
+import explainData from '../../InitData/explain'
+
+const Schema = mongoose.Schema;
+
+const explainSchema = new Schema({
+	data: Schema.Types.Mixed,
+})
+
+const Explain = mongoose.model('Explain', explainSchema);
+
+Explain.findOne((err, data) => {
+	if(!data){
+		Explain.create({data: explainData});
+	}
+})
+
+export default Explain

+ 1 - 0
package.json

@@ -42,6 +42,7 @@
     "node-fetch": "^1.6.3",
     "pinyin": "^2.8.3",
     "pm2": "^2.4.6",
+    "qiniu": "^6.1.13",
     "sha1": "^1.1.1",
     "supervisor": "^0.12.0",
     "time-stamp": "^2.0.0",

+ 4 - 0
routes/index.js

@@ -3,10 +3,12 @@
 import home from './home'
 import v1 from './v1'
 import v2 from './v2'
+import v3 from './v3'
 import v4 from './v4'
 import ugc from './ugc'
 import bos from './bos'
 import shopping from './shopping'
+import promotion from './promotion'
 
 export default app => {
 	app.get('/', (req, res, next) => {
@@ -15,8 +17,10 @@ export default app => {
 	app.use('/home', home);
 	app.use('/v1', v1);
 	app.use('/v2', v2);
+	app.use('/v3', v3);
 	app.use('/v4', v4);
 	app.use('/ugc', ugc);
 	app.use('/bos', bos);
 	app.use('/shopping', shopping);
+	app.use('/promotion', promotion);
 }

+ 7 - 1
routes/promotion.js

@@ -1,4 +1,10 @@
 'use strict';
 
 import express from 'express';
-const router = express.Router();
+import Hongbao from '../controller/promotion/hongbao'
+const router = express.Router();
+
+router.get('/v2/users/:user_id/hongbaos', Hongbao.getHongbao)
+router.get('/v2/users/:user_id/expired_hongbaos', Hongbao.getExpiredHongbao)
+
+export default router

+ 6 - 1
routes/v3.js

@@ -1,4 +1,9 @@
 'use strict';
 
 import express from 'express';
-const router = express.Router();
+import Explain from '../controller/v3/explain'
+const router = express.Router();
+
+router.get('/profile/explain', Explain.getExpalin)
+
+export default router

Some files were not shown because too many files changed in this diff