Files
ClassContent/历届学生/罗朝/项目练习/电商App/back-shop/routes/index.js
2024-09-27 02:06:13 +08:00

48 lines
1.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;