chenjiahe
2024-03-01 f87850bb6c6109a3bda06ab474575631407bbf09
phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java
@@ -446,44 +446,62 @@
        //查找是否处理了赠送的增值金
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        values.put("isDel",102);
        values.put("isDel",RefundUserAssets.DEL_BURST);
        values.put("orderId",refundRecord.getOrderId());
        sqlSentence.sqlSentence("SELECT * FROM refund_user_assets rua WHERE rua.isDel = #{m.isDel} AND rua.status = 1 AND rua.amountStatus IN(1,3) AND rua.orderId = #{m.orderId}",values);
        List<RefundUserAssets> refundUserAssetsList = commonService.selectList(RefundUserAssetsMapper.class,sqlSentence);
        if(refundUserAssetsList.size() == 0){
            return;
        }
        for(RefundUserAssets refundUserAssets:refundUserAssetsList){
            //判断是否已经存在了别的赠送记录
            if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),commonService).size() == 0){
                //是否有扣减用户资产
                if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){
                    orderNodeBuilder.append(",活动赠送增加成功");
                    UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"退款作废:活动赠送资金回退作废",refundUserAssets.getOperatorId()
                            ,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType()
                            ,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES);
                }else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){
                    //用户未领取记录,还原
                    orderNodeBuilder.append(",活动赠送用户未领取,作废的领取记录还原");
                    values.clear();
                    values.put("id",refundUserAssets.getUserMoneyUnclaimedId());
                    values.put("status",UserMoneyUnclaimed.STATUS_WAI);
                    sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values);
                    if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
                        throw new TipsException("活动赠送资产记录状态已变化[作废]!");
            //---无操作记录
            //获取有效的,如果有,那么就不做处理
            UserMoneyUnclaimed userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.YES,commonService);
            if(userMoneyUnclaimed != null){
                return;
            }
            //获取无效的,如果有,那么就要处理规则,没有就跳过
            userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.NO,commonService);
            if(userMoneyUnclaimed == null){
                return;
            }
            Integer opType = BaseEntity.YES;
            if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
                opType = BaseEntity.NO;
            }
            //增值金到账处理
            userMoneyUnclaimed = UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()
                    ,ordersTotal.getId(),ordersTotal.getActivityPageCode(),userMoneyUnclaimed.getMoneyRuleId(),commonService);
        }else{
            //有操作记录
            for(RefundUserAssets refundUserAssets:refundUserAssetsList){
                //判断是否已经存在了别的赠送记录
                if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),BaseEntity.YES,commonService).size() == 0){
                    //是否有扣减用户资产
                    if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){
                        orderNodeBuilder.append(",活动赠送增加成功");
                        UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"退款作废:活动赠送资金回退作废",refundUserAssets.getOperatorId()
                                ,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType()
                                ,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES);
                    }else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){
                        //用户未领取记录,还原
                        orderNodeBuilder.append(",活动赠送用户未领取,作废的领取记录还原");
                        values.clear();
                        values.put("id",refundUserAssets.getUserMoneyUnclaimedId());
                        values.put("status",UserMoneyUnclaimed.STATUS_WAI);
                        sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values);
                        if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
                            throw new TipsException("活动赠送资产记录状态已变化[作废]!");
                        }
                    }
                }
            }
            //记录作废
            values.clear();
            values.put("id",refundUserAssets.getId());
            values.put("status",RefundUserAssets.STATUS_CANCEL);
            values.put("oldStatus",RefundUserAssets.STATUS_NORMAL);
            sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
            if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){
                throw new TipsException("活动赠送资产退款记录状态已变化[作废]!");
                //记录作废
                values.clear();
                values.put("id",refundUserAssets.getId());
                values.put("status",RefundUserAssets.STATUS_CANCEL);
                values.put("oldStatus",RefundUserAssets.STATUS_NORMAL);
                sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
                if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){
                    throw new TipsException("活动赠送资产退款记录状态已变化[作废]!");
                }
            }
        }
    }