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 {
appKey: { type: 'string', required: true },
userId: { type: 'string', required: true },
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 = {
sign: 'string',
params: {
type: 'object',
type: 'object', required: true,
rule: {
token: 'string',
orderId: 'string',
appKey: 'string',
timestamp: 'string',
token: { type: 'string', required: true },
orderId: { type: 'string', required: true },
appKey: { type: 'string', required: true },
timestamp: { type: 'string', required: true },
},
},
};
......@@ -29,7 +36,7 @@ class OrderController extends Controller {
const { ctx, service } = this;
ctx.validate(this.createRule);
// 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 ctx.helper.getUuid();
await service.order.create({
......@@ -39,30 +46,32 @@ class OrderController extends Controller {
cityId: '',
appkey: appKey,
status: 'init',
callbackUrl: notifyUrl,
notifyUrl,
redirectUrl,
});
ctx.success({ orderId });
}
async show() {
const { ctx, service } = this;
ctx.validate(this.showRule);
const { orderId } = ctx.params;
await service.signature.signatureCheck(ctx.request.body);
const data = await service.order.getOneByOrderId(orderId);
if (data) {
if (data.status === 'success') {
const result = await service.storage.read(orderId);
ctx.success(result);
return;
}
ctx.success({
status: data.status,
});
return;
}
ctx.fail('无此订单号');
}
// 只根据订单号获取数据
// async show() {
// const { ctx, service } = this;
// ctx.validate(this.showRule);
// const { orderId, appKey } = ctx.params;
// await service.signature.signatureCheck(ctx.request.body);
// const data = await service.order.getOneByOrderId(orderId);
// if (data) {
// if (data.status === 'success') {
// const result = await service.storage.read(orderId, appKey);
// ctx.success(result);
// return;
// }
// ctx.success({
// status: data.status,
// });
// return;
// }
// ctx.fail('无此订单号');
// }
async fetchOrderId() {
const { ctx, service } = this;
......@@ -80,6 +89,21 @@ class OrderController extends Controller {
});
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;
......@@ -52,11 +52,11 @@ class PartnerController extends Controller {
ctx.status = 200;
try {
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);
const data = await service.order.getOneByOrderId(orderId);
if (data && data.status === 'success') {
const result = await service.storage.read(orderId);
const result = await service.storage.read(orderId, appKey);
ctx.body = {
code: 0,
data: result,
......
......@@ -125,7 +125,7 @@ class TaskController extends Controller {
insertData.appKey = appkey;
delete insertData.code;
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) {
ctx.logger.err(`【controller/task/handleCallback err】:${err}${JSON.stringify(result)}`);
taskNote = {
......@@ -135,7 +135,7 @@ class TaskController extends Controller {
}
break;
default:
ctx.logger.warn('handleCallback', result);
ctx.logger.warn('【handleCallback】:', JSON.stringify(result));
break;
}
await service.cache.set({
......
'use strict';
const querystring = require('querystring');
const crypto = require('crypto');
const uuid = require('uuid/v4');
const uuid = require('uuid/v1');
function process(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 => {
allowNull: false,
field: 'appkey',
},
callbackUrl: {
notifyUrl: {
type: DataTypes.STRING(255),
allowNull: false,
allowNull: true,
defaultValue: '',
field: 'callbackUrl',
},
redirectUrl: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'redirectUrl',
},
status: {
type: DataTypes.STRING(50),
allowNull: false,
......
......@@ -24,7 +24,6 @@ module.exports = app => {
sbRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典
sbRouter.post('/tokens', controller.token.create); // 创建token
sbRouter.post('/orders', controller.order.create); // 创建订单号
// sbRouter.post('/orders/:orderId', controller.order.show); // 获取订单号详情
sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
......@@ -35,4 +34,5 @@ module.exports = app => {
sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token
sbRouter.post('/getData', controller.partner.partnerShow); // 合作方获取订单数据
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 {
// 查询结束后回调通知合作方
// 对于状态已经是成功的订单号不会在做通知
// orderId/userId/status
async notify({ taskId, cb, orderId, userId }) {
async notify({ taskId, cb, orderId, userId, appKey }) {
const { ctx, service } = this;
if (!cb) {
ctx.logger.info(`【orderId】:${orderId} 没有回调地址`);
return;
if (ctx.app.notifyMap.has(appKey)) {
cb = ctx.app.notifyMap.get(appKey);
} else {
ctx.logger.info(`【orderId】:${orderId} 没有回调地址`);
return;
}
}
const data = await service.cache.get({ key: taskId });
......
......@@ -42,7 +42,7 @@ class StorageService extends Service {
return;
}
async read(orderId) {
async read(orderId, appKey) {
const { readUrl, readDataKey, ctx } = this;
const result = await this._request(`${readUrl}/${orderId}`, {
method: 'get',
......@@ -54,6 +54,12 @@ class StorageService extends Service {
ctx.logger.error(`storageAPI read ${readUrl}/${orderId}`, JSON.stringify(result.data));
ctx.throw(400, { message: result.data.msg });
}
// 操作cus_data表记录拉取数据
await ctx.model.Cusdata.create({
appKey,
orderId,
type: 'shebao',
});
return result.data.data[readDataKey];
}
}
......
......@@ -57,6 +57,7 @@ module.exports = () => {
signatureUrl: '/Access/SignValidityCheck',
fetchParnterUrl: '',
signatureType: 'shebao',
customerUrl: '/customer/query',
};
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