fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/OrderHongBaoMapMapper.java
@@ -1,7 +1,6 @@ package com.yeshi.fanli.dao.mybatis.order; import java.math.BigDecimal; import java.util.Map; import org.apache.ibatis.annotations.Param; @@ -10,5 +9,11 @@ public interface OrderHongBaoMapMapper extends BaseMapper<OrderHongBaoMap>{ Map<String,BigDecimal> getCouponHongbaoByOrderNo(@Param("orderNo")String orderNo, @Param("uid")Long uid); /** * 获取奖励金额 * @param orderNo * @param uid * @return */ BigDecimal getCouponHongbaoByOrderNo(@Param("orderNo")String orderNo, @Param("uid")Long uid); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponMapper.java
@@ -10,6 +10,7 @@ public interface UserSystemCouponMapper extends BaseMapper<UserSystemCoupon> { List<UserSystemCoupon> getUserCouponList(@Param("start") long start, @Param("count") int count, @Param("uid") Long uid); @@ -50,5 +51,10 @@ */ List<UserSystemCoupon> getCouponByState(@Param("uid") Long uid, @Param("state") String state); /** * 查询没有激活的券 * @param couponId */ List<UserSystemCoupon> getCouponByTypeAndNotActivated(@Param("uid") Long uid, @Param("couponId") Long couponId); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponRecordMapper.java
@@ -16,6 +16,15 @@ * @param listCouponId * @return */ List<UserSystemCouponRecord> getRecordByState(@Param("uid") Long uid, @Param("state") Integer state); /** * 根据单个订单查询 * @param uid * @param activated * @param listCouponId * @return */ UserSystemCouponRecord getRecordByOrderNo(@Param("orderNo") String orderNo, @Param("state") Integer state); fanli/src/main/java/com/yeshi/fanli/mapping/order/OrderHongBaoMapMapper.xml
@@ -66,12 +66,12 @@ </update> <select id="getCouponHongbaoByOrderNo" resultType="java.util.Map"> SELECT COALESCE(SUM(IF(hb.hb_type=1,hb.`hb_money`,0)),0)AS totalMoney, COALESCE(SUM(IF(hb.hb_type=10,hb.`hb_money`,0)),0)AS couponMoney <select id="getCouponHongbaoByOrderNo" resultType="java.math.BigDecimal"> SELECT COALESCE(SUM(hb.`hb_money`),0)AS couponMoney FROM `yeshi_ec_order_hongbaov2_map` hm LEFT JOIN `yeshi_ec_order` o ON o.`id` = hm.`ohm_order_id` LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} )hb ON hb.hb_id = hm.`ohm_hongbao_id` LEFT JOIN (SELECT v2.`hb_money`,v2.`hb_id` FROM yeshi_ec_hongbao_v2 v2 WHERE v2.`hb_uid`= #{uid} AND v2.`hb_type` = 10 )hb ON hb.hb_id = hm.`ohm_hongbao_id` WHERE hb.hb_id IS NOT NULL AND o.`orderid` = #{orderNo} </select> fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml
@@ -121,7 +121,7 @@ AND uc.usc_coupon_id in <foreach collection="list" item="item" open="(" close=")" separator=",">#{item}</foreach> ORDER BY uc.usc_state_activate, uc.`usc_create_time` ORDER BY uc.usc_state_activate desc, uc.`usc_create_time` </select> <select id="getCounponNowInvalid" resultMap="BaseResultMap"> @@ -138,4 +138,10 @@ </if> </select> <select id="getCouponByTypeAndNotActivated" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_user_system_coupon WHERE usc_uid = #{uid} AND usc_coupon_id = #{couponId} AND (usc_state_activate = 0 OR usc_state_activate is null) </select> </mapper> fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponRecordMapper.xml
@@ -60,6 +60,13 @@ </set> where ucr_id = #{id,jdbcType=BIGINT} </update> <select id="getRecordByState" resultMap="BaseResultMap"> SELECT * FROM `yeshi_ec_user_system_coupon_record` cd LEFT JOIN `yeshi_ec_user_system_coupon` uc ON uc.`usc_id` = cd.`ucr_user_coupon_id` WHERE uc.`usc_uid` = #{uid} AND cd.`ucr_state` = #{state} </select> <select id="getRecordByOrderNo" resultMap="BaseResultMap"> SELECT * FROM `yeshi_ec_user_system_coupon_record` cd LEFT JOIN `yeshi_ec_user_system_coupon` uc ON uc.`usc_id` = cd.`ucr_user_coupon_id` fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -488,8 +488,9 @@ if (rewardSuccess) { // 奖励成功 rewardOrder = true; } else if(hasRewardCoupon && !freeOrder && HongBaoV2.STATE_YILINGQU == hongBaoState) { // 有可用的奖励券 、非免单订单 、且已到账的 } else if(hasRewardCoupon && !freeOrder && HongBaoV2.TYPE_ZIGOU == hongBaoType && HongBaoV2.STATE_YILINGQU == hongBaoState) { // 有可用的奖励券 、非免单订单 、且已到账的 、返利订单 type = 2; rewardOrder = true; } fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderHongBaoMapServiceImpl.java
@@ -2,7 +2,6 @@ import java.math.BigDecimal; import java.util.Date; import java.util.Map; import javax.annotation.Resource; @@ -35,7 +34,7 @@ @Override public Map<String,BigDecimal> getCouponHongbaoByOrderNo(String orderNo, Long uid) { public BigDecimal getCouponHongbaoByOrderNo(String orderNo, Long uid) { return orderHongBaoMapMapper.getCouponHongbaoByOrderNo(orderNo, uid); } } fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponRecordServiceImpl.java
@@ -36,6 +36,11 @@ public int updateByPrimaryKey(UserSystemCouponRecord record) { return userSystemCouponRecordMapper.updateByPrimaryKey(record); } @Override public List<UserSystemCouponRecord> getRecordByState(Long uid, Integer state) { return userSystemCouponRecordMapper.getRecordByState(uid, state); } @Override public UserSystemCouponRecord getRecordByOrderNo(String orderNo, Integer state) { fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -218,7 +218,7 @@ // 更新过期券 updateCounponInvalid(uid); // 退回券 sendBackCoupon(uid); sendBackTimeOutCoupon(uid); List<UserSystemCouponVO> listVO = userSystemCouponMapper.getUserCouponVOList(start, count, uid); if (listVO == null || listVO.size() == 0) { @@ -465,7 +465,7 @@ // 更新过期券 updateCounponInvalid(uid); // 退回券 sendBackCoupon(uid); sendBackTimeOutCoupon(uid); // 订单相关的券 List<SystemCoupon> couponList = systemCouponService.getOrderCouponList(); @@ -485,7 +485,7 @@ // 更新过期券 updateCounponInvalid(uid); // 退回券 sendBackCoupon(uid); sendBackTimeOutCoupon(uid); // 商品相关的券 List<SystemCoupon> couponList = systemCouponService.getGoodsCouponList(); @@ -718,17 +718,20 @@ } // 获取奖励金额 Map<String, BigDecimal> map = orderHongBaoMapService.getCouponHongbaoByOrderNo(orderNo, uid); BigDecimal couponMoney = orderHongBaoMapService.getCouponHongbaoByOrderNo(orderNo, uid); UserSystemCouponRecordVO userRecordVO = new UserSystemCouponRecordVO(); userRecordVO.setCouponMoneyState("已到账"); userRecordVO.setCommonOrder(commonOrderVO); userRecordVO.setCouponName("奖励金: ¥" + map.get("couponMoney").setScale(2, BigDecimal.ROUND_DOWN)); userRecordVO.setCouponName("奖励金: ¥" + couponMoney.setScale(2, BigDecimal.ROUND_DOWN)); // 比例 BigDecimal percent = baseCoupon.getPercent(); BigDecimal hongBao = map.get("totalMoney").setScale(2, BigDecimal.ROUND_DOWN); userRecordVO.setCouponEffect("返利¥" + hongBao + "已返" + percent + "%"); BigDecimal hongBao = commonOrderVO.getHongBao(); if (hongBao == null) { hongBao = new BigDecimal(0); } userRecordVO.setCouponEffect("返利¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN) + "已返" + percent + "%"); // 跳转福利中心 JumpDetailV2 welfareCore = jumpDetailV2Service.getByTypeCache("welfareCore"); @@ -949,6 +952,48 @@ return userRecordVO; } @Override public void activatedWelfareFreeCoupon(Long uid) { if (uid == null) { return; } // 福利免单券 String welfareFree = CouponTypeEnum.welfareFreeCoupon.name(); SystemCoupon systemCoupon = systemCouponService.getCouponByType(welfareFree); if (systemCoupon == null) { return; } // 待活福利免单券 List<UserSystemCoupon> list = userSystemCouponMapper.getCouponByTypeAndNotActivated(uid, systemCoupon.getId()); if (list == null || list.size() == 0) { return; } for (UserSystemCoupon userSystemCoupon: list) { // 激活 userSystemCoupon.setStateActivated(1); userSystemCoupon.setUpdateTime(new Date()); userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon); // 消息推送 try { userOtherMsgNotificationService.welfareCouponGet(userSystemCoupon); } catch(Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } @Override public void updateCounponInvalid(Long uid) { @@ -993,7 +1038,7 @@ } @Override public void sendBackCoupon(Long uid) { public void sendBackTimeOutCoupon(Long uid) { // 超过120秒 未被匹配的券 List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 120); if (list == null || list.size() == 0) { @@ -1007,9 +1052,6 @@ userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord); UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon(); // 状态初始化 userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE); userSystemCoupon.setUseTime(null); int expiryDay = 15; @@ -1028,16 +1070,128 @@ } catch (ParseException e) { e.printStackTrace(); } // 状态初始化 userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE); userSystemCoupon.setUseTime(null); // 有效期时间重新定义 userSystemCoupon.setStartTime(new Date()); userSystemCoupon.setEndTime(endTime); userSystemCoupon.setUpdateTime(new Date()); userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon); } } @Override public boolean updateCouponRecordUsed(Long uid, String orderNo, BigDecimal payment, Long auctionId) throws Exception{ boolean isfree = false; if (uid == null || payment == null || auctionId == null || orderNo == null || orderNo.trim().length() == 0 ) { throw new Exception("传递参数不能为空"); } // 查询等待匹配的券记录 List<UserSystemCouponRecord> list = userSystemCouponRecordService.getRecordByState(uid, UserSystemCouponRecord.STATE_WAIT); if (list == null || list.size() == 0) { return isfree; } // 匹配 boolean matching = false; UserSystemCouponRecord record = null; for (UserSystemCouponRecord userSystemCouponRecord : list) { Long goodId = userSystemCouponRecord.getGoodId(); if (auctionId.equals(goodId)) { matching = true; // 匹配成功 record = userSystemCouponRecord; break; } } // 商品匹配成功 if (matching) { record.setOrderNo(orderNo); record.setUpdateTime(new Date()); UserSystemCoupon userSystemCoupon = record.getUserSystemCoupon(); if (payment.compareTo(new BigDecimal(10)) > 0) { // 更新记录 -- 金额不匹配 大10元 record.setState(UserSystemCouponRecord.STATE_FAIL_RULE); userSystemCouponRecordService.updateByPrimaryKeySelective(record); // 退回券 sendBackCoupon(userSystemCoupon); } else { // 免单匹配成功 isfree = true; //更新记录--免单中 record.setState(UserSystemCouponRecord.STATE_FREE_ON); userSystemCouponRecordService.updateByPrimaryKeySelective(record); // 券结束使用 userSystemCoupon.setState(UserSystemCoupon.STATE_END_USE); userSystemCoupon.setUpdateTime(new Date()); userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon); SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon(); SystemCoupon baseCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId()); if (baseCoupon == null) { // 券已使用 userOtherMsgNotificationService.freeSheetCouponUsed(userSystemCoupon); } else if (baseCoupon.getType() != CouponTypeEnum.welfareFreeCoupon) { userOtherMsgNotificationService.welfareCouponUsed(userSystemCoupon); } else if (baseCoupon.getType() != CouponTypeEnum.freeCoupon) { userOtherMsgNotificationService.freeSheetCouponUsed(userSystemCoupon); } } } return isfree; } /** * 退回券 初始数据 * @param userSystemCoupon */ public void sendBackCoupon(UserSystemCoupon userSystemCoupon) throws Exception{ 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.setState(UserSystemCoupon.STATE_CAN_USE); userSystemCoupon.setUseTime(null); // 有效期时间重新定义 userSystemCoupon.setStartTime(new Date()); userSystemCoupon.setEndTime(endTime); userSystemCoupon.setUpdateTime(new Date()); userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon); } fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderHongBaoMapService.java
@@ -28,6 +28,6 @@ * @param uid * @return */ public Map<String, BigDecimal> getCouponHongbaoByOrderNo(String orderNo, Long uid); public BigDecimal getCouponHongbaoByOrderNo(String orderNo, Long uid); } fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponRecordService.java
@@ -25,5 +25,13 @@ * @return */ public List<UserSystemCouponRecord> getCouponByUsingTimeOut(Long uid, long seconds); /** * 查询状态 * @param uid * @param state * @return */ public List<UserSystemCouponRecord> getRecordByState(Long uid, Integer state); } fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java
@@ -1,5 +1,6 @@ package com.yeshi.fanli.service.inter.user; import java.math.BigDecimal; import java.util.List; import com.yeshi.fanli.entity.bus.user.UserSystemCoupon; @@ -144,7 +145,24 @@ * 退回券 * @param uid */ public void sendBackCoupon(Long uid); public void sendBackTimeOutCoupon(Long uid); /** * 激活福利免单券 * @param uid */ public void activatedWelfareFreeCoupon(Long uid); /** * 更新券记录 ——匹配免单券 * @param uid 用户id * @param orderNo 订单号 * @param payment 付款金额 * @param auctionId 商品id(淘宝) * @return 免单成功 true * @throws Exception */ public boolean updateCouponRecordUsed(Long uid, String orderNo, BigDecimal payment, Long auctionId) throws Exception; } fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -30,6 +30,7 @@ import com.yeshi.fanli.service.inter.push.IOSPushService; import com.yeshi.fanli.service.inter.user.ExtractService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; /** * 系统初始化 @@ -63,6 +64,10 @@ @Resource private QualityFactoryService qualityFactoryService; @Resource private UserSystemCouponService userSystemCouponService; private static boolean isInited = false; @@ -415,11 +420,9 @@ ThreeSale threeSale = map.get(key); if (threeSale != null) { if (threeSale.getState() != null && threeSale.getState() == true) { // 邀请成功 // TODO 券激活生效 // threeSale.getBoss().getId(); // 邀请成功 - 券激活生效 Long bossId = threeSale.getBoss().getId(); userSystemCouponService.activatedWelfareFreeCoupon(bossId); } } ThreeSaleCMQManager.getInstance()