From 12b75ea8869fa6e65b1bd53d4460328e73a66125 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 22 三月 2023 22:35:20 +0800
Subject: [PATCH] 新增加司机端接口

---
 driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 170 insertions(+), 0 deletions(-)

diff --git a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
index f601368..e957afc 100644
--- a/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
+++ b/driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/DriverServiceImpl.java
@@ -12,6 +12,7 @@
 import com.supersavedriving.driver.modular.system.model.*;
 import com.supersavedriving.driver.modular.system.service.*;
 import com.supersavedriving.driver.modular.system.dao.DriverMapper;
+import com.supersavedriving.driver.modular.system.util.PayMoneyUtil;
 import com.supersavedriving.driver.modular.system.util.RedisUtil;
 import com.supersavedriving.driver.modular.system.util.ResultUtil;
 import com.supersavedriving.driver.modular.system.util.UUIDUtil;
@@ -83,6 +84,12 @@
 
     @Autowired
     private IOrderService orderService;
+
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
+    @Autowired
+    private IRechargeRecordService rechargeRecordService;
 
 
 
@@ -483,6 +490,7 @@
             if(h > 0 && h > time){
                 Driver driver = this.selectById(driverId);
                 AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+                accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
                 accountChangeDetail.setUserType(2);
                 accountChangeDetail.setUserId(driverId);
                 accountChangeDetail.setType(2);
@@ -510,6 +518,8 @@
         Driver driver = this.selectById(uid);
         DriverInfoWarpper driverInfo = new DriverInfoWarpper();
         BeanUtils.copyProperties(driver, driverInfo);
+        driverInfo.setBalance(driver.getBalance() + driver.getBackgroundBalance() + driver.getCouponBalance() + driver.getCommission());
+
         YouTuiDriver youTuiDriver = youTuiDriverService.selectOne(new EntityWrapper<YouTuiDriver>().eq("driverId", uid).last(" and failureTime > now() order by failureTime limit 0, 1"));
         if(null != youTuiDriver){
             driverInfo.setYouTuiStart(youTuiDriver.getCreateTime().getTime());
@@ -527,6 +537,7 @@
             Integer second = Integer.valueOf(value.split("_")[0]);
             driverInfo.setOnline(second);
         }
+        driverInfo.setWechatAuthorization(driver.getOpenid() == null ? 0 : 1);
         return driverInfo;
     }
 
@@ -550,6 +561,12 @@
         if(ToolUtil.isNotEmpty(driverInfo.getEmergencyPhone())){
             driver.setEmergencyPhone(driverInfo.getEmergencyPhone());
         }
+        if(ToolUtil.isNotEmpty(driverInfo.getWxCollectionCode())){
+            driver.setWxCollectionCode(driverInfo.getWxCollectionCode());
+        }
+        if(ToolUtil.isNotEmpty(driverInfo.getZfbCollectionCode())){
+            driver.setZfbCollectionCode(driverInfo.getZfbCollectionCode());
+        }
         if(ToolUtil.isNotEmpty(driverInfo.getPhone()) && ToolUtil.isNotEmpty(driverInfo.getCode())){
             String value = redisUtil.getValue(driverInfo.getPhone());
             if(ToolUtil.isEmpty(value)){
@@ -560,7 +577,160 @@
             }
             driver.setPhone(driverInfo.getPhone());
         }
+        if(ToolUtil.isNotEmpty(driverInfo.getOpenid())){
+            driver.setOpenid(driverInfo.getOpenid());
+        }
         this.updateById(driver);
         return ResultUtil.success();
     }
+
+    /**
+     * 清空司机积分
+     */
+    @Override
+    public void emptyIntegral() {
+        List<Driver> drivers = this.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("status", 1));
+        List<AccountChangeDetail> list = new ArrayList<>();
+        for (Driver driver : drivers) {
+            AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+            accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+            accountChangeDetail.setUserType(2);
+            accountChangeDetail.setUserId(driver.getId());
+            accountChangeDetail.setCreateTime(new Date());
+            accountChangeDetail.setOldData(driver.getIntegral().doubleValue());
+            accountChangeDetail.setType(2);
+            accountChangeDetail.setExplain("定时清空积分");
+            driver.setIntegral(0);
+            accountChangeDetail.setNewData(driver.getIntegral().doubleValue());
+            list.add(accountChangeDetail);
+        }
+        if(drivers.size() > 0){
+            this.updateBatchById(drivers);
+            accountChangeDetailService.insertBatch(list);
+        }
+
+    }
+
+
+    @Override
+    public ResultUtil balanceRecharge(Integer uid, Double amount) throws Exception {
+        Driver driver = this.selectById(uid);
+        //调起微信
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        String out_trade_no = sdf.format(new Date()) + UUIDUtil.getNumberRandom(3);
+        RechargeRecord rechargeRecord = new RechargeRecord();
+        rechargeRecord.setType(2);
+        rechargeRecord.setUserId(uid);
+        rechargeRecord.setCode(out_trade_no);
+        rechargeRecord.setAmount(amount);
+        rechargeRecord.setPayType(1);
+        rechargeRecord.setPayStatus(1);
+        rechargeRecord.setCreateTime(new Date());
+        rechargeRecord.setAgentId(driver.getAgentId());
+        rechargeRecordService.insert(rechargeRecord);
+
+
+        ResultUtil weixinpay = payMoneyUtil.weixinpay("余额充值", "", out_trade_no, amount.toString(), "/base/driver/balanceRechargeCallback", "APP");
+        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;
+                        }
+
+                        /**
+                         * SUCCESS--支付成功
+                         * REFUND--转入退款
+                         * NOTPAY--未支付
+                         * CLOSED--已关闭
+                         * REVOKED--已撤销(刷卡支付)
+                         * USERPAYING--用户支付中
+                         * PAYERROR--支付失败(其他原因,如银行返回失败)
+                         * ACCEPT--已接收,等待扣款
+                         */
+                        ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, "");
+                        if(resultUtil.getCode() == 200){
+                            Map<String, String> map = resultUtil.getData();
+                            String trade_type = map.get("trade_type");
+                            String trade_state = map.get("trade_state");
+                            String transaction_id = map.get("transaction_id");
+                            if("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){
+                                rechargeRecordService.deleteById(rechargeRecord1.getId());
+                                return;
+                            }
+                            if("SUCCESS".equals(trade_state)){
+                                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.setBalance(driver1.getBalance() + amount);
+                                accountChangeDetail.setNewData(driver1.getBalance());
+                                DriverServiceImpl.this.updateById(driver1);
+                                accountChangeDetailService.saveData(accountChangeDetail);
+
+                                rechargeRecord1.setPayTime(new Date());
+                                rechargeRecord1.setPayStatus(2);
+                                rechargeRecord1.setOrderNumber(transaction_id);
+                                rechargeRecordService.updateById(rechargeRecord1);
+                                return;
+                            }
+                            if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){
+                                Thread.sleep(wait);
+                                num++;
+                            }
+                        }
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+            }
+        }).start();
+        return weixinpay;
+    }
+
+
+    /**
+     * 充值回调通知逻辑处理
+     * @param out_trade_no
+     * @throws Exception
+     */
+    @Override
+    public void balanceRechargeCallback(String out_trade_no, String transaction_id) throws Exception {
+        RechargeRecord rechargeRecord1 = rechargeRecordService.selectOne(new EntityWrapper<RechargeRecord>().eq("code", out_trade_no));
+        if(rechargeRecord1.getPayStatus() != 1){
+            return;
+        }
+        Driver driver1 = this.selectById(rechargeRecord1.getUserId());
+        AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
+        accountChangeDetail.setUserType(2);
+        accountChangeDetail.setUserId(rechargeRecord1.getUserId());
+        accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3));
+        accountChangeDetail.setChangeType(3);
+        accountChangeDetail.setType(1);
+        accountChangeDetail.setCreateTime(new Date());
+        accountChangeDetail.setExplain("余额充值");
+        accountChangeDetail.setOldData(driver1.getBalance());
+        driver1.setBalance(driver1.getBalance() + rechargeRecord1.getAmount());
+        accountChangeDetail.setNewData(driver1.getBalance());
+        this.updateById(driver1);
+        accountChangeDetailService.saveData(accountChangeDetail);
+
+        rechargeRecord1.setPayTime(new Date());
+        rechargeRecord1.setPayStatus(2);
+        rechargeRecord1.setOrderNumber(transaction_id);
+        rechargeRecordService.updateById(rechargeRecord1);
+    }
 }

--
Gitblit v1.7.1