| | |
| | | private AccountMapper accountMapper; |
| | | @Autowired |
| | | private UserMapper userMapper; |
| | | @Autowired |
| | | private ScoreDetailsMapper scoreDetailsMapper; |
| | | @Autowired |
| | | private UserShareInfoMapper userShareInfoMapper; |
| | | @Autowired |
| | | private OrderMapper orderMapper; |
| | | |
| | | /** |
| | | * 团长积分/环保币返利规则 |
| | | * |
| | | * @param orderId |
| | | * @param userId |
| | | */ |
| | | public void distribRecord(Long orderId, String userId) { |
| | | UserHeadRelate userHeadRelate = userHeadRelateMapper.selectRelateByUserId(userId); |
| | | if (userHeadRelate == null) { |
| | |
| | | } |
| | | |
| | | Integer count = userHeadDetailsMapper.selectDetailsCount(userId); |
| | | UserInfo userInfo = userMapper.selectByPrimaryKey(userId); |
| | | AccountInfo accountInfo = accountMapper.selectAccountInfoByUserId(userId); |
| | | // UserInfo userInfo = userMapper.selectByPrimaryKey(userId); |
| | | AccountInfo accountInfo = accountMapper.selectAccountInfoByUserId(userHeadRelate.getHeadUserId()); |
| | | |
| | | if (AccountInfo.IS_PROHIBIT_Y.equals(accountInfo.getIsProhibit())) { |
| | | return; |
| | | } |
| | | |
| | | List<String> remark = new ArrayList<>(); |
| | | BigDecimal totalReturnScore = BigDecimal.ZERO; |
| | | BigDecimal totalReturnCoin = BigDecimal.ZERO; |
| | |
| | | // 首单返利 |
| | | if (StrUtil.isNotBlank(value) && !"0".equals(value)) { |
| | | BigDecimal money = new BigDecimal(value); |
| | | totalReturnScore = totalReturnScore.add(money); |
| | | totalReturnCoin = totalReturnCoin.add(money); |
| | | remark.add("首单返利:" + money); |
| | | } |
| | | } |
| | |
| | | |
| | | if (StrUtil.isNotBlank(value) && !"0".equals(value)) { |
| | | // 首单完成后,在value单内,返利积分或者环保币 |
| | | if (count - 1 <= Integer.parseInt(value)) { |
| | | if (count - 1 < Integer.parseInt(value)) { |
| | | String scoreStr = getRuleValue(redPaperRule, CommonEnum.返利固定积分.getValue()); |
| | | String coinStr = getRuleValue(redPaperRule, CommonEnum.返利环保币比例.getValue()); |
| | | // 根据积分返利固定积分 |
| | |
| | | // 根据订单总积分, 1:40比例,换算成环保币,返对应百分比 |
| | | if (StrUtil.isNotBlank(coinStr) && !"0".equals(coinStr)) { |
| | | BigDecimal coinRatio = new BigDecimal(coinStr).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN); |
| | | BigDecimal totalCoin = totalScore.multiply(new BigDecimal(40)); |
| | | BigDecimal totalCoin = totalScore.divide(new BigDecimal(50), 2, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal returnCoin = totalCoin.multiply(coinRatio).setScale(2, BigDecimal.ROUND_DOWN); |
| | | totalReturnCoin = totalReturnCoin.add(returnCoin); |
| | |
| | | userHeadDetailsMapper.insert(userHeadDetails); |
| | | |
| | | userHeadRelate.setAmount(userHeadRelate.getAmount().add(totalReturnCoin)); |
| | | userHeadRelate.setScore(userHeadDetails.getScore().add(totalReturnScore)); |
| | | userHeadRelate.setScore(userHeadRelate.getScore().add(totalReturnScore)); |
| | | userHeadRelateMapper.updateByPrimaryKey(userHeadRelate); |
| | | |
| | | accountInfo.setAccountId(accountInfo.getAccountId()); |
| | | accountInfo.setMoney(new BigDecimal(accountInfo.getMoney()).add(totalReturnCoin).setScale(2, BigDecimal.ROUND_DOWN).toString()); |
| | | BigDecimal collectScore = StrUtil.isNotBlank(accountInfo.getCollectScore()) ? new BigDecimal(accountInfo.getCollectScore()) : BigDecimal.ZERO; |
| | | accountInfo.setCollectScore(collectScore.add(totalReturnScore).setScale(2, BigDecimal.ROUND_DOWN).toString()); |
| | | accountInfo.setCollectScore(collectScore.add(totalReturnScore).setScale(0, BigDecimal.ROUND_DOWN).toString()); |
| | | accountMapper.updateByPrimaryKey(accountInfo); |
| | | |
| | | if (totalReturnScore.compareTo(BigDecimal.ZERO) > 0) { |
| | | ScoreDetails scoreDetails = new ScoreDetails(); |
| | | scoreDetails.setCurrentScore(new BigDecimal(accountInfo.getCollectScore())); |
| | | scoreDetails.setOriginalScore(collectScore); |
| | | scoreDetails.setChangeScore(totalReturnScore); |
| | | scoreDetails.setCreatedTime(new Date()); |
| | | scoreDetails.setType(ScoreDetails.SCORE_TYPE_OTHER); |
| | | scoreDetails.setUserId(userHeadRelate.getHeadUserId()); |
| | | scoreDetails.setOrderNo(order.getOrderNo()); |
| | | scoreDetailsMapper.insert(scoreDetails); |
| | | } |
| | | |
| | | SysMessage sysMessage = new SysMessage(); |
| | | sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); |
| | |
| | | sysMessage.setUserId(userHeadRelate.getHeadUserId()); |
| | | sysMessage.setMessageType("4"); |
| | | sysMessage.setMessageSubTypeName("返利消息"); |
| | | sysMessage.setMessage("收到用户:" + Base64.decodeStr(userInfo.getNickName()) + "的订单返利, 积分:" + totalReturnScore +", 环保币:" + totalReturnCoin); |
| | | sysMessage.setMessage("收到用户:" + accountInfo.getAccountName().replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2") + "的订单返利, 积分:" + totalReturnScore +", 环保币:" + totalReturnCoin); |
| | | sysMessage.setFlag("2"); |
| | | sysMessageMapper.insert(sysMessage); |
| | | } |
| | | |
| | | /** |
| | | * 普通用户邀请用户并下单返利规则 |
| | | * |
| | | */ |
| | | public void inviteAddOrderScore(String userId, String orderId) { |
| | | UserInfo userInfo = userMapper.selectByPrimaryKey(userId); |
| | | UserShareInfo userShareInfo = userShareInfoMapper.selectUserShareInfoByInvited(userInfo.getMobilePhone()); |
| | | |
| | | if (userShareInfo == null) { |
| | | return; |
| | | } |
| | | |
| | | // 查询当前用户邀请人信息,判断是否为团长,如果是团长,则不返利 |
| | | AccountInfo accountInfo = accountMapper.selectAccountInfoByPhone(userShareInfo.getMobilePhone()); |
| | | if (AccountInfo.IS_HEAD_Y.equals(accountInfo.getIsHead())) { |
| | | log.info("邀请人为团长, 不执行返利"); |
| | | return; |
| | | } |
| | | |
| | | if (AccountInfo.IS_PROHIBIT_Y.equals(accountInfo.getIsProhibit())) { |
| | | return; |
| | | } |
| | | |
| | | List<RedPaperRule> rules = redPaperRuleMapper.selectRuleByType(10); |
| | | if (CollUtil.isEmpty(rules)) { |
| | | log.info("没有具体规则"); |
| | | return; |
| | | } |
| | | |
| | | RedPaperRule rule = rules.get(0); |
| | | if (rule.getStatus() == 0) { |
| | | log.info("规则被禁用, 不执行返利"); |
| | | return; |
| | | } |
| | | |
| | | List<OrderInfo> riderOrders = orderMapper.selectOrderNoWaitAndCancel(userId); |
| | | int riderCnt = 0; |
| | | if (CollUtil.isNotEmpty(riderOrders)) { |
| | | riderCnt = riderOrders.size(); |
| | | } |
| | | |
| | | List<JhyOrder> jhyOrders = jhyOrderMapper.selectJhyOrderNoWaitAndCancel(userId); |
| | | int jhyCnt = 0; |
| | | if (CollUtil.isNotEmpty(jhyOrders)) { |
| | | jhyCnt = jhyOrders.size(); |
| | | } |
| | | |
| | | // 仅首单返利 |
| | | if (jhyCnt + riderCnt > 1) { |
| | | return; |
| | | } |
| | | |
| | | String value = getRuleValue(rule, CommonEnum.推荐首单奖励.getValue()); |
| | | BigDecimal returnScore = BigDecimal.ZERO; |
| | | if (StrUtil.isNotBlank(value)) { |
| | | returnScore = new BigDecimal(value); |
| | | } |
| | | |
| | | BigDecimal collectScore = StrUtil.isNotBlank(accountInfo.getCollectScore()) ? new BigDecimal(accountInfo.getCollectScore()) : BigDecimal.ZERO; |
| | | accountInfo.setCollectScore(collectScore.add(returnScore).setScale(0, BigDecimal.ROUND_DOWN).toString()); |
| | | accountMapper.updateByPrimaryKey(accountInfo); |
| | | |
| | | if (returnScore.compareTo(BigDecimal.ZERO) > 0) { |
| | | ScoreDetails scoreDetails = new ScoreDetails(); |
| | | scoreDetails.setCurrentScore(new BigDecimal(accountInfo.getCollectScore())); |
| | | scoreDetails.setOriginalScore(collectScore); |
| | | scoreDetails.setChangeScore(returnScore); |
| | | scoreDetails.setCreatedTime(new Date()); |
| | | scoreDetails.setType(ScoreDetails.SCORE_TYPE_INVITE_FIRST_ORDER); |
| | | scoreDetails.setUserId(accountInfo.getUserId()); |
| | | scoreDetails.setOrderNo(orderId.toString()); |
| | | scoreDetailsMapper.insert(scoreDetails); |
| | | } |
| | | |
| | | SysMessage sysMessage = new SysMessage(); |
| | | sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")); |
| | | sysMessage.setCreateUserId(accountInfo.getUserId()); |
| | | sysMessage.setUserId(accountInfo.getUserId()); |
| | | sysMessage.setMessageType("4"); |
| | | sysMessage.setMessageSubTypeName("返利消息"); |
| | | sysMessage.setMessage("收到用户:" + userInfo.getMobilePhone().replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2") + "的订单返利, 积分:" + returnScore); |
| | | sysMessage.setFlag("2"); |
| | | sysMessageMapper.insert(sysMessage); |
| | | |
| | | } |
| | | |
| | | private String getRuleValue(RedPaperRule redPaperRule, String key) { |
| | | List<String> rules = StrUtil.split(redPaperRule.getSharingProfitType(), ','); |
| | | List<String> values = StrUtil.split(redPaperRule.getShareRatio(), ','); |