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 {
super(ctx);
this.createRule = {
appKey: { type: 'string', required: true },
userId: { type: 'string', required: true },
userId: { type: 'string', required: false },
notifyUrl: { type: 'string', required: false },
redirectUrl: { type: 'string', required: false },
backUrl: { type: 'string', required: false },
orderId: {
type: 'string',
required: false,
......@@ -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() {
const { ctx, service } = this;
ctx.validate(this.createRule);
// 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 ctx.helper.getUuid();
await service.order.create({
orderId = orderId || ctx.helper.getUuid();
await service.order.update({
orderId,
taskId: '',
userId,
userId: userId || '',
cityId: '',
appkey: appKey,
status: 'init',
notifyUrl,
redirectUrl,
notifyUrl: notifyUrl || (ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl,
});
ctx.success({ orderId });
}
......@@ -75,19 +87,35 @@ class OrderController extends Controller {
async fetchOrderId() {
const { ctx, service } = this;
const token = await service.signature.getToken();
const signParams = ctx.helper.buildRequestBody({ token });
const { appKey } = signParams.params;
const orderId = await service.signature.createOrderId(signParams);
try {
ctx.validate(this.fetchRule, ctx.request.body);
const { appKey } = ctx.request.body.params;
const orderId = await service.signature.createOrderId(ctx.request.body);
await service.order.create({
orderId,
taskId: '',
userId: '',
cityId: '',
appkey: appKey,
notifyUrl: ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl || '',
appKey,
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() {
......
......@@ -8,6 +8,7 @@ class TaskController extends Controller {
this.createRule = {
scriptId: { type: 'number', required: true },
orderId: { type: 'string', required: true },
userId: { type: 'string', required: false },
};
this.submitRule = {
......@@ -143,6 +144,10 @@ class TaskController extends Controller {
value: taskNote,
});
}
async fetchCityConfig() {
}
}
module.exports = TaskController;
......@@ -25,5 +25,4 @@ module.exports = {
error,
};
},
};
......@@ -12,9 +12,7 @@ module.exports = (options, app) => {
await next();
ms = new Date() - start;
app.logger.info(
`[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)}`
`[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)}`
);
};
};
......@@ -47,13 +47,13 @@ module.exports = app => {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'callbackUrl',
field: 'notifyUrl',
},
redirectUrl: {
backUrl: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'redirectUrl',
field: 'backUrl',
},
status: {
type: DataTypes.STRING(50),
......
......@@ -23,7 +23,7 @@ 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', controller.order.create); // 创建订单号(新版H5)
sbRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
......@@ -32,6 +32,7 @@ module.exports = app => {
sbRouter.get('/agreements/:id', controller.partner.fetchAgreements); // 查询协议
sbRouter.post('/getToken', controller.partner.getToken); // 合作方获取token
sbRouter.post('/getOrderSn', controller.order.fetchOrderId); // 合作方获取订单号(老版H5)
sbRouter.post('/getData', controller.partner.partnerShow); // 合作方获取订单数据
sbRouter.post('/getCityConfig', controller.task.fetchCityConfig); // 合作方获取城市配置
sbRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow); // 获取展示页面数据
......
......@@ -33,14 +33,27 @@ class OrderService extends Service {
async update(params) {
const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({
const order = await ctx.model.TaskStatus.findAll({
where: { orderId: params.orderId },
order: [['createDate', 'DESC']],
});
if (!order) {
ctx.throw(400, { message: 'no order' });
// console.log(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",
"description": "公积金H5认证服务",
"description": "社保H5认证服务",
"private": true,
"dependencies": {
"egg": "^2.2.1",
......@@ -29,9 +29,9 @@
"node": ">=8.9.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-hf_h5_server",
"stop": "egg-scripts stop --title=egg-server-hf_h5_server",
"docker": "eggctl start --title=egg-server-hf_h5_serverr",
"start": "egg-scripts start --daemon --title=egg-server-shebao_h5_server",
"stop": "egg-scripts stop --title=egg-server-shebao_h5_server",
"docker": "eggctl start --title=egg-server-shebao_h5_server",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
......@@ -48,6 +48,6 @@
"type": "git",
"url": ""
},
"author": "HAYWAEL",
"author": "gaozf",
"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