admin
2019-03-05 941b279c4eda537ba54e8fc3be9d2e2086155658
Merge remote-tracking branch 'origin/master'
2个文件已修改
119 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/UserCouponController.java 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/UserCouponController.java
@@ -433,11 +433,17 @@
    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;
@@ -456,46 +462,52 @@
                    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();
                        if (systemCouponId != null) {
                            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;
                }
                // 奖品
                prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, countPrize, list.size(), couponId);
                // 奖品小于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(), 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);
                        newCouponId = coupon.getId();
                        if (coupon != null) {
                            newCouponId = coupon.getId();
                        }
                    }
                }
@@ -508,41 +520,59 @@
                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, 0, countUsed, couponType);
                }
                // 奖品
                prize = getLotteryPrize(Constant.MAX_COUNT_LOTTERY_NEWBIES, list.size(), Constant.MAX_COUNT_LOTTERY_NEWBIES - lotteryNewbies, couponId);
                // 抽中
                if (prize != null && prize.trim().length() > 0) {
                    if (hasPrize.equals(prize)) {
                    if (prize.equals(couponType)) {
                        // 已有此券
                        prize = null;
                    } else {
                        // 插入券信息
                        userSystemCouponService.insertUserCoupon(uid, prize, UserSystemCoupon.SOURCE_CHOUJIANG);
                    }
                }
                // 剩余次数
                userInfoExtra.setLotteryNewbies(count);
                userInfoExtraService.saveUserInfoExtra(userInfoExtra);
@@ -573,7 +603,7 @@
     * @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(); // 福利免费券
@@ -581,16 +611,10 @@
        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 {
                    prize = freeCoupon; // 福利免费券
                }
            if (rebateCoupon.equals(couponType)) {
                prize = freeCoupon; // 福利免费券
            } else {
                prize = rebateCoupon; // 奖励券
                prize = rebateCoupon;  // 奖励券
            }
        } else if (countPrize == 0 && record == maxCount - 2) {
@@ -601,7 +625,7 @@
            } else {
                prize = rebateCoupon; // 奖励券
            }
        } else { // 大于3次机会
            if (countPrize < 2) { // 不足两个奖品
@@ -613,7 +637,6 @@
                }
            }
        }
        return prize;
    }
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml
@@ -117,7 +117,7 @@
  <select id="getEnableListByCouponId" resultMap="ResultVOMap">
    SELECT * FROM `yeshi_ec_user_system_coupon` uc
    WHERE uc.`usc_uid`= #{uid} AND uc.usc_state = 1 
        AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ >= ]]>DATE_FORMAT(uc.`usc_start_time`,'%Y%m%d');
        AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ >= ]]>DATE_FORMAT(uc.`usc_start_time`,'%Y%m%d')
        <if test="activated != null">AND uc.usc_state_activate = #{activated}</if>
        AND uc.usc_coupon_id in
        <foreach collection="list" item="item" open="(" close=")"