Commit 8e5a1516 authored by 何娜's avatar 何娜

taxh5 限制appkey上限

parent 71d11922
Pipeline #7165 passed with stage
in 2 seconds
......@@ -46,9 +46,9 @@ class OrderController extends Controller {
}
async create() {
const { ctx, service } = this;
const {ctx, service} = this;
ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, redirectUrl, orderId } = ctx.request.body;
let {appKey, userId, notifyUrl, redirectUrl, orderId} = ctx.request.body;
ctx.logger.info('【orders】 appKey', appKey);
const appKeyInfo = await service.partner.fetchInfo(appKey);
ctx.logger.info(appKey, ',appKeyInfo,', appKeyInfo);
......@@ -69,13 +69,13 @@ class OrderController extends Controller {
await service.order.update(object);
} else {
if (!userId) {
ctx.throw(422, { message: '请输入userId' });
ctx.throw(422, {message: '请输入userId'});
return;
}
}
object.orderId = ctx.helper.getUuid();
await service.order.create(object);
}
ctx.success({ orderId: object.orderId });
ctx.success({orderId: object.orderId});
}
async partnerOrder() {
......@@ -107,20 +107,21 @@ class OrderController extends Controller {
}
}
const sign = await service.signature.signatureCheck(ctx.request.body);
if(sign.code != 0){
if (sign.code != 0) {
return ctx.body = {
code: -1,
mag: sign.msg
}
}
const data = await service.order.getOneByOrderId({ orderId, status: 'success' });
const data = await service.order.getOneByOrderId({orderId, status: 'success'});
if (data) {
const result = await service.storage.read(orderId, appKey);
ctx.body = {
code: 0,
data: result
};
return;
await service.partner.appKeyLimit(appKey);
const result = await service.storage.read(orderId, appKey);
ctx.body = {
code: 0,
data: result
};
return;
}
ctx.body = {
code: -1,
......@@ -129,13 +130,13 @@ class OrderController extends Controller {
}
async orderShow() {
const { ctx, service } = this;
const { appKey, orderId } = ctx.params;
const {ctx, service} = this;
const {appKey, orderId} = ctx.params;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableItView === true)) {
return ctx.fail('未开通此服务');
}
const data = await service.order.getOneByOrderId({orderId, status: 'success' });
const data = await service.order.getOneByOrderId({orderId, status: 'success'});
if (data) {
if (data.status === 'success' && (data.appkey === appKey)) {
const result = await service.storage.read(orderId, appKey);
......
......@@ -24,8 +24,8 @@ module.exports = {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
}
});
ctx.app.notifyMap = notifyMap;
}
ctx.app.notifyMap = notifyMap;
} catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
}
......
......@@ -156,6 +156,50 @@ class PartnerService extends Service {
ctx.logger.info('【Partner】 notice no send', 'orderId:', orderId);
}
}
async appKeyLimit(appKey) {
const { ctx, partnerAPI: { redisappKeyLimitPrefix } } = this;
let data = await this.app.redis.get(redisappKeyLimitPrefix);
data = JSON.parse(data);
if (data) {
if (data.includes(appKey)) {
let limit = await this.app.redis.get(redisappKeyLimitPrefix + appKey);
if (limit) {
limit = JSON.parse(limit);
if (limit.currentCount >= limit.limitCount) {
ctx.throw(422, { message: 'appKey查询数量超过限制,请联系技术人员' });
} else {
// limit.currentCount++;
// await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount: limit.currentCount, limitCount: limit.limitCount }), 'EX', 300);
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
} else {
const dbRes = await ctx.model.NodeLimit.findAll({
attributes: ['appKey', 'currentCount', 'limitCount'],
where: { type: 'gjj' },
});
if (dbRes) {
const appKeyArray = [];
for (const item of dbRes) {
const { appKey, currentCount, limitCount } = item;
appKeyArray.push(appKey);
await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount, limitCount }), 'EX', 300);
}
await this.app.redis.set(redisappKeyLimitPrefix, JSON.stringify(appKeyArray), 'EX', 300);
if (appKeyArray.includes(appKey)) {
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
}
}
module.exports = PartnerService;
......@@ -34,6 +34,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
};
config.scriptsAPI = {
......
......@@ -37,6 +37,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
};
config.scriptsAPI = {
......
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