Commit 672106f1 authored by 何娜's avatar 何娜

学信H5 增加测试上限

parent 72edc639
Pipeline #7287 passed with stage
in 6 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, backUrl, orderId } = ctx.request.body;
let {appKey, userId, notifyUrl, redirectUrl, orderId} = ctx.request.body;
const appKeyInfo = await service.partner.fetchInfo(appKey);
ctx.logger.info(appKey, ',appKeyInfo,', appKeyInfo);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableIt === true)) {
......@@ -60,7 +60,7 @@ class OrderController extends Controller {
userId: userId || '',
cityId: '',
notifyUrl: notifyUrl || (ctx.app.notifyMap && ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl: backUrl || '',
backUrl: redirectUrl || '',
appkey: appKey,
status: 'init',
};
......@@ -70,7 +70,7 @@ class OrderController extends Controller {
object.orderId = ctx.helper.getUuid();
await service.order.create(object);
}
ctx.success({ orderId: object.orderId });
ctx.success({orderId: object.orderId});
}
async partnerOrder() {
......@@ -93,16 +93,30 @@ class OrderController extends Controller {
async partnerData() {
const {ctx, service} = this;
ctx.validate(this.showRule);
const {appKey, orderSn} = ctx.request.body.params;
await service.signature.signatureCheck(ctx.request.body);
const data = await service.order.getOneByOrderId(orderSn);
const {appKey, orderId} = ctx.request.body.params;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableIt === true)) {
return ctx.body = {
code: -1,
mag: '未开通此服务'
}
}
const sign = await service.signature.signatureCheck(ctx.request.body);
if (sign.code != 0) {
return ctx.body = {
code: -1,
mag: sign.msg
}
}
const data = await service.order.getOneByOrderId({orderId, status: 'success'});
if (data && data.status === 'success') {
const result = await service.storage.read(orderSn, 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,
......@@ -111,8 +125,8 @@ 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('未开通此服务');
......
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const nodeLimit = app.model.define('nodeLimit', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
companyName: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'companyName',
},
appKey: {
type: DataTypes.STRING(255),
allowNull: false,
field: 'appKey',
},
type: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'type',
},
currentCount: {
type: DataTypes.INTEGER(20),
allowNull: true,
defaultValue: 0,
field: 'currentCount',
},
limitCount: {
type: DataTypes.INTEGER(20),
allowNull: true,
defaultValue: 0,
field: 'limitCount',
},
createTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'createTime',
},
updateTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'updateTime',
},
text: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'text2',
},
},
{
tableName: 'node_limit',
timestamps: false,
});
return nodeLimit;
};
......@@ -17,7 +17,7 @@ class PartnerService extends Service {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchParams', redisThemePrefix + appKey, 'result:', data, err);
ctx.logger.error('【Partner】fetchTheme', redisThemePrefix + appKey, 'result:', data, err);
await this.app.redis.del(redisThemePrefix + appKey);
}
}
......@@ -32,7 +32,7 @@ class PartnerService extends Service {
subject: 'it'
}
});
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data);
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisThemePrefix + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
......@@ -47,7 +47,7 @@ class PartnerService extends Service {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchInfo', redisInfoPrefix + appKey, 'result:', data, err);
ctx.logger.error('【Partner】fetchInfo', redisInfoPrefix + appKey, 'result:', data, err);
await this.app.redis.del(redisInfoPrefix + appKey);
}
}
......@@ -62,7 +62,7 @@ class PartnerService extends Service {
appKey
}
});
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchInfo}?appKey=${appKey}`, ret.data);
ctx.logger.info(`【Partner】 fetchInfo ${host + fetchInfo}?appKey=${appKey}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisInfoPrefix + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
......@@ -90,7 +90,7 @@ class PartnerService extends Service {
dataType: 'json',
method: 'GET',
});
ctx.logger.info(`【Partner】 fetchTheme ${url}`, JSON.stringify(ret.data));
ctx.logger.info(`【Partner】 fetchScripts ${url}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.id === appKey) {
await this.app.redis.set(redisScriptsPrefix + appKey, JSON.stringify(ret.data), 'EX', 300);
}
......@@ -147,6 +147,50 @@ class PartnerService extends Service {
}
return
}
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: 'xuexin' },
});
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;
......@@ -96,8 +96,8 @@ class SignatureService extends Service {
contentType: 'json',
});
ctx.logger.info('【Signature】signatureCheck params', JSON.stringify({ ...params, type: signatureType }), 'result:', JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data;
// this._checkSuccess(result);
return result.data;
}
async cityConfig(params){
......
......@@ -33,6 +33,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.XX.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.XX.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.XX.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.XX.PARNTERS.Limit',
};
config.scriptsAPI = {
......
......@@ -36,6 +36,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.XX.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.XX.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.XX.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.XX.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