Helius
2021-08-04 04b04d8e0746f6bf6f83450caec52bc7f9ce8db9
add invite reutrn score'
13 files modified
282 ■■■■ changed files
gc-core/src/main/java/com/xzx/gc/common/constant/CommonEnum.java 4 ●●● patch | view | raw | blame | history
gc-core/src/main/java/com/xzx/gc/entity/ScoreDetails.java 1 ●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/mapper/AccountMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/mapper/OrderMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/mapper/RedPaperRuleMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/mapper/UserShareInfoMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/service/DistribService.java 96 ●●●●● patch | view | raw | blame | history
gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java 152 ●●●●● patch | view | raw | blame | history
gc-order/src/main/resources/mapper/order/AccountMapper.xml 5 ●●●●● patch | view | raw | blame | history
gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml 5 ●●●●● patch | view | raw | blame | history
gc-order/src/main/resources/mapper/order/OrderMapper.xml 5 ●●●● patch | view | raw | blame | history
gc-order/src/main/resources/mapper/order/RedPaperRuleMapper.xml 4 ●●●● patch | view | raw | blame | history
gc-core/src/main/java/com/xzx/gc/common/constant/CommonEnum.java
@@ -98,7 +98,9 @@
    首单后返利数量("order_num_first"),
    返利固定积分("regular_point"),
    返利环保币比例("regular_money_percent"),
    完成数量后返积分("point_reward")
    完成数量后返积分("point_reward"),
    推荐首单奖励("first_score")
    ;//枚举结束
    private String value;
gc-core/src/main/java/com/xzx/gc/entity/ScoreDetails.java
@@ -25,6 +25,7 @@
    public static final Integer SCORE_TYPE_SHOPPING_RETURN = 5;
    public static final Integer SCORE_TYPE_ADMIN_RECHARGE = 6;
    public static final Integer SCORE_TYPE_OTHER = 7;
    public static final Integer SCORE_TYPE_INVITE_FIRST_ORDER = 8;
    //原始积分
    private BigDecimal originalScore;
gc-order/src/main/java/com/xzx/gc/order/mapper/AccountMapper.java
@@ -36,4 +36,6 @@
    void updateUserAccount(@Param("accountId") String accountId, @Param("money") String money, @Param("overdraftLimit") String overdraftLimit);
    AccountInfo selectAccountInfoByUserId(@Param("userId") String userId);
    AccountInfo selectAccountInfoByPhone(@Param("phone") String phone);
}
gc-order/src/main/java/com/xzx/gc/order/mapper/JhyOrderMapper.java
@@ -19,4 +19,6 @@
    List<JhyStatusCountVo> selectOrderStatusCount(@Param("type") Integer type, @Param("userId") String userId);
    List<JhyOrder> selectJhyOrderListByStatus(@Param("list") List<String> list, @Param("userId") String userId);
    List<JhyOrder> selectJhyOrderNoWaitAndCancel(@Param("userId") String userId);
}
gc-order/src/main/java/com/xzx/gc/order/mapper/OrderMapper.java
@@ -221,5 +221,7 @@
    List<OrderInfo> findListOrderReceiveTime(@Param("receiver")String receiver);
    List<OrderInfo> selectOrderNoWaitAndCancel(@Param("userId") String userId);
}
gc-order/src/main/java/com/xzx/gc/order/mapper/RedPaperRuleMapper.java
@@ -59,4 +59,6 @@
    List<XzxUserRedpaperRuleModel> queryRoyalty(@Param("partnerIds")List<String> partnerIds, @Param("partnerId")String partnerId);
    RedPaperRule selectDistribRule();
    List<RedPaperRule> selectRuleByType(@Param("type") Integer type);
}
gc-order/src/main/java/com/xzx/gc/order/mapper/UserShareInfoMapper.java
@@ -26,6 +26,8 @@
    List<Map<String, Object>> queryPackageGoods(@Param("packageId") String packageId, @Param("partnerId") String partnerId);
    UserShareInfo selectUserShareInfoByInvited(@Param("phone") String phone);
}
gc-order/src/main/java/com/xzx/gc/order/service/DistribService.java
@@ -44,7 +44,17 @@
    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) {
@@ -160,6 +170,92 @@
        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_OTHER);
            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(), ',');
gc-order/src/main/java/com/xzx/gc/order/service/JhyOrderService.java
@@ -7,9 +7,11 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.constant.RedisKeyConstant;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.utils.IdUtils;
import com.xzx.gc.common.utils.LocationUtils;
import com.xzx.gc.common.utils.RedisUtil;
import com.xzx.gc.entity.*;
import com.xzx.gc.order.dto.AddJhyOrderDto;
import com.xzx.gc.order.dto.JhyOrderConfirmDto;
@@ -59,6 +61,9 @@
    @Autowired
    private DistribService distribService;
    @Autowired
    private RedisUtil redisUtil;
    public void addJhyOrder(AddJhyOrderDto orderDto) {
        JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(orderDto.getUserId());
@@ -200,74 +205,89 @@
    }
    public void confirmOrder(JhyOrderConfirmDto confirmDto) {
        JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(confirmDto.getUserId());
        if (jhyInfo == null || !JhyInfo.CHECK_PASS.equals(jhyInfo.getStatus())) {
            throw new RestException(-3, "不是集物员");
        String key = RedisKeyConstant.ORDER_PAY + confirmDto.getOrderId();
        if (redisUtil.setnx(key, "0")) {
            try {
                JhyInfo jhyInfo = jhyInfoMapper.selectJhyInfoByUserId(confirmDto.getUserId());
                if (jhyInfo == null || !JhyInfo.CHECK_PASS.equals(jhyInfo.getStatus())) {
                    throw new RestException(-3, "不是集物员");
                }
                jhyOrderItemsMapper.deleteItemsByOrderId(confirmDto.getOrderId());
                BigDecimal totalScore = BigDecimal.ZERO;
                for (JhyOrderConfirmItemsDto item : confirmDto.getItems()) {
                    BigDecimal weight = StrUtil.isNotBlank(item.getWeight()) ? new BigDecimal(item.getWeight()) : BigDecimal.ZERO;
                    SysEnvironmentalInfo environmentalInfo = environmentalInfoMapper.selectByPrimaryKey(item.getId());
                    JhyOrderItems orderItems = new JhyOrderItems();
                    orderItems.setOrderId(confirmDto.getOrderId());
                    orderItems.setPicture(environmentalInfo.getPicture());
                    orderItems.setItemType(item.getId());
                    orderItems.setTitle(environmentalInfo.getTitle());
                    orderItems.setPrice(new BigDecimal(environmentalInfo.getPrice()));
                    BigDecimal total = orderItems.getPrice().multiply(BigDecimal.valueOf(40)).multiply(weight);
                    orderItems.setScore(total.setScale(0, BigDecimal.ROUND_DOWN).toString());
                    orderItems.setWeight(weight);
                    jhyOrderItemsMapper.insert(orderItems);
                    totalScore = totalScore.add(total);
                }
                JhyOrder order = jhyOrderMapper.selectByPrimaryKey(confirmDto.getOrderId());
                AccountInfo jhyAccount = accountMapper.selectAccountInfoByUserId(order.getJhyId());
                BigDecimal collectScore = StrUtil.isNotBlank(jhyAccount.getCollectScore()) ? new BigDecimal(jhyAccount.getCollectScore()) : BigDecimal.ZERO;
                if (totalScore.compareTo(collectScore) > 0) {
                    throw new RestException(-3, "剩余积分不足");
                }
                order.setStatus(JhyOrder.ORDER_STATUS_CONFIRM);
                order.setReceivingTime(new Date());
                jhyOrderMapper.updateByPrimaryKey(order);
                BigDecimal jhyScore = StrUtil.isBlank(jhyAccount.getCollectScore()) ? BigDecimal.ZERO : new BigDecimal(jhyAccount.getCollectScore());
                ScoreDetails jhyScoreDetail = new ScoreDetails();
                jhyScoreDetail.setOrderNo(order.getOrderNo());
                jhyScoreDetail.setUserId(order.getJhyId());
                jhyScoreDetail.setType(ScoreDetails.SCORE_TYPE_PAY);
                jhyScoreDetail.setChangeScore(totalScore.negate().setScale( 0, BigDecimal.ROUND_DOWN ));
                jhyScoreDetail.setOriginalScore(jhyScore.setScale( 0, BigDecimal.ROUND_DOWN ));
                jhyScoreDetail.setCurrentScore(jhyScore.subtract(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ));
                jhyScoreDetail.setCreatedTime(new Date());
                scoreDetailsMapper.insert(jhyScoreDetail);
                jhyAccount.setCollectScore(jhyScore.subtract(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ).toString());
                accountMapper.updateByPrimaryKey(jhyAccount);
                AccountInfo userAccount = accountMapper.selectAccountInfoByUserId(order.getUserId());
                BigDecimal userScore = StrUtil.isBlank(userAccount.getCollectScore()) ? BigDecimal.ZERO : new BigDecimal(userAccount.getCollectScore());
                ScoreDetails userScoreDetail = new ScoreDetails();
                userScoreDetail.setOrderNo(order.getOrderNo());
        //        userScoreDetail.setUserId(order.getJhyId());
                userScoreDetail.setUserId(order.getUserId());
                userScoreDetail.setType(ScoreDetails.SCORE_TYPE_EXCHANGE);
                userScoreDetail.setChangeScore(totalScore.setScale( 0, BigDecimal.ROUND_DOWN ));
                userScoreDetail.setOriginalScore(userScore.setScale( 0, BigDecimal.ROUND_DOWN ));
                userScoreDetail.setCurrentScore(userScore.add(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ));
                userScoreDetail.setCreatedTime(new Date());
                scoreDetailsMapper.insert(userScoreDetail);
                userAccount.setCollectScore(userScore.add(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ).toString());
                accountMapper.updateByPrimaryKey(userAccount);
                // 团长返利
                distribService.distribRecord(order.getId(), order.getUserId());
                // 推荐返利
                distribService.inviteAddOrderScore(order.getUserId(), order.getId().toString());
            } catch (Exception e) {
                throw new RestException("支付失败");
            } finally {
                redisUtil.del(key);
            }
        } else {
            throw new RestException("支付中");
        }
        jhyOrderItemsMapper.deleteItemsByOrderId(confirmDto.getOrderId());
        BigDecimal totalScore = BigDecimal.ZERO;
        for (JhyOrderConfirmItemsDto item : confirmDto.getItems()) {
            BigDecimal weight = StrUtil.isNotBlank(item.getWeight()) ? new BigDecimal(item.getWeight()) : BigDecimal.ZERO;
            SysEnvironmentalInfo environmentalInfo = environmentalInfoMapper.selectByPrimaryKey(item.getId());
            JhyOrderItems orderItems = new JhyOrderItems();
            orderItems.setOrderId(confirmDto.getOrderId());
            orderItems.setPicture(environmentalInfo.getPicture());
            orderItems.setItemType(item.getId());
            orderItems.setTitle(environmentalInfo.getTitle());
            orderItems.setPrice(new BigDecimal(environmentalInfo.getPrice()));
            BigDecimal total = orderItems.getPrice().multiply(BigDecimal.valueOf(40)).multiply(weight);
            orderItems.setScore(total.setScale(0, BigDecimal.ROUND_DOWN).toString());
            orderItems.setWeight(weight);
            jhyOrderItemsMapper.insert(orderItems);
            totalScore = totalScore.add(total);
        }
        JhyOrder order = jhyOrderMapper.selectByPrimaryKey(confirmDto.getOrderId());
        AccountInfo jhyAccount = accountMapper.selectAccountInfoByUserId(order.getJhyId());
        BigDecimal collectScore = StrUtil.isNotBlank(jhyAccount.getCollectScore()) ? new BigDecimal(jhyAccount.getCollectScore()) : BigDecimal.ZERO;
        if (totalScore.compareTo(collectScore) > 0) {
            throw new RestException(-3, "剩余积分不足");
        }
        order.setStatus(JhyOrder.ORDER_STATUS_CONFIRM);
        order.setReceivingTime(new Date());
        jhyOrderMapper.updateByPrimaryKey(order);
        BigDecimal jhyScore = StrUtil.isBlank(jhyAccount.getCollectScore()) ? BigDecimal.ZERO : new BigDecimal(jhyAccount.getCollectScore());
        ScoreDetails jhyScoreDetail = new ScoreDetails();
        jhyScoreDetail.setOrderNo(order.getOrderNo());
        jhyScoreDetail.setUserId(order.getJhyId());
        jhyScoreDetail.setType(ScoreDetails.SCORE_TYPE_PAY);
        jhyScoreDetail.setChangeScore(totalScore.negate().setScale( 0, BigDecimal.ROUND_DOWN ));
        jhyScoreDetail.setOriginalScore(jhyScore.setScale( 0, BigDecimal.ROUND_DOWN ));
        jhyScoreDetail.setCurrentScore(jhyScore.subtract(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ));
        jhyScoreDetail.setCreatedTime(new Date());
        scoreDetailsMapper.insert(jhyScoreDetail);
        jhyAccount.setCollectScore(jhyScore.subtract(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ).toString());
        accountMapper.updateByPrimaryKey(jhyAccount);
        AccountInfo userAccount = accountMapper.selectAccountInfoByUserId(order.getUserId());
        BigDecimal userScore = StrUtil.isBlank(userAccount.getCollectScore()) ? BigDecimal.ZERO : new BigDecimal(userAccount.getCollectScore());
        ScoreDetails userScoreDetail = new ScoreDetails();
        userScoreDetail.setOrderNo(order.getOrderNo());
//        userScoreDetail.setUserId(order.getJhyId());
        userScoreDetail.setUserId(order.getUserId());
        userScoreDetail.setType(ScoreDetails.SCORE_TYPE_EXCHANGE);
        userScoreDetail.setChangeScore(totalScore.setScale( 0, BigDecimal.ROUND_DOWN ));
        userScoreDetail.setOriginalScore(userScore.setScale( 0, BigDecimal.ROUND_DOWN ));
        userScoreDetail.setCurrentScore(userScore.add(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ));
        userScoreDetail.setCreatedTime(new Date());
        scoreDetailsMapper.insert(userScoreDetail);
        userAccount.setCollectScore(userScore.add(totalScore).setScale( 0, BigDecimal.ROUND_DOWN ).toString());
        accountMapper.updateByPrimaryKey(userAccount);
        distribService.distribRecord(order.getId(), order.getUserId());
    }
    public Map<Integer, Integer> orderStatusCount(Integer type, String userId) {
gc-order/src/main/resources/mapper/order/AccountMapper.xml
@@ -92,4 +92,9 @@
    <select id="selectAccountInfoByUserId" resultType="com.xzx.gc.entity.AccountInfo">
        select * from xzx_account_info where user_id=#{userId}
    </select>
    <select id="selectAccountInfoByPhone" resultType="com.xzx.gc.entity.AccountInfo">
        select a.* from xzx_account_info a, xzx_user_info b
        where a.user_id=b.user_id and b.mobile_phone=#{phone}
    </select>
</mapper>
gc-order/src/main/resources/mapper/order/JhyOrderMapper.xml
@@ -79,4 +79,9 @@
            #{id}
        </foreach>
    </select>
    <select id="selectJhyOrderNoWaitAndCancel" resultType="com.xzx.gc.entity.JhyOrder">
        select * from xzx_jhy_order
        where status not in (1, 5)
    </select>
</mapper>
gc-order/src/main/resources/mapper/order/OrderMapper.xml
@@ -1523,5 +1523,8 @@
            b.receive_time ASC
    </select>
    <select id="selectOrderNoWaitAndCancel" resultType="com.xzx.gc.entity.OrderInfo">
        select * from xzx_order_info
        where order_status not in ('1', '6') and create_user_id=#{userId}
    </select>
</mapper>
gc-order/src/main/resources/mapper/order/RedPaperRuleMapper.xml
@@ -321,4 +321,8 @@
    <select id="selectDistribRule" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from xzx_user_redpaper_rule where rule_type=9
    </select>
    <select id="selectRuleByType" resultType="com.xzx.gc.entity.RedPaperRule">
        select * xzx_user_redpaper_rule where rule_type=#{type}
    </select>
</mapper>