package com.stylefeng.guns.modular.taxi.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.server.IOrderCrossCityService; import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl; import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.dao.*; 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.warpper.BaseWarpper; import com.stylefeng.guns.modular.system.warpper.EndPushWarpper; import com.stylefeng.guns.modular.system.warpper.OrderServerWarpper; import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.model.PaymentRecord; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; import org.bouncycastle.crypto.tls.MACAlgorithm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @Service @Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class OrderTaxiServiceImpl extends ServiceImpl implements IOrderTaxiService { @Resource private OrderTaxiMapper orderTaxiMapper; @Resource private SensitiveWordsMapper sensitiveWordsMapper; @Resource private SysIntegralMapper sysIntegralMapper; @Resource private UserActivityDiscount1Mapper userActivityDiscount1Mapper; @Resource private OrderPrivateCarMapper orderPrivateCarMapper; @Resource private RegionMapper regionMapper; @Autowired private IOrderCancelService orderCancelService; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private IDriverService driverService; @Autowired private DateUtil dateUtil; @Autowired private IUserInfoService userInfoService; @Autowired private IPushOrderService pushOrderService; @Autowired private ICancleOrderService cancleOrderService; @Autowired private PayMoneyUtil payMoneyUtil; @Autowired private ITransactionDetailsService transactionDetailsService; @Autowired private IPaymentRecordService paymentRecordService; @Autowired private IUserCouponRecordService userCouponRecordService; @Autowired private IUserRedPacketRecordService userRedPacketRecordService; @Autowired private GDMapGeocodingUtil gdMapGeocodingUtil; @Autowired private ICompanyCityService companyCityService; @Autowired private PushUtil pushUtil; @Autowired private RedisUtil redisUtil; @Autowired private RestTemplate internalRestTemplate; @Autowired private IUserActivityRedenvelopeService userActivityRedenvelopeService; @Autowired private IDriverOrdersService driverOrdersService; @Autowired private IIncomeService incomeService; @Autowired private ICompanyService companyService; /*@Autowired private ICBCPayUtil icbcPayUtil;*/ @Autowired private ISystemNoticeService systemNoticeService; @Autowired private IOrderPositionService orderPositionService; @Autowired private ChinaMobileUtil chinaMobileUtil; @Autowired private IDriverServiceService driverServiceService; @Autowired private GDFalconUtil gdFalconUtil; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Autowired private IOrderCrossCityService orderCrossCityService; public static List orderIds = new ArrayList<>(); @Value("${callbackPath}") private String callbackPath; /** * 出租车下单操作 * @param orderTaxi * @param uid * @return * @throws Exception */ @Override public synchronized ResultUtil taxiOrder(OrderTaxi orderTaxi, Integer uid) throws Exception { //定义用户所属公司 UserInfo userInfo1 = userInfoService.selectById(uid); Company query = companyCityService.query1(orderTaxi.getUserId(), String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat())); if(null == query){ return ResultUtil.error("出发点暂未开通"); } if(null != userInfo1.getCompanyId() && 0 != userInfo1.getCompanyId()){ userInfo1.setCompanyId(query.getId()); userInfoService.updateById(userInfo1); } if(orderTaxi.getTravelTime().getTime() > (System.currentTimeMillis() + 600000)){ orderTaxi.setOrderType(2); } /** * 1.下了即时单就不能下预约单和即时单 * 2.下了预约单和再下一张即时单不能再下预约单 */ List list = orderTaxiMapper.queryByState_(uid, 1, 1, 1, 2, 3, 4, 5, 6, 11); if(list.size() > 0){ return ResultUtil.error("有未完成的订单"); } List orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 1, 1, 1, 2, 3, 4, 5, 6, 7, 11); if(orderPrivateCars.size() > 0){ return ResultUtil.error("有未完成的订单"); } list = orderTaxiMapper.queryByState_(uid, 2, 1, 1, 2, 3, 4, 5, 6, 11); if(list.size() > 0 && orderTaxi.getOrderType() == 2){ return ResultUtil.error("有未完成的订单"); } orderPrivateCars = orderPrivateCarMapper.queryByState(uid, 2, 1, 1, 2, 3, 4, 5, 6, 7, 11); if(orderPrivateCars.size() > 0 && orderTaxi.getOrderType() == 2){ return ResultUtil.error("有未完成的订单"); } orderTaxi.setOrderNum(this.getOrderNum()); Map geocode = gdMapGeocodingUtil.geocode(String.valueOf(orderTaxi.getPlacementLon()), String.valueOf(orderTaxi.getPlacementLat())); orderTaxi.setPlacementAddress(geocode.get("address")); orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #40;", "\\("));//特殊字符转义 orderTaxi.setStartAddress(orderTaxi.getStartAddress().replaceAll("& #41;", "\\)")); orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #40;", "\\(")); orderTaxi.setEndAddress(orderTaxi.getEndAddress().replaceAll("& #41;", "\\)")); orderTaxi.setUserId(uid); orderTaxi.setMileage(0D); orderTaxi.setOrderMoney(0D); orderTaxi.setTravelMoney(0D); orderTaxi.setParkMoney(0D); orderTaxi.setRoadTollMoney(0D); orderTaxi.setRedPacketMoney(0D); orderTaxi.setCouponMoney(0D); orderTaxi.setInsertTime(new Date()); orderTaxi.setIsReassign(1); if(orderTaxi.getSubstitute() == 0){//不是代下单 UserInfo userInfo = userInfoService.selectById(uid); if(ToolUtil.isEmpty(userInfo.getPhone())){ return ResultUtil.error("请先绑定手机号码"); } orderTaxi.setPassengers(userInfo.getFirstName() + "." + userInfo.getLastName()); orderTaxi.setPassengersPhone(userInfo.getPhone()); } orderTaxi.setState(1);//待接单 if(orderTaxi.getOrderSource() == 2 && null != orderTaxi.getDriverId()){//扫码下单, Driver driver = driverService.selectById(orderTaxi.getDriverId()); if(null == driver){ return ResultUtil.error("扫码下单失败,司机信息有误"); } if(driver.getAuthState() == 1){ return ResultUtil.error("司机信息还未完成审核,无法完成下单"); } if(driver.getAuthState() == 3){ return ResultUtil.error("司机账户已被冻结,无法提供服务"); } if(driver.getAuthState() == 4){ return ResultUtil.error("司机信息未通过审核,无法提供服务"); } if(driver.getState() == 1){ return ResultUtil.error("司机还未上线,无法提供服务"); } if(driver.getState() == 3){ return ResultUtil.error("司机正在服务中,无法提供服务"); } List driverServices = driverServiceService.query(orderTaxi.getDriverId(), 2); if(driverServices.size() == 0){ return ResultUtil.error("该司机不能服务此业务"); } orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : ( driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1)); orderTaxi.setCarId(driver.getCarId()); orderTaxi.setState(2);//待出发 orderTaxi.setSnatchOrderTime(new Date()); //调用高德创建轨迹 String s = gdFalconUtil.selectTerminal(driver.getPhone()); String track = gdFalconUtil.createTrack(s); orderTaxi.setTrackId(track); //调用移动的小号接口 Map geocode1 = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString()); Region region = regionMapper.query(geocode1.get("districtCode")); // Map map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1))); // if(String.valueOf(map.get("code")).equals("200")){ // orderTaxi.setTelX(map.get("telX")); // orderTaxi.setBindId(map.get("bindId")); // } driver.setState(3); driverService.updateById(driver); } this.insert(orderTaxi); new Thread(new Runnable() { @Override public void run() { if(orderTaxi.getState() == 2){ //推送司机订单状态 pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); } } }).start(); if(orderTaxi.getState() == 1){ //推送司机抢单 this.pushOrder(orderTaxi); } //添加消息 systemNoticeService.addSystemNotice(1, "您的出租车订单已下单成功,我们正在为您指派司机,请稍后!", orderTaxi.getUserId(), 1); BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setId(orderTaxi.getId()); return ResultUtil.success(baseWarpper); } /** * 继续执行推动等待操作 * @param id * @throws Exception */ @Override public ResultUtil pushOrderTaxi(Integer id) throws Exception { OrderTaxi orderTaxi = this.selectById(id); if(null == orderTaxi){ return ResultUtil.error("推送订单失败,订单信息有误"); } if(orderTaxi.getState() != 1){ return ResultUtil.error("订单已被司机接单,不能重复推送"); } //处理摆渡订单的继续推单操作 if(orderTaxi.getType() == 2){ OrderCrossCityServiceImpl.pushEndMap.put(orderTaxi.getCrossCityOrderId(), false);//还原标识数据 List list = orderPrivateCarService.selectList(new EntityWrapper().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace())); List> orders = new ArrayList<>(); for(OrderPrivateCar orderPrivateCar1 : list){ if(orderPrivateCar1.getState() != 1){ return ResultUtil.error("订单已被司机接单,推单取消"); } Map map = new HashMap<>(); map.put("orderType", 1); map.put("orderId", orderPrivateCar1.getId()); orders.add(map); } List list1 = this.selectList(new EntityWrapper().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace())); for(OrderTaxi orderTaxi1 : list1){ if(orderTaxi1.getState() != 1){ return ResultUtil.error("订单已被司机接单,推单取消"); } Map map = new HashMap<>(); map.put("orderType", 2); map.put("orderId", orderTaxi1.getId()); orders.add(map); } //开始重新推单 orderCrossCityService.pushOrder(orders); }else{ this.pushOrder(orderTaxi); } return ResultUtil.success(); } /** * 获取取消订单需要支付的金额(包含小费) * @param id * @return * @throws Exception */ @Override public ResultUtil queryCancleAmount(Integer id) throws Exception { OrderTaxi orderTaxi = this.selectById(id); if(null == orderTaxi){ return ResultUtil.error("获取数据失败,订单信息有误"); } double amount = 0; // CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId()); // if(null != orderTaxi.getDriverId() && // (orderTaxi.getSnatchOrderTime().getTime() + query.getMinuteNum() * 60 * 1000) < new Date().getTime()){//收费的情况 // if(null != query){ // amount += query.getMoney(); // } // } BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setAmount(amount); return ResultUtil.success(baseWarpper); } /** * 添加订单取消 * @param id * @param reason * @param remark * @param uid * @throws Exception */ @Override public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception { if(ToolUtil.isNotEmpty(remark)){ if(ToolUtil.isNotEmpty(remark)){ remark = remark.toLowerCase(); List sensitiveWords = sensitiveWordsMapper.selectList(null); for(SensitiveWords s : sensitiveWords) { remark = remark.replaceAll(s.getContent().toLowerCase(), "***"); } } } OrderTaxi orderTaxi = this.selectById(id); Integer integer = null; if(null == orderTaxi){ return ResultUtil.error("取消订单失败,订单信息有误"); } if(orderTaxi.getState() > 5 && orderTaxi.getState() != 12){ return ResultUtil.error("取消订单失败,不合法的操作"); } if(null == orderTaxi.getDriverId()){//没有接单的情况 if(orderTaxi.getType() == 2){//摆渡车 OrderCrossCityServiceImpl.pushEndMap.remove(orderTaxi.getCrossCityOrderId());//删除标识数据 List list = orderPrivateCarService.selectList(new EntityWrapper().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace())); for(OrderPrivateCar orderPrivateCar1 : list){ orderCancelService.saveData(orderPrivateCar1.getId(), 1, "无司机接单", "无司机接单", null, null, 2, 1, uid); orderPrivateCar1.setState(10); orderPrivateCarService.updateById(orderPrivateCar1); } List list1 = this.selectList(new EntityWrapper().eq("type", 2).eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()).eq("place", orderTaxi.getPlace())); for(OrderTaxi orderTaxi1 : list1){ orderCancelService.saveData(orderTaxi1.getId(), 2, "无司机接单", "无司机接单", null, null, 2, 1, uid); orderTaxi1.setState(10); this.updateById(orderTaxi1); } }else{ integer = orderCancelService.saveData(id, 2, "无司机接单", "无司机接单", null, null, 2, 1, uid); orderTaxi.setState(10); this.updateById(orderTaxi); } }else { // CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId()); // if (null != query) { // if ((orderTaxi.getSnatchOrderTime().getTime() + query.getMinuteNum() * 60 * 1000) < System.currentTimeMillis() && query.getMoney().compareTo(0D) > 0) {//收费的情况 // orderTaxi.setState(12); // this.updateById(orderTaxi); // integer = orderCancelService.saveData(id, 2, reason, remark, null, query.getMoney(), 1, 1, uid); // } else { // integer = orderCancelService.saveData(id, 2, reason, remark, null, null, 2, 1, uid); // // orderTaxi.setState(10); // this.updateById(orderTaxi); // } // this.deleteTask(id);//删除定时任务 // // new Thread(new Runnable() { // @Override // public void run() { // pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0); // System.err.println("推送取消操作---------------------"); // } // }).start(); // // //修改司机为空闲 // Driver driver = driverService.selectById(orderTaxi.getDriverId()); // driver.setState(2); // driverService.updateById(driver); // }else{ // return ResultUtil.error("请完善后台取消规则设置"); // } } //添加消息 systemNoticeService.addSystemNotice(1, "您已成功取消出行订单,谢谢使用!", orderTaxi.getUserId(), 1); Map map = new HashMap<>(); map.put("id", integer); return ResultUtil.success(map); } /** * 取消订单操作 * @param id * @return * @throws Exception */ @Override public ResultUtil cancleOrderTaxi(Integer id, Integer payType, Integer cancleId, Integer type, Integer language) throws Exception { OrderTaxi orderTaxi = this.selectById(id); Integer uid = orderTaxi.getUserId(); UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(""); if(null == orderTaxi){ return ResultUtil.error((language == 1 ? "订单信息有误" : language == 2 ? "Order-information error" : "Erreur d’information de commande"), ""); } if(orderTaxi.getState() != 12){ return ResultUtil.error((language == 1 ? "订单取消失败" : language == 2 ? "Failed to cancel order" : "Échec de l’annulation de la commande"), ""); } OrderCancel orderCancel = null; if(null == cancleId){ orderCancel = orderCancelService.query(id, 2, null, null, 1); }else{ orderCancel = orderCancelService.selectById(cancleId); } // CancleOrder query = cancleOrderService.query(orderTaxi.getOrderType(), 2, orderTaxi.getCompanyId()); // if(null != query){ // if(payType == 1){//微信支付 // orderCancel.setPayType(1); // orderCancelService.updateById(orderCancel); // resultUtil = payMoneyUtil.weixinpay("订单取消",id +"",id + "_2_fei",query.getMoney()+"","/base/wxCancelOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); // } // if(payType == 2){//支付宝支付 // orderCancel.setPayType(2); // orderCancelService.updateById(orderCancel); // resultUtil = payMoneyUtil.alipay("订单取消","订单取消",id + ",2",query.getMoney()+"","/base/aliCancelOrderTaxi"); // } // if(payType == 3){//余额支付 // if(userInfo.getBalance() != null && userInfo.getBalance() < query.getMoney()){ // return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant"); // } // // userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(query.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); // //添加交易明细 // transactionDetailsService.saveData(uid, "取消订单", query.getMoney(), 2, 1, 1, 2, id); // userInfoService.updateById(userInfo); // // //解除小号绑定 // if(orderTaxi.getBindId() != null){ // chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(),orderTaxi.getTelX()); // } // // orderTaxi.setState(10); // orderTaxi.setTelX(""); // orderTaxi.setBindId(""); // this.updateById(orderTaxi); // // orderCancel.setState(2); // orderCancel.setPayType(3); // orderCancelService.updateById(orderCancel); // // //添加已收入明细 // incomeService.saveData(1, orderTaxi.getCompanyId(), 3, orderTaxi.getId(), 2, query.getMoney()); // // this.deleteTask(id);//删除定时任务 // //// new Thread(new Runnable() { //// @Override //// public void run() { //// pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0); //// } //// }).start(); // // //添加消息 // systemNoticeService.addSystemNotice(1, "您已使用余额成功支付取消订单费用,谢谢使用!", orderTaxi.getUserId(), 1); // } // } return resultUtil; } /** * 删除定时任务 * @param orderId */ @Override public void deleteTask(Integer orderId){ //发送验证码短信 HttpHeaders headers = new HttpHeaders(); // 以表单的方式提交 headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); //将请求头部和参数合成一个请求 MultiValueMap params = new LinkedMultiValueMap<>(); params.add("orderId", orderId + ""); params.add("orderType", "2"); HttpEntity> requestEntity = new HttpEntity<>(params, headers); String s = internalRestTemplate.postForObject("http://driver-server/base/netty/deleteTask", requestEntity, String.class); JSONObject jsonObject = JSON.parseObject(s, JSONObject.class); if(jsonObject.getIntValue("code") != 200){ System.err.println("调用driver-server出错了"); } } /** * 获取用户余额和可用优惠券数量 * @param uid * @return * @throws Exception */ @Override public Map queryBalance(Integer orderId, Integer uid) throws Exception { Map map = new HashMap<>(); UserInfo userInfo = userInfoService.selectById(uid); map.put("balance", userInfo.getBalance()); OrderTaxi orderTaxi = this.selectById(orderId); int i = userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney()); i = i + userCouponRecordService.queryAvailable(uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney()); map.put("coupon", i); return map; } /** * 获取优惠券列表 * @param orderId * @return * @throws Exception */ @Override public List> queryCoupon(Integer language, Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); List> list = userCouponRecordService.queryCoupon(language, uid, orderTaxi.getCompanyId(), 1, 2, orderTaxi.getOrderMoney(), pageNum, size); List> list1 = userCouponRecordService.queryCoupon(language, uid, orderTaxi.getCompanyId(), 1, 0, orderTaxi.getOrderMoney(), pageNum, size); list.addAll(list1); return list; } /** * 订单完成支付订单操作 * @param payType 1=微信,2=支付宝,3=余额 * @param orderId * @return * @throws Exception */ @Override public ResultUtil payTaxiOrder(Integer payType, Integer orderId, Integer couponId, Integer type, Integer language) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); if(orderTaxi.getState() == 8 || orderTaxi.getState() == 9){ return ResultUtil.error("订单已完成支付,不允许重复支付"); } if(orderTaxi.getState() != 7){ return ResultUtil.error("订单不在待支付状态,不允许支付"); } Integer uid = orderTaxi.getUserId(); Double orderMoney = orderTaxi.getOrderMoney(); UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(); orderTaxi.setCouponMoney(0D);//初始化历史数据 orderTaxi.setCouponId(null); //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ userCouponRecord = userCouponRecordService.selectById(couponId); if(userCouponRecord.getCompanyId() != orderTaxi.getCompanyId()){ return ResultUtil.error("优惠券不能用于此订单"); } if(userCouponRecord.getState() == 2){ return ResultUtil.error("优惠券已使用"); } if(userCouponRecord.getState() == 3){ return ResultUtil.error("优惠券已过期"); } if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 2){ return ResultUtil.error("优惠券不能用于此类型订单"); } if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ return ResultUtil.error("优惠券不能用于此订单"); } orderMoney = orderMoney - userCouponRecord.getMoney(); orderTaxi.setCouponMoney(userCouponRecord.getMoney()); orderTaxi.setCouponId(couponId); } //计算红包 UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderTaxi.getCompanyId(), 1, 2, orderMoney); if(null != query && orderMoney.compareTo(query.getMoney()) > 0){ orderMoney = orderMoney - query.getMoney(); orderTaxi.setRedPacketMoney(query.getMoney()); orderTaxi.setRedPacketId(query.getId()); } //计算折扣 UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderTaxi.getCompanyId()); if(null != query2){ Double taxi = query2.getTaxi(); orderTaxi.setDiscount(taxi); double v = new BigDecimal(orderMoney).multiply(new BigDecimal(taxi / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); if(orderMoney.compareTo(v) > 0){ orderTaxi.setDiscountMoney(orderMoney - v); orderTaxi.setActivityId(query2.getId()); orderMoney = v; } } if(payType == 1){//微信支付 resultUtil = payMoneyUtil.weixinpay("完成订单",orderId +"",orderId + "_2_fei",orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); } if(payType == 2){//支付宝支付 resultUtil = payMoneyUtil.alipay("完成订单","完成订单",orderId + ",2",orderMoney+"","/base/aliPayOrderTaxi"); } if(payType == 3){//余额支付 if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant"); } userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(uid, "完成订单", orderMoney, 2, 1, 1, 2, orderId); userInfoService.updateById(userInfo); orderTaxi.setState(8); orderTaxi.setPayType(3); orderTaxi.setPayMoney(orderMoney); //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } if(null != query){ query.setState(2); query.setEndTime(new Date()); userRedPacketRecordService.updateById(query); } //添加已收入明细 Company company = companyService.selectById(orderTaxi.getCompanyId()); Double taxi = company.getTaxiMoney(); BigDecimal d = null;//企业收入 BigDecimal c = null;//司机收入 if(company.getIsTaxiFixedOrProportional() == 2){//固定 d = new BigDecimal(taxi); c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d);//只有出行金额参与抽成,其余归属司机 } if(company.getIsTaxiFixedOrProportional() == 1){//比例 d = new BigDecimal(orderTaxi.getTravelMoney()).multiply(new BigDecimal(taxi).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } incomeService.saveData(1, orderTaxi.getCompanyId(), 2, orderTaxi.getId(), 2, d.doubleValue()); incomeService.saveData(2, orderTaxi.getDriverId(), 2, orderTaxi.getId(), 2, c.doubleValue()); Driver driver = driverService.selectById(orderTaxi.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, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); } }).start(); //用户付款后,删除限制司机6分钟不能接单的标识 String vehicle = redisUtil.getValue("VEHICLE"); if(ToolUtil.isNotEmpty(vehicle)){ JSONArray jsonArray = JSON.parseArray(vehicle); for(int i = 0; i < jsonArray.size(); i++){ if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){ jsonArray.remove(i); break; } } redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString()); } systemNoticeService.addSystemNotice(1, "您已使用余额成功完成出行订单支付,谢谢使用!", uid, 1); } this.updateAllColumnById(orderTaxi); return resultUtil; } /** * 手动完成订单操作 * @param orderId * @param orderType * @return * @throws Exception */ @Override public ResultUtil completeOrder(Integer orderId, Integer orderType) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); if(orderTaxi.getState() != 7){ return ResultUtil.error("订单不在待支付,无法完成订单"); } orderTaxi.setPayManner(2);//其他方式支付 // orderTaxi.setOrderMoney(0D); // orderTaxi.setTravelMoney(0D); // orderTaxi.setParkMoney(0D); // orderTaxi.setRoadTollMoney(0D); orderTaxi.setRedPacketMoney(0D); orderTaxi.setCouponMoney(0D); orderTaxi.setDiscount(0D); orderTaxi.setDiscountMoney(0D); orderTaxi.setPayMoney(orderTaxi.getOrderMoney()); orderTaxi.setState(8); this.updateById(orderTaxi); new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); } }).start(); return ResultUtil.success(); } /** * 获取用户的订单列表 * @param uid * @param pageNum * @param size * @return * @throws Exception */ @Override public List> queryMyOrderList(Integer language, Integer uid, Integer pageNum, Integer size) throws Exception { pageNum = (pageNum - 1) * size; List> maps = orderTaxiMapper.queryMyOrderList(uid, pageNum, size); for(Map map : maps){ if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){ map.put("state", map.get("oldState")); } if(null != map.get("orderTime")){ String orderTime = map.get("orderTime").toString(); map.put("orderTime", DateUtil.conversionFormat(language, orderTime)); } if(null != map.get("time")){ String time = map.get("time").toString(); map.put("time", DateUtil.conversionFormat1(language, time)); } } return maps; } /** * 获取历史消费记录 * @param uid * @return * @throws Exception */ @Override public List> queryMyTravelRecord(Integer language, Integer uid) throws Exception { List> list = orderTaxiMapper.queryMyTravelRecord(uid); for (Map map : list) { if(null != map.get("time")){ String time = map.get("time").toString(); map.put("time", DateUtil.conversionFormat(language, time)); } } return list; } /** * 获取红包使用记录 * @param uid * @return * @throws Exception */ @Override public List> queryRedEnvelope(Integer language, Integer uid) throws Exception { List> list = orderTaxiMapper.queryRedEnvelope(uid); for (Map map : list) { if(null != map.get("time")){ String time = map.get("time").toString(); map.put("time", DateUtil.conversionFormat(language, time)); } } return list; } /** * 获取用户单发票页面的订单列表 * @param type 开票状态(1=未开票,2=已开票) * @param startTime 订单开始时间 * @param endTime 订单结束时间 * @param startMoney 订单金额范围 * @param endMoney * @param uid * @return * @throws Exception */ @Override public List> queryInvoiceOrder(Integer language, Integer type, Date startTime, Date endTime, Double startMoney, Double endMoney, Integer uid) throws Exception { startTime = dateUtil.getStartOrEndDate(startTime, "start"); endTime = dateUtil.getStartOrEndDate(endTime, "end"); List> list = orderTaxiMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid); for (Map map : list) { if(null != map.get("time")){ String time = map.get("time").toString(); map.put("time", DateUtil.conversionFormat(language, time)); } } return list; } /** * 获取订单详情 * @param orderId * @return */ @Override public Map queryOrderInfo(Integer language, Integer orderId) throws Exception{ Map map = orderTaxiMapper.queryOrderInfo(orderId); if(null != map && null != map.get("reassignNotice") && Integer.valueOf(String.valueOf(map.get("reassignNotice"))) == 2){//改派完成,重新获取了新的司机数据,开始修改数据防止继续调用 OrderTaxi orderTaxi = this.selectById(orderId); orderTaxi.setReassignNotice(0); this.updateById(orderTaxi); } if(Integer.valueOf(String.valueOf(map.get("state"))) == 11){ map.put("state", map.get("oldState")); } String driverId = redisUtil.getValue("DEVICE_" + map.get("driverId")); map.put("device", ToolUtil.isNotEmpty(driverId) ? 2 : 1); map.put("orderType", 2); if(null != map.get("insertTime")){ String insertTime = map.get("insertTime").toString(); map.put("insertTime", DateUtil.conversionFormat(language, insertTime)); } if(null != map.get("travelTime")){ String travelTime = map.get("travelTime").toString(); map.put("travelTime", DateUtil.conversionFormat1(language, travelTime)); } if(null != map.get("arriveTime")){ String arriveTime = map.get("arriveTime").toString(); map.put("arriveTime", DateUtil.conversionFormat(language, arriveTime)); } return map; } /** * 获取下单推送完后没有司机下单的提醒 * @return * @throws Exception */ @Override public EndPushWarpper queryEndPush(Integer uid) throws Exception { List list = orderTaxiMapper.queryByState(uid, 1); EndPushWarpper endPushWarpper = new EndPushWarpper(); if(list.size() > 0){ OrderTaxi orderTaxi = list.get(0); if(!orderIds.contains(orderTaxi.getId())){ endPushWarpper.setOrderId(orderTaxi.getId()); endPushWarpper.setOrderType(2); endPushWarpper.setState(1); List querys = pushOrderService.querys(null, 2, orderTaxi.getCompanyId());//获取需要推送的次数 int time = 0; for(int i = 1; i <= querys.size(); i++){ PushOrder pushOrder = pushOrderService.querys(i, 2, orderTaxi.getCompanyId()).get(0); time += pushOrder.getPushTime() * 1000; } //当前时间减去推单总时间大于下单时间 if((System.currentTimeMillis() - time) > orderTaxi.getInsertTime().getTime()){ endPushWarpper.setState(2); } } } return endPushWarpper; } /** * 获取服务中的订单数据 * @param uid * @return * @throws Exception */ @Override public OrderServerWarpper queryOrderServer(Integer orderId, Integer uid) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); //计算预计距离和剩余时间 String value = redisUtil.getValue("DRIVER" + String.valueOf(orderTaxi.getDriverId())); if(null == value || "".equals(value)){ System.err.println("司机没有上传位置信息"); //调用获取轨迹中的数据 List> list = orderPositionService.queryTrack(orderId, 2); if(list.size() > 0){ Map map = list.get(list.size() - 1); value = map.get("lon") + "," + map.get("lat"); } } Map distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(), 1); String d = "0"; String t = "0"; if(null == distance){ System.err.println("查询距离出错了"); }else{ d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString(); t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + ""; } OrderServerWarpper orderServerWarpper = new OrderServerWarpper(); orderServerWarpper.setOrderId(orderTaxi.getId()); orderServerWarpper.setOrderType(2); orderServerWarpper.setState(orderTaxi.getState()); orderServerWarpper.setLon(null != value ? value.split(",")[0] : "0.0"); orderServerWarpper.setLat(null != value ? value.split(",")[1] : "0.0"); orderServerWarpper.setReassignNotice(orderTaxi.getReassignNotice()); if(orderTaxi.getState() == 2 || orderTaxi.getState() == 3){//前往预约地 orderServerWarpper.setReservationMileage(d); orderServerWarpper.setReservationTime(t); orderServerWarpper.setServedMileage("0"); orderServerWarpper.setServedTime("0"); orderServerWarpper.setLaveMileage("0"); orderServerWarpper.setLaveTime("0"); } if(orderTaxi.getState() == 5 || orderTaxi.getState() == 6){//服务中 distance = gdMapElectricFenceUtil.getDistance(value, orderTaxi.getEndLon() + "," + orderTaxi.getEndLat(), 1); if(null == distance){ System.err.println("查询距离出错了"); }else{ d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString(); t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + ""; } orderServerWarpper.setReservationMileage("0"); orderServerWarpper.setReservationTime("0"); orderServerWarpper.setServedMileage(String.valueOf(orderTaxi.getMileage() / 1000)); orderServerWarpper.setServedTime(Long.valueOf((new Date().getTime() - orderTaxi.getStartServiceTime().getTime()) / 60000).intValue() + ""); orderServerWarpper.setLaveMileage(d); orderServerWarpper.setLaveTime(t); } return orderServerWarpper; } /** * 评论成功后获取红包金额 * @param orderId * @return * @throws Exception */ @Override public synchronized ResultUtil queryRedMoney(Integer orderId) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); Integer companyId = orderTaxi.getCompanyId(); Map query = userActivityRedenvelopeService.query(companyId, orderTaxi.getTravelTime()); Double money = 0D; if(null != query){ Integer type = Integer.valueOf(String.valueOf(query.get("type"))); if(type == 1){//固定金额 money = Double.valueOf(String.valueOf(query.get("money"))); }else{//随机金额 Double startMoney = Double.valueOf(String.valueOf(query.get("startMoney"))); Double endMoney = Double.valueOf(String.valueOf(query.get("endMoney"))); money = new BigDecimal(startMoney + (Math.random() * (endMoney - startMoney))).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); } } BaseWarpper baseWarpper = new BaseWarpper(); //判断当前红包是否大于剩余可领取总金额 if(money.compareTo(Double.valueOf(query.get("lavePrice").toString())) > 0){ baseWarpper.setAmount(0D); return ResultUtil.success(baseWarpper); } baseWarpper.setAmount(money); if(money > 0){ //添加临时红包数据 UserRedPacketRecord userRedPacketRecord = new UserRedPacketRecord(); userRedPacketRecord.setMoney(money); userRedPacketRecord.setRemainingAmount(money); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(String.valueOf(query.get("effective")))); userRedPacketRecord.setInsertTime(new Date()); userRedPacketRecord.setCompanyId(Integer.valueOf(String.valueOf(query.get("companyId")))); userRedPacketRecord.setState(0); userRedPacketRecord.setOrderId(orderTaxi.getId()); userRedPacketRecord.setOrderType(2); userRedPacketRecord.setUserId(orderTaxi.getUserId()); userRedPacketRecordService.insert(userRedPacketRecord); } return ResultUtil.success(baseWarpper); } /** * 分享成功后添加红包 * @param orderId * @return * @throws Exception */ @Override public synchronized ResultUtil shareRedEnvelope(Integer orderId) throws Exception { OrderTaxi orderTaxi = this.selectById(orderId); UserRedPacketRecord query = userRedPacketRecordService.query_(orderTaxi.getUserId(), orderTaxi.getCompanyId(), 0, 2, null); if(null != query){ Double money = query.getMoney(); Map map = userActivityRedenvelopeService.query(orderTaxi.getCompanyId(), orderTaxi.getTravelTime()); Double laveMoney = Double.valueOf(String.valueOf(map.get("laveMoney"))); if(money.compareTo(laveMoney) > 0){ return ResultUtil.error("手速太慢了,红包已派发完啦!"); } //判断当前红包是否大于剩余可领取总金额 if(money.compareTo(Double.valueOf(map.get("lavePrice").toString())) > 0){ return ResultUtil.error("手速太慢了,红包已派发完啦!"); } double v = new BigDecimal(laveMoney).subtract(new BigDecimal(money)).doubleValue(); UserActivityRedenvelope id = userActivityRedenvelopeService.selectById(String.valueOf(map.get("id"))); id.setLaveMoney(v); id.setLavePrice(new BigDecimal(id.getLavePrice() - money).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); userActivityRedenvelopeService.updateById(id); query.setState(1); query.setRedPacketActivityId(id.getId()); userRedPacketRecordService.updateById(query); } return ResultUtil.success(); } /** * 获取订单数据 * @param uid * @param state * @return * @throws Exception */ @Override public List queryOrder(Integer uid, Integer... state) throws Exception { List list = orderTaxiMapper.queryByState(uid, state); return list; } /** * 订单支付完成后的处理 * @param id 订单=id * @param order_id 工行支付单号 * @param type 1=微信,2=支付宝 * @throws Exception */ @Override public void payOrderTaxiCallback(Integer id, String order_id, Integer type) throws Exception { OrderTaxi orderTaxi = this.selectById(id); PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 2, type, 1); if(null != query){ //添加交易明细 transactionDetailsService.saveData(orderTaxi.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId()); orderTaxi.setState(8); orderTaxi.setPayType(type); orderTaxi.setPayMoney(query.getAmount()); this.updateById(orderTaxi); UserInfo userInfo = userInfoService.selectById(orderTaxi.getUserId()); SysIntegral query1 = sysIntegralMapper.query(orderTaxi.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分 userInfoService.updateById(userInfo); //处理优惠券和红包 if(null != orderTaxi.getCouponId()){ UserCouponRecord userCouponRecord = userCouponRecordService.selectById(orderTaxi.getCouponId()); userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } if(null != orderTaxi.getRedPacketId()){ UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderTaxi.getRedPacketId()); userRedPacketRecord.setState(2); userRedPacketRecord.setEndTime(new Date()); userRedPacketRecordService.updateById(userRedPacketRecord); } query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); //添加已收入明细 Company company = companyService.selectById(orderTaxi.getCompanyId()); Double taxi = company.getTaxiMoney(); BigDecimal d = null;//企业收入 BigDecimal c = null;//司机收入 if(company.getIsTaxiFixedOrProportional() == 2){//固定 d = new BigDecimal(taxi); c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } if(company.getIsTaxiFixedOrProportional() == 1){//比例 d = new BigDecimal(orderTaxi.getTravelMoney()).multiply(new BigDecimal(taxi).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); c = new BigDecimal(orderTaxi.getOrderMoney()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } incomeService.saveData(1, orderTaxi.getCompanyId(), 2, orderTaxi.getId(), 2, d.doubleValue()); incomeService.saveData(2, orderTaxi.getDriverId(), 2, orderTaxi.getId(), 2, c.doubleValue()); Driver driver = driverService.selectById(orderTaxi.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, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0, "", "user"); } }).start(); //用户付款后,删除限制司机6分钟不能接单的标识 String vehicle = redisUtil.getValue("VEHICLE"); if(ToolUtil.isNotEmpty(vehicle)){ JSONArray jsonArray = JSON.parseArray(vehicle); for(int i = 0; i < jsonArray.size(); i++){ if(jsonArray.getInteger(i).compareTo(orderTaxi.getDriverId()) == 0){ jsonArray.remove(i); break; } } redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString()); } systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成出行订单支付,谢谢使用!", orderTaxi.getUserId(), 1); }else{ System.err.println("预支付数据异常(orderId = " + id + ")"); } } /** * 取消订单支付后的处理 * @param id 订单=id * @param order_id 工行支付单号 * @param type 1=微信,2=支付宝 * @throws Exception */ @Override public void payCancelOrderTaxi(Integer id, String order_id, Integer type) throws Exception { OrderTaxi orderTaxi = this.selectById(id); PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 2, type, 1); if(null != query){ //添加交易明细 transactionDetailsService.saveData(orderTaxi.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 2, query.getOrderId()); orderTaxi.setState(10); //解除小号绑定 if(orderTaxi.getBindId() != null){ chinaMobileUtil.midAxbUnBindSend(orderTaxi.getBindId(),orderTaxi.getTelX()); } orderTaxi.setBindId(""); orderTaxi.setTelX(""); this.updateById(orderTaxi); query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); OrderCancel query1 = orderCancelService.query(query.getOrderId(), query.getOrderType(), query.getAmount(), query.getPayType(), 1); if (null != query1){ query1.setState(2); orderCancelService.updateById(query1); } //添加已收入明细 incomeService.saveData(1, orderTaxi.getCompanyId(), 3, orderTaxi.getId(), 2, query.getAmount()); this.deleteTask(orderTaxi.getId());//删除定时任务 // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 // new Thread(new Runnable() { // @Override // public void run() { // pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState(), 0); // } // }).start(); //添加消息 systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功支付取消订单费用,谢谢使用!", orderTaxi.getUserId(), 1); }else{ System.err.println("预支付数据异常(orderId = " + id + ")"); } } /** * 推送订单给司机抢单 * @param orderTaxi * @throws Exception */ public void pushOrder(OrderTaxi orderTaxi) throws Exception{ new Thread(new Runnable() { @Override public void run() { try { orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单 String vehicle = redisUtil.getValue("VEHICLE"); List integers = new ArrayList<>(); if(ToolUtil.isNotEmpty(vehicle)){ integers = JSON.parseArray(vehicle).toJavaList(Integer.class); } Company query = companyCityService.query1(orderTaxi.getUserId(), String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));//获取起点所属分公司 List querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数 for(int i = 1; i <= querys.size(); i++){ PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0); //获取空闲司机 List list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 if(list.size() > 0){ double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) list = list.subList(0, lastIndex);//获取空闲司机中占比数据 for(Driver driver : list){//开始进行推送 //查询是否在限制推单范围内 boolean bo = false; for(Integer integer : integers){ if(integer.compareTo(driver.getId()) == 0){ bo = true; break; } } if(bo){ continue; } pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime(), "", "user"); } } Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间 Integer state = orderTaxiMapper.selectById(orderTaxi.getId()).getState(); if(state > 1){ break; } if(i == querys.size() && state == 1){ pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2); orderIds.remove(orderTaxi.getId()); } } } catch (Exception e) { e.printStackTrace(); } } }).start(); } @Override public synchronized String getOrderNum() throws Exception{ int size = this.selectCount(null); return "TAXI" + String.valueOf(1000000 + size + 1).substring(1); } }