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 { ...@@ -46,9 +46,9 @@ class OrderController extends Controller {
} }
async create() { async create() {
const { ctx, service } = this; const {ctx, service} = this;
ctx.validate(this.createRule); 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); ctx.logger.info('【orders】 appKey', appKey);
const appKeyInfo = await service.partner.fetchInfo(appKey); const appKeyInfo = await service.partner.fetchInfo(appKey);
ctx.logger.info(appKey, ',appKeyInfo,', appKeyInfo); ctx.logger.info(appKey, ',appKeyInfo,', appKeyInfo);
...@@ -69,13 +69,13 @@ class OrderController extends Controller { ...@@ -69,13 +69,13 @@ class OrderController extends Controller {
await service.order.update(object); await service.order.update(object);
} else { } else {
if (!userId) { if (!userId) {
ctx.throw(422, { message: '请输入userId' }); ctx.throw(422, {message: '请输入userId'});
return; return;
} }
object.orderId = ctx.helper.getUuid(); object.orderId = ctx.helper.getUuid();
await service.order.create(object); await service.order.create(object);
} }
ctx.success({ orderId: object.orderId }); ctx.success({orderId: object.orderId});
} }
async partnerOrder() { async partnerOrder() {
...@@ -107,20 +107,21 @@ class OrderController extends Controller { ...@@ -107,20 +107,21 @@ class OrderController extends Controller {
} }
} }
const sign = await service.signature.signatureCheck(ctx.request.body); const sign = await service.signature.signatureCheck(ctx.request.body);
if(sign.code != 0){ if (sign.code != 0) {
return ctx.body = { return ctx.body = {
code: -1, code: -1,
mag: sign.msg mag: sign.msg
} }
} }
const data = await service.order.getOneByOrderId({ orderId, status: 'success' }); const data = await service.order.getOneByOrderId({orderId, status: 'success'});
if (data) { if (data) {
const result = await service.storage.read(orderId, appKey); await service.partner.appKeyLimit(appKey);
ctx.body = { const result = await service.storage.read(orderId, appKey);
code: 0, ctx.body = {
data: result code: 0,
}; data: result
return; };
return;
} }
ctx.body = { ctx.body = {
code: -1, code: -1,
...@@ -129,13 +130,13 @@ class OrderController extends Controller { ...@@ -129,13 +130,13 @@ class OrderController extends Controller {
} }
async orderShow() { async orderShow() {
const { ctx, service } = this; const {ctx, service} = this;
const { appKey, orderId } = ctx.params; const {appKey, orderId} = ctx.params;
const appKeyInfo = await service.partner.fetchInfo(appKey); const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableItView === true)) { if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableItView === true)) {
return ctx.fail('未开通此服务'); 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) {
if (data.status === 'success' && (data.appkey === appKey)) { if (data.status === 'success' && (data.appkey === appKey)) {
const result = await service.storage.read(orderId, appKey); const result = await service.storage.read(orderId, appKey);
......
...@@ -24,8 +24,8 @@ module.exports = { ...@@ -24,8 +24,8 @@ module.exports = {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl }); notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
} }
}); });
ctx.app.notifyMap = notifyMap;
} }
ctx.app.notifyMap = notifyMap;
} catch (e) { } catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e)); ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
} }
......
...@@ -156,6 +156,50 @@ class PartnerService extends Service { ...@@ -156,6 +156,50 @@ class PartnerService extends Service {
ctx.logger.info('【Partner】 notice no send', 'orderId:', orderId); 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; module.exports = PartnerService;
...@@ -34,6 +34,7 @@ module.exports = () => { ...@@ -34,6 +34,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS', redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements', redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info', redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
}; };
config.scriptsAPI = { config.scriptsAPI = {
......
...@@ -37,6 +37,7 @@ module.exports = () => { ...@@ -37,6 +37,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS', redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements', redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info', redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
}; };
config.scriptsAPI = { 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