付智勇

用户api

@@ -114,7 +114,7 @@ userController.prototype.login = async(ctx, next) =>{ @@ -114,7 +114,7 @@ userController.prototype.login = async(ctx, next) =>{
114 114
115 userController.prototype.getStu = async(ctx, next) =>{ 115 userController.prototype.getStu = async(ctx, next) =>{
116 try { 116 try {
117 - const stuType = ctx.params.type; 117 + const stuType = ctx.request.body;
118 if(!stuType){ 118 if(!stuType){
119 return status.paramError('type'); 119 return status.paramError('type');
120 } 120 }
  1 +## 课堂管理
  2 +
  3 +
  4 +### 创建课堂
  5 +
  6 +
1 -# 网校接口文档  
2 1
3 2
4 ## 用户管理 3 ## 用户管理
@@ -103,4 +102,150 @@ @@ -103,4 +102,150 @@
103 102
104 103
105 104
  105 +## 用户查询
  106 +
  107 + 请求url
  108 + post /users/getUser
  109 +
  110 + 请求参数:
  111 +
  112 + localhost:3000/users/getUser
  113 + 查询条件都可以不填就是查询所有
  114 + {
  115 + "loginName": "尼安德特", // 登录名
  116 + "password": "123456", //登录密码
  117 + "companyName":"bat", //公司名字
  118 + "userName":"尼安德特人", //用户名
  119 + "userRole":0, // 用户角色 0超级管理员,1管理员,2监课,3老师,4学生
  120 + "userEmail":"kengni@buyouyu.com", // 用户邮箱
  121 + "userMobile":123124, // 用户手机号
  122 + "content":"2017-09-01", // 用户简介
  123 + "groupId":1 //用户组id
  124 + }
  125 + 返回参数:
  126 +
  127 + {
  128 + "code": 200,
  129 + "returnData": {
  130 + "data": {
  131 + "users": [
  132 + {
  133 + "id": "aMwJvonVWdyL4Em2ZmZDR5AP72YblpkK",
  134 + "loginName": "l3989",
  135 + "IDcard": "231243",
  136 + "password": "4eef3be2f1aa6240ada14d0df9720d05",
  137 + "salt": 21,
  138 + "companyName": "bat",
  139 + "userName": "智人",
  140 + "userType": 1,
  141 + "userRole": 3,
  142 + "userEmail": "42237539@qq.com",
  143 + "userMobile": "12328555324",
  144 + "createTime": "2017-08-28 06:50:01",
  145 + "endTime": "Invalid date",
  146 + "content": "2017-09-01",
  147 + "serialNo": 0,
  148 + "siteId": "3m",
  149 + "userStatus": 0,
  150 + "groupId": "1"
  151 + },
  152 + {
  153 + "id": "Rv2G3Ay45kjp6B1XyalrMLzEg0DJ9mdQ",
  154 + "loginName": "0bk4a",
  155 + "IDcard": "231243",
  156 + "password": "a071495b74b65a34559c76227e0633a4",
  157 + "salt": 5,
  158 + "companyName": "bat",
  159 + "userName": "智人",
  160 + "userType": 1,
  161 + "userRole": 3,
  162 + "userEmail": "422339@qq.com",
  163 + "userMobile": "12328555824",
  164 + "createTime": "2017-08-28 06:46:56",
  165 + "endTime": "Invalid date",
  166 + "content": "2017-09-01",
  167 + "serialNo": 0,
  168 + "siteId": "3m",
  169 + "userStatus": 0,
  170 + "groupId": "1"
  171 + }
  172 + ],
  173 + "count": 2,
  174 + "page": 1,
  175 + "pageno": 10
  176 + }
  177 + }
  178 + }
  179 +
  180 +
  181 +
  182 +## 用户编辑
  183 +
  184 + 请求url
  185 + put localhost:3000/users/updateUserByUserId/:id
  186 +
  187 + 请求参数(可选填):
  188 + {
  189 + "loginName": "尼安德特20",
  190 + "IDcard": "231243",
  191 + "companyName": "bat",
  192 + "userName": "小asd明",
  193 + "userEmail": "15314352890@163.com",
  194 + "userMobile": "123280824",
  195 + "createTime": "2017-08-28 06:41:30",
  196 + "endTime": "Invalid date",
  197 + "content": "2017-09-asd"
  198 + }
  199 +
  200 + 返回参数:
  201 +
  202 + {
  203 + "code": 200,
  204 + "returnData": {
  205 + "data": {
  206 + "id": "GpQKn0yLMda7OVXMZ82PqYvjAxZ5493J",
  207 + "loginName": "尼安德特20",
  208 + "IDcard": "231243",
  209 + "password": "d2322484d96897dca51bef5dc8126ef2",
  210 + "salt": 65,
  211 + "companyName": "bat",
  212 + "userName": "小asd明",
  213 + "userType": 1,
  214 + "userRole": 4,
  215 + "userEmail": "15314352890@163.com",
  216 + "userMobile": "123280824",
  217 + "createTime": "2017-08-27 22:41:30",
  218 + "endTime": "Invalid date",
  219 + "content": "2017-09-asd",
  220 + "serialNo": 0,
  221 + "siteId": "3m",
  222 + "userStatus": 0,
  223 + "groupId": "1"
  224 + }
  225 + }
  226 + }
  227 +
  228 +
  229 +## 删除用户
  230 +
  231 + 请求url
  232 +
  233 + localhost:3000/users/delUserByUserId/:id
  234 +
  235 +请求参数:
  236 +
  237 +名称|类型|描述
  238 +:--|:--|:--
  239 +|id |string |必须, 用户ID |
  240 +
  241 +
  242 +返回参数:
  243 +
  244 + {
  245 + "code": 200,
  246 + "returnData": {
  247 + "data": 1
  248 + }
  249 + }
  250 +
106 251
@@ -43,7 +43,7 @@ router.get('/authLogin.html', async function(ctx, next){ @@ -43,7 +43,7 @@ router.get('/authLogin.html', async function(ctx, next){
43 /** 43 /**
44 *获取用户列表 44 *获取用户列表
45 */ 45 */
46 -router.get('/getStu/:type',async(ctx, next)=>{ 46 +router.post('/getUser',async(ctx, next)=>{
47 try{ 47 try{
48 var data = await userContoller.getStu(ctx, next); 48 var data = await userContoller.getStu(ctx, next);
49 status.successTemp(ctx,200,data); 49 status.successTemp(ctx,200,data);
  1 +// export class Point {
  2 +// constructor(x, y) {
  3 +// this.x = x;
  4 +// this.y = y;
  5 +// }
  6 +
  7 +// a() {
  8 +// return '(' + this.x + ', ' + this.y + ')';
  9 +// }
  10 +// }
@@ -69,8 +69,10 @@ userService.prototype.getStu = async(type,page = 1,pageno =10)=>{ @@ -69,8 +69,10 @@ userService.prototype.getStu = async(type,page = 1,pageno =10)=>{
69 FROM 69 FROM
70 3m_user u 70 3m_user u
71 LEFT JOIN 3m_user_group ug ON ug.id = u.group_id`; 71 LEFT JOIN 3m_user_group ug ON ug.id = u.group_id`;
  72 + let users = await userModel.findAll({where:type,offset: (page-1)*pageno, limit: pageno});
  73 + let count = await userModel.count({where:type})
72 let User = await sequelize.query(sql); 74 let User = await sequelize.query(sql);
73 - return User 75 + return {users:users,count:count,page:page,pageno:pageno};
74 } catch (error) { 76 } catch (error) {
75 throw new Error(error); 77 throw new Error(error);
76 } 78 }
@@ -114,7 +116,7 @@ userService.prototype.updateUserByUserId = async(userId,data)=>{ @@ -114,7 +116,7 @@ userService.prototype.updateUserByUserId = async(userId,data)=>{
114 try { 116 try {
115 var t = await sequelize.transaction({ autocommit: true }) 117 var t = await sequelize.transaction({ autocommit: true })
116 let oldUser = await userModel.findAll({where:{id:userId}},{transaction: t}); 118 let oldUser = await userModel.findAll({where:{id:userId}},{transaction: t});
117 - if(!oldUser){ 119 + if(!oldUser[0]){
118 t.rollback() 120 t.rollback()
119 return {msg:'用户不存在'} 121 return {msg:'用户不存在'}
120 } 122 }
@@ -2,10 +2,6 @@ @@ -2,10 +2,6 @@
2 * 2 *
3 * @Description 邮件发送 3 * @Description 邮件发送
4 * 调用方法:sendMail('amor_zhang@qq.com','这是测试邮件', 'Hi Amor,这是一封测试邮件'); 4 * 调用方法:sendMail('amor_zhang@qq.com','这是测试邮件', 'Hi Amor,这是一封测试邮件');
5 - * @Author Amor  
6 - * @Created 2016/04/26 15:10  
7 - * 技术只是解决问题的选择,而不是解决问题的根本...  
8 - * 我是Amor,为发骚而生!  
9 * 5 *
10 */ 6 */
11 7