Commit 3837d238 authored by 高诸锋's avatar 高诸锋

fix

parent 250e3412
Pipeline #4070 passed with stage
in 51 seconds
'use strict';
module.exports = app => {
app.beforeStart(async () => {
});
};
...@@ -51,7 +51,7 @@ class OrderController extends Controller { ...@@ -51,7 +51,7 @@ class OrderController extends Controller {
let { orderId } = ctx.request.body; let { orderId } = ctx.request.body;
// const orderId = await service.signature.createOrderId(ctx.request.body); // const orderId = await service.signature.createOrderId(ctx.request.body);
orderId = orderId || ctx.helper.getUuid(); orderId = orderId || ctx.helper.getUuid();
await service.order.update({ const toDbObj = {
orderId, orderId,
taskId: '', taskId: '',
userId: userId || '', userId: userId || '',
...@@ -60,7 +60,12 @@ class OrderController extends Controller { ...@@ -60,7 +60,12 @@ class OrderController extends Controller {
status: 'init', status: 'init',
notifyUrl: notifyUrl || (ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '', notifyUrl: notifyUrl || (ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl, backUrl,
}); };
if (orderId) { // 老的H5
await service.order.update(toDbObj);
} else {
await service.order.create(toDbObj);
}
ctx.success({ orderId }); ctx.success({ orderId });
} }
......
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const { query } = ctx.request;
// 测试appKey限制
const isLimit = await judgeLimit(query);
if (isLimit) {
ctx.body = { code: 107, msg: '测试appKey使用次数到达限制' };
return;
}
await next();
};
};
async function judgeLimit(params) {
const { ctx, app } = this;
const { appKey } = params;
// ctx.logger.info(app.devAppkeyMap.keys());
if (!app.nodeLimitMap.has(appKey)) {
return false;
}
let { currentCount, limitCount, env } = app.devAppkeyMap.get(appKey);
if (env === 'dev' && currentCount >= limitCount) {
return true;
}
currentCount++;
const upObj = {
currentCount,
};
await ctx.model.NodeLimit.update(
upObj,
{ where: { appKey } }
);
return false;
}
'use strict';
module.exports = app => {
return {
schedule: {
interval: '5m', // 5分钟间隔
type: 'all',
immediate: true,
},
// 定时操作node_gjj.node_limit表
async task(ctx) {
const rows = await ctx.nodeGjj.query('SELECT appKey, currentCount, limitCount, text FROM node_limit WHERE type = shebao', { type: 'SELECT' });
const map = new Map();
rows.forEach(item => {
const { currentCount, limitCount, text } = item;
const obj = {
currentCount,
limitCount,
env: text,
};
map.set(item.appKey, obj);
});
ctx.app.modeLimitMap = map;
},
};
};
...@@ -21,14 +21,7 @@ class OrderService extends Service { ...@@ -21,14 +21,7 @@ class OrderService extends Service {
async create(params) { async create(params) {
const { ctx } = this; const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({
where: { orderId: params.orderId },
});
if (order) {
ctx.throw(400, { message: 'already have order' });
}
await ctx.model.TaskStatus.create(params); await ctx.model.TaskStatus.create(params);
return order;
} }
async update(params) { async update(params) {
...@@ -38,8 +31,9 @@ class OrderService extends Service { ...@@ -38,8 +31,9 @@ class OrderService extends Service {
order: [['createDate', 'DESC']], order: [['createDate', 'DESC']],
}); });
// console.log(order); // console.log(order);
if (order.length === 0) { // if (order.length === 0) { // 创建订单号
await ctx.model.TaskStatus.create(params); // await ctx.model.TaskStatus.create(params);
ctx.throw(400, { message: 'no orderId' });
return; return;
} }
for (const item of order) { for (const item of order) {
......
...@@ -100,6 +100,17 @@ module.exports = () => { ...@@ -100,6 +100,17 @@ module.exports = () => {
username: 'hexin', username: 'hexin',
password: 'gYUHszn9#q', password: 'gYUHszn9#q',
port: 3306, port: 3306,
}, {
// 东八时区
timezone: '+08:00',
delegate: 'nodeGjj',
baseDir: 'model',
dialect: 'mysql',
host: 'rm-bp1272001633qc0x9o.mysql.rds.aliyuncs.com',
database: 'nodetest',
username: 'hexin',
password: 'gYUHszn9#q',
port: 3306,
}], }],
}; };
......
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