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
730aa56a
Commit
730aa56a
authored
Oct 10, 2019
by
Hsinli
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of t-git.51gjj.com:fangbin/51business
parents
66492aec
838d8d50
Pipeline
#14659
passed with stage
in 34 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
531 additions
and
471 deletions
+531
-471
test.js
app/controller/common/test.js
+1
-1
callrisk.js
app/controller/credit/callrisk.js
+3
-2
order.js
app/controller/credit/order.js
+1
-1
institution.js
app/service/course/institution.js
+415
-395
option.js
app/service/course/option.js
+46
-46
apply.js
app/service/credit/apply.js
+17
-8
callrisk.js
app/service/credit/callrisk.js
+39
-10
yys.js
app/service/credit/yys.js
+8
-7
config.local.js
config/config.local.js
+1
-1
No files found.
app/controller/common/test.js
View file @
730aa56a
...
...
@@ -6,7 +6,7 @@ class TestController extends Controller {
const
{
service
,
ctx
}
=
this
;
const
from
=
{
lng
:
120.069206
,
lat
:
30.291121
};
const
to
=
{
lng
:
120.212997
,
lat
:
30.29133
};
const
ret
=
await
service
.
course
.
lbs
.
getLBSDistance
(
'
driving'
,
from
,
[
to
]);
const
ret
=
await
service
.
course
.
lbs
.
getLBSDistance
(
'
walking'
,
from
,
[
to
,
to
]);
ctx
.
success
(
ret
);
}
}
...
...
app/controller/credit/callrisk.js
View file @
730aa56a
...
...
@@ -39,7 +39,8 @@ class CallriskController extends Controller {
name
:
{
type
:
'string'
,
required
:
true
},
phone
:
{
type
:
'string'
,
required
:
true
},
id_card
:
{
type
:
'string'
,
required
:
true
},
password
:
{
type
:
'string'
,
required
:
true
}
password
:
{
type
:
'string'
,
required
:
true
},
net
:
{
type
:
'string'
,
required
:
true
},
}
ctx
.
validate
(
rule
,
input_params
);
const
result
=
await
ctx
.
service
.
credit
.
apply
.
applyCallrisk
(
input_params
);
...
...
@@ -70,7 +71,7 @@ class CallriskController extends Controller {
const
{
ctx
}
=
this
;
const
order_id
=
ctx
.
params
.
order_id
;
const
result
=
await
ctx
.
service
.
credit
.
callrisk
.
queryTaskStatus
(
order_id
);
ctx
.
success
({
result
});
}
...
...
app/controller/credit/order.js
View file @
730aa56a
...
...
@@ -34,7 +34,7 @@ class OrderController extends Controller {
const
{
method
,
order_id
,
reject_url
}
=
input_params
;
let
result
=
await
ctx
.
service
.
credit
.
order
.
unifiedOrder
(
method
,
order_id
);
// result.reject_url = reject_url;
result
.
url
=
`
${
result
.
url
}
&
py=#shanp.com&
redirect_url=
${
reject_url
}
`
;
result
.
url
=
`
${
result
.
url
}
&redirect_url=
${
reject_url
}
`
;
ctx
.
success
({
result
});
}
...
...
app/service/course/institution.js
View file @
730aa56a
...
...
@@ -8,456 +8,476 @@ const moment = require('moment');
class
InstitutionService
extends
Service
{
//
机构列表页
async
getInstitutions
(
input
)
{
const
{
ctx
}
=
this
;
const
user_uuid
=
ctx
.
userUuid
;
const
{
cats
,
ages
,
lat
,
lng
,
address
}
=
input
;
const
where_institutions
=
input
.
institutions
;
//
保存定位记录
if
(
address
&&
lat
&&
lng
)
{
ctx
.
classModel
.
CourseLogUserGps
.
add
({
user_uuid
,
address
,
lat
,
lng
});
}
//
机构列表页
async
getInstitutions
(
input
)
{
const
{
ctx
}
=
this
;
const
user_uuid
=
ctx
.
userUuid
;
const
{
cats
,
ages
,
lat
,
lng
,
address
}
=
input
;
const
where_institutions
=
input
.
institutions
;
//
保存定位记录
if
(
address
&&
lat
&&
lng
)
{
ctx
.
classModel
.
CourseLogUserGps
.
add
({
user_uuid
,
address
,
lat
,
lng
});
}
//
处理条件过滤条件
le
t
where
=
{
status
:
1
,
is_deleted
:
0
};
if
(
Number
(
cats
))
{
const
cat_ret
=
await
ctx
.
classModel
.
CourseCat
.
one
({
where
:
{
id
:
cats
}
});
const
cat_id
=
cat_ret
.
id
;
const
cat_level
=
cat_ret
.
level
;
const
next_level
=
cat_level
+
1
;
const
next_next_level
=
cat_level
+
2
;
const
next_cat
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
level
:
next_level
,
parent_id
:
cat_id
}
});
const
next_next_cat
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
level
:
next_next_level
,
first_id
:
cat_id
}
});
let
cat_ids
=
[
cat_id
,
];
cat_ids
=
cat_ids
.
concat
(
R
.
pluck
(
'id'
,
next_cat
)).
concat
(
R
.
pluck
(
'id'
,
next_next_cat
));
const
institutions
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
all
({
where
:
{
cat_id
:
{
$in
:
cat_ids
}
}
});
where
.
id
=
{
$in
:
R
.
pluck
(
'institution_id'
,
institutions
)
};
}
if
(
Number
(
ages
))
{
where
.
max_age
=
{
$gte
:
ages
};
where
.
min_age
=
{
$lte
:
ages
};
}
if
(
where_institutions
)
{
where
.
corner
=
{
$ne
:
''
};
}
//
处理条件过滤条件
cons
t
where
=
{
status
:
1
,
is_deleted
:
0
};
if
(
Number
(
cats
))
{
const
cat_ret
=
await
ctx
.
classModel
.
CourseCat
.
one
({
where
:
{
id
:
cats
}
});
const
cat_id
=
cat_ret
.
id
;
const
cat_level
=
cat_ret
.
level
;
const
next_level
=
cat_level
+
1
;
const
next_next_level
=
cat_level
+
2
;
const
next_cat
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
level
:
next_level
,
parent_id
:
cat_id
}
});
const
next_next_cat
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
level
:
next_next_level
,
first_id
:
cat_id
}
});
let
cat_ids
=
[
cat_id
];
cat_ids
=
cat_ids
.
concat
(
R
.
pluck
(
'id'
,
next_cat
)).
concat
(
R
.
pluck
(
'id'
,
next_next_cat
));
const
institutions
=
await
ctx
.
classModel
.
CourseInstitutionToCat
.
all
({
where
:
{
cat_id
:
{
$in
:
cat_ids
}
}
});
where
.
id
=
{
$in
:
R
.
pluck
(
'institution_id'
,
institutions
)
};
}
if
(
Number
(
ages
))
{
where
.
max_age
=
{
$gte
:
ages
};
where
.
min_age
=
{
$lte
:
ages
};
}
if
(
where_institutions
)
{
where
.
corner
=
{
$ne
:
''
};
}
//
关联校区表查找信息
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
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
attributes
,
include
,
where
});
//
关联校区表查找信息
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
institutions
=
await
ctx
.
classModel
.
CourseInstitution
.
findAll
({
attributes
,
include
,
where
});
const
institution_area_list
=
await
this
.
getInstitutionAreaList
(
institutions
);
//
将校区表处理成数组
// const from = { 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
ret
=
await
this
.
formatInstitutions
(
institution_areas
);
const
institution_area_list
=
await
this
.
getInstitutionAreaList
(
institutions
);
//
将校区表处理成数组
// const from = { 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
ret
=
await
this
.
formatInstitutions
(
institution_areas
);
return
ret
;
}
return
ret
;
}
/**
/**
* 机构详情页
*/
async
getInstitution
(
input
)
{
const
{
ctx
}
=
this
;
const
user_uuid
=
ctx
.
userUuid
;
const
{
institution_id
,
area_id
}
=
input
;
const
lat
=
ctx
.
isEmpty
(
input
.
lat
)
?
0
:
input
.
lat
;
const
lng
=
ctx
.
isEmpty
(
input
.
lng
)
?
0
:
input
.
lng
;
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
one
({
where
:
{
id
:
institution_id
}
});
const
teachers
=
await
this
.
getTeachers
({
institution_id
,
limit
:
6
});
const
classes
=
await
this
.
getClasses
({
institution_id
,
limit
:
4
});
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
});
let
institution_detail
=
await
this
.
formatInstitutions
([
institution
]);
institution_detail
=
institution_detail
[
0
];
institution_detail
.
address
=
current_area
.
address
;
institution_detail
.
phone
=
current_area
.
phone
;
institution_detail
.
description
=
institution
.
description
;
institution_detail
.
point
=
institution
.
point
;
institution_detail
.
honor
=
institution
.
honor
;
institution_detail
.
is_collect
=
0
;
//计算校区距离
const
areas_ret
=
await
this
.
getInstitutionAreas
({
institution_id
,
limit
:
1000
});
//校区
const
area_rows
=
areas_ret
.
rows
;
const
area_lbs
=
(
lat
>
0
||
lng
>
0
)
?
await
this
.
computeDistance
(
area_rows
,
{
lat
,
lng
})
:
[];
//计算距离信息
const
areas
=
[];
for
(
let
i
in
area_rows
)
{
const
area
=
area_rows
[
i
];
const
lbs
=
i
<
area_lbs
.
length
?
area_lbs
[
i
]
:
{
distance
:
0
,
duration
:
0
,
travel_method
:
''
};
const
area_name
=
area
.
name
;
const
distance
=
lbs
.
distance
;
const
duration
=
lbs
.
duration
;
let
travel_tips
=
`距我
${
distance
}
km,开车
${
duration
}
分钟`
;
if
(
lbs
.
travel_method
===
'walking'
)
{
travel_tips
=
`距我
${
distance
}
km,步行
${
duration
}
分钟`
;
}
if
(
distance
===
0
&&
duration
===
0
)
{
travel_tips
=
'暂无法计算出距离'
;
}
if
(
area
.
id
==
area_id
&&
area
.
institution_id
==
institution_id
)
{
institution_detail
.
travel_tips
=
travel_tips
;
institution_detail
.
lat
=
area
.
lat
;
institution_detail
.
lng
=
area
.
lng
;
}
areas
.
push
({
id
:
area
.
id
,
institution_id
:
area
.
institution_id
,
name
:
area_name
,
address
:
area
.
address
,
phone
:
area
.
phone
,
travel_tips
,
lat
:
area
.
lat
,
lng
:
area
.
lng
,
});
}
async
getInstitution
(
input
)
{
const
{
ctx
}
=
this
;
const
user_uuid
=
ctx
.
userUuid
;
const
{
institution_id
,
area_id
}
=
input
;
const
lat
=
ctx
.
isEmpty
(
input
.
lat
)
?
0
:
input
.
lat
;
const
lng
=
ctx
.
isEmpty
(
input
.
lng
)
?
0
:
input
.
lng
;
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
one
({
where
:
{
id
:
institution_id
}
});
const
teachers
=
await
this
.
getTeachers
({
institution_id
,
limit
:
6
});
const
classes
=
await
this
.
getClasses
({
institution_id
,
limit
:
4
});
const
institution_images
=
await
ctx
.
classModel
.
CourseImages
.
all
({
where
:
{
type
:
1
,
type_id
:
institution_id
}
});
// 图片
// 处理详情页信息
const
current_area
=
await
ctx
.
classModel
.
CourseArea
.
one
({
where
:
{
id
:
area_id
}
});
let
institution_detail
=
await
this
.
formatInstitutions
([
institution
]);
institution_detail
=
institution_detail
[
0
];
institution_detail
.
address
=
current_area
.
address
;
institution_detail
.
phone
=
current_area
.
phone
;
institution_detail
.
description
=
institution
.
description
;
institution_detail
.
point
=
institution
.
point
;
institution_detail
.
honor
=
institution
.
honor
;
institution_detail
.
is_collect
=
0
;
// 计算校区距离
const
areas_ret
=
await
this
.
getInstitutionAreas
({
institution_id
,
limit
:
1000
});
// 校区
const
area_rows
=
areas_ret
.
rows
;
const
area_lbs
=
(
lat
>
0
||
lng
>
0
)
?
await
this
.
computeDistance
(
area_rows
,
{
lat
,
lng
})
:
[];
// 计算距离信息
let
areas
=
[];
for
(
const
i
in
area_rows
)
{
const
area
=
area_rows
[
i
];
const
lbs
=
i
<
area_lbs
.
length
?
area_lbs
[
i
]
:
{
distance
:
0
,
duration
:
0
,
travel_method
:
''
};
const
area_name
=
area
.
name
;
const
distance
=
lbs
.
distance
;
const
duration
=
lbs
.
duration
;
let
travel_tips
=
`距我
${
distance
}
km,开车
${
duration
}
分钟`
;
if
(
lbs
.
travel_method
===
'walking'
)
{
travel_tips
=
`距我
${
distance
}
km,步行
${
duration
}
分钟`
;
}
if
(
Number
(
distance
)
===
0
&&
duration
===
0
)
{
travel_tips
=
'暂无法计算出距离'
;
}
if
(
area
.
id
==
area_id
&&
area
.
institution_id
==
institution_id
)
{
institution_detail
.
travel_tips
=
travel_tips
;
institution_detail
.
lat
=
area
.
lat
;
institution_detail
.
lng
=
area
.
lng
;
}
areas
.
push
({
id
:
area
.
id
,
institution_id
:
area
.
institution_id
,
name
:
area_name
,
address
:
area
.
address
,
phone
:
area
.
phone
,
travel_tips
,
lat
:
area
.
lat
,
lng
:
area
.
lng
,
distance
:
Number
(
distance
)
===
0
?
999999999.0
:
parseFloat
(
distance
),
});
}
areas
=
_
.
orderBy
(
areas
,
[
'distance'
],
[
'asc'
]);
//
是否收藏过
const
collection_ret
=
await
ctx
.
classModel
.
CourseUserCollection
.
one
({
where
:
{
user_uuid
,
institution_id
,
is_deleted
:
0
}
});
if
(
collection_ret
&&
collection_ret
.
id
)
{
institution_detail
.
is_collect
=
1
;
}
//
是否收藏过
const
collection_ret
=
await
ctx
.
classModel
.
CourseUserCollection
.
one
({
where
:
{
user_uuid
,
institution_id
,
is_deleted
:
0
}
});
if
(
collection_ret
&&
collection_ret
.
id
)
{
institution_detail
.
is_collect
=
1
;
}
//处理图片
const
photo_album
=
[];
for
(
let
i
in
institution_images
)
{
const
institution_image
=
institution_images
[
i
];
photo_album
.
push
({
image
:
institution_image
.
image_url
,
is_video
:
institution_image
.
is_video
,
video_url
:
institution_image
.
video_url
,
});
// 处理图片
const
photo_album
=
[];
const
photo_check
=
[];
// 去重
for
(
const
i
in
institution_images
)
{
const
institution_image
=
institution_images
[
i
];
if
(
institution_image
.
is_video
>
0
)
{
if
(
photo_check
.
includes
(
institution_image
.
video_url
))
{
continue
;
}
else
{
photo_check
.
push
(
institution_image
.
video_url
);
}
institution_detail
.
photo_album
=
photo_album
;
return
{
institution_detail
,
teachers
:
teachers
.
rows
,
classes
:
classes
.
rows
,
areas
:
areas
};
}
else
{
if
(
photo_check
.
includes
(
institution_image
.
image_url
))
{
continue
;
}
else
{
photo_check
.
push
(
institution_image
.
image_url
);
}
}
photo_album
.
push
({
image
:
institution_image
.
image_url
,
is_video
:
institution_image
.
is_video
,
video_url
:
institution_image
.
video_url
,
});
}
async
getTeacher
(
teacher_id
)
{
const
{
ctx
}
=
this
;
const
where
=
{
id
:
teacher_id
};
let
teacher
=
await
ctx
.
classModel
.
CourseTeacher
.
one
({
where
});
teacher
.
dataValues
.
point_tags
=
teacher
.
point
?
teacher
.
point
.
split
(
';'
)
:
[];
teacher
.
dataValues
.
work_experience_tags
=
teacher
.
work_experience
?
teacher
.
work_experience
.
split
(
';'
)
:
[];
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
find
({
where
:
{
id
:
teacher
.
institution_id
}
});
teacher
.
dataValues
.
institution_name
=
institution
.
name
;
return
teacher
;
institution_detail
.
photo_album
=
photo_album
;
return
{
institution_detail
,
teachers
:
teachers
.
rows
,
classes
:
classes
.
rows
,
areas
};
}
async
getTeacher
(
teacher_id
)
{
const
{
ctx
}
=
this
;
const
where
=
{
id
:
teacher_id
};
const
teacher
=
await
ctx
.
classModel
.
CourseTeacher
.
one
({
where
});
teacher
.
dataValues
.
point_tags
=
teacher
.
point
?
teacher
.
point
.
split
(
','
)
:
[];
teacher
.
dataValues
.
work_experience_tags
=
teacher
.
work_experience
?
teacher
.
work_experience
.
split
(
';'
)
:
[];
const
institution
=
await
ctx
.
classModel
.
CourseInstitution
.
find
({
where
:
{
id
:
teacher
.
institution_id
}
});
teacher
.
dataValues
.
institution_name
=
institution
.
name
;
return
teacher
;
}
async
getClass
(
class_id
)
{
const
{
ctx
}
=
this
;
const
where
=
{
id
:
class_id
};
const
classs
=
await
ctx
.
classModel
.
CourseClass
.
one
({
where
});
classs
.
dataValues
.
age_text
=
Number
(
classs
.
max_age
)
>
0
?
`
${
classs
.
min_age
}
-
${
classs
.
max_age
}
岁`
:
''
;
classs
.
dataValues
.
point_tags
=
classs
.
point
?
classs
.
point
.
split
(
','
)
:
[];
classs
.
dataValues
.
photo_album
=
classs
.
image
?
classs
.
image
.
split
(
';'
)
:
[];
classs
.
dataValues
.
class_period
=
classs
.
class_period
>
0
?
classs
.
class_period
:
''
;
return
classs
;
}
async
getTeachers
(
input
)
{
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'avatar'
,
'teacher_experience'
,
'lesson'
,
'educational_background'
,
'certificate'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
teachers
=
await
ctx
.
classModel
.
CourseTeacher
.
list
({
attributes
,
page
,
limit
,
where
});
const
ret
=
[];
for
(
const
i
in
teachers
.
rows
)
{
const
teacher
=
teachers
.
rows
[
i
];
ret
.
push
({
id
:
teacher
.
id
,
institution_id
:
teacher
.
institution_id
,
name
:
teacher
.
name
?
teacher
.
name
:
''
,
avatar
:
teacher
.
avatar
?
teacher
.
avatar
:
''
,
teacher_experience
:
teacher
.
teacher_experience
?
teacher
.
teacher_experience
:
''
,
lesson
:
teacher
.
lesson
?
teacher
.
lesson
:
''
,
educational_background
:
teacher
.
educational_background
?
teacher
.
educational_background
:
''
,
certificate
:
teacher
.
certificate
?
teacher
.
certificate
:
''
,
});
}
async
getClass
(
class_id
)
{
const
{
ctx
}
=
this
;
const
where
=
{
id
:
class_id
};
let
classs
=
await
ctx
.
classModel
.
CourseClass
.
one
({
where
});
classs
.
dataValues
.
age_text
=
`
${
classs
.
min_age
}
-
${
classs
.
max_age
}
岁`
;
classs
.
dataValues
.
point_tags
=
classs
.
point
?
classs
.
point
.
split
(
';'
)
:
[];
classs
.
dataValues
.
photo_album
=
classs
.
image
?
classs
.
image
.
split
(
';'
)
:
[];
return
{
page
,
count
:
ret
.
length
,
rows
:
ret
};
return
classs
;
}
}
async
getTeachers
(
input
)
{
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'avatar'
,
'teacher_experience'
,
'lesson'
,
'educational_background'
,
'certificate'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
teachers
=
await
ctx
.
classModel
.
CourseTeacher
.
list
({
attributes
,
page
,
limit
,
where
});
const
ret
=
[];
for
(
let
i
in
teachers
)
{
const
teacher
=
teachers
[
i
];
ret
.
push
({
id
:
teacher
.
id
,
institution_id
:
teacher
.
institution_id
,
name
:
teacher
.
name
?
teacher
.
name
:
''
,
avatar
:
teacher
.
avatar
?
teacher
.
avatar
:
''
,
teacher_experience
:
teacher
.
teacher_experience
?
teacher
.
teacher_experience
:
''
,
lesson
:
teacher
.
lesson
?
teacher
.
lesson
:
''
,
educational_background
:
teacher
.
educational_background
?
teacher
.
educational_background
:
''
,
certificate
:
teacher
.
certificate
?
teacher
.
certificate
:
''
,
});
}
async
getClasses
(
input
)
{
return
ret
;
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'type'
,
'price'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
classes
=
await
ctx
.
classModel
.
CourseClass
.
list
({
attributes
,
page
,
limit
,
where
});
const
p_class_images
=
[];
// 获取图片信息
for
(
const
j
in
classes
.
rows
)
{
const
classs
=
classes
.
rows
[
j
];
p_class_images
[
j
]
=
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
2
,
type_id
:
classs
.
id
,
is_video
:
0
}
});
}
async
getClasses
(
input
)
{
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'type'
,
'price'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
classes
=
await
ctx
.
classModel
.
CourseClass
.
list
({
attributes
,
page
,
limit
,
where
});
const
p_class_images
=
[];
//获取图片信息
for
(
let
j
in
classes
.
rows
)
{
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
}
});
}
const
class_images
=
await
Promise
.
all
(
p_class_images
).
then
(
result
=>
{
//等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
//格式化课程信息
let
ret
=
[];
for
(
let
i
in
classes
.
rows
)
{
let
classs
=
classes
.
rows
[
i
];
classs
.
dataValues
.
image
=
class_images
[
i
]
?
class_images
[
i
].
image_url
:
''
;;
const
class_images
=
await
Promise
.
all
(
p_class_images
).
then
(
result
=>
{
// 等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
// 格式化课程信息
const
ret
=
[];
for
(
const
i
in
classes
.
rows
)
{
const
classs
=
classes
.
rows
[
i
];
classs
.
dataValues
.
image
=
class_images
[
i
]
?
class_images
[
i
].
image_url
:
''
;
classs
.
dataValues
.
price_text
=
classs
.
price
?
classs
.
price
:
'现场咨询'
;
ret
.
push
(
classs
);
}
return
{
page
:
classes
.
page
,
count
:
classes
.
count
,
rows
:
ret
};
classs
.
dataValues
.
class_period
=
classs
.
class_period
>
0
?
classs
.
class_period
:
''
;
ret
.
push
(
classs
);
}
async
getInstitutionAreas
(
input
)
{
return
{
page
:
classes
.
page
,
count
:
classes
.
count
,
rows
:
ret
};
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'phone'
,
'lat'
,
'lng'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
areas
=
await
ctx
.
classModel
.
CourseArea
.
list
({
attributes
,
page
,
limit
,
where
});
}
return
areas
;
async
getInstitutionAreas
(
input
)
{
}
const
{
ctx
}
=
this
;
const
attributes
=
[
'id'
,
'institution_id'
,
'name'
,
'address'
,
'phone'
,
'lat'
,
'lng'
];
const
{
institution_id
,
page
,
limit
}
=
input
;
const
where
=
{
institution_id
};
const
areas
=
await
ctx
.
classModel
.
CourseArea
.
list
({
attributes
,
page
,
limit
,
where
});
//机构列表 并有多校区 {id:1,..., course_areas:[{},{}]
async
getInstitutionAreaList
(
institutions
)
{
return
areas
;
const
{
ctx
}
=
this
;
}
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
return
[];
}
// 机构列表 并有多校区 {id:1,..., course_areas:[{},{}]
async
getInstitutionAreaList
(
institutions
)
{
const
ret
=
[];
for
(
let
i
in
institutions
)
{
let
institution
=
institutions
[
i
];
if
(
!
institution
.
course_areas
||
institution
.
course_areas
.
length
===
0
)
continue
;
const
course_areas
=
institution
.
course_areas
;
for
(
let
j
in
course_areas
)
{
const
course_area
=
course_areas
[
j
];
ret
.
push
({
id
:
institution
.
id
,
name
:
institution
.
name
,
type
:
institution
.
type
,
image
:
institution
.
image
,
establishment_time
:
institution
.
establishment_time
,
class_type
:
institution
.
class_type
,
teacher_count
:
institution
.
teacher_count
,
teacher_experience
:
institution
.
teacher_experience
,
corner
:
institution
.
corner
,
min_age
:
institution
.
min_age
,
max_age
:
institution
.
max_age
,
price
:
institution
.
price
,
characteristic
:
institution
.
characteristic
,
area_id
:
course_area
.
id
,
area_name
:
course_area
.
name
,
area_address
:
course_area
.
address
,
lat
:
course_area
.
lat
,
lng
:
course_area
.
lng
,
});
}
}
const
{
ctx
}
=
this
;
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
return
[];
}
return
ret
;
const
ret
=
[];
for
(
const
i
in
institutions
)
{
const
institution
=
institutions
[
i
];
if
(
!
institution
.
course_areas
||
institution
.
course_areas
.
length
===
0
)
continue
;
const
course_areas
=
institution
.
course_areas
;
for
(
const
j
in
course_areas
)
{
const
course_area
=
course_areas
[
j
];
ret
.
push
({
id
:
institution
.
id
,
name
:
institution
.
name
,
type
:
institution
.
type
,
image
:
institution
.
image
,
establishment_time
:
institution
.
establishment_time
,
class_type
:
institution
.
class_type
,
teacher_count
:
institution
.
teacher_count
,
teacher_experience
:
institution
.
teacher_experience
,
corner
:
institution
.
corner
,
min_age
:
institution
.
min_age
,
max_age
:
institution
.
max_age
,
price
:
institution
.
price
,
characteristic
:
institution
.
characteristic
,
area_id
:
course_area
.
id
,
area_name
:
course_area
.
name
,
area_address
:
course_area
.
address
,
lat
:
course_area
.
lat
,
lng
:
course_area
.
lng
,
});
}
}
/**
return
ret
;
}
/**
* 起点()到多个终点([{ 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
;
if
(
!
Array
.
isArray
(
lbs_array
)
||
lbs_array
.
length
===
0
)
{
return
[];
}
const
{
ctx
}
=
this
;
const
from
=
from_gps
;
const
lat
=
from
.
lat
;
const
lng
=
from
.
lng
;
// console.info({ lat, lng });
//计算距离
const
driving_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
{
lat
,
lng
},
lbs_array
);
const
walking_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'walking'
,
{
lat
,
lng
},
lbs_array
);
if
(
!
walking_results
.
results
&&
!
driving_results
.
results
)
{
return
[];
}
if
(
!
Array
.
isArray
(
lbs_array
)
||
lbs_array
.
length
===
0
)
{
return
[];
}
//处理距离结果
const
drivings
=
driving_results
.
results
.
map
(
item
=>
{
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
1
);
const
duration
=
Math
.
ceil
(
item
.
duration
/
60
);
return
{
distance
:
distance
,
duration
:
duration
}
});
const
walkings
=
walking_results
.
results
.
map
(
item
=>
{
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
2
);
const
duration
=
Math
.
ceil
(
item
.
distance
/
80
);
return
{
distance
:
distance
,
duration
:
duration
}
});
const
from
=
from_gps
;
const
lat
=
from
.
lat
;
const
lng
=
from
.
lng
;
// console.info({ lat, lng });
// 计算距离
const
driving_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'driving'
,
{
lat
,
lng
},
lbs_array
);
const
walking_results
=
await
ctx
.
service
.
course
.
lbs
.
getLBSDistance
(
'walking'
,
{
lat
,
lng
},
lbs_array
);
if
(
!
walking_results
.
results
&&
!
driving_results
.
results
)
{
return
[];
}
//格式化 判断步行或驾车
const
results
=
[];
for
(
let
i
in
lbs_array
)
{
let
lbs
=
lbs_array
[
i
];
const
driving
=
(
drivings
[
i
]
&&
drivings
[
i
].
distance
!==
-
1
)
?
drivings
[
i
]
:
{
distance
:
0
,
duration
:
0
};
const
walking
=
(
walkings
[
i
]
&&
walkings
[
i
].
distance
!==
-
1
)
?
walkings
[
i
]
:
{
distance
:
0
,
duration
:
0
};
const
lbs_distance
=
driving
.
distance
>
distance
?
driving
:
walking
;
const
travel_method
=
driving
.
distance
>
distance
?
'driving'
:
'walking'
;
results
.
push
({
lat
:
lbs
.
lat
,
lng
:
lbs
.
lng
,
distance
:
lbs_distance
.
distance
,
duration
:
lbs_distance
.
duration
,
travel_method
,
});
}
// 处理距离结果
const
drivings
=
driving_results
.
results
.
map
(
item
=>
{
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
1
);
const
duration
=
Math
.
ceil
(
item
.
duration
/
60
);
return
{
distance
,
duration
};
});
const
walkings
=
walking_results
.
results
.
map
(
item
=>
{
const
distance
=
(
item
.
distance
/
1000
).
toFixed
(
2
);
const
duration
=
Math
.
ceil
(
item
.
distance
/
80
);
return
{
distance
,
duration
};
});
// 格式化 判断步行或驾车
const
results
=
[];
for
(
const
i
in
lbs_array
)
{
const
lbs
=
lbs_array
[
i
];
const
driving
=
(
drivings
[
i
]
&&
drivings
[
i
].
distance
!==
-
1
)
?
drivings
[
i
]
:
{
distance
:
0
,
duration
:
0
};
const
walking
=
(
walkings
[
i
]
&&
walkings
[
i
].
distance
!==
-
1
)
?
walkings
[
i
]
:
{
distance
:
0
,
duration
:
0
};
const
lbs_distance
=
driving
.
distance
>
distance
?
driving
:
walking
;
const
travel_method
=
driving
.
distance
>
distance
?
'driving'
:
'walking'
;
results
.
push
({
lat
:
lbs
.
lat
,
lng
:
lbs
.
lng
,
distance
:
lbs_distance
.
distance
,
duration
:
lbs_distance
.
duration
,
travel_method
,
});
}
return
results
;
return
results
;
}
}
/**
*
/**
*
* @param {*} institution_areas 校区列表
* @param {*} areas_list 校区距离列表
*/
async
findShortestDistanceAreas
(
institution_areas
,
areas_list
)
{
const
{
ctx
}
=
this
;
let
ret
=
[];
// const institution_lbs = await this.computeDistance(areas_list);
const
institution_lbs
=
areas_list
;
for
(
let
i
in
institution_areas
)
{
let
institution_area
=
institution_areas
[
i
];
//TODO 校验经纬度
const
lbs
=
i
<
institution_lbs
.
length
?
institution_lbs
[
i
]
:
{
distance
:
0
,
duration
:
0
,
travel_method
:
''
};
const
area_name
=
institution_area
.
area_name
;
const
distance
=
lbs
.
distance
;
const
duration
=
lbs
.
duration
;
let
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,开车
${
duration
}
分钟`
;
if
(
lbs
.
travel_method
===
'walking'
)
{
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,步行
${
duration
}
分钟`
;
}
if
(
distance
===
0
&&
duration
===
0
)
{
travel_tips
=
'暂无法计算出距离'
;
}
// area.distance = distance;
// area.duration = duration;
// area.travel_tips = travel_tips;
institution_area
.
distance
=
distance
;
institution_area
.
duration
=
duration
;
institution_area
.
travel_tips
=
travel_tips
;
ret
[
i
]
=
institution_area
;
}
const
results
=
[];
ret
=
_
.
orderBy
(
ret
,
[
'distance'
],
[
'asc'
]);
for
(
let
j
in
ret
)
{
const
val
=
ret
[
j
];
if
(
!
results
[
val
.
id
])
{
results
[
val
.
id
]
=
val
;
}
}
return
results
;
async
findShortestDistanceAreas
(
institution_areas
,
areas_list
)
{
const
{
ctx
}
=
this
;
let
ret
=
[];
// const institution_lbs = await this.computeDistance(areas_list);
const
institution_lbs
=
areas_list
;
for
(
const
i
in
institution_areas
)
{
const
institution_area
=
institution_areas
[
i
];
// TODO 校验经纬度
const
lbs
=
i
<
institution_lbs
.
length
?
institution_lbs
[
i
]
:
{
distance
:
0
,
duration
:
0
,
travel_method
:
''
};
const
area_name
=
institution_area
.
area_name
;
const
distance
=
lbs
.
distance
;
const
duration
=
lbs
.
duration
;
let
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,开车
${
duration
}
分钟`
;
if
(
lbs
.
travel_method
===
'walking'
)
{
travel_tips
=
`
${
area_name
}
,距我
${
distance
}
km,步行
${
duration
}
分钟`
;
}
if
(
Number
(
distance
)
===
0
&&
Number
(
duration
)
===
0
)
{
travel_tips
=
'暂无法计算出距离'
;
}
// area.distance = distance;
// area.duration = duration;
// area.travel_tips = travel_tips;
institution_area
.
distance
=
Number
(
distance
)
===
0
?
999999999.0
:
parseFloat
(
distance
);
institution_area
.
duration
=
duration
;
institution_area
.
travel_tips
=
travel_tips
;
ret
[
i
]
=
institution_area
;
}
async
formatInstitutions
(
institutions
)
{
const
{
ctx
}
=
this
;
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
return
[];
}
//处理机构图片
const
p_institution_images
=
[];
for
(
let
j
in
institutions
)
{
const
institution
=
institutions
[
j
];
p_institution_images
[
j
]
=
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
1
,
type_id
:
institution
.
id
,
is_cover
:
1
,
is_video
:
0
}
});
}
const
institution_images
=
await
Promise
.
all
(
p_institution_images
).
then
(
result
=>
{
//等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
const
ret
=
[];
for
(
let
i
in
institutions
)
{
const
institution
=
institutions
[
i
];
// const course_areas = institution.course_areas;
// if (!course_areas || course_areas.length === 0) continue;
const
age_tag
=
institution
.
min_age
+
'-'
+
institution
.
max_age
+
'岁'
;
const
build_time
=
moment
().
format
(
'YYYY'
)
-
institution
.
establishment_time
;
const
tags
=
[];
if
(
institution
.
max_age
)
{
tags
.
push
(
age_tag
);
}
if
(
institution
.
class_type
)
{
tags
.
push
(
institution
.
class_type
);
}
if
(
Number
(
institution
.
establishment_time
))
{
tags
.
push
(
'成立'
+
build_time
+
'年'
);
}
const
image
=
institution_images
[
i
]
?
institution_images
[
i
].
image_url
:
''
;
ret
.
push
({
id
:
institution
.
id
,
name
:
institution
.
name
,
image
,
establishment_time
:
institution
.
establishment_time
,
class_type
:
institution
.
class_type
,
teacher_count
:
institution
.
teacher_count
?
institution
.
teacher_count
:
0
,
teacher_experience
:
institution
.
teacher_experience
?
institution
.
teacher_experience
:
0
,
corner
:
institution
.
corner
?
institution
.
corner
:
''
,
min_age
:
institution
.
min_age
,
max_age
:
institution
.
max_age
,
price
:
institution
.
price
?
institution
.
price
:
0
,
tags
,
area_id
:
institution
.
area_id
,
//校区id TODO
travel_tips
:
institution
.
travel_tips
,
//TODO
characteristic
:
institution
.
characteristic
?
institution
.
characteristic
:
''
,
});
}
return
ret
;
const
results
=
[];
ret
=
_
.
orderBy
(
ret
,
[
'distance'
],
[
'asc'
]);
for
(
const
j
in
ret
)
{
const
val
=
ret
[
j
];
if
(
!
results
[
val
.
id
])
{
results
[
val
.
id
]
=
val
;
}
}
return
results
;
}
async
formatInstitutions
(
institutions
)
{
const
{
ctx
}
=
this
;
if
(
!
Array
.
isArray
(
institutions
)
||
institutions
.
length
===
0
)
{
return
[];
}
// 处理机构图片
const
p_institution_images
=
[];
for
(
const
j
in
institutions
)
{
const
institution
=
institutions
[
j
];
p_institution_images
[
j
]
=
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
1
,
type_id
:
institution
.
id
,
is_cover
:
1
,
is_video
:
0
}
});
}
const
institution_images
=
await
Promise
.
all
(
p_institution_images
).
then
(
result
=>
{
// 等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
let
ret
=
[];
for
(
const
i
in
institutions
)
{
const
institution
=
institutions
[
i
];
// const course_areas = institution.course_areas;
// if (!course_areas || course_areas.length === 0) continue;
const
age_tag
=
institution
.
min_age
+
'-'
+
institution
.
max_age
+
'岁'
;
const
build_time
=
moment
().
format
(
'YYYY'
)
-
institution
.
establishment_time
;
const
tags
=
[];
if
(
institution
.
max_age
)
{
tags
.
push
(
age_tag
);
}
if
(
institution
.
class_type
)
{
tags
.
push
(
institution
.
class_type
);
}
if
(
Number
(
institution
.
establishment_time
))
{
tags
.
push
(
'成立'
+
build_time
+
'年'
);
}
let
image
=
institution_images
[
i
]
?
institution_images
[
i
].
image_url
:
''
;
// 取不到封面图就从详情图列表里选一张
if
(
ctx
.
isEmpty
(
image
))
{
const
tmpImage
=
await
ctx
.
classModel
.
CourseImages
.
one
({
where
:
{
type
:
1
,
type_id
:
institution
.
id
,
is_cover
:
0
,
is_video
:
0
}
});
image
=
ctx
.
isEmpty
(
tmpImage
)
?
''
:
tmpImage
.
image_url
;
}
ret
.
push
({
id
:
institution
.
id
,
name
:
institution
.
name
,
image
,
establishment_time
:
institution
.
establishment_time
,
class_type
:
institution
.
class_type
,
teacher_count
:
institution
.
teacher_count
?
institution
.
teacher_count
:
0
,
teacher_experience
:
institution
.
teacher_experience
?
institution
.
teacher_experience
:
0
,
corner
:
institution
.
corner
?
institution
.
corner
:
''
,
min_age
:
institution
.
min_age
,
max_age
:
institution
.
max_age
,
price
:
institution
.
price
?
institution
.
price
:
0
,
tags
,
area_id
:
institution
.
area_id
,
// 校区id TODO
travel_tips
:
institution
.
travel_tips
,
// TODO
characteristic
:
institution
.
characteristic
?
institution
.
characteristic
:
''
,
distance
:
institution
.
distance
,
});
}
ret
=
_
.
orderBy
(
ret
,
[
'distance'
],
[
'asc'
]);
return
ret
;
}
}
...
...
app/service/course/option.js
View file @
730aa56a
...
...
@@ -4,66 +4,66 @@
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
},
{
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
INSTITUTION_TYPE
=
[
{
id
:
-
14
,
name
:
'全部'
,
value
:
''
},
{
id
:
-
15
,
name
:
'品牌'
,
value
:
'品牌'
},
{
id
:
-
14
,
name
:
'全部'
,
value
:
''
},
{
id
:
-
15
,
name
:
'品牌'
,
value
:
'品牌'
},
];
class
OptionService
extends
Service
{
/**
/**
* 我的信用首页
*/
async
getOptions
()
{
async
getOptions
()
{
const
{
ctx
}
=
this
;
const
cats
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
status
:
1
,
is_deleted
:
0
}
});
const
tree_cats
=
this
.
getTrees
(
cats
,
0
);
const
{
ctx
}
=
this
;
const
cats
=
await
ctx
.
classModel
.
CourseCat
.
all
({
where
:
{
status
:
1
,
is_deleted
:
0
}
});
const
tree_cats
=
this
.
getTrees
(
cats
,
0
);
const
options
=
{
cats
:
tree_cats
,
ages
:
AGE_CATS
,
institutions
:
INSTITUTION_TYPE
,
}
return
options
;
}
const
options
=
{
cats
:
tree_cats
,
ages
:
AGE_CATS
,
institutions
:
INSTITUTION_TYPE
,
};
return
options
;
}
getTrees
(
data
,
rootId
)
{
const
ret
=
[];
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
node
=
data
[
i
];
if
(
node
.
parent_id
==
rootId
)
{
const
newNode
=
{};
// if (node.parent_id == 0) newNode._child.push({ id: 0, name: '全部', value: '' });
newNode
.
id
=
node
.
id
;
newNode
.
name
=
node
.
name
;
newNode
.
tips
=
node
.
tips
;
newNode
.
image
=
node
.
image
;
newNode
.
color
=
node
.
color
;
newNode
.
level
=
node
.
level
;
newNode
.
value
=
node
.
id
;
newNode
.
_child
=
this
.
getTrees
(
data
,
node
.
id
);
if
(
newNode
.
_child
.
length
!==
0
)
newNode
.
_child
.
unshift
({
id
:
0
,
name
:
'全部'
,
value
:
0
});
ret
.
push
(
newNode
);
}
}
return
ret
;
getTrees
(
data
,
rootId
)
{
const
ret
=
[];
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
const
node
=
data
[
i
];
if
(
node
.
parent_id
==
rootId
)
{
const
newNode
=
{};
// if (node.parent_id == 0) newNode._child.push({ id: 0, name: '全部', value: '' });
newNode
.
id
=
node
.
id
;
newNode
.
name
=
node
.
name
;
newNode
.
tips
=
node
.
tips
;
newNode
.
image
=
node
.
image
;
newNode
.
color
=
node
.
color
;
newNode
.
level
=
node
.
level
;
newNode
.
value
=
node
.
id
;
newNode
.
_child
=
this
.
getTrees
(
data
,
node
.
id
);
if
(
newNode
.
_child
.
length
!==
0
)
newNode
.
_child
.
unshift
({
id
:
0
,
name
:
'全部'
,
value
:
node
.
id
});
ret
.
push
(
newNode
);
}
}
return
ret
;
}
}
...
...
app/service/credit/apply.js
View file @
730aa56a
...
...
@@ -58,20 +58,29 @@ class ApplyService extends Service {
return
ret
;
}
/**
* 进入个人通话查询页面
*/
async
callriskInit
()
{
const
{
ctx
}
=
this
;
if
(
!
ctx
.
userId
)
{
ctx
.
failed
(
'登录异常'
);
}
let
ret
=
{
have_be_pay_order
:
false
,
order_id
:
null
,
phone
:
''
,
placeholder
:
{
name
:
''
,
id_card
:
''
id_card
:
''
,
}
}
let
bePayOrder
=
await
ctx
.
service
.
credit
.
order
.
getBePayOrder
(
'callrisk'
);
if
(
bePayOrder
.
length
!==
0
)
{
ret
.
have_be_pay_order
=
true
;
ret
.
order_id
=
bePayOrder
[
0
].
id
;
ret
.
phone
=
bePayOrder
[
0
].
phone
.
substring
(
0
,
3
)
+
'****'
+
bePayOrder
[
0
].
phone
.
substring
(
7
,
11
)
}
//第一次查询成功的订单,反显姓名和身份证
...
...
@@ -330,7 +339,7 @@ class ApplyService extends Service {
async
applyCallrisk
(
input
)
{
const
{
ctx
}
=
this
;
const
{
name
,
phone
,
id_card
,
password
}
=
input
;
const
{
name
,
phone
,
id_card
,
password
,
net
}
=
input
;
const
user_id
=
ctx
.
userId
;
const
app_type_id
=
ctx
.
appTypeId
;
const
app_user_id
=
ctx
.
appUserId
;
...
...
@@ -353,7 +362,7 @@ class ApplyService extends Service {
const
order_id
=
order
.
id
;
//创建yys-order apply 记录
const
apply
=
await
this
.
createYysApply
({
name
,
phone
,
id_card
,
password
,
order_id
});
const
apply
=
await
this
.
createYysApply
({
name
,
phone
,
id_card
,
password
,
net
,
order_id
});
const
order_sn
=
apply
.
r_order_id
;
//第一次调用运营商获取验证码接口
...
...
@@ -392,10 +401,10 @@ class ApplyService extends Service {
const
app_type_id
=
ctx
.
appTypeId
;
const
app_user_id
=
ctx
.
appUserId
;
const
app_id
=
ctx
.
appId
;
const
{
name
,
phone
,
id_card
,
password
,
order_id
}
=
input
;
const
{
name
,
phone
,
id_card
,
password
,
net
,
order_id
}
=
input
;
//运营商API.创建订单号
const
order_sn_info
=
await
ctx
.
service
.
credit
.
yys
.
getOrderSn
(
phone
);
const
order_sn_info
=
await
ctx
.
service
.
credit
.
yys
.
getOrderSn
(
{
phone
,
net
}
);
if
(
order_sn_info
.
code
!==
0
)
{
ctx
.
failed
(
'getOrderSn error msg:'
+
order_sn_info
.
msg
);
}
...
...
@@ -430,14 +439,14 @@ class ApplyService extends Service {
let
orderFilter
=
{
arrtibutes
:
[
'id'
,
'name'
,
'id_card'
],
where
:
{
user_id
:
ctx
.
userI
d
,
user_id
:
user_i
d
,
state
:
'已支付'
,
type
:
2
,
type
:
type
,
valid
:
1
}
}
let
orderInfo
=
await
ctx
.
prometheusModel
.
CreditOrder
.
findOne
(
orderFilter
);
if
(
orderInfo
!==
null
&&
(
inputParams
.
name
!==
orderInfo
.
name
||
inputParams
.
id_card
!==
orderInfo
.
id_card
))
{
if
(
orderInfo
!==
null
&&
(
name
!==
orderInfo
.
name
||
id_card
!==
orderInfo
.
id_card
))
{
ctx
.
failed
(
'仅供本人查询使用,无法查询其他人信息'
);
}
...
...
app/service/credit/callrisk.js
View file @
730aa56a
...
...
@@ -82,7 +82,7 @@ class CallriskService extends Service {
//订单是否在有效期内
const
report_valid
=
await
ctx
.
service
.
credit
.
order
.
getReportValid
(
'callrisk'
,
report_id
);
cons
t
report
=
{
le
t
report
=
{
basics
:
{
data
:
basics
},
call_overview
:
{
data
:
call_overview
},
call_type
:
{
data
:
call_type
},
...
...
@@ -90,6 +90,7 @@ class CallriskService extends Service {
call_behavior
:
{
data
:
call_behavior
},
report_valid
,
};
report
.
basics
.
data
.
call_result_assessment
=
await
this
.
getEvaluationLevel
(
report
);
const
ret
=
this
.
formatHeadExplainMsg
(
report
);
...
...
@@ -138,9 +139,30 @@ class CallriskService extends Service {
const
{
ctx
}
=
this
;
const
call_behavior
=
await
ctx
.
prometheusModel
.
CreditCallriskCallBehavior
.
one
({
where
:
{
report_id
}
});
const
call_behavior_silence_cycles
=
await
ctx
.
prometheusModel
.
CreditCallriskSilenceCycle
.
all
({
where
:
{
report_id
}
});
call_behavior
.
silence_cycle
=
call_behavior
?
[]
:
call_behavior_silence_cycles
;
const
ret
=
{
silence_count_3day
:
call_behavior
.
silence_count_3day
,
silence_time_3day
:
call_behavior
.
silence_time_3day
,
silence_time_rate_3day
:
call_behavior
.
silence_time_rate_3day
,
silence_cycle
:
call_behavior_silence_cycles
,
call_each_other
:
{
active_call_count
:
call_behavior
.
active_call_count
,
passive_call_count
:
call_behavior
.
passive_call_count
,
each_call_count
:
call_behavior
.
each_call_count
,
},
call_rank
:
{
maximum_active_call_count
:
call_behavior
.
maximum_active_call_count
,
maximum_active_call_number
:
call_behavior
.
maximum_active_call_number
,
maximum_active_call_city
:
call_behavior
.
maximum_active_call_city
,
maximum_passive_call_count
:
call_behavior
.
maximum_passive_call_count
,
maximum_passive_call_number
:
call_behavior
.
maximum_passive_call_number
,
maximum_passive_call_city
:
call_behavior
.
maximum_passive_call_city
,
maximum_call_time
:
call_behavior
.
maximum_call_time
,
maximum_call_time_number
:
call_behavior
.
maximum_call_time_number
,
maximum_call_time_city
:
call_behavior
.
maximum_call_time_city
,
},
};
return
call_behavior
;
return
ret
;
}
async
formatReport
()
{
...
...
@@ -338,8 +360,8 @@ class CallriskService extends Service {
const
{
ctx
}
=
this
;
const
basics
=
report
.
basics
.
data
;
const
call_overview
=
report
.
call_overview
.
data
;
//
const call_type = report.call_type.data;
//
const call_active = report.call_active.data;
const
call_type
=
report
.
call_type
.
data
;
const
call_active
=
report
.
call_active
.
data
;
const
call_behavior
=
report
.
call_behavior
.
data
;
//入网时长分数计算
...
...
@@ -357,11 +379,11 @@ class CallriskService extends Service {
//话费分数计算
let
month_fee_sum
=
0
;
for
(
let
i
in
call_overview
.
data
)
{
const
month_call_overview
=
call_overview
.
data
[
i
];
for
(
let
i
in
call_overview
)
{
const
month_call_overview
=
call_overview
[
i
];
month_fee_sum
+=
month_call_overview
.
call_fee_month
;
}
const
fee_avg
=
month_fee_sum
/
call_overview
.
data
.
length
;
//平均月话费
const
fee_avg
=
month_fee_sum
/
call_overview
.
length
;
//平均月话费
let
fee_avg_score
=
0
;
if
(
fee_avg
<
20
)
{
fee_avg_score
=
20
;
...
...
@@ -370,6 +392,12 @@ class CallriskService extends Service {
}
//通话类型分数计算
const
loan_call_count
=
call_type
.
loan_call_count
;
const
bank_call_count
=
call_type
.
bank_call_count
;
const
court_call_count
=
call_type
.
court_call_count
;
const
collection_call_count
=
call_type
.
collection_call_count
;
const
laywer_call_count
=
call_type
.
laywer_call_count
;
const
macao_call_count
=
call_type
.
macao_call_count
;
let
call_type_score
=
0
;
if
(
loan_call_count
>=
1
)
{
call_type_score
+=
7
;
...
...
@@ -391,8 +419,8 @@ class CallriskService extends Service {
}
//通话活跃分数计算
const
call_time_percent
=
night_call_time
/
routine_call_time
;
const
call_count_percent
=
night_call_count
/
routine_call_count
;
const
call_time_percent
=
call_active
.
night_call_time
/
call_active
.
routine_call_time
;
const
call_count_percent
=
call_active
.
night_call_count
/
call_active
.
routine_call_count
;
let
call_time_score
=
0
;
let
call_count_score
=
0
;
if
(
call_time_percent
>=
0.2
)
{
...
...
@@ -426,6 +454,7 @@ class CallriskService extends Service {
call_behavior_socre
=
10
;
}
console
.
info
(
net_time_score
,
fee_avg_score
,
call_type_score
,
call_active_score
,
call_behavior_socre
);
const
sum_score
=
net_time_score
+
fee_avg_score
+
call_type_score
+
call_active_score
+
call_behavior_socre
;
let
call_result_assessment
=
'优质'
;
...
...
app/service/credit/yys.js
View file @
730aa56a
...
...
@@ -12,13 +12,14 @@ class YysService extends Service {
* 创建订单号
* @param {*}
*/
async
getOrderSn
(
phone
)
{
async
getOrderSn
(
{
phone
,
net
}
)
{
const
{
ctx
}
=
this
;
let
params
=
{
phone
:
phone
phone
:
phone
,
net
:
Number
(
net
),
}
let
url
=
this
.
config
.
NODE_BASE_URL
+
'/yys_api/getorderSn'
+
'?appKey='
+
this
.
config
.
YYS_APP_KEY
;
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
timeout
:
30000
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
yys_getorderSn_params
:
params
,
yys_getorderSn_result
:
resp
}));
if
(
resp
.
data
.
code
===
undefined
||
resp
.
data
.
code
!==
0
)
{
ctx
.
failed
(
'getorderSn error:'
+
resp
.
data
.
msg
);
...
...
@@ -43,7 +44,7 @@ class YysService extends Service {
// }
// }
let
url
=
this
.
config
.
NODE_BASE_URL
+
'/yys_api/getCode'
+
'?appKey='
+
this
.
config
.
YYS_APP_KEY
;
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
timeout
:
30000
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
yys_getCode_params
:
params
,
yys_getCode_result
:
resp
}));
await
this
.
addCreditLogYys
(
params
.
orderSn
,
'/yys_api/getCode'
,
params
,
resp
.
data
);
// console.info(resp);
...
...
@@ -65,7 +66,7 @@ class YysService extends Service {
// }
// }
const
url
=
this
.
config
.
NODE_BASE_URL
+
'/yys_api/commit'
+
'?appKey='
+
this
.
config
.
YYS_APP_KEY
;
const
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
const
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
timeout
:
30000
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
yys_commit_params
:
params
,
yys_commit_result
:
resp
}));
await
this
.
addCreditLogYys
(
params
.
orderSn
,
'/yys_api/commit'
,
params
,
resp
.
data
);
return
resp
.
data
;
...
...
@@ -81,7 +82,7 @@ class YysService extends Service {
orderSn
:
orderSn
,
}
let
url
=
this
.
config
.
NODE_BASE_URL
+
'/yys_api/query'
+
'?appKey='
+
this
.
config
.
YYS_APP_KEY
;
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
let
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
timeout
:
30000
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
yys_query_params
:
params
,
yys_query_result
:
resp
}));
await
this
.
addCreditLogYys
(
orderSn
,
'/yys_api/query'
,
params
,
resp
.
data
);
return
resp
.
data
;
...
...
@@ -106,7 +107,7 @@ class YysService extends Service {
}
params
.
sign
=
await
ctx
.
service
.
credit
.
common
.
sign
(
params
.
signParams
,
this
.
config
.
YYS_REPORT_APPSECRET
);
const
url
=
this
.
config
.
YYS_REPORT_URL
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
,
timeout
:
30000
});
ctx
.
logger
.
info
(
JSON
.
stringify
({
thxdReport_parmas
:
params
,
thxdReport_result
:
result
}));
return
result
.
data
;
...
...
config/config.local.js
View file @
730aa56a
...
...
@@ -103,7 +103,7 @@ module.exports = appInfo => {
// other sequelize configurations
dialect
:
'mysql'
,
host
:
'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com'
,
database
:
'class_
dev
'
,
database
:
'class_
uat
'
,
username
:
'class_testing'
,
password
:
'WV862L32451I6KD58tU9K'
,
port
:
3306
,
...
...
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