Authored by yyq

handel status

@@ -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
@@ -367,6 +367,7 @@ class AdminModel extends global.yoho.BaseModel { @@ -367,6 +367,7 @@ class AdminModel extends global.yoho.BaseModel {
367 return this.ctx.req.ctx(zerobuyModel).getList(-1, page, { 367 return this.ctx.req.ctx(zerobuyModel).getList(-1, page, {
368 noCache: true 368 noCache: true
369 }).then(result => { 369 }).then(result => {
  370 + console.log(result.data);
370 return result.data; 371 return result.data;
371 }); 372 });
372 } 373 }
@@ -17,6 +17,24 @@ @@ -17,6 +17,24 @@
17 </thead> 17 </thead>
18 18
19 <tbody class="article-list"> 19 <tbody class="article-list">
  20 + {{#each list}}
  21 + <tr class="even pointer">
  22 + <td class="text-center">{{id}}</td>
  23 + <td class="text-center">{{name}}</td>
  24 + <td class="text-center">{{repeatLimit}}</td>
  25 + <td class="text-center">{{voteLimit}}</td>
  26 + <td class="text-center">{{limit}}</td>
  27 + <td class="text-center">{{sort}}</td>
  28 + <td class="text-center">
  29 + <image src="{{cover_img}}">
  30 + </td>
  31 + <td class="text-center" data-id="{{id}}">
  32 + {{# btns}}
  33 + <button class="btn btn-danger btn-{{type}}">{{name}}</button>
  34 + {{/ btns}}
  35 + </td>
  36 + </tr>
  37 + {{/each}}
20 </tbody> 38 </tbody>
21 </table> 39 </table>
22 <div class="table-pagination article-pagination pull-right"></div> 40 <div class="table-pagination article-pagination pull-right"></div>
  1 +require('admin/activity.page.css');