Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sb_h5
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
sb_h5
Commits
d1a51b43
Commit
d1a51b43
authored
Mar 04, 2019
by
高诸锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add && fix
parent
8210eef2
Pipeline
#4011
passed with stage
in 7 seconds
Changes
11
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
188 additions
and
36 deletions
+188
-36
order.js
app/controller/order.js
+50
-26
partner.js
app/controller/partner.js
+2
-2
task.js
app/controller/task.js
+2
-2
helper.js
app/extend/helper.js
+1
-1
cusdata.js
app/model/cusdata.js
+78
-0
taskStatus.js
app/model/taskStatus.js
+8
-2
router.js
app/router.js
+1
-1
notify_url.js
app/schedule/notify_url.js
+33
-0
partner.js
app/service/partner.js
+5
-1
storage.js
app/service/storage.js
+7
-1
config.local.js
config/config.local.js
+1
-0
No files found.
app/controller/order.js
View file @
d1a51b43
...
@@ -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
;
app/controller/partner.js
View file @
d1a51b43
...
@@ -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
,
...
...
app/controller/task.js
View file @
d1a51b43
...
@@ -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
({
...
...
app/extend/helper.js
View file @
d1a51b43
'use strict'
;
'use strict'
;
const
querystring
=
require
(
'querystring'
);
const
querystring
=
require
(
'querystring'
);
const
crypto
=
require
(
'crypto'
);
const
crypto
=
require
(
'crypto'
);
const
uuid
=
require
(
'uuid/v
4
'
);
const
uuid
=
require
(
'uuid/v
1
'
);
function
process
(
params
)
{
function
process
(
params
)
{
const
keys
=
Object
.
keys
(
params
)
const
keys
=
Object
.
keys
(
params
)
...
...
app/model/cusdata.js
0 → 100644
View file @
d1a51b43
'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
;
};
app/model/taskStatus.js
View file @
d1a51b43
...
@@ -43,12 +43,18 @@ module.exports = app => {
...
@@ -43,12 +43,18 @@ module.exports = app => {
allowNull
:
false
,
allowNull
:
false
,
field
:
'appkey'
,
field
:
'appkey'
,
},
},
callback
Url
:
{
notify
Url
:
{
type
:
DataTypes
.
STRING
(
255
),
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
fals
e
,
allowNull
:
tru
e
,
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
,
...
...
app/router.js
View file @
d1a51b43
...
@@ -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
);
// 获取展示页面数据
};
};
app/schedule/notify_url.js
0 → 100644
View file @
d1a51b43
'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
));
}
},
};
app/service/partner.js
View file @
d1a51b43
...
@@ -66,12 +66,16 @@ class PartnerService extends Service {
...
@@ -66,12 +66,16 @@ 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
)
{
if
(
ctx
.
app
.
notifyMap
.
has
(
appKey
))
{
cb
=
ctx
.
app
.
notifyMap
.
get
(
appKey
);
}
else
{
ctx
.
logger
.
info
(
`【orderId】:
${
orderId
}
没有回调地址`
);
ctx
.
logger
.
info
(
`【orderId】:
${
orderId
}
没有回调地址`
);
return
;
return
;
}
}
}
const
data
=
await
service
.
cache
.
get
({
key
:
taskId
});
const
data
=
await
service
.
cache
.
get
({
key
:
taskId
});
if
(
data
&&
data
.
status
===
'success'
)
{
if
(
data
&&
data
.
status
===
'success'
)
{
...
...
app/service/storage.js
View file @
d1a51b43
...
@@ -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
];
}
}
}
}
...
...
config/config.local.js
View file @
d1a51b43
...
@@ -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
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment