Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-activity-platform
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
李奇
6 years ago
Commit
11bbd163c5f250c3576c0cb1e4db4a1d38448b86
1 parent
23d628f7
中奖用户导出功能添加
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
48 deletions
apps/admin/controllers/wheel-surf.js
apps/admin/models/wheel-surf.js
apps/admin/router.js
apps/api/models/wheel-surf.js
public/vue/wheel-surf/prize-sent-list.vue
apps/admin/controllers/wheel-surf.js
View file @
11bbd16
...
...
@@ -3,8 +3,10 @@
* @author: leo <qi.li@yoho.cn>
* @date: 26/09/2018
*/
const
moment
=
require
(
'moment'
);
const
wheelSurfModel
=
require
(
'../models/wheel-surf'
);
const
valid
=
require
(
'../../../utils/validator'
);
const
{
excel_export
}
=
require
(
'../../../utils/excel'
);
const
whSurfController
=
{
entry
(
req
,
res
)
{
...
...
@@ -266,15 +268,42 @@ const whSurfController = {
userFind
:
async
function
(
req
,
res
)
{
let
obj
=
req
.
body
;
let
result
=
await
req
.
ctx
(
wheelSurfModel
).
userFind
(
obj
);
//
let result = await req.ctx(wheelSurfModel).userFind(obj);
return
res
.
json
({
code
:
200
,
data
:
{
list
:
result
[
1
],
total
:
result
[
0
]
}
data
:
{}
});
},
exportRecords
:
async
function
(
req
,
res
)
{
let
result
=
await
req
.
ctx
(
wheelSurfModel
).
exportRecords
(
req
.
query
.
actId
);
let
excelConf
=
{
name
:
'mysheet'
,
cols
:
[
'用户UID'
,
'奖品类型'
,
'奖品名称'
,
'中奖时间'
],
rows
:
[]
};
let
temp
=
[];
result
.
forEach
(
item
=>
{
temp
=
[];
temp
.
push
(
item
.
uid
);
temp
.
push
(
item
.
type
);
temp
.
push
(
item
.
name
);
temp
.
push
(
moment
(
+
item
.
time
).
format
(
'YYYY-MM-DD HH:mm:ss'
));
excelConf
.
rows
.
push
(
temp
);
});
return
excel_export
({
title
:
excelConf
.
cols
,
data
:
excelConf
.
rows
,
fileName
:
'ActivityUserList'
,
sheetName
:
excelConf
.
name
,
res
});
}
};
...
...
apps/admin/models/wheel-surf.js
View file @
11bbd16
...
...
@@ -29,49 +29,21 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
userFind
(
obj
)
{
let
pageNo
=
obj
.
pageNo
||
1
;
let
pageSize
=
obj
.
pageSize
||
20
;
}
obj
.
start
=
(
pageNo
-
1
)
*
pageSize
;
obj
.
page
=
pageSize
;
let
sql
=
`
select
u
.
uid
,
u
.
act_id
act_id
,
u
.
prize_id
prize_id
,
u
.
create_time
create_time
,
a
.
title
title
,
p
.
name
name
,
p
.
type
type
,
p
.
value
value
,
p
.
img
img
from
act_wheel_surf_user
u
,
act_wheel_surf_prize
p
,
activity
a
where
u
.
prize_id
=
p
.
id
and
u
.
act_id
=
:
act_id
and
a
.
id
=
:
act_id
`
;
let
arr
=
Object
.
keys
(
obj
);
let
countSql
=
`
select
count
(
1
)
total
from
act_wheel_surf_user
u
,
act_wheel_surf_prize
p
where
u
.
prize_id
=
p
.
id
and
u
.
act_id
=
:
act_id
`
;
arr
.
forEach
(
function
(
value
,
index
)
{
if
(
!
obj
[
value
])
{
return
;
}
switch
(
value
)
{
case
'type'
:
sql
+=
' and p.type=:type'
;
countSql
+=
' and p.type=:type'
;
break
;
case
'title'
:
sql
+=
' and a.title=:title'
;
break
;
case
'uid'
:
sql
+=
' and u.uid=:uid'
;
countSql
+=
' and u.uid=:uid'
;
break
;
case
'name'
:
sql
+=
' and p.name=:name'
;
countSql
+=
' and p.name=:name'
;
break
;
}
if
(
index
===
arr
.
length
-
1
)
{
sql
+=
' order by u.create_time desc limit :start, :page;'
;
}
async
exportRecords
(
actId
)
{
let
len
=
await
this
.
client
.
llenAsync
(
`
turntable
:
$
{
actId
}:
prize
:
user
`
);
return
this
.
client
.
lrangeAsync
(
`
turntable
:
$
{
actId
}:
prize
:
users
`
,
0
,
len
-
1
).
then
(
prizes
=>
{
return
prizes
.
map
(
prize
=>
{
prize
=
prize
.
split
(
':::'
);
return
{
uid
:
prize
[
0
],
type
:
prize
[
1
],
name
:
prize
[
2
],
time
:
prize
[
3
]
}
});
});
try
{
return
Promise
.
all
([
mysqlCli
.
query
(
countSql
,
obj
).
then
(
res
=>
{
return
res
[
0
].
total
}),
mysqlCli
.
query
(
sql
,
obj
)]);
}
catch
(
e
)
{
return
Promise
.
reject
({
code
:
305
,
result
:
false
,
msg
:
'服务错误,请稍等'
});
}
}
getActConf
(
actId
)
{
...
...
apps/admin/router.js
View file @
11bbd16
...
...
@@ -105,6 +105,7 @@ router.get('/wheelSurf/api/prize/list', wheelSurf.prizeFindByActId);
router
.
post
(
'/wheelSurf/api/prize/create'
,
wheelSurf
.
prizeCreate
);
router
.
post
(
'/wheelSurf/api/prize/update'
,
wheelSurf
.
prizeUpdate
);
router
.
post
(
'/wheelSurf/api/prize/userFind'
,
wheelSurf
.
userFind
);
router
.
get
(
'/wheelSurf/api/prize/exportRecords'
,
wheelSurf
.
exportRecords
);
router
.
get
(
'/wheelSurf/*'
,
wheelSurf
.
entry
);
...
...
apps/api/models/wheel-surf.js
View file @
11bbd16
...
...
@@ -308,7 +308,7 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
this
.
client
.
zaddAsync
(
`
turntable
:
$
{
obj
.
act_id
}:
user
:
$
{
obj
.
uid
}:
prize
`
,
score
,
`
$
{
JSON
.
stringify
(
getPrize
)}:::
$
{
score
}
`
),
this
.
client
.
lpushAsync
(
`
turntable
:
$
{
obj
.
act_id
}:
prize
:
users
`
,
`
$
{
obj
.
uid
}:::
$
{
prizeType
[
getPrize
.
type
]}
:::
$
{
getPrize
.
name
}
:::
$
{
JSON
.
stringify
(
getPrize
)
}
`
)
`
turntable
:
$
{
obj
.
act_id
}:
prize
:
users
`
,
`
$
{
obj
.
uid
}:::
$
{
prizeType
[
getPrize
.
type
]}
:::
$
{
getPrize
.
name
}
:::
$
{
score
}
`
)
]);
if
(
result
)
{
...
...
public/vue/wheel-surf/prize-sent-list.vue
View file @
11bbd16
...
...
@@ -109,7 +109,7 @@
this.list(params);
},
output() {
console.log('output')
window.open(`/admin/wheelSurf/api/prize/exportRecords?actId=${this.actId}`, '_blank');
}
},
created() {
...
...
Please
register
or
login
to post a comment