Commit 250e3412 authored by 高诸锋's avatar 高诸锋

fix

parent d1a51b43
Pipeline #4059 passed with stage
in 50 seconds
...@@ -7,9 +7,9 @@ class OrderController extends Controller { ...@@ -7,9 +7,9 @@ class OrderController extends Controller {
super(ctx); super(ctx);
this.createRule = { this.createRule = {
appKey: { type: 'string', required: true }, appKey: { type: 'string', required: true },
userId: { type: 'string', required: true }, userId: { type: 'string', required: false },
notifyUrl: { type: 'string', required: false }, notifyUrl: { type: 'string', required: false },
redirectUrl: { type: 'string', required: false }, backUrl: { type: 'string', required: false },
orderId: { orderId: {
type: 'string', type: 'string',
required: false, required: false,
...@@ -30,24 +30,36 @@ class OrderController extends Controller { ...@@ -30,24 +30,36 @@ class OrderController extends Controller {
}, },
}, },
}; };
this.fetchRule = {
sign: { type: 'string', required: true },
params: {
type: 'object', required: true, rule: {
token: { type: 'string', required: true },
appKey: { type: 'string', required: true },
timestamp: { type: 'string', required: true },
},
},
};
} }
async create() { async create() {
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, redirectUrl } = ctx.request.body; const { appKey, userId, notifyUrl, backUrl } = ctx.request.body;
let { orderId } = 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(); orderId = orderId || ctx.helper.getUuid();
await service.order.create({ await service.order.update({
orderId, orderId,
taskId: '', taskId: '',
userId, userId: userId || '',
cityId: '', cityId: '',
appkey: appKey, appkey: appKey,
status: 'init', status: 'init',
notifyUrl, notifyUrl: notifyUrl || (ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
redirectUrl, backUrl,
}); });
ctx.success({ orderId }); ctx.success({ orderId });
} }
...@@ -75,19 +87,35 @@ class OrderController extends Controller { ...@@ -75,19 +87,35 @@ class OrderController extends Controller {
async fetchOrderId() { async fetchOrderId() {
const { ctx, service } = this; const { ctx, service } = this;
const token = await service.signature.getToken(); try {
const signParams = ctx.helper.buildRequestBody({ token }); ctx.validate(this.fetchRule, ctx.request.body);
const { appKey } = signParams.params; const { appKey } = ctx.request.body.params;
const orderId = await service.signature.createOrderId(signParams); const orderId = await service.signature.createOrderId(ctx.request.body);
await service.order.create({ await service.order.create({
orderId, orderId,
taskId: '', taskId: '',
userId: '', cityId: '',
cityId: '', notifyUrl: ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl || '',
appkey: appKey, appKey,
status: 'init', status: 'init',
}); });
ctx.success({ orderId }); ctx.body = {
code: 0,
data: {
orderSn: orderId,
},
msg: '',
};
} catch (e) {
ctx.logger.error('【fetchOrderId】:', JSON.stringify(e));
ctx.status = 200;
if (e.code === 'invalid_param') {
ctx.body = { code: -1, msg: e.message || '' };
return;
}
ctx.body = { code: e.code || -1, msg: e.message || '' };
return;
}
} }
async orderShow() { async orderShow() {
......
...@@ -8,6 +8,7 @@ class TaskController extends Controller { ...@@ -8,6 +8,7 @@ class TaskController extends Controller {
this.createRule = { this.createRule = {
scriptId: { type: 'number', required: true }, scriptId: { type: 'number', required: true },
orderId: { type: 'string', required: true }, orderId: { type: 'string', required: true },
userId: { type: 'string', required: false },
}; };
this.submitRule = { this.submitRule = {
...@@ -143,6 +144,10 @@ class TaskController extends Controller { ...@@ -143,6 +144,10 @@ class TaskController extends Controller {
value: taskNote, value: taskNote,
}); });
} }
async fetchCityConfig() {
}
} }
module.exports = TaskController; module.exports = TaskController;
...@@ -25,5 +25,4 @@ module.exports = { ...@@ -25,5 +25,4 @@ module.exports = {
error, error,
}; };
}, },
}; };
...@@ -12,9 +12,7 @@ module.exports = (options, app) => { ...@@ -12,9 +12,7 @@ module.exports = (options, app) => {
await next(); await next();
ms = new Date() - start; ms = new Date() - start;
app.logger.info( app.logger.info(
`[middleware-response-time](${ms}ms) ${request.method} ${request.protocol}://${request.ip}${ `[middleware-response-time](${ms}ms) ${request.method} ${request.protocol}://${request.ip}${request.originalUrl}, request.query:${JSON.stringify(request.query)}, request.body: ${JSON.stringify(request.body)}, response.status: ${ctx.response.status}, response.body: ${JSON.stringify(ctx.response.body)}`
request.originalUrl}, request.query:${JSON.stringify(request.query)}, request.body:
${JSON.stringify(request.body)}, response.status: ${ctx.response.status}, response.body: ${JSON.stringify(ctx.response.body)}`
); );
}; };
}; };
...@@ -47,13 +47,13 @@ module.exports = app => { ...@@ -47,13 +47,13 @@ module.exports = app => {
type: DataTypes.STRING(255), type: DataTypes.STRING(255),
allowNull: true, allowNull: true,
defaultValue: '', defaultValue: '',
field: 'callbackUrl', field: 'notifyUrl',
}, },
redirectUrl: { backUrl: {
type: DataTypes.STRING(255), type: DataTypes.STRING(255),
allowNull: true, allowNull: true,
defaultValue: '', defaultValue: '',
field: 'redirectUrl', field: 'backUrl',
}, },
status: { status: {
type: DataTypes.STRING(50), type: DataTypes.STRING(50),
......
...@@ -23,7 +23,7 @@ module.exports = app => { ...@@ -23,7 +23,7 @@ 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); // 创建订单号(新版H5)
sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组) sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
...@@ -32,6 +32,7 @@ module.exports = app => { ...@@ -32,6 +32,7 @@ module.exports = app => {
sbRouter.get('/agreements/:id', controller.partner.fetchAgreements); // 查询协议 sbRouter.get('/agreements/:id', controller.partner.fetchAgreements); // 查询协议
sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token
sbRouter.post('/getOrderSn', controller.order.fetchOrderId); // 合作方获取订单号(老版H5)
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); // 获取展示页面数据 sbRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow); // 获取展示页面数据
......
...@@ -33,14 +33,27 @@ class OrderService extends Service { ...@@ -33,14 +33,27 @@ class OrderService extends Service {
async update(params) { async update(params) {
const { ctx } = this; const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({ const order = await ctx.model.TaskStatus.findAll({
where: { orderId: params.orderId }, where: { orderId: params.orderId },
order: [['createDate', 'DESC']],
}); });
if (!order) { // console.log(order);
ctx.throw(400, { message: 'no order' }); if (order.length === 0) { //
await ctx.model.TaskStatus.create(params);
return;
}
for (const item of order) {
if (item.status === 'success') {
ctx.throw(400, { message: 'orderId success' });
return;
}
}
const { appKey, taskId, notifyUrl, backUrl, userId } = order[0];
if (taskId) {
await ctx.model.TaskStatus.create({ appKey, status: 'init', notifyUrl, backUrl, userId, ...params });
} else {
order[0].update(params);
} }
await order.update(params);
return order;
} }
} }
......
{ {
"name": "hf_h5_server", "name": "shebao_h5_server",
"version": "1.0.0", "version": "1.0.0",
"description": "公积金H5认证服务", "description": "社保H5认证服务",
"private": true, "private": true,
"dependencies": { "dependencies": {
"egg": "^2.2.1", "egg": "^2.2.1",
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
"node": ">=8.9.0" "node": ">=8.9.0"
}, },
"scripts": { "scripts": {
"start": "egg-scripts start --daemon --title=egg-server-hf_h5_server", "start": "egg-scripts start --daemon --title=egg-server-shebao_h5_server",
"stop": "egg-scripts stop --title=egg-server-hf_h5_server", "stop": "egg-scripts stop --title=egg-server-shebao_h5_server",
"docker": "eggctl start --title=egg-server-hf_h5_serverr", "docker": "eggctl start --title=egg-server-shebao_h5_server",
"dev": "egg-bin dev", "dev": "egg-bin dev",
"debug": "egg-bin debug", "debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local", "test": "npm run lint -- --fix && npm run test-local",
...@@ -48,6 +48,6 @@ ...@@ -48,6 +48,6 @@
"type": "git", "type": "git",
"url": "" "url": ""
}, },
"author": "HAYWAEL", "author": "gaozf",
"license": "MIT" "license": "MIT"
} }
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