From 2a498d9f65f873cedb74ab5bcb48ad4b845d0622 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 30 八月 2023 10:01:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java |  411 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 386 insertions(+), 25 deletions(-)

diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java
index 4b3da9d..10c71f4 100644
--- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java
+++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java
@@ -1,30 +1,36 @@
 package com.supersavedriving.user.modular.api;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.supersavedriving.user.core.common.annotion.ServiceLog;
 import com.supersavedriving.user.core.util.ToolUtil;
-import com.supersavedriving.user.modular.system.model.AppUser;
-import com.supersavedriving.user.modular.system.model.Order;
-import com.supersavedriving.user.modular.system.service.IAppUserService;
-import com.supersavedriving.user.modular.system.service.IOrderService;
+import com.supersavedriving.user.modular.system.model.*;
+import com.supersavedriving.user.modular.system.service.*;
+import com.supersavedriving.user.modular.system.util.GaoDe.MapUtil;
+import com.supersavedriving.user.modular.system.util.GaoDe.model.District;
+import com.supersavedriving.user.modular.system.util.MallBook.model.InterfaceResponse;
+import com.supersavedriving.user.modular.system.util.MallBook.model.Receive;
+import com.supersavedriving.user.modular.system.util.MallBook.model.ReceiveUser;
+import com.supersavedriving.user.modular.system.util.MallBook.util.RSASignature;
+import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest;
 import com.supersavedriving.user.modular.system.util.PayMoneyUtil;
 import com.supersavedriving.user.modular.system.util.ResultUtil;
 import com.supersavedriving.user.modular.system.warpper.*;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -36,6 +42,8 @@
 @RequestMapping("")
 public class OrderController {
 
+    Logger logger = LoggerFactory.getLogger(OrderController.class);
+
     @Autowired
     private IOrderService orderService;
 
@@ -44,6 +52,79 @@
 
     @Autowired
     private PayMoneyUtil payMoneyUtil;
+
+    @Autowired
+    private IBillService billService;
+
+    @Autowired
+    private IRevenueService revenueService;
+
+    @Autowired
+    private IDriverService driverService;
+
+    @Autowired
+    private IBranchOfficeService branchOfficeService;
+
+    @Autowired
+    private ISystemConfigService systemConfigService;
+
+    @Autowired
+    private IRechargeRecordService rechargeRecordService;
+
+    @Autowired
+    private IAccountChangeDetailService accountChangeDetailService;
+
+    @Autowired
+    private IDivisionRecordService divisionRecordService;
+
+
+
+
+
+    @ResponseBody
+    @PostMapping("/api/order/queryServerPrice")
+//    @ServiceLog(name = "获取正在进行中的订单id", url = "/api/order/queryServerOrder")
+    @ApiOperation(value = "根据定位获取恶劣天气+节假日信息", tags = {"用户端-首页"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "String"),
+            @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "String"),
+    })
+    public ResponseWarpper<Integer> queryServerPrice(String lat,String lon){
+        try {
+            Integer i =0; // 0为不能接单 1为恶劣天气  2为节假日 3为恶劣+节假日
+            District geocode = MapUtil.geocode(lon, lat);
+            String districtCode = geocode.getDistrictCode();
+            List<BranchOffice> districtCode1 = branchOfficeService.selectList(new EntityWrapper<BranchOffice>().eq("districtCode", districtCode).eq("status",1));
+            if(districtCode1.size()>0){
+                BranchOffice branchOffice = districtCode1.get(0);
+                Integer id = branchOffice.getId();
+                SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", id));
+                if(systemConfig!=null){
+                    String content = systemConfig.getContent();
+                    JSONObject jsonObject = JSONObject.parseObject(content);
+                    String num1 = jsonObject.get("num1").toString();
+                    String num9 = jsonObject.get("num3").toString();
+                    if("1".equals(num1)){
+                        i=1;
+                    }
+                    if("1".equals(num9)){
+                        i=2;
+                    }
+                    if("1".equals(num1)&&"1".equals(num9)){
+                        i=3;
+                    }
+                }
+                if(i == 0){
+                    i = 4;
+                }
+            }
+            return ResponseWarpper.success(i);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
 
 
 
@@ -72,6 +153,7 @@
             return new ResponseWarpper(500, e.getMessage());
         }
     }
+
 
 
 
@@ -181,6 +263,28 @@
 
 
     @ResponseBody
+    @PostMapping("/base/order/queryShareOrderInfo")
+//    @ServiceLog(name = "获取订单详情", url = "/base/order/queryShareOrderInfo")
+    @ApiOperation(value = "获取订单详情", tags = {"用户端-分享"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
+    })
+    public ResponseWarpper<OrderInfoWarpper> queryOrderInfo1(Long orderId){
+        if(null == orderId){
+            return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
+        }
+        try {
+            OrderInfoWarpper orderInfoWarpper = orderService.queryOrderInfo(null, orderId);
+            return ResponseWarpper.success(orderInfoWarpper);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
     @PostMapping("/api/order/editOrderEndAddress")
 //    @ServiceLog(name = "修改终点", url = "/api/order/editOrderEndAddress")
     @ApiOperation(value = "修改终点", tags = {"用户端-首页"}, notes = "")
@@ -208,10 +312,39 @@
     @ApiOperation(value = "获取订单费用明细", tags = {"用户端-首页"}, notes = "")
     @ApiImplicitParams({
             @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
-            @ApiImplicitParam(value = "是否余额抵扣(0=否,1=是)", name = "payType", required = true, dataType = "int"),
             @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
     })
-    public ResponseWarpper<OrderPriceWarpper> queryOrderPrice(Long orderId, Integer payType){
+    public ResponseWarpper<OrderPriceInfoWarpper> queryOrderPrice(Long orderId){
+        if(null == orderId){
+            return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            OrderPriceInfoWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId);
+            return ResponseWarpper.success(orderPriceWarpper);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/api/order/calculationOfExpenses")
+//    @ServiceLog(name = "重新计算待支付页面订单费用明细", url = "/api/order/calculationOfExpenses")
+    @ApiOperation(value = "重新计算待支付页面订单费用明细", tags = {"用户端-首页"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
+            @ApiImplicitParam(value = "优惠券id", name = "couponId", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "是否使用余额抵扣(0=否,1=是)", name = "payType", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "抵扣金额", name = "balance", required = true, dataType = "double"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<OrderPriceWarpper> calculationOfExpenses(Long orderId, Integer couponId, Integer payType, Double balance){
         if(null == orderId){
             return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
         }
@@ -223,7 +356,7 @@
             if(null == uid){
                 return ResponseWarpper.success(ResultUtil.tokenErr());
             }
-            OrderPriceWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId, payType);
+            OrderPriceWarpper orderPriceWarpper = orderService.calculationOfExpenses(uid, orderId, couponId, payType, balance);
             return ResponseWarpper.success(orderPriceWarpper);
         }catch (Exception e){
             e.printStackTrace();
@@ -283,26 +416,147 @@
 
     /**
      * 订单微信支付回调处理
-     * @param request
      * @param response
      */
     @ResponseBody
     @PostMapping("/base/order/orderPayCallback")
-    public void orderPayCallback(HttpServletRequest request, HttpServletResponse response){
+    public void orderPayCallback(@RequestBody InterfaceResponse interfaceResponse, HttpServletResponse response){
         try {
-            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
-            if(null != map){
-                String out_trade_no = map.get("out_trade_no");
-                String transaction_id = map.get("transaction_id");
-                String result = map.get("result");
-                String orderId = out_trade_no.substring(17);
-                ResultUtil resultUtil = orderService.orderPayCallback(orderId, transaction_id);
-                if(resultUtil.getCode() == 10000){
+            // 验签
+            boolean verify = RSASignature.validate(interfaceResponse.content(), interfaceResponse.getSign());
+            if (verify) {//验签成功业务处理逻辑
+                if("0000".equals(interfaceResponse.getCode())){
+                    JSONObject jsonObject = JSON.parseObject(interfaceResponse.getResult());
+                    Integer status = jsonObject.getInteger("status");
+                    String orderId = jsonObject.getString("parameter1");
+                    String parameter2 = jsonObject.getString("parameter2");
+                    if(2 == status){
+                        Order order = orderService.selectById(orderId);
+                        AccountChangeDetail accountChangeDetail = accountChangeDetailService.selectById(parameter2);
+                        Double m = new BigDecimal(accountChangeDetail.getOldData()).subtract(new BigDecimal(accountChangeDetail.getNewData())).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
+                        AppUser appUser1 = appUserService.selectById(order.getUserId());
+                        appUser1.setAccountBalance(new BigDecimal(appUser1.getAccountBalance()).add(new BigDecimal(m)).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
+                        appUserService.updateById(appUser1);
+                        accountChangeDetailService.deleteById(accountChangeDetail.getId());
+                        System.err.println("支付失败");
+                    }
+                    if(1 == status){
+                        String merOrderId = jsonObject.getString("merOrderId");
+                        ResultUtil resultUtil = orderService.orderPayCallback(orderId, merOrderId);
+                        if(resultUtil.getCode() == 10000){
+                            response.setStatus(200);
+                            PrintWriter out = response.getWriter();
+                            out.print("OK");
+                            out.flush();
+                            out.close();
+                        }
+                    }
+                }
+            } else {//验签失败业务处理逻辑
+                System.err.println("支付回调验签失败");
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 转账回调
+     * @param execute
+     * @param response
+     */
+    @ResponseBody
+    @PostMapping("/base/order/zhaunzhangCallback")
+    public void zhaunzhangCallback(@RequestBody InterfaceResponse execute, HttpServletResponse response){
+        try {
+            if("0000".equals(execute.getCode())){
+                JSONObject jsonObject = JSON.parseObject(execute.getResult());
+                Integer status = jsonObject.getInteger("status");//0:待处理;1:成功;2:失败
+                if(2 == status){
+                    logger.warn("转账失败");
+                    return;
+                }
+                String parameter1 = jsonObject.getString("parameter1");
+                RechargeRecord rechargeRecord = rechargeRecordService.selectById(parameter1);
+
+
+                response.setStatus(200);
+                PrintWriter out = response.getWriter();
+                out.print("OK");
+                out.flush();
+                out.close();
+            }else{
+                logger.warn("转账失败:" + execute.getMsg());
+                return;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+
+    /**
+     * 异步分账回调
+     */
+    @ResponseBody
+    @PostMapping("/base/order/ledgerCallback")
+    public void ledgerCallback(@RequestBody InterfaceResponse execute, HttpServletResponse response){
+        try{
+            // 验签
+            boolean verify = RSASignature.validate(execute.content(), execute.getSign());
+            if (verify) {//验签成功业务处理逻辑
+                if("0000".equals(execute.getCode())){
+                    JSONObject jsonObject = JSON.parseObject(execute.getResult());
+                    Integer status = jsonObject.getInteger("status");
+                    if(2 == status){
+                        logger.warn("异步分账回调异常");
+                        return;
+                    }
+                    String merOrderId = jsonObject.getString("merOrderId");
+                    String divisionRecordId = jsonObject.getString("parameter1");
+                    DivisionRecord divisionRecord = divisionRecordService.selectById(divisionRecordId);
+                    if(divisionRecord.getState() == 2){
+
+                    }
+
+                    //确认收货
+                    new Timer().schedule(new TimerTask() {
+                        @Override
+                        public void run() {
+                            Receive receive = new Receive();//确认收货
+                            receive.setOriginalMerOrderId(merOrderId);
+                            receive.setRcvAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + "");
+                            List<ReceiveUser> splitList = new ArrayList<>();
+                            ReceiveUser receiveUser = new ReceiveUser();
+                            receiveUser.setSplitUserId(divisionRecord.getMerchantNumber());
+                            receiveUser.setRcvSplitAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + "");
+                            splitList.add(receiveUser);
+                            receive.setSplitList(splitList);
+                            TrhRequest<Receive> request1 = new TrhRequest();
+                            InterfaceResponse execute = request1.execute(receive, Receive.SERVICE_CODE);
+                            if(!"0000".equals(execute.getCode())){
+                                logger.warn("确认收货" + execute.getMsg());
+                            }
+                            JSONObject jsonObject = JSON.parseObject(execute.getResult());
+                            String status = jsonObject.getString("status");
+                            if("2".equals(status)){
+                                logger.warn("确认收货失败");
+                            }
+                            if("0".equals(status)){
+                                logger.warn("确认收货处理中");
+                            }
+                        }
+                    }, 60000);
+                    response.setStatus(200);
                     PrintWriter out = response.getWriter();
-                    out.print(result);
+                    out.print("OK");
                     out.flush();
                     out.close();
                 }
+            } else {//验签失败业务处理逻辑
+                System.err.println("支付回调验签失败");
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -336,5 +590,112 @@
         }
     }
 
+    @ResponseBody
+    @PostMapping("/api/order/queryMyOrder")
+//    @ServiceLog(name = "获取我的行程", url = "/api/order/queryMyOrder")
+    @ApiOperation(value = "获取我的行程", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<List<OrderListWarpper>> queryMyOrder(Integer pageNum, Integer pageSize){
+        if(null == pageNum){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
+        }
+        if(null == pageSize){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            List<OrderListWarpper> orderListWarppers = orderService.queryMyOrder(uid, pageNum, pageSize);
+            return ResponseWarpper.success(orderListWarppers);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/order/queryNotInvoiceOrder")
+//    @ServiceLog(name = "获取未开票订单列表", url = "/api/order/queryNotInvoiceOrder")
+    @ApiOperation(value = "获取未开票订单列表", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<List<OrderListWarpper>> queryNotInvoiceOrder(NotInvoiceOrder notInvoiceOrder){
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            List<OrderListWarpper> orderListWarppers = orderService.queryNotInvoiceOrder(uid, notInvoiceOrder);
+            return ResponseWarpper.success(orderListWarppers);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/api/order/invoicing")
+//    @ServiceLog(name = "开票操作", url = "/api/order/invoicing")
+    @ApiOperation(value = "开票操作", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper invoicing(Invoicing invoicing){
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            ResultUtil invoicing1 = billService.invoicing(uid, invoicing);
+            return ResponseWarpper.success(invoicing1);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/api/order/queryBillList")
+//    @ServiceLog(name = "获取开票历史", url = "/api/order/queryBillList")
+    @ApiOperation(value = "获取开票历史", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<List<BillWarpper>> queryBillList(Integer pageNum, Integer pageSize){
+        if(null == pageNum){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
+        }
+        if(null == pageSize){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            List<BillWarpper> billWarppers = billService.queryBillList(uid, pageNum, pageSize);
+            return ResponseWarpper.success(billWarppers);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
 
 }

--
Gitblit v1.7.1