Commit 87c4a9fd authored by 李尚科's avatar 李尚科

fix

parent 1e89629d
Pipeline #13845 passed with stage
in 35 seconds
'use strict';
const Controller = require('egg').Controller;
class InstitutionController extends Controller {
/**
* 机构列表
*/
async list() {
const { ctx } = this;
let ret = await ctx.service.credit.home.home();
ctx.success(ret);
}
}
module.exports = InstitutionController;
'use strict';
const Controller = require('egg').Controller;
class OptionController extends Controller {
/**
* 筛选项
*/
async getOptions() {
const { ctx } = this;
const results = await ctx.service.course.option.getOptions();
ctx.success({ results });
}
}
module.exports = OptionController;
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseCat = app.prometheusModel.define('course_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
first_id: INTEGER,
parent_id: INTEGER,
level: INTEGER,
name: STRING,
tips: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_cat',
});
CourseCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseCat.findOne({
attributes: attributes,
where: where,
});
}
CourseCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseCat.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await CourseCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseCat;
};
\ No newline at end of file
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseInstitutionToCat = app.prometheusModel.define('course_institution_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
cat_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_institution_to_cat',
});
CourseInstitutionToCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseInstitutionToCat.findOne({
attributes: attributes,
where: where,
});
}
CourseInstitutionToCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseInstitutionToCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseInstitutionToCat.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await CourseInstitutionToCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseInstitutionToCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseInstitutionToCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseInstitutionToCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseInstitutionToCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseInstitutionToCat;
};
\ No newline at end of file
......@@ -4,7 +4,7 @@ module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course');
const loginAuth = app.middleware.loginAuth({ type: 'new' });//登录中间件
// router.get('/history/:type', 'credit.order.getRecord');
router.get('/option', 'course.option.getOptions');
};
'use strict';
const Service = require('egg').Service;
class InstitutionService extends Service {
/**
* 我的信用首页
*/
async home() {
}
}
module.exports = InstitutionService;
'use strict';
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 INSTITUTION_TYPE = [
{ id: -14, name: '全部', value: '' },
{ id: -15, name: '品牌', value: '品牌' },
];
class OptionService extends Service {
/**
* 我的信用首页
*/
async getOptions() {
const { ctx } = this;
const cats = await ctx.prometheusModel.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;
}
getTrees(data, rootId) {
const ret = [];
for (let i = 0; i < data.length; i++) {
const node = data[i];
if (node.parent_id == rootId) {
const newNode = {};
ret.push({ id: 0, name: '全部', value: '' });
newNode.id = node.id;
newNode.name = node.name;
newNode.tips = node.tips;
newNode.level = node.level;
newNode.value = node.id;
newNode._child = this.getTrees(data, node.id);
ret.push(newNode);
}
}
return ret;
}
}
module.exports = OptionService;
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