1 Star 0 Fork 0

懒大王/back end

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
router.js 69.72 KB
一键复制 编辑 原始数据 按行查看 历史
懒大王 提交于 2020-04-03 16:48 . '第一版本结束'
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
const express = require('express'); // express 框架
const fs = require('fs') // 引入fs核心模块
const path = require('path'); // 引入 path 核心模块
const md5 = require('md5'); // 引入md5 加载密码
const User = require('./nodels/User'); // 封装用户文档集合 (表)
const Cart = require('./nodels/Cart') // 购物车集合
const Coupon = require('./nodels/Coupon') // 评论集合
const Order = require('./nodels/Order') // 订单集合
const sendEmail = require('./nodels/sendEmail'); // 封装发送邮件模块
const formidable = require('formidable')
const multer = require('multer'); // 保存图片模块
// const upload = multer({ dest: 'public/img/avatar/'}) // 文件储存路径
const storage = multer.diskStorage({
//设置上传后文件路径,uploads文件夹会自动创建。
destination: function (req, file, cb) {
if (req.url === '/sendGoods' && file.fieldname == 'goods') {
cb(null, './public/img/goods')
} else if (req.url === '/sendGoods' && file.fieldname == 'goodsParams') {
cb(null, './public/img/goodsparams')
}else if (req.url === '/sendGoods' && file.fieldname == 'goodsDesc') {
cb(null, './public/img/goodsdesc')
}
else if (req.url === '/sendfile') {
cb(null, './public/img/avatar')
}
else if (req.url === '/editgoods') {
if (file.fieldname == 'goods') {
cb(null, './public/img/goods')
}
if (file.fieldname == 'goodsParams') {
cb(null, './public/img/goodsparams')
}
if (file.fieldname == 'goodsDesc') {
cb(null, './public/img/goodsdesc')
}
} else if (req.url === '/addFirstSwiper') {
cb(null, './public/img/firstSwiper')
}else if (req.url == '/changeLogo') {
cb(null, './public/img/logo')
}
},
// 给上传文件重命名,获取添加后缀名
filename: function (req, file, cb) {
let fileFormat = (file.originalname).split(".");
if (req.url === '/sendGoods' || req.url === '/editgoods' || req.url === '/addFirstSwiper') {
cb(null, new Date().getTime() + "." + fileFormat[fileFormat.length - 1]);
} else if (req.url === '/sendfile') {
cb(null, req.session.user._id + "." + fileFormat[fileFormat.length - 1]);
}else if (req.url === '/changeLogo') {
cb(null, 'newLogo.' + fileFormat[fileFormat.length - 1])
}
}
});
const upload = multer({
storage: storage
});
const alipayBox = require('./nodels/util/alipayBox') // 封装阿里支付
const Comment = require('./nodels/Comment')
let authorityPassword = 'motherandboby'
// 工具函数
const {upDataUrlAndDelFile, getNewUrlAndFileName, appendParams} = require('./nodels/util/changeGoods')
// 导入商家模块
const Good = require('./nodels/Good') // 商品集合
const GoodsType = require('./nodels/GoodsType') // 商品类型集合
const BusinessAccount = require('./nodels/BusinessAccount') // 商家账号集合
const BaseSetUp = require('./nodels/BaseSetUp') // 商家对系统设置集合
const Notice = require('./nodels/Notice')
// 路由
const router = express.Router();
// 解决跨域问题
router.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:8080");
// res.header("Access-Control-Allow-Origin", '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
// res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
// 加载前端页面
router.get('/', (request, response)=> {
response.sendFile(path.join(__dirname, 'dist', 'index.html'))
})
// 处理提交注册信息
router.post('/register', (request, response)=>{
request.body.password = md5(md5(request.body.password));
new User(request.body).save((err)=>{
if (err) {
return response.status(500).json({
res_code: 0,
message: 'Server error.'
})
} else {
return response.status(200).json({
res_code: 0,
message: 'success'
})
}
})
})
// 查询邮箱是否重复
router.get('/findEmail',(request, response)=>{
User.findOne({
email: request.query.email
}, (err, data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: '访问人数过多,请稍后重试'
})
}
if (data) {
return response.status(200).json({
res_code: 1,
message: '当前邮箱被注册'
})
} else {
return response.status(200).json({
res_code: 2,
message: '当前邮箱可用'
})
}
})
})
// 获取验证码
router.get('/getCode',(request, response)=>{
// console.log(request.query.email)
let emailCode = Math.random().toString().slice(-6) //验证码为6位随机数
let email = {
title: 'MotherAndBobyMall--邮箱验证码',
htmlBody: '<h1>Hello!</h1><p style="font-size: 18px;color:#000;">验证码为:<u style="font-size: 16px;color:#1890ff;">'+ emailCode +'</u></p><p style="font-size: 14px;color:#666;">10分钟内有效</p>>'
}
let mailOptions = {
from: '2465431331@qq.com', // 发件人地址
to: request.query.email, // 收件人地址,多个收件人可以使用逗号分隔
subject: email.title, // 邮件标题
html: email.htmlBody // 邮件内容
};
sendEmail.send(mailOptions)
response.status(200).json({
key_code: emailCode
})
})
// 验证登录信息
router.post('/signIn', (request, response)=> {
User.findOne({
email: request.body.email,
password: md5(md5(request.body.password))
}, (err, data)=>{
if (err) {
return response.status('500').json({
res_code: 0,
message: 'Serve Busy'
})
}else {
if (!data) {
response.status(200).json({
res_code: 1,
message: 'Email Or Password Invalid'
})
}else {
request.session.user = data;
response.status(200).json({
res_code: 2,
message: 'OK',
userMessage: data,
})
}
}
})
})
// 前端保持登录状态
router.post('/getUser', (request, response)=> {
if (request.session.user) {
User.findById(request.session.user._id, (err, data)=> {
return response.status(200).json({
user: data
})
})
} else {
return response.status(200).json({
user: null
})
}
})
// 退出登录
router.post('/signout', (request, response)=> {
// console.log(request.session.user);
request.session.user = null
response.status(200).send()
})
// 更新用户信息
router.post('/changeInformation', (request, response)=> {
console.log(request.session.user);
User.findByIdAndUpdate(request.session.user._id,request.body.config,(err, data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}else {
return response.status(200).json({
res_code: 1,
message: 'OK'
})
}
})
// console.log(request.body.config);
// response.send()
})
// 更改密码
router.post('/changepassword', (request, response)=> {
console.log(request.body)
User.findOne({
_id: request.session.user,
password:md5(md5( request.body.config.oldpassword))
}, (err, data)=>{
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}
if(!data) {
return response.status(200).json({
res_code: 1,
message: '旧密码错误'
})
}else {
User.findByIdAndUpdate(request.session.user._id,{
password: md5(md5(request.body.config.newpassword))
},(err)=>{
if(err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
}
})
})
// 操作用户收货地址
router.get('/receivingaddress', (request, response)=> {
if (!request.session.user) {
response.status(200).json({
res_code: 1,
message: ' Account number is Invalid '
})
}else {
User.findById(request.session.user._id,function (err,user) {
if (err) {
return response.status(500).json({
res_code: 0,
messsage: err.message
})
}else {
user.address.push(JSON.parse(request.query.data));
user.markModified('address');
user.save((err)=>{
if(err) {
return response.status(500).json({
res_code: 1,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
}
})
}
})
// 更改收货地址
router.post('/changeaddress', (request, response)=> {
if (!request.session.user) {
return response.status(500).json({
res_code: 0,
message: ' Account number is Invalid '
})
}else {
User.findById(request.session.user._id,(err, user)=>{
if (err) {
return response.status(500).json({
res_code: 1,
message: err.message
})
}else {
user.address.splice(request.body.index, 1, request.body.data);
user.markModified('address');
user.save((err)=>{
if(err) {
return response.status(500).json({
res_code: 1,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
}
})
}
})
// 删除收货地址
router.get('/deleaddress',(request,response)=>{
User.findById(request.session.user._id, (err, user)=>{
if (err) {
return response.status(500).json({
res_code: 1,
message: err.message
})
}else {
user.address.splice(request.query.data , 1);
user.markModified('address');
user.save((err)=>{
if(err) {
return response.status(500).json({
res_code: 1,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
}
})
})
// 用户上传图像
router.post('/sendfile', upload.single('avatar'), (request,response)=> {
let file = request.file;
// console.log(file)
// console.log(request.session,222);
let path = `http://localhost:3000/public/img/avatar/${file.filename}`;
User.findByIdAndUpdate(request.session.user._id,{
avatar: path
}, (err)=> {
if(err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}
})
response.json({
res_code: 2,
message: 'OK',
path: path
})
})
/*
*
* 处理商家请求
*
* */
// sendGoods
router.post('/sendGoods', upload.fields([{name: 'goods', maxCount: 99}, {name: 'goodsParams',maxCount: 99}, {name: 'goodsDesc',maxCount: 99}]), (request, respones)=>{
let files = request.files;
let goods = request.body;
goods.category = goods.category.split(',')
goods.paramsFilename = [];
goods.params = [];
goods.descFilename = [];
goods.desImg = [];
goods.goodsFilename = [];
goods.goodsImg = [];
if (request.body.paramTitle instanceof Array) {
for (let i in files.goodsParams) {
goods.paramsFilename.push(files.goodsParams[i].filename)
goods.params.push({
title: request.body.paramTitle[i],
url: `http://localhost:3000/public/img/goodsparams/${files.goodsParams[i].filename}`
})
}
} else {
for (let i of files.goodsParams) {
goods.paramsFilename.push(i.filename)
goods.params.push({
title: request.body.paramTitle,
url: `http://localhost:3000/public/img/goodsparams/${i.filename}`
})
}
}
for (let i of files.goods) {
goods.goodsFilename.push(i.filename)
goods.goodsImg.push({url:`http://localhost:3000/public/img/goods/${i.filename}`})
}
for (let i of files.goodsDesc) {
goods.descFilename.push(i.filename)
goods.desImg.push({url: `http://localhost:3000/public/img/goodsdesc/${i.filename}`})
}
new Good(goods).save((err, data)=> {
if (err) {
respones.status(500).json({
res_code: 0,
message: err.message
})
} else {
respones.status(200).json({
res_code: 2,
message: 'OK',
goods: data
})
}
});
})
// 修改商品
router.post('/editgoods', upload.fields([{name: 'goods', maxCount: 99}, {name: 'goodsParams',maxCount: 99}, {name: 'goodsDesc',maxCount: 99}]), (request, response)=> {
let files = request.files;
Good.findById(request.body._id, (err, data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
} else {
upDataUrlAndDelFile({
delUrl: request.body.delGoodsFile,
dataUrl: data.goodsImg,
dataName: data.goodsFilename,
path: 'goods',
})
if (files.goods) {
getNewUrlAndFileName(files.goods, data,'goods')
}
upDataUrlAndDelFile({
delUrl: request.body.delDescFile,
dataUrl: data.desImg,
dataName: data.descFilename,
path: 'goodsdesc',
})
if (files.goodsDesc) {
getNewUrlAndFileName(files.goodsDesc, data, 'goodsDesc')
}
upDataUrlAndDelFile({
delUrl: request.body.delGoodsParamsUrl,
dataUrl: data.params,
dataName: data.paramsFilename,
path: 'goodsparams',
})
if (files.goodsParams) {
appendParams(files.goodsParams, data, request.body.paramTitle)
}
data.name = request.body.name;
data.category = request.body.category.split(',');
data.isSell = request.body.isSell;
data.price = request.body.price;
data.describe = request.body.describe;
data.stock = request.body.stock;
data.save((err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
}else {
response.status(200).json({
res_code: 2,
message: 'OK',
goods: data
})
}
});
}
})
})
// 获取所有商品
router.post('/getallgoods', (request, response)=> {
Good.find({},(err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
}else {
response.status(200).json({
res_code: 2,
message: 'OK',
goods: data
})
}
})
});
// 更改商品上架状态
router.post('/changesell', (request, response)=> {
Good.findByIdAndUpdate(request.body.id, {
isSell: request.body.isSell
}, err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
})
// 删除商品
router.post('/delgoods', (request, response)=> {
let p1,p2,p3;
Good.findById(request.body.id, (err, data)=> {
})
Good.findByIdAndRemove(request.body.id, (err, data)=> {
p1 = new Promise((resolve, reject) => {
data.goodsFilename.forEach(item=> {
fs.unlink(path.join(__dirname, 'public','img','goods', item), err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
} else {
resolve()
}
})
})
})
p2 = new Promise((resolve, reject) => {
data.paramsFilename.forEach(item=> {
fs.unlink(path.join(__dirname, 'public','img','goodsparams', item), err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
} else {
resolve()
}
})
})
})
p3 = new Promise((resolve, reject) => {
data.descFilename.forEach(item=> {
fs.unlink(path.join(__dirname, 'public','img','goodsdesc', item), err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
} else {
resolve()
}
})
})
})
Promise.all([p1, p2, p3]).then(()=>{
response.status(200).json({
res_code: 2,
message: 'OK'
});
});
})
})
// 添加商品种类
router.post('/addtype', (request, response)=> {
GoodsType.findOne({
value: request.body.value
}, (err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
if (!data) {
new GoodsType({
value: request.body.value[0],
label: request.body.label,
children: [{
value: request.body.value[0] + 1,
label: request.body.title
}]
}).save((err,data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message,
})
} else {
response.status(200).json({
res_code: 2,
message: 'Ok',
data: data
})
}
})
} else {
data.children.push({
value: data.children.length + 1 + data.value,
label: request.body.title
})
response.status(200).json({
res_code: 2,
message: 'Ok',
data: data
})
data.save()
}
}
})
})
// 获取所有商品分类
router.post('/getgoodstype', (request, response)=> {
GoodsType.find({}, (err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
response.status(200).json({
res_code: 2,
message: 'OK',
data: data
})
}
})
})
// 删除商品子分类
router.post('/deltype', (request, response)=> {
let condition = Math.floor(request.body.value / 1000) *1000
GoodsType.findOne({
value: condition
}, (err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
let num;
data.children.filter((item, index)=> {
if (item.value === request.body.value) {
num = index
}
});
data.children.splice(num, 1);
data.save(err=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
}
})
})
// 修改商品子分类名称
router.post('/edittype', (request, response)=> {
GoodsType.findOne({
value: request.body.value
}, (err, data)=> {
data.children.find((item)=> {
if (item.value == request.body.code) {
item.label = request.body.title
}
})
data.markModified('children')
data.save(err=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
})
})
// 获取分类子分类
router.post('/singlegoodstype', (request, response)=> {
GoodsType.findOne({
value: request.body.value
}, (err, data)=> {
if (err) {
response.status(500).json({
res_code: 0,
message: err.message
})
} else {
if (data) {
response.status(200).json({
res_code: 2,
message: 'OK',
data: data,
})
} else {
response.status(200).json({
res_code: 1,
message: 'GoodsType Is Null',
})
}
}
})
});
// 获取分类对应的商品
router.post('/singlegoods', (request, response)=> {
request.body.value = request.body.value + ''
Good.find({
category: {$in: [,request.body.value]}
}, (err, data)=> {
if (err) {
console.log(err.message)
}else {
if (request.body.screen == 'sales') {
data.sort((firstEl, secondEl)=> secondEl.salesd - firstEl.salesd)
}else if (request.body.screen == 'praise') {
data.sort((firstEl, secondEl)=> secondEl.star - firstEl.star)
}else if (request.body.screen == 'new') {
data.reverse()
}
if (request.body.price instanceof Array) {
data = data.filter(item=> item.price > request.body.price[0] && item.price < request.body.price[1])
}
let goods = null;
if (request.body.currentPage == 1) {
goods = data.slice(0, 13);
} else {
goods = data.slice((request.body.currentPage -1) * 12 -1, request.body.currentPage *12);
}
let num = data.length/12;
if (num > Math.floor(num)) {
num = Math.floor(num) + 1
}
response.status(200).json({
res_code: 2,
message: 'ok',
goods: goods,
totalPage: num * 10
})
}
})
});
// 获取单个商品
router.post('/getdetail', (request, response)=> {
Good.findById(request.body.id, (err, data)=> {
if (err) response.status(500).json({res_code:0, message: err.message})
response.status(200).json({
res_code: 2,
message: 'OK',
goods: data
})
})
});
// 收藏商品
router.post('/collection', (request, response)=> {
Good.findById(request.body.id,(err,data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}else {
if (request.body.isCollection) {
data.favorites--;
User.findByIdAndUpdate(request.session.user._id,{
$pull: {favorites: request.body.id}
},(err)=> {
if (err) {
console.log(err.message)
} else {
return response.status(200).json({
res_code: 2,
message: "ok"
})
}
})
} else {
data.favorites++;
User.findByIdAndUpdate(request.session.user._id,{
$push: {favorites: request.body.id}
},(err)=> {
if (err) {
console.log(err.message)
} else {
return response.status(200).json({
res_code: 2,
message: "ok"
})
}
})
}
data.save()
}
});
})
// 通过id 获取商品(仅用于用户中心页面使用)
router.post('/idtogoods', (request, response)=> {
let resArr = [];
new Promise(resolve => {
request.body.idArr.forEach((item, index)=> {
Good.findById(item, (err, data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}
let obj;
if (data) {
obj = {
imgUrl: data.goodsImg[0],
name: data.name,
price: data.price
}
resArr.push(obj)
}
if (index === request.body.idArr.length -1) {
resolve(resArr)
}
})
})
}).then((res)=> {
return response.status(200).json({
res_code: 2,
message: 'Ok',
show: res
})
})
});
// 添加足迹商品
router.post('/addfootfrint',(request, response)=> {
User.findById(request.session.user._id, (err, data)=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}
let num = data.footFrint.indexOf(request.body.id);
if (num != -1) {
data.footFrint.splice(num, 1);
}
data.footFrint.unshift(request.body.id);
if (data.footFrint.length > 50) {
data.footFrint.splice(data.footFrint.length - 1, 1)
}
data.markModified('footFrint');
data.save(err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
} else {
return response.status(200).json({
res_code: 2,
message: 'ok'
})
}
})
})
});
// 删除用户浏览记录
router.post('/delfootfrint', (request, response)=> {
User.findByIdAndUpdate(request.session.user._id, {
$pull: {footFrint: request.body.id}
},err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}else {
return response.status(200).json({
res_code: 2,
messsage: 'OK'
})
}
})
});
// 添加购物车
router.post('/addCart', (request, response)=> {
Cart.findOne({
userId: request.body.userId
},(err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
if (data) {
let num;
data.carts.find((item, index)=> {
if (item.id == request.body.id && item.params == request.body.params) {
return num = index
}
})
if (num>=0) {
data.carts[num].num ++
} else {
data.carts.push({
num: request.body.num,
id: request.body.id,
showUrl: request.body.showUrl,
params: request.body.params,
name: request.body.name,
price: request.body.price,
isChoose: true,
stock: request.body.stock,
isCom: false
})
}
data.markModified('carts');
data.save(err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message
})
}
return response.status(200).json({
res_code: 2,
message: '添加成功',
index: num
})
})
} else {
new Cart({
userId: request.body.userId,
carts: [{
num: request.body.num,
id: request.body.id,
showUrl: request.body.showUrl,
params: request.body.params,
name: request.body.name,
price: request.body.price,
isChoose: true,
stock: request.body.stock,
isCom: false
}]
}).save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
return response.status(200).json({
res_code: 2,
message: '添加成功'
})
})
}
})
});
// 获取购物车商品
router.post('/getCart', (request, response)=> {
Cart.findOne({
userId: request.body.userId
}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
if (data) {
return response.status(200).json({
res_code: 2,
cart: data.carts
})
} else {
return response.status(200).json({
res_code: 2,
cart: []
})
}
})
});
// 获取优惠券
router.post('/getCoupon', (request, response)=> {
Coupon.find({
userId: request.body.userId
}, (err, data)=> {
if (err) {
console.log(err.message);
return response.status(500).json({
res_code: 0,
coupons: []
})
} else {
return response.status(200).json({
res_code: 2,
message: 'OK'
})
}
})
})
// 删除购物车商品
router.post('/delCartGoods', (request, response)=> {
console.log(request.body)
Cart.findOne({
userId: request.session.user._id
},(err, data)=> {
let num;
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
data.carts.filter((item, index)=> {
if (item.id == request.body.goodsId && item.params == request.body.params) {
return num = index
}
})
data.carts.splice(num, 1);
data.markModified('carts');
data.save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
return response.status(200).json({
res_code: 2,
message: '删除成功',
num: num
})
})
})
});
// 操作购物车
router.post('/editCartGoods', (request, response)=> {
Cart.findOne({
userId: request.session.user._id
}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
data.carts.filter(item=> {
if (item.id == request.body.id && item.params == request.body.params) {
if (request.body.plus) {
if (item.stock > item.num) {
item.num ++
}else {
return response.status(200).json({
res_code: 1,
message: '超出库存数量'
})
}
}else {
if (item.num > 1) {
item.num ++
} else {
return response.status(200).json({
res_code: 1,
message: '购物车内商品不可少于1'
})
}
}
}
})
data.markModified('carts')
data.save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
return response.status(200).json({
res_code: 2,
message: 'ok'
})
})
})
})
router.post('/pay', (request, response)=> {
let sumPrice = request.body.cartGoods.reduce((total, currentValue)=> {
return total + currentValue.num * currentValue.price
},0).toString()
sumPrice = (sumPrice * request.body.discount - request.body.integral / 100).toFixed(2)
alipayBox.pay(sumPrice).then(res=> {
request.body.sumPrice = sumPrice
request.session.order = request.body
return response.status(200).json({
url: res
})
})
})
// 处理支付成功逻辑 但是此处有问题,未来跳转地址需要其他地址!!!!!!!!!!!
router.get('/callpay', (request, response)=> {
// console.log(request.session.order)
if (request.session.order.discountId) {
Coupon.remove({
value: request.session.order.discountId
})
}
request.session.order.cartGoods.forEach(item=> {
Good.update({
_id: item.id
}, {
$inc: {salesd: 1, stock: (item.num * -1)}
}).then(res=> {
console.log('我是更新商品')
})
})
Cart.update({
userId: request.session.user._id
}, {
$pull: {carts: {$in: request.session.order.cartGoods}}
}).then(res=> {
console.log('我是购物车')
})
User.findById(request.session.user._id, (err, data)=> {
data.luckNumber ++;
data.integral = data.integral - request.session.order.integral + parseInt( request.session.order.sumPrice)
data.markModified('luckNumber')
data.markModified('integral')
data.save(err=> {
if (err) {
console.log(err.message)
return
};
response.redirect('http://localhost:8080/luckDraw') // 后期必改点
})
});
new Order({
goodsMessage: request.session.order.cartGoods,
address: request.session.order.address,
userId: request.session.user._id
}).save(err=> {
if (err) {
console.log(err.message)
}else {
request.session.order = null
}
})
})
// 获取订单
router.post('/getOrder', (request, response)=> {
Order.find({
userId: request.body.id
}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
return response.status(200).json({
res_code: 2,
orders: data
})
})
})
// 抽奖
router.post('/luck', (request, response)=> {
User.findById(request.session.user._id,(err, data)=> {
data.luckNumber --
data.markModified('luckNumber')
data.save(err=> {
if (parseInt(request.body.discount) > 0) {
new Coupon({
userId: request.session.user._id,
label: request.body.discount,
coupon: request.body.discount.substr(0, request.body.discount.length - 1)
}).save(err=> {
return response.status(200)
})
}else {
return response.status(200)
}
})
})
})
// 注册超级管理员
router.post('/Superregister', (request, resonse)=> {
if (request.body.key != authorityPassword) {
return resonse.status(200).json({
res_code: 1,
message: '权限密码不正确'
})
}
new BusinessAccount({
isSuper: true,
nickname: '超级管理员',
account: request.body.account,
password: md5(md5(request.body.password)),
jurisdiction: ['客服','商品管理','系统设置','订单管理']
}).save(err=> {
if (err) return resonse.status(500).json({
res_code: 0,
message: err.messagem,
type: 'error'
})
return resonse.status(200).json({
res_code: 2,
message: '注册成功',
type: 'success'
})
})
})
// 检测账号是否被注册
router.post('/inspect',(request, response)=> {
BusinessAccount.findOne({
account: request.body.account
}, (err,data)=> {
if (request.body.edit) {
if(data && data.account != request.body.edit) {
return response.status(200).json({
res_code: 1,
})
}else {
return response.status(200).json({
res_code: 2,
})
}
}else {
if(data) {
return response.status(200).json({
res_code: 1,
})
}else {
return response.status(200).json({
res_code: 2,
})
}
}
})
})
// 商家登录
router.post('/businessSignIn', (request, response)=> {
BusinessAccount.findOne({
account: request.body.account,
password: md5(md5(request.body.password))
},(err, data)=> {
if (err) {
return response.status(200).json({
res_code: 0,
message: err.message,
type: 'error'
})
}
if (data) {
request.session.businessUser = data
return response.status(200).json({
res_code: 2,
message: '登录成功',
type: 'success',
businessUser: data
})
} else {
return response.status(200).json({
res_code: 1,
message: 'User Or Passord Invalid',
type: 'warning',
})
}
})
})
// 获取登录商家信息
router.post('/getBusinessUser', (request, response)=> {
if (request.session.businessUser) {
BusinessAccount.findById(request.session.businessUser._id, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message
})
return response.status(200).json({
res_code: 2,
message: 'ok',
businessUser: data
})
})
}else {
return response.status(200).json({
res_code: 2,
message: '未登录',
businessUser: {jurisdiction: []}
})
}
})
// 商家退出
router.post('/businessSignOut',(request, response)=> {
request.session.businessUser = null
response.status(200).send()
})
// 获取所有账户
router.post('/findAllAccount', (request, response)=> {
BusinessAccount.find({},(err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: 'OK',
accounts: data
})
})
})
// 注册普通用户
router.post('/addAccount', (request, response)=> {
request.body.password = md5(md5(request.body.password))
new BusinessAccount(request.body).save(err=> {
if (err) {
return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
}
return response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
})
})
})
// 更改商家用户信息
router.post('/changeAccount',(request, response)=> {
BusinessAccount.findByIdAndUpdate(request.body._id,{
isSuper: request.body.isSuper,
jurisdiction: request.body.jurisdiction,
account: request.body.account,
nickname: request.body.nickname,
tel: request.body.tel,
password: md5(md5(request.body.password))
},(err)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '更改成功',
type: 'success'
})
})
})
// 删除商家账户
router.post('/delAccount', (request, response)=> {
BusinessAccount.findByIdAndRemove(request.body.id, (err)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '删除成功',
type: 'success'
})
})
})
// 商家获取全部订单
router.post('/getBusinessOrders', (request, response)=> {
Order.find({},(err, data)=> {
if (err) return response.status(200).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '加载数据成功',
type: 'success',
data: data
})
})
})
// 添加物流单号
router.post('/addDelivery', (request, response)=> {
Order.findByIdAndUpdate(request.body.id, {
delivery: request.body.delivery,
lssue: true
}, (err)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
})
})
})
// 上传一级轮播图
router.post('/addFirstSwiper',upload.single('firstSwiper'), (request, response)=> {
let file = request.file
BaseSetUp.findOne({},(err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
console.log()
if (data) {
data.firstSwiper.push({
imgUrl: `http://localhost:3000/public/img/firstSwiper/${file.filename}`,
fileName: file.filename,
url: request.body.url,
id: Date.now()
})
data.markModified('firstSwiper')
data.save(()=> response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
}))
}else {
new BaseSetUp({
firstSwiper: {
imgUrl: `http://localhost:3000/public/img/firstSwiper/${file.filename}`,
fileName: file.filename,
url: request.body.url,
id: Date.now()
}
}).save(()=> response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
}))
}
})
})
// 获取设置数据
router.get('/getBaseSetData', (request, response)=> {
let query = JSON.parse(request.query.data);
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
let obj = {
res_code: 2,
message: 'ok',
}
// console.log(data.firstSwiper)
if (!data) {
obj.data = []
}else if (query.type == 1) {
obj.data = data.firstSwiper
}
return response.status(200).json(obj)
})
})
// 删除第一个轮播图
router.post('/delFirstSwiper', (request, response)=> {
fs.unlink(path.join(__dirname,'public','img','firstSwiper', request.body.filename),(err => {
BaseSetUp.findOne({}, (err, data)=> {
let num;
data.firstSwiper.forEach((item, index)=> {
if (item.fileName == request.body.filename) {
num = index
}
})
data.firstSwiper.splice(num, 1);
data.markModified('firstSwiper')
data.save(()=> response.status(200).json({
res_code: 2,
message: '删除成功',
type: 'success'
}))
})
}))
})
// 获取系统品牌名称及logo
router.get('/brand', (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: '请求失败',
type: 'error'
})
if (data) {
return response.status(200).json({
res_code: 2,
message: '请求成功',
type: 'success',
data: {
brand: data.brand,
logoUrl: data.logoUrl,
test: '1'
}
})
}else {
return response.status(200).json({
res_code: 2,
message: '请求成功',
type: 'success',
data: {
brand: '母婴销售系统',
logoUrl: 'http://localhost:3000/public/img/logo/logo.png',
test: '2'
}
})
}
})
})
// 改变logo
router.post('/changeLogo', upload.single('logo'), (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (data) {
data.logoUrl = `http://localhost:3000/public/img/logo/${request.file.filename}`
data.save()
}else {
new BaseSetUp({
logoUrl: `http://localhost:3000/public/img/logo/${request.file.filename}`
}).save()
}
return response.status(200).json({
res_code: 2,
message: '上传成功',
type: 'success'
})
})
})
// 改变系统品牌名称
router.post('/changeBrand', (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (data) {
data.brand = request.body.brand
data.save()
}else {
new BaseSetUp({
brand: request.body.brand
}).save()
}
return response.status(200).json({
res_code: 2,
message: '更新成功',
type: 'success'
})
})
})
// 添加公告
router.post('/addNotice', (request, response)=> {
new Notice(request.body).save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
})
})
})
// 获取公告
router.post('/getNotice', (request, response)=> {
Notice.find({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '获取成功',
type: 'success',
data: data
})
})
})
// 通过名字获取商品id
router.post('/searchName', (request, response)=> {
Good.find({
name: {$regex: request.body.searchName}
}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
let arr = []
data.forEach(item=> {
arr.push({
id: item._id,
name: item.name
})
})
return response.status(200).json({
res_code: 2,
message: '查询成功',
type: 'success',
goods: arr
})
})
})
// 添加推荐类
router.post('/addRec', (request, response) => {
request.body.id = Date.now()
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (data) {
console.log(data)
data.recommends.push(request.body)
data.markModified('recommends')
data.save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
})
})
}else {
new BaseSetUp({
recommends: [request.body]
}).save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '添加成功',
type: 'success'
})
})
}
})
})
// 获取推荐类
router.get('/getRec', (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (data) {
return response.status(200).json({
res_code: 2,
message: '成功',
type: 'success',
data: data.recommends
})
} else {
return response.status(200).json({
res_code: 2,
message: '成功',
type: 'success',
data: []
})
}
})
})
// 删除推荐类
router.post('/delRec', (request, response)=> {
BaseSetUp.findOne({},(err, data)=> {
let num;
data.recommends.forEach((item, index)=> {
if (item.id == request.body.id) {
return num = index
}
})
data.recommends.splice(num, 1)
data.markModified('recommends')
data.save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '删除成功',
type: 'success'
})
})
})
})
// 获取首页轮播数据
router.get('/getSwiper', (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (data) {
return response.status(200).json({
res_code: 2,
message: 'ok',
type: 'success',
swiper: data.firstSwiper
})
}else {
return response.status(200).json({
res_code: 2,
message: 'ok',
type: 'success',
swiper: []
})
}
})
})
// 获取首页推荐类
router.get('/getWeek', (request, response)=> {
BaseSetUp.findOne({}, (err, data)=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
if (!data) {
return response.status(200).json({
res_code: 2,
message: 'ok',
type: 'success',
recommends: []
})
} else {
if (data.recommends.length == 0) {
return response.status(200).json({
res_code: 2,
message: 'ok',
type: 'success',
recommends: []
})
} else {
let recommends = []
data.recommends.forEach((item, index)=> {
let obj = {goods: []}
obj.title = item.title
Good.find({
_id: {$in: item.goodsId}
}).then(res=> {
obj.goods = res
recommends.push(obj)
if (recommends.length == data.recommends.length) {
return response.status(200).json({
res_code: 2,
message: 'ok',
type: 'success',
recommends,
})
}
})
})
}
}
})
})
// 导航栏搜索功能
router.post('/nameToGoods', (request, response)=> {
if (request.body.name == '') {
return response.status(200).json({
type: 'success',
goods: []
})
}else {
Good.find({
name: {$regex: request.body.name}
}).then(res=> {
return response.status(200).json({
type: 'success',
goods: res
})
})
}
})
// 添加评论
router.post('/addComment', (request, response)=> {
Order.findOne({
_id: request.body.id
}, async (err, data)=> {
data.goodsMessage.forEach((item, index)=> {
if (item.id == request.body.goods) {
item.isCom = true
}
})
data.markModified('goodsMessage')
await data.save()
await new Comment({
userId: request.session.user,
goodsId: request.body.goods,
message: request.body.comments.message,
star: request.body.comments.rate
}).save()
await Good.findOne({
_id: request.body.goods
}, (err, data)=> {
Comment.find({
goodsId: request.body.goods
}).then(res=> {
data.star = (request.body.comments.rate + data.star) / res.length
data.save(err=> {
if (err) return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
return response.status(200).json({
res_code: 2,
message: '评论成功',
type: 'success'
})
})
})
})
})
})
// 用户获取评论信息
router.get('/getComments', (request, response)=> {
Comment.find({
userId: request.session.user._id
}).then(res=> {
return response.status(200).json({
res_code: 2,
message: 'OK',
comments: res,
type: 'success'
})
}).catch(err=> {
return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
})
})
// 评论模块,通过商品Id获取第一张图片和名字
router.post('/getGoodsStar', (request, response)=> {
// console.log(request.body)
Good.findOne({
_id: request.body.id
}).then(res=> {
return response.status(200).json({
res_code: 2,
type: 'success',
message: 'Ok',
data: {
name: res.name,
url: res.goodsImg[0].url
}
})
}).catch(err=> {
return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
})
})
// 删除评论
router.post('/delComment', async (request, response)=> {
await Comment.findByIdAndRemove(request.body.id)
await Good.findOne({
_id: request.body.goodsId
}, (err, data)=> {
Comment.find({
goodsId: request.body.goods
}).then(res=> {
let sum = res.reduce((total, item)=> {
return total + item.star
},0)
if (res.length == 0) {
data.star = 0
}else {
data.star = sum / res.length
}
data.markModified('star')
data.save(err=> {
if (err) console.log(err.message)
return response.status(200).json({
res_code: 2,
message: '删除成功',
type: 'success'
})
})
})
})
})
// 用户获取优惠券
router.get('/getCoupon', (request, response)=> {
Coupon.find({
userId: request.session.user._id
}).then(res=> {
return response.status(200).json({
res_code: 2,
message: 'OK',
type: 'success',
coupons: res
})
}).catch(err=> {
return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error',
})
})
})
// 获取当前商品评价状态
router.post('/hasCom', (request, response)=> {
Comment.find({
goodsId: request.body.id
}).then(res=> {
let num = res.reduce((total, item)=> {
return total + item.star
},0)
return response.status(200).json({
res_code: 2,
message: 'OK',
type: 'success',
comMsg: {
averageStar: num / res.length,
num: res.length
}
})
})
})
// 获取所有评论
router.post('/getGoodsComments', (request, response)=> {
Comment.find({
goodsId: request.body.id
}).then(res=> {
return response.status(200).json({
res_code: 2,
message: 'OK',
type: 'success',
comments: res
})
}).catch(err=> {
return response.status(500).json({
res_code: 0,
message: err.message,
type: 'error'
})
})
})
// 获取用户头像加名字
router.post('/getUserMsg', (requset, response)=> {
User.findOne({
_id: requset.body.id
}).then(res=> {
return response.status(200).json({
res_code: 2,
message: 'OK',
type: 'success',
user: {
avatar: res.avatar,
nickname: res.nickname
}
})
})
})
// 获取评论的商品star
router.post('/getCommentsStar', (request, response)=> {
Good.findOne({
_id: request.body.id
}).then(res=> {
return response.status(200).json({
res_code: 2,
message: 'OK',
type: 'success',
star: res.star
})
})
})
module.exports = router;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ganghongyu/back-end.git
git@gitee.com:ganghongyu/back-end.git
ganghongyu
back-end
back end
master

搜索帮助