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
56f5f001
Commit
56f5f001
authored
Feb 19, 2020
by
Aria
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add onlineClass collect
parent
ff5c7ef7
Pipeline
#19421
passed with stage
in 58 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
4 deletions
+114
-4
online.js
app/controller/course/v4/online.js
+21
-0
course_v4.js
app/router/course_v4.js
+5
-3
online.js
app/service/course/v4/online.js
+88
-1
No files found.
app/controller/course/v4/online.js
View file @
56f5f001
...
...
@@ -42,6 +42,27 @@ class OnlineController extends Controller {
}
// 收藏在线课程
async
collectClass
()
{
const
{
ctx
,
service
}
=
this
;
const
inputParams
=
ctx
.
request
.
body
;
if
(
ctx
.
isEmpty
(
inputParams
)
||
ctx
.
isEmpty
(
inputParams
.
id
))
{
ctx
.
failed
(
'id is empty'
);
}
const
ret
=
await
service
.
course
.
v4
.
online
.
collectClass
(
inputParams
.
id
);
ctx
.
success
(
ret
);
}
// 获取在线课程收藏列表
async
getCollectionClasses
()
{
const
{
ctx
,
service
}
=
this
;
const
inputParams
=
ctx
.
request
.
query
;
const
ret
=
await
service
.
course
.
v4
.
online
.
getCollectionClasses
(
inputParams
);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
OnlineController
;
app/router/course_v4.js
View file @
56f5f001
...
...
@@ -50,8 +50,10 @@ module.exports = app => {
router
.
post
(
'third'
,
'/like'
,
miniAuth
,
'course.v4.institution.like'
);
// 点赞
router
.
post
(
'third'
,
'/unlike'
,
miniAuth
,
'course.v4.institution.unlike'
);
// 取消点赞
router
.
get
(
'third'
,
'/online/classes'
,
miniAuth
,
'course.v4.online.getClasses'
);
// 在线课程列表
router
.
get
(
'third'
,
'/online/class/:id'
,
miniAuth
,
'course.v4.online.getClass'
);
// 在线课程详情
router
.
get
(
'third'
,
'/online/option'
,
miniAuth
,
'course.v4.online.getOption'
);
// 在线课程选项
router
.
get
(
'third'
,
'/online/classes'
,
'course.v4.online.getClasses'
);
// 在线课程列表
router
.
post
(
'third'
,
'/online/collection/class'
,
miniAuth
,
'course.v4.online.collectClass'
);
// 收藏在线课程
router
.
get
(
'third'
,
'/online/collection/classes'
,
miniAuth
,
'course.v4.online.getCollectionClasses'
);
// 在线课程收藏列表
router
.
get
(
'third'
,
'/online/class/:id'
,
'course.v4.online.getClass'
);
// 在线课程详情
router
.
get
(
'third'
,
'/online/option'
,
'course.v4.online.getOption'
);
// 在线课程选项
};
app/service/course/v4/online.js
View file @
56f5f001
...
...
@@ -56,7 +56,8 @@ class OnlineService extends Service {
const
cats
=
await
ctx
.
classModel
.
V4
.
CourseOnlineCat
.
findAll
({
where
:
{
id
:
{
$in
:
catIds
}
},
attributes
:
[
'id'
,
'name'
]
});
// 收藏信息
const
userCollect
=
await
ctx
.
classModel
.
V4
.
CourseUserCollection
.
findOne
({
where
:
{
user_uuid
:
ctx
.
userUuid
,
type
:
3
,
type_id
:
id
,
is_deleted
:
0
}
});
const
uuid
=
ctx
.
headers
.
uuid
||
''
;
const
userCollect
=
await
ctx
.
classModel
.
V4
.
CourseUserCollection
.
findOne
({
where
:
{
user_uuid
:
uuid
,
type
:
3
,
type_id
:
id
,
is_deleted
:
0
}
});
const
ret
=
{
id
,
...
...
@@ -177,6 +178,92 @@ class OnlineService extends Service {
return
ret
;
}
// 收藏在线课程
async
collectClass
(
id
)
{
const
{
ctx
}
=
this
;
const
userUuid
=
ctx
.
userUuid
;
const
data
=
{
user_uuid
:
userUuid
,
type
:
5
,
type_id
:
id
,
is_deleted
:
0
,
created_time
:
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
),
};
const
check
=
await
ctx
.
classModel
.
CourseUserCollection
.
findOne
({
where
:
{
user_uuid
:
userUuid
,
type
:
5
,
type_id
:
id
,
is_deleted
:
0
}
});
if
(
!
ctx
.
isEmpty
(
check
))
{
ctx
.
failed
(
'请勿重复收藏'
);
}
const
ret
=
await
ctx
.
classModel
.
CourseUserCollection
.
create
(
data
);
return
ret
;
}
// 获取收藏课程列表
async
getCollectionClasses
(
input
)
{
const
{
ctx
}
=
this
;
const
page
=
Number
(
input
.
page
)
||
1
;
const
limit
=
Number
(
input
.
limit
)
||
10
;
const
offset
=
(
page
-
1
)
*
limit
;
const
userUuid
=
ctx
.
userUuid
;
const
userCollection
=
await
ctx
.
classModel
.
V4
.
CourseUserCollection
.
findAndCountAll
({
where
:
{
user_uuid
:
userUuid
,
is_deleted
:
0
,
type
:
5
},
raw
:
true
,
limit
,
offset
});
let
classIds
=
R
.
pluck
(
'type_id'
,
userCollection
);
const
filter
=
{
where
:
{
id
:
{
$in
:
classIds
},
status
:
'online'
,
is_deleted
:
0
},
order
:
[[
'institution_id'
,
'desc'
]],
limit
,
offset
,
attributes
:
[
'id'
,
'institution_id'
,
'name'
,
'price'
,
'type'
,
'age'
,
'mode'
,
'time'
,
'created_time'
]
};
const
classes
=
await
ctx
.
classModel
.
V4
.
CourseOnlineClass
.
findAll
(
filter
);
classIds
=
R
.
pluck
(
'id'
,
classes
);
// 分类
const
classToCats
=
await
ctx
.
classModel
.
V4
.
CourseOnlineClassToCat
.
findAll
({
where
:
{
class_id
:
{
$in
:
classIds
},
status
:
'online'
,
is_deleted
:
0
},
attributes
:
[
'class_id'
,
'cat_id'
]
});
const
catIds
=
R
.
pluck
(
'cat_id'
,
classToCats
);
let
cats
=
await
ctx
.
classModel
.
V4
.
CourseOnlineCat
.
findAll
({
where
:
{
id
:
{
$in
:
catIds
}
}
});
cats
=
_
.
groupBy
(
cats
,
'id'
);
let
classCats
=
[];
for
(
const
v
of
classToCats
)
{
const
tmp
=
{
id
:
v
.
cat_id
,
class_id
:
v
.
class_id
,
name
:
ctx
.
isEmpty
(
cats
[
v
.
cat_id
])
?
''
:
cats
[
v
.
cat_id
][
0
].
name
,
};
classCats
.
push
(
tmp
);
}
classCats
=
_
.
groupBy
(
classCats
,
'class_id'
);
// 机构
const
institutionIds
=
R
.
pluck
(
'institution_id'
,
classes
);
let
institutions
=
await
ctx
.
classModel
.
V4
.
CourseOnlineInstitution
.
findAll
({
where
:
{
id
:
{
$in
:
institutionIds
}
},
attributes
:
[
'id'
,
'name'
,
'logo'
]
});
institutions
=
_
.
groupBy
(
institutions
,
'id'
);
const
result
=
[];
for
(
const
v
of
classes
)
{
const
tmp
=
{
id
:
v
.
id
,
name
:
v
.
name
,
institution_id
:
v
.
institution_id
,
institution_name
:
ctx
.
isEmpty
(
institutions
[
v
.
institution_id
])
?
''
:
institutions
[
v
.
institution_id
][
0
].
name
,
logo
:
ctx
.
isEmpty
(
institutions
[
v
.
institution_id
])
?
''
:
institutions
[
v
.
institution_id
][
0
].
logo
,
type
:
v
.
type
,
mode
:
await
this
.
getClassModelInfo
(
v
.
mode
),
price
:
v
.
price
,
time
:
v
.
time
,
created_time
:
v
.
created_time
,
cats
:
ctx
.
isEmpty
(
classCats
[
v
.
id
])
?
[]
:
classCats
[
v
.
id
],
};
result
.
push
(
tmp
);
}
const
ret
=
{
results
:
result
,
count
:
userCollection
.
count
,
page
,
};
return
ret
;
}
}
module
.
exports
=
OnlineService
;
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