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
869169e2
Commit
869169e2
authored
Sep 24, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
course fix
parent
4b3afa89
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
55 deletions
+113
-55
user.js
app/controller/course/user.js
+28
-20
mini_auth.js
app/middleware/mini_auth.js
+11
-6
course_cat.js
app/model/class/course_cat.js
+1
-0
course.js
app/router/course.js
+19
-17
institution.js
app/service/course/institution.js
+49
-10
option.js
app/service/course/option.js
+3
-1
user.js
app/service/course/user.js
+2
-1
No files found.
app/controller/course/user.js
View file @
869169e2
...
@@ -8,26 +8,32 @@ class UserController extends Controller {
...
@@ -8,26 +8,32 @@ class UserController extends Controller {
async
auth
()
{
async
auth
()
{
const
{
ctx
,
app
}
=
this
;
const
{
ctx
,
app
}
=
this
;
const
code
=
ctx
.
request
.
body
.
code
=
'123123sfdsf'
;
const
code
=
ctx
.
request
.
body
.
code
;
if
(
!
code
)
{
if
(
!
code
)
{
ctx
.
failed
(
'error code'
);
ctx
.
failed
(
'error code'
);
}
}
//请求微信授权 获取openid
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
user
.
requestWxAuth
(
code
);
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
user
.
requestWxAuth
(
code
);
const
openid
=
wx_auth_ret
.
openid
;
const
openid
=
wx_auth_ret
.
openid
;
//获取openid
// const session_key = wx_auth_ret.session_key;
//检查是否已授权过 是否已入用户表
let
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
let
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
if
(
!
user
||
!
user
.
uuid
)
{
if
(
!
user
||
!
user
.
uuid
)
{
const
uuid
=
uuidv4
();
const
uuid
=
uuidv4
();
user
=
await
ctx
.
classModel
.
CourseUser
.
add
({
uuid
,
openid
});
user
=
await
ctx
.
classModel
.
CourseUser
.
add
({
uuid
,
openid
});
}
}
//存储缓存标识
const
user_uuid
=
user
.
uuid
;
const
user_uuid
=
user
.
uuid
;
const
key
=
'course_user_session_'
+
user_uuid
;
const
key
=
'course_user_session_'
+
user_uuid
;
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
);
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
);
const
token
=
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
);
const
auth_token
=
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
);
ctx
.
set
(
'Session_Id'
,
key
);
ctx
.
set
(
'uuid'
,
key
);
ctx
.
set
(
'token'
,
token
);
ctx
.
set
(
'auth_token'
,
auth_token
);
const
result
=
{
uuid
,
auth_token
};
const
result
=
{
user_uuid
};
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
...
@@ -38,6 +44,8 @@ class UserController extends Controller {
...
@@ -38,6 +44,8 @@ class UserController extends Controller {
const
uuid
=
ctx
.
userUuid
;
const
uuid
=
ctx
.
userUuid
;
const
input_params
=
ctx
.
request
.
body
;
const
input_params
=
ctx
.
request
.
body
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
//查找用户是否存在并更新
const
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
uuid
}
});
const
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
uuid
}
});
await
ctx
.
classModel
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
await
ctx
.
classModel
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
let
bindphone
=
0
;
let
bindphone
=
0
;
...
@@ -49,18 +57,8 @@ class UserController extends Controller {
...
@@ -49,18 +57,8 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
async
verify_auth
()
{
const
{
ctx
}
=
this
;
const
headers
=
ctx
.
request
.
headers
;
ctx
.
success
({
headers
});
}
/**
/**
*
*
获取baby信息
*/
*/
async
getBabyInfo
()
{
async
getBabyInfo
()
{
...
@@ -70,6 +68,9 @@ class UserController extends Controller {
...
@@ -70,6 +68,9 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
/**
* 保存baby信息
*/
async
saveBabyInfo
()
{
async
saveBabyInfo
()
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -79,6 +80,9 @@ class UserController extends Controller {
...
@@ -79,6 +80,9 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
/**
* 删除baby信息
*/
async
delBabyInfo
()
{
async
delBabyInfo
()
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -87,7 +91,9 @@ class UserController extends Controller {
...
@@ -87,7 +91,9 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
/**
* 用户收藏机构列表
*/
async
getCollectInstitutions
()
{
async
getCollectInstitutions
()
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -97,7 +103,9 @@ class UserController extends Controller {
...
@@ -97,7 +103,9 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
/**
* 收藏机构列表
*/
async
collectInstitution
()
{
async
collectInstitution
()
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
...
app/middleware/mini_auth.js
View file @
869169e2
...
@@ -4,14 +4,19 @@ module.exports = (options, app) => {
...
@@ -4,14 +4,19 @@ module.exports = (options, app) => {
return
async
function
(
ctx
,
next
)
{
return
async
function
(
ctx
,
next
)
{
const
session_id
=
ctx
.
headers
.
Session_Id
;
const
uuid
=
ctx
.
headers
.
uuid
;
const
key
=
'course_user_session_'
+
session_id
;
const
key
=
'course_user_session_'
+
uuid
;
const
auth_info
=
await
app
.
memcache
.
get
(
key
);
const
auth_info
=
await
ctx
.
app
.
memcache
.
get
(
key
);
if
(
!
auth_info
)
{
await
next
();
return
;
// ctx.failed('login auth error');
}
const
openid
=
auth_info
.
openid
;
const
openid
=
auth_info
.
openid
;
const
user_uuid
=
auth_info
.
user_uuid
;
const
user_uuid
=
auth_info
.
user_uuid
;
const
token
=
ctx
.
headers
.
token
;
const
auth_token
=
ctx
.
headers
.
auth_
token
;
if
(
ctx
.
helper
.
md5
(
openid
+
u
ser_uuid
+
'jbwl'
)
!=
token
)
{
if
(
ctx
.
helper
.
md5
(
openid
+
u
uid
+
'jbwl'
)
!=
auth_
token
)
{
ctx
.
failed
(
'login auth error'
);
//
ctx.failed('login auth error');
}
}
ctx
.
setUserUuid
(
user_uuid
);
ctx
.
setUserUuid
(
user_uuid
);
...
...
app/model/class/course_cat.js
View file @
869169e2
...
@@ -17,6 +17,7 @@ module.exports = app => {
...
@@ -17,6 +17,7 @@ module.exports = app => {
level
:
INTEGER
,
level
:
INTEGER
,
name
:
STRING
,
name
:
STRING
,
image
:
STRING
,
image
:
STRING
,
color
:
STRING
,
tips
:
STRING
,
tips
:
STRING
,
status
:
ENUM
(
'offline'
,
'online'
),
status
:
ENUM
(
'offline'
,
'online'
),
is_deleted
:
INTEGER
,
is_deleted
:
INTEGER
,
...
...
app/router/course.js
View file @
869169e2
...
@@ -3,25 +3,27 @@
...
@@ -3,25 +3,27 @@
module
.
exports
=
app
=>
{
module
.
exports
=
app
=>
{
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/course'
);
const
router
=
app
.
router
.
namespace
(
app
.
config
.
projectRootPath
+
'/course'
);
const
loginAuth
=
app
.
middleware
.
loginAuth
({
type
:
'new'
});
//登录中间件
const
loginAuth
=
app
.
middleware
.
loginAuth
({
type
:
'new'
});
//登录中间件
const
miniAuth
=
app
.
middleware
.
miniAuth
();
//登录中间件
router
.
get
(
'/options'
,
'course.option.getOptions'
);
router
.
get
(
'/options'
,
'course.option.getOptions'
);
//筛选项
router
.
post
(
'/institutions'
,
'course.institution.institutionList'
);
router
.
post
(
'/institutions'
,
'course.institution.institutionList'
);
//机构列表
router
.
get
(
'/institutions'
,
'course.institution.institutionList'
);
router
.
get
(
'/institutions'
,
'course.institution.institutionList'
);
//机构列表
router
.
get
(
'/institution/:institution_id/:area_id'
,
'course.institution.institutionInfo'
);
router
.
get
(
'/institution/:institution_id/:area_id'
,
'course.institution.institutionInfo'
);
//机构详情
router
.
post
(
'/classes'
,
'course.institution.classList'
);
router
.
post
(
'/classes'
,
'course.institution.classList'
);
//课程列表
router
.
get
(
'/classes'
,
'course.institution.classList'
);
router
.
get
(
'/classes'
,
'course.institution.classList'
);
//课程列表
router
.
get
(
'/class/:class_id'
,
'course.institution.classInfo'
);
router
.
get
(
'/class/:class_id'
,
'course.institution.classInfo'
);
//课程详情
router
.
post
(
'/teachers'
,
'course.institution.teacherList'
);
router
.
post
(
'/teachers'
,
'course.institution.teacherList'
);
//老师列表
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/auth'
,
'course.user.auth'
);
router
.
post
(
'/user/auth'
,
'course.user.auth'
);
//微信授权登录
router
.
get
(
'/user/verify_auth'
,
'course.user.verify_auth'
);
router
.
post
(
'/user/register_user'
,
miniAuth
,
'course.user.registerUserInfo'
);
//授权后注册用户
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
.
get
(
'/user/baby'
,
'course.user.getBabyInfo'
);
//获取baby信息
router
.
post
(
'/user/collection/institution'
,
'course.user.collectInstitution'
);
router
.
post
(
'/user/baby'
,
'course.user.saveBabyInfo'
);
//保存baby信息
router
.
delete
(
'/user/baby'
,
'course.user.delBabyInfo'
);
//删除baby信息
router
.
get
(
'/user/collection/institution'
,
'course.user.getCollectInstitutions'
);
//收藏的机构列表
router
.
post
(
'/user/collection/institution'
,
'course.user.collectInstitution'
);
//收藏机构
};
};
app/service/course/institution.js
View file @
869169e2
...
@@ -11,7 +11,15 @@ class InstitutionService extends Service {
...
@@ -11,7 +11,15 @@ class InstitutionService extends Service {
async
getInstitutions
(
input
)
{
async
getInstitutions
(
input
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
{
cat
,
age
,
institution
,
lat
,
lng
}
=
input
;
const
user_uuid
=
ctx
.
userUuid
;
const
{
cat
,
age
,
institution
,
lat
,
lng
,
address
}
=
input
;
//保存定位记录
if
(
address
&&
lat
&&
lng
)
{
ctx
.
classModel
.
CourseLogUserGps
.
add
({
user_uuid
,
address
,
lat
,
lng
});
}
//处理条件过滤条件
let
where
=
{
status
:
1
,
is_deleted
:
0
};
let
where
=
{
status
:
1
,
is_deleted
:
0
};
if
(
cat
)
{
if
(
cat
)
{
const
cat_ret
=
await
ctx
.
classModel
.
CourseCat
.
one
({
where
:
{
id
:
cat
}
});
const
cat_ret
=
await
ctx
.
classModel
.
CourseCat
.
one
({
where
:
{
id
:
cat
}
});
...
@@ -33,13 +41,15 @@ class InstitutionService extends Service {
...
@@ -33,13 +41,15 @@ class InstitutionService extends Service {
if
(
institution
)
{
if
(
institution
)
{
where
.
corner
=
{
$ne
:
''
};
where
.
corner
=
{
$ne
:
''
};
}
}
//关联校区表查找信息
const
include
=
[{
model
:
ctx
.
classModel
.
CourseArea
,
where
:
{
status
:
1
,
is_deleted
:
0
},
attributes
:
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'lat'
,
'lng'
]
}];
const
include
=
[{
model
:
ctx
.
classModel
.
CourseArea
,
where
:
{
status
:
1
,
is_deleted
:
0
},
attributes
:
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'lat'
,
'lng'
]
}];
const
attributes
=
[
'id'
,
'name'
,
'type'
,
'establishment_time'
,
'class_type'
,
'teacher_count'
,
'teacher_experience'
,
'corner'
,
'min_age'
,
'max_age'
,
'price'
,
'characteristic'
,];
const
attributes
=
[
'id'
,
'name'
,
'type'
,
'establishment_time'
,
'class_type'
,
'teacher_count'
,
'teacher_experience'
,
'corner'
,
'min_age'
,
'max_age'
,
'price'
,
'characteristic'
,];
const
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
attributes
,
include
,
where
});
const
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
attributes
,
include
,
where
});
const
institution_area_list
=
await
this
.
getInstitutionAreaList
(
institutions
);
const
institution_area_list
=
await
this
.
getInstitutionAreaList
(
institutions
);
//将校区表处理成数组
const
area_lbs
=
await
this
.
computeDistance
(
institution_area_list
,
{
lat
,
lng
});
const
area_lbs
=
await
this
.
computeDistance
(
institution_area_list
,
{
lat
,
lng
});
//计算距离信息
const
institution_areas
=
await
this
.
findShortestDistanceAreas
(
institution_area_list
,
area_lbs
);
const
institution_areas
=
await
this
.
findShortestDistanceAreas
(
institution_area_list
,
area_lbs
);
//查找最短距离并输出
const
ret
=
await
this
.
formatInstitutions
(
institution_areas
);
const
ret
=
await
this
.
formatInstitutions
(
institution_areas
);
return
ret
;
return
ret
;
...
@@ -51,17 +61,21 @@ class InstitutionService extends Service {
...
@@ -51,17 +61,21 @@ class InstitutionService extends Service {
async
getInstitution
({
institution_id
,
area_id
})
{
async
getInstitution
({
institution_id
,
area_id
})
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
one
({
where
:
{
id
:
institution_id
}
});
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
one
({
where
:
{
id
:
institution_id
}
});
const
teachers
=
await
this
.
getTeachers
({
institution_id
,
limit
:
6
});
const
teachers
=
await
this
.
getTeachers
({
institution_id
,
limit
:
6
});
const
classes
=
await
this
.
getClasses
({
institution_id
,
limit
:
4
});
const
classes
=
await
this
.
getClasses
({
institution_id
,
limit
:
4
});
const
areas
=
await
this
.
getInstitutionAreas
({
institution_id
,
limit
:
1000
});
const
areas
=
await
this
.
getInstitutionAreas
({
institution_id
,
limit
:
1000
});
//校区
const
institution_images
=
await
ctx
.
classModel
.
CourseImages
.
all
({
where
:
{
type
:
1
,
type_id
:
institution_id
}
});
const
institution_images
=
await
ctx
.
classModel
.
CourseImages
.
all
({
where
:
{
type
:
1
,
type_id
:
institution_id
}
});
//图片
//处理详情页信息
const
current_area
=
await
ctx
.
classModel
.
CourseArea
.
one
({
id
:
area_id
});
const
current_area
=
await
ctx
.
classModel
.
CourseArea
.
one
({
id
:
area_id
});
let
institution_detail
=
await
this
.
formatInstitutions
([
institution
]);
let
institution_detail
=
await
this
.
formatInstitutions
([
institution
]);
institution_detail
=
institution_detail
[
0
];
institution_detail
=
institution_detail
[
0
];
institution_detail
.
address
=
current_area
.
address
;
institution_detail
.
address
=
current_area
.
address
;
institution_detail
.
phone
=
current_area
.
phone
;
institution_detail
.
phone
=
current_area
.
phone
;
institution_detail
.
description
=
institution
.
description
;
institution_detail
.
description
=
institution
.
description
;
//处理图片
//处理图片
const
photo_album
=
[];
const
photo_album
=
[];
for
(
let
i
in
institution_images
)
{
for
(
let
i
in
institution_images
)
{
...
@@ -96,6 +110,7 @@ class InstitutionService extends Service {
...
@@ -96,6 +110,7 @@ class InstitutionService extends Service {
classs
.
dataValues
.
age_text
=
`
${
classs
.
min_age
}
-
${
classs
.
max_age
}
岁`
;
classs
.
dataValues
.
age_text
=
`
${
classs
.
min_age
}
-
${
classs
.
max_age
}
岁`
;
classs
.
dataValues
.
point_tags
=
classs
.
point
.
split
(
';'
);
classs
.
dataValues
.
point_tags
=
classs
.
point
.
split
(
';'
);
classs
.
dataValues
.
photo_album
=
classs
.
image
.
split
(
';'
);
classs
.
dataValues
.
photo_album
=
classs
.
image
.
split
(
';'
);
return
classs
;
return
classs
;
}
}
...
@@ -119,6 +134,8 @@ class InstitutionService extends Service {
...
@@ -119,6 +134,8 @@ class InstitutionService extends Service {
const
where
=
{
institution_id
};
const
where
=
{
institution_id
};
const
classes
=
await
ctx
.
classModel
.
CourseClass
.
list
({
attributes
,
page
,
limit
,
where
});
const
classes
=
await
ctx
.
classModel
.
CourseClass
.
list
({
attributes
,
page
,
limit
,
where
});
const
p_class_images
=
[];
const
p_class_images
=
[];
//获取图片信息
for
(
let
j
in
classes
.
rows
)
{
for
(
let
j
in
classes
.
rows
)
{
const
classs
=
classes
.
rows
[
j
];
const
classs
=
classes
.
rows
[
j
];
p_class_images
[
j
]
=
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
2
,
type_id
:
classs
.
id
,
is_cover
:
1
,
is_video
:
0
}
});
p_class_images
[
j
]
=
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
2
,
type_id
:
classs
.
id
,
is_cover
:
1
,
is_video
:
0
}
});
...
@@ -129,6 +146,7 @@ class InstitutionService extends Service {
...
@@ -129,6 +146,7 @@ class InstitutionService extends Service {
ctx
.
failed
(
error
);
ctx
.
failed
(
error
);
});
});
//格式化课程信息
let
ret
=
[];
let
ret
=
[];
for
(
let
i
in
classes
.
rows
)
{
for
(
let
i
in
classes
.
rows
)
{
let
classs
=
classes
.
rows
[
i
];
let
classs
=
classes
.
rows
[
i
];
...
@@ -153,6 +171,7 @@ class InstitutionService extends Service {
...
@@ -153,6 +171,7 @@ class InstitutionService extends Service {
}
}
//机构列表 并有多校区 {id:1,..., course_areas:[{},{}]
async
getInstitutionAreaList
(
institutions
)
{
async
getInstitutionAreaList
(
institutions
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -190,15 +209,24 @@ class InstitutionService extends Service {
...
@@ -190,15 +209,24 @@ class InstitutionService extends Service {
return
ret
;
return
ret
;
}
}
//distance=3km
/**
* 起点()到多个终点([{ lng: 120.212997, lat: 30.29133 }];) 计算距离 distance=3km
* @param {*} lbs_array [{ lng: 120.212997, lat: 30.29133 }]
* @param {*} from_gps { lng: 120.069206, lat: 30.291121 }
* @param {*} distance 3
*/
async
computeDistance
(
lbs_array
,
from_gps
,
distance
=
3
)
{
async
computeDistance
(
lbs_array
,
from_gps
,
distance
=
3
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
from
=
from_gps
;
const
from
=
from_gps
;
//计算距离
const
driving_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
from
,
lbs_array
);
const
driving_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
from
,
lbs_array
);
const
walking_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'walking'
,
from
,
lbs_array
);
const
walking_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'walking'
,
from
,
lbs_array
);
if
(
!
walking_results
.
results
&&
!
driving_results
.
results
)
{
return
[];
}
//处理距离结果
const
drivings
=
driving_results
.
results
.
map
(
item
=>
{
const
drivings
=
driving_results
.
results
.
map
(
item
=>
{
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
1
);
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
1
);
const
duration
=
Math
.
ceil
(
item
.
duration
/
60
);
const
duration
=
Math
.
ceil
(
item
.
duration
/
60
);
...
@@ -210,6 +238,7 @@ class InstitutionService extends Service {
...
@@ -210,6 +238,7 @@ class InstitutionService extends Service {
return
{
distance
:
distance
,
duration
:
duration
}
return
{
distance
:
distance
,
duration
:
duration
}
});
});
//格式化 判断步行或驾车
const
results
=
[];
const
results
=
[];
for
(
let
i
in
lbs_array
)
{
for
(
let
i
in
lbs_array
)
{
let
lbs
=
lbs_array
[
i
];
let
lbs
=
lbs_array
[
i
];
...
@@ -230,6 +259,11 @@ class InstitutionService extends Service {
...
@@ -230,6 +259,11 @@ class InstitutionService extends Service {
}
}
/**
*
* @param {*} institution_areas 校区列表
* @param {*} areas_list 校区距离列表
*/
async
findShortestDistanceAreas
(
institution_areas
,
areas_list
)
{
async
findShortestDistanceAreas
(
institution_areas
,
areas_list
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
...
@@ -237,11 +271,13 @@ class InstitutionService extends Service {
...
@@ -237,11 +271,13 @@ class InstitutionService extends Service {
const
ret
=
[];
const
ret
=
[];
const
institution_lbs
=
await
this
.
computeDistance
(
areas_list
);
const
institution_lbs
=
await
this
.
computeDistance
(
areas_list
);
for
(
let
i
in
institution_areas
)
{
for
(
let
i
in
institution_areas
)
{
let
institution_area
=
institution_areas
[
i
];
let
institution_area
=
institution_areas
[
i
];
const
lbs
=
institution_lbs
[
i
];
const
lbs
=
institution_lbs
[
i
];
const
area_name
=
institution_area
.
area_name
;
const
area_name
=
institution_area
.
area_name
;
const
distance
=
lbs
.
distance
;
const
distance
=
lbs
.
distance
?
lbs
.
distance
:
10
;
const
duration
=
lbs
.
duration
;
const
duration
=
lbs
.
duration
?
lbs
.
duration
:
60
;
let
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,开车
${
duration
}
分钟`
;
let
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,开车
${
duration
}
分钟`
;
if
(
lbs
.
travel_method
===
'walking'
)
{
if
(
lbs
.
travel_method
===
'walking'
)
{
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,步行
${
duration
}
分钟`
;
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,步行
${
duration
}
分钟`
;
...
@@ -266,6 +302,8 @@ class InstitutionService extends Service {
...
@@ -266,6 +302,8 @@ class InstitutionService extends Service {
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
return
[];
return
[];
}
}
//处理机构图片
const
p_institution_images
=
[];
const
p_institution_images
=
[];
for
(
let
j
in
institutions
)
{
for
(
let
j
in
institutions
)
{
const
institution
=
institutions
[
j
];
const
institution
=
institutions
[
j
];
...
@@ -276,6 +314,7 @@ class InstitutionService extends Service {
...
@@ -276,6 +314,7 @@ class InstitutionService extends Service {
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
ctx
.
failed
(
error
);
});
});
const
ret
=
[];
const
ret
=
[];
for
(
let
i
in
institutions
)
{
for
(
let
i
in
institutions
)
{
const
institution
=
institutions
[
i
];
const
institution
=
institutions
[
i
];
...
...
app/service/course/option.js
View file @
869169e2
...
@@ -34,6 +34,7 @@ class OptionService extends Service {
...
@@ -34,6 +34,7 @@ class OptionService extends Service {
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
cats
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
status
:
1
,
is_deleted
:
0
}
});
const
cats
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
status
:
1
,
is_deleted
:
0
}
});
const
tree_cats
=
this
.
getTrees
(
cats
,
0
);
const
tree_cats
=
this
.
getTrees
(
cats
,
0
);
const
options
=
{
const
options
=
{
cats
:
tree_cats
,
cats
:
tree_cats
,
ages
:
AGE_CATS
,
ages
:
AGE_CATS
,
...
@@ -48,11 +49,12 @@ class OptionService extends Service {
...
@@ -48,11 +49,12 @@ class OptionService extends Service {
const
node
=
data
[
i
];
const
node
=
data
[
i
];
if
(
node
.
parent_id
==
rootId
)
{
if
(
node
.
parent_id
==
rootId
)
{
const
newNode
=
{};
const
newNode
=
{};
ret
.
push
({
id
:
0
,
name
:
'全部'
,
value
:
''
});
//
ret.push({ id: 0, name: '全部', value: '' });
newNode
.
id
=
node
.
id
;
newNode
.
id
=
node
.
id
;
newNode
.
name
=
node
.
name
;
newNode
.
name
=
node
.
name
;
newNode
.
tips
=
node
.
tips
;
newNode
.
tips
=
node
.
tips
;
newNode
.
image
=
node
.
image
;
newNode
.
image
=
node
.
image
;
newNode
.
color
=
node
.
color
;
newNode
.
level
=
node
.
level
;
newNode
.
level
=
node
.
level
;
newNode
.
value
=
node
.
id
;
newNode
.
value
=
node
.
id
;
newNode
.
_child
=
this
.
getTrees
(
data
,
node
.
id
);
newNode
.
_child
=
this
.
getTrees
(
data
,
node
.
id
);
...
...
app/service/course/user.js
View file @
869169e2
...
@@ -104,7 +104,7 @@ class UserService extends Service {
...
@@ -104,7 +104,7 @@ class UserService extends Service {
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
APPID
=
'wx4769ebba9b91f8ec'
;
const
APPID
=
'wx4769ebba9b91f8ec'
;
const
SECRET
=
'
1231312321312
'
;
const
SECRET
=
'
680440637b4e38c9b66529cfd5dc590e
'
;
const
url
=
`https://api.weixin.qq.com/sns/jscode2session?appid=
${
APPID
}
&secret=
${
SECRET
}
&js_code=
${
code
}
&grant_type=authorization_code`
;
const
url
=
`https://api.weixin.qq.com/sns/jscode2session?appid=
${
APPID
}
&secret=
${
SECRET
}
&js_code=
${
code
}
&grant_type=authorization_code`
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{},
{
method
:
'GET'
});
...
@@ -112,6 +112,7 @@ class UserService extends Service {
...
@@ -112,6 +112,7 @@ class UserService extends Service {
if
(
result
.
status
===
200
)
{
if
(
result
.
status
===
200
)
{
ctx
.
failed
(
'授权失败'
);
ctx
.
failed
(
'授权失败'
);
}
}
const
ret
=
result
.
data
;
const
ret
=
result
.
data
;
if
(
ret
.
errcode
!==
0
)
{
if
(
ret
.
errcode
!==
0
)
{
ctx
.
failed
(
ret
.
errmsg
);
ctx
.
failed
(
ret
.
errmsg
);
...
...
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