Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
付智勇
/
koa2_Sequelize_project
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
付智勇
8 years ago
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
819dd0fe66391c82daf3187b7dd0d09c8f3f7646
819dd0fe
1 parent
49ec598c
用户查询修改头像
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
95 行增加
和
16 行删除
controller/userController.js
model/attachmentModel.js
routes/upload.js
services/userService.js
views/index.html
controller/userController.js
查看文件 @
819dd0f
...
...
@@ -121,8 +121,11 @@ userController.prototype.login = async(ctx, next) =>{
userController
.
prototype
.
getStu
=
async
(
ctx
,
next
)
=>
{
try
{
const
stuType
=
ctx
.
request
.
body
;
if
(
!
stuType
){
return
status
.
paramError
(
'type'
);
if
(
!
stuType
.
siteId
){
return
status
.
paramError
(
'siteId'
);
}
if
(
!
stuType
.
userType
){
return
status
.
paramError
(
'userType'
);
}
let
page
=
ctx
.
header
.
page
?
Number
(
ctx
.
header
.
page
):
ctx
.
header
.
page
;
let
pageno
=
ctx
.
header
.
pageno
?
Number
(
ctx
.
header
.
pageno
):
ctx
.
header
.
pageno
;
...
...
model/attachmentModel.js
0 → 100644
查看文件 @
819dd0f
var
sequelize
=
require
(
'../config'
);
var
Sequelize
=
require
(
'sequelize'
);
var
uuid
=
require
(
'../util/UuidUtil'
)
var
attachment
=
sequelize
.
define
(
'3m_attachment'
,
{
id
:
{
type
:
Sequelize
.
STRING
(
32
),
defaultValue
:
uuid
.
db32
(),
allowNull
:
false
,
unique
:
true
,
primaryKey
:
true
,
field
:
"id"
},
businessId
:
{
allowNull
:
false
,
type
:
Sequelize
.
STRING
(
32
),
field
:
"business_id"
},
category
:
{
allowNull
:
false
,
type
:
Sequelize
.
INTEGER
(
10
),
field
:
"category"
},
path
:
{
allowNull
:
false
,
type
:
Sequelize
.
STRING
(
255
),
field
:
"path"
}
},
{
timestamps
:
false
,
freezeTableName
:
true
});
module
.
exports
=
attachment
;
\ No newline at end of file
...
...
routes/upload.js
查看文件 @
819dd0f
...
...
@@ -10,6 +10,9 @@ const moment = require('moment')
var
body
=
require
(
'koa-better-body'
)
var
formParse
=
require
(
'co-busboy'
)
const
uuid
=
require
(
'../util/UuidUtil'
);
const
attachmentModel
=
require
(
'../model/attachmentModel'
)
const
applacation
=
require
(
'../applacation'
);
...
...
@@ -24,16 +27,27 @@ router.prefix('/upload');
var
uploaddemo
=
mu
.
single
(
'file'
);
router
.
post
(
'/upLoadDoc'
,
uploaddemo
,
async
(
ctx
,
next
)
=>
{
//let s = await uploaddemo(ctx.req,ctx.res,next)
//let w = await fs.rename('/Users/fzy/project/koa2_Sequelize_project/uploads/'+'19543f72d9682d0bedf67fc98da4597b','/Users/fzy/project/koa2_Sequelize_project/uploads/'+'www.jpg')
console
.
log
(
ctx
.
req
.
file
)
console
.
log
(
'文件名'
,
ctx
.
request
.
file
)
try
{
const
businessId
=
ctx
.
query
.
businessId
;
const
category
=
ctx
.
query
.
category
;
let
w
=
await
fs
.
rename
(
applacation
.
uploade
+
ctx
.
req
.
file
.
filename
,
applacation
.
uploade
+
ctx
.
req
.
file
.
originalname
)
ctx
.
body
=
{
filename
:
2
attachmentData
=
{
id
:
uuid
.
db32
(),
businessId
:
businessId
,
category
:
category
,
path
:
'http://localhost:10000/'
+
ctx
.
req
.
file
.
originalname
}
let
attachment
=
await
attachmentModel
.
create
(
attachmentData
)
ctx
.
response
.
status
=
200
;
ctx
.
body
=
{
fileUrl
:
'http://localhost:10000/'
+
ctx
.
req
.
file
.
originalname
}
}
catch
(
error
)
{
console
.
log
(
error
)
ctx
.
response
.
status
=
400
;
ctx
.
body
=
{
msg
:
error
}
}
})
router
.
post
(
'/tgpCallback'
,
async
(
ctx
,
next
)
=>
{
...
...
services/userService.js
查看文件 @
819dd0f
...
...
@@ -64,14 +64,41 @@ userService.prototype.getStu = async(type,page = 1,pageno =10)=>{
try
{
let
sql
=
`
SELECT
u
.
*
,
ug
.
name
groupName
FROM
3
m_user
u
LEFT
JOIN
3
m_user_group
ug
ON
ug
.
id
=
u
.
group_id
`
;
u
.
id
,
u
.
login_name
loginName
,
u
.
company_name
companyName
,
u
.
user_name
userName
,
u
.
user_type
userType
,
u
.
user_role
userRole
,
u
.
user_email
userEmail
,
u
.
user_mobile
userMobile
,
u
.
create_time
createTime
,
u
.
end_time
endTime
,
u
.
content
content
,
u
.
serial_no
serialNo
,
u
.
site_id
siteId
,
u
.
user_status
userStatus
,
3
ma
.
path
userPhoto
FROM
3
m_user
u
LEFT
JOIN
3
m_attachment
3
ma
ON
3
ma
.
business_id
=
u
.
id
where
1
=
1
`
;
if
(
type
.
id
){
sql
+=
" and u.id = '"
+
type
.
id
+
"'"
;
}
if
(
type
.
userType
){
sql
+=
" and u.user_type = '"
+
type
.
userType
+
"'"
;
}
sql
+=
" and u.site_id = '"
+
type
.
siteId
+
"'"
;
sql
+=
' ORDER BY u.create_time DESC LIMIT '
+
(
page
-
1
)
*
pageno
+
' , '
+
pageno
let
users
=
await
userModel
.
findAll
({
where
:
type
,
offset
:
(
page
-
1
)
*
pageno
,
limit
:
pageno
});
let
count
=
await
userModel
.
count
({
where
:
type
})
let
User
=
await
sequelize
.
query
(
sql
);
return
{
users
:
users
,
count
:
count
,
page
:
page
,
pageno
:
pageno
};
console
.
log
(
sql
)
return
{
users
:
User
[
0
],
count
:
count
,
page
:
page
,
pageno
:
pageno
};
}
catch
(
error
)
{
throw
new
Error
(
error
);
}
...
...
views/index.html
查看文件 @
819dd0f
...
...
@@ -7,7 +7,7 @@
<script
src=
"http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"
></script>
</head>
<body>
<form
action=
"/upload/upLoadDoc?
name
=1"
method=
"post"
enctype=
"multipart/form-data"
>
<form
action=
"/upload/upLoadDoc?
businessId=1&category
=1"
method=
"post"
enctype=
"multipart/form-data"
>
<input
type=
"file"
name=
"file"
/>
<input
type=
"text"
value=
"1212"
name=
"class"
>
<input
type=
"submit"
value=
"ok"
/>
...
...
请
注册
或
登录
后发表评论