Commit b37f03a9 authored by 何娜's avatar 何娜

学信 注册

parent e8520821
Pipeline #7726 passed with stage
in 3 seconds
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const { appKey } = ctx.request.body;
// 可以在这里增加验签的功能;
if (appKey && ctx.app.appKeyArr.includes(appKey)) {
await next();
} else {
ctx.throw(400, '无效的appKey');
}
};
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const Register = app.model.define('register', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
orderId: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: '',
primaryKey: true,
field: 'orderId',
},
taskId: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: '',
field: 'taskId',
},
appkey: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'appKey',
},
status: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'status',
},
note: {
type: DataTypes.STRING(8000),
allowNull: true,
defaultValue: '',
field: 'note',
get() {
const note = this.getDataValue('note');
if (note) {
try {
return JSON.parse(note);
} catch (error) {
return {};
}
}
return {};
},
set(val) {
this.setDataValue('note', JSON.stringify(val));
},
},
created_at: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'createDate',
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'updateDate',
},
text1: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text2',
},
text3: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text3',
},
}, {
tableName: 'xuexin_register_status',
// timestamps: false,
});
return Register;
};
'use strict';
const Service = require('egg').Service;
class OrderService extends Service {
async getOneByOrderId(orderId) {
const { ctx } = this;
const order = await ctx.model.Register.findOne({
where: { orderId },
});
return order;
}
async getOneByTaskId(taskId) {
const { ctx } = this;
const order = await ctx.model.Register.findOne({
where: { taskId },
});
return order;
}
async create(params) {
const { ctx } = this;
const order = await ctx.model.Register.findOne({
where: { orderId: params.orderId },
});
if (order) {
ctx.throw(400, { message: 'already have order' });
}
await ctx.model.Register.create(params);
return order;
}
async update(params) {
const { ctx } = this;
const order = await ctx.model.Register.findAll({
where: { orderId: params.orderId },
order: [['createDate', 'DESC']],
});
if (order.length === 0) {
ctx.throw(400, { message: 'no order' });
return;
}
for (const item of order) {
if (item.status === 'success') {
ctx.throw(400, { message: 'orderId success' });
return;
}
}
const { appKey, taskId, notifyUrl, backUrl, userId } = order[0];
if (taskId) {
await ctx.model.Register.create({ appKey, status: 'init', notifyUrl, backUrl, userId, ...params })
} else {
await order[0].update(params);
}
return order[0];
}
}
module.exports = OrderService;
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