liujie
2025-11-25 b502ac4e96aca2ab29caa77187ab7673a853a797
ManagementJYXTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TOrderLogisticsController.java
@@ -13,6 +13,7 @@
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.stylefeng.guns.modular.huifu.biz.DouGongRefundBiz;
import com.stylefeng.guns.modular.huifu.biz.FenZhangUtil;
import com.stylefeng.guns.modular.system.controller.util.Base64Util;
import com.stylefeng.guns.modular.system.dao.OrderCancelMapper;
@@ -22,6 +23,8 @@
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.AllocationResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@@ -33,10 +36,14 @@
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * 小件物流订单控制器
@@ -79,6 +86,8 @@
    private PayMoneyUtil payMoneyUtil;
    @Autowired
    private IUserCouponRecordService userCouponRecordService;
    @Autowired
    private DouGongRefundBiz douGongRefundBiz;
    /**
     * 跳转到小件物流订单首页
@@ -152,6 +161,7 @@
        try{
            ShiroUser user = ShiroKit.getUser();
            TOrderLogistics tOrderLogistics = tOrderLogisticsService.selectById(tOrderLogisticsId);
            Integer orgState = tOrderLogistics.getState();
            tOrderLogistics.setState(10);
            //已支付的情况下进行退款操作
@@ -184,14 +194,38 @@
                        List<PaymentRecord> querys = paymentRecordService.query_(1, tOrderLogistics.getUserId(), 1, tOrderLogistics.getId(), tOrderLogistics.getType(), tOrderLogistics.getPayType(), 2);
                        System.out.println(querys);
                        boolean b = false;
                        List<Integer> orderIds = querys.stream().map(PaymentRecord::getOrderId).collect(Collectors.toList());
                        Map<Integer, TOrderLogistics> orderLogisticsMap = Collections.emptyMap();
                        if (CollectionUtils.isNotEmpty(orderIds)) {
                            orderLogisticsMap = tOrderLogisticsService.selectList(new EntityWrapper<TOrderLogistics>()
                                            .in("id", orderIds).isNotNull("outTradeNo"))
                                    .stream().collect(Collectors.toMap(TOrderLogistics::getId, Function.identity()));
                        }
                        for (PaymentRecord query : querys) {
                            System.out.println("支付方式:"+query.getPayType());
                            if(query.getPayType() == 1){//微信
                                Map<String, String> map = payMoneyUtil.wxRefund(query.getCode(), tOrderLogistics.getId() + "_" + tOrderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), query.getAmount().toString(), query.getAmount().toString(), "/base/cancleOrderWXPay");
                                System.out.println("map:"+map);
                                if(!"SUCCESS".equals(map.get("return_code"))){
                                    return ResultUtil.error(map.get("return_msg"));
                                //Map<String, String> map = payMoneyUtil.wxRefund(query.getCode(), tOrderLogistics.getId() + "_" + tOrderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), query.getAmount().toString(), query.getAmount().toString(), "/base/cancleOrderWXPay");
                                //System.out.println("map:"+map);
                                //if(!"SUCCESS".equals(map.get("return_code"))){
                                //    return ResultUtil.error(map.get("return_msg"));
                                //}
                                TOrderLogistics orderLogistics = orderLogisticsMap.get(query.getOrderId());
                                if (Objects.isNull(orderLogistics)) {
                                    log.error("小件物流取消订单退款失败,未找到对应的斗拱支付订单,orderId={}", query.getOrderId());
                                    continue;
                                }
                                String refundReqSeqId = RequestSeqUtil.generate("TK");
                                Map<String, Object> refund = douGongRefundBiz.refund(refundReqSeqId, BigDecimal.valueOf(query.getAmount()), DateUtil.format(query.getInsertTime(), "yyyyMMdd"), orderLogistics.getOutTradeNo(), 1);
                                orderLogistics.setRefundReqSeqId(refundReqSeqId);
                                orderLogistics.setState(orgState);
                                tOrderLogistics.setState(orgState);
                                if ("00000000".equals(refund.get("resp_code")) && "S".equals(refund.get("trans_stat"))) {
                                    orderLogistics.setState(10);
                                    tOrderLogistics.setState(10);
                                }else if (!"00000000".equals(refund.get("resp_code"))) {
                                    return ResultUtil.error("订单取消失败:" + refund.get("resp_desc").toString());
                                }
                                tOrderLogisticsService.updateById(orderLogistics);
                            }
                        }
                    }
@@ -283,60 +317,78 @@
        AllocationReq allocationReq= new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        if(type==1){
            allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
        }else {
            allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
        }
        money=money*100;
        allocationReq.setAmount((int)money);
        allocationReq.setProductName("分账");
        allocationReq.setProductCount(1);
        allocationReq.setOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setOrderAmount(1l);
        try {
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.out.println(allocationResp);
            return "ok";
        } catch (UpyztException e) {
            e.printStackTrace();
            return e.getMessage();
            Map<String, Object> result;
            if(type==1){
                //allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
                //
                //allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
                result = FenZhangUtil.fenzhang(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
            }else {
                //allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
                result = FenZhangUtil.payFromUser(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
            }
            if ("00000000".equals(result.get("respCode").toString())) {
                return "ok";
            } else {
                return result.get("respDesc").toString();
            }
        } catch (Exception e) {
            log.error("分账异常", e);
            throw new RuntimeException(e);
        }
        //money=money*100;
        //allocationReq.setAmount((int)money);
        //allocationReq.setProductName("分账");
        //allocationReq.setProductCount(1);
        //allocationReq.setOrderNo(ToolUtil.getRandomString(32));
        //allocationReq.setOrderAmount(1l);
        //try {
        //    AllocationResp allocationResp = AllocationExample.create(allocationReq);
        //    System.out.println(allocationResp);
        //    return "ok";
        //} catch (UpyztException e) {
        //    e.printStackTrace();
        //    return e.getMessage();
        //}
    }
    public String createAllocationReqUser(Integer companyId,Integer userId,int type,double money) throws Exception {
    public String createAllocationReqUser(Integer companyId,Integer userId,int type,double money) {
        List<TEnterpriseWithdrawal> tEnterpriseWithdrawals = tEnterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", companyId));
        TUser tUser = userService.selectById(userId);
        List<UserWithdrawal> userWithdrawals = userWithdrawalService.selectList(new EntityWrapper<UserWithdrawal>().eq("phone", tUser.getPhone()));
        if(userWithdrawals.size()==0){
            return "error";
        }
        AllocationReq allocationReq= new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        Map<String, Object> result;
        if(type==1){
        //AllocationReq allocationReq= new AllocationReq();
        //allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        try {
            Map<String, Object> result;
            if(type==1){
            //allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            //allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            //
            //allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
            result = FenZhangUtil.fenzhang(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
        }else {
            //allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
            //allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
            //allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
            result = FenZhangUtil.payFromUser(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
        }
        if ("00000000".equals(result.get("respCode").toString())) {
            return "ok";
        } else {
            return result.get("respDesc").toString();
                //allocationReq.setPayBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setRecvBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
                //
                //allocationReq.setPassword(Base64Util.decode(tEnterpriseWithdrawals.get(0).getTransactionAuthorizationCode()));
                result = FenZhangUtil.fenzhang(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
            }else {
                //allocationReq.setRecvBalanceAcctId(tEnterpriseWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setPayBalanceAcctId(userWithdrawals.get(0).getBalanceAcctId());
                //allocationReq.setPassword(Base64Util.decode(userWithdrawals.get(0).getTransactionAuthorizationCode()));
                result = FenZhangUtil.payFromUser(RequestSeqUtil.generate("TK"), DateUtil.formatDate(new Date(), "yyyyMMdd"), String.valueOf(money), userWithdrawals.get(0).getHuiFuId());
            }
            if ("00000000".equals(result.get("respCode").toString())) {
                return "ok";
            } else {
                return result.get("respDesc").toString();
            }
        } catch (Exception e) {
            log.error("分账异常", e);
            throw new RuntimeException(e);
        }
        //money=money*100;
        //allocationReq.setAmount((int)money);