| | |
| | | package com.stylefeng.guns.modular.shunfeng.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; |
| | | import com.stylefeng.guns.modular.shunfeng.model.Financial; |
| | | import com.stylefeng.guns.modular.shunfeng.model.OrderRide; |
| | | import com.stylefeng.guns.modular.shunfeng.model.vo.ApiJson; |
| | | import com.stylefeng.guns.modular.shunfeng.service.IDriverRideService; |
| | | import com.stylefeng.guns.modular.shunfeng.service.IFinancialService; |
| | | import com.stylefeng.guns.modular.shunfeng.service.IOrderRideService; |
| | | import com.stylefeng.guns.modular.shunfeng.service.IParamService; |
| | | import com.stylefeng.guns.modular.shunfeng.service.ITimeTaskService; |
| | | import com.stylefeng.guns.modular.system.model.Company; |
| | | import com.stylefeng.guns.modular.system.model.Driver; |
| | | import com.stylefeng.guns.modular.system.model.UserInfo; |
| | | import com.stylefeng.guns.modular.system.service.ISystemNoticeService; |
| | | import com.stylefeng.guns.modular.system.service.IUserInfoService; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.OrderUtil; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.model.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 支付相关接口 |
| | | */ |
| | | @Api(tags = "顺风车支付相关接口") |
| | | @Api("顺风车支付相关接口") |
| | | @Controller |
| | | @RequestMapping("/api/payInfo") |
| | | public class PayInfoController { |
| | | |
| | | @Autowired |
| | | private IParamService paramService; |
| | | @Autowired |
| | | private IOrderRideService orderRideService; |
| | | @Autowired |
| | |
| | | private IUserInfoService userInfoService; |
| | | @Autowired |
| | | private ISystemNoticeService systemNoticeService; |
| | | /*顺风车司机*/ |
| | | @Autowired |
| | | private IDriverRideService driverRideService; |
| | | @Autowired |
| | | private IFinancialService financialService; |
| | | |
| | | |
| | | |
| | |
| | | * @param couponId |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/payBalanceRide") |
| | | @ApiOperation(value = "余额支付", httpMethod = "POST") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), |
| | | @ApiImplicitParam(name = "couponId", value = "优惠券id", dataType = "int"), |
| | | }) |
| | | public Object payBalanceRide(Integer orderId,Integer couponId){ |
| | | try { |
| | | OrderRide orderRide=orderRideService.selectById(orderId); |
| | |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("/payOnline") |
| | | public Object payOnline(Integer orderId,Integer type,String code,Integer payType,Integer isBalance,HttpServletRequest request,Integer couponId){ |
| | | @PostMapping("/payOnline") |
| | | @ApiOperation(value = "线上支付", httpMethod = "POST") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"), |
| | | @ApiImplicitParam(name = "payType", value = "支付类型 1=支付宝,2 = 微信 3:银行卡 4:小程序", dataType = "int"), |
| | | @ApiImplicitParam(name = "path", value = "前端支付很后的跳转页面", dataType = "string"), |
| | | @ApiImplicitParam(name = "ip", value = "前端支付IP地址", dataType = "string"), |
| | | }) |
| | | public Object payOnline(Integer orderId,Integer type,String code,Integer payType,Integer isBalance, |
| | | String path, String ip, HttpServletRequest request,Integer couponId){ |
| | | try { |
| | | if(orderId == null || orderId == 0){ |
| | | return ApiJson.returnNG("订单ID不能为空"); |
| | |
| | | if(orderRide.getState()==2){//已支付 |
| | | return ApiJson.returnNG("该订单不需要支付"); |
| | | } |
| | | info = new PayUtil().getPayInfo(payType,orderRide.getOrderNum(),openId,request); |
| | | Double orderMoney = orderRide.getMoney(); |
| | | if(2 == payType){ |
| | | UserInfo userInfo = userInfoService.selectById(orderRide.getUserId()); |
| | | if(null == orderRide.getIsCreated() || 0 == orderRide.getIsCreated()){ |
| | | //调用中台创建订单及拉起支付接口 |
| | | TradeOrderCreateData tradeOrderCreateData = new TradeOrderCreateData(); |
| | | tradeOrderCreateData.setTreatShopId("0"); |
| | | tradeOrderCreateData.setField1("{\"profitSharing\":\"1\",\"isCompensate\":\"0\",\"isPromote\":\"0\"}"); |
| | | tradeOrderCreateData.setCharge(new BigDecimal(orderMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | tradeOrderCreateData.setOrderNo("SF" + orderRide.getId()); |
| | | tradeOrderCreateData.setCustomerId(userInfo.getOnconUUID()); |
| | | tradeOrderCreateData.setPartnerPayId(orderRide.getZttravelId()); |
| | | tradeOrderCreateData.setTotalFee(Double.valueOf(orderMoney * 100).intValue() + ""); |
| | | tradeOrderCreateData.setOrderDesc("完成订单"); |
| | | tradeOrderCreateData.setRetUrl(path); |
| | | tradeOrderCreateData.setClientIp(ip); |
| | | tradeOrderCreateData.setServiceType(4); |
| | | |
| | | List<GoodsInfoRequest> goodsInfo = new ArrayList<>(); |
| | | GoodsInfoRequest goodsInfoRequest = new GoodsInfoRequest(); |
| | | goodsInfoRequest.setSubOpenId(userInfo.getAppletsOpenId()); |
| | | goodsInfoRequest.setProfitSharing("1"); |
| | | goodsInfo.add(goodsInfoRequest); |
| | | tradeOrderCreateData.setGoodsInfo(goodsInfo); |
| | | TradeOrderCreate tradeOrderCreate = OrderUtil.tradeOrderCreate1(tradeOrderCreateData, 0); |
| | | PayInfo payInfo = tradeOrderCreate.getPayInfo(); |
| | | if(!"000000".equals(payInfo.getRetCode())){ |
| | | return ResultUtil.error(payInfo.getRetMsg()); |
| | | } |
| | | orderRide.setIsCreated(1); |
| | | orderRide.setZttravelId(tradeOrderCreate.getOrderInfo().getOrderId()); |
| | | info = payInfo.getData().getRedirectUrl(); |
| | | }else{ |
| | | //拉起支付 |
| | | TradePayOff1Data tradePayOff1Data = new TradePayOff1Data(); |
| | | tradePayOff1Data.setPartnerPayId(orderRide.getZttravelId()); |
| | | tradePayOff1Data.setTotalFee(Double.valueOf(orderMoney * 100).intValue() + ""); |
| | | tradePayOff1Data.setRetUrl(path); |
| | | tradePayOff1Data.setClientIp(ip); |
| | | tradePayOff1Data.setOrderDesc("完成订单"); |
| | | List<GoodsInfoRequest> goodsInfo = new ArrayList<>(); |
| | | GoodsInfoRequest goodsInfoRequest = new GoodsInfoRequest(); |
| | | goodsInfoRequest.setSubOpenId(userInfo.getAppletsOpenId()); |
| | | goodsInfoRequest.setProfitSharing("1"); |
| | | goodsInfo.add(goodsInfoRequest); |
| | | tradePayOff1Data.setGoodsInfo(goodsInfo); |
| | | PayInfo payInfo = OrderUtil.tradePayOff1(tradePayOff1Data, 0); |
| | | if(!"000000".equals(payInfo.getRetCode())){ |
| | | return ResultUtil.error(payInfo.getRetMsg()); |
| | | } |
| | | info = payInfo.getData().getRedirectUrl(); |
| | | } |
| | | orderRideService.updateById(orderRide); |
| | | |
| | | //创建定时任务查询订单支付状态 |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | threadPoolExecutor.execute(()->{ |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 13) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | OrderRide orderRide1 = orderRideService.selectById(orderRide.getId()); |
| | | if (orderRide1.getState() != 1) { |
| | | break; |
| | | } |
| | | GetTravelItineraryListRequest request1 = new GetTravelItineraryListRequest(); |
| | | request1.setCustomerId(userInfo.getOnconUUID()); |
| | | request1.setOrderNo("SF" + orderRide1.getId()); |
| | | ListPage<List<TravelItinerary>> travelItineraryList = OrderUtil.getTravelItineraryList(request1); |
| | | TravelItinerary travelItinerary = travelItineraryList.getList().get(0); |
| | | if(travelItinerary.getStatus() != 7 || Arrays.asList(3, 11).contains(travelItinerary.getOrderStatus())){ |
| | | GetPaymentInfoDataRequest getPaymentInfoDataRequest1 = new GetPaymentInfoDataRequest(); |
| | | getPaymentInfoDataRequest1.setPartnerPayId(orderRide1.getZttravelId()); |
| | | GetPaymentInfo getPaymentInfo1 = OrderUtil.paymentInfo(getPaymentInfoDataRequest1); |
| | | |
| | | String trade_no = getPaymentInfo1.getPayId(); |
| | | Financial financial = new Financial(); |
| | | financial.setType(1);//类型 1=收入 2=支出 |
| | | financial.setPayType("2");//支付类型 1=余额 2=微信 3=支付宝 |
| | | financial.setMoney(orderMoney);//支付金额 |
| | | financial.setOrderNum(orderRide1.getOrderNum());//我们本地的订单号 |
| | | financial.setLsType(trade_no);//流水号 |
| | | financial.setAddTime(new Date()); |
| | | financial.setTradeStatus("success"); |
| | | //顺风车支付 |
| | | //修改订单表中的订单流水和支付方式 |
| | | orderRide1.setOutNum(financial.getLsType());//流水 |
| | | orderRide1.setPayTime(new Date()); |
| | | orderRide1.setPayType(2); |
| | | orderRide1.setState(2); |
| | | financial.setPwType(8);//顺风车 |
| | | financial.setUserId(orderRide1.getUserId()); |
| | | financial.setLx(1);//1=用户 2=司机 |
| | | financial.setOrderType(4);//顺风车 |
| | | financialService.insert(financial); |
| | | orderRideService.updateById(orderRide1); |
| | | /*添加系统消息*/ |
| | | try { |
| | | systemNoticeService.addSystemNotice(1, "您成功支付从" + orderRide1.getStartName() + "到" + orderRide1.getEndName() + "的顺风车订单", orderRide1.getUserId(), 1); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | threadPoolExecutor.shutdown(); |
| | | } |
| | | |
| | | }); |
| | | }else{ |
| | | info = new PayUtil().getPayInfo(payType,orderRide.getOrderNum(),openId,request); |
| | | } |
| | | return ApiJson.returnOK(info); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |