Pu Zhibing
4 天以前 8675ddc7e76f418ee47adc50ee7bac35171a9620
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,11 @@
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.data.redis.core.RedisTemplate;
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;
@@ -65,9 +57,9 @@
    @Autowired
    private IOrderLogisticsSpreadService orderLogisticsSpreadService;
    @Autowired
    private RedisUtil redisUtil;
    private RedisTemplate redisTemplate;
    @Autowired
    private ICompanyService companyService;
@@ -330,13 +322,13 @@
                        }
                        merchantActivityService.updateBatchById(merchantActivities);
                    }
                    String value = redisUtil.getValue("merchantVoucher");
                    String value = (String) redisTemplate.opsForValue().get("merchantVoucher");
                    JSONObject jsonObject = JSON.parseObject(value);
                    if(null == jsonObject){
                        jsonObject = new JSONObject();
                    }
                    jsonObject.put(userInfo.getPhone(), listWarppers);
                    redisUtil.setStrValue("merchantVoucher", jsonObject.toJSONString());
                    redisTemplate.opsForValue().set("merchantVoucher", jsonObject.toJSONString());
                }
                break;
@@ -402,59 +394,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();
        }
    }
@@ -539,8 +484,8 @@
        orderLogistics.setArriveTime(date);
        orderLogistics.setStartServiceTime(date);
        orderLogistics.setBoardingTime(date);
        String value = redisUtil.getValue("DRIVER" + uid);
        String value = (String) redisTemplate.opsForValue().get("DRIVER" + uid);
        if(ToolUtil.isNotEmpty(value)){
            String[] split = value.split(",");
            Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(split[0], split[1]);