正在显示
5 个修改的文件
包含
95 行增加
和
16 行删除
| @@ -121,8 +121,11 @@ userController.prototype.login = async(ctx, next) =>{ | @@ -121,8 +121,11 @@ userController.prototype.login = async(ctx, next) =>{ | ||
| 121 | userController.prototype.getStu = async(ctx, next) =>{ | 121 | userController.prototype.getStu = async(ctx, next) =>{ |
| 122 | try { | 122 | try { |
| 123 | const stuType = ctx.request.body; | 123 | const stuType = ctx.request.body; |
| 124 | - if(!stuType){ | ||
| 125 | - return status.paramError('type'); | 124 | + if(!stuType.siteId){ |
| 125 | + return status.paramError('siteId'); | ||
| 126 | + } | ||
| 127 | + if(!stuType.userType){ | ||
| 128 | + return status.paramError('userType'); | ||
| 126 | } | 129 | } |
| 127 | let page = ctx.header.page ? Number(ctx.header.page):ctx.header.page; | 130 | let page = ctx.header.page ? Number(ctx.header.page):ctx.header.page; |
| 128 | let pageno = ctx.header.pageno ? Number(ctx.header.pageno):ctx.header.pageno; | 131 | let pageno = ctx.header.pageno ? Number(ctx.header.pageno):ctx.header.pageno; |
model/attachmentModel.js
0 → 100644
| 1 | +var sequelize = require('../config'); | ||
| 2 | +var Sequelize = require('sequelize'); | ||
| 3 | +var uuid = require('../util/UuidUtil') | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +var attachment = sequelize.define('3m_attachment', { | ||
| 7 | + id: { | ||
| 8 | + type: Sequelize.STRING(32), | ||
| 9 | + defaultValue:uuid.db32(), | ||
| 10 | + allowNull: false, | ||
| 11 | + unique: true, | ||
| 12 | + primaryKey: true, | ||
| 13 | + field: "id" | ||
| 14 | + }, | ||
| 15 | + businessId: { | ||
| 16 | + allowNull: false, | ||
| 17 | + type: Sequelize.STRING(32), | ||
| 18 | + field: "business_id" | ||
| 19 | + }, | ||
| 20 | + category: { | ||
| 21 | + allowNull: false, | ||
| 22 | + type:Sequelize.INTEGER(10), | ||
| 23 | + field: "category" | ||
| 24 | + }, | ||
| 25 | + path: { | ||
| 26 | + allowNull: false, | ||
| 27 | + type:Sequelize.STRING(255), | ||
| 28 | + field: "path" | ||
| 29 | + } | ||
| 30 | +}, { | ||
| 31 | + timestamps: false, | ||
| 32 | + freezeTableName: true | ||
| 33 | + }); | ||
| 34 | + | ||
| 35 | +module.exports = attachment; |
| @@ -10,6 +10,9 @@ const moment = require('moment') | @@ -10,6 +10,9 @@ const moment = require('moment') | ||
| 10 | var body = require('koa-better-body') | 10 | var body = require('koa-better-body') |
| 11 | var formParse = require('co-busboy') | 11 | var formParse = require('co-busboy') |
| 12 | const uuid = require('../util/UuidUtil'); | 12 | const uuid = require('../util/UuidUtil'); |
| 13 | +const attachmentModel =require( '../model/attachmentModel') | ||
| 14 | + | ||
| 15 | + | ||
| 13 | 16 | ||
| 14 | 17 | ||
| 15 | const applacation = require('../applacation'); | 18 | const applacation = require('../applacation'); |
| @@ -24,16 +27,27 @@ router.prefix('/upload'); | @@ -24,16 +27,27 @@ router.prefix('/upload'); | ||
| 24 | var uploaddemo=mu.single('file'); | 27 | var uploaddemo=mu.single('file'); |
| 25 | 28 | ||
| 26 | router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { | 29 | router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { |
| 27 | - | ||
| 28 | - //let s = await uploaddemo(ctx.req,ctx.res,next) | ||
| 29 | - //let w = await fs.rename('/Users/fzy/project/koa2_Sequelize_project/uploads/'+'19543f72d9682d0bedf67fc98da4597b','/Users/fzy/project/koa2_Sequelize_project/uploads/'+'www.jpg') | ||
| 30 | - console.log( ctx.req.file) | ||
| 31 | - console.log('文件名',ctx.request.file) | 30 | + try { |
| 31 | + const businessId = ctx.query.businessId; | ||
| 32 | + const category = ctx.query.category; | ||
| 32 | let w = await fs.rename(applacation.uploade+ctx.req.file.filename,applacation.uploade+ctx.req.file.originalname) | 33 | let w = await fs.rename(applacation.uploade+ctx.req.file.filename,applacation.uploade+ctx.req.file.originalname) |
| 33 | - | ||
| 34 | - ctx.body = { | ||
| 35 | - filename:2 | 34 | + attachmentData = { |
| 35 | + id:uuid.db32(), | ||
| 36 | + businessId:businessId, | ||
| 37 | + category:category, | ||
| 38 | + path:'http://localhost:10000/'+ctx.req.file.originalname | ||
| 39 | + } | ||
| 40 | + let attachment = await attachmentModel.create(attachmentData) | ||
| 41 | + ctx.response.status= 200; | ||
| 42 | + ctx.body = { | ||
| 43 | + fileUrl:'http://localhost:10000/'+ctx.req.file.originalname | ||
| 36 | } | 44 | } |
| 45 | + } catch (error) { | ||
| 46 | + console.log(error) | ||
| 47 | + ctx.response.status= 400; | ||
| 48 | + ctx.body = {msg:error} | ||
| 49 | + } | ||
| 50 | + | ||
| 37 | }) | 51 | }) |
| 38 | 52 | ||
| 39 | router.post('/tgpCallback', async (ctx, next) => { | 53 | router.post('/tgpCallback', async (ctx, next) => { |
| @@ -64,14 +64,41 @@ userService.prototype.getStu = async(type,page = 1,pageno =10)=>{ | @@ -64,14 +64,41 @@ userService.prototype.getStu = async(type,page = 1,pageno =10)=>{ | ||
| 64 | try { | 64 | try { |
| 65 | 65 | ||
| 66 | let sql = `SELECT | 66 | let sql = `SELECT |
| 67 | - u.*, ug.name groupName | ||
| 68 | - FROM | ||
| 69 | - 3m_user u | ||
| 70 | - LEFT JOIN 3m_user_group ug ON ug.id = u.group_id`; | 67 | + u.id, |
| 68 | + u.login_name loginName, | ||
| 69 | + u.company_name companyName, | ||
| 70 | + u.user_name userName, | ||
| 71 | + u.user_type userType, | ||
| 72 | + u.user_role userRole, | ||
| 73 | + u.user_email userEmail, | ||
| 74 | + u.user_mobile userMobile, | ||
| 75 | + u.create_time createTime, | ||
| 76 | + u.end_time endTime, | ||
| 77 | + u.content content, | ||
| 78 | + u.serial_no serialNo, | ||
| 79 | + u.site_id siteId, | ||
| 80 | + u.user_status userStatus, | ||
| 81 | + 3ma.path userPhoto | ||
| 82 | + FROM | ||
| 83 | + 3m_user u | ||
| 84 | + LEFT JOIN 3m_attachment 3ma ON 3ma.business_id = u.id | ||
| 85 | + where 1=1 | ||
| 86 | + `; | ||
| 87 | + if(type.id){ | ||
| 88 | + sql += " and u.id = '" + type.id+"'"; | ||
| 89 | + } | ||
| 90 | + if(type.userType){ | ||
| 91 | + sql += " and u.user_type = '" + type.userType+"'"; | ||
| 92 | + } | ||
| 93 | + sql += " and u.site_id = '" + type.siteId+"'"; | ||
| 94 | + | ||
| 95 | + sql += ' ORDER BY u.create_time DESC LIMIT '+(page-1)*pageno+' , ' +pageno | ||
| 96 | + | ||
| 71 | let users = await userModel.findAll({where:type,offset: (page-1)*pageno, limit: pageno}); | 97 | let users = await userModel.findAll({where:type,offset: (page-1)*pageno, limit: pageno}); |
| 72 | let count = await userModel.count({where:type}) | 98 | let count = await userModel.count({where:type}) |
| 73 | let User = await sequelize.query(sql); | 99 | let User = await sequelize.query(sql); |
| 74 | - return {users:users,count:count,page:page,pageno:pageno}; | 100 | + console.log(sql) |
| 101 | + return {users:User[0],count:count,page:page,pageno:pageno}; | ||
| 75 | } catch (error) { | 102 | } catch (error) { |
| 76 | throw new Error(error); | 103 | throw new Error(error); |
| 77 | } | 104 | } |
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | <script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> | 7 | <script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> |
| 8 | </head> | 8 | </head> |
| 9 | <body> | 9 | <body> |
| 10 | - <form action="/upload/upLoadDoc?name=1" method="post" enctype="multipart/form-data"> | 10 | + <form action="/upload/upLoadDoc?businessId=1&category=1" method="post" enctype="multipart/form-data"> |
| 11 | <input type="file" name="file"/> | 11 | <input type="file" name="file"/> |
| 12 | <input type="text" value="1212" name="class" > | 12 | <input type="text" value="1212" name="class" > |
| 13 | <input type="submit" value="ok"/> | 13 | <input type="submit" value="ok"/> |
-
请 注册 或 登录 后发表评论