yujian
2019-02-28 f92377709d27a03726001e8fb1de51512c43d5e2
fanli/src/main/java/com/yeshi/fanli/controller/client/UserCouponController.java
@@ -39,6 +39,7 @@
/**
 * 福利中心
 *
 * @author Administrator
 *
 */
@@ -84,6 +85,7 @@
   
   /**
    * 用户券列表查询
    *
    * @param acceptData
    * @param page
    * @param uid
@@ -111,8 +113,8 @@
         }
         
         long count = 0;
         List<UserSystemCouponVO> resultList = UserSystemCouponService.getUserCouponVOList((page - 1) * Constant.PAGE_SIZE,
               Constant.PAGE_SIZE, uid );
         List<UserSystemCouponVO> resultList = UserSystemCouponService
               .getUserCouponVOList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
         
         if (resultList != null && resultList.size() > 0) {
            count = UserSystemCouponService.countUserCouponList(uid);
@@ -157,6 +159,7 @@
   
   /**
    * 用户奖励券
    *
    * @param acceptData
    * @param page
    * @param uid
@@ -176,7 +179,6 @@
         if (resultList == null ) {
            resultList =new ArrayList<UserSystemCouponVO>();
         }
         
         JSONObject dataTip = new JSONObject();
         dataTip.put("content", configService.get("free_coupon_tip"));
@@ -198,9 +200,9 @@
      }
   }
   
   /**
    *  免单券使用记录 以及状态修改
    *
    * @param acceptData
    * @param page
    * @param uid
@@ -224,9 +226,9 @@
      }
   }
   
   /**
    * 用户奖励券
    *
    * @param acceptData
    * @param page
    * @param uid
@@ -262,9 +264,9 @@
      }
   }
   
   /**
    *  免单券使用记录 以及状态修改
    *
    * @param acceptData
    * @param page
    * @param uid
@@ -295,6 +297,7 @@
   
   /**
    *  订单-奖励进度详情
    *
    * @param acceptData
    * @param orderNo 订单号
    * @param out
@@ -321,6 +324,7 @@
   
   /**
    *  订单-奖励进度详情
    *
    * @param acceptData
    * @param orderNo 订单号
    * @param out
@@ -345,7 +349,6 @@
      }
   }
   
   /**
    * 获取抽奖次数
    * 
@@ -356,15 +359,55 @@
    */
   @RequestMapping(value = "getLotteryCount")
   public void getLotteryCount(String callback, AcceptData acceptData, Long uid, PrintWriter out) {
      int count = 0;
      try {
         count = getSurplusCount(acceptData, uid);
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMessage()));
         e.printStackTrace();
         // 默认最大抽奖次数
         int count = 5;
         if (uid == null || uid == 0) { // 未登录
            int platformType = 0;
            String platform = acceptData.getPlatform();
            if ("android".equals(platform)) {
               platformType = 1;
            } else if ("ios".equals(platform)) {
               platformType = 2;
            } else {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("平台有误"));
               return;
      }
      try {
            String device = acceptData.getDevice();
            if (device == null || device.trim().length() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("设备不存在"));
               return;
            }
            List<DeviceLotteryRecord> list = deviceLotteryRecordService.listByPlatformAndDevice(platformType,
                  device);
            if (list != null && list.size() > 0) {
               count = count - list.size();
            }
         } else { // 已登录
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra == null) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户信息不存在"));
               return;
            }
            Integer lotteryNewbies = userInfoExtra.getLotteryNewbies();
            if (lotteryNewbies == null) { // 未抽过
               // 是否有过订单:返利、分享订单
               boolean hasOrder = commonOrderCountService.hasRebateAndShareOrder(uid);
               if (hasOrder) {
                  count = 0; // 不算新用户
               }
               userInfoExtra.setLotteryNewbies(count);
               userInfoExtraService.saveUserInfoExtra(userInfoExtra);
            } else {
               count = lotteryNewbies; // 剩余次数
            }
         }
         // 抽奖规则
         String lotteryRule = configService.get("lottery_rule_newbies");
@@ -379,7 +422,6 @@
         e.printStackTrace();
      }
   }
   
   /**
    * 获取抽奖结果
@@ -399,7 +441,7 @@
         String hasPrize = "";
         Long couponId = null;
         
         if (uid == null) { // 未登录
         if (uid == null || uid == 0) { // 未登录
            int platformType = 0;
            String platform = acceptData.getPlatform();
            if ("android".equals(platform)) {
@@ -438,9 +480,7 @@
                  }
               }
               
               count = MAX_COUNT - 1 - list.size();
               
            } else {
               count = MAX_COUNT - 1;
@@ -483,7 +523,8 @@
               count = lotteryNewbies - 1; // 剩余次数
            }
            
            List<UserSystemCoupon> list = userSystemCouponService.getUserCouponBySource(uid, UserSystemCoupon.SOURCE_CHOUJIANG);
            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);
@@ -526,6 +567,7 @@
   
   /**
    * 奖品抽取
    *
    * @param maxCount  最大次数
    * @param hasPrize 拥有奖品数量
    * @param record  已抽次数
@@ -574,64 +616,6 @@
      }
      
      return prize;
   }
   /**
    * 获取抽奖结果
    *
    * @param callback
    * @param acceptData
    * @param uid
    * @param out
    */
   public int getSurplusCount(AcceptData acceptData, Long uid) throws Exception {
      // 默认最大抽奖次数
      int count = 5;
      if (uid == null) { // 未登录
         int platformType = 0;
         String platform = acceptData.getPlatform();
         if ("android".equals(platform)) {
            platformType = 1;
         } else if ("ios".equals(platform)) {
            platformType = 2;
         } else {
            throw new Exception("平台有误");
         }
         String device = acceptData.getDevice();
         if (device == null || device.trim().length() == 0) {
            throw new Exception("设备不存在");
         }
         List<DeviceLotteryRecord> list = deviceLotteryRecordService.listByPlatformAndDevice(platformType, device);
         if (list != null && list.size() > 0) {
            count = count - list.size();
         }
      } else { // 已登录
         UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
         if (userInfoExtra == null) {
            throw new Exception("信息不正确");
         }
         Integer lotteryNewbies = userInfoExtra.getLotteryNewbies();
         if (lotteryNewbies == null) { // 未抽过
            // 是否有过订单:返利、分享订单
            boolean hasOrder = commonOrderCountService.hasRebateAndShareOrder(uid);
            if (hasOrder) {
               count = 0; // 不算新用户
            }
            userInfoExtra.setLotteryNewbies(count);
            userInfoExtraService.saveUserInfoExtra(userInfoExtra);
         } else {
            count = lotteryNewbies; // 剩余次数
         }
      }
      return count;
   }
}