Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
open-api
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
刘松
open-api
Commits
2d9d1c5d
Commit
2d9d1c5d
authored
Mar 20, 2019
by
yaobeibei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6b755d8f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
12 deletions
+131
-12
cache.js
controllers/cache.js
+25
-0
calltask.js
controllers/calltask.js
+45
-9
clue.js
controllers/clue.js
+1
-1
order.js
controllers/order.js
+51
-0
calltask.js
db/mongo/open/calltask.js
+2
-0
jwt.js
middleware/jwt.js
+4
-1
order.js
routes/api/order.js
+2
-1
yarn.lock
yarn.lock
+1
-0
No files found.
controllers/cache.js
0 → 100644
View file @
2d9d1c5d
const
jwt
=
require
(
'jsonwebtoken'
);
const
config
=
require
(
'config'
);
const
hash
=
require
(
'utils/hash'
);
const
OpenAccount
=
require
(
'db/mongo/open/account'
);
const
_
=
require
(
'lodash'
);
const
NodeCache
=
require
(
'node-cache'
);
const
mongoose
=
require
(
'mongoose'
);
const
{
ObjectId
}
=
require
(
'mongoose'
).
Types
;
const
rmkCache
=
new
NodeCache
();
exports
.
openAccountCache
=
async
(
openAccount
)
=>
{
let
temp
=
openAccount
+
''
;
if
(
rmkCache
.
get
(
temp
))
return
rmkCache
.
get
(
temp
);
else
{
let
obj
=
await
OpenAccount
.
findById
(
temp
);
let
info
=
(
obj
?
obj
.
toJSON
()
:
null
);
rmkCache
.
set
(
temp
,
obj
);
return
obj
;
}
}
\ No newline at end of file
controllers/calltask.js
View file @
2d9d1c5d
...
@@ -9,6 +9,7 @@ const clueContrl = require('./clue');
...
@@ -9,6 +9,7 @@ const clueContrl = require('./clue');
const
groupContrl
=
require
(
'./group'
);
const
groupContrl
=
require
(
'./group'
);
const
Clue
=
require
(
'db/mongo/open/clue'
);
const
Clue
=
require
(
'db/mongo/open/clue'
);
const
CallTask
=
require
(
'db/mongo/open/calltask'
);
const
CallTask
=
require
(
'db/mongo/open/calltask'
);
const
cache
=
require
(
'./cache'
);
//const callTaskContrl = require('./callTask');
//const callTaskContrl = require('./callTask');
const
HOST
=
config
.
HOST
;
const
HOST
=
config
.
HOST
;
const
STAMP
=
1000
*
60
;
const
STAMP
=
1000
*
60
;
...
@@ -34,17 +35,34 @@ async function unbindWhenCall( phone ) {
...
@@ -34,17 +35,34 @@ async function unbindWhenCall( phone ) {
},
},
json
:
true
json
:
true
});
});
console
.
dir
(
rep
);
console
.
log
(
'****************************'
)
console
.
log
(
rep
)
console
.
log
(
rep
)
await
CallTask
.
updateOne
({
_id
},
{
$set
:
{
if
((
rep
&&
rep
.
status
===
'ok'
)
||
rep
.
msg
===
'already unbinded'
)
{
let
callTaskObj
=
await
CallTask
.
findOneAndUpdate
({
_id
},
{
$set
:
{
updateTime
:
Date
.
now
(),
updateTime
:
Date
.
now
(),
duration
:
0
,
duration
:
0
,
url
:
null
,
url
:
null
,
result
:
'OTHER'
,
result
:
'OTHER'
,
minutes
:
0
,
minutes
:
0
,
whencall
:
true
trigger
:
'beforecall'
,
}})
status
:
2
}},
{
new
:
true
})
console
.
dir
(
`准备回调`
);
let
account
=
await
cache
.
openAccountCache
(
callTaskObj
.
account
);
console
.
dir
(
account
);
console
.
dir
(
`获取host`
)
let
host
=
account
&&
account
.
calltaskNotityUrl
?
account
.
calltaskNotityUrl
:
null
;
console
.
dir
(
`host:
${
host
}
`
);
if
(
host
)
{
await
api
({
method
:
'POST'
,
url
:
host
,
body
:
callTaskObj
,
json
:
true
});
}
}
}
}
console
.
log
(
'拨打前解绑结束:*******'
)
console
.
log
(
'拨打前解绑结束:*******'
)
return
;
return
;
...
@@ -69,15 +87,33 @@ async function unbind() {
...
@@ -69,15 +87,33 @@ async function unbind() {
});
});
console
.
log
(
'auto unbinding job result'
)
console
.
log
(
'auto unbinding job result'
)
console
.
log
(
rep
)
console
.
log
(
rep
)
if
((
rep
&&
rep
.
status
===
'ok'
)
||
rep
.
msg
===
'already unbinded'
)
if
((
rep
&&
rep
.
status
===
'ok'
)
||
rep
.
msg
===
'already unbinded'
)
{
await
CallTask
.
updateOn
e
({
_id
},
{
$set
:
{
let
callTaskObj
=
await
CallTask
.
findOneAndUpdat
e
({
_id
},
{
$set
:
{
updateTime
:
Date
.
now
(),
updateTime
:
Date
.
now
(),
duration
:
0
,
duration
:
0
,
url
:
null
,
url
:
null
,
result
:
'OTHER'
,
result
:
'OTHER'
,
minutes
:
0
,
minutes
:
0
,
cron
:
true
trigger
:
'cron'
,
}})
status
:
2
}},
{
new
:
true
})
console
.
dir
(
`准备回调`
);
let
account
=
await
cache
.
openAccountCache
(
callTaskObj
.
account
);
console
.
dir
(
account
);
console
.
dir
(
`获取host`
)
let
host
=
account
&&
account
.
calltaskNotityUrl
?
account
.
calltaskNotityUrl
:
null
;
console
.
dir
(
`host:
${
host
}
`
);
if
(
host
)
{
await
api
({
method
:
'POST'
,
url
:
host
,
body
:
callTaskObj
,
json
:
true
});
}
}
}
}
}
}
...
...
controllers/clue.js
View file @
2d9d1c5d
...
@@ -119,7 +119,7 @@ exports.list = async (ctx, next) => {
...
@@ -119,7 +119,7 @@ exports.list = async (ctx, next) => {
ctx
.
body
=
{
ctx
.
body
=
{
status
:
'ok'
,
status
:
'ok'
,
result
:
{
result
:
{
clues
:
(
clues
||
[]).
map
(
clue
=>
_
.
pick
(
clue
,
[
'account'
,
'user'
,
'unikey'
,
'code'
,
'type'
,
'from'
,
'group'
,
'sex'
,
'age'
,
'city'
,
'province'
,
'virtualHost'
,
'lastCall'
,
'order'
,
'subOrder'
,
'lastCall'
,
'calledHistory'
,
'_id'
])),
clues
:
(
clues
||
[]).
map
(
clue
=>
_
.
pick
(
clue
,
[
'account'
,
'user'
,
'code'
,
'type'
,
'from'
,
'group'
,
'sex'
,
'age'
,
'city'
,
'province'
,
'virtualHost'
,
'lastCall'
,
'order'
,
'subOrder'
,
'lastCall'
,
'calledHistory'
,
'_id'
])),
total
,
total
,
skip
skip
}
}
...
...
controllers/order.js
View file @
2d9d1c5d
...
@@ -77,6 +77,31 @@ exports.list = async (ctx, next) => {
...
@@ -77,6 +77,31 @@ exports.list = async (ctx, next) => {
}
}
}
}
exports
.
check
=
async
(
ctx
,
next
)
=>
{
let
{
order
}
=
ctx
.
request
.
body
;
ctx
.
assert
(
tools
.
valid
(
order
),
500
,
'参数错误,user'
,
{
code
:
1
});
let
orderObj
=
await
Order
.
findById
(
order
);
ctx
.
assert
(
orderObj
,
500
,
'参数错误,order'
,
{
code
:
1
});
if
(
orderObj
.
status
==
'审核中'
)
{
orderObj
.
status
=
'执行中'
;
orderObj
.
history
=
orderObj
.
history
.
concat
([{
status
:
'执行中'
,
date
:
new
Date
()
}])
await
orderObj
.
save
();
}
ctx
.
body
=
{
status
:
'ok'
}
}
exports
.
all
=
async
(
ctx
,
next
)
=>
{
exports
.
all
=
async
(
ctx
,
next
)
=>
{
let
{
let
{
id
=
0
,
id
=
0
,
...
@@ -132,6 +157,32 @@ exports.all = async (ctx, next) => {
...
@@ -132,6 +157,32 @@ exports.all = async (ctx, next) => {
}
}
}
}
exports
.
check
=
async
(
ctx
,
next
)
=>
{
let
{
order
}
=
ctx
.
request
.
body
;
ctx
.
assert
(
tools
.
valid
(
order
),
500
,
'参数错误,user'
,
{
code
:
1
});
let
orderObj
=
await
Order
.
findById
(
order
);
ctx
.
assert
(
orderObj
,
500
,
'参数错误,order'
,
{
code
:
1
});
if
(
orderObj
.
status
==
'审核中'
)
{
orderObj
.
status
=
'执行中'
;
orderObj
.
history
=
orderObj
.
history
.
concat
([{
status
:
'执行中'
,
date
:
new
Date
()
}])
await
orderObj
.
save
();
}
ctx
.
body
=
{
status
:
'ok'
}
}
//创建订单
//创建订单
exports
.
create
=
async
(
ctx
,
next
)
=>
{
exports
.
create
=
async
(
ctx
,
next
)
=>
{
let
{
let
{
...
...
db/mongo/open/calltask.js
View file @
2d9d1c5d
...
@@ -75,6 +75,8 @@ const schema = mongoose.Schema({
...
@@ -75,6 +75,8 @@ const schema = mongoose.Schema({
type
:
Number
,
type
:
Number
,
required
:
false
,
required
:
false
,
},
},
trigger
:
String
,
status
:
Number
,
// 回调标识 1 联通回调 2 脚本回调
archive
:
{
// 归档标识
archive
:
{
// 归档标识
type
:
Boolean
type
:
Boolean
},
},
...
...
middleware/jwt.js
View file @
2d9d1c5d
...
@@ -12,7 +12,9 @@ module.exports = (opt = {}) => {
...
@@ -12,7 +12,9 @@ module.exports = (opt = {}) => {
'/api/token/account'
,
'/api/token/account'
,
'/api/token'
,
'/api/token'
,
'/api/clue/input'
,
'/api/clue/input'
,
'/api/order/all'
'/api/order/check'
,
'/api/order/all'
,
'/api/order/check'
]
]
});
});
};
};
\ No newline at end of file
routes/api/order.js
View file @
2d9d1c5d
...
@@ -5,5 +5,5 @@ const Auth = require('controllers/auth');
...
@@ -5,5 +5,5 @@ const Auth = require('controllers/auth');
router
.
post
(
'/list'
,
Auth
.
auth
,
$
.
list
);
router
.
post
(
'/list'
,
Auth
.
auth
,
$
.
list
);
router
.
post
(
'/create'
,
Auth
.
auth
,
$
.
create
);
router
.
post
(
'/create'
,
Auth
.
auth
,
$
.
create
);
router
.
post
(
'/all'
,
$
.
all
);
router
.
post
(
'/all'
,
$
.
all
);
router
.
post
(
'/check'
,
$
.
check
);
module
.
exports
=
router
;
module
.
exports
=
router
;
\ No newline at end of file
yarn.lock
View file @
2d9d1c5d
...
@@ -7641,6 +7641,7 @@ no-case@^2.2.0:
...
@@ -7641,6 +7641,7 @@ no-case@^2.2.0:
node-cache@^4.2.0:
node-cache@^4.2.0:
version "4.2.0"
version "4.2.0"
resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-4.2.0.tgz#48ac796a874e762582692004a376d26dfa875811"
resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-4.2.0.tgz#48ac796a874e762582692004a376d26dfa875811"
integrity sha512-obRu6/f7S024ysheAjoYFEEBqqDWv4LOMNJEuO8vMeEw2AT4z+NCzO4hlc2lhI4vATzbCQv6kke9FVdx0RbCOw==
dependencies:
dependencies:
clone "2.x"
clone "2.x"
lodash "4.x"
lodash "4.x"
...
...
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