Pu Zhibing
6 天以前 638e7deedf01e2fa276d38f2215003e43996c54f
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -6,12 +6,8 @@
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
import com.stylefeng.guns.modular.account.util.Base64Util;
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.stylefeng.guns.modular.smallLogistics.dao.OrderLogisticsMapper;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread;
@@ -23,15 +19,10 @@
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.warpper.MerchantCouponListWarpper;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.AllocationResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -402,59 +393,12 @@
                income.setObjectId(orderLogistics.getCompanyId());
                incomeService.insert(income);
                // TODO 司机云闪付 超时扣款 司机电子余额转账到平台
                // 超时扣款 司机电子余额转账到平台
                divideAccounts(orderLogistics.getDriverId(),timeOutMoney,orderLogistics.getOrderNum());
            }
        }
        this.updateById(orderLogistics);
        return ResultUtil.success();
    }
    /**
     * 分账
     */
    private void divideAccounts(Integer driverId,double amount,String orderNum){
        try{
            // 查询平台开户信息
            TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
                    .eq("companyId", 1)
                    .last("LIMIT 1"));
            if(Objects.isNull(enterpriseWithdrawal)){
                throw new RuntimeException("平台开户信息为空");
            }
            // 司机开户信息
            Driver driver = driverService.selectById(driverId);
            if(Objects.isNull(driver)){
                throw new RuntimeException("司机信息不存在");
            }
            // TODO 司机进件信息
            UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
                    .eq("phone", driver.getPhone())
                    .last("LIMIT 1"));
            if(Objects.isNull(driverWith)){
                throw new RuntimeException("司机开户信息为空");
            }
            AllocationReq allocationReq = new AllocationReq();
            allocationReq.setOutOrderNo(orderNum);
            allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId()); // 发送方
            allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 接收方
            BigDecimal multiply = new BigDecimal(100).multiply(BigDecimal.valueOf(amount));
            allocationReq.setAmount(multiply.intValue()); // 金额
            allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
            allocationReq.setOrderNo(orderNum);
            allocationReq.setOrderAmount((long) multiply.intValue());
            allocationReq.setProductName("小件物流超时扣款");
            allocationReq.setProductCount(1);
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            System.err.println("小件物流超时扣款:"+allocationResp);
        }catch (UpyztException e){
            e.printStackTrace();
        }
    }