first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,249 @@
const { log } = require("debug");
const _ = require("../import");
/**
* @api {post} /home/index index
* @apiDescription 获取首页商品列表默认返回20条数据不需要参数传空对象 {} 即可
* @apiName index
* @apiGroup Home
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/index
* @apiVersion 1.0.0
*/
_.router.post('/index', async function (req, res, next) {
var data = await _.db.query({
sql: _.config.sql.getIndex,
data: []
})
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
/**
* @api {post} /home/banner banner
* @apiDescription 获取首页的banner数据
* @apiName banner
* @apiGroup Home
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/banner
* @apiVersion 1.0.0
*/
_.router.post('/banner', async function (req, res, next) {
var data = await _.db.query({
sql: _.config.sql.getIndex,
data: []
});
var banner = []
data.forEach((v, i) => {
if (i < 3) {
banner.push(v);
}
});
banner.forEach((v, i) => {
switch (i) {
case 0:
v.banner = "https://img.pconline.com.cn/images/product/6448/644851/novalite-c_m2.jpg"
break;
case 1:
v.banner = "https://2c.zol-img.com.cn/product/199_800x600/122/cet0UsShO9wl.jpg";
break;
case 2:
v.banner = "https://2e.zol-img.com.cn/product/196_800x600/88/ceHLpcITEHhtw.jpg"
break;
}
})
console.log("banner: ", banner);
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(banner)
});
});
/**
* @api {post} /home/recommend recommend
* @apiDescription 获取首页推荐分类的数据
* @apiName recommend
* @apiGroup Home
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/recommend
* @apiVersion 1.0.0
*/
_.router.post('/recommend', async function (req, res, next) {
var recommend = [
{ id: 1, url: '/img/type_1.png', title: '限时白嫖' },
{ id: 2, url: '/img/type_2.png', title: '新品推荐' },
{ id: 3, url: '/img/type_3.png', title: '低价高配' },
{ id: 4, url: '/img/type_4.png', title: '超值特卖' }
];
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(recommend)
});
});
/**
* @api {post} /home/info info
* @apiDescription 获取商品的详情接口
* @apiName info
* @apiGroup Home
* @apiParam {number} id 商品的id参数从 /home/index 接口中获得 wares_id 作为id参数传入即可
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/info
* @apiVersion 1.0.0
*/
_.router.post('/info', async function (req, res, next) {
var id = req.headers.data.id;
var data = (await _.db.query({
sql: _.config.sql.getInfo,
data: [id]
}))[0]
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
/**
* @api {post} /home/activity activity
* @apiDescription 获取首页轮播下活动分类商品的接口
* @apiName activity
* @apiGroup Home
* @apiParam {number} id 活动的id取值对应为1->限时白嫖2->新品推荐3->低价高配4->超值特卖
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/activity
* @apiVersion 1.0.0
*/
_.router.post('/activity', async function (req, res, next) {
var activity_id = req.headers.data.id;
var data = await _.db.query({
sql: _.config.sql.getActivity,
data: [activity_id]
})
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
/**
* @api {post} /home/search search
* @apiDescription 搜索接口,用于首页搜索商品
* @apiName search
* @apiGroup Home
* @apiParam {string} keyword 搜索关键词,例如:小米
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/home/search
* @apiVersion 1.0.0
*/
_.router.post('/search', async function (req, res, next) {
var keyword = req.headers.data.keyword;
console.log("keyword ", keyword)
var data = await _.db.query({
sql: `SELECT * from wares where wares_title LIKE "%${keyword}%"`,
data: []
});
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
module.exports = _.router;