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
c2442c60
Commit
c2442c60
authored
Apr 25, 2018
by
刘松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
7dcc9b08
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
30 deletions
+111
-30
Dockerfile
Dockerfile
+1
-1
index.js
api/index.js
+93
-21
Login.vue
src/components/Login.vue
+1
-1
Main.vue
src/components/Main.vue
+7
-6
numbers.js
src/store/modules/numbers.js
+9
-1
No files found.
Dockerfile
View file @
c2442c60
### Health check 'curl /ping'
### Health check 'curl /ping'
FROM
node:latest
FROM
reg.yunpro.cn/library/node:9.11.1
WORKDIR
/app
WORKDIR
/app
ADD
./package.json /app/
ADD
./package.json /app/
#front end
#front end
...
...
api/index.js
View file @
c2442c60
...
@@ -8,7 +8,7 @@ const moment = require('moment');
...
@@ -8,7 +8,7 @@ const moment = require('moment');
const
adminID
=
process
.
env
.
NODE_ENV
===
'production'
?
'5a9f9e6b46da1176a40e1082'
:
'5ab083b1f6134d82b40d95f2'
;
const
adminID
=
process
.
env
.
NODE_ENV
===
'production'
?
'5a9f9e6b46da1176a40e1082'
:
'5ab083b1f6134d82b40d95f2'
;
let
db
=
{};
let
db
=
{};
const
dbpath
=
process
.
env
.
MONGO
||
"mongodb://
localhost
:27017/remarketing"
;
const
dbpath
=
process
.
env
.
MONGO
||
"mongodb://
127.0.0.1
:27017/remarketing"
;
const
salt
=
",tom"
;
const
salt
=
",tom"
;
const
EXPIRATION
=
60
*
30
;
const
EXPIRATION
=
60
*
30
;
// TODO ! put into init
// TODO ! put into init
...
@@ -24,14 +24,13 @@ MongoClient.connect(dbpath, (err, conn) => {
...
@@ -24,14 +24,13 @@ MongoClient.connect(dbpath, (err, conn) => {
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
)
res
.
status
(
500
).
json
({
error
:
err
});
if
(
err
)
re
turn
re
s
.
status
(
500
).
json
({
error
:
err
});
if
(
data
&&
data
.
number
)
{
if
(
data
&&
data
.
number
)
{
console
.
dir
(
data
)
checkBill
({
accountID
:
pubID
,
number
:
data
.
number
},(
_err
)
=>
{
checkBill
({
accountID
:
pubID
,
number
:
data
.
number
},(
_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
.
s
endStatus
(
500
);
if
(
!
notEmpty
(
req
.
body
))
res
.
s
tatus
(
500
).
json
({
error
:
"参数错误"
}
);
else
{
else
{
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/bind/"
+
pubID
+
'/'
+
slotID
+
'?caller='
+
phone
+
'&unikey='
+
unikey
+
'&expiration='
+
expiration
;
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/bind/"
+
pubID
+
'/'
+
slotID
+
'?caller='
+
phone
+
'&unikey='
+
unikey
+
'&expiration='
+
expiration
;
axios
(
host
,
{
axios
(
host
,
{
...
@@ -39,14 +38,15 @@ router.post('/job/call',function (req,res) {
...
@@ -39,14 +38,15 @@ router.post('/job/call',function (req,res) {
headers
:
{
"Content-Type"
:
"application/json"
},
headers
:
{
"Content-Type"
:
"application/json"
},
timeout
:
300000
timeout
:
300000
})
})
.
then
(
rep
=>
{
.
then
(
async
rep
=>
{
console
.
dir
(
rep
.
data
);
console
.
dir
(
rep
);
if
(
rep
.
data
&&
rep
.
data
.
called
&&
rep
.
data
.
_id
){
if
(
rep
.
data
&&
rep
.
data
.
called
&&
rep
.
data
.
_id
&&
rep
.
data
.
bindID
){
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
,
type
:
'call'
,
taskID
:
rep
.
data
.
_id
},
(
err
,
_rep
)
=>
{
if
(
err
)
{
if
(
err
)
{
// log 代码;
// log 代码;
}
}
res
.
send
({
status
:
'ok'
,
called
:
rep
.
data
.
called
})
res
.
send
({
status
:
'ok'
,
called
:
rep
.
data
.
called
,
bindID
:
rep
.
data
.
bindID
});
});
});
}
}
else
{
else
{
...
@@ -54,7 +54,8 @@ router.post('/job/call',function (req,res) {
...
@@ -54,7 +54,8 @@ router.post('/job/call',function (req,res) {
}
}
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
if
(
err
)
return
res
.
sendStatus
(
500
);
console
.
dir
(
err
)
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'参数错误,取号失败'
});
});
});
}
}
}
}
...
@@ -65,15 +66,34 @@ router.post('/job/call',function (req,res) {
...
@@ -65,15 +66,34 @@ router.post('/job/call',function (req,res) {
});
});
});
});
router
.
get
(
'/unbind'
,
function
(
req
,
res
)
{
const
{
bindID
}
=
req
.
query
;
const
host
=
"http://remarketing-job-yh.yoo.yunpro.cn/unbind?bindID="
+
bindID
;
axios
(
host
,
{
method
:
"GET"
,
headers
:
{
"Content-Type"
:
"application/json"
},
timeout
:
300000
})
.
then
(
rep
=>
{
console
.
dir
(
rep
);
res
.
send
({
status
:
'ok'
,
data
:
rep
});
})
.
catch
(
err
=>
{
console
.
dir
(
err
);
if
(
err
)
return
res
.
status
(
500
).
json
({
error
:
'解绑错误'
});
});
});
router
.
post
(
'/login'
,
async
function
(
req
,
res
)
{
router
.
post
(
'/login'
,
async
function
(
req
,
res
)
{
//token phone sessionID
//token phone sessionID
checkSession
(
req
.
body
,
(
err
,
rep
)
=>
{
checkSession
(
req
.
body
,
(
err
,
rep
)
=>
{
if
(
err
)
return
res
.
s
endStatus
(
500
);
if
(
err
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"查询失败"
}
);
if
(
!
rep
)
{
if
(
!
rep
)
{
//没有符合的session
//没有符合的session
return
authorize
(
req
.
body
,
(
err
,
rep
)
=>
{
return
authorize
(
req
.
body
,
(
err
,
rep
)
=>
{
if
(
err
)
return
res
.
s
endStatus
(
500
);
if
(
err
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"查询账户失败"
}
);
if
(
!
rep
)
return
res
.
s
endStatus
(
403
);
if
(
!
rep
)
return
res
.
s
tatus
(
403
).
json
({
error
:
"账户不存在"
}
);
//验证通过
//验证通过
const
token
=
_
.
merge
(
rep
,
{
sessionID
:
genSessionID
(
rep
.
_id
)
});
const
token
=
_
.
merge
(
rep
,
{
sessionID
:
genSessionID
(
rep
.
_id
)
});
delete
token
.
token
;
delete
token
.
token
;
...
@@ -83,7 +103,7 @@ router.post('/login',async function (req,res) {
...
@@ -83,7 +103,7 @@ router.post('/login',async function (req,res) {
db
db
.
collection
(
"tokens"
)
.
collection
(
"tokens"
)
.
findOne
({
_id
:
OID
(
rep
.
tokenID
)
},
(
err
,
rep
)
=>
{
.
findOne
({
_id
:
OID
(
rep
.
tokenID
)
},
(
err
,
rep
)
=>
{
if
(
err
||
!
rep
)
return
res
.
s
endStatus
(
500
);
if
(
err
||
!
rep
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"查询账户失败"
}
);
const
token
=
_
.
merge
(
rep
,
{
sessionID
:
req
.
body
.
sessionID
});
const
token
=
_
.
merge
(
rep
,
{
sessionID
:
req
.
body
.
sessionID
});
delete
token
.
token
;
delete
token
.
token
;
delete
token
.
passwd
;
delete
token
.
passwd
;
...
@@ -98,19 +118,24 @@ router.post("/logout",function(req,res) {
...
@@ -98,19 +118,24 @@ router.post("/logout",function(req,res) {
db
db
.
collection
(
'tokenSession'
)
.
collection
(
'tokenSession'
)
.
remove
({
_id
:
OID
(
sessionID
)
},
(
err
,
rep
)
=>
{
.
remove
({
_id
:
OID
(
sessionID
)
},
(
err
,
rep
)
=>
{
if
(
err
||
!
rep
)
return
res
.
s
endStatus
(
500
);
if
(
err
||
!
rep
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"更新session新失败"
}
);
res
.
send
({
status
:
"ok"
,
rep
});
res
.
send
({
status
:
"ok"
,
rep
});
});
});
});
});
router
.
get
(
"/recognitions"
,
function
(
req
,
res
)
{
router
.
get
(
"/recognitions"
,
function
(
req
,
res
)
{
let
{
sessionID
,
limit
=
10
,
skip
=
0
,
date
,
called
=
'false'
}
=
req
.
query
;
let
{
sessionID
,
limit
=
10
,
skip
=
0
,
date
=
null
,
start
,
end
,
called
=
'false'
}
=
req
.
query
;
checkSession
(
req
.
query
,
async
(
err
,
rep
)
=>
{
checkSession
(
req
.
query
,
async
(
err
,
rep
)
=>
{
if
(
err
||
!
rep
)
return
res
.
s
endStatus
(
500
);
if
(
err
||
!
rep
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"session错误,重新登录"
,
code
:
302
}
);
else
{
else
{
const
tokenID
=
rep
.
tokenID
;
const
tokenID
=
rep
.
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
)
};
if
(
date
)
{
_
.
merge
(
qs
,
{
calledInfo
:
{
$exists
:
called
==
'true'
}
}
);
start
=
(
end
=
date
);
}
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) };
_
.
merge
(
qs
,
{
calledInfo
:
{
$exists
:
called
==
'true'
}
,
'tokenInfo.tokenID'
:
OID
(
tokenID
)
}
);
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'
)
...
@@ -119,9 +144,10 @@ router.get("/recognitions",function(req,res) {
...
@@ -119,9 +144,10 @@ router.get("/recognitions",function(req,res) {
.
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
.
s
endStatus
(
500
);
if
(
err
)
return
res
.
s
tatus
(
500
).
json
({
error
:
"数据查询失败"
}
);
const
arrs
=
await
getStars
(
rep
);
const
arrs
=
await
getStars
(
rep
);
const
_arrs
=
await
getSlots
(
arrs
);
let
_arrs
=
await
getSlots
(
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
}
})
});
});
}
}
...
@@ -168,7 +194,7 @@ function md5token(str) {
...
@@ -168,7 +194,7 @@ function md5token(str) {
}
}
function
checkSession
(
data
,
callback
)
{
function
checkSession
(
data
,
callback
)
{
if
(
!
data
.
sessionID
)
return
callback
(
null
);
if
(
!
data
.
sessionID
||
!
/^
[
0-9a-z
]{24}
$/
.
test
(
data
.
sessionID
)
)
return
callback
(
null
);
db
db
.
collection
(
"tokenSession"
)
.
collection
(
"tokenSession"
)
.
findOne
({
sessionID
:
OID
(
data
.
sessionID
)
},
(
err
,
rep
)
=>
{
.
findOne
({
sessionID
:
OID
(
data
.
sessionID
)
},
(
err
,
rep
)
=>
{
...
@@ -291,6 +317,31 @@ async function getCallConsumeByUnikey(unikey,callback) {
...
@@ -291,6 +317,31 @@ async function getCallConsumeByUnikey(unikey,callback) {
}
}
}
}
async
function
getTasks
(
arrays
)
{
let
_tasks
=
[];
arrays
.
forEach
((
x
)
=>
{
_tasks
.
push
(
new
Promise
(
async
(
r
,
e
)
=>
{
if
(
x
.
calledInfo
&&
x
.
calledInfo
.
length
)
{
let
tasks
=
[];
x
.
calledInfo
.
forEach
((
y
)
=>
{
tasks
.
push
(
new
Promise
(
async
(
r
,
e
)
=>
{
const
TaskInfo
=
(
y
.
taskID
&&
exsists
(
y
.
taskID
))
?
await
db
.
collection
(
"callTask"
)
.
findOne
({
_id
:
OID
(
y
.
taskID
)
},{
startTime
:
1
})
:
{
startTime
:
-
1
};
r
(
_
.
merge
(
y
,
{
TaskInfo
}
));
}));
});
const
arrs
=
await
Promise
.
all
(
tasks
);
x
.
calledInfo
=
arrs
;
}
r
(
x
);
}));
});
const
_arr
=
await
Promise
.
all
(
_tasks
);
return
_arr
;
}
function
OID
(
str
)
{
function
OID
(
str
)
{
return
typeof
str
===
'string'
?
mongodb
.
ObjectID
(
str
)
:
str
;
return
typeof
str
===
'string'
?
mongodb
.
ObjectID
(
str
)
:
str
;
}
}
...
@@ -299,4 +350,25 @@ function wrapTime(obj) {
...
@@ -299,4 +350,25 @@ function wrapTime(obj) {
return
_
.
merge
(
obj
,
{
createdAt
:
new
Date
()
})
return
_
.
merge
(
obj
,
{
createdAt
:
new
Date
()
})
}
}
async
function
getFromID
(
accountID
)
{
const
account
=
await
db
.
collection
(
'account'
).
findOne
({
_id
:
OID
(
accountID
)
});
return
(
account
&&
account
.
fromID
?
account
.
fromID
:
'self'
);
}
function
getTimeRange
({
start
,
end
,
type
,
key
})
{
if
(
/^
[
0-9
]{8}
$/
.
test
(
start
)
&&
/^
[
0-9
]{8}
$/
.
test
(
end
)
)
{
if
(
type
===
'millisecond'
)
{
return
{
[
key
]:
{
'$gt'
:
parseInt
(
moment
(
start
,
'YYYYMMDD'
).
startOf
(
'day'
).
format
(
'x'
)),
'$lte'
:
parseInt
(
moment
(
end
,
'YYYYMMDD'
).
endOf
(
'day'
).
format
(
'x'
))
}
};
}
else
{
return
{
[
key
]:
{
'$gt'
:
moment
(
start
,
'YYYYMMDD'
).
startOf
(
'day'
).
toDate
(),
'$lte'
:
moment
(
end
,
'YYYYMMDD'
).
endOf
(
'day'
).
toDate
()
}
};
}
}
else
{
if
(
type
===
'millisecond'
)
{
return
{
[
key
]:
{
'$gt'
:
parseInt
(
moment
().
add
(
-
7
,
'days'
).
startOf
(
'day'
).
format
(
'x'
)),
'$lte'
:
parseInt
(
moment
().
endOf
(
'day'
).
format
(
'x'
))
}
};
}
else
{
return
{
[
key
]:
{
'$gt'
:
moment
().
add
(
-
7
,
'days'
).
startOf
(
'day'
).
toDate
(),
'$lte'
:
moment
().
endOf
(
'day'
).
toDate
()
}
};
}
}
}
module
.
exports
=
router
;
module
.
exports
=
router
;
src/components/Login.vue
View file @
c2442c60
...
@@ -23,7 +23,7 @@ export default {
...
@@ -23,7 +23,7 @@ export default {
methods
:
{
methods
:
{
onSubmit
()
{
onSubmit
()
{
const
{
phone
,
token
}
=
this
.
form
;
const
{
phone
,
token
}
=
this
.
form
;
if
(
/
[
0-9
]{11}
$/
.
test
(
phone
)
&&
/
[
a-z0-9
]{
9
}
$/
.
test
(
token
))
{
if
(
/
[
0-9
]{11}
$/
.
test
(
phone
)
&&
/
[
a-z0-9
]{
1,
}
$/
.
test
(
token
))
{
this
.
login
({
phone
,
token
,
callback
:
this
.
reqCallback
});
this
.
login
({
phone
,
token
,
callback
:
this
.
reqCallback
});
}
else
{
}
else
{
Toast
({
Toast
({
...
...
src/components/Main.vue
View file @
c2442c60
...
@@ -44,11 +44,12 @@
...
@@ -44,11 +44,12 @@
<div
class=
"dia-wrap"
>
<div
class=
"dia-wrap"
>
<div
class=
"inner"
>
<div
class=
"inner"
>
<h3><pre><i
class=
"fa fa-user-times fa-lg"
></i>
{{
" 来源:"
+
item
.
slot
.
slotName
}}
</pre></h3>
<h3><pre><i
class=
"fa fa-user-times fa-lg"
></i>
{{
" 来源:"
+
item
.
slot
.
slotName
}}
</pre></h3>
<mt-button
type=
"
default"
size=
"small"
disabled
>
已
拨打
</mt-button>
<mt-button
type=
"
primary"
size=
"small"
@
click=
"call(item)"
>
一键
拨打
</mt-button>
</div>
</div>
<div
class=
"inner-bottom"
>
<div
class=
"inner-bottom"
>
<span><pre>
{{
"拨打时间:"
+
item
.
updateCalledTimestamp
}}
</pre></span>
<span><pre>
{{
"最近:"
+
item
.
startTime
}}
</pre></span>
<span><pre>
{{
"营销指数:"
+
(
item
.
score
.
score
<
0
?
0
:
item
.
score
.
score
)
}}
</pre></span>
<span><pre>
{{
"次数:"
+
item
.
times
}}
</pre></span>
<span><pre>
{{
"指数:"
+
(
item
.
score
.
score
<
0
?
0
:
item
.
score
.
score
)
}}
</pre></span>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -261,7 +262,7 @@ export default {
...
@@ -261,7 +262,7 @@ export default {
return
this
.
$store
.
state
.
session
.
currentUser
.
role
===
1
;
return
this
.
$store
.
state
.
session
.
currentUser
.
role
===
1
;
},
},
startDate
()
{
startDate
()
{
return
moment
().
add
(
-
3
0
,
'days'
).
toDate
();
return
moment
().
add
(
-
10
0
,
'days'
).
toDate
();
},
},
endDate
()
{
endDate
()
{
return
moment
().
toDate
();
return
moment
().
toDate
();
...
@@ -306,8 +307,8 @@ export default {
...
@@ -306,8 +307,8 @@ export default {
closeOnClickModal
:
false
,
closeOnClickModal
:
false
,
popupVisible
:
false
,
popupVisible
:
false
,
selected
:
'tasks'
,
selected
:
'tasks'
,
currentDate
:
'20180130'
,
currentDate
:
moment
().
format
(
'YYYYMMDD'
)
,
currentDateCalled
:
'20180130'
,
//moment().format('YYYYMMDD')
currentDateCalled
:
moment
().
format
(
'YYYYMMDD'
)
,
//moment().format('YYYYMMDD')
target
:
''
,
target
:
''
,
};
};
},
},
...
...
src/store/modules/numbers.js
View file @
c2442c60
...
@@ -36,7 +36,15 @@ const getters = {
...
@@ -36,7 +36,15 @@ const getters = {
},
},
getCalledConsumers
()
{
getCalledConsumers
()
{
console
.
dir
(
state
.
calledNumbers
)
console
.
dir
(
state
.
calledNumbers
)
return
state
.
calledNumbers
;
return
state
.
calledNumbers
.
map
(
x
=>
{
if
(
x
.
calledInfo
&&
x
.
calledInfo
.
length
)
{
const
last
=
x
.
calledInfo
[
x
.
calledInfo
.
length
-
1
];
console
.
dir
(
last
);
x
.
startTime
=
last
.
TaskInfo
&&
last
.
TaskInfo
.
startTime
>
0
?
moment
(
last
.
TaskInfo
.
startTime
,
'x'
).
format
(
'YYYY/MM/DD HH:mm'
)
:
'未知'
;
}
x
.
times
=
x
.
calledInfo
.
length
;
return
x
;
});
},
},
getConsumersLoading
()
{
getConsumersLoading
()
{
return
state
.
numbersLoading
;
return
state
.
numbersLoading
;
...
...
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