Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
9bcf31a3
Commit
9bcf31a3
authored
Apr 29, 2016
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
4f2e1269
'
parents
4e5f38f8
4f2e1269
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
256 additions
and
12 deletions
+256
-12
forumUser.js
app/controllers/mobile/forumUser.js
+127
-0
httpService.js
app/service/httpService.js
+61
-10
user.js
app/utils/user.js
+68
-2
No files found.
app/controllers/mobile/forumUser.js
View file @
9bcf31a3
...
@@ -509,3 +509,130 @@ router.get('/user/getUserFavorWithThreadAndInfo', function(req, res, next) {
...
@@ -509,3 +509,130 @@ router.get('/user/getUserFavorWithThreadAndInfo', function(req, res, next) {
}
}
});
});
});
});
//查看总经验排行
router
.
get
(
'/user/exp/topChart'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
ent_code
=
req
.
session
.
user
.
ent_code
;
forumUserService
.
getByConditionsSelectyField
({
_id
:
userId
},
'mid'
,
function
(
err
,
doc
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
if
(
!
doc
.
mid
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
DATA_NOTEXITS
);
}
else
{
async
.
parallel
([
function
(
cb
)
{
user
.
getMemberExp
(
ent_code
,
doc
.
mid
,
3
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
},
function
(
cb
)
{
user
.
getMemberExpTopChart
(
ent_code
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{
user
:
results
[
0
],
list
:
results
[
1
]
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
//查看月经验排行
router
.
get
(
'/user/exp/topMonthChart'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
ent_code
=
req
.
session
.
user
.
ent_code
;
forumUserService
.
getByConditionsSelectyField
({
_id
:
userId
},
'mid'
,
function
(
err
,
doc
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
if
(
!
doc
.
mid
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
DATA_NOTEXITS
);
}
else
{
async
.
parallel
([
function
(
cb
)
{
user
.
getMemberExp
(
ent_code
,
doc
.
mid
,
1
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
},
function
(
cb
)
{
user
.
getMemberExpTopMonthChart
(
ent_code
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{
user
:
results
[
0
],
list
:
results
[
1
]
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
//查看周经验排行
router
.
get
(
'/user/exp/topWeekChart'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
ent_code
=
req
.
session
.
user
.
ent_code
;
forumUserService
.
getByConditionsSelectyField
({
_id
:
userId
},
'mid'
,
function
(
err
,
doc
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
if
(
!
doc
.
mid
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
DATA_NOTEXITS
);
}
else
{
async
.
parallel
([
function
(
cb
)
{
user
.
getMemberExp
(
ent_code
,
doc
.
mid
,
2
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
},
function
(
cb
)
{
user
.
getMemberExpTopWeekChart
(
ent_code
,
function
(
err
,
entity
)
{
cb
(
err
,
entity
);
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{
user
:
results
[
0
],
list
:
results
[
1
]
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
\ No newline at end of file
app/service/httpService.js
View file @
9bcf31a3
...
@@ -6,6 +6,7 @@ var ACTION_KEY = {
...
@@ -6,6 +6,7 @@ var ACTION_KEY = {
'post'
:
'FORUM_THREAD_POST'
,
'post'
:
'FORUM_THREAD_POST'
,
'share'
:
'FORUM_THREAD_SHARE'
,
'share'
:
'FORUM_THREAD_SHARE'
,
'share_timeline'
:
'FORUM_THREAD_SHARE_TIMELINE'
,
'share_timeline'
:
'FORUM_THREAD_SHARE_TIMELINE'
,
'share_singlemessage'
:
'FORUM_THREAD_SHARE_SINGLEMESSAGE'
,
'comment'
:
'FORUM_THREAD_COMMENT'
,
'comment'
:
'FORUM_THREAD_COMMENT'
,
'thread_praise'
:
'FORUM_THREAD_PRAISE'
,
'thread_praise'
:
'FORUM_THREAD_PRAISE'
,
'comment_praise'
:
'FORUM_COMMENT_PRAISE'
,
'comment_praise'
:
'FORUM_COMMENT_PRAISE'
,
...
@@ -15,26 +16,76 @@ var ACTION_KEY = {
...
@@ -15,26 +16,76 @@ var ACTION_KEY = {
};
};
var
mongoose
=
require
(
'mongoose'
),
var
mongoose
=
require
(
'mongoose'
),
moment
=
require
(
'moment'
),
moment
=
require
(
'moment'
),
then
=
require
(
'thenjs'
);
then
=
require
(
'thenjs'
),
request
=
require
(
'request'
),
config
=
require
(
'../../config/config'
),
_
=
require
(
'lodash'
);
var
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
),
var
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
),
ForumUVLog
=
mongoose
.
model
(
'ForumUVLog'
),
ForumUVLog
=
mongoose
.
model
(
'ForumUVLog'
),
ForumShareLog
=
mongoose
.
model
(
'ForumShareLog'
),
ForumShareLog
=
mongoose
.
model
(
'ForumShareLog'
),
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
exports
.
sendRequest
=
function
(
ent_code
,
mid
,
action
,
messageid
,
integral
,
exp
)
{
function
paramSort
(
obj
){
console
.
log
(
'积分对象:'
,
obj
);
try
{
var
keys
=
_
.
map
(
obj
,
function
(
v
,
k
){
return
k
;
}).
sort
();
return
_
.
map
(
keys
,
function
(
n
){
return
(
obj
[
n
]
||
''
).
toString
();
}).
join
(
''
);
}
catch
(
e
){
console
.
log
(
'参数排序失败'
,
e
);
}
return
null
;
}
function
createSignature
(
str
){
var
signature
=
null
;
try
{
var
Buffer
=
require
(
"buffer"
).
Buffer
;
var
buf
=
new
Buffer
(
str
);
var
str
=
buf
.
toString
(
"binary"
);
return
require
(
"crypto"
).
createHash
(
"md5"
).
update
(
str
).
digest
(
"hex"
);
}
catch
(
e
){
console
.
log
(
'生成参数签名错误'
,
e
);
}
return
signature
;
}
exports
.
sendRequest
=
function
(
ent_code
,
mid
,
action
,
messageid
,
integral
,
exp
,
reason
)
{
/*var obj = {
tag: 'member',
key: 'forum',
action: ACTION_KEY[action],
mid: mid,
entcode: ent_code,
messageid: messageid || '',
integral: integral || 0,
exp: exp || 0
};
redis.lpush('adapter-redis-to-ons', JSON.stringify(obj), function(err, reply) {
if (err) {
console.error(err);
}
});*/
//使用 rabbitmq 提供的restful接口
var
obj
=
{
var
obj
=
{
tag
:
'member'
,
key
:
'forum'
,
action
:
ACTION_KEY
[
action
],
action
:
ACTION_KEY
[
action
],
mid
:
mid
,
mid
:
mid
,
entcode
:
ent_code
,
entCode
:
ent_code
,
messageid
:
messageid
||
''
,
integral
:
integral
||
0
,
integral
:
integral
||
0
,
exp
:
exp
||
0
exp
:
exp
||
0
,
reason
:
reason
||
''
};
};
redis
.
lpush
(
'adapter-redis-to-ons'
,
JSON
.
stringify
(
obj
),
function
(
err
,
reply
)
{
//将参数排序
if
(
err
)
{
obj
.
signature
=
createSignature
(
paramSort
(
obj
));
//接口调用参数签名
console
.
error
(
err
);
request
.
post
({
url
:
config
.
rest_api
+
'/v1.0/internal/taskcenter/integral/change'
,
json
:
obj
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
}
});
});
};
};
...
...
app/utils/user.js
View file @
9bcf31a3
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
var
request
=
require
(
'request'
);
var
request
=
require
(
'request'
);
var
env
=
process
.
env
.
NODE_ENV
;
var
env
=
process
.
env
.
NODE_ENV
;
var
API_ADDRESS
=
'http://localhost:808
0
'
;
var
API_ADDRESS
=
'http://localhost:808
2
'
;
if
(
env
==
'sandbox'
)
{
if
(
env
==
'sandbox'
)
{
API_ADDRESS
=
'http://rest.wxpai.cn'
;
API_ADDRESS
=
'http://rest.wxpai.cn'
;
}
else
if
(
env
==
'production'
)
{
}
else
if
(
env
==
'production'
)
{
...
@@ -111,4 +111,70 @@ exports.findMember=function(ent_code, mid, callback){
...
@@ -111,4 +111,70 @@ exports.findMember=function(ent_code, mid, callback){
callback
(
null
,
body
.
data
);
callback
(
null
,
body
.
data
);
}
}
});
});
}
}
\ No newline at end of file
exports
.
getMemberExp
=
function
(
ent_code
,
mid
,
type
,
callback
){
if
(
!
ent_code
||
!
mid
){
return
callback
&&
callback
(
null
,
null
);
}
var
url
=
API_ADDRESS
+
'/v1.0/internal/member/exp/getMemberInfo?mid='
+
mid
+
'&entCode='
+
ent_code
+
'&type='
+
type
;
request
.
get
({
url
:
url
,
json
:
{}
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
return
callback
&&
callback
(
null
,(
body
&&
body
.
data
)
||
null
);
});
};
exports
.
getMemberExpTopChart
=
function
(
ent_code
,
callback
){
if
(
!
ent_code
){
return
callback
&&
callback
(
null
,
null
);
}
var
url
=
API_ADDRESS
+
'/v1.0/internal/member/exp/all?entCode='
+
ent_code
;
request
.
get
({
url
:
url
,
json
:
{}
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
return
callback
&&
callback
(
null
,(
body
&&
body
.
data
)
||
null
);
});
};
exports
.
getMemberExpTopMonthChart
=
function
(
ent_code
,
callback
){
if
(
!
ent_code
){
return
callback
&&
callback
(
null
,
null
);
}
var
url
=
API_ADDRESS
+
'/v1.0/internal/member/exp/month?entCode='
+
ent_code
;
request
.
get
({
url
:
url
,
json
:
{}
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
return
callback
&&
callback
(
null
,(
body
&&
body
.
data
)
||
null
);
});
};
exports
.
getMemberExpTopWeekChart
=
function
(
ent_code
,
callback
){
if
(
!
ent_code
){
return
callback
&&
callback
(
null
,
null
);
}
var
url
=
API_ADDRESS
+
'/v1.0/internal/member/exp/week?entCode='
+
ent_code
;
request
.
get
({
url
:
url
,
json
:
{}
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
return
callback
&&
callback
(
null
,(
body
&&
body
.
data
)
||
null
);
});
};
\ No newline at end of file
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