251 lines
6.0 KiB
JavaScript
Executable File
251 lines
6.0 KiB
JavaScript
Executable File
const { log } = require("debug");
|
||
const _ = require("../import");
|
||
|
||
/**
|
||
* @api {post} /home/token token
|
||
* @apiDescription 获取阿里云资源上传的配置信息。
|
||
* @apiName token
|
||
* @apiGroup Home
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/token
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/token', async function (req, res, next) {
|
||
const mpHelper = new _.uploadOssHelper({
|
||
accessKeyId: 'LTAIXlLtUBP2Cr8F',
|
||
accessKeySecret: 'B6i0KohY3yf0YGM6xsdqrXeGgFMifs',
|
||
timeout: 1,
|
||
maxSize: 10,
|
||
});
|
||
|
||
const params = mpHelper.createUploadParams();
|
||
res.json({
|
||
status: 200,
|
||
message: '请求成功',
|
||
result: params
|
||
});
|
||
})
|
||
|
||
/**
|
||
* @api {post} /home/notice notice
|
||
* @apiDescription 获取最新公告
|
||
* @apiName notice
|
||
* @apiGroup Home
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/notice
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/notice', async function (req, res, next) {
|
||
|
||
var data = await _.db.query({
|
||
sql: _.config.sql.getNotice,
|
||
data: []
|
||
})
|
||
|
||
res.json({
|
||
status: 200,
|
||
message: '请求成功',
|
||
result: data
|
||
});
|
||
});
|
||
|
||
|
||
/**
|
||
* @api {post} /home/push push
|
||
* @apiDescription 发布寻物启事
|
||
* @apiName push
|
||
* @apiGroup Home
|
||
* @apiParam {number} user_id 用户id
|
||
* @apiParam {string} thing_title 标题
|
||
* @apiParam {string} thing_introduce 介绍信息
|
||
* @apiParam {string} thing_img 图片地址
|
||
* @apiParam {number} thing_type 类型: 1 失物招领,2 寻物启事
|
||
* @apiParam {number} thing_category 物品的类别, 1证件 2服装 3数码 4日用品 5其他
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/push
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/push', async function (req, res, next) {
|
||
|
||
let { user_id, thing_title, thing_introduce, thing_img, thing_type, thing_category } = req.body;
|
||
|
||
var data = await _.db.query({
|
||
sql: _.config.sql.push,
|
||
data: [ user_id, thing_title, thing_introduce, thing_img, thing_type, thing_category]
|
||
})
|
||
|
||
res.json({
|
||
status: 200,
|
||
message: '发布成功',
|
||
result: '发布成功'
|
||
});
|
||
});
|
||
|
||
|
||
/**
|
||
* @api {post} /home/info info
|
||
* @apiDescription 获取商品的详情接口
|
||
* @apiName info
|
||
* @apiGroup Home
|
||
* @apiParam {number} thing_id 寻物启事的 thing_id
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/info
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/info', async function (req, res, next) {
|
||
var { thing_id } = req.body;
|
||
|
||
var data = await _.db.query({
|
||
sql: _.config.sql.getInfo,
|
||
data: [thing_id]
|
||
})
|
||
|
||
res.json({
|
||
status: 200,
|
||
message: '请求成功',
|
||
result: data[0]
|
||
});
|
||
});
|
||
|
||
|
||
/**
|
||
* @api {post} /home/tab tab
|
||
* @apiDescription 获取广场的数据
|
||
* @apiName tab
|
||
* @apiGroup Home
|
||
* @apiParam {number} thing_type 1 失物招领,2 寻物启事
|
||
* @apiParam {number} thing_category 物品的类别,1证件 2服装 3数码 4日用品 5其他
|
||
* @apiParam {number} page 分页 默认 1
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/tab
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/tab', async function (req, res, next) {
|
||
var { thing_type, thing_category, page } = req.body;
|
||
page -= 1;
|
||
|
||
var data = await _.db.query({
|
||
sql: thing_category == -1 ? _.config.sql.allTabs : _.config.sql.tabs,
|
||
data: thing_category == -1 ? [thing_type, page] : [thing_type, thing_category, page]
|
||
})
|
||
|
||
res.json({
|
||
status: 200,
|
||
message: '请求成功',
|
||
result: data
|
||
});
|
||
|
||
});
|
||
|
||
|
||
|
||
/**
|
||
* @api {post} /home/search search
|
||
* @apiDescription 搜索接口
|
||
* @apiName search
|
||
* @apiGroup Home
|
||
* @apiParam {number} keyword 搜索的内容
|
||
* @apiParam {number} page 页数
|
||
* @apiSuccessExample {json} 请求成功的返回:
|
||
* {
|
||
* "status" : 200,
|
||
* "message" : "请求成功"
|
||
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
|
||
* }
|
||
* @apiErrorExample {json} 请求失败的返回
|
||
* {
|
||
* "status": 404,
|
||
* "message" : "请求失败"
|
||
* "result": null
|
||
* }
|
||
* @apiSampleRequest http://127.0.0.1:3030/home/search
|
||
* @apiVersion 1.0.0
|
||
*/
|
||
_.router.post('/search', async function (req, res, next) {
|
||
var { keyword, page } = req.body;
|
||
|
||
page -= 1
|
||
|
||
var data = await _.db.query({
|
||
sql: _.config.sql.search,
|
||
data: [keyword, page]
|
||
})
|
||
|
||
if (data.length != 0) {
|
||
res.json({
|
||
status: 200,
|
||
message: '请求成功',
|
||
result: data
|
||
});
|
||
} else {
|
||
res.json({
|
||
status: 200,
|
||
message: '暂无数据',
|
||
result: []
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
|
||
module.exports = _.router;
|
||
|