puzhibing
2023-05-25 9a6ce5f7180a4e8c9e8dfd4ea5232052d9220b3a
driver/guns-admin/src/main/java/com/agentdriving/driver/modular/system/service/impl/DriverServiceImpl.java
@@ -502,7 +502,7 @@
    @Override
    public PromotionWarpper queryPromotionQRCode(Integer uid) throws Exception {
        PromotionWarpper promotionWarpper = new PromotionWarpper();
        promotionWarpper.setUrl("http://121.37.15.157/share/driverShare/index.html?inviterId=" + uid);
        promotionWarpper.setUrl("http://139.9.238.199/share/driverShare/index.html?inviterId=" + uid);
        int user = appUserService.selectCount(new EntityWrapper<AppUser>().eq("inviterType", 2).eq("inviterId", uid).eq("status", 1));
        int driver = this.selectCount(new EntityWrapper<Driver>().eq("inviterType", 2).eq("inviterId", uid).eq("approvalStatus", 2).eq("status", 1));
        promotionWarpper.setTotal(user + driver);
@@ -679,7 +679,7 @@
    @Override
    public ResultUtil balanceRecharge(Integer uid, Double amount) throws Exception {
    public ResultUtil balanceRecharge(Integer uid, Integer type, Double amount) throws Exception {
        Driver driver = this.selectById(uid);
        //调起微信
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
@@ -695,8 +695,11 @@
        rechargeRecord.setAgentId(driver.getAgentId());
        rechargeRecordService.insert(rechargeRecord);
        if(type == 1){
        ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/driver/balanceRechargeCallback", "APP");
            if(weixinpay.getCode() != 200){
                return weixinpay;
            }
        new Thread(new Runnable() {
            @Override
            public void run() {
@@ -772,6 +775,84 @@
        }).start();
        return weixinpay;
    }
        if(type == 2){
            ResultUtil<String> alipay = payMoneyUtil.alipay("余额充值", "余额充值", out_trade_no, amount.toString(), "/base/driver/balanceRechargeCallbackAli");
            if(alipay.getCode() != 200){
                return alipay;
            }
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        int num = 1;
                        int wait = 0;
                        while (num <= 10){
                            int min = 5000;
                            wait += (min * num);
                            RechargeRecord rechargeRecord1 = rechargeRecordService.selectOne(new EntityWrapper<RechargeRecord>().eq("code", out_trade_no));
                            if(rechargeRecord1.getPayStatus() != 1){
                                return;
                            }
                            /**
                             * 交易状态:
                             * WAIT_BUYER_PAY(交易创建,等待买家付款)、
                             * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
                             * TRADE_SUCCESS(交易支付成功)、
                             * TRADE_FINISHED(交易结束,不可退款)
                             */
                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(out_trade_no);
                            if(resultUtil.getCode() == 200){
                                Map<String, String> map = resultUtil.getData();
                                String tradeStatus = map.get("tradeStatus");
                                String tradeNo = map.get("tradeNo");
                                if("TRADE_CLOSED".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)){
                                    rechargeRecordService.deleteById(rechargeRecord1.getId());
                                    return;
                                }
                                if("TRADE_SUCCESS".equals(tradeStatus)){
                                    Driver driver1 = DriverServiceImpl.this.selectById(uid);
                                    AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
                                    accountChangeDetail.setUserType(2);
                                    accountChangeDetail.setUserId(uid);
                                    accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
                                    accountChangeDetail.setChangeType(3);
                                    accountChangeDetail.setType(1);
                                    accountChangeDetail.setCreateTime(new Date());
                                    accountChangeDetail.setExplain("余额充值");
                                    accountChangeDetail.setOldData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                    driver1.setBalance(driver1.getBalance() + amount);
                                    accountChangeDetail.setNewData(driver1.getBalance() + driver1.getBackgroundBalance() + driver1.getCouponBalance() + driver1.getCommission());
                                    DriverServiceImpl.this.updateById(driver1);
                                    accountChangeDetailService.saveData(accountChangeDetail);
                                    rechargeRecord1.setPayTime(new Date());
                                    rechargeRecord1.setPayStatus(2);
                                    rechargeRecord1.setOrderNumber(tradeNo);
                                    rechargeRecordService.updateById(rechargeRecord1);
                                    return;
                                }
                                if("WAIT_BUYER_PAY".equals(tradeStatus)){
                                    Thread.sleep(wait);
                                    num++;
                                }
                            }else{
                                Thread.sleep(wait);
                                num++;
                            }
                            if(10 == num){
                                rechargeRecordService.deleteById(rechargeRecord1.getId());
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }).start();
            return alipay;
        }
        return ResultUtil.success();
    }
    /**