| | |
| | | public void getLotteryResult(String callback, AcceptData acceptData, Long uid, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | // 奖品
|
| | | // 剩余抽奖次数
|
| | | int count = 0;
|
| | | String prize = "";
|
| | | String hasPrize = "";
|
| | | Long couponId = null;
|
| | | // 本次抽中的奖品
|
| | | String prize = null;
|
| | | |
| | | // 已使用抽奖次数
|
| | | int countUsed = 0;
|
| | | // 已拥有奖品数量
|
| | | int countPrize = 0;
|
| | | // 已有券类型
|
| | | String couponType = null;
|
| | |
|
| | | if (uid == null || uid == 0) { // 未登录
|
| | | int platformType = 0;
|
| | |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("设备不存在"));
|
| | | return;
|
| | | }
|
| | | int countPrize = 0;
|
| | |
|
| | | List<DeviceLotteryRecord> list = deviceLotteryRecordService.listByPlatformAndDevice(platformType,
|
| | | device);
|
| | | if (list != null && list.size() == Constant.MAX_COUNT_LOTTERY_NEWBIES) { // 无抽奖机会
|
| | | if (list != null && list.size() >= Constant.MAX_COUNT_LOTTERY_NEWBIES) { // 无抽奖机会
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "抽奖次数不足"));
|
| | | return;
|
| | | } else if (list != null && list.size() < Constant.MAX_COUNT_LOTTERY_NEWBIES) { // 拥有抽奖机会
|
| | | } |
| | | |
| | | Long couponId = null;
|
| | | |
| | | if (list == null || list.size() == 0) { // 拥有抽奖机会
|
| | | count = Constant.MAX_COUNT_LOTTERY_NEWBIES - 1;
|
| | | } else {
|
| | |
|
| | | for (DeviceLotteryRecord deviceLotteryRecord : list) {
|
| | | Long systemCouponId = deviceLotteryRecord.getSystemCouponId();
|
| | |
| | | countPrize++;
|
| | | couponId = systemCouponId;
|
| | | }
|
| | |
|
| | | }
|
| | | |
| | | if (countPrize == 1 && couponId != null) {
|
| | | SystemCoupon coupon = systemCouponService.selectByPrimaryKey(couponId);
|
| | | hasPrize = coupon.getType().name();
|
| | | }
|
| | |
|
| | | count = Constant.MAX_COUNT_LOTTERY_NEWBIES - 1 - list.size();
|
| | |
|
| | | } else {
|
| | | count = Constant.MAX_COUNT_LOTTERY_NEWBIES - 1;
|
| | | }
|
| | |
|
| | | // 奖品小于2时才抽奖
|
| | | if (countPrize < 2) {
|
| | | if (couponId != null) {
|
| | | SystemCoupon coupon = systemCouponService.selectByPrimaryKey(couponId);
|
| | | // 已有券
|
| | | couponType = coupon.getType().name();
|
| | | }
|
| | | // 奖品
|
| | | prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, countPrize, list.size(), couponId);
|
| | | prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, countPrize, list.size(), couponType);
|
| | | }
|
| | | |
| | | // 抽中
|
| | | Long newCouponId = null;
|
| | | if (prize != null && prize.trim().length() > 0) {
|
| | | // 已存在此券
|
| | | if (hasPrize.equals(prize)) {
|
| | | if (prize.equals(couponType)) {
|
| | | prize = null;
|
| | | } else {
|
| | | SystemCoupon coupon = systemCouponService.getCouponByType(prize);
|
| | | if (coupon != null) {
|
| | | newCouponId = coupon.getId();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | deviceLotteryRecordService.insertSelective(record);
|
| | |
|
| | | } else { // 已登录
|
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("信息不正确"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 剩余抽奖次数
|
| | | Integer lotteryNewbies = userInfoExtra.getLotteryNewbies();
|
| | | if (lotteryNewbies == null || lotteryNewbies < 1) { // 次数已用光
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "抽奖次数不足"));
|
| | | return;
|
| | | } else {
|
| | | count = lotteryNewbies - 1; // 剩余次数
|
| | | }
|
| | |
|
| | | // 剩余次数
|
| | | count = lotteryNewbies - 1; |
| | | // 已使用次数
|
| | | countUsed = Constant.MAX_COUNT_LOTTERY_NEWBIES - lotteryNewbies;
|
| | | |
| | |
|
| | | // 已抽中的奖品
|
| | | List<UserSystemCoupon> list = userSystemCouponService.getUserCouponBySource(uid,
|
| | | UserSystemCoupon.SOURCE_CHOUJIANG);
|
| | | if (list != null && list.size() == 1) {
|
| | | couponId = list.get(0).getSystemCoupon().getId();
|
| | | SystemCoupon coupon = systemCouponService.selectByPrimaryKey(couponId);
|
| | | hasPrize = coupon.getType().name();
|
| | | |
| | | if (list == null || list.size() == 0) {
|
| | | // 抽奖
|
| | | prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, 0, countUsed, couponType);
|
| | | |
| | | } else if (list.size() == 1) {
|
| | | UserSystemCoupon userSystemCoupon = list.get(0);
|
| | | |
| | | SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
|
| | | if (systemCoupon != null) {
|
| | | SystemCoupon coupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
|
| | | // 已有券
|
| | | couponType = coupon.getType().name();
|
| | | }
|
| | |
|
| | | // 奖品
|
| | | prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, list.size(), Constant.MAX_COUNT_LOTTERY_NEWBIES - lotteryNewbies, couponId);
|
| | | // 抽奖
|
| | | prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, 0, countUsed, couponType);
|
| | | }
|
| | |
|
| | | // 抽中
|
| | | if (prize != null && prize.trim().length() > 0) {
|
| | |
|
| | | if (hasPrize.equals(prize)) {
|
| | | if (prize.equals(couponType)) {
|
| | | // 已有此券
|
| | | prize = null;
|
| | | } else {
|
| | | // 插入券信息
|
| | |
| | | * @param couponId 券id
|
| | | * @return
|
| | | */
|
| | | public String getLotteryPrize(int maxCount, int countPrize, int record, Long couponId) {
|
| | | public String getLotteryPrize(int maxCount, int countPrize, int record, String couponType) {
|
| | |
|
| | | String prize = null;
|
| | | String freeCoupon = CouponTypeEnum.welfareFreeCoupon.name(); // 福利免费券
|
| | |
| | |
|
| | | if (countPrize == 1 && record == maxCount - 1) {
|
| | | // 最后一次: 只收到一个奖品
|
| | | SystemCoupon systemCoupon = systemCouponService.selectByPrimaryKey(couponId);
|
| | | if (systemCoupon != null) {
|
| | | CouponTypeEnum type = systemCoupon.getType();
|
| | | if (type.name() == freeCoupon) {
|
| | | prize = rebateCoupon; // 奖励券
|
| | | } else {
|
| | | if (rebateCoupon.equals(couponType)) {
|
| | | prize = freeCoupon; // 福利免费券
|
| | | }
|
| | | } else {
|
| | | prize = rebateCoupon; // 奖励券
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return prize;
|
| | | }
|
| | |
|