From 7da4caa40befd523033b8a1d01246ae468674680 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 12 九月 2022 08:57:59 +0800
Subject: [PATCH] 更新用户端接口

---
 UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java |  256 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 216 insertions(+), 40 deletions(-)

diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
index 8357092..67953d2 100644
--- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
+++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -5,6 +5,7 @@
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.core.util.ToolUtil;
+import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
 import com.stylefeng.guns.modular.smallLogistics.dao.OrderLogisticsMapper;
 import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
 import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread;
@@ -17,6 +18,7 @@
 import com.stylefeng.guns.modular.system.model.*;
 import com.stylefeng.guns.modular.system.service.*;
 import com.stylefeng.guns.modular.system.util.*;
+import com.stylefeng.guns.modular.system.util.GoogleMap.*;
 import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
 import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
 import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
@@ -102,6 +104,9 @@
     @Autowired
     private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
+    @Autowired
+    private IUserCouponRecordService userCouponRecordService;
+
     @Value("${callbackPath}")
     private String callbackPath;
 
@@ -143,7 +148,16 @@
      */
     @Override
     public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer uid) throws Exception {
-        Company query = companyCityService.query(startLonLat.split(",")[0], startLonLat.split(",")[1]);
+        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(startLonLat.split(",")[1]), Double.valueOf(startLonLat.split(",")[0]));
+        if(null == reverseGeocode){
+            return ResultUtil.error("地理位置解析失败");
+        }
+        AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos();
+        String[] city = new String[addressComponentsVos.length];
+        for (int i = 0; i < addressComponentsVos.length; i++) {
+            city[i] = addressComponentsVos[i].getLongName();
+        }
+        Company query = companyCityService.query(city);
         if(null == query){
             return ResultUtil.error("预约取货点暂无企业服务");
         }
@@ -186,12 +200,13 @@
      * @throws Exception
      */
     public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endAddress) throws Exception{
-        Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress);
-        if(Integer.valueOf(geocoding.get("status").toString()) != 0){
+        FindPlaceFromTextVo findplacefromtext = GoogleMapUtil.findplacefromtext(endAddress);
+        if(null == findplacefromtext){
             return ResultUtil.error("收货地址有误,无法查询具体地址信息");
         }
-        String location = ((List<String>)geocoding.get("data")).get(0);
-        ResultUtil<Map<String, Double>> price = this.getPrice(type, startLonLat.split(",")[0], startLonLat.split(",")[1], location.split(",")[0], location.split(",")[1]);
+        Double lng = findplacefromtext.getLng();
+        Double lat = findplacefromtext.getLat();
+        ResultUtil<Map<String, Double>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString());
         if(price.getCode() == 200 && type == 5){
             Map<String, Double> data = price.getData();
             data.put("ordinary", data.get("ordinary") * number);
@@ -231,7 +246,7 @@
         endAddress = endAddress.replaceAll("& #40;", "(");
         endAddress = endAddress.replaceAll("& #41;", ")");
         OrderLogistics orderLogistics = new OrderLogistics();
-        Company query = companyCityService.query(placementLon, placementLat);
+        Company query = companyCityService.query1(placementLon, placementLat);
         if(null == query){
             return ResultUtil.error("该地点暂无企业服务");
         }
@@ -244,21 +259,24 @@
         orderLogistics.setRemark(remark);
         orderLogistics.setPlacementLon(Double.valueOf(placementLon));
         orderLogistics.setPlacementLat(Double.valueOf(placementLat));
-        Map<String, String> geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat);
-        orderLogistics.setPlacementAddress(geocode.get("address"));
+        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(placementLat), Double.valueOf(placementLon));
+        if(null == reverseGeocode){
+            return ResultUtil.error("解析地址出错");
+        }
+
+        String address = reverseGeocode.getAddress();
+        orderLogistics.setPlacementAddress(address);
         orderLogistics.setStartLon(Double.valueOf(startLon));
         orderLogistics.setStartLat(Double.valueOf(startLat));
         orderLogistics.setStartAddress(startAddress);
-        Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress);
-        if(Integer.valueOf(geocoding.get("status").toString()) != 0){
+        FindPlaceFromTextVo findplacefromtext = GoogleMapUtil.findplacefromtext(endAddress);
+        if(null == findplacefromtext){
             return ResultUtil.error("收货地址有误,无法查询具体地址信息");
         }
-        if(((List<String>)geocoding.get("data")).size() == 0){
-            return ResultUtil.error("无法查询具体地址信息");
-        }
-        String location = ((List<String>)geocoding.get("data")).get(0);
-        orderLogistics.setEndLon(Double.valueOf(location.split(",")[0]));
-        orderLogistics.setEndLat(Double.valueOf(location.split(",")[1]));
+        Double lng = findplacefromtext.getLng();
+        Double lat = findplacefromtext.getLat();
+        orderLogistics.setEndLon(lng);
+        orderLogistics.setEndLat(lat);
         orderLogistics.setEndAddress(endAddress);
         orderLogistics.setUrgent(urgent);
         orderLogistics.setRecipient(recipient);
@@ -266,7 +284,7 @@
         orderLogistics.setMileage(0D);
         orderLogistics.setIsReassign(1);
         orderLogistics.setReassignNotice(0);
-        ResultUtil<Map<String, Double>> price = this.getPrice(type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]);
+        ResultUtil<Map<String, Double>> price = this.getPrice1(type, String.valueOf(startLon), String.valueOf(startLat), lng.toString(), lat.toString());
         if(price.getCode() != 200){
             return price;
         }
@@ -314,6 +332,65 @@
             JSONObject jsonObject = JSON.parseObject(content);
             String distance1 = distance.get("distance");
             Double dist = Double.valueOf(distance1) / 1000;
+            if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num1")) < 0){
+                price1 = jsonObject.getDouble("num2");
+            }
+            if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num12")) < 0){
+                price2 = jsonObject.getDouble("num13");
+            }
+
+            if(dist.compareTo(jsonObject.getDouble("num3")) >= 0 && dist.compareTo(jsonObject.getDouble("num4")) < 0){
+                price1 = jsonObject.getDouble("num5");
+            }
+            if(dist.compareTo(jsonObject.getDouble("num14")) >= 0 && dist.compareTo(jsonObject.getDouble("num15")) < 0){
+                price2 = jsonObject.getDouble("num16");
+            }
+
+            if(dist.compareTo(jsonObject.getDouble("num6")) >= 0 && dist.compareTo(jsonObject.getDouble("num7")) < 0){
+                price1 = jsonObject.getDouble("num8");
+            }
+            if(dist.compareTo(jsonObject.getDouble("num17")) >= 0 && dist.compareTo(jsonObject.getDouble("num18")) < 0){
+                price2 = jsonObject.getDouble("num19");
+            }
+
+            if(dist.compareTo(jsonObject.getDouble("num9")) >= 0 && dist.compareTo(jsonObject.getDouble("num10")) < 0){
+                price1 = jsonObject.getDouble("num11");
+            }
+            if(dist.compareTo(jsonObject.getDouble("num20")) >= 0 && dist.compareTo(jsonObject.getDouble("num21")) < 0){
+                price2 = jsonObject.getDouble("num22");
+            }
+        }else{
+            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
+            String content = String.valueOf(query1.get("content"));
+            JSONObject jsonObject = JSON.parseObject(content);
+            price1 = jsonObject.getDouble("num1");
+            price2 = jsonObject.getDouble("num2");
+        }
+        Map<String, Double> map = new HashMap<>();
+        map.put("ordinary", price1);//普通
+        map.put("precious", price2);//贵重
+        return ResultUtil.success(map);
+    }
+
+
+
+    public ResultUtil<Map<String, Double>> getPrice1(Integer type, String startLon, String startLat, String endLon, String endLat) throws Exception{
+        Company query = companyCityService.query1(startLon, startLat);
+        if(null == query){
+            return ResultUtil.error("预约取货点暂无企业服务");
+        }
+        Double price1 = 0D;
+        Double price2 = 0D;
+        if(type == 4){//同城
+            Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null);
+            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(startLat), Double.valueOf(startLon), Double.valueOf(endLat), Double.valueOf(endLon));
+            if(null == distancematrix){
+                return ResultUtil.error("计算距离出错");
+            }
+            String content = String.valueOf(query1.get("content"));
+            JSONObject jsonObject = JSON.parseObject(content);
+            Long distance = distancematrix.getDistance();
+            Double dist = Double.valueOf(distance) / 1000;
             if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num1")) < 0){
                 price1 = jsonObject.getDouble("num2");
             }
@@ -438,7 +515,7 @@
         UserInfo userInfo = userInfoService.selectById(uid);
         ResultUtil resultUtil = ResultUtil.success(new HashMap<>());
 
-        if(payType == 1){//微信支付
+        if(payType == 1){//手机支付
            return payMoneyUtil.weixinpay("小件物流下单支付",orderId +"",orderId + "_" + orderLogistics.getType(),orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId());
                   /*  icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(),
                             "小件物流下单支付", orderMoney, callbackPath + "/base/wxPayOrderTaxi", "",
@@ -450,7 +527,7 @@
                 resultUtil = ResultUtil.error(map.get("msg"), "");
             }*/
         }
-        if(payType == 2){//支付宝支付
+        if(payType == 2){//银行卡支付
             return payMoneyUtil.alipay("小件物流下单支付","小件物流下单支付",orderId + "," + orderLogistics.getType(),orderMoney+"","/base/aliPayOrderTaxi");
            /* Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流下单支付", orderMoney, callbackPath + "/base/aliPayOrderTaxi", "", type, null);
             if(map.get("code").equals("200")){
@@ -491,6 +568,32 @@
             this.pushOrder(orderLogistics);//推单
         }
 
+        if(payType == 4){//现金支付
+            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
+            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
+
+            //添加交易明细
+            transactionDetailsService.saveData(uid, "小件物流下单支付", orderMoney, 2, 1, 1, 4, orderId);
+            userInfoService.updateById(userInfo);
+
+            orderLogistics.setState(1);//小件物流先支付后司机抢单
+            orderLogistics.setDriverPay(1);
+            orderLogistics.setPayType(4);
+            orderLogistics.setPayMoney(orderMoney);
+
+            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                }
+            }).start();
+
+            systemNoticeService.addSystemNotice(1, "您已使用现金成功完成小件物流订单支付,谢谢使用!", uid, 1);
+
+            this.pushOrder(orderLogistics);//推单
+        }
+
         this.updateById(orderLogistics);
         return resultUtil;
     }
@@ -514,29 +617,10 @@
         Double orderMoney = orderLogisticsSpread.getPrice();
         UserInfo userInfo = userInfoService.selectById(uid);
         ResultUtil resultUtil = ResultUtil.success("");
-
-        /*if(payType == 1){//微信支付
-            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 9, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/wxPayOrderLogisticsSpread", "", type, userInfo.getAppletsOpenId());
-            if(map.get("code").equals("200")){
-                paymentRecordService.saveData(1, null, null, orderId, orderLogistics.getType(), 1, orderMoney, map.get("order_id"), 1);//添加预支付数据
-                resultUtil = ResultUtil.success(map.get("data"));
-            }else{
-                resultUtil = ResultUtil.error(map.get("msg"), "");
-            }
-        }
-        if(payType == 2){//支付宝支付
-            Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + "," + orderLogistics.getType(), 10, 5, uid.toString(), "小件物流补差价", orderMoney, callbackPath + "/base/aliPayOrderLogisticsSpread", "", type, null);
-            if(map.get("code").equals("200")){
-                paymentRecordService.saveData(1, null, null, orderId, orderLogistics.getType(), 2, orderMoney, map.get("order_id"), 1);//添加预支付数据
-                resultUtil = ResultUtil.success(map.get("data"));
-            }else{
-                resultUtil = ResultUtil.error(map.get("msg"), "");
-            }
-        }*/
-        if(payType == 1){//微信支付
+        if(payType == 1){//手机支付
             return payMoneyUtil.weixinpay("小件物流下单支付",orderId +"",orderId + "_" + orderLogistics.getType(),orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId());
         }
-        if(payType == 2){//支付宝支付
+        if(payType == 2){//银行卡支付
             return payMoneyUtil.alipay("小件物流下单支付","小件物流下单支付",orderId + "," + orderLogistics.getType(),orderMoney+"","/base/aliPayOrderTaxi");
         }
         if(payType == 3){//余额支付
@@ -598,6 +682,68 @@
 
             systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单差价支付,谢谢使用!", uid, 1);
         }
+
+        if(payType == 4){//现金支付
+            if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){
+                return ResultUtil.error("余额不足,无法完成支付", "");
+            }
+
+            userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+
+            SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId());
+            userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分
+
+            //添加交易明细
+            transactionDetailsService.saveData(uid, "小件物流补差价", orderMoney, 2, 1, 1, 4, orderId);
+            userInfoService.updateById(userInfo);
+
+            orderLogistics.setState(12);//已支付差价
+            this.updateById(orderLogistics);
+
+            orderLogisticsSpread.setPayMoney(orderMoney);
+            orderLogisticsSpread.setPayTime(new Date());
+            orderLogisticsSpread.setPayType(4);
+            orderLogisticsSpread.setDriverPay(1);
+            orderLogisticsSpreadService.updateById(orderLogisticsSpread);
+
+            //添加已收入明细
+            Company company = companyService.selectById(orderLogistics.getCompanyId());
+            Double speMoney =  orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney();
+            BigDecimal d = null;
+            BigDecimal c = null;
+            if(company.getIsSpeFixedOrProportional() == 2){//固定
+                d = new BigDecimal(speMoney);
+                c = new BigDecimal(orderMoney).subtract(d);
+            }
+            if(company.getIsSpeFixedOrProportional() == 1){//比例
+                d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+                c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+            }
+
+            Income income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
+            income.setMoney(income.getMoney() + d.doubleValue());
+            incomeService.updateById(income);
+            income = incomeService.selectOne(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType()));
+            income.setMoney(income.getMoney() + c.doubleValue());
+            incomeService.updateById(income);
+            Driver driver = driverService.selectById(orderLogistics.getDriverId());
+            driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
+            driverService.updateById(driver);
+
+            // TODO: 2020/5/24 这里需要给司机和用户推送订单状态
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                    pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0);
+                }
+            }).start();
+
+            systemNoticeService.addSystemNotice(1, "您已使用现金成功完成小件物流订单差价支付,谢谢使用!", uid, 1);
+        }
+
 
         this.updateById(orderLogistics);
         return resultUtil;
@@ -961,10 +1107,40 @@
         return map;
     }
 
+    @Override
+    public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
+        Map<String, Object> map = orderLogisticsMapper.queryOrderInfo(orderId);
+        OrderLogistics orderLogistics = this.selectById(orderId);
+        if(null != map.get("reassignNotice") && Integer.valueOf(String.valueOf(map.get("reassignNotice"))) == 2){//改派完成,重新获取了新的司机数据,开始修改数据防止继续调用
+            orderLogistics.setReassignNotice(0);
+            this.updateById(orderLogistics);
+        }
+        if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){
+            map.put("state", map.get("oldState"));
+        }
+        Map<String, String> geocode = gdMapGeocodingUtil.geocode(map.get("startLon").toString(), map.get("startLat").toString());
+        map.put("startCity", geocode.get("city"));
+        geocode = gdMapGeocodingUtil.geocode(map.get("endLon").toString(), map.get("endLat").toString());
+        map.put("endCity", geocode.get("city"));
 
+        String driverId = redisUtil.getValue("DEVICE_" + map.get("driverId"));
+        map.put("device", ToolUtil.isNotEmpty(driverId) ? 2 : 1);
+        map.put("orderType", orderLogistics.getType());
+        return map;
+    }
 
     public synchronized String getOrderNum() throws Exception{
         int size = this.selectCount(null);
         return "LOGISTICS" + String.valueOf(1000000 + size + 1).substring(1);
     }
+
+
+    @Override
+    public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception {
+        OrderLogistics orderLogistics = this.selectById(orderId);
+        List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney(), pageNum, size);
+        List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney(), pageNum, size);
+        list.addAll(list1);
+        return list;
+    }
 }

--
Gitblit v1.7.1