Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
android-remarketing
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
刘松
android-remarketing
Commits
b0cb1a7a
Commit
b0cb1a7a
authored
Jun 11, 2018
by
刘松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix auditstatus
parent
4b4d92f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
173 additions
and
20 deletions
+173
-20
index.js
api/index.js
+173
-20
No files found.
api/index.js
View file @
b0cb1a7a
...
@@ -21,28 +21,96 @@ MongoClient.connect(dbpath, (err, conn) => {
...
@@ -21,28 +21,96 @@ MongoClient.connect(dbpath, (err, conn) => {
.
createIndex
({
createdAt
:
1
},
{
expireAfterSeconds
:
3600
*
24
});
.
createIndex
({
createdAt
:
1
},
{
expireAfterSeconds
:
3600
*
24
});
});
});
router
.
post
(
'/remark'
,
function
(
req
,
res
)
{
const
{
recog
,
remark
,
unikey
}
=
req
.
body
;
let
doc
=
{
recog
,
remark
,
unikey
};
if
(
doc
.
recog
)
delete
doc
.
unikey
;
if
(
doc
.
unikey
)
delete
doc
.
recog
;
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/remark"
;
axios
(
host
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
},
data
:
doc
,
timeout
:
300000
})
.
then
(
async
rep
=>
{
res
.
send
({
status
:
'ok'
,
data
:
rep
.
data
});
})
.
catch
(
err
=>
{
console
.
dir
(
err
);
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'服务出错'
});
});
});
router
.
post
(
'/job/call'
,
function
(
req
,
res
)
{
router
.
post
(
'/job/call'
,
function
(
req
,
res
)
{
const
{
pubID
,
slotID
,
phone
,
expiration
=
EXPIRATION
,
unikey
}
=
req
.
body
;
const
{
pubID
,
slotID
,
phone
,
expiration
=
EXPIRATION
,
unikey
}
=
req
.
body
;
getCallConsumeByUnikey
(
unikey
,
(
err
,
data
)
=>
{
getCallConsumeByUnikey
(
unikey
,
(
err
,
data
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
data
&&
data
.
number
)
{
if
(
data
&&
data
.
number
)
{
checkBill
({
accountID
:
pubID
,
number
:
data
.
number
},(
_err
)
=>
{
checkBill
({
accountID
:
pubID
,
number
:
data
.
number
},
async
(
_err
)
=>
{
if
(
_err
)
{
return
res
.
status
(
500
).
json
({
error
:
_err
});
}
else
{
if
(
!
notEmpty
(
req
.
body
))
res
.
status
(
500
).
json
({
error
:
"参数错误"
});
else
{
const
fromID
=
await
getFromID
(
pubID
);
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/bind/"
+
(
pubID
+
"_"
+
fromID
)
+
'/'
+
slotID
+
'?caller='
+
phone
+
'&unikey='
+
unikey
+
'&expiration='
+
expiration
;
axios
(
host
,
{
method
:
"GET"
,
headers
:
{
"Content-Type"
:
"application/json"
},
timeout
:
300000
})
.
then
(
async
rep
=>
{
if
(
rep
.
data
&&
rep
.
data
.
called
&&
rep
.
data
.
_id
&&
rep
.
data
.
bindID
){
//const fromID = await getFromID(pubID);
console
.
dir
(
fromID
+
'====>'
);
updateBill
({
pre
:
true
,
number
:
data
.
number
,
accountID
:
pubID
,
fromID
,
type
:
'call'
,
taskID
:
rep
.
data
.
_id
},
(
err
,
_rep
)
=>
{
if
(
err
)
{
// log 代码;
}
res
.
send
({
status
:
'ok'
,
called
:
rep
.
data
.
called
,
bindID
:
rep
.
data
.
bindID
});
});
}
else
{
res
.
status
(
500
).
json
({
error
:
'取号失败'
});
}
})
.
catch
(
err
=>
{
console
.
dir
(
err
)
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'运营商拒绝服务'
});
});
}
}
});
}
else
{
res
.
status
(
500
);
}
});
});
router
.
post
(
'/job/dspcall'
,
function
(
req
,
res
)
{
const
{
pubID
,
groupID
,
phone
,
expiration
=
EXPIRATION
,
unikey
}
=
req
.
body
;
getCallConsumeByUnikey
(
unikey
,
(
err
,
data
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
err
});
if
(
data
&&
data
.
number
)
{
checkBill
({
accountID
:
pubID
,
number
:
data
.
number
},
async
(
_err
)
=>
{
if
(
_err
)
{
if
(
_err
)
{
return
res
.
status
(
500
).
json
({
error
:
_err
});
return
res
.
status
(
500
).
json
({
error
:
_err
});
}
else
{
}
else
{
if
(
!
notEmpty
(
req
.
body
))
res
.
status
(
500
).
json
({
error
:
"参数错误"
});
if
(
!
notEmpty
(
req
.
body
))
res
.
status
(
500
).
json
({
error
:
"参数错误"
});
else
{
else
{
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/bind/"
+
pubID
+
'/'
+
slotID
+
'?caller='
+
phone
+
'&unikey='
+
unikey
+
'&expiration='
+
expiration
;
const
fromID
=
await
getFromID
(
pubID
);
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/dspBind/"
+
(
pubID
+
"_"
+
fromID
)
+
'/'
+
groupID
+
'?caller='
+
phone
+
'&unikey='
+
unikey
+
'&expiration='
+
expiration
;
axios
(
host
,
{
axios
(
host
,
{
method
:
"GET"
,
method
:
"GET"
,
headers
:
{
"Content-Type"
:
"application/json"
},
headers
:
{
"Content-Type"
:
"application/json"
},
timeout
:
300000
timeout
:
300000
})
})
.
then
(
async
rep
=>
{
.
then
(
async
rep
=>
{
console
.
dir
(
rep
);
if
(
rep
.
data
&&
rep
.
data
.
called
&&
rep
.
data
.
_id
&&
rep
.
data
.
bindID
){
if
(
rep
.
data
&&
rep
.
data
.
called
&&
rep
.
data
.
_id
&&
rep
.
data
.
bindID
){
const
fromID
=
await
getFromID
(
pubID
);
//
const fromID = await getFromID(pubID);
updateBill
({
pre
:
true
,
number
:
data
.
number
,
accountID
:
pubID
,
type
:
'call'
,
taskID
:
rep
.
data
.
_id
},
(
err
,
_rep
)
=>
{
updateBill
({
pre
:
true
,
number
:
data
.
number
,
accountID
:
pubID
,
fromID
,
type
:
'dspcall'
,
groupID
,
taskID
:
rep
.
data
.
_id
},
(
err
,
_rep
)
=>
{
if
(
err
)
{
if
(
err
)
{
// log 代码;
// log 代码;
}
}
...
@@ -55,7 +123,7 @@ router.post('/job/call',function (req,res) {
...
@@ -55,7 +123,7 @@ router.post('/job/call',function (req,res) {
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
console
.
dir
(
err
)
console
.
dir
(
err
)
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'
参数错误,取号失败
'
});
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'
运营商拒绝服务
'
});
});
});
}
}
}
}
...
@@ -75,8 +143,25 @@ router.get('/unbind',function (req,res) {
...
@@ -75,8 +143,25 @@ router.get('/unbind',function (req,res) {
timeout
:
300000
timeout
:
300000
})
})
.
then
(
rep
=>
{
.
then
(
rep
=>
{
console
.
dir
(
rep
);
res
.
send
({
status
:
'ok'
});
res
.
send
({
status
:
'ok'
,
data
:
rep
});
})
.
catch
(
err
=>
{
console
.
dir
(
err
);
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'解绑错误'
});
});
});
router
.
get
(
'/dspUnbind'
,
function
(
req
,
res
)
{
const
{
bindID
}
=
req
.
query
;
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/dspUnbind?bindID="
+
bindID
;
axios
(
host
,
{
method
:
"GET"
,
headers
:
{
"Content-Type"
:
"application/json"
},
timeout
:
300000
})
.
then
(
rep
=>
{
res
.
send
({
status
:
'ok'
});
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
console
.
dir
(
err
);
console
.
dir
(
err
);
...
@@ -132,21 +217,28 @@ router.get("/recognitions",function(req,res) {
...
@@ -132,21 +217,28 @@ router.get("/recognitions",function(req,res) {
if
(
date
)
{
if
(
date
)
{
start
=
(
end
=
date
);
start
=
(
end
=
date
);
}
}
let
sort
=
{};
let
qs
=
getTimeRange
({
start
,
end
,
key
:
'updateTimestamp'
,
type
:
'millisecond'
});
let
qs
=
getTimeRange
({
start
,
end
,
key
:
'updateTimestamp'
,
type
:
'millisecond'
});
//let qs = { updateTimestamp: { '$gt': parseInt(moment(date, 'YYYYMMDD').startOf('day').format('x')), '$lte': parseInt(moment(date, 'YYYYMMDD').endOf('day').format('x')) }, 'tokenInfo.tokenID': OID(tokenID) };
//let qs = { updateTimestamp: { '$gt': parseInt(moment(date, 'YYYYMMDD').startOf('day').format('x')), '$lte': parseInt(moment(date, 'YYYYMMDD').endOf('day').format('x')) }, 'tokenInfo.tokenID': OID(tokenID) };
_
.
merge
(
qs
,
{
calledInfo
:
{
$exists
:
called
==
'true'
}
,
'tokenInfo.tokenID'
:
OID
(
tokenID
)
}
);
_
.
merge
(
qs
,
{
calledInfo
:
{
$exists
:
called
==
'true'
}
,
'tokenInfo.tokenID'
:
OID
(
tokenID
)
,
auditStatus
:
2
}
);
if
(
called
==
'true'
)
sort
.
calledTimestamp
=
-
1
;
else
sort
.
updateTimestamp
=
-
1
;
console
.
dir
(
qs
);
console
.
dir
(
qs
);
const
count
=
await
db
.
collection
(
'recognition'
).
count
(
qs
);
const
count
=
await
db
.
collection
(
'recognition'
).
count
(
qs
);
db
db
.
collection
(
'recognition'
)
.
collection
(
'recognition'
)
.
find
(
qs
)
.
find
(
qs
)
.
sort
(
{
updateTimestamp
:
-
1
}
)
.
sort
(
sort
)
.
skip
(
parseInt
(
skip
*
limit
))
.
skip
(
parseInt
(
skip
*
limit
))
.
limit
(
parseInt
(
limit
))
.
limit
(
parseInt
(
limit
))
.
toArray
(
async
(
err
,
rep
)
=>
{
.
toArray
(
async
(
err
,
rep
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
"数据查询失败"
});
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
"数据查询失败"
});
const
arrs
=
await
getStars
(
rep
);
//const arrs = await getStars(rep);
let
_arrs
=
await
getSlots
(
arrs
);
let
_arrs
=
await
getSlots
(
rep
);
_arrs
=
_arrs
.
map
(
x
=>
{
x
.
score
=
{
score
:
x
.
score
||
0
};
return
x
;
});
if
(
called
==
'true'
)
_arrs
=
await
getTasks
(
_arrs
);
if
(
called
==
'true'
)
_arrs
=
await
getTasks
(
_arrs
);
res
.
send
({
status
:
"ok"
,
recognitions
:
_arrs
,
page
:
{
skip
:
skip
,
total
:
count
}
})
res
.
send
({
status
:
"ok"
,
recognitions
:
_arrs
,
page
:
{
skip
:
skip
,
total
:
count
}
})
});
});
...
@@ -154,6 +246,52 @@ router.get("/recognitions",function(req,res) {
...
@@ -154,6 +246,52 @@ router.get("/recognitions",function(req,res) {
});
});
});
});
router
.
get
(
"/dsprecognitions"
,
function
(
req
,
res
)
{
let
{
sessionID
,
limit
=
10
,
skip
=
0
,
date
=
null
,
start
,
end
,
called
=
'false'
}
=
req
.
query
;
checkSession
(
req
.
query
,
async
(
err
,
rep
)
=>
{
if
(
err
||
!
rep
)
return
res
.
status
(
500
).
json
({
error
:
"session错误,重新登录"
,
code
:
302
});
else
{
const
tokenID
=
rep
.
tokenID
;
if
(
date
)
{
start
=
(
end
=
date
);
}
let
sort
=
{};
let
qs
=
getTimeRange
({
start
,
end
,
key
:
'createdAt'
,
type
:
'millisecond'
});
//let qs = { updateTimestamp: { '$gt': parseInt(moment(date, 'YYYYMMDD').startOf('day').format('x')), '$lte': parseInt(moment(date, 'YYYYMMDD').endOf('day').format('x')) }, 'tokenInfo.tokenID': OID(tokenID) };
_
.
merge
(
qs
,
{
calledInfo
:
{
$exists
:
called
==
'true'
}
,
'tokenInfo.tokenID'
:
OID
(
tokenID
)
}
);
console
.
dir
(
qs
);
if
(
called
==
'true'
)
sort
.
calledTimestamp
=
-
1
;
else
sort
.
createdAt
=
-
1
;
const
count
=
await
db
.
collection
(
'dspRecognition'
).
count
(
qs
);
db
.
collection
(
'dspRecognition'
)
.
find
(
qs
,{
tags
:
0
})
.
sort
(
sort
)
.
skip
(
parseInt
(
skip
*
limit
))
.
limit
(
parseInt
(
limit
))
.
toArray
(
async
(
err
,
rep
)
=>
{
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
"数据查询失败"
});
let
_arrs
=
await
getCallGroupInfo
(
rep
);
res
.
send
({
status
:
"ok"
,
recognitions
:
_arrs
,
page
:
{
skip
:
skip
,
total
:
count
}
})
});
}
});
});
async
function
getCallGroupInfo
(
arrays
)
{
let
tasks
=
[];
arrays
.
forEach
((
x
)
=>
{
tasks
.
push
(
new
Promise
(
async
(
r
,
e
)
=>
{
const
GroupInfo
=
(
x
.
groupID
&&
exists
(
x
.
groupID
))
?
await
db
.
collection
(
"dspCallGroups"
)
.
findOne
({
_id
:
OID
(
x
.
groupID
)
},{
dspgroup
:
1
})
:
{
dspgroup
:
''
};
r
(
_
.
merge
(
x
,
{
dspgroup
:
(
GroupInfo
?
GroupInfo
.
dspgroup
:
''
)
}
));
}));
});
const
arrs
=
await
Promise
.
all
(
tasks
);
return
arrs
;
}
async
function
getStars
(
arrays
)
{
async
function
getStars
(
arrays
)
{
let
tasks
=
[];
let
tasks
=
[];
...
@@ -254,7 +392,7 @@ async function checkBill(data, callback) {
...
@@ -254,7 +392,7 @@ async function checkBill(data, callback) {
callback
&&
callback
();
callback
&&
callback
();
}
}
async
function
updateBill
(
data
,
callback
)
{
/*
async function updateBill(data, callback) {
if(!notEmpty(data)) return callback('params wrong');
if(!notEmpty(data)) return callback('params wrong');
let { pre, number, accountID, type, taskID } = data;
let { pre, number, accountID, type, taskID } = data;
if(!/^[0-9a-z]{24}$/.test(accountID) ) return callback('参数错误');
if(!/^[0-9a-z]{24}$/.test(accountID) ) return callback('参数错误');
...
@@ -264,6 +402,23 @@ async function updateBill(data, callback) {
...
@@ -264,6 +402,23 @@ async function updateBill(data, callback) {
if (err) return callback(err);
if (err) return callback(err);
callback && callback(null, rep);
callback && callback(null, rep);
});
});
}*/
async
function
updateBill
(
data
,
callback
)
{
if
(
!
notEmpty
(
data
))
return
callback
(
'params wrong'
);
let
{
pre
,
number
,
accountID
,
type
,
taskID
,
fromID
=
'self'
,
groupID
,
preNum
=
30
}
=
data
;
if
(
!
/^
[
0-9a-z
]{24}
$/
.
test
(
accountID
)
)
return
callback
(
'params wrong'
);
let
_data
=
{
pre
,
number
,
accountID
:
OID
(
accountID
),
fromID
,
type
};
if
(
groupID
)
{
_data
.
groupID
=
OID
(
groupID
);
}
_data
.
taskID
=
OID
(
taskID
);
db
.
collection
(
'bills'
)
.
insert
(
wrapTime
(
_data
,
true
),
(
err
,
rep
)
=>
{
if
(
err
)
return
callback
(
err
);
callback
&&
callback
(
null
,
rep
);
});
}
}
async
function
getBillByAccount
(
accountID
)
{
async
function
getBillByAccount
(
accountID
)
{
...
@@ -305,16 +460,11 @@ async function getRechargeByAccount(accountID) {
...
@@ -305,16 +460,11 @@ async function getRechargeByAccount(accountID) {
return
(
(
recharges
&&
recharges
.
length
)
?
recharges
[
0
].
sum
:
0
);
return
(
(
recharges
&&
recharges
.
length
)
?
recharges
[
0
].
sum
:
0
);
}
}
async
function
getCallConsumeByUnikey
(
unikey
,
callback
)
{
async
function
getCallConsumeByUnikey
(
unikey
,
callback
)
{
const
price
=
db
.
collection
(
'price'
).
findOne
({
type
:
'call'
});
const
price
=
db
.
collection
(
'price'
).
findOne
({
type
:
'call'
});
let
number
=
(
price
&&
price
.
number
)
?
price
.
number
:
1
;
let
number
=
(
price
&&
price
.
number
)
?
price
.
number
:
1
;
const
task
=
db
.
collection
(
'callTask'
).
findOne
({
unikey
});
//const task = db.collection('callTask').findOne({ unikey });
if
(
!
task
)
{
callback
(
null
,
{
number
:
Math
.
ceil
((
EXPIRATION
/
60
)
)
*
number
});
callback
(
null
,
{
number
:
3
+
Math
.
ceil
((
EXPIRATION
/
60
)
-
1
)
*
number
});
}
else
{
callback
(
null
,
{
number
:
Math
.
ceil
((
EXPIRATION
/
60
)
)
*
number
});
}
}
}
async
function
getTasks
(
arrays
)
{
async
function
getTasks
(
arrays
)
{
...
@@ -374,5 +524,8 @@ function getTimeRange({ start, end, type, key}) {
...
@@ -374,5 +524,8 @@ function getTimeRange({ start, end, type, key}) {
}
}
}
}
}
}
function
exists
(
ID
)
{
return
ID
!==
undefined
&&
ID
!==
null
&&
ID
!==
'null'
&&
ID
!==
''
&&
ID
!==
'all'
&&
ID
!==
'undefined'
;
}
module
.
exports
=
router
;
module
.
exports
=
router
;
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