48 lines
1.2 KiB
JavaScript
Executable File
48 lines
1.2 KiB
JavaScript
Executable File
var express = require('express');
|
||
var router = express.Router();
|
||
var db = require("../db");
|
||
var config = require("../confg")
|
||
|
||
/**
|
||
* APP的首页接口
|
||
* 请求地址:http://127.0.0.1:3000/json/2.0/index
|
||
* 请求方式:GET
|
||
* 请求参数:无
|
||
*/
|
||
router.get('/index', function(req, res, next) {
|
||
db.query(config.SqlConfig.index.QueryIndex, {}, result => {
|
||
res.json(result)
|
||
})
|
||
});
|
||
|
||
router.get('/class', function(req, res, next) {
|
||
var brand = req.query.brand;
|
||
console.log(brand)
|
||
db.query(config.SqlConfig.index.QueryClassShop, [brand], result => {
|
||
res.json(result)
|
||
})
|
||
});
|
||
|
||
router.get('/search', function(req, res, next) {
|
||
var keyword = req.query.keyword;
|
||
db.query(`SELECT * from shop_commodity WHERE commodity_name or commodity_brand LIKE '%${keyword}%'`, [], result => {
|
||
res.json(result)
|
||
})
|
||
});
|
||
|
||
/**
|
||
* APP从首页点击商品进入详情的接口
|
||
* 请求地址:http://127.0.0.1:3000/json/2.0/index/info
|
||
* 请求方式:GET
|
||
* 请求参数:
|
||
* id: string 需要请求的商品id,从首页接口获得
|
||
*/
|
||
router.get('/index/info', function(req, res, next) {
|
||
let id = req.query.id
|
||
db.query(config.SqlConfig.index.QueryIndexInfo, id, result => {
|
||
res.json(result)
|
||
})
|
||
});
|
||
|
||
module.exports = router;
|