admin
2019-02-27 ad3119f7b7e0375a8363b900346284bb1c274a3d
Merge remote-tracking branch 'origin/master'
10个文件已修改
235 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/apph5/AppH5QualityGoodsController.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponRecordMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/UserSystemCouponRecord.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponRecordMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponRecordServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java 154 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponRecordService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/apph5/AppH5QualityGoodsController.java
@@ -22,6 +22,7 @@
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoHongBaoInfo;
import com.yeshi.fanli.entity.taobao.TaobaoMeterial;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
@@ -1209,8 +1210,12 @@
                TaoBaoGoodsBriefExtra extra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, 
                        proportion.toString(), null);
                // 将在售价改为券后价
                extra.setZkPrice(extra.getQuanPrice());
                // 将返利改为券后价
                TaoBaoHongBaoInfo taoBaoHongBaoInfo = extra.getTaoBaoHongBaoInfo();
                if (taoBaoHongBaoInfo != null) {
                    taoBaoHongBaoInfo.setHongbao(extra.getQuanPrice());
                    taoBaoHongBaoInfo.setRate("¥" + extra.getQuanPrice());
                }
                
                array.add(gson.toJson(extra));
            }
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponMapper.java
@@ -35,6 +35,20 @@
     */
    List<UserSystemCoupon> getUserCouponBySource(@Param("uid") Long uid, @Param("source") String source);
    
    /**
     * 获取已经过期但状态未改变的券
     * @param uid
     * @return
     */
    List<UserSystemCoupon> getCounponNowInvalid(@Param("uid") Long uid);
    /**
     * 根据状态查询券
     * @param uid
     * @param source
     * @return
     */
    List<UserSystemCoupon> getCouponByState(@Param("uid") Long uid, @Param("state") String state);
    
    
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponRecordMapper.java
@@ -28,4 +28,13 @@
     */
    List<UserSystemCouponRecord> getRecordByOrderNoList(@Param("list") List<String> list);
    
    /**
     * 查询正在使用中 超过时间仍未匹配到订单记录
     * @param uid
     * @param seconds
     * @return
     */
    List<UserSystemCouponRecord> getCouponByUsingTimeOut(@Param("uid") Long uid,@Param("seconds") long seconds);
}
fanli/src/main/java/com/yeshi/fanli/entity/bus/user/UserSystemCouponRecord.java
@@ -13,10 +13,11 @@
@Table("yeshi_ec_user_system_coupon_record")
public class UserSystemCouponRecord {
    // 状态: 匹配中0   规则不匹配1   退款退回4     免单中2  使用成功3
    // 状态: 匹配中0    规则不匹配1   退款退回4  匹配超时退回5   免单中2  使用成功3
    public final static int STATE_WAIT= 0;
    public final static int STATE_FAIL_RULE =1;
    public final static int STATE_FAIL_DRAWBACK = 4;
    public final static int STATE_WAIT_TIME_OUT = 5;
    
    public final static int STATE_FREE_ON = 2;
    public final static int STATE_SUCCESS = 3;
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml
@@ -124,4 +124,18 @@
    ORDER BY uc.usc_state_activate, uc.`usc_create_time`
  </select>
  
  <select id="getCounponNowInvalid" resultMap="BaseResultMap">
      SELECT * FROM `yeshi_ec_user_system_coupon` cp
    WHERE cp.`usc_uid` = #{uid} AND cp.`usc_state` = 1
        AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ > ]]>DATE_FORMAT(cp.`usc_end_time`,'%Y%m%d');
  </select>
  <select id="getCouponByState" resultMap="BaseResultMap">
      SELECT * FROM `yeshi_ec_user_system_coupon` cp
    WHERE cp.`usc_uid` = #{uid}
        <if test="state != null">
             AND cp.`usc_state` = #{state}
        </if>
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponRecordMapper.xml
@@ -77,4 +77,11 @@
            separator=",">#{item}</foreach>
  </select>
  
  <select id="getCouponByUsingTimeOut" resultMap="BaseResultMap">
     SELECT * FROM `yeshi_ec_user_system_coupon` cp
    LEFT JOIN `yeshi_ec_user_system_coupon_record` rd ON rd.`ucr_user_coupon_id` = cp.`usc_id`
    WHERE cp.`usc_uid` = #{uid} AND cp.`usc_state` = 2 AND rd.`ucr_state` = 0
          AND UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(cp.`usc_use_time`) > #{seconds} ; 
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponRecordServiceImpl.java
@@ -46,5 +46,10 @@
    public List<UserSystemCouponRecord> getRecordByOrderNoList(List<String> list) {
        return userSystemCouponRecordMapper.getRecordByOrderNoList(list);
    }
    @Override
    public List<UserSystemCouponRecord> getCouponByUsingTimeOut(Long uid, long seconds) {
        return userSystemCouponRecordMapper.getCouponByUsingTimeOut(uid, seconds);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.service.impl.user;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -27,12 +28,14 @@
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.exception.user.UserSystemCouponException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemCouponService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
@@ -99,6 +102,10 @@
    
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    @Resource
    private UserOtherMsgNotificationService userOtherMsgNotificationService;
    // 券失效图片
    public final static String PIC_INVALID = "http://192.168.1.200/icon/mian_invalid.png";
@@ -177,6 +184,25 @@
        userCoupon.setUpdateTime(new Date());
        // 插入数据库
        insertSelective(userCoupon);
        // 消息推送
        try {
            if (coupon.getType() != CouponTypeEnum.welfareFreeCoupon) {
                userOtherMsgNotificationService.welfareCouponGet(userCoupon);
            } else if (coupon.getType() != CouponTypeEnum.freeCoupon) {
                userOtherMsgNotificationService.freeSheetCouponGet(userCoupon);
            } else if (coupon.getType() != CouponTypeEnum.rebatePercentCoupon) {
                userOtherMsgNotificationService.rewardCouponGet(userCoupon);
            }
        } catch(Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
    
@@ -188,7 +214,12 @@
        if (uid == null) {
            return null;
        }
        // 更新过期券
        updateCounponInvalid(uid);
        // 退回券
        sendBackCoupon(uid);
        List<UserSystemCouponVO> listVO = userSystemCouponMapper.getUserCouponVOList(start, count, uid);
        if (listVO == null || listVO.size() == 0) {
            return listVO;
@@ -430,6 +461,12 @@
        if (uid == null) {
            throw new UserSystemCouponException(1, "用户未登录");
        }
        // 更新过期券
        updateCounponInvalid(uid);
        // 退回券
        sendBackCoupon(uid);
        // 订单相关的券
        List<SystemCoupon> couponList = systemCouponService.getOrderCouponList();
        if (couponList == null || couponList.size() == 0) {
@@ -444,6 +481,12 @@
        if (uid == null) {
            throw new UserSystemCouponException(1, "用户未登录");
        }
        // 更新过期券
        updateCounponInvalid(uid);
        // 退回券
        sendBackCoupon(uid);
        // 商品相关的券
        List<SystemCoupon> couponList = systemCouponService.getGoodsCouponList();
        if (couponList == null || couponList.size() == 0) {
@@ -502,6 +545,19 @@
        couponRecord.setCreateTime(date);
        couponRecord.setUpdateTime(date);
        userSystemCouponRecordService.insertSelective(couponRecord);
        // 消息推送
        try {
            if (baseCoupon.getType() != CouponTypeEnum.welfareFreeCoupon) {
                userOtherMsgNotificationService.welfareCouponUsing(userSystemCoupon);
            } else if (baseCoupon.getType() != CouponTypeEnum.freeCoupon) {
                userOtherMsgNotificationService.freeSheetCouponUsing(userSystemCoupon);
            }
        } catch(Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
    @Transactional
@@ -607,6 +663,13 @@
            couponRecord.setCreateTime(date);
            couponRecord.setUpdateTime(date);
            userSystemCouponRecordService.insertSelective(couponRecord);
            // 消息推送
            try {
                userOtherMsgNotificationService.rewardCouponUsed(userSystemCoupon);
            } catch(Exception e) {
                LogHelper.errorDetailInfo(e);
            }
        }
    }
@@ -887,6 +950,95 @@
        return userRecordVO;
    }
    @Override
    public void updateCounponInvalid(Long uid) {
        List<UserSystemCoupon> list = userSystemCouponMapper.getCounponNowInvalid(uid);
        if (list == null || list.size() == 0) {
            return;
        }
        for (UserSystemCoupon userSystemCoupon: list) {
            // 更新券已过期
            userSystemCoupon.setState(UserSystemCoupon.STATE_OVERDUE);
            userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
            SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
            if (systemCoupon == null) {
                continue;
            }
            SystemCoupon baseCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
            if (baseCoupon == null || baseCoupon.getId() == null) {
                continue;
            }
            // 消息推送
            try {
                if (baseCoupon.getType() != CouponTypeEnum.welfareFreeCoupon) {
                    userOtherMsgNotificationService.welfareCouponAlreadyOutOfDate(userSystemCoupon);
                } else if (baseCoupon.getType() != CouponTypeEnum.freeCoupon) {
                    userOtherMsgNotificationService.freeSheetCouponAlreadyOutOfDate(userSystemCoupon);
                } else if (baseCoupon.getType() != CouponTypeEnum.rebatePercentCoupon) {
                    userOtherMsgNotificationService.rewardCouponAlreadyOutOfDate(userSystemCoupon);
                }
            } catch(Exception e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    @Override
    public void  sendBackCoupon(Long uid) {
        // 超过120秒 未被匹配的券
        List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 120);
        if (list == null || list.size() == 0) {
            return;
        }
        for (UserSystemCouponRecord couponRecord: list) {
            // 更新状态:匹配超时
            couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
            couponRecord.setUpdateTime(new Date());
            userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
            UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
            // 状态初始化
            userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
            userSystemCoupon.setUseTime(null);
            int expiryDay = 15;
            SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
            SystemCoupon coupon= systemCouponService.selectByPrimaryKey(systemCoupon.getId());
            if (coupon != null) {
                expiryDay = coupon.getExpiryDay();
            }
            // 结束日期
            Date endTime = null;
            try {
                String endDay = DateUtil.plusDay(expiryDay, new Date());
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                endTime = format.parse(endDay);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            // 有效期时间重新定义
            userSystemCoupon.setStartTime(new Date());
            userSystemCoupon.setEndTime(endTime);
            userSystemCoupon.setUpdateTime(new Date());
            userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
        }
    }
    
    
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponRecordService.java
@@ -17,5 +17,13 @@
    public UserSystemCouponRecord getRecordByOrderNo(String orderNo, Integer state);
    public List<UserSystemCouponRecord> getRecordByOrderNoList(List<String> list);
    /**
     * 查询正在使用中 超过时间仍未匹配到订单记录
     * @param uid
     * @param seconds
     * @return
     */
    public List<UserSystemCouponRecord> getCouponByUsingTimeOut(Long uid, long seconds);
    
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java
@@ -134,5 +134,17 @@
     */
    public void insertUserCoupon(Long uid, String couponType, String source) throws UserSystemCouponException, Exception;
    /**
     * 券已过期更新
     * @param uid
     */
    public void updateCounponInvalid(Long uid);
    /**
     * 退回券
     * @param uid
     */
    public void sendBackCoupon(Long uid);
    
}