Pu Zhibing
7 天以前 0b5d21c6338bb3bd094a5bf2379001c4e9772eb5
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
@@ -15,8 +15,10 @@
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.model.vo.UnPayOrderVO;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.util.qianyuntong.model.QYTPaymentCallback;
import com.stylefeng.guns.modular.system.warpper.*;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
@@ -28,13 +30,11 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
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.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -47,7 +47,7 @@
 * 订单控制器(综合)
 */
@Api
//@CrossOrigin
@Slf4j
@RestController
@RequestMapping("")
public class OrderController {
@@ -66,25 +66,28 @@
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private WeChatUtil weChatUtil;
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
    @Autowired
    private IComplaintService complaintService;
    @Autowired
    private IOrderEvaluateService orderEvaluateService;
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
@@ -131,7 +134,10 @@
    private SystemPriceMapper systemPriceMapper;
    
    @Resource
    private RedisTemplate redisTemplate;
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private ISystemPriceCityService systemPriceCityService;
    
    
    /**
@@ -509,18 +515,27 @@
                }
                OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                if(orderPrivateCar.getState()>1){
                    Map<String, Object> query1 = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId());
                    System.out.println("参数:"+orderPrivateCar.getCompanyId()+"|"+orderPrivateCar.getServerCarModelId());
                    System.out.println("query1:"+query1);
                if(orderPrivateCar.getState()>1) {
                    Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderPrivateCar.getStartLon().toString(), orderPrivateCar.getStartLat().toString());
                    String provinceCode = geocode.get("provinceCode");
                    String cityCode = geocode.get("cityCode");
                    String districtCode = geocode.get("districtCode");
                    //获取匹配的城市价格配置
                    SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode);
                    if (null == systemPriceCity) {
                        return ResultUtil.error("请先配置价格规则");
                    }
                    Map<String, Object> query1 = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId(), systemPriceCity.getId());
                    System.out.println("参数:" + orderPrivateCar.getCompanyId() + "|" + orderPrivateCar.getServerCarModelId());
                    System.out.println("query1:" + query1);
                    //开始根据不同的方式计算金额
                    if(query1!=null){
                    JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费
                    JSONObject contentPutOne = JSON.parseObject(query1.get("contentPutOne").toString());//一人拼成
                    JSONObject contentNotOne = JSON.parseObject(query1.get("contentNotOne").toString());//一人未拼成
                    JSONObject contentPutTwo = JSON.parseObject(query1.get("contentPutTwo").toString());//2人拼成
                    JSONObject contentNotTwo = JSON.parseObject(query1.get("contentNotTwo").toString());//2人未拼成
                    JSONObject contentPutThree = JSON.parseObject(query1.get("contentPutThree").toString());//3人拼成
                    if (query1 != null) {
                        JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费
                        JSONObject contentPutOne = JSON.parseObject(query1.get("contentPutOne").toString());//一人拼成
                        JSONObject contentNotOne = JSON.parseObject(query1.get("contentNotOne").toString());//一人未拼成
                        JSONObject contentPutTwo = JSON.parseObject(query1.get("contentPutTwo").toString());//2人拼成
                        JSONObject contentNotTwo = JSON.parseObject(query1.get("contentNotTwo").toString());//2人未拼成
                        JSONObject contentPutThree = JSON.parseObject(query1.get("contentPutThree").toString());//3人拼成
                    JSONObject contentNotThree = JSON.parseObject(query1.get("contentNotThree").toString());//3人未拼成
                    JSONObject contentExclusive = JSON.parseObject(query1.get("contentExclusive").toString());//独享
                    JSONObject contentPrice = JSON.parseObject(query1.get("contentPrice").toString());//一口价
@@ -575,6 +590,41 @@
                orderInfoWarpper.setTime(arriveTime.substring(11,arriveTime.length()-3));
            }
            return ResultUtil.success(orderInfoWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/order/addAppeal")
    @ApiOperation(value = "发起申诉", tags = {"用户端-服务中"}, notes = "",response = OrderInfoWarpper.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=城际)", name = "orderType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "申诉描述", name = "abnormalIntro", required = true, dataType = "String"),
            @ApiImplicitParam(value = "申诉图片", name = "abnormalImg", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<OrderInfoWarpper> addAppeal(Integer orderId, Integer orderType,String abnormalIntro, String abnormalImg, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            switch (orderType){
                case 1://专车
                     orderPrivateCarService.addAppeal(uid, orderId,abnormalIntro,abnormalImg);
                    break;
                case 2://出租车
                    orderTaxiService.addAppeal(uid,orderId,abnormalIntro,abnormalImg);
                    break;
                case 3://跨城
                     orderCrossCityService.addAppeal(uid,orderId,abnormalIntro,abnormalImg);
                    break;
            }
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -1568,15 +1618,12 @@
            System.out.println("完成订单微信支付回调");
            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
            System.out.println("wx支付信息:"+map);
            if(null != map){
                String order_id = map.get("transaction_id");
                String out_trade_no = map.get("out_trade_no");
                String result = map.get("result");
                String total_fee = map.get("total_fee");
                String transaction_id = map.get("transaction_id");
                if(ToolUtil.isNotEmpty(out_trade_no) && ToolUtil.isNotEmpty(order_id)){
                    PrintWriter out = response.getWriter();
                    out.write(result);
@@ -1995,61 +2042,99 @@
    /**
     * 管理后台推单
     *
     * @param orderType
     * @return
     */
    @ResponseBody
    @PostMapping("/base/taxi/pushOrder")
    public ResultUtil pushOrder(Integer orderId, Integer orderType){
    public ResultUtil pushOrder(Integer orderId, Integer orderType) {
        try {
            switch (orderType){
            switch (orderType) {
                case 1:
                    return orderPrivateCarService.pushOrderPrivateCar(orderId);
                case 2:
                    return orderTaxiService.pushOrderTaxi(orderId);
            }
            return ResultUtil.success();
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
//    public  void cloudPay(String total_fee,String transaction_id,int type) {
//        if(type==1){
//            BigDecimal divide = new BigDecimal(total_fee).divide(new BigDecimal(100));
//            total_fee=divide.toString();
//        }
//        Company company = companyService.selectOne(new EntityWrapper<Company>()
//                .eq("type", 1)
//                .last("LIMIT 1"));
//        // 查询平台开户信息
//        TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
//                .eq("companyId", company.getId()));
//        DepositReq depositReq = new DepositReq();
//        depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
//        depositReq.setTotalAmount(new BigDecimal(total_fee).multiply(new BigDecimal(100)).intValue()); // 总金额
//        depositReq.setAmount(new BigDecimal(total_fee).multiply(new BigDecimal(100)).intValue()); // 支付金额
//        depositReq.setDiscountAmount(0); // 优惠金额
//        depositReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
//        depositReq.setDepositType("1");
//        depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
//        depositReq.setPaymentTradeNo(transaction_id); // 系统交易流水号
//        depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
//        depositReq.setOrderNo(transaction_id);
//        depositReq.setOrderAmount(new BigDecimal(total_fee).multiply(new BigDecimal(100)).longValue());
//        depositReq.setProductName("用户支付充值");
//        depositReq.setProductCount(1);
//
//        try {
//            DepositResp depositResp = DepositExample.create(depositReq);
//            System.err.println(depositResp);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
    /**
     * 黔云通支付回调通知
     *
     * @param qytPaymentCallback
     * @return
     */
    @ResponseBody
    @PostMapping("/base/order/qytPaymentCallback")
    public String qytPaymentCallback(@RequestBody QYTPaymentCallback qytPaymentCallback) {
        log.info("【黔云通支付回调通知】请求参数:" + JSON.toJSONString(qytPaymentCallback));
        if (null == qytPaymentCallback) {
            return "error";
        }
        return "success";
    }
    @ResponseBody
    @PostMapping("/api/get/unPayOrder")
    @ApiOperation(value = "获取未支付订单", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
           @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城,4=小件物流,null=全部)", name = "orderType", required = false, dataType = "int"),
           @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil getUnPayOrder( Integer orderType,  HttpServletRequest request){
        try {
            // 从Redis中获取当前用户ID
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            List<UnPayOrderVO> unpaidOrders = new ArrayList<>();
            // 根据订单类型查询对应未支付订单
            if (orderType == null || orderType == 1) {
                // 查询未支付的专车订单
                List<UnPayOrderVO> privateCarOrders = orderPrivateCarService.getUnpayPrivateOrders(uid);
                unpaidOrders.addAll(privateCarOrders);
            }
            if (orderType == null || orderType == 2) {
                // 查询未支付的出租车订单
                List<UnPayOrderVO> taxiOrders = orderTaxiService.getUnpayTaxiOrders(uid);
                unpaidOrders.addAll(taxiOrders);
            }
            if (orderType == null || orderType == 3) {
                // 查询未支付的跨城订单
                List<UnPayOrderVO> crossCityOrders = orderCrossCityService.getUnpayCrossCityOrders(uid);
                unpaidOrders.addAll(crossCityOrders);
            }
            if (orderType == null || orderType == 4 || orderType == 5) {
                // 查询未支付的物流订单(包含类型4和5)
                List<UnPayOrderVO> logisticsOrders = orderLogisticsService.getUnpayLogisticsOrders(uid);
                unpaidOrders.addAll(logisticsOrders);
            }
            // 按创建时间倒序排序(最新的订单在前)
            unpaidOrders.sort(Comparator.comparing(UnPayOrderVO::getInsertTime).reversed());
            Map<String, Object> result = new HashMap<>();
            result.put("total", unpaidOrders.size());
            result.put("orders", unpaidOrders);
            return ResultUtil.success(result);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}