Commit 32c95433 authored by 姜登's avatar 姜登

gjj

parent 396d21dc
Pipeline #4049 passed with stage
in 5 seconds
......@@ -7,7 +7,10 @@ class OrderController extends Controller {
super(ctx);
this.createRule = {
appKey: 'string',
userId: 'string',
userId: {
type: 'string',
required: false,
},
orderId: {
type: 'string',
required: false,
......@@ -48,10 +51,10 @@ class OrderController extends Controller {
ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, backUrl, orderId } = ctx.request.body;
orderId = orderId || uuid.v1();
await service.order.create({
await service.order.update({
orderId,
taskId: '',
userId: userId,
userId: userId || '',
cityId: '',
notifyUrl: notifyUrl || (ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl: backUrl || '',
......
......@@ -40,9 +40,9 @@ class TaskController extends Controller {
async create() {
const { ctx, service } = this;
ctx.validate(this.createRule);
const { scriptId, orderId, userId } = ctx.request.body;
const { scriptId, orderId } = ctx.request.body;
const taskId = await service.task.create(scriptId);
await service.order.update({ orderId, cityId: scriptId, taskId, userId });
await service.order.update({ orderId, cityId: scriptId, taskId });
await service.cache.set({
key: taskId,
value: { status: 'init', note: { message: 'init' } },
......
......@@ -34,17 +34,22 @@ class OrderService extends Service {
const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({
where: { orderId: params.orderId },
order: [['updateDate', 'DESC']]
});
if (!order) {
ctx.throw(400, { message: 'no order' });
}
if (params.orderId) {
const success = await ctx.model.TaskStatus.findOne({
where: { orderId: params.orderId, status: 'success' },
});
if (success) {
ctx.throw(400, { message: 'order success' });
}
}
const { appKey, taskId, notifyUrl, backUrl, userId } = order;
if (taskId) {
if (params.userId) {
await ctx.model.TaskStatus.create({ appKey, status: 'init', notifyUrl, backUrl, ...params })
} else {
await ctx.model.TaskStatus.create({ appKey, status: 'init', notifyUrl, backUrl, ...params, userId })
}
await ctx.model.TaskStatus.create({ appKey, status: 'init', notifyUrl, backUrl, userId, ...params })
} else {
await order.update(params);
}
......
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