fanli/src/main/java/com/yeshi/fanli/dao/mybatis/HongBaoV2CountMapper.java
@@ -169,5 +169,23 @@ * @return */ long countShareOrInviteOrder(@Param("uid") Long uid); /** * 统计下级产生有效分享奖金 * @param uid * @param teamUid 下级id * @param endTime 结束时间 * @return */ BigDecimal getShareRewardByTeamUid(@Param("uid") Long uid, @Param("teamUid") Long teamUid, @Param("endTime") Date endTime); /** * 统计下级上个有效订单 * @param uid * @param teamUid 下级id * @param endTime 结束时间 * @return */ BigDecimal getShareRewardByTeamUidLastMonth(@Param("uid") Long uid, @Param("teamUid") Long teamUid); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/CommonOrderMapper.java
@@ -329,4 +329,11 @@ * @return */ BigDecimal getTotalRewardMoneyByOrderNoAndSourceType(@Param("orderNo") String orderNo, @Param("sourceType") Integer sourceType); /** * 统计24小时有效自购订单 * @param uid * @return */ long count24HValidOrderByUid(@Param("uid") Long uid, @Param("minTime") Date minTime); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/redpack/RedPackWinInviteMapper.java
@@ -25,10 +25,26 @@ * @param type * @return */ long countByUidAndTeamUidAndType(@Param("uid")Long uid,@Param("teamUid")Long teamUid, @Param("type")String type); int countByUidAndTeamUidAndType(@Param("uid")Long uid,@Param("teamUid")Long teamUid, @Param("type")String type); /** * 统计用户、下级、类型的数量 * @param uid * @param type * @return */ RedPackWinInvite getByUidAndTeamUidAndType(@Param("uid")Long uid,@Param("teamUid")Long teamUid, @Param("type")String type); /** * 统计用户、下级、类型的数量 * @param uid * @param type * @return */ RedPackWinInvite getByUidAndTeamUidAndTypeMonth(@Param("uid")Long uid,@Param("teamUid")Long teamUid, @Param("type")String type); /** * 查询用户记录 * @param start * @param count fanli/src/main/java/com/yeshi/fanli/dto/msg/MsgRedPackAddContentDTO.java
File was deleted fanli/src/main/java/com/yeshi/fanli/dto/msg/MsgRedPackTeamRewardContentDTO.java
New file @@ -0,0 +1,26 @@ package com.yeshi.fanli.dto.msg; /** * 红包奖励-队友 * * @author Administrator * */ public class MsgRedPackTeamRewardContentDTO { private String nickName; // 队友昵称 private String portrait; // 队友头像 public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } public String getPortrait() { return portrait; } public void setPortrait(String portrait) { this.portrait = portrait; } } fanli/src/main/java/com/yeshi/fanli/entity/bus/msg/MsgMoneyDetail.java
@@ -37,10 +37,9 @@ redPackGiveBack("红包退回"), redPackExchangePass("红包提现成功"), redPackExchangeReject("红包提现失败"), redPackNewUserReward("新人奖励-完成首笔订单"), redPackInviteSucceed("立得现金-成功邀请好友"), redPackFirstSharedOrder("递增奖励-好友完成订单"), redPackMonthSharedOrder("连续奖励-好友完成订单"), redPackOneStageReward("第一阶段-立得现金-成功邀请好友"), redPackTwoStageReward("第二阶段-递增奖励-好友完成订单"), redPackThreeStageReward("第三阶段-连续奖励-好友完成订单"), redPackUseSuccess("红包使用成功"), redPackUseFail("红包使用失败"); fanli/src/main/java/com/yeshi/fanli/entity/redpack/RedPackWinInvite.java
@@ -16,9 +16,9 @@ public class RedPackWinInvite { public enum RedPackWinInviteTypeEnum { newUserReward("首次使用板栗快省新人奖励"), inviteSucceed("成功邀请好友立得现金"), firstSharedOrder("完成分享订单递增奖励"), monthSharedOrder("完成分享订单连续奖励"); oneStageReward("成功邀请好友立得现金"), twoStageReward("完成分享订单递增奖励"), threeStageReward("完成分享订单连续奖励"); private final String desc; fanli/src/main/java/com/yeshi/fanli/mapping/hongbao/HongBaoV2CountMapper.xml
@@ -359,4 +359,20 @@ AND (`hb_type` =5 OR `hb_type` =6 OR `hb_type` =7 OR `hb_type` =20 OR `hb_type`=21 OR `hb_type` =22 ) </select> <select id="getShareRewardByTeamUid" resultType="BigDecimal"> SELECT SUM(v2.`hb_money`) FROM yeshi_ec_hongbao_v2 v2 LEFT JOIN yeshi_ec_hongbao_v2 p ON p.`hb_id` = v2.`hb_pid` WHERE v2.`hb_type` = 21 AND v2.`hb_state` = 3 AND v2.`hb_uid` = #{uid} AND p.`hb_uid` = #{teamUid} AND v2.`hb_create_time`<![CDATA[<=]]> #{endTime} </select> <select id="getShareRewardByTeamUidLastMonth" resultType="BigDecimal"> SELECT SUM(v2.`hb_money`) FROM yeshi_ec_hongbao_v2 v2 LEFT JOIN yeshi_ec_hongbao_v2 p ON p.`hb_id` = v2.`hb_pid` WHERE v2.`hb_type` = 21 AND v2.`hb_state` = 3 AND v2.`hb_uid` = #{uid} AND p.`hb_uid` = #{teamUid} AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'), DATE_FORMAT(v2.`hb_create_time`, '%Y%m')) = 1 </select> </mapper> fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -1048,5 +1048,15 @@ WHERE v2.`hb_type` = 20 AND v2.`hb_state` = 3 AND co.`co_order_no` = #{orderNo} AND co.`co_source_type`= #{sourceType})A </select> <select id="count24HValidOrderByUid" resultType="Long"> SELECT IFNULL(COUNT(A.co_order_no),0) FROM (SELECT co.`co_order_no` FROM yeshi_ec_hongbao_order ho LEFT JOIN yeshi_ec_hongbao_v2 v2 ON v2.hb_id = ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE v2.`hb_type` = 1 AND co.`co_state_whole_order`<![CDATA[<>]]> 3 AND co.`co_uid` = #{uid} AND co.co_third_create_time <![CDATA[>]]> #{minTime} AND co.`co_third_create_time` <![CDATA[<=]]> DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY co.`co_order_no`,co.`co_source_type`)A </select> </mapper> fanli/src/main/java/com/yeshi/fanli/mapping/redpack/RedPackWinInviteMapper.xml
@@ -62,11 +62,24 @@ WHERE d.`rwr_uid` = #{uid} AND d.`rwr_type` = #{type} </select> <select id="countByUidAndTeamUidAndType" resultType="Long"> <select id="countByUidAndTeamUidAndType" resultType="Integer"> SELECT IFNULL(COUNT(d.`rwr_id`),0) FROM yeshi_ec_red_pack_win_invite d WHERE d.`rwr_uid` = #{uid} AND d.`rwr_team_uid` = #{teamUid} AND d.`rwr_type` = #{type} </select> <select id="getByUidAndTeamUidAndType" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_red_pack_win_invite d WHERE d.`rwr_uid` = #{uid} AND d.`rwr_team_uid` = #{teamUid} AND d.`rwr_type` = #{type} LIMIT 1 </select> <select id="getByUidAndTeamUidAndTypeMonth" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_red_pack_win_invite d WHERE d.`rwr_uid` = #{uid} AND d.`rwr_team_uid` = #{teamUid} AND d.`rwr_type` = #{type} AND DATE_FORMAT(d.rwr_create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') LIMIT 1 </select> <select id="getRewardList" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_red_pack_win_invite d WHERE d.`rwr_uid` = #{uid} fanli/src/main/java/com/yeshi/fanli/service/impl/count/HongBaoV2CountServiceImpl.java
@@ -297,4 +297,13 @@ return hongBaoV2CountMapper.countAlreadyGetMoneyByUid(uid, typeList, minGetTime, maxGetTime); } @Override public BigDecimal getShareRewardByTeamUid(Long uid, Long teamUid, Date endTime) { return hongBaoV2CountMapper.getShareRewardByTeamUid(uid, teamUid, endTime); } @Override public BigDecimal getShareRewardByTeamUidLastMonth(Long uid, Long teamUid) { return hongBaoV2CountMapper.getShareRewardByTeamUidLastMonth(uid, teamUid); } } fanli/src/main/java/com/yeshi/fanli/service/impl/money/msg/MsgMoneyDetailServiceImpl.java
@@ -131,10 +131,9 @@ || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackGiveBack || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackExchangePass || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackExchangeReject || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackNewUserReward || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackInviteSucceed || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackFirstSharedOrder || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackMonthSharedOrder || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackOneStageReward || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackTwoStageReward || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackThreeStageReward || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackUseFail || detail.getMsgType() == MsgTypeMoneyTypeEnum.redPackUseSuccess) { if (detail.getUser() == null) fanli/src/main/java/com/yeshi/fanli/service/impl/money/msg/UserMoneyMsgNotificationServiceImpl.java
@@ -14,6 +14,7 @@ import com.yeshi.fanli.entity.bus.user.AlipayAccountValidNormalHistory; import com.yeshi.fanli.entity.bus.user.Extract; import com.yeshi.fanli.entity.bus.user.ExtractWeiXinRecord; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.config.push.PushMsgFactory; import com.yeshi.fanli.exception.msg.MsgMoneyDetailException; import com.yeshi.fanli.exception.push.PushException; @@ -295,6 +296,25 @@ e.printStackTrace(); } } @Override public void teamRedPackRewardMsg(Long uid, MsgTypeMoneyTypeEnum type,BigDecimal money, String stateDesc, String content) { MsgMoneyDetail detail = new MsgMoneyDetail(); detail.setRead(false); detail.setMoney(money); detail.setMsgType(type); detail.setContent(content); detail.setStateDesc(stateDesc); detail.setUser(new UserInfo(uid)); detail.setBeiZhu("系统已下发到“我的-红包”中"); detail.setCreateTime(new Date()); try { msgMoneyDetailService.addMsgMoneyDetail(detail); } catch (MsgMoneyDetailException e) { e.printStackTrace(); } } @Override public void inviteOrderSubSidy(Long uid, Date date, String from, BigDecimal money, BigDecimal balance) { fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -1605,4 +1605,10 @@ public BigDecimal getTotalRewardMoneyByOrderNoAndSourceType(String orderNo, Integer sourceType) { return commonOrderMapper.getTotalRewardMoneyByOrderNoAndSourceType(orderNo, sourceType); } @Override public long count24HValidOrderByUid(Long uid, Date minTime) { return commonOrderMapper.count24HValidOrderByUid(uid, minTime); } } fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackWinInviteServiceImpl.java
@@ -12,15 +12,15 @@ import com.google.gson.Gson; import com.yeshi.fanli.dao.mybatis.redpack.RedPackWinInviteMapper; import com.yeshi.fanli.dto.msg.MsgRedPackAddContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackTeamRewardContentDTO; import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum; import com.yeshi.fanli.entity.bus.user.ThreeSale; import com.yeshi.fanli.entity.bus.user.UserActiveLog; import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.order.CommonOrder; import com.yeshi.fanli.entity.redpack.RedPackWinInvite; import com.yeshi.fanli.entity.redpack.RedPackWinInvite.RedPackWinInviteTypeEnum; import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; @@ -37,7 +37,6 @@ import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService; import com.yeshi.fanli.util.factory.RedPackDetailFactory; import com.yeshi.fanli.vo.order.CommonOrderVO; @Service public class RedPackWinInviteServiceImpl implements RedPackWinInviteService { @@ -72,6 +71,9 @@ @Resource private UserActiveLogService userActiveLogService; @Resource private HongBaoV2CountService hongBaoV2CountService; @Override public List<RedPackWinInvite> getRewardList(int start, int count, Long uid) { @@ -89,6 +91,76 @@ return redPackWinInviteMapper.getRewardMoney(uid); } @Override @RequestSerializableByKeyService(key = "#teamUid") @Transactional(rollbackFor = Exception.class) public void inviteSucceedReward(Long teamUid) throws Exception{ // 是否在上线之后的邀请关系 ThreeSale threeSale = threeSaleSerivce.getByWorkerIdAndTime(teamUid, Constant.RED_PACK_REWARD_TIME); if (threeSale == null) return; // 上级id Long bossId = threeSale.getBoss().getId(); UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId); if (activeLog == null) return; // 小于2.0.2版本不增加 if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) return; // 同一队员奖励一次 int totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(bossId, teamUid, RedPackWinInviteTypeEnum.oneStageReward.name()); if (totalReward > 0) return; // 建立邀请关系时间超过20天 Long succeedTime = threeSale.getSucceedTime(); Date endDate = DateUtil.plusDayDate(Constant.ONE_STAGE_LIMIT_DAYS, new Date(succeedTime)); if (endDate.getTime() < java.lang.System.currentTimeMillis()) return; // 绑定电话号码和微信 UserInfo userInfo = userInfoService.selectByPKey(teamUid); if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getPhone()) || StringUtil.isNullOrEmpty(userInfo.getWxOpenId())) return; // 授权淘宝 UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(teamUid); if (taoBaoInfo == null || StringUtil.isNullOrEmpty(taoBaoInfo.getTaoBaoUid())) return; // 好友产生一笔返利订单(自购)且 24 小时内不失效; long validOrder = commonOrderService.count24HValidOrderByUid(teamUid, new Date(succeedTime)); if (validOrder < 1) return; // 奖励金额 BigDecimal money = Constant.ONE_STAGE_MONEY; // 获得红包 RedPackWinInvite winInvite = new RedPackWinInvite(); winInvite.setCreateTime(new Date()); winInvite.setUpdateTime(new Date()); winInvite.setType(RedPackWinInviteTypeEnum.oneStageReward); winInvite.setUid(bossId); winInvite.setTeamUid(teamUid); winInvite.setMoney(money); redPackWinInviteMapper.insertSelective(winInvite); // 增加红包 redPackBalanceService.addRedPack(bossId, money, RedPackDetailFactory.createInvite(winInvite)); // 消息 MsgRedPackTeamRewardContentDTO dto = new MsgRedPackTeamRewardContentDTO(); dto.setNickName(userInfo.getNickName()); dto.setPortrait(userInfo.getPortrait()); userMoneyMsgNotificationService.teamRedPackRewardMsg(bossId, MsgTypeMoneyTypeEnum.redPackOneStageReward, money, "队员(好友)完成第一阶段", new Gson().toJson(dto)); } @RequestSerializableByKeyService(key = "#uid") @Transactional(rollbackFor = Exception.class) @@ -100,19 +172,7 @@ ThreeSale threeSale = threeSaleSerivce.getByWorkerIdAndTime(uid, Constant.RED_PACK_REWARD_TIME); if(threeSale == null) return; Long bossId = threeSale.getBoss().getId(); UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId); if (activeLog == null) return; // 小于2.0.2版本不增加 if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) return; // 奖励上级 bossReward(bossId, uid, source, orderNo); bossReward(threeSale.getBoss().getId(), uid, source, orderNo); } @@ -125,68 +185,77 @@ * @throws Exception */ @Transactional private void bossReward(Long uid, Long teamUid, Integer source, String orderNo) throws Exception { firstSharedOrderRewardToBoss(uid, teamUid, source, orderNo); firstSharedOrderRewardTheMonthToBoss(uid, teamUid, source, orderNo); private void bossReward(Long bossId, Long teamUid, Integer source, String orderNo) throws Exception { UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId); if (activeLog == null) return; // 小于2.0.2版本不增加 if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) return; // 第一阶段(验证) RedPackWinInvite oneStage = redPackWinInviteMapper.getByUidAndTeamUidAndType(bossId, teamUid, RedPackWinInviteTypeEnum.oneStageReward.name()); if (oneStage == null) return; // 第二阶段(验证) RedPackWinInvite twoStage = redPackWinInviteMapper.getByUidAndTeamUidAndType(bossId, teamUid, RedPackWinInviteTypeEnum.twoStageReward.name()); if (twoStage == null) { twoStageRewardToBoss(bossId, teamUid, oneStage.getCreateTime(), source, orderNo); return; } // 第三阶段 threeStageRewardToBoss(bossId, teamUid, twoStage.getCreateTime(), source, orderNo); } /** * 上级奖励:被邀请人完成首笔分享订单 (已到账) * 上级奖励--第二阶段 * @param uid * @param source * @param orderNo * @param bossId */ @Transactional private void firstSharedOrderRewardToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{ // 1、同一队员奖励一次 long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(uid, inviteeUid, RedPackWinInviteTypeEnum.firstSharedOrder.name()); if (totalReward > 0) private void twoStageRewardToBoss(Long bossId, Long teamUid, Date oneStageTime, Integer source, String orderNo) throws Exception{ // 第一阶段完成之后的90天内 ; 队友产生的订单中(自购+分享),邀请人累计产生≥1 元奖金 Date endDate = DateUtil.plusDayDate(Constant.TWO_STAGE_LIMIT_DAYS, oneStageTime); BigDecimal rewardMoney = hongBaoV2CountService.getShareRewardByTeamUid(bossId, teamUid, endDate); if (rewardMoney == null || rewardMoney.compareTo(Constant.TWO_STAGE_ORDER_REWARD_MIN) < 0) return; // 2、是否下级的首个分享订单 CommonOrder commonOrder = commonOrderService.getFirstShareOrderByUid(inviteeUid); if (commonOrder == null || !orderNo.equals(commonOrder.getOrderNo()) || source != commonOrder.getSourceType()) return ; // 3、到账奖励金额 是否大于5 BigDecimal totalRewardMoney = commonOrderService.getTotalRewardMoneyByOrderNoAndSourceType(orderNo, source); if (totalRewardMoney == null || totalRewardMoney.compareTo(Constant.RED_PACK_ORDER_REWARD_MIN) < 0) return; // 2、判断是第几个人 long total = redPackWinInviteMapper.countByUidAndType(uid, RedPackWinInviteTypeEnum.firstSharedOrder.name()); // 计算应增加红包金额 BigDecimal money = new BigDecimal(redPackConfigService.getValueByKey("first_shared_order")); long num = total % 9; if (num > 0) { BigDecimal addMoney = new BigDecimal(redPackConfigService.getValueByKey("first_shared_order_add")); money = MoneyBigDecimalUtil.add(money, MoneyBigDecimalUtil.mul(addMoney, new BigDecimal(num))); // 计算奖励 BigDecimal money = Constant.TWO_STAGE_MONEY_MIN; long total = redPackWinInviteMapper.countByUidAndType(bossId, RedPackWinInviteTypeEnum.twoStageReward.name()); if (total > 0 && total < Constant.TWO_STAGE_MONEY_ADD_NUM) { long num = total % Constant.TWO_STAGE_MONEY_ADD_NUM; money = MoneyBigDecimalUtil.add(money, MoneyBigDecimalUtil.mul(Constant.TWO_STAGE_MONEY_ADD, new BigDecimal(num))); } // 3、获得红包记录 // 获得红包记录 RedPackWinInvite winInvite = new RedPackWinInvite(); winInvite.setCreateTime(new Date()); winInvite.setUpdateTime(new Date()); winInvite.setType(RedPackWinInviteTypeEnum.firstSharedOrder); winInvite.setUid(uid); winInvite.setTeamUid(inviteeUid); winInvite.setUid(bossId); winInvite.setTeamUid(teamUid); winInvite.setMoney(money); winInvite.setSource(source); winInvite.setOrderNo(orderNo); winInvite.setCreateTime(new Date()); winInvite.setUpdateTime(new Date()); winInvite.setType(RedPackWinInviteTypeEnum.twoStageReward); redPackWinInviteMapper.insertSelective(winInvite); // 4、增加红包 redPackBalanceService.addRedPack(uid, money, RedPackDetailFactory.createIncreaseReward(winInvite)); redPackBalanceService.addRedPack(bossId, money, RedPackDetailFactory.createIncreaseReward(winInvite)); // 5、消息 MsgRedPackAddContentDTO dto = new MsgRedPackAddContentDTO(); dto.setTitle("红包增加"); dto.setMoney("¥" + money.setScale(2)); dto.setBalance("¥" + redPackBalanceService.getBalance(uid).setScale(2)); userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackFirstSharedOrder, new Gson().toJson(dto), "请到“我的-红包”中查看"); UserInfo userInfo = userInfoService.selectByPKey(teamUid); MsgRedPackTeamRewardContentDTO dto = new MsgRedPackTeamRewardContentDTO(); dto.setNickName(userInfo.getNickName()); dto.setPortrait(userInfo.getPortrait()); userMoneyMsgNotificationService.teamRedPackRewardMsg(bossId, MsgTypeMoneyTypeEnum.redPackTwoStageReward, money, "队员(好友)完成第二阶段", new Gson().toJson(dto)); } @@ -198,31 +267,33 @@ * @param bossId */ @Transactional private void firstSharedOrderRewardTheMonthToBoss(Long uid, Long inviteeUid, Integer source, String orderNo) throws Exception{ // 1、判断是否是上个月首单 CommonOrderVO order = commonOrderService.firstValidOrderLastMonthByUidAndType(inviteeUid, 2); if (order == null || source != order.getSourceType() || !orderNo.equals(order.getOrderNo()) || order.getAccountTime() == null) private void threeStageRewardToBoss(Long bossId, Long teamUid, Date twoStageTime, Integer source, String orderNo) throws Exception{ // 二、三阶段不可同月 if (DateUtil.isSameMonth(twoStageTime, new Date())) return; // 分享订单实付款≥10元 if (order.getPayment() == null || order.getPayment().compareTo(Constant.RED_PACK_PAY_MIN) < 0) // 是否已领取本月 RedPackWinInvite threeStage = redPackWinInviteMapper.getByUidAndTeamUidAndTypeMonth(bossId, teamUid, RedPackWinInviteTypeEnum.threeStageReward.name()); if (threeStage != null) return; // 已奖励次数 int totalNum = redPackWinInviteMapper.countByUidAndTeamUidAndType(bossId, teamUid, RedPackWinInviteTypeEnum.threeStageReward.name()); if (totalNum >= Constant.THREE_STAGE_REWARD_MONTH) return; // 2、是否下级的首个分享订单 // CommonOrder firstorder = commonOrderService.getFirstShareOrderByUid(inviteeUid); // if (firstorder == null || (orderNo.equals(firstorder.getOrderNo()) && source == firstorder.getSourceType())); // return; // 是否已间断 int monthSpace = DateUtil.getMonthSpace(twoStageTime, new Date()); if (monthSpace != totalNum + 1) return; // 第一次到账的次月开始连续15个月 自然月获得(已到账) // int monthSpace = DateUtil.getMonthSpace(order.getThirdCreateTime(), firstorder.getThirdCreateTime()); // if (monthSpace == 0 || monthSpace > Constant.RED_PACK_REWARD_MONTH) // return; // 每月给你累计产生≥2 元 BigDecimal rewardMoney = hongBaoV2CountService.getShareRewardByTeamUidLastMonth(bossId, teamUid); if (rewardMoney == null || rewardMoney.compareTo(Constant.THREE_STAGE_ORDER_REWARD_MIN) < 0) return; // 计算随机奖励 double randomMoney = Constant.RED_PACK_RANDOM_MIN + Math.random() * (Constant.RED_PACK_RANDOM_MAX - Constant.RED_PACK_RANDOM_MIN); double randomMoney = Constant.THREE_STAGE_RANDOM_MIN + Math.random() * (Constant.THREE_STAGE_RANDOM_MAX - Constant.THREE_STAGE_RANDOM_MIN); // 保留两位小数 BigDecimal money = new BigDecimal(randomMoney).setScale(2, BigDecimal.ROUND_HALF_UP); @@ -230,109 +301,24 @@ RedPackWinInvite winInvite = new RedPackWinInvite(); winInvite.setCreateTime(new Date()); winInvite.setUpdateTime(new Date()); winInvite.setType(RedPackWinInviteTypeEnum.monthSharedOrder); winInvite.setUid(uid); winInvite.setTeamUid(inviteeUid); winInvite.setType(RedPackWinInviteTypeEnum.threeStageReward); winInvite.setUid(bossId); winInvite.setTeamUid(teamUid); winInvite.setMoney(money); winInvite.setSource(source); winInvite.setOrderNo(orderNo); redPackWinInviteMapper.insertSelective(winInvite); // 4、增加红包 redPackBalanceService.addRedPack(uid, money, RedPackDetailFactory.createSeriesReward(winInvite)); redPackBalanceService.addRedPack(bossId, money, RedPackDetailFactory.createSeriesReward(winInvite)); //消息 MsgRedPackAddContentDTO dto = new MsgRedPackAddContentDTO(); dto.setTitle("红包增加"); dto.setMoney("¥" + money.setScale(2)); dto.setBalance("¥" + redPackBalanceService.getBalance(uid).setScale(2)); userMoneyMsgNotificationService.redPackMsg(uid, MsgTypeMoneyTypeEnum.redPackMonthSharedOrder, new Gson().toJson(dto), "请到“我的-红包”中查看"); // 消息 UserInfo userInfo = userInfoService.selectByPKey(teamUid); MsgRedPackTeamRewardContentDTO dto = new MsgRedPackTeamRewardContentDTO(); dto.setNickName(userInfo.getNickName()); dto.setPortrait(userInfo.getPortrait()); userMoneyMsgNotificationService.teamRedPackRewardMsg(bossId, MsgTypeMoneyTypeEnum.redPackThreeStageReward, money, "队员(好友)完成第三阶段连续[第"+ monthSpace + "个月]", new Gson().toJson(dto)); } @Override @RequestSerializableByKeyService(key = "#uid") @Transactional(rollbackFor = Exception.class) public void inviteSucceedReward(Long uid) throws Exception{ // 验证是否存在上级 ThreeSale threeSale = threeSaleSerivce.getByWorkerIdAndTime(uid, Constant.RED_PACK_REWARD_TIME); if (threeSale == null) return; // 上级id Long bossId = threeSale.getBoss().getId(); UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(bossId); if (activeLog == null) return; // 小于2.0.2版本不增加 if (!VersionUtil.greaterThan_2_1("appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) return; // 同一队员奖励一次 long totalReward = redPackWinInviteMapper.countByUidAndTeamUidAndType(bossId, uid, RedPackWinInviteTypeEnum.inviteSucceed.name()); if (totalReward > 0) return; // 1、绑定电话号码 UserInfo userInfo = userInfoService.selectByPKey(uid); if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getPhone())) return; // 2、授权淘宝 UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); if (taoBaoInfo == null || StringUtil.isNullOrEmpty(taoBaoInfo.getTaoBaoUid())) return; boolean finishTask = false; // 3.1、产生任意有效订单(无需到账) CommonOrder commonOrder = commonOrderService.selectLatestValidByUid(uid); if (commonOrder != null) finishTask = true; // 3.2、单位时间类累计产生≥200金币 if (!finishTask) { long totalGoldCoin = integralTaskRecordService.getTotalGoldCoinByUid(uid); if (totalGoldCoin >= Constant.RED_PACK_GOLD_COIN) finishTask = true; } // 3.3、成功邀请一个好友 if (!finishTask) { long countTeam = threeSaleSerivce.countSuccessFirstTeam(uid); if (countTeam >= 1) finishTask = true; } if (finishTask) { // 奖励金额 BigDecimal money = new BigDecimal(redPackConfigService.getValueByKey("invite_succeed")); // 获得红包记录 RedPackWinInvite winInvite = new RedPackWinInvite(); winInvite.setCreateTime(new Date()); winInvite.setUpdateTime(new Date()); winInvite.setType(RedPackWinInviteTypeEnum.inviteSucceed); winInvite.setUid(bossId); winInvite.setTeamUid(uid); winInvite.setMoney(money); redPackWinInviteMapper.insertSelective(winInvite); // 增加红包 redPackBalanceService.addRedPack(bossId, money, RedPackDetailFactory.createInvite(winInvite)); // 消息 MsgRedPackAddContentDTO dto = new MsgRedPackAddContentDTO(); dto.setTitle("红包增加"); dto.setMoney("¥" + money.setScale(2)); dto.setBalance("¥" + redPackBalanceService.getBalance(bossId).setScale(2)); userMoneyMsgNotificationService.redPackMsg(bossId, MsgTypeMoneyTypeEnum.redPackInviteSucceed, new Gson().toJson(dto), "请到“我的-红包”中查看"); } } } fanli/src/main/java/com/yeshi/fanli/service/inter/count/HongBaoV2CountService.java
@@ -184,4 +184,21 @@ public long countAlreadyGetMoneyByUid(Long uid, List<Integer> typeList, Date minGetTime, Date maxGetTime); /** * 查询来源该下级成功分享奖金活动 * @param uid * @param teamUid * @param endTime * @return */ public BigDecimal getShareRewardByTeamUid(Long uid, Long teamUid, Date endTime); /** * 统计下级上个有效订单 * @param uid * @param teamUid 下级id * @return */ public BigDecimal getShareRewardByTeamUidLastMonth(Long uid, Long teamUid); } fanli/src/main/java/com/yeshi/fanli/service/inter/money/msg/UserMoneyMsgNotificationService.java
@@ -155,10 +155,6 @@ */ public void extractAuto(ExtractWeiXinRecord extractRecord, String stateDesc, String desc, String beiZhu); /** * 红包消息 */ public void redPackMsg(Long uid, MsgTypeMoneyTypeEnum type, String content, String beiZhu); /** * 补贴消息 @@ -171,4 +167,14 @@ */ public void inviteOrderSubSidy(Long uid, Date date, String from, BigDecimal money, BigDecimal balance); /** * 红包消息 */ public void redPackMsg(Long uid, MsgTypeMoneyTypeEnum type, String content, String beiZhu); /** * 红包消息-队友奖励 */ public void teamRedPackRewardMsg(Long uid, MsgTypeMoneyTypeEnum type, BigDecimal money, String stateDesc,String content); } fanli/src/main/java/com/yeshi/fanli/service/inter/order/CommonOrderService.java
@@ -345,4 +345,12 @@ */ public BigDecimal getTotalRewardMoneyByOrderNoAndSourceType(String orderNo, Integer sourceType); /** * 统计24小时有效自购订单 * @param uid * @param minTime * @return */ public long count24HValidOrderByUid(Long uid, Date minTime); } fanli/src/main/java/com/yeshi/fanli/util/Constant.java
@@ -123,21 +123,33 @@ public static final int AUTO_EXTRACT_MONEY = 1; // 微信自动提现最低余额 public static final int AUTO_EXTRACT_MIN_SURPLUS = 2; // 红包奖励-到账奖励不低于5元 public static final BigDecimal RED_PACK_ORDER_REWARD_MIN = new BigDecimal("5"); // 红包奖励随机范围 public static final double RED_PACK_RANDOM_MIN = 0.5; public static final double RED_PACK_RANDOM_MAX = 2; // 红包奖励订单实付款最低 public static final BigDecimal RED_PACK_PAY_MIN = new BigDecimal("10"); // 红包奖励分享订单连续奖励月数 public static final int RED_PACK_REWARD_MONTH = 15; // 红包奖励-单位时间类累计产生≥200金币 public static final long RED_PACK_GOLD_COIN = 200; // 红包奖励-邀请时间筛选 2019-11-14 11:51:43 public static final long RED_PACK_REWARD_TIME = 1573703503000L; // 一阶段:20天数限制 public static final int ONE_STAGE_LIMIT_DAYS = 20; // 一阶段:立得现金3元 public static final BigDecimal ONE_STAGE_MONEY = new BigDecimal("3"); // 二阶段:90天数限制 public static final int TWO_STAGE_LIMIT_DAYS = 90; // 二阶段:-队友产生的订单中(自购+分享),邀请人累计产生≥1 元奖金 public static final BigDecimal TWO_STAGE_ORDER_REWARD_MIN = new BigDecimal("1"); // 二阶段: 红包金额最少3元 public static final BigDecimal TWO_STAGE_MONEY_MIN = new BigDecimal("3"); // 二阶段:每次最多增加0.5 public static final BigDecimal TWO_STAGE_MONEY_ADD = new BigDecimal("0.5"); // 二阶段: 增加9次 public static final int TWO_STAGE_MONEY_ADD_NUM = 9; // 三阶段:连续奖励月数 public static final int THREE_STAGE_REWARD_MONTH = 15; // 三阶段:-连续 15 个月好友每月“给你累计产生≥2 元奖 金” public static final BigDecimal THREE_STAGE_ORDER_REWARD_MIN = new BigDecimal("2"); // 三阶段:红包奖励随机范围 public static final double THREE_STAGE_RANDOM_MIN = 1.5; public static final double THREE_STAGE_RANDOM_MAX = 2; // 新人奖励连续天数 public static final long RED_PACK_NEW_USER_DAYS = 7; fanli/src/main/java/com/yeshi/fanli/util/factory/msg/MsgMoneyDetailFactory.java
@@ -4,6 +4,8 @@ import java.util.Calendar; import java.util.Date; import org.yeshi.utils.StringUtil; import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail; import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum; import com.yeshi.fanli.entity.bus.user.AlipayAccountValidNormalHistory; @@ -11,7 +13,6 @@ import com.yeshi.fanli.entity.bus.user.ExtractWeiXinRecord; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; public class MsgMoneyDetailFactory { @@ -365,26 +366,6 @@ } /** * 红包相关信息 * @param uid * @param type * @param content * @param beiZhu * @return */ public static MsgMoneyDetail createRedPackMsg(Long uid, MsgTypeMoneyTypeEnum type, String content, String beiZhu) { if (uid == null || type == null || StringUtil.isNullOrEmpty(content)) return null; MsgMoneyDetail detail = new MsgMoneyDetail(); detail.setUser(new UserInfo(uid)); detail.setRead(false); detail.setContent(content); detail.setMsgType(type); detail.setBeiZhu(beiZhu); detail.setCreateTime(new Date()); return detail; } /** * 邀请订单补贴 @@ -417,5 +398,27 @@ return detail; } /** * 红包相关信息 * @param uid * @param type * @param content * @param beiZhu * @return */ public static MsgMoneyDetail createRedPackMsg(Long uid, MsgTypeMoneyTypeEnum type, String content, String beiZhu) { if (uid == null || type == null || StringUtil.isNullOrEmpty(content)) return null; MsgMoneyDetail detail = new MsgMoneyDetail(); detail.setUser(new UserInfo(uid)); detail.setRead(false); detail.setContent(content); detail.setMsgType(type); detail.setBeiZhu(beiZhu); detail.setCreateTime(new Date()); return detail; } } fanli/src/main/java/com/yeshi/fanli/util/factory/msg/UserMsgVOFactory.java
@@ -14,9 +14,9 @@ import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO; import com.yeshi.fanli.dto.msg.MsgOtherSystemGiveDTO; import com.yeshi.fanli.dto.msg.MsgOtherTaoLiJinContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackAddContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackExchangeContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackGiveContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackTeamRewardContentDTO; import com.yeshi.fanli.dto.msg.MsgRedPackUseContentDTO; import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail; import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail.MsgTypeAccountTypeEnum; @@ -741,35 +741,34 @@ return new UserMsgVO("http://img.flqapp.com/resource/msg/icon_hongbao_tixian.png", dto.getTitle(), msg.getUpdateTime() == null ? msg.getCreateTime() : msg.getUpdateTime(), items); } else if (msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackNewUserReward || msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackInviteSucceed || msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackFirstSharedOrder || msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackMonthSharedOrder) { // 红包邀请获得 } else if (msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackOneStageReward || msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackTwoStageReward || msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackThreeStageReward) { // 红包邀请获得 if (StringUtil.isNullOrEmpty(msg.getContent())) return null; MsgRedPackAddContentDTO dto = new Gson().fromJson(msg.getContent(), MsgRedPackAddContentDTO.class); MsgRedPackTeamRewardContentDTO dto = new Gson().fromJson(msg.getContent(), MsgRedPackTeamRewardContentDTO.class); if (dto == null) return null; contentList = new ArrayList<>(); contentList.add(new ClientTextStyleVO(msg.getMsgType().getDesc() + "", COLOR_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("增加原因", COLOR_TITLE), contentList)); contentList.add(new ClientTextStyleVO(dto.getNickName() + "", COLOR_CONTENT,dto.getPortrait())); items.add(new CommonMsgItemVO(new ClientTextStyleVO("被邀请人", COLOR_TITLE), contentList)); contentList = new ArrayList<>(); contentList.add(new ClientTextStyleVO(msg.getStateDesc(), COLOR_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("红包进程", COLOR_TITLE), contentList)); contentList = new ArrayList<>(); contentList.add(new ClientTextStyleVO(dto.getMoney() + "", COLOR_HIGHLIGHT_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("金 额", COLOR_TITLE), contentList)); contentList = new ArrayList<>(); contentList.add(new ClientTextStyleVO(dto.getBalance() + "", COLOR_HIGHLIGHT_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("红包余额", COLOR_TITLE), contentList)); contentList.add(new ClientTextStyleVO("¥" + filterMoney(msg.getMoney()) + "", COLOR_HIGHLIGHT_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("红包金额", COLOR_TITLE), contentList)); contentList = new ArrayList<>(); contentList.add(new ClientTextStyleVO(StringUtil.isNullOrEmpty(msg.getBeiZhu()) ? "无" : msg.getBeiZhu(), COLOR_CONTENT)); items.add(new CommonMsgItemVO(new ClientTextStyleVO("备 注", COLOR_TITLE), contentList)); return new UserMsgVO("http://img.flqapp.com/img/tlj/icon_tlj.png", dto.getTitle(), return new UserMsgVO("http://img.flqapp.com/img/tlj/icon_tlj.png", "红包提醒", msg.getUpdateTime() == null ? msg.getCreateTime() : msg.getUpdateTime(), items); } else if (msg.getMsgType() == MsgTypeMoneyTypeEnum.redPackUseSuccess) { // 红包使用成功 if (StringUtil.isNullOrEmpty(msg.getContent()))