chenjiahe
2024-03-01 f87850bb6c6109a3bda06ab474575631407bbf09
爆款活动-退款处理
3个文件已修改
145 ■■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java
@@ -2,11 +2,13 @@
import com.hx.common.service.CommonService;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.OrderTotalConstants;
import com.hx.phiappt.model.consume.ConsumePayItem;
import com.hx.phiappt.model.order.OrdersTotal;
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
import com.hx.phip.dao.mapper.ConsumePayItemMapper;
import com.hx.phip.dao.mapper.UserMoneyUnclaimedMapper;
import com.hx.util.StringUtils;
import java.util.HashMap;
import java.util.List;
@@ -44,17 +46,55 @@
    }
    /**获取用户活动赠送资金奖励记录-有效*/
    public static List<UserMoneyUnclaimed> getActivityGive(String userId,String commonId, CommonService commonService){
    public static List<UserMoneyUnclaimed> getActivityGive(String userId,String commonId,Integer isValid, CommonService commonService){
        //查找领取记录释放存在
        //领取记录是否已领取
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        StringBuilder sql = new StringBuilder();
        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);
        sql.append("SELECT * FROM user_money_unclaimed WHERE isDel = 0");
        if(isValid != null){
            values.put("isValid",isValid);
            sql.append(" AND isValid = #{m.isValid}");
        }
        if(StringUtils.noNull(userId)){
            values.put("userId",userId);
            sql.append(" AND userId = #{m.userId}");
        }
        if(StringUtils.noNull(commonId)){
            values.put("commonId",commonId);
            sql.append(" AND commonId = #{m.commonId}");
        }
        sqlSentence.sqlSentence(sql.toString(),values);
        return commonService.selectList(UserMoneyUnclaimedMapper.class,sqlSentence);
    }
    /**获取用户活动赠送资金奖励记录-获取一条*/
    public static UserMoneyUnclaimed getActivityGiveByOrder(OrdersTotal ordersTotal,Integer isValid, CommonService commonService){
        //根据当前用户,获取到所有的记录
        //领取记录是否已领取
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        StringBuilder sql = new StringBuilder();
        values.put("commonId",ordersTotal.getActivityPageCode());
        values.put("userId",ordersTotal.getUserId());
        values.put("payStatus", OrderTotalConstants.PAY_STATUS_SUC);
        values.put("activityPageType", ordersTotal.getActivityPageType());
        values.put("activityPageCode", ordersTotal.getActivityPageCode());
        sql.append("SELECT umu.* FROM orders_total ot ");
        sql.append(" JOIN user_money_unclaimed umu ON umu.orderId = ot.id AND umu.isDel = 0 AND umu.commonId = #{m.commonId}");
        if(isValid != null){
            values.put("isValid",isValid);
            sql.append(" AND umu.isValid = #{m.isValid}");
        }
        sql.append(" WHERE ot.isDel = 0 AND ot.activityPageType = #{m.activityPageType} AND ot.activityPageCode = #{m.activityPageCode}" +
                " AND ot.userId = #{m.userId} AND ot.payStatus = #{m.payStatus} ORDER BY umu.createTime ASC LIMIT 1");
        sqlSentence.sqlSentence(sql.toString(),values);
        return commonService.selectOne(UserMoneyUnclaimedMapper.class,sqlSentence);
    }
}
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("活动赠送资产退款记录状态已变化[作废]!");
                }
            }
        }
    }
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
@@ -189,7 +189,7 @@
        }
        //爆款活动规则退款,暂时不屏蔽保存提示
        activityPageGiveIncrease(ordersTotal,refundRecord,operationId,0,commonService);
        activityPageGiveIncrease(ordersTotal,refundRecord,0,commonService);
        //初始化初复诊信息
        if(OrderTotalConstants.STATUS_CANCEL == ordersTotal.getStatus()){
@@ -902,11 +902,10 @@
    /**页面活动赠送的增值金退款处理
     * @param ordersTotal 订单
     * @param refundRecord 退款订单
     * @param operationId 操作人标识
     * @param circulateNum 避免死循环,调用的时候传0
     * @param commonService 映射
     */
    public static void activityPageGiveIncrease(OrdersTotal ordersTotal,RefundRecord refundRecord,String operationId,int circulateNum,CommonService commonService){
    public static void activityPageGiveIncrease(OrdersTotal ordersTotal,RefundRecord refundRecord,int circulateNum,CommonService commonService){
        if(circulateNum > 1){
            return;
@@ -932,8 +931,8 @@
        RefundUserAssets refundUserAssets;
        //生成记录
        refundUserAssets = new RefundUserAssets();
        //设置未102是当前的记录类型
        refundUserAssets.setIsDel(102);
        //设置为102是当前的记录类型
        refundUserAssets.setIsDel(RefundUserAssets.DEL_BURST);
        refundUserAssets.setType(userMoneyUnclaimed.getOperationReason());
        refundUserAssets.setStatus(RefundUserAssets.STATUS_NORMAL);
        refundUserAssets.setAmountType(userMoneyUnclaimed.getFundType());
@@ -966,7 +965,7 @@
            sqlSentence.sqlWhere("isValid = #{m.isValid} WHERE id = #{m.id} AND status = #{m.status}",values);
            if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
                circulateNum++;
                activityPageGiveIncrease(ordersTotal,refundRecord,operationId,circulateNum,commonService);
                activityPageGiveIncrease(ordersTotal,refundRecord,circulateNum,commonService);
            }
        }
        //保存记录,正常扣减和未领取才去保存这个记录
@@ -980,12 +979,12 @@
        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);
                " AND id != #{m.id} AND activityPageType = #{m.activityPageType} AND activityPageCode = #{m.activityPageCode} ORDER BY payTime ASC LIMIT 1",values);
        OrdersTotal ordersTotal1 = commonService.selectOne(OrdersTotalMapper.class,sqlSentence);
        if(ordersTotal1 != null){
            Integer opType = BaseEntity.NO;
            Integer opType = BaseEntity.YES;
            if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
                opType = BaseEntity.YES;
                opType = BaseEntity.NO;
            }
            //增值金到账处理
            UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()