Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
9c00589b
Commit
9c00589b
authored
Sep 18, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
3130f337
Pipeline
#13891
passed with stage
in 16 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
395 additions
and
0 deletions
+395
-0
institution.js
app/controller/course/institution.js
+6
-0
user.js
app/controller/course/user.js
+63
-0
course_user_baby.js
app/model/prometheus/course_user_baby.js
+106
-0
course_user_collection.js
app/model/prometheus/course_user_collection.js
+104
-0
course.js
app/router/course.js
+7
-0
user.js
app/service/course/user.js
+109
-0
No files found.
app/controller/course/institution.js
View file @
9c00589b
...
@@ -47,6 +47,9 @@ class InstitutionController extends Controller {
...
@@ -47,6 +47,9 @@ class InstitutionController extends Controller {
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
class_id
=
ctx
.
params
.
class_id
;
const
class_id
=
ctx
.
params
.
class_id
;
if
(
!
class_id
)
{
ctx
.
failed
(
'error class_id'
);
}
let
ret
=
await
ctx
.
service
.
course
.
institution
.
getClass
(
class_id
);
let
ret
=
await
ctx
.
service
.
course
.
institution
.
getClass
(
class_id
);
ctx
.
success
(
ret
);
ctx
.
success
(
ret
);
...
@@ -71,6 +74,9 @@ class InstitutionController extends Controller {
...
@@ -71,6 +74,9 @@ class InstitutionController extends Controller {
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
teacher_id
=
ctx
.
params
.
teacher_id
;
const
teacher_id
=
ctx
.
params
.
teacher_id
;
if
(
!
teacher_id
)
{
ctx
.
failed
(
'error teacher_id'
);
}
let
ret
=
await
ctx
.
service
.
course
.
institution
.
getTeacher
(
teacher_id
);
let
ret
=
await
ctx
.
service
.
course
.
institution
.
getTeacher
(
teacher_id
);
ctx
.
success
(
ret
);
ctx
.
success
(
ret
);
...
...
app/controller/course/user.js
0 → 100644
View file @
9c00589b
'use strict'
;
const
Controller
=
require
(
'egg'
).
Controller
;
class
UserController
extends
Controller
{
/**
*
*/
async
getBabyInfo
()
{
const
{
ctx
}
=
this
;
const
result
=
await
ctx
.
service
.
course
.
user
.
getBabyInfo
();
ctx
.
success
({
result
});
}
async
saveBabyInfo
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
result
=
await
ctx
.
service
.
course
.
user
.
saveBabyInfo
(
input_params
);
ctx
.
success
({
result
});
}
async
delBabyInfo
()
{
const
{
ctx
}
=
this
;
const
result
=
await
ctx
.
service
.
course
.
user
.
delBabyInfo
();
ctx
.
success
({
result
});
}
async
getCollectInstitutions
()
{
const
{
ctx
}
=
this
;
const
input_params
=
ctx
.
request
.
body
;
const
result
=
await
ctx
.
service
.
course
.
user
.
getCollectInstitutions
(
input_params
);
ctx
.
success
({
result
});
}
async
collectInstitution
()
{
const
{
ctx
}
=
this
;
const
institution_id
=
ctx
.
request
.
body
.
institution_id
;
if
(
!
institution_id
)
{
ctx
.
failed
(
'error institution_id'
);
}
const
result
=
await
ctx
.
service
.
course
.
user
.
collectInstitution
(
institution_id
);
ctx
.
success
({
result
});
}
}
module
.
exports
=
UserController
;
app/model/prometheus/course_user_baby.js
0 → 100644
View file @
9c00589b
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseUserBaby
=
app
.
prometheusModel
.
define
(
'course_user_baby'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
user_id
:
STRING
,
app_user_id
:
STRING
,
app_id
:
STRING
,
app_type_id
:
STRING
,
gender
:
ENUM
(
'boy'
,
'girl'
),
birth
:
STRING
,
address
:
STRING
,
is_deleted
:
INTEGER
,
created_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_user_baby'
,
});
CourseUserBaby
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUserBaby
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseUserBaby
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseUserBaby
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseUserBaby
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
CourseUserBaby
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseUserBaby
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseUserBaby
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
}
CourseUserBaby
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUserBaby
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
}
return
CourseUserBaby
;
};
\ No newline at end of file
app/model/prometheus/course_user_collection.js
0 → 100644
View file @
9c00589b
'use strict'
;
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
,
DECIMAL
,
TEXT
,
ENUM
}
=
app
.
Sequelize
;
const
CourseUserCollection
=
app
.
prometheusModel
.
define
(
'course_user_collection'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
user_id
:
STRING
,
app_user_id
:
STRING
,
app_id
:
STRING
,
app_type_id
:
STRING
,
institution_id
:
INTEGER
,
is_deleted
:
INTEGER
,
created_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_at
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_at'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_user_collection'
,
});
CourseUserCollection
.
one
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
return
await
CourseUserCollection
.
findOne
({
attributes
:
attributes
,
where
:
where
,
});
}
CourseUserCollection
.
all
=
async
(
data
)
=>
{
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
order
=
data
.
order
?
data
.
order
:
[];
return
await
CourseUserCollection
.
findAll
({
attributes
:
attributes
,
where
:
where
,
order
,
});
}
CourseUserCollection
.
list
=
async
(
data
=
{})
=>
{
const
limit
=
data
.
limit
?
Number
(
data
.
limit
)
:
10
;
const
page
=
data
.
page
?
data
.
page
:
1
;
const
order
=
data
.
order
?
data
.
order
:
[];
const
attributes
=
data
.
attributes
?
data
.
attributes
:
{};
const
where
=
data
.
where
?
data
.
where
:
{};
const
condition
=
{
offset
:
(
page
-
1
)
*
limit
,
limit
,
where
:
where
,
order
:
order
,
attributes
:
attributes
,
};
const
{
count
,
rows
}
=
await
CourseUserCollection
.
findAndCountAll
(
condition
);
return
{
page
,
count
,
rows
};
}
CourseUserCollection
.
add
=
async
(
data
)
=>
{
try
{
//返回promise对象实力 instance
const
res
=
await
CourseUserCollection
.
create
(
data
);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return
res
.
id
;
}
catch
(
error
)
{
throw
(
error
);
}
}
CourseUserCollection
.
edit
=
async
(
data
)
=>
{
const
where
=
data
.
where
;
const
params
=
data
.
params
;
try
{
const
res
=
await
CourseUserCollection
.
update
(
params
,
{
where
:
where
})
return
res
;
}
catch
(
error
)
{
throw
(
error
);
}
}
return
CourseUserCollection
;
};
\ No newline at end of file
app/router/course.js
View file @
9c00589b
...
@@ -15,4 +15,11 @@ module.exports = app => {
...
@@ -15,4 +15,11 @@ module.exports = app => {
router
.
get
(
'/teachers'
,
'course.institution.teacherList'
);
router
.
get
(
'/teachers'
,
'course.institution.teacherList'
);
router
.
get
(
'/teacher/:teacher_id'
,
'course.institution.teacherInfo'
);
router
.
get
(
'/teacher/:teacher_id'
,
'course.institution.teacherInfo'
);
router
.
get
(
'/user/baby'
,
'course.user.getBabyInfo'
);
router
.
post
(
'/user/baby'
,
'course.user.saveBabyInfo'
);
router
.
delete
(
'/user/baby'
,
'course.user.delBabyInfo'
);
router
.
get
(
'/user/collection/institution'
,
'course.user.getCollectInstitutions'
);
router
.
post
(
'/user/collection/institution'
,
'course.user.collectInstitution'
);
};
};
app/service/course/user.js
0 → 100644
View file @
9c00589b
'use strict'
;
const
Service
=
require
(
'egg'
).
Service
;
const
moment
=
require
(
'moment'
);
const
R
=
require
(
'ramda'
);
const
GENDER
=
{
boy
:
'小王子'
,
girl
:
'小公举'
}
class
UserService
extends
Service
{
async
getBabyInfo
()
{
const
{
ctx
}
=
this
;
const
user_id
=
1
;
const
app_type_id
=
1
;
const
app_user_id
=
1
;
const
app_id
=
1
;
const
where
=
{
user_id
,
is_deleted
:
0
};
const
baby_info
=
await
ctx
.
prometheusModel
.
CourseUserBaby
.
one
({
where
,
});
let
ret
=
{};
if
(
baby_info
&&
baby_info
.
id
)
{
ret
.
id
=
baby_info
.
id
;
ret
.
gender
=
baby_info
.
gender
;
ret
.
birth
=
baby_info
.
birth
;
ret
.
address
=
baby_info
.
address
;
ret
.
gender_text
=
GENDER
[
ret
.
gender
];
ret
.
age
=
moment
().
format
(
'YYYY'
)
-
baby_info
.
birth
.
substr
(
0
,
4
);
}
return
ret
;
}
async
saveBabyInfo
(
input
)
{
const
{
ctx
}
=
this
;
const
user_id
=
1
;
const
app_type_id
=
1
;
const
app_user_id
=
1
;
const
app_id
=
1
;
const
{
gender
,
birth
,
address
}
=
input
;
const
baby_info
=
await
this
.
getBabyInfo
();
const
where
=
{
user_id
,
is_deleted
:
0
};
if
(
baby_info
&&
baby_info
.
id
)
{
await
ctx
.
prometheusModel
.
CourseUserBaby
.
edit
({
params
:
{
gender
,
birth
,
address
},
where
});
}
else
{
await
ctx
.
prometheusModel
.
CourseUserBaby
.
add
({
user_id
,
app_type_id
,
app_user_id
,
app_id
,
gender
,
birth
,
address
});
}
return
true
;
}
async
delBabyInfo
()
{
const
{
ctx
}
=
this
;
const
user_id
=
1
;
const
app_type_id
=
1
;
const
app_user_id
=
1
;
const
app_id
=
1
;
await
ctx
.
prometheusModel
.
CourseUserBaby
.
edit
({
params
:
{
is_deleted
:
1
,
},
where
:
{
user_id
}
});
return
true
;
}
async
collectInstitution
(
institution_id
)
{
const
{
ctx
}
=
this
;
const
user_id
=
1
;
const
app_type_id
=
1
;
const
app_user_id
=
1
;
const
app_id
=
1
;
const
where
=
{
user_id
,
is_deleted
:
0
};
let
ret
=
await
ctx
.
prometheusModel
.
CourseUserCollection
.
one
({
where
,
});
if
(
ret
&&
ret
.
id
)
{
return
ret
.
id
;
}
ret
=
await
await
ctx
.
prometheusModel
.
CourseUserCollection
.
add
({
user_id
,
app_type_id
,
app_user_id
,
app_id
,
institution_id
});
return
ret
;
}
async
getCollectInstitutions
(
input
)
{
const
{
ctx
}
=
this
;
const
user_id
=
1
;
const
app_type_id
=
1
;
const
app_user_id
=
1
;
const
app_id
=
1
;
const
{
page
,
limit
}
=
input
;
const
where
=
{
user_id
,
is_deleted
:
0
};
const
collect_institution_rows
=
await
ctx
.
prometheusModel
.
CourseUserCollection
.
list
({
page
,
limit
,
where
});
const
institution_ids
=
R
.
pluck
(
'institution_id'
,
collect_institution_rows
.
rows
);
if
(
institution_ids
.
length
===
0
)
{
return
{
page
:
collect_institution_rows
.
page
,
count
:
collect_institution_rows
.
count
,
rows
:
[]
};
}
const
institutions
=
await
ctx
.
prometheusModel
.
CourseInstitution
.
all
({
where
:
{
id
:
{
$in
:
institution_ids
},
status
:
1
,
is_deleted
:
0
}
});
const
ret
=
await
ctx
.
service
.
course
.
institution
.
formatInstitutions
(
institutions
);
return
{
page
:
collect_institution_rows
.
page
,
count
:
collect_institution_rows
.
count
,
rows
:
ret
};
}
}
module
.
exports
=
UserService
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment