chenjiahe
2023-08-14 f3ff4ed544dab12f9471a738e106379a466bb5e2
退款兼容
4个文件已修改
150 ■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/tool/payment/ConsumeTool.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/resources/mapper/platform/RefundCashMapper.xml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java 122 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/payment/ConsumeTool.java
@@ -2,10 +2,10 @@
import com.hx.common.service.CommonService;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.dao.mapper.ConsumeNotifyMapper;
import com.hx.phiappt.model.PaymentMethod;
import com.hx.phiappt.model.consume.ConsumeNotify;
import com.hx.phiappt.model.consume.ConsumePay;
import com.hx.phip.dao.mapper.ConsumeNotifyMapper;
import com.hx.phip.dao.mapper.PaymentMethodMapper;
import com.hx.util.StringUtils;
@@ -162,8 +162,11 @@
        StringBuilder stringBuilder = new StringBuilder();
        values.put("orderId",orderId);
        stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND orderId = #{m.orderId}");
        if(StringUtils.noNull(paymentNo)){
        values.put("paymentNo",paymentNo);
        stringBuilder.append("SELECT * FROM consume_notify WHERE isDel = 0 AND paymentNo = #{m.paymentNo} AND orderId = #{m.orderId}");
            stringBuilder.append(" AND paymentNo = #{m.paymentNo}");
        }
        if(payAmount != null){
            values.put("payAmount",payAmount);
            stringBuilder.append(" AND payAmount = #{m.payAmount}");
@@ -182,7 +185,7 @@
        values.put("id",consumeNotify.getId());
        values.put("refundStatus",refundStatus);
        sqlSentence.sqlUpdate("refundTotal = refundTotal+#{m.refundTotal},refundStatus = #{m.refundStatus} WHERE id = #{m.id}",values);
        commonService.updateWhere(ConsumeNotify.class,sqlSentence);
        commonService.updateWhere(ConsumeNotifyMapper.class,sqlSentence);
    }
phi_platform_common/src/main/resources/mapper/platform/RefundCashMapper.xml
@@ -8,7 +8,7 @@
    <!-- 整个实体类修改,表字段=实体类字段-->
    <sql id="Update_Column_All">
        <trim prefixOverrides=",">
            ,platTrxNo = #{platTrxNo},refunNo = #{refunNo},refundTotal = #{refundTotal},refundRecordId = #{refundRecordId},refundRecordMethodId = #{refundRecordMethodId},orderId = #{orderId},userId = #{userId},consumeNotifyId = #{consumeNotifyId},isDel = #{isDel},createTime = #{createTime},editTime = #{editTime}
            ,outOrderNo = #{outOrderNo},platTrxNo = #{platTrxNo},refunNo = #{refunNo},refundTotal = #{refundTotal},refundRecordId = #{refundRecordId},orderId = #{orderId},consumeNotifyId = #{consumeNotifyId},isDel = #{isDel},createTime = #{createTime},editTime = #{editTime}
        </trim>
    </sql>
     
@@ -19,11 +19,11 @@
        <selectKey keyProperty="id" resultType="String" order="BEFORE">
               select replace(uuid(),'-','') from dual
        </selectKey>
        insert into refund_cash (id,platTrxNo,refunNo,refundTotal,refundRecordId,refundRecordMethodId,orderId,userId,consumeNotifyId,isDel,createTime,editTime)  values (#{id},#{platTrxNo},#{refunNo},#{refundTotal},#{refundRecordId},#{refundRecordMethodId},#{orderId},#{userId},#{consumeNotifyId},#{isDel},#{createTime},#{editTime})
        insert into refund_cash (id,outOrderNo,platTrxNo,refunNo,refundTotal,refundRecordId,orderId,consumeNotifyId,isDel,createTime,editTime)  values (#{id},#{outOrderNo},#{platTrxNo},#{refunNo},#{refundTotal},#{refundRecordId},#{orderId},#{consumeNotifyId},#{isDel},#{createTime},#{editTime})
    </insert>
    <insert id="insertById" parameterType="com.hx.phiappt.model.refund.RefundCash">
        insert into refund_cash (id,platTrxNo,refunNo,refundTotal,refundRecordId,refundRecordMethodId,orderId,userId,consumeNotifyId,isDel,createTime,editTime)  values (#{id},#{platTrxNo},#{refunNo},#{refundTotal},#{refundRecordId},#{refundRecordMethodId},#{orderId},#{userId},#{consumeNotifyId},#{isDel},#{createTime},#{editTime})
        insert into refund_cash (id,outOrderNo,platTrxNo,refunNo,refundTotal,refundRecordId,orderId,consumeNotifyId,isDel,createTime,editTime)  values (#{id},#{outOrderNo},#{platTrxNo},#{refunNo},#{refundTotal},#{refundRecordId},#{orderId},#{consumeNotifyId},#{isDel},#{createTime},#{editTime})
    </insert>
    <select id="selectList" resultType="com.hx.phiappt.model.refund.RefundCash" parameterType="com.hx.mybatisTool.SqlSentence" >
@@ -55,14 +55,14 @@
    <select id="selectOneByKey" resultType="com.hx.phiappt.model.refund.RefundCash" parameterType="java.lang.Object" >
        select 
            id,platTrxNo,refunNo,refundTotal,refundRecordId,refundRecordMethodId,orderId,userId,consumeNotifyId,isDel,createTime,editTime
            id,outOrderNo,platTrxNo,refunNo,refundTotal,refundRecordId,orderId,consumeNotifyId,isDel,createTime,editTime
        from refund_cash
        WHERE id = #{value}
    </select>
    <select id="selectOneByKeyBlob" resultType="com.hx.phiappt.model.refund.RefundCash" parameterType="java.lang.Object" >
        select 
            id,platTrxNo,refunNo,refundTotal,refundRecordId,refundRecordMethodId,orderId,userId,consumeNotifyId,isDel,createTime,editTime
            id,outOrderNo,platTrxNo,refunNo,refundTotal,refundRecordId,orderId,consumeNotifyId,isDel,createTime,editTime
        from refund_cash
        WHERE id = #{value}
    </select>
phi_platform_user/src/main/java/com/hx/phip/service/order/impl/OrderRefundServiceImpl.java
@@ -1636,34 +1636,40 @@
        orderRefundNoteListDto.setOperationId(operationId);
        orderRefundNoteListDto.setOrderId(ordersTotal.getId());
        //获取退款信息
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> map=new HashMap<>();
        sqlSentence.setM(map);
        map.put("orderId",ordersTotal.getId());
        //获取总退款方式
        map.put("refundRecordId",refundRecord.getId());
        map.put("refundStatus",RefundNote.STATUS_SUCCESS);
        sqlSentence.sqlSentence("SELECT * FROM refund_note WHERE orderId=#{m.orderId} and refundRecordId=#{m.refundRecordId} and isDel=0 AND refundStatus != #{m.refundStatus}",map);
        List<RefundNote> refundNotes=refundNoteMapper.selectList(sqlSentence);
        if(refundNotes==null || refundNotes.size()==0){
        sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",map);
        List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence);
        if(refundRecordMethodList.size() == 0){
            return;
        }
        //组装数据,只有现金才生成
        List<OrderRefundNoteDto> orderRefundNoteDtos=new ArrayList<>();
        OrderRefundNoteDto orderRefundNoteDto;
        for (RefundNote refundNote : refundNotes) {
            if(StringUtils.isEmpty(refundNote.getRefundNumberNo())){
                throw new TipsException("退款方式接收失败[624]!");
        for (RefundRecordMethod refundRecordMethod : refundRecordMethodList) {
            //是现金
            if(refundRecordMethod.getIsMoneyPay().equals(BaseEntity.YES)){
                continue;
            }
            orderRefundNoteDto=new OrderRefundNoteDto();
            BeanUtils.copyProperties(refundNote,orderRefundNoteDto);
            //退款
            if(refundNote.getPaymentNumberNo().equals(refundNote.getRefundNumberNo())){
            //退款,是否原路退回
            if(refundRecordMethod.getNumberNo().equals(refundRecordMethod.getRefundNumberNo())){
                orderRefundNoteDto.setRefundroute(1);
            }else{
                orderRefundNoteDto.setRefundroute(0);
            }
            orderRefundNoteDto.setRefundNumberNo(refundNote.getRefundNumberNo());
            orderRefundNoteDto.setRefundName(refundNote.getRefundName());
            orderRefundNoteDto.setRefundRecordMethodId(refundRecordMethod.getId());
            orderRefundNoteDto.setPaymentTotal(refundRecordMethod.getActualTotal());
            orderRefundNoteDto.setPaymentNumberNo(refundRecordMethod.getNumberNo());
            orderRefundNoteDto.setPaymentName(refundRecordMethod.getName());
            orderRefundNoteDto.setRefundNumberNo(refundRecordMethod.getRefundNumberNo());
            orderRefundNoteDto.setRefundName(refundRecordMethod.getRefundName());
            orderRefundNoteDtos.add(orderRefundNoteDto);
        }
        orderRefundNoteListDto.setOrderRefundNoteDtos(orderRefundNoteDtos);
@@ -1671,7 +1677,7 @@
        noteConfirm(orderRefundNoteListDto, ordersTotal,refundRecord,orderNodeBuilder);
    }
    public PlatformResult noteConfirm(OrderRefundNoteListDto orderRefundNoteListDto,OrdersTotal ordersTotal,RefundRecord refundRecord
    public void noteConfirm(OrderRefundNoteListDto orderRefundNoteListDto,OrdersTotal ordersTotal,RefundRecord refundRecord
            ,StringBuilder orderNodeBuilder) {
        logger.info("退款单确认打印参数:{}",JSON.toJSONString(orderRefundNoteListDto));
        Map<String, String> operator = ApiOrderUtil.getOperator(commonService, orderRefundNoteListDto.getOperationId());//获取操作人信息
@@ -1683,29 +1689,32 @@
        Map<String,Object> map=new HashMap<>();
        sqlSentence.setM(map);
        List<OrderRefundNoteDto> orderRefundNoteDtos=orderRefundNoteListDto.getOrderRefundNoteDtos();
        if(orderRefundNoteDtos == null || orderRefundNoteDtos.size() == 0){
            return;
        }
        if("crm".equals(ordersTotal.getAppIdCode())){
            //CRM退款
            handleCrmRefundOrder(orderRefundNoteDtos,ordersTotal,refundRecord,operatorId,operatorName,orderNodeBuilder);
        }else {
            sqlSentence.sqlSentence(" refundroute=#{m.refundroute}, refundStoredTotal=#{m.refundStoredTotal},refundStatus=#{m.refundStatus},remarks=#{m.remarks},shopId=#{m.shopId}, " +
                    " shopName=#{m.shopName},operationName=#{m.operationName},operationId=#{m.operationId} where id=#{m.id} ",map);
            map.put("shopId",ordersTotal.getShopId());
            map.put("shopName",ordersTotal.getShopName());
            map.put("operationName",operatorName);
            map.put("operationId",operatorId);
            map.put("refundStatus",RefundNote.STATUS_SUCCESS);
            RefundCashVo refundCashVo = new RefundCashVo();
            refundCashVo.setOrderId(ordersTotal.getId());
            refundCashVo.setRemark(refundRecord.getRemarks());
            List<RefundCashItemVo> refundCashItemVoList = new ArrayList<>();
            RefundCashItemVo refundCashItemVo;
            for (OrderRefundNoteDto orderRefundNoteDto : orderRefundNoteDtos) {
                map.put("refundroute",orderRefundNoteDto.getRefundroute());
                map.put("refundStoredTotal",orderRefundNoteDto.getRefundStoredTotal());
                map.put("remarks",orderRefundNoteDto.getRemarks());
                map.put("id",orderRefundNoteDto.getId());
                refundNoteMapper.updateWhere(sqlSentence);
                if(BaseEntity.YES.equals(orderRefundNoteDto.getRefundroute())){
                    refundCashItemVo = new RefundCashItemVo();
                    refundCashItemVo.setPaymentNo(orderRefundNoteDto.getRefundNumberNo());
                    refundCashItemVo.setRefundTotal(orderRefundNoteDto.getPaymentTotal());
                    refundCashItemVo.setRefundRecordId(refundRecord.getId());
                    refundCashItemVo.setRefundRecordMethodId(orderRefundNoteDto.getRefundRecordMethodId());
                    refundCashItemVoList.add(refundCashItemVo);
            }
        }
            refundCashVo.setRefundCashItemVoList(refundCashItemVoList);
            refundCash(refundRecord.getId(),refundCashVo);
        }
        //记录操作日志
        StringBuffer stringBuffer=new StringBuffer("操作人:"+operator.get("operatorName")+",已支付订单现金支付退款:");
@@ -1713,7 +1722,6 @@
                ,operator.get("operatorName"),operator.get("operatorId"),OrderTotalConstants.STATUS_CANCEL);
        commonService.insert(OrderLogMapper.class,orderLog);
        return PlatformResult.success();
    }
    /**处理crm退款*/
    public void handleCrmRefundOrder(List<OrderRefundNoteDto> orderRefundNoteDtos,OrdersTotal ordersTotal,RefundRecord refundRecord
@@ -1779,34 +1787,8 @@
            }
        }
        logger.info("订单状态为:{}",ordersTotal.getRefundStatus());
        sqlSentence.sqlSentence(" refundroute=#{m.refundroute}, refundStoredTotal=#{m.refundStoredTotal},refundStatus=#{m.refundStatus},remarks=#{m.remarks},shopId=#{m.shopId}, " +
                " shopName=#{m.shopName},operationName=#{m.operationName},operationId=#{m.operationId} where id=#{m.id} ",map);
        map.put("shopId",ordersTotal.getShopId());
        map.put("shopName",ordersTotal.getShopName());
        map.put("operationName",operatorName);
        map.put("operationId",operatorId);
        map.put("refundStatus",RefundNote.STATUS_SUCCESS);
        for (OrderRefundNoteDto orderRefundNoteDto : orderRefundNoteDtos) {
            map.put("refundroute",orderRefundNoteDto.getRefundroute());
            map.put("refundStoredTotal",orderRefundNoteDto.getRefundStoredTotal());
            map.put("remarks",orderRefundNoteDto.getRemarks());
            map.put("id",orderRefundNoteDto.getId());
            refundNoteMapper.updateWhere(sqlSentence);
            if (!StringUtils.isEmpty(orderRefundNoteDto.getImageList())){
                String [] imageList= orderRefundNoteDto.getImageList().split(",");
                for (String s : imageList) {
                    RefundNoteItems refundNoteItems=new RefundNoteItems();
                    refundNoteItems.setRefundNoteId(orderRefundNoteDto.getId());
                    refundNoteItems.setImgUrl(s);
                    refundNoteItemsMapper.insert(refundNoteItems);
                }
            }
        }
        try{
        //退款成功发送企业微信给订单开单人
        JSONObject object = new JSONObject();
        object.put("abnormal","订单退款成功,现金支付资产已退回!");
@@ -1815,7 +1797,9 @@
        object.put("userName",user==null?"":user.getName());
        object.put("notificationSubject", NotificationLog.NOTIFICATION_SUBJECT_REFUND_NOTE_PHISKIN_SUC_NOTICE);
        SendNoticeUtil.successOrderSendNotice(commonService, customParameter, ordersTotal,object);
        }catch (Exception e){
            logger.error("退款成功发送企业微信给订单开单人错误:",e);
        }
    }
    /**
@@ -2560,6 +2544,7 @@
        List<ConsumeNotify> consumeNotifyList;
        String refundNo;
        BigDecimal consumeTotal;
        BigDecimal consumeRefundTotal;
        int refundStatus;
        for (Map.Entry<String, BigDecimal> entry : refundMap.entrySet()) {
            refundTotal = entry.getValue();
@@ -2569,11 +2554,19 @@
            //初始化可退金额
            consumeTotal = BigDecimal.ZERO;
            consumeRefundTotal = BigDecimal.ZERO;
            //获取支付信息(回调)
            consumeNotifyList = ConsumeTool.selectList(refundCashVo.getOrderId(),entry.getKey(),null,commonService);
            for(ConsumeNotify consumeNotify:consumeNotifyList){
                //计算总可退款金额
                consumeTotal = consumeTotal.add(consumeNotify.getPayAmount()).subtract(consumeNotify.getRefundTotal());
                consumeRefundTotal = consumeRefundTotal.add(consumeNotify.getRefundTotal());
            }
            //避免多退,要减去已退款
            refundTotal = refundTotal.subtract(consumeRefundTotal);
            if(refundTotal.compareTo(BigDecimal.ZERO) < 1){
                continue;
            }
            if(refundTotal.compareTo(consumeTotal) > 0){
@@ -2607,19 +2600,24 @@
                    //生成退款记录
                    RefundCash refundCash = new RefundCash();
                    refundCash.setRefundTotal(consumeTotal);
                    refundCash.setOutOrderNo(consumeNotify.getOutOrderNo());
                    refundCash.setPlatTrxNo(consumeNotify.getPlatTrxNo());
                    refundCash.setRefunNo(refundNo);
                    refundCash.setOrderId(refundCashVo.getOrderId());
                    refundCash.setConsumeNotifyId(consumeNotify.getConsumePayId());
                    refundCash.setRefundRecordId(refundRecordId);
                    commonService.insert(RefundCashMapper.class,refundCash);
                    //调起中心平台的退款
                    CenterPayUtil.unifyRefund(consumeNotify.getAppId(),consumeNotify.getPlatTrxNo(),refundNo,refundCashVo.getRemark(),consumeNotify.getPayAmount()
                    CenterPayUtil.unifyRefund(consumeNotify.getAppId(),consumeNotify.getPlatTrxNo(),refundNo,"员工退款",consumeNotify.getPayAmount()
                            ,consumeTotal,customParameter.getAppId(),customParameter.getPrivatekey(),fRefundService);
                    //已经退的跳过
                    refundTotal = refundTotal.subtract(consumeTotal);
                    commonService.insert(RefundCashMapper.class,refundCash);
                    //支付回调信息变化
                    ConsumeTool.updateRefundTotal(consumeNotify,consumeTotal,refundStatus,commonService);
                }catch (Exception e){
                    logger.error("第三方退款失败",e);
                    logger.error("第三方退款失败,错误信息:",e);
                }
            }
        }
phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
@@ -35,7 +35,6 @@
import com.hx.util.StringUtils;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -74,7 +73,6 @@
     */
    public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId) {
        System.out.println("commonService:"+commonService);
        RefundRecord refundRecord = commonService.selectOneByKeyBlob(RefundRecordMapper.class,refundId);
        if(refundRecord ==null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该退款信息!");
@@ -284,13 +282,6 @@
                OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,refundRecordMethod.getName()+"退款金额:"+refundRecordMethod.getActualTotal(),0, OrderLogConstants.LOG_TYPE_REFUND);
                orderLog.setOrderId(ordersTotal.getId());
                commonService.insert(OrderLogMapper.class,orderLog);
                //现金支付需要创建创建退款单进行退款
                RefundNote refundNote = new RefundNote(refundRecordMethod.getActualTotal(), refundRecordMethod.getNumberNo(),refundRecordMethod.getName(),ordersTotal.getId(),refundRecord.getUserId());
                refundNote.setRefundRecordId(refundRecord.getId());
                refundNote.setRefundName(refundRecordMethod.getRefundName());
                refundNote.setRefundNumberNo(refundRecordMethod.getRefundNumberNo());
                commonService.insert(RefundNoteMapper.class,refundNote);
            }
        }
        return refundCarryVo;