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
yyq
7 years ago
Commit
aa4a5c146486a212ab0282a729c1e3ade842873a
1 parent
cba2f246
add status
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
13 deletions
apps/activity/models/zero-buy.js
apps/admin/models/activity.js
migrations/20180810104355.sql
migrations/index.js
apps/activity/models/zero-buy.js
View file @
aa4a5c1
...
...
@@ -51,8 +51,15 @@ function getActivityStatus(info = {}, num, now) {
}
else
{
resStatus
=
2
;
// 活动已开始
if
(
now
>
info
.
end_time
||
num
>=
info
.
limit
)
{
// 当传入参与人数时以参与人数为准
if
(
num
>=
info
.
limit
)
{
// 参与人数达到活动限制人数
resStatus
=
3
;
// 活动已结束
}
else
if
(
now
>
info
.
end_time
)
{
if
(
info
.
is_full
>
0
)
{
resStatus
=
3
;
// 活动已结束
}
else
{
resStatus
=
5
;
// 人数未达到,活动失败
}
}
else
if
(
now
<
info
.
start_time
)
{
resStatus
=
1
;
// 活动未开始
}
...
...
@@ -116,16 +123,27 @@ module.exports = class extends global.yoho.BaseModel {
const
page
=
parseInt
(
extra
.
page
,
10
)
||
1
;
let
limit
=
`
$
{(
page
-
1
)
*
PAGE_SIZE
},
$
{
PAGE_SIZE
}
`
;
let
now
=
new
Date
().
getTime
()
/
1000
;
uid
=
parseInt
(
uid
,
10
)
||
0
;
return
mysqlCli
.
query
(
`
select
u
.
*
,
p
.
name
,
p
.
price
,
p
.
status
,
p
.
cover_img
,
p
.
start_time
,
p
.
end_time
from
let
where
=
''
;
if
(
extra
.
type
)
{
where
=
'(p.status = 2 or (p.is_full = 0 and p.end_time <= :now))'
;
}
else
{
where
=
'(p.status < 2 != (p.is_full = 0 and p.end_time <= :now))'
;
}
return
mysqlCli
.
query
(
`
select
u
.
*
,
p
.
name
,
p
.
price
,
p
.
status
,
p
.
cover_img
,
p
.
start_time
,
p
.
end_time
,
p
.
is_full
from
$
{
TABLE_ACT_PRIZE_PRODUCT_USER
}
u
left
join
$
{
TABLE_ACT_PRIZE_PRODUCT
}
p
on
u
.
act_prize_id
=
p
.
id
where
u
.
act_id
=
:
actId
and
u
.
uid
=
:
uid
and
p
.
status
$
{
+
extra
.
type
?
'='
:
'<'
}
2
where
u
.
act_id
=
:
actId
and
u
.
uid
=
:
uid
and
$
{
where
}
order
by
u
.
create_time
desc
limit
$
{
limit
}
`
,
{
uid
,
actId
actId
,
now
}).
then
(
result
=>
{
return
handelResult
(
handelActivityList
(
result
));
});
...
...
@@ -297,8 +315,15 @@ module.exports = class extends global.yoho.BaseModel {
};
let
productInfo
=
_
.
get
(
info
,
'[0][0]'
);
let
joinNum
=
_
.
get
(
info
,
'[1].join_num'
,
0
);
// 参与人数满时更新活动状态
if
(
+
info
.
is_full
===
0
&&
joinNum
>=
info
.
limit
)
{
mysqlCli
.
update
(
`
update
$
{
TABLE_ACT_PRIZE_PRODUCT
}
set
is_full
=
1
where
id
=
:
actPrizeId
and
is_full
=
0
limit
1
`
,
{
actPrizeId
});
}
let
status
=
getActivityStatus
(
productInfo
,
_
.
get
(
info
,
'[1].join_num'
,
0
)
);
let
status
=
getActivityStatus
(
productInfo
,
joinNum
);
if
(
!
status
||
status
>=
3
)
{
return
errorData
;
...
...
apps/admin/models/activity.js
View file @
aa4a5c1
...
...
@@ -732,12 +732,9 @@ class AdminModel extends global.yoho.BaseModel {
});
}
/**
* 向参加活动用户发送开奖消息
* @param uid
* @param actPrizeId
* @param extra
* @param id
* @returns {*}
*/
async
sendWechatMessage
(
id
)
{
...
...
@@ -774,11 +771,24 @@ class AdminModel extends global.yoho.BaseModel {
}
});
if
(
!
msgApi
.
length
)
{
return
Promise
.
resolve
();
return
this
.
batchSend
(
msgApi
);
}
/**
* 分批发送模板消息
* @param apis
* @returns {*}
*/
batchSend
(
apis
)
{
if
(
_
.
isEmpty
(
apis
))
{
return
;
}
return
Promise
.
all
(
msgApi
);
setTimeout
(()
=>
{
this
.
batchSend
(
_
.
drop
(
apis
,
20
));
},
1000
);
return
Promise
.
all
(
_
.
take
(
apis
,
20
));
}
}
...
...
migrations/20180810104355.sql
0 → 100644
View file @
aa4a5c1
/*
true
@author: yyq <kingcoon@163.com>
@date: 2018-08-10 10:43:55
*/
#
注意:
GO
;
分割执行块
ALTER
TABLE
act_prize_product
ADD
`is_full`
TINYINT
DEFAULT
0
comment
'是否参与活动人数已满'
;
GO
;
...
...
migrations/index.js
View file @
aa4a5c1
module
.
exports
=
[
'_migration'
,
'20170913102356'
,
'20170927092926'
,
'20171025145423'
,
'20171102104558'
,
'20171115144710'
,
'20180131104311'
,
'20180402134610'
,
'20180413105509'
,
'20180719134813'
];
module
.
exports
=
[
'_migration'
,
'20170913102356'
,
'20170927092926'
,
'20171025145423'
,
'20171102104558'
,
'20171115144710'
,
'20180131104311'
,
'20180402134610'
,
'20180413105509'
,
'20180719134813'
,
'20180810104355'
];
...
...
Please
register
or
login
to post a comment