Authored by bblu

会员日

@@ -25,8 +25,8 @@ public class UserdayPrizeLogController { @@ -25,8 +25,8 @@ public class UserdayPrizeLogController {
25 @ResponseBody 25 @ResponseBody
26 public ApiResponse addPrizeLog(int uid, int prize_type) throws Exception { 26 public ApiResponse addPrizeLog(int uid, int prize_type) throws Exception {
27 log.debug("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type); 27 log.debug("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type);
28 - userdayPrizeLogService.addPrizeLog(uid, prize_type);  
29 - return new ApiResponse(new Object()); 28 + int result = userdayPrizeLogService.addPrizeLog(uid, prize_type);
  29 + return new ApiResponse(result);
30 } 30 }
31 31
32 @RequestMapping("/existsPrizeLog") 32 @RequestMapping("/existsPrizeLog")
@@ -9,7 +9,7 @@ public interface IUserdayPrizeLogService { @@ -9,7 +9,7 @@ public interface IUserdayPrizeLogService {
9 9
10 UserdayPrizeLog queryPrizeLogForLeaveWords(int uid) throws Exception; 10 UserdayPrizeLog queryPrizeLogForLeaveWords(int uid) throws Exception;
11 11
12 - void addPrizeLog(int uid, int prize_type) throws Exception; 12 + int addPrizeLog(int uid, int prize_type) throws Exception;
13 13
14 boolean existsPrizeLog(int uid, int prize_type) throws Exception; 14 boolean existsPrizeLog(int uid, int prize_type) throws Exception;
15 } 15 }
@@ -2,12 +2,15 @@ package com.yoho.activity.service.impl; @@ -2,12 +2,15 @@ package com.yoho.activity.service.impl;
2 2
3 import com.yoho.activity.common.helper.SendCouponHelper; 3 import com.yoho.activity.common.helper.SendCouponHelper;
4 import com.yoho.activity.service.IUserdayDrawPrizeService; 4 import com.yoho.activity.service.IUserdayDrawPrizeService;
  5 +import com.yoho.core.rest.client.ServiceCaller;
  6 +import com.yoho.service.model.request.YohoCoinLogReqBO;
5 import com.yoho.userday.dal.model.UserdayPrizeLog; 7 import com.yoho.userday.dal.model.UserdayPrizeLog;
6 import org.slf4j.Logger; 8 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
10 12
  13 +import javax.annotation.Resource;
11 import java.util.List; 14 import java.util.List;
12 import java.util.Random; 15 import java.util.Random;
13 16
@@ -21,6 +24,8 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService @@ -21,6 +24,8 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService
21 24
22 @Autowired 25 @Autowired
23 private SendCouponHelper sendCouponHelper; 26 private SendCouponHelper sendCouponHelper;
  27 + @Resource
  28 + ServiceCaller serviceCaller;
24 29
25 @Override 30 @Override
26 public int drawPrize(int uid) throws Exception { 31 public int drawPrize(int uid) throws Exception {
@@ -31,7 +36,18 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService @@ -31,7 +36,18 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService
31 throw new Exception("参数不合法"); 36 throw new Exception("参数不合法");
32 } 37 }
33 38
34 - // (2)根据中奖规则获取有货币数量 39 + // (2)判断有货币数量是否足够抽奖
  40 + YohoCoinLogReqBO yohoCoinLogReqBO = new YohoCoinLogReqBO();
  41 + yohoCoinLogReqBO.setUid(uid);
  42 + int num = serviceCaller.call("users.getYohoCoinNum", yohoCoinLogReqBO, Integer.class);
  43 + if (20 > num) {
  44 + throw new Exception("有货币数量不足");
  45 + }
  46 +
  47 + // (3)消耗有货币用于抽奖
  48 + sendCouponHelper.sendYOHOBi(uid, -20, 12);
  49 +
  50 + // (4)根据中奖规则获取有货币数量
35 int yohoCoinNum = 0; 51 int yohoCoinNum = 0;
36 int random = new Random().nextInt(1000); 52 int random = new Random().nextInt(1000);
37 if (999 == random) { 53 if (999 == random) {
@@ -47,12 +63,12 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService @@ -47,12 +63,12 @@ public class UserdayDrawYohoCoinServiceImpl implements IUserdayDrawPrizeService
47 } 63 }
48 log.info("drawPrize: draw prize complete. uid={}, yohoCoinNum={}, random={}", uid, yohoCoinNum, random); 64 log.info("drawPrize: draw prize complete. uid={}, yohoCoinNum={}, random={}", uid, yohoCoinNum, random);
49 65
50 - // (3)发送有货币 66 + // (5)发送有货币
51 if (0 < yohoCoinNum) { 67 if (0 < yohoCoinNum) {
52 - sendCouponHelper.sendYOHOBi(uid, yohoCoinNum); 68 + sendCouponHelper.sendYOHOBi(uid, yohoCoinNum, 6);
53 } 69 }
54 70
55 - // (4)返回 71 + // (6)返回
56 return yohoCoinNum; 72 return yohoCoinNum;
57 } 73 }
58 74
@@ -40,7 +40,7 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { @@ -40,7 +40,7 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService {
40 } 40 }
41 41
42 @Override 42 @Override
43 - public void addPrizeLog(int uid, int prize_type) throws Exception { 43 + public int addPrizeLog(int uid, int prize_type) throws Exception {
44 log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type); 44 log.info("enter addPrizeLog. param uid={}, prize_type={}", uid, prize_type);
45 45
46 // (1)校验uid, prize_type 46 // (1)校验uid, prize_type
@@ -58,6 +58,8 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService { @@ -58,6 +58,8 @@ public class UserdayPrizeLogServiceImpl implements IUserdayPrizeLogService {
58 // (3)保存抽奖日志 58 // (3)保存抽奖日志
59 UserdayPrizeLog userdayPrizeLog = new UserdayPrizeLog(uid, prize_type, prize_value, DateUtil.currentTimeSeconds()); 59 UserdayPrizeLog userdayPrizeLog = new UserdayPrizeLog(uid, prize_type, prize_value, DateUtil.currentTimeSeconds());
60 userdayPrizeLogDAO.insertLog(userdayPrizeLog); 60 userdayPrizeLogDAO.insertLog(userdayPrizeLog);
  61 +
  62 + return prize_value;
61 } 63 }
62 64
63 @Override 65 @Override