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
6ae206e6
Commit
6ae206e6
authored
Apr 14, 2020
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option and so on.
parent
49b9429e
Pipeline
#21659
passed with stage
in 12 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
286 additions
and
42 deletions
+286
-42
institution.js
app/controller/course/v5/institution.js
+23
-0
option.js
app/controller/course/v5/option.js
+2
-6
user.js
app/controller/course/v5/user.js
+23
-0
wechat.js
app/controller/course/v5/wechat.js
+16
-0
courseV5UserBaby.js
app/model/class/v5/courseV5UserBaby.js
+45
-0
course_v5.js
app/router/course_v5.js
+5
-0
institution.js
app/service/course/v5/institution.js
+29
-2
option.js
app/service/course/v5/option.js
+72
-34
user.js
app/service/course/v5/user.js
+37
-0
wechat.js
app/service/course/v5/wechat.js
+34
-0
No files found.
app/controller/course/v5/institution.js
View file @
6ae206e6
...
...
@@ -25,6 +25,29 @@ class InstitutionController extends Controller {
ctx
.
success
(
ret
);
}
// 收藏课程列表
async
getCollectionClassList
()
{
const
{
ctx
}
=
this
;
const
queryParams
=
ctx
.
request
.
query
;
const
ret
=
await
ctx
.
service
.
course
.
v5
.
institution
.
getCollectionClassList
(
queryParams
);
ctx
.
success
(
ret
);
}
// 收藏课程
async
collectClass
()
{
const
{
ctx
}
=
this
;
const
class_id
=
ctx
.
params
.
class_id
;
if
(
!
class_id
)
{
ctx
.
failed
(
'error class_id'
);
}
const
ret
=
await
ctx
.
service
.
course
.
v5
.
institution
.
collectClass
(
class_id
);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
InstitutionController
;
app/controller/course/v5/option.js
View file @
6ae206e6
...
...
@@ -3,16 +3,12 @@
const
Controller
=
require
(
'egg'
).
Controller
;
class
OptionController
extends
Controller
{
/**
* 筛选项
*/
async
getOptions
()
{
const
{
ctx
}
=
this
;
const
re
sults
=
await
ctx
.
service
.
course
.
v5
.
option
.
getOptions
();
const
re
t
=
await
ctx
.
service
.
course
.
v5
.
option
.
getOptions
();
ctx
.
success
(
{
results
}
);
ctx
.
success
(
ret
);
}
async
getBannerList
()
{
...
...
app/controller/course/v5/user.js
View file @
6ae206e6
...
...
@@ -66,6 +66,29 @@ class UserController extends Controller {
ctx
.
success
(
ret
);
}
// 上传用户宝宝信息
async
addUserBaby
()
{
const
{
ctx
,
service
}
=
this
;
const
params
=
ctx
.
request
.
body
;
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
baby_name
))
{
ctx
.
failed
(
'name is empty'
);
}
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
baby_age
))
{
ctx
.
failed
(
'age is empty'
);
}
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
baby_sex
))
{
ctx
.
failed
(
'sex is empty'
);
}
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
baby_birth
))
{
ctx
.
failed
(
'birth is empty'
);
}
const
ret
=
await
service
.
course
.
v5
.
user
.
addUserBaby
(
params
);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
UserController
;
app/controller/course/v5/wechat.js
View file @
6ae206e6
...
...
@@ -45,6 +45,22 @@ class WechatController extends Controller {
ctx
.
success
();
}
}
// 获取二维码
async
getQRCode
()
{
const
{
ctx
,
service
}
=
this
;
const
params
=
ctx
.
request
.
body
;
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
path
))
{
ctx
.
failed
(
'path is empty'
);
}
if
(
ctx
.
isEmpty
(
params
)
||
ctx
.
isEmpty
(
params
.
width
))
{
ctx
.
failed
(
'width is empty'
);
}
const
ret
=
await
service
.
course
.
v5
.
wechat
.
getQRCode
(
params
);
ctx
.
success
(
ret
);
}
}
module
.
exports
=
WechatController
;
app/model/class/v5/courseV5UserBaby.js
0 → 100644
View file @
6ae206e6
'use strict'
;
const
moment
=
require
(
'moment'
);
module
.
exports
=
app
=>
{
const
{
STRING
,
INTEGER
,
DATE
}
=
app
.
Sequelize
;
const
CourseV5UserBaby
=
app
.
classModel
.
define
(
'course_v5_user_baby'
,
{
id
:
{
type
:
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
,
},
user_uuid
:
STRING
,
baby_name
:
STRING
,
baby_age
:
INTEGER
,
baby_sex
:
INTEGER
,
baby_birth
:
STRING
,
status
:
INTEGER
,
is_deleted
:
INTEGER
,
created_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'created_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
updated_time
:
{
type
:
DATE
,
allowNull
:
true
,
get
()
{
const
date
=
this
.
getDataValue
(
'updated_time'
);
return
date
?
moment
(
date
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
undefined
;
},
},
},
{
timestamps
:
false
,
tableName
:
'course_v5_user_baby'
,
});
return
CourseV5UserBaby
;
};
app/router/course_v5.js
View file @
6ae206e6
...
...
@@ -10,11 +10,16 @@ module.exports = app => {
router
.
post
(
'third'
,
'/login/wechat'
,
'course.v5.user.loginByWX'
);
// 微信登录
router
.
post
(
'third'
,
'/user/register_user'
,
auth
,
'course.v5.user.registerUserInfo'
);
// 授权后注册用户
router
.
get
(
'third'
,
'/user/info'
,
auth
,
'course.v5.user.getUserInfo'
);
// 获取用户信息
router
.
post
(
'third'
,
'/user/baby'
,
auth
,
'course.v5.user.addUserBaby'
);
// 上传用户宝宝信息
router
.
get
(
'third'
,
'/category/all'
,
'course.v5.option.getCategoryList'
);
// 获取分类列表
router
.
get
(
'third'
,
'/banner/all'
,
'course.v5.option.getBannerList'
);
// 获取banner列表
router
.
get
(
'third'
,
'/options'
,
'course.v5.option.getOptions'
);
// 获取配置项
router
.
post
(
'third'
,
'/wechat/qrcode'
,
'course.v5.wechat.getQRCode'
);
// 获取二维码
router
.
get
(
'third'
,
'/class/all'
,
auth
,
'course.v5.institution.getClassList'
);
// 获取课程列表
router
.
get
(
'third'
,
'/class/:class_id'
,
auth
,
'course.v5.institution.getClassInfo'
);
// 获取课程详情
router
.
get
(
'/third'
,
'/collection/class/all'
,
auth
,
'course.v5.institution.getCollectionClassList'
);
// 获取收藏课程列表
router
.
post
(
'/third'
,
'/collection/class/:class_id'
,
auth
,
'course.v5.institution.collectClass'
);
// 收藏课程
};
app/service/course/v5/institution.js
View file @
6ae206e6
...
...
@@ -114,7 +114,7 @@ class InstitutionSubService extends Service {
}
// 用户收藏课程列表
async
get
UserCollected
ClassList
(
input
)
{
async
get
Collection
ClassList
(
input
)
{
const
{
ctx
}
=
this
;
const
page
=
Number
(
input
.
page
)
||
1
;
const
page_size
=
Number
(
input
.
page_size
)
||
10
;
...
...
@@ -141,7 +141,34 @@ class InstitutionSubService extends Service {
return
ret
;
}
//
// 收藏课程
async
collectClass
(
id
)
{
const
{
ctx
}
=
this
;
// 先检查课程是否存在
const
classInfo
=
await
ctx
.
classModel
.
V5
.
CourseV5Class
.
findOne
({
where
:
{
id
,
is_deleted
:
0
},
attributes
:
[
'id'
]
});
if
(
ctx
.
isEmpty
(
classInfo
))
{
ctx
.
failed
(
'课程不存在'
);
}
// 检查是否已收藏
const
collectInfo
=
await
ctx
.
classModel
.
V5
.
CourseUserCollection
.
findOne
({
where
:
{
user_uuid
:
ctx
.
userUuid
,
type
:
3
,
type_id
:
id
,
is_deleted
:
0
}
});
if
(
!
ctx
.
isEmpty
(
collectInfo
))
{
ctx
.
failed
(
'请勿重复收藏'
);
}
const
data
=
{
user_uuid
:
ctx
.
userUuid
,
institution_id
:
0
,
type
:
3
,
type_id
:
id
,
is_deleted
:
0
,
created_time
:
moment
().
format
(
'YYYY-MM-DD hh:mm:ss'
),
};
await
ctx
.
classModel
.
V5
.
CourseUserCollection
.
create
(
data
);
const
ret
=
{
result
:
true
};
return
ret
;
}
}
module
.
exports
=
InstitutionSubService
;
app/service/course/v5/option.js
View file @
6ae206e6
...
...
@@ -3,47 +3,85 @@
const
Service
=
require
(
'egg'
).
Service
;
const
AGE_CATS
=
[
{
id
:
-
2
,
name
:
'全部'
,
value
:
0
},
{
id
:
-
3
,
name
:
'3岁以下'
,
value
:
3
},
{
id
:
-
4
,
name
:
'4岁'
,
value
:
4
},
{
id
:
-
5
,
name
:
'5岁'
,
value
:
5
},
{
id
:
-
6
,
name
:
'6岁'
,
value
:
6
},
{
id
:
-
7
,
name
:
'7岁'
,
value
:
7
},
{
id
:
-
8
,
name
:
'8岁'
,
value
:
8
},
{
id
:
-
9
,
name
:
'9岁'
,
value
:
9
},
{
id
:
-
10
,
name
:
'10岁'
,
value
:
10
},
{
id
:
-
11
,
name
:
'11岁'
,
value
:
11
},
{
id
:
-
12
,
name
:
'12岁'
,
value
:
12
},
{
id
:
-
13
,
name
:
'12岁以上'
,
value
:
13
},
const
MODE
=
[
{
id
:
1
,
name
:
'直播'
,
value
:
1
,
},
{
id
:
2
,
name
:
'录播'
,
value
:
2
,
},
{
id
:
3
,
name
:
'直播+回放'
,
value
:
3
,
},
{
id
:
0
,
name
:
'全部'
,
value
:
0
,
},
];
const
INSTITUTION_TYPE
=
[
{
id
:
-
14
,
name
:
'全部'
,
value
:
''
},
{
id
:
-
15
,
name
:
'品牌'
,
value
:
'品牌'
},
];
const
DISTANCES
=
[
{
id
:
-
16
,
name
:
'全部'
,
value
:
0
},
{
id
:
-
17
,
name
:
'500米以内'
,
value
:
500
},
{
id
:
-
18
,
name
:
'1公里以内'
,
value
:
1000
},
{
id
:
-
19
,
name
:
'2公里以内'
,
value
:
2000
},
{
id
:
-
20
,
name
:
'3公里以内'
,
value
:
3000
},
{
id
:
-
21
,
name
:
'5公里以内'
,
value
:
5000
},
const
PRICE_TYPE
=
[
{
id
:
1
,
name
:
'低价体验课'
,
value
:
1
,
},
{
id
:
2
,
name
:
'公益免费课'
,
value
:
2
,
},
{
id
:
3
,
name
:
'正价课'
,
value
:
3
,
},
{
id
:
0
,
name
:
'全部'
,
value
:
0
,
},
];
class
OptionService
extends
Service
{
async
getOptions
()
{
const
{
service
}
=
this
;
const
cats
=
await
service
.
course
.
v5
.
institution
.
getCats
();
const
options
=
{
cats
,
ages
:
AGE_CATS
,
institutions
:
INSTITUTION_TYPE
,
distances
:
DISTANCES
,
const
{
ctx
}
=
this
;
// 分类
const
categoryList
=
await
ctx
.
classModel
.
V5
.
CourseV5Category
.
findAll
({
where
:
{
type
:
1
,
status
:
1
,
is_deleted
:
0
},
order
:
[[
'sort'
,
'asc'
]],
attributes
:
[
'id'
,
'name'
],
raw
:
true
});
categoryList
.
forEach
(
e
=>
{
e
.
value
=
e
.
id
;
});
categoryList
.
push
({
id
:
0
,
name
:
'全部'
,
value
:
0
});
// 年龄段
const
ageList
=
await
ctx
.
classModel
.
V5
.
CourseV5Age
.
findAll
({
where
:
{
status
:
1
,
is_deleted
:
0
},
order
:
[[
'sort'
,
'asc'
]],
attributes
:
[
'id'
,
'name'
],
raw
:
true
});
ageList
.
forEach
(
e
=>
{
e
.
value
=
e
.
id
;
});
ageList
.
push
({
id
:
0
,
name
:
'全部'
,
value
:
0
});
// // 课程班型
// const typeList = await ctx.classModel.V5.CourseV5Type.findAll({ where: { status: 1, is_deleted: 0 }, order: [ ['sort', 'asc'] ], attributes: [ 'id', 'name' ], raw: true });
// typeList.forEach(e => {
// e.value = e.id;
// });
// typeList.push({ id: 0, name: '全部', value: 0 });
// // 授课频次
// const frequencyList = await ctx.classModel.V5.CourseV5Frequency.findAll({ where: { status: 1, is_deleted: 0 }, order: [ ['sort', 'asc'] ], attributes: [ 'id', 'name' ], raw: true });
// frequencyList.forEach(e => {
// e.value = e.id;
// });
// frequencyList.push({ id: 0, name: '全部', value: 0 });
const
options
=
[
{
title
:
'所在班级'
,
value
:
ageList
,
alias
:
'age'
},
{
title
:
'科目类型'
,
value
:
categoryList
,
alias
:
'category'
},
{
title
:
'课程状态'
,
value
:
MODE
,
alias
:
'mode'
},
{
title
:
'课程类型'
,
value
:
PRICE_TYPE
,
alias
:
'price_type'
},
];
const
ret
=
{
list
:
options
,
};
return
options
;
return
ret
;
}
async
getBannerList
(
alias
)
{
...
...
app/service/course/v5/user.js
View file @
6ae206e6
...
...
@@ -195,6 +195,9 @@ class UserService extends Service {
ctx
.
failed
(
'用户不存在'
);
}
// 获取用户宝宝信息
const
userBabyInfo
=
await
ctx
.
classModel
.
V5
.
CourseV5UserBaby
.
findOne
({
where
:
{
user_uuid
:
userUuid
,
status
:
1
,
is_deleted
:
0
}
});
const
ret
=
{
user_uuid
:
userInfo
.
uuid
,
nickname
:
userInfo
.
nickname
,
...
...
@@ -202,8 +205,42 @@ class UserService extends Service {
sex
:
userInfo
.
sex
,
openid
:
userInfo
.
openid
,
bind_phone
:
ctx
.
isEmpty
(
userInfo
.
phone
)
?
0
:
1
,
baby_name
:
ctx
.
isEmpty
(
userBabyInfo
)
?
''
:
userBabyInfo
.
baby_name
,
baby_age
:
ctx
.
isEmpty
(
userBabyInfo
)
?
''
:
userBabyInfo
.
baby_age
,
baby_sex
:
ctx
.
isEmpty
(
userBabyInfo
)
?
''
:
userBabyInfo
.
baby_sex
,
baby_birth
:
ctx
.
isEmpty
(
userBabyInfo
)
?
''
:
userBabyInfo
.
baby_birth
,
};
return
ret
;
}
// 上传用户宝宝信息
async
addUserBaby
(
input
)
{
const
{
ctx
}
=
this
;
const
name
=
input
.
baby_name
||
''
;
const
age
=
input
.
baby_age
||
''
;
const
sex
=
input
.
baby_sex
||
''
;
const
birth
=
input
.
baby_birth
||
''
;
const
data
=
{
user_uuid
:
ctx
.
userUuid
,
baby_name
:
name
,
baby_age
:
age
,
baby_sex
:
sex
,
baby_birth
:
birth
,
};
// 是否原来已经有数据
const
babyInfo
=
await
ctx
.
classModel
.
V5
.
CourseV5UserBaby
.
findOne
({
where
:
{
user_uuid
:
ctx
.
userUuid
,
status
:
1
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
babyInfo
))
{
await
ctx
.
classModel
.
V5
.
CourseV5UserBaby
.
findOrCreate
(
data
);
}
else
{
await
ctx
.
classModel
.
V5
.
CourseV5UserBaby
.
update
(
data
,
{
where
:
{
id
:
babyInfo
.
id
}
});
}
const
ret
=
{
result
:
true
,
};
return
ret
;
}
}
...
...
app/service/course/v5/wechat.js
View file @
6ae206e6
...
...
@@ -215,6 +215,40 @@ class WechatService extends Service {
return
decoded
;
}
// 获取二维码
async
getQRCode
(
input
)
{
const
{
ctx
}
=
this
;
const
path
=
input
.
path
;
const
width
=
input
.
width
;
let
image
=
await
this
.
app
.
memcache
.
get
(
`course_wechat_v5_QRCode_
${
path
}
_
${
width
}
`
);
if
(
image
)
{
return
{
image
};
}
const
token
=
await
this
.
getAccessToken
();
const
url
=
`https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=
${
token
}
`
;
let
params
=
{
path
,
width
,
};
params
=
JSON
.
stringify
(
params
);
const
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
contentType
:
'JSON'
,
dataType
:
'BUFFER'
});
image
=
''
;
if
(
resp
.
status
===
200
&&
!
ctx
.
isEmpty
(
resp
.
data
))
{
let
data
=
resp
.
data
.
toString
();
if
(
data
.
includes
(
'errcode'
)
&&
data
.
includes
(
'errmsg'
))
{
data
=
JSON
.
parse
(
data
);
ctx
.
failed
(
data
.
errmsg
);
}
await
this
.
app
.
memcache
.
set
(
`course_wechat_v5_QRCode_
${
path
}
_
${
width
}
`
,
resp
.
data
.
toString
(
'base64'
));
image
=
resp
.
data
.
toString
(
'base64'
);
}
return
{
image
};
}
}
module
.
exports
=
WechatService
;
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