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 @@
c1d61e30-06c0-487d-9b66-53565d72504d

View File

@@ -0,0 +1,279 @@
const _ = require("../import");
/**
* @api {post} /car/addCar addCar
* @apiDescription 详情页添加商品到购物车
* @apiName addCar
* @apiGroup car
* @apiParam {number} waresid 需要被收藏的商品idwares_id字段
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "成功添加购物车"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "不要重复收藏"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/addCar
* @apiVersion 1.0.0
*/
_.router.post('/addCar', async function(req, res, next) {
var shopid = req.headers.data.waresid;
var IsAddShopCar = await _.db.query({
sql: _.config.sql.selectCarShop,
data: [ _.jwt.decode(req.headers.token).id, shopid]
});
if(IsAddShopCar.length != 0) {
res.json({
status: 404,
message: '不要添加购物车',
result: null
});
} else {
var data = await _.db.query({
sql: _.config.sql.addCar,
data: [ _.jwt.decode(req.headers.token).id, shopid, 1]
});
res.json({
status: 200,
message: '成功添加购物车',
result: _.rsa.PrivateKeyEncryption(data)
});
}
});
/**
* @api {post} /car/getCarList getCarList
* @apiDescription 获取用户的购物车商品数据(不需要参数,传空对象 {} 即可
* @apiName getCarList
* @apiGroup car
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "购物车没有数据"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/getCarList
* @apiVersion 1.0.0
*/
_.router.post('/getCarList', async function(req, res, next) {
var data = await _.db.query({
sql: _.config.sql.getCarList,
data: [ _.jwt.decode(req.headers.token).id]
});
if(data.length != 0) {
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
} else {
res.json({
status: 200,
message: '购物车没有数据',
result: _.rsa.PrivateKeyEncryption({})
});
}
});
/**
* @api {post} /car/checkCar checkCar
* @apiDescription 检查商品是否已经被用户添加到购物车,已添加 result 为true未添加 result 为false
* @apiName checkCar
* @apiGroup car
* @apiParam {number} waresid 商品idwares_id字段
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "商品已添加购物车"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 200,
* "message" : "商品未添加购物车"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/checkCar
* @apiVersion 1.0.0
*/
_.router.post('/checkCar', async function(req, res, next) {
var shopid = req.headers.data.waresid;
console.log("req.headers.data: ", req.headers.data);
var IsAddShopCar = await _.db.query({
sql: _.config.sql.selectCarShop,
data: [ _.jwt.decode(req.headers.token).id, shopid]
});
console.log("IsAddShopCar ==== :", IsAddShopCar);
if(IsAddShopCar.length != 0) {
res.json({
status: 200,
message: '商品已添加购物车',
result: _.rsa.PrivateKeyEncryption({
isAddCar: true
})
});
} else {
res.json({
status: 200,
message: '商品未添加购物车',
result: _.rsa.PrivateKeyEncryption({
isAddCar: false
})
});
}
});
/**
* @api {post} /car/deleteCar deleteCar
* @apiDescription 删除被添加到购物车的商品
* @apiName deleteCar
* @apiGroup car
* @apiParam {Array} carid 购物车商品id从getCarList接口中获得car_id即可。参数格式"[1,2,3]"
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "删除成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 200,
* "message" : "删除失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/deleteCar
* @apiVersion 1.0.0
*/
_.router.post('/deleteCar', async function(req, res, next) {
var carid = req.headers.data.carid;
carid.forEach(async function(val) {
var deleteCar = await _.db.query({
sql: _.config.sql.deleteCarShop,
data: [ val ]
});
});
res.json({
status: 200,
message: '删除成功',
result: _.rsa.PrivateKeyEncryption({})
});
});
/**
* @api {post} /car/updateCarNum updateCarNum
* @apiDescription 更新购物车需要购买的商品数量
* @apiName updateCarNum
* @apiGroup car
* @apiParam {number} carid 购物车商品id从getCarList接口中获得car_id即可
* @apiParam {number} quantity 购物车商品的数量
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "更新成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 200,
* "message" : "更新失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/updateCarNum
* @apiVersion 1.0.0
*/
_.router.post('/updateCarNum', async function(req, res, next) {
var carid = req.headers.data.carid;
var quantity = req.headers.data.quantity;
var updateCarNum = await _.db.query({
sql: _.config.sql.updateCarNum,
data: [ quantity, carid ]
});
console.log(updateCarNum)
if(updateCarNum.affectedRows == 1) {
res.json({
status: 200,
message: '更新成功',
result: _.rsa.PrivateKeyEncryption({})
});
} else {
res.json({
status: 404,
message: '更新失败',
result: _.rsa.PrivateKeyEncryption({})
});
}
});
/**
* @api {post} /car/submitCar submitCar
* @apiDescription 更新购物车需要购买的商品数量,提交的数据是个对象,例如:"{"carList":[{"waresid":113,"goodsnum":2,"goodsprice":1000},{"waresid":114,"goodsnum":1,"goodsprice":1100}]}"
* @apiName submitCar
* @apiGroup car
* @apiParam {Object} carList 为对象,包含下面三个参数,需要前端自己构造数组
* @apiParam {string} waresid 商品的waresid
* @apiParam {string} goodsnum 购买的数量
* @apiParam {string} goodsprice 购买的单价
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "订单增加成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 200,
* "message" : "订单增加失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/car/submitCar
* @apiVersion 1.0.0
*/
_.router.post('/submitCar', async function(req, res, next) {
//"{"carList":[{"waresid":113,"goodsnum":2,"goodsprice":1000},{"waresid":114,"goodsnum":1,"goodsprice":1100}]}"
var carList = JSON.parse(req.headers.data).carList;
carList.forEach(async function(val) {
val.user_id = _.jwt.decode(req.headers.token).id;
var addCarToOrder = await _.db.query({
sql: _.config.sql.addCarToOrder,
data: [ val.user_id,val.waresid,val.goodsnum,val.goodsprice,val.goodsnum * val.goodsprice]
});
});
res.json({
status: 200,
message: '订单增加成功',
result: _.rsa.PrivateKeyEncryption({})
});
});
module.exports = _.router;

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;

View File

@@ -0,0 +1,102 @@
const _ = require("../import");
/**
* @api {post} /order/allOrder allOrder
* @apiDescription 获取不同状态的订单
* @apiName allOrder
* @apiGroup order
* @apiParam {string} status 查询的订单状态0待付款1待发货2待收货3退款/售后,-1查看所有订单
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/order/allOrder
* @apiVersion 1.0.0
*/
_.router.post('/allOrder', async function(req, res, next) {
var status = req.headers.data.status, sql = null, params = [];
if (status == -1) {
sql = _.config.sql.getAllOrder
params = [ _.jwt.decode(req.headers.token).id ]
} else {
sql = _.config.sql.getStatusOrder
params = [ _.jwt.decode(req.headers.token).id, status]
}
var allOrder = await _.db.query({
sql: sql,
data: params
});
if(allOrder.length != 0) {
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(allOrder)
});
} else {
res.json({
status: 200,
message: '没有订单',
result: _.rsa.PrivateKeyEncryption({})
});
}
});
/**
* @api {post} /order/buyOrder buyOrder
* @apiDescription submitCar提交订单后订单页面购买支付后需要用的接口更改订单状态为待发货
* @apiName buyOrder
* @apiGroup order
* @apiParam {Array} goodsid 订单的goods_id从allOrder接口中获得。参数格式"[5,6]"
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "购买成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "购买失败,余额不足"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/order/buyOrder
* @apiVersion 1.0.0
*/
_.router.post('/buyOrder', async function(req, res, next) {
var goods_id = JSON.parse(req.headers.data.goodsid);
goods_id.forEach(async function(val) {
var buyOrder = await _.db.query({
sql: _.config.sql.buyOrder,
data: [ 1, val ]
});
});
res.json({
status: 200,
message: '购买成功',
result: _.rsa.PrivateKeyEncryption({})
});
});
module.exports = _.router;

View File

@@ -0,0 +1,44 @@
const _ = require("../import");
/**
* @api {post} /type/list list
* @apiDescription 分类页面获取分类商品的接口
* @apiName list
* @apiGroup type
* @apiParam {string} typename 分类的中文名称,例如:小米
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/type/list
* @apiVersion 1.0.0
*/
_.router.post('/list', async function(req, res, next) {
var typename = req.headers.data.typename;
var data = await _.db.query({
sql: _.config.sql.getTypeList,
data: [ typename ]
});
data.forEach(function (val,index) {
val.wares_masterimg = JSON.parse(val.wares_masterimg)[0]
});
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
module.exports = _.router;

View File

@@ -0,0 +1,255 @@
const _ = require("../import");
/**
* @api {post} /user/login login
* @apiDescription 用户登录的接口注意用户登录成功后会在result中包含token参数请前端本地保存token。
* @apiName login
* @apiGroup user
* @apiParam {string} name 用户名
* @apiParam {string} pwd 用户密码
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求错误"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/user/login
* @apiVersion 1.0.0
*/
_.router.post('/login', async function (req, res, next) {
var username = req.headers.data.name,
userpwd = req.headers.data.pwd;
console.log("username: ", username);
console.log("userpwd: ", userpwd);
var data = await _.db.query({
sql: _.config.sql.userLogin,
data: [username,_.utils.Md5Password(userpwd)]
})
if (data.length != 0 ){
var token = _.jwt.sign({
id: data[0].user_id,
username: data[0].user_name
}, _.config.jwt, { expiresIn: '3h' }); // 1m
res.json({
status: 200,
message: '登录成功',
result: _.rsa.PrivateKeyEncryption({
token: token
})
});
} else {
res.json({
status: 404,
message: '账户名或密码有误',
result: null
});
}
});
/**
* @api {post} /user/add add
* @apiDescription 用户注册的接口
* @apiName add
* @apiGroup user
* @apiParam {string} name 用户名
* @apiParam {string} pwd 用户密码
* @apiParam {string} phone 用户手机号
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "注册成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "注册失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/user/add
* @apiVersion 1.0.0
*/
_.router.post('/add', async function (req, res, next) {
var username = req.headers.data.name,
userpwd = req.headers.data.pwd,
userphone = req.headers.data.phone;
var data = await _.db.query({
sql: _.config.sql.addUser,
data: [username,_.utils.Md5Password(userpwd),userphone, _.utils.getTime()]
})
if(data.hasOwnProperty('insertId')) {
res.json({
status: 200,
message: '注册成功',
result: _.rsa.PrivateKeyEncryption({})
});
} else {
res.json({
status: 404,
message: '注册失败',
result: null
});
}
});
/**
* @api {post} /user/like like
* @apiDescription 用户在详情页收藏商品使用的接口
* @apiName like
* @apiGroup user
* @apiParam {number} shopid 需要被收藏商品的id这里是商品的 wares_id 字段
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "收藏成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "抱歉,请勿重复收藏"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/user/like
* @apiVersion 1.0.0
*/
_.router.post('/like', async function (req, res, next) {
var like_shop = req.headers.data.shopid;
var IsLike = await _.db.query({
sql: _.config.sql.selectLike,
data: [like_shop,_.jwt.decode(req.headers.token).id]
});
if(IsLike.length != 0) {
res.json({
status: 404,
message: '抱歉,请勿重复收藏',
result: _.rsa.PrivateKeyEncryption({})
});
} else {
var data = await _.db.query({
sql: _.config.sql.likeShop,
data: [like_shop, _.jwt.decode(req.headers.token).id]
});
if(data.hasOwnProperty('insertId')) {
res.json({
status: 200,
message: '收藏成功',
result: _.rsa.PrivateKeyEncryption({})
});
} else {
res.json({
status: 404,
message: '收藏失败',
result: null
});
}
}
});
/**
* @api {post} /user/likeList likeList
* @apiDescription 获取用户收藏的商品不需要参数后端会解密请求头token获取user_id
* @apiName likeList
* @apiGroup user
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 404,
* "message" : "请求失败"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/user/likeList
* @apiVersion 1.0.0
*/
_.router.post('/likeList', async function(req, res, next) {
var data = await _.db.query({
sql: _.config.sql.getLikeList,
data: [ _.jwt.decode(req.headers.token).id ]
});
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
});
/**
* @api {post} /user/getUserAddress getUserAddress
* @apiDescription 获取用户的收货地址(不需要参数,传空对象 {} 即可
* @apiName getUserAddress
* @apiGroup user
* @apiSuccessExample {json} 请求成功的返回:
* {
* "status" : 200,
* "message" : "请求成功"
* "result" : "asjXzXxmnSp8TZGWiTSlJF8Gb...5LhYoHs86SEI2LBXrTZ9e/a4frZOWHZ"
* }
* @apiErrorExample {json} 请求失败的返回
* {
* "status": 200,
* "message" : "没有收货地址"
* "result": null
* }
* @apiSampleRequest http://127.0.0.1:9090/user/getUserAddress
* @apiVersion 1.0.0
*/
_.router.post('/getUserAddress', async function(req, res, next) {
var data = await _.db.query({
sql: _.config.sql.getUserAddress,
data: [ _.jwt.decode(req.headers.token).id ]
});
if (data[0].user_address == null || data[0].user_address.length == 0) {
res.json({
status: 200,
message: '没有收货地址',
result: _.rsa.PrivateKeyEncryption({})
});
} else {
res.json({
status: 200,
message: '请求成功',
result: _.rsa.PrivateKeyEncryption(data)
});
}
});
module.exports = _.router;