chenjiahe
2024-03-01 cfedbfad423aa6fd758da748967122819b1787e2
爆款活动-退款处理
3个文件已修改
114 ■■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java
@@ -43,5 +43,18 @@
        return commonService.selectOne(UserMoneyUnclaimedMapper.class,sqlSentence);
    }
    /**获取用户活动赠送资金奖励记录-有效*/
    public static List<UserMoneyUnclaimed> getActivityGive(String userId,String commonId, CommonService commonService){
        //查找领取记录释放存在
        //领取记录是否已领取
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        values.put("userId",userId);
        values.put("commonId",commonId);
        sqlSentence.sqlSentence("SELECT * FROM user_money_unclaimed WHERE isDel = 0 AND isValid = 1 AND userId = #{m.userId} AND commonId = #{m.commonId}",values);
        return commonService.selectList(UserMoneyUnclaimedMapper.class,sqlSentence);
    }
}
phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java
@@ -22,6 +22,7 @@
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
import com.hx.phip.dao.mapper.*;
import com.hx.phip.service.order.impl.OrderRefundServiceImpl;
import com.hx.phip.tool.order.OrderTool;
import com.hx.phip.tool.user.UserCardTool;
import com.hx.phip.tool.user.UserProjectTool;
import com.hx.phip.util.api.UserMoneyUtil;
@@ -435,6 +436,58 @@
        }
    }
    /**作废退款-爆款活动赠送处理*/
    public static void burstActivityHandle(StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){
        //不是爆款活动
        if(ordersTotal.getActivityPageType() != OrderTotalConstants.ACTIVITY_TYPE_BURST){
            return;
        }
        //查找是否处理了赠送的增值金
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        values.put("isDel",102);
        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("活动赠送资产记录状态已变化[作废]!");
                    }
                }
            }
            //记录作废
            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("活动赠送资产退款记录状态已变化[作废]!");
            }
        }
    }
    /**退款子项处理*/
    public static void refundRecordItemHandle(OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
@@ -915,7 +915,7 @@
            return;
        }
        //订单取消状态才处理
        if(ordersTotal.getStatus() != OrderTotalConstants.STATUS_CANCEL){
        if(ordersTotal.getRefundStatus() != OrderTotalConstants.STATUS_REFUND_FINSH){
            return;
        }
@@ -925,20 +925,40 @@
        if(userMoneyUnclaimed == null){
            return;
        }
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        //-----生成一条记录,可以回溯
        RefundUserAssets refundUserAssets;
        //生成记录
        refundUserAssets = new RefundUserAssets();
        //设置未102是当前的记录类型
        refundUserAssets.setIsDel(102);
        refundUserAssets.setType(userMoneyUnclaimed.getOperationReason());
        refundUserAssets.setStatus(RefundUserAssets.STATUS_NORMAL);
        refundUserAssets.setAmountType(userMoneyUnclaimed.getFundType());
        refundUserAssets.setAmount(userMoneyUnclaimed.getOpNumber().negate());
        refundUserAssets.setOperatorId(refundRecord.getOperatorId());
        refundUserAssets.setOperatorNo(refundRecord.getOperatorNo());
        refundUserAssets.setOperatorName(refundRecord.getOperatorName());
        refundUserAssets.setOrderId(refundRecord.getOrderId());
        refundUserAssets.setRefundRecordId(refundRecord.getId());
        refundUserAssets.setUserMoneyUnclaimedId(userMoneyUnclaimed.getId());
        refundUserAssets.setUserId(userMoneyUnclaimed.getUserId());
        if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
            //已领取,那么就扣回来
            if(userMoneyUnclaimed.getOpNumber().compareTo(BigDecimal.ZERO) < 1){
                return;
            }
            refundUserAssets.setAmountStatus(RefundUserAssets.AMOUNT_STATUS_NORMAL);
            UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(),UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber().negate(),BaseEntity.NO,OperationReasonConstants.OP_REASON_INVITE_ORDER_CANCEL,"好友订单退款-活动赠送扣除["+ordersTotal.getOrderNo()+"]","操作原因:退款审核通过,活动赠送扣除资金,退款方式:退回增值金",ordersTotal.getOperatorId()
                    ,ordersTotal.getId(),ordersTotal.getActivityPageCode(),null,commonService);
        }else{
            if(!UserMoneyUnclaimed.YES.equals(userMoneyUnclaimed.getIsValid())){
               return;
            }
            SqlSentence sqlSentence = new SqlSentence();
            Map<String,Object> values = new HashMap<>();
            refundUserAssets.setAmountStatus(RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE);
            //没有领取就作废
            values.put("id",userMoneyUnclaimed.getId());
            values.put("isValid",UserMoneyUnclaimed.NO);
@@ -949,6 +969,28 @@
                activityPageGiveIncrease(ordersTotal,refundRecord,operationId,circulateNum,commonService);
            }
        }
        //保存记录,正常扣减和未领取才去保存这个记录
        commonService.insert(RefundUserAssetsMapper.class,refundUserAssets);
        //查看是否有第二张订单符合
        values.clear();
        values.put("status",OrderTotalConstants.STATUS_CANCEL);
        values.put("payStatus",OrderTotalConstants.PAY_STATUS_SUC);
        values.put("id",ordersTotal.getId());
        values.put("activityPageType",ordersTotal.getActivityPageType());
        values.put("activityPageCode",ordersTotal.getActivityPageCode());
        sqlSentence.sqlSentence("SELECT * FROM orders_total WHERE isDel = 0 AND status != #{m.status} AND payStatus = #{m.payStatus}" +
                " AND id != #{m.id} AND activityPageType = #{m.activityPageType} AND activityPageCode = #{m.activityPageCode} ORDER BY createTime ASC LIMIT 1",values);
        OrdersTotal ordersTotal1 = commonService.selectOne(OrdersTotalMapper.class,sqlSentence);
        if(ordersTotal1 != null){
            Integer opType = BaseEntity.NO;
            if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
                opType = BaseEntity.YES;
            }
            //增值金到账处理
            UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()
                    ,ordersTotal1.getId(),ordersTotal.getActivityPageCode(),userMoneyUnclaimed.getMoneyRuleId(),commonService);
        }
    }