Commit 4df4e4e4 authored by 任国军's avatar 任国军

add wechat_unlimitedCode & getAllRecommendClass

parent ae23777e
Pipeline #21827 passed with stage
in 12 seconds
...@@ -49,6 +49,14 @@ class ReportController extends Controller { ...@@ -49,6 +49,14 @@ class ReportController extends Controller {
const ret = await service.course.v5.report.getReportList(); const ret = await service.course.v5.report.getReportList();
ctx.success(ret); ctx.success(ret);
} }
// 获取所有报告推荐课程
async getAllReportRecommendClassList() {
const { ctx, service } = this;
const ret = await service.course.v5.report.getAllReportRecommendClassList();
ctx.success(ret);
}
} }
module.exports = ReportController; module.exports = ReportController;
...@@ -61,6 +61,19 @@ class WechatController extends Controller { ...@@ -61,6 +61,19 @@ class WechatController extends Controller {
const ret = await service.course.v5.wechat.getQRCode(params); const ret = await service.course.v5.wechat.getQRCode(params);
ctx.success(ret); ctx.success(ret);
} }
// 获取小程序码
async getUnlimitedCode() {
const { ctx, service } = this;
const params = ctx.request.body;
if (ctx.isEmpty(params) || ctx.isEmpty(params.scene)) {
ctx.failed('scene is empty');
}
const ret = await service.course.v5.wechat.getUnlimitedCode(params);
ctx.success(ret);
}
} }
module.exports = WechatController; module.exports = WechatController;
...@@ -16,6 +16,7 @@ module.exports = app => { ...@@ -16,6 +16,7 @@ module.exports = app => {
router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表 router.get('third', '/banner/all', 'course.v5.option.getBannerList');// 获取banner列表
router.get('third', '/options', 'course.v5.option.getOptions');// 获取配置项 router.get('third', '/options', 'course.v5.option.getOptions');// 获取配置项
router.post('third', '/wechat/qrcode', 'course.v5.wechat.getQRCode');// 获取二维码 router.post('third', '/wechat/qrcode', 'course.v5.wechat.getQRCode');// 获取二维码
router.post('third', '/wechat/unlimited_code', 'course.v5.wechat.getUnlimitedCode');// 获取小程序码
router.get('third', '/feedback/type', 'course.v5.option.getFeedbackTypeList');// 获取反馈分类 router.get('third', '/feedback/type', 'course.v5.option.getFeedbackTypeList');// 获取反馈分类
router.post('third', '/feedback', auth, 'course.v5.option.addFeedback');// 反馈 router.post('third', '/feedback', auth, 'course.v5.option.addFeedback');// 反馈
...@@ -31,6 +32,7 @@ module.exports = app => { ...@@ -31,6 +32,7 @@ module.exports = app => {
router.get('third', '/question/all', 'course.v5.report.getQuestionList');// 获取问题列表 router.get('third', '/question/all', 'course.v5.report.getQuestionList');// 获取问题列表
router.post('third', '/report', auth, 'course.v5.report.generateReport');// 生成报告 router.post('third', '/report', auth, 'course.v5.report.generateReport');// 生成报告
router.get('third', '/report/all', auth, 'course.v5.report.getReportList');// 获取报告列表 router.get('third', '/report/all', auth, 'course.v5.report.getReportList');// 获取报告列表
router.get('third', '/recommend/class/all', auth, 'course.v5.report.getAllReportRecommendClassList');// 获取所有报告推荐课程
router.get('third', '/report/:report_id', auth, 'course.v5.report.getReportById');// 获取报告详情 router.get('third', '/report/:report_id', auth, 'course.v5.report.getReportById');// 获取报告详情
}; };
...@@ -179,7 +179,7 @@ class ReportService extends Service { ...@@ -179,7 +179,7 @@ class ReportService extends Service {
const category = ctx.isEmpty(categoryList[v.cat_id]) ? '' : categoryList[v.cat_id][0].name; const category = ctx.isEmpty(categoryList[v.cat_id]) ? '' : categoryList[v.cat_id][0].name;
results.push({ results.push({
id: v.id, id: v.id,
title: category + '选课报告', title: category,
icon: ctx.isEmpty(categoryList[v.cat_id]) ? '' : categoryList[v.cat_id][0].report_icon, icon: ctx.isEmpty(categoryList[v.cat_id]) ? '' : categoryList[v.cat_id][0].report_icon,
created_time: v.created_time, created_time: v.created_time,
}); });
...@@ -530,6 +530,52 @@ class ReportService extends Service { ...@@ -530,6 +530,52 @@ class ReportService extends Service {
return ret; return ret;
} }
// 获取所有报告推荐课程
async getAllReportRecommendClassList() {
const { ctx } = this;
const userReportList = await ctx.classModel.V5.CourseUserReport.findAll({ where: { user_uuid: ctx.userUuid, status: 1, is_deleted: 0 }, raw: true });
const categoryIds = _.uniq(R.pluck('cat_id', userReportList));
let categoryList = await ctx.classModel.V5.CourseV5Category.findAll({ where: { id: { $in: categoryIds } }, attributes: [ 'id', 'name', 'url' ] });
categoryList = _.groupBy(categoryList, 'id');
const results = [];
const checkIds = [];
for (const v of userReportList) {
if (!checkIds.includes(v.cat_id)) {
results.push({
id: v.id,
category: ctx.isEmpty(categoryList[v.cat_id]) ? {} : categoryList[v.cat_id][0],
answer: v.answer,
});
checkIds.push(v.cat_id);
}
}
const handle = [];
for (const i in results) {
handle.push(this.getRecommendClassListByReport(results[i].answer));
}
const handleResult = await Promise.all(handle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
const ret = [];
for (const i in results) {
ret.push({
id: results[i].id,
category: results[i].category,
recommend_class_list: handleResult[i],
});
}
return { list: ret };
}
} }
module.exports = ReportService; module.exports = ReportService;
...@@ -28,7 +28,8 @@ class UserService extends Service { ...@@ -28,7 +28,8 @@ class UserService extends Service {
let userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { phone, is_deleted: 0 } }); let userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { phone, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) { if (ctx.isEmpty(userInfo)) {
const uuid = uuidV4(); const uuid = uuidV4();
userInfo = await ctx.classModel.V5.CourseUser.findOrCreate({ where: { phone, is_deleted: 0 }, defaults: { uuid, phone } }); await ctx.classModel.V5.CourseUser.findOrCreate({ where: { phone, is_deleted: 0 }, defaults: { uuid, phone } });
userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { phone, is_deleted: 0 } });
} }
// 校验验证码 // 校验验证码
......
...@@ -249,6 +249,47 @@ class WechatService extends Service { ...@@ -249,6 +249,47 @@ class WechatService extends Service {
return { image }; return { image };
} }
// 获取小程序码
async getUnlimitedCode(input) {
const { ctx } = this;
const scene = input.scene || '';
const token = await this.getAccessToken();
const url = `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${token}`;
let params = {
scene,
};
if (!ctx.isEmpty(input.page)) {
params.page = input.page;
}
if (!ctx.isEmpty(input.width)) {
params.width = input.width;
}
if (!ctx.isEmpty(input.auto_color)) {
params.auto_color = input.auto_color;
}
if (!ctx.isEmpty(input.line_color)) {
params.line_color = input.line_color;
}
if (!ctx.isEmpty(input.is_hyaline)) {
params.is_hyaline = input.is_hyaline;
}
params = JSON.stringify(params);
const resp = await ctx.helper.send_request(url, params, { method: 'POST', contentType: 'JSON', dataType: 'BUFFER' });
let 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);
}
image = resp.data.toString('base64');
}
return { image };
}
} }
module.exports = WechatService; module.exports = WechatService;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment