mall-wu-jiang
v1.0.8
Published
UTIL CONfig.js 一、 // token 秘钥 const secret = 'zxcvbnm123456'
Downloads
10
Readme
UTIL CONfig.js 一、 // token 秘钥 const secret = 'zxcvbnm123456'
//白名单
const whiteList = [/^\/myweb/,'/goods/type','/goods/detail','/goods/list',/^\/phone/,];
module.exports = {
secret,
whiteList
}
二、 IORedis.js const Redis = require('ioredis'); const redis = new Redis()
function get(key) {
return redis.get(key)
}
function set(key, time,val) {
return redis.setex(key, time,val);
}
module.exports = {
get,set
}
三、 Jwt var jwt = require('jsonwebtoken'); var {secret} = require('./config'); // const secret = 'zxcvbnm123456'
// class JWT {
// constructor(parameter) {
// }
// sign(userinfo) {
// return jwt.sign(userinfo, secret, { expiresIn: '2h'})
// }
// verify(token) {
// return jwt.verify(token, secret)
// }
// }
function sign(userinfo) {
return jwt.sign(userinfo, secret, { expiresIn: '2h'})
}
function verify(token) {
return jwt.verify(token, secret)
}
module.exports = {
sign,
verify
}
List of goods
const query = require('../db/query');
//查询二级分类
const selectType = ()=>{
let sql = `select * from type_tab`;
return query(sql)
}
//查询商品
const selectGoods = (params)=>{
/*
typeid 二级分类
title 标题 模糊查询
goodsid 商品 id
page count 分页查询
*/
let sql = `select * from goods_tab `;
if (params?.typeid || params?.title || params?.goodsid || params?.brandid ) {
sql += ' where '
}
//根据分类查询
if (params?.typeid ) {
sql += ` typeid = ${params.typeid} `
}
//根据商品 id 查询
if (params?.goodsid ) {
sql += ` goodsid = ${params.goodsid} `
}
//根据品牌 id 查询
if (params?.brandid ) {
sql += ` brandid = '${params.brandid}' `
}
//模糊查询
if (params?.title ) {
sql += ` title like '%${params.title}%' `
}
//根据价格升序降序
// select * from goods_tab order by price desc
if (params?.desc == 1 ) { // desc 1 升序 2 降序
sql += ` order by price `
}else if (params?.desc == 2 ){
sql += ` order by price desc`
}
//根据品牌查询
if (params?.title ) {
sql += ` title like '%${params.title}%' `
}
//根据品牌查询
if (params?.page && params?.count) {
sql += ` limit ${(params.page-1)*params.count},${params.count} `
}
console.log(sql);
return query(sql)
}
const selectGoodsDetail = (params)=>{
// 多表 两表联查
// select * from 表1 inner join 表2 on 表1.articleid = 表二.tagid where 表1.articleid = 10001
// join 拼接
// let sql = `select * from comment_tab inner join detail_tab `
// sql+=`on comment_tab.goodsid = detail_tab.goodsid where comment_tab.goodsid=${params.goodsid}`
//多表 三表联查
let sql = `select * from goods_tab as t1 inner join comment_tab as t2 on t1.goodsid = t2.goodsid `
sql += `inner join detail_tab as t3 on t1.goodsid=t3.goodsid `
sql += `where t1.goodsid=${params.goodsid}`
// console.log(sql);
return query(sql)
}
//更新点赞状态
const updateCommentZan = (params)=>{
// update 表名 set 列名 = '内容' where userid = "标识值"
let sql = `update comment_tab set zan = ${params.zan},userid = ${params.userid} where id=${params.id}`
console.log(sql);
return query(sql)
}
const selectZan = ()=>{
// update 表名 set 列名 = '内容' where userid = "标识值"
let sql = `select * from comment_tab where zan=1`
console.log(sql);
return query(sql)
}