const AdminModel = require('../../models/AdminModel') const UserModel = require('../../models/UserModel') const AddressModel = require('../../models/AddressModel') const ProvinceModel = require('../../models/ProvinceModel') const CityModel = require('../../models/CityModel') const AdoptionModel = require('../../models/AdoptionModel') const PetModel = require('../../models/PetModel') const OrganizationModel = require('../../models/OrganizationModel') const CategoryModel = require('../../models/CategoryModel') const ClassificationModel = require('../../models/ClassificationModel') const jwt = require('jsonwebtoken') const {SECRET} = require('../../config/constants') const Sequelize = require('sequelize') const Op = Sequelize.Op // 查看用户信息 exports.getUser = async (ctx, next) => { const token = ctx.header['admin-token'] const adminInfo = jwt.verify(token, SECRET) try { const admin = await AdminModel.findOne({ attributes: ['id'], where: { mobile: adminInfo.mobile } }) if (admin) { let page = parseInt(ctx.params.page) let limit = parseInt(ctx.params.limit) let offset = (page - 1) * limit let mobile = ctx.query.mobile let name = ctx.query.name let idcard = ctx.query.idcard let status = ctx.query.status let isOrg = ctx.query.isOrg let time1 = ctx.query.time1 let time2 = ctx.query.time2 let where = {} if (mobile) { where['mobile'] = {[Op.like]: `%${mobile}%`} if (idcard) { where['idcard'] = {[Op.like]: `%${idcard}%`} } } else { if (idcard) { where['idcard'] = {[Op.like]: `%${idcard}%`} } } if (status) { where['status'] = status if (isOrg) { where['isOrg'] = isOrg } } else { if (isOrg) { where['isOrg'] = isOrg } } if(name) { where['name'] = {[Op.like]: `%${name}%`} } if(time1 && time2) { time1 = time1 + ' 00:00:00' time2 = time2 + ' 23:59:59' where['gmt_create'] = {[Op.gt]: `${time1}`, [Op.lt]: `${time2}`} } let order = [] if (ctx.query.sort === 'asc') { order = [['id', 'asc']] } else { order = [['id', 'desc']] } const userInfo = await UserModel.findAndCountAll({ limit: limit, offset: offset, attributes: ['id', 'mobile', 'name', 'idcard', 'sex', 'status', 'isOrg', 'gmt_create', 'gmt_modified'], where: where, order: order }) ctx.body = { code: 200, data: { userInfo } } } else { ctx.body = { code: 400, message: '请重新登录' } } } catch (e) { ctx.body = { code: 500, message: '网络出错' } } } // 根据id查看某个用户的信息 exports.getOneUser = async (ctx, next) => { const token = ctx.header['admin-token'] const adminInfo = jwt.verify(token, SECRET) try { const admin = await AdminModel.findOne({ attributes: ['id'], where: { mobile: adminInfo.mobile } }) if (admin) { const userInfo = await UserModel.findOne({ attributes: ['mobile', 'name', 'idcard', 'sex', 'heading', 'status', 'isOrg'], where: { id: ctx.query.id } }) ctx.body = { code: 200, data: { userInfo } } } else { ctx.body = { code: 400, message: '请重新登录' } } } catch (e) { ctx.body = { code: 500, message: '网络出错' } } } // 修改用户信息 exports.updateUser = async (ctx, next) => { const req = ctx.request.body const token = ctx.header['admin-token'] const adminInfo = jwt.verify(token, SECRET) try { const admin = await AdminModel.findOne({ attributes: ['id'], where: { mobile: adminInfo.mobile } }) if (admin) { const res = await UserModel.update({ status: req.status, }, { where: { id: req.id } }) ctx.body = { code: 200, message: '修改成功' } } else { ctx.body = { code: 400, message: '请重新登录' } } } catch (e) { ctx.body = { code: 500, message: '网络出错' } } } // 查看地址信息 exports.getAddress = async (ctx, next) => { const token = ctx.header['admin-token'] const adminInfo = jwt.verify(token, SECRET) try { const admin = await AdminModel.findOne({ attributes: ['id'], where: { mobile: adminInfo.mobile } }) if (admin) { let page = parseInt(ctx.params.page) let limit = parseInt(ctx.params.limit) let offset = (page - 1) * limit let userMobile = ctx.query.userMobile let userName = ctx.query.userName let addressName = ctx.query.addressName let addressMobile = ctx.query.addressMobile let provinceName = ctx.query.provinceName let where1 = {} let where2 = {} if (userMobile) { where2['mobile'] = {[Op.like]: `%${userMobile}%`} if(userName) { where2['name'] = {[Op.like]: `%${userName}%`} } } else { if(userName) { where2['name'] = {[Op.like]: `%${userName}%`} } } if (addressName) { where1['name'] = {[Op.like]: `%${addressName}%`} if (addressMobile) { where1['mobile'] = {[Op.like]: `%${addressMobile}%`} } } else { if (addressMobile) { where1['mobile'] = {[Op.like]: `%${addressMobile}%`} } } if (provinceName) { where1['provinceCode'] = {[Op.like]: `%${provinceName}%`} } let order = [] if (ctx.query.sort === 'asc') { order = [['id', 'asc']] } else { order = [['id', 'desc']] } const addressInfo = await AddressModel.findAndCountAll({ limit: limit, offset: offset, attributes: ['id', 'name', 'mobile', 'isDefault'], where: where1, order: order, include: [ { model: UserModel, attributes: ['mobile', 'name'], where: where2, as: 'addressUser' }, { model: ProvinceModel, attributes: ['name'], as: 'addressProvince' }, { model: CityModel, attributes: ['name'], as: 'addressCity' }, ] }) ctx.body = { code: 200, data: { addressInfo } } } else { ctx.body = { code: 400, message: '请重新登录' } } } catch (e) { ctx.body = { code: 500, message: '网络出错' } } } // 根据id查看某个用户地址信息 exports.getOneAddress = async (ctx, next) => { const token = ctx.header['admin-token'] const adminInfo = jwt.verify(token, SECRET) try { const admin = await AdminModel.findOne({ attributes: ['id'], where: { mobile: adminInfo.mobile } }) if (admin) { const addressInfo = await AddressModel.findOne({ attributes: ['name', 'mobile', 'detail'], where: { id: ctx.query.id }, order: [ ['id', 'asc'] ], include: [ { model: ProvinceModel, attributes: ['name'], as: 'addressProvince' }, { model: CityModel, attributes: ['name'], as: 'addressCity' }, ] }) ctx.body = { code: 200, data: { addressInfo } } } else { ctx.body = { code: 400, message: '请重新登录' } } } catch (e) { ctx.body = { code: 500,
相关知识
基于Node.js的宠物领养系统的设计与实现源码+项目说明文档.zip资源
【全源码及文档】基于JAVA的宠物网站设计与实现
基于JavaWeb的宠物商城网站设计与实现
宠物领养系统的设计与实现 计算机专业毕业设计源码46903
【附源码】django计算机毕业设计宠物爱好者交流网站的设计与实现(源码+mysql+论文)
基于微信小程序的宠物医院宠物健康管理系统(开题报告+源码)
宠物社交类APP的设计与应用——以“闻闻窝”为例.pdf资源
基于SSH技术的宠物救助系统的设计与实现
案例12:Java宠物医院预约管理系统设计与实现开题报告
基于java的宠物管理系统设计与实现(项目报告+答辩PPT+源代码+数据库+截图+部署视频)
网址: 基于Node.js的宠物领养系统的设计与实现源码+项目说明文档.zip资源 https://m.mcbbbk.com/newsview23883.html
上一篇: 宠宠熊app下载 |
下一篇: 4399九天仙梦怀旧庆典专服活动 |