Commit d1a51b43 authored by 高诸锋's avatar 高诸锋

add && fix

parent 8210eef2
Pipeline #4011 passed with stage
in 7 seconds
...@@ -9,17 +9,24 @@ class OrderController extends Controller { ...@@ -9,17 +9,24 @@ class OrderController extends Controller {
appKey: { type: 'string', required: true }, appKey: { type: 'string', required: true },
userId: { type: 'string', required: true }, userId: { type: 'string', required: true },
notifyUrl: { type: 'string', required: false }, notifyUrl: { type: 'string', required: false },
redirectUrl: { type: 'string', required: false },
orderId: {
type: 'string',
required: false,
format: /^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/,
message: '订单号格式错误',
},
}; };
this.showRule = { this.showRule = {
sign: 'string', sign: 'string',
params: { params: {
type: 'object', type: 'object', required: true,
rule: { rule: {
token: 'string', token: { type: 'string', required: true },
orderId: 'string', orderId: { type: 'string', required: true },
appKey: 'string', appKey: { type: 'string', required: true },
timestamp: 'string', timestamp: { type: 'string', required: true },
}, },
}, },
}; };
...@@ -29,7 +36,7 @@ class OrderController extends Controller { ...@@ -29,7 +36,7 @@ class OrderController extends Controller {
const { ctx, service } = this; const { ctx, service } = this;
ctx.validate(this.createRule); ctx.validate(this.createRule);
// const { appKey } = ctx.request.body.params; // const { appKey } = ctx.request.body.params;
const { appKey, userId, notifyUrl } = ctx.request.body; const { appKey, userId, notifyUrl, redirectUrl } = ctx.request.body;
// const orderId = await service.signature.createOrderId(ctx.request.body); // const orderId = await service.signature.createOrderId(ctx.request.body);
const orderId = await ctx.helper.getUuid(); const orderId = await ctx.helper.getUuid();
await service.order.create({ await service.order.create({
...@@ -39,30 +46,32 @@ class OrderController extends Controller { ...@@ -39,30 +46,32 @@ class OrderController extends Controller {
cityId: '', cityId: '',
appkey: appKey, appkey: appKey,
status: 'init', status: 'init',
callbackUrl: notifyUrl, notifyUrl,
redirectUrl,
}); });
ctx.success({ orderId }); ctx.success({ orderId });
} }
async show() { // 只根据订单号获取数据
const { ctx, service } = this; // async show() {
ctx.validate(this.showRule); // const { ctx, service } = this;
const { orderId } = ctx.params; // ctx.validate(this.showRule);
await service.signature.signatureCheck(ctx.request.body); // const { orderId, appKey } = ctx.params;
const data = await service.order.getOneByOrderId(orderId); // await service.signature.signatureCheck(ctx.request.body);
if (data) { // const data = await service.order.getOneByOrderId(orderId);
if (data.status === 'success') { // if (data) {
const result = await service.storage.read(orderId); // if (data.status === 'success') {
ctx.success(result); // const result = await service.storage.read(orderId, appKey);
return; // ctx.success(result);
} // return;
ctx.success({ // }
status: data.status, // ctx.success({
}); // status: data.status,
return; // });
} // return;
ctx.fail('无此订单号'); // }
} // ctx.fail('无此订单号');
// }
async fetchOrderId() { async fetchOrderId() {
const { ctx, service } = this; const { ctx, service } = this;
...@@ -80,6 +89,21 @@ class OrderController extends Controller { ...@@ -80,6 +89,21 @@ class OrderController extends Controller {
}); });
ctx.success({ orderId }); ctx.success({ orderId });
} }
async orderShow() {
const { ctx, service } = this;
const { appKey, orderId } = ctx.params;
const data = await service.order.getOneByOrderId(orderId);
if (data) {
if (data.status === 'success' && (data.appKey === appKey)) {
const result = await service.storage.read(orderId, appKey);
const ret = service.washData.dealData(result);
ctx.success(ret);
return;
}
}
ctx.fail('无此订单号');
}
} }
module.exports = OrderController; module.exports = OrderController;
...@@ -52,11 +52,11 @@ class PartnerController extends Controller { ...@@ -52,11 +52,11 @@ class PartnerController extends Controller {
ctx.status = 200; ctx.status = 200;
try { try {
ctx.validate(this.showRule); ctx.validate(this.showRule);
const orderId = ctx.request.body.params.orderId; const { orderId, appKey } = ctx.request.body.params;
await service.signature.signatureCheck(ctx.request.body); await service.signature.signatureCheck(ctx.request.body);
const data = await service.order.getOneByOrderId(orderId); const data = await service.order.getOneByOrderId(orderId);
if (data && data.status === 'success') { if (data && data.status === 'success') {
const result = await service.storage.read(orderId); const result = await service.storage.read(orderId, appKey);
ctx.body = { ctx.body = {
code: 0, code: 0,
data: result, data: result,
......
...@@ -125,7 +125,7 @@ class TaskController extends Controller { ...@@ -125,7 +125,7 @@ class TaskController extends Controller {
insertData.appKey = appkey; insertData.appKey = appkey;
delete insertData.code; delete insertData.code;
await service.storage.write(insertData); await service.storage.write(insertData);
await service.partner.notify({ taskId, cb: order.callbackUrl, orderId: order.orderId, userId: order.userId }); await service.partner.notify({ taskId, cb: order.notifyUrl, orderId: order.orderId, userId: order.userId, appKey: order.appKey });
} catch (err) { } catch (err) {
ctx.logger.err(`【controller/task/handleCallback err】:${err}${JSON.stringify(result)}`); ctx.logger.err(`【controller/task/handleCallback err】:${err}${JSON.stringify(result)}`);
taskNote = { taskNote = {
...@@ -135,7 +135,7 @@ class TaskController extends Controller { ...@@ -135,7 +135,7 @@ class TaskController extends Controller {
} }
break; break;
default: default:
ctx.logger.warn('handleCallback', result); ctx.logger.warn('【handleCallback】:', JSON.stringify(result));
break; break;
} }
await service.cache.set({ await service.cache.set({
......
'use strict'; 'use strict';
const querystring = require('querystring'); const querystring = require('querystring');
const crypto = require('crypto'); const crypto = require('crypto');
const uuid = require('uuid/v4'); const uuid = require('uuid/v1');
function process(params) { function process(params) {
const keys = Object.keys(params) const keys = Object.keys(params)
......
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const cusDatas = app.model.define('cusDatas', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
orderId: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: '',
primaryKey: true,
field: 'orderId',
},
appKey: {
type: DataTypes.STRING(255),
allowNull: false,
field: 'appKey',
},
type: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'type',
},
date: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'date',
},
text1: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text2',
},
text3: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text3',
},
text4: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text4',
},
date1: {
type: DataTypes.DATE,
allowNull: true,
field: 'date1',
},
date2: {
type: DataTypes.DATE,
allowNull: true,
field: 'date2',
},
},
{
tableName: 'cus_data',
timestamps: false,
});
return cusDatas;
};
...@@ -43,12 +43,18 @@ module.exports = app => { ...@@ -43,12 +43,18 @@ module.exports = app => {
allowNull: false, allowNull: false,
field: 'appkey', field: 'appkey',
}, },
callbackUrl: { notifyUrl: {
type: DataTypes.STRING(255), type: DataTypes.STRING(255),
allowNull: false, allowNull: true,
defaultValue: '', defaultValue: '',
field: 'callbackUrl', field: 'callbackUrl',
}, },
redirectUrl: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'redirectUrl',
},
status: { status: {
type: DataTypes.STRING(50), type: DataTypes.STRING(50),
allowNull: false, allowNull: false,
......
...@@ -24,7 +24,6 @@ module.exports = app => { ...@@ -24,7 +24,6 @@ module.exports = app => {
sbRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典 sbRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典
sbRouter.post('/tokens', controller.token.create); // 创建token sbRouter.post('/tokens', controller.token.create); // 创建token
sbRouter.post('/orders', controller.order.create); // 创建订单号 sbRouter.post('/orders', controller.order.create); // 创建订单号
// sbRouter.post('/orders/:orderId', controller.order.show); // 获取订单号详情
sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组) sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
...@@ -35,4 +34,5 @@ module.exports = app => { ...@@ -35,4 +34,5 @@ module.exports = app => {
sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token
sbRouter.post('/getData', controller.partner.partnerShow); // 合作方获取订单数据 sbRouter.post('/getData', controller.partner.partnerShow); // 合作方获取订单数据
sbRouter.post('/getCityConfig', controller.task.fetchCityConfig); // 合作方获取城市配置 sbRouter.post('/getCityConfig', controller.task.fetchCityConfig); // 合作方获取城市配置
sbRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow); // 获取展示页面数据
}; };
'use strict';
module.exports = {
schedule: {
interval: '5m', // 5分钟间隔
type: 'all', // 所有woker
immediate: true,
},
async task(ctx) {
try {
const { host, customerUrl } = ctx.app.config.signatureAPI;
const notifyMap = new Map();
const ret = await ctx.curl(host + customerUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
// ctx.logger.info(JSON.stringify(ret.data));
if (ret.data.code === '0') {
ret.data.data.customerList.map(customer => {
if ('callBackUrl' in customer) {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
}
});
ctx.app.notifyMap = notifyMap;
}
} catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
}
},
};
...@@ -66,11 +66,15 @@ class PartnerService extends Service { ...@@ -66,11 +66,15 @@ class PartnerService extends Service {
// 查询结束后回调通知合作方 // 查询结束后回调通知合作方
// 对于状态已经是成功的订单号不会在做通知 // 对于状态已经是成功的订单号不会在做通知
// orderId/userId/status // orderId/userId/status
async notify({ taskId, cb, orderId, userId }) { async notify({ taskId, cb, orderId, userId, appKey }) {
const { ctx, service } = this; const { ctx, service } = this;
if (!cb) { if (!cb) {
ctx.logger.info(`【orderId】:${orderId} 没有回调地址`); if (ctx.app.notifyMap.has(appKey)) {
return; cb = ctx.app.notifyMap.get(appKey);
} else {
ctx.logger.info(`【orderId】:${orderId} 没有回调地址`);
return;
}
} }
const data = await service.cache.get({ key: taskId }); const data = await service.cache.get({ key: taskId });
......
...@@ -42,7 +42,7 @@ class StorageService extends Service { ...@@ -42,7 +42,7 @@ class StorageService extends Service {
return; return;
} }
async read(orderId) { async read(orderId, appKey) {
const { readUrl, readDataKey, ctx } = this; const { readUrl, readDataKey, ctx } = this;
const result = await this._request(`${readUrl}/${orderId}`, { const result = await this._request(`${readUrl}/${orderId}`, {
method: 'get', method: 'get',
...@@ -54,6 +54,12 @@ class StorageService extends Service { ...@@ -54,6 +54,12 @@ class StorageService extends Service {
ctx.logger.error(`storageAPI read ${readUrl}/${orderId}`, JSON.stringify(result.data)); ctx.logger.error(`storageAPI read ${readUrl}/${orderId}`, JSON.stringify(result.data));
ctx.throw(400, { message: result.data.msg }); ctx.throw(400, { message: result.data.msg });
} }
// 操作cus_data表记录拉取数据
await ctx.model.Cusdata.create({
appKey,
orderId,
type: 'shebao',
});
return result.data.data[readDataKey]; return result.data.data[readDataKey];
} }
} }
......
...@@ -57,6 +57,7 @@ module.exports = () => { ...@@ -57,6 +57,7 @@ module.exports = () => {
signatureUrl: '/Access/SignValidityCheck', signatureUrl: '/Access/SignValidityCheck',
fetchParnterUrl: '', fetchParnterUrl: '',
signatureType: 'shebao', signatureType: 'shebao',
customerUrl: '/customer/query',
}; };
config.lockKeys = { config.lockKeys = {
......
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