|
@@ -26,17 +26,28 @@ function handelResult(result) { |
|
@@ -26,17 +26,28 @@ function handelResult(result) { |
26
|
}
|
26
|
}
|
27
|
|
27
|
|
28
|
function getActivityStatus(info = {}, num, now) {
|
28
|
function getActivityStatus(info = {}, num, now) {
|
29
|
- let resData = {
|
|
|
30
|
- isEnd: true
|
|
|
31
|
- };
|
29
|
+ const status = +info.status;
|
|
|
30
|
+ let resStatus = 0;
|
32
|
|
31
|
|
33
|
now = now || (new Date().getTime() / 1000);
|
32
|
now = now || (new Date().getTime() / 1000);
|
34
|
|
33
|
|
35
|
- if (!info.status || num >= info.limit || now >= info.end_time) {
|
|
|
36
|
- return resData;
|
34
|
+ if (!status) {
|
|
|
35
|
+ return resStatus;
|
37
|
}
|
36
|
}
|
38
|
|
37
|
|
39
|
- return {};
|
38
|
+ if (status === 2) {
|
|
|
39
|
+ resStatus = 4; // 活动已开奖
|
|
|
40
|
+ } else {
|
|
|
41
|
+ resStatus = 2; // 活动已开始
|
|
|
42
|
+
|
|
|
43
|
+ if (now > info.end_time || num >= info.limit) {
|
|
|
44
|
+ resStatus = 3; // 活动已结束
|
|
|
45
|
+ } else if (now < info.start_time) {
|
|
|
46
|
+ resStatus = 1; // 活动未开始
|
|
|
47
|
+ }
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ return resStatus;
|
40
|
}
|
51
|
}
|
41
|
|
52
|
|
42
|
module.exports = class extends global.yoho.BaseModel {
|
53
|
module.exports = class extends global.yoho.BaseModel {
|
|
@@ -131,7 +142,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
@@ -131,7 +142,7 @@ module.exports = class extends global.yoho.BaseModel { |
131
|
return Promise.resolve(handelResult(resData));
|
142
|
return Promise.resolve(handelResult(resData));
|
132
|
}
|
143
|
}
|
133
|
|
144
|
|
134
|
- return Promise.all([
|
145
|
+ let query = [
|
135
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
146
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
136
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {
|
147
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {
|
137
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
148
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
|
@@ -139,15 +150,34 @@ module.exports = class extends global.yoho.BaseModel { |
|
@@ -139,15 +150,34 @@ module.exports = class extends global.yoho.BaseModel { |
139
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
|
150
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
|
140
|
where act_prize_id = :actPrizeId;`, {actPrizeId}, {
|
151
|
where act_prize_id = :actPrizeId;`, {actPrizeId}, {
|
141
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
152
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
142
|
- })
|
|
|
143
|
- ]).then(result => {
|
|
|
144
|
- let [product, content] = result;
|
153
|
+ }),
|
|
|
154
|
+ this.getUserJoinNum(actPrizeId).then(result => {
|
|
|
155
|
+ return result.data;
|
|
|
156
|
+ })
|
|
|
157
|
+ ];
|
|
|
158
|
+
|
|
|
159
|
+ if (extra.uid) {
|
|
|
160
|
+ query.push(mysqlCli.query(`select count(*) as code_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
161
|
+ where act_prize_id = :actPrizeId and uid = :uid;`, {
|
|
|
162
|
+ actPrizeId,
|
|
|
163
|
+ uid: extra.uid
|
|
|
164
|
+ }));
|
|
|
165
|
+ }
|
|
|
166
|
+
|
|
|
167
|
+ return Promise.all(query).then(result => {
|
|
|
168
|
+ let [product, content, count] = result;
|
145
|
|
169
|
|
146
|
if (product && product.length) {
|
170
|
if (product && product.length) {
|
147
|
resData = product[0];
|
171
|
resData = product[0];
|
148
|
resData.content = _.sortBy(content || [], o => {
|
172
|
resData.content = _.sortBy(content || [], o => {
|
149
|
return o.sort;
|
173
|
return o.sort;
|
150
|
});
|
174
|
});
|
|
|
175
|
+
|
|
|
176
|
+ let joinNum = _.get(count, 'join_num', 0);
|
|
|
177
|
+
|
|
|
178
|
+ resData.joinNum = joinNum;
|
|
|
179
|
+ resData.status = getActivityStatus(resData, joinNum);
|
|
|
180
|
+ resData.myCodeNum = _.get(result, '[3][0].code_num', 0);
|
151
|
}
|
181
|
}
|
152
|
|
182
|
|
153
|
return resData;
|
183
|
return resData;
|
|
@@ -232,7 +262,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
@@ -232,7 +262,7 @@ module.exports = class extends global.yoho.BaseModel { |
232
|
|
262
|
|
233
|
let status = getActivityStatus(_.get(info, '[0][0]'), _.get(info, '[1].join_num', 0));
|
263
|
let status = getActivityStatus(_.get(info, '[0][0]'), _.get(info, '[1].join_num', 0));
|
234
|
|
264
|
|
235
|
- if (status.isEnd) {
|
265
|
+ if (!status || status >= 3) {
|
236
|
return errorData;
|
266
|
return errorData;
|
237
|
}
|
267
|
}
|
238
|
|
268
|
|