package com.stylefeng.guns.modular.smallLogistics.server.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.common.constant.state.BalanceChangeType; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.account.controller.AppOrderController; import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper; import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; import com.stylefeng.guns.modular.smallLogistics.dao.OrderLogisticsMapper; import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics; import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService; import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.system.dao.*; 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.warpper.BaseWarpper; import com.stylefeng.guns.modular.system.warpper.CouponsListVo; import com.stylefeng.guns.modular.system.warpper.DriverInfoWarpper; import com.stylefeng.guns.modular.system.warpper.PreferentialDataVo; 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.IPaymentRecordService; import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @Service public class OrderLogisticsServiceImpl extends ServiceImpl implements IOrderLogisticsService { @Resource private SystemPriceMapper systemPriceMapper; @Resource private OrderLogisticsMapper orderLogisticsMapper; @Resource private SensitiveWordsMapper sensitiveWordsMapper; @Autowired private ICompanyCityService companyCityService; @Autowired private GDMapGeocodingUtil gdMapGeocodingUtil; @Autowired private DateUtil dateUtil; @Autowired private ISystemNoticeService systemNoticeService; @Autowired private IPushOrderService pushOrderService; @Autowired private IDriverService driverService; @Autowired private PushUtil pushUtil; @Autowired private IUserInfoService userInfoService; @Autowired private IPaymentRecordService paymentRecordService; @Resource private SysIntegralMapper sysIntegralMapper; @Autowired private ITransactionDetailsService transactionDetailsService; @Autowired private ICompanyService companyService; @Autowired private IIncomeService incomeService; @Autowired private IOrderCancelService orderCancelService; @Autowired private IOrderLogisticsSpreadService orderLogisticsSpreadService; @Resource private RedisTemplate redisTemplate; @Resource private RegionMapper regionMapper; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private PayMoneyUtil payMoneyUtil; @Autowired private CbyzxOrderPayHelper cbyzxOrderPayHelper; @Resource private OrderPrivateCarMapper orderPrivateCarMapper; @Resource private OrderCrossCityMapper orderCrossCityMapper; @Resource private OrderTaxiMapper orderTaxiMapper; @Autowired private IOpenCityService openCityService; @Autowired private ITaxiCardPaymentService taxiCardPaymentService; @Autowired private IUserCouponRecordService userCouponRecordService; @Autowired private ITaxiCardService taxiCardService; @Autowired private IUserUserService userUserService; @Autowired private IUserTaxiCardService userTaxiCardService; @Autowired private IRegionService regionService; @Value("${callbackPath}") private String callbackPath; private static List orderIds = new ArrayList<>(); /** * 根据起点和终点坐标判断是不是同一个市内 * @param startLonLat * @param endAddress * @return */ @Override public ResultUtil judgingTheCity(String startLonLat, String endAddress) throws Exception { Map sgeocode = gdMapGeocodingUtil.geocode(startLonLat.split(",")[0], startLonLat.split(",")[1]); String scityCode = sgeocode.get("cityCode"); Map geocoding = gdMapGeocodingUtil.geocoding(endAddress); if(Integer.valueOf(geocoding.get("status").toString()) != 0){ return ResultUtil.error("收货地址有误,无法查询具体地址信息"); } List list = (List)geocoding.get("data"); Map egeocode = gdMapGeocodingUtil.geocode(list.get(0).split(",")[0], list.get(0).split(",")[1]); String ecityCode = egeocode.get("cityCode"); if(!scityCode.equals(ecityCode)){ return ResultUtil.error("已超出服务范围,请重新选择跨城小件物流"); } return ResultUtil.success(); } /** * 获取小件物流的单价 * @param type * @param startLonLat * @param endAddress * @return * @throws Exception */ @Override public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer uid) throws Exception { Company query = companyCityService.query(startLonLat.split(",")[0], startLonLat.split(",")[1]); if(null == query){ return ResultUtil.error("预约取货点暂无企业服务"); } Double price1 = 0D; Double price2 = 0D; if(type == 4){//同城 Map query1 = systemPriceMapper.query(query.getId(), type, null, null); if(null == query1){ return ResultUtil.error("请先完善价格设定"); } String content = String.valueOf(query1.get("content")); JSONObject jsonObject = JSON.parseObject(content); price1 = jsonObject.getDouble("num2"); price2 = jsonObject.getDouble("num13"); }else{ Map query1 = systemPriceMapper.query(query.getId(), type, null, null); if(null == query1){ return ResultUtil.error("请先完善价格设定"); } String content = String.valueOf(query1.get("content")); JSONObject jsonObject = JSON.parseObject(content); price1 = jsonObject.getDouble("num1"); price2 = jsonObject.getDouble("num2"); } int i = this.selectCount(new EntityWrapper().eq("userId", uid).eq("isDelete", 1)); Map map = new HashMap<>(); map.put("ordinary", price1); map.put("precious", price2); map.put("first", i); return ResultUtil.success(map); } /** * 获取支付金额 * @param type * @param startLonLat * @param endAddress * @return * @throws Exception */ public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endAddress) throws Exception{ Map geocoding = gdMapGeocodingUtil.geocoding(endAddress); if(Integer.valueOf(geocoding.get("status").toString()) != 0){ return ResultUtil.error("收货地址有误,无法查询具体地址信息"); } String location = ((List)geocoding.get("data")).get(0); ResultUtil> price = this.getPrice(null, type, startLonLat.split(",")[0], startLonLat.split(",")[1], location.split(",")[0], location.split(",")[1]); if(price.getCode() == 200 && type == 5){ Map data = price.getData(); data.put("ordinary", data.get("ordinary") * number); data.put("precious", data.get("precious") * number); } return price; } /** * 小件物流下单操作 * @param type * @param cargoType * @param cargoNumber * @param remark * @param placementLon * @param placementLat * @param startLon * @param startLat * @param startAddress * @param recipient * @param recipientPhone * @param endAddress * @param travelTime * @param orderSource * @param uid * @return * @throws Exception */ @Override public ResultUtil smallLogistics(Integer type, Integer cargoType, Integer cargoNumber, String remark, String placementLon, String placementLat, String startLon, String startLat, String startAddress, String recipient, String recipientPhone, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, Integer uid) throws Exception { /** * 1.出租车、专车、跨城有待支付的订单不能叫车 * 2.小件物流有未完成的订单可以下跨城、专车、出租车 * 3.出租车、专车、跨城有预约单可以下即时单 */ List orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12); if(orderPrivateCars.size() > 0){ return ResultUtil.error("有未完成的订单"); } List list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12); if(list.size() > 0){ return ResultUtil.error("有未完成的订单"); } List orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12); if(orderCrossCities1.size() > 0){ return ResultUtil.error("有未完成的订单"); } startAddress = startAddress.replaceAll("& #40;", "("); startAddress = startAddress.replaceAll("& #41;", ")"); endAddress = endAddress.replaceAll("& #40;", "("); endAddress = endAddress.replaceAll("& #41;", ")"); OrderLogistics orderLogistics = new OrderLogistics(); Company query = companyCityService.query(placementLon, placementLat); if(null == query){ return ResultUtil.error("该地点暂无企业服务"); } orderLogistics.setCompanyId(query.getId()); orderLogistics.setType(type); orderLogistics.setUserId(uid); orderLogistics.setOrderNum(this.getOrderNum()); orderLogistics.setCargoType(cargoType); orderLogistics.setCargoNumber(cargoNumber); orderLogistics.setRemark(remark); orderLogistics.setPlacementLon(Double.valueOf(placementLon)); orderLogistics.setPlacementLat(Double.valueOf(placementLat)); Map geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat); orderLogistics.setPlacementAddress(geocode.get("address")); orderLogistics.setStartLon(Double.valueOf(startLon)); orderLogistics.setStartLat(Double.valueOf(startLat)); orderLogistics.setStartAddress(startAddress); Map geocoding = gdMapGeocodingUtil.geocoding(endAddress); if(Integer.valueOf(geocoding.get("status").toString()) != 0){ return ResultUtil.error("收货地址有误,无法查询具体地址信息"); } if(((List)geocoding.get("data")).size() == 0){ return ResultUtil.error("无法查询具体地址信息"); } String location = ((List)geocoding.get("data")).get(0); orderLogistics.setEndLon(Double.valueOf(location.split(",")[0])); orderLogistics.setEndLat(Double.valueOf(location.split(",")[1])); orderLogistics.setEndAddress(endAddress); orderLogistics.setUrgent(urgent); orderLogistics.setRecipient(recipient); orderLogistics.setRecipientPhone(recipientPhone); orderLogistics.setMileage(0D); orderLogistics.setIsReassign(1); orderLogistics.setReassignNotice(0); ResultUtil> price = this.getPrice(null, type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]); if(price.getCode() != 200){ return price; } Map data = price.getData(); orderLogistics.setOrderMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) + tipMoney); orderLogistics.setTravelMoney(cargoType == 1 ? data.get("ordinary") : data.get("precious")); if(type == 5){ orderLogistics.setOrderMoney(((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber) + tipMoney); orderLogistics.setTravelMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber); } orderLogistics.setTipMoney(tipMoney); orderLogistics.setState(7);//待支付 orderLogistics.setInsertTime(new Date()); orderLogistics.setTravelTime(travelTime); orderLogistics.setOrderSource(orderSource); orderLogistics.setIsDelete(1); this.insert(orderLogistics); //添加消息 systemNoticeService.addSystemNotice(1, "您的"+ (type == 4 ? "同城" : "跨城") + "小件物流订单已下单成功,我们正在为您指派司机,请稍后!", orderLogistics.getUserId(), 1); BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setId(orderLogistics.getId()); return ResultUtil.success(baseWarpper); } @Override public ResultUtil smallLogistics1(String arriveTime, Integer type, Integer cargoType, Integer cargoNumber, String remark, String placementLon, String placementLat, String startLon, String startLat, String startAddress, String recipient, String recipientPhone, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, String userImg, Integer uid) throws Exception { /** * 1.出租车、专车、跨城有待支付的订单不能叫车 * 2.小件物流有未完成的订单可以下跨城、专车、出租车 * 3.出租车、专车、跨城有预约单可以下即时单 */ List orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12); if(orderPrivateCars.size() > 0){ return ResultUtil.error("有未完成的订单"); } List list = orderTaxiMapper.queryByState_(uid, null, 1, 1, 2, 3, 4, 5, 6, 7, 11, 12); if(list.size() > 0){ return ResultUtil.error("有未完成的订单"); } List orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12); if(orderCrossCities1.size() > 0){ return ResultUtil.error("有未完成的订单"); } startAddress = startAddress.replaceAll("& #40;", "("); startAddress = startAddress.replaceAll("& #41;", ")"); endAddress = endAddress.replaceAll("& #40;", "("); endAddress = endAddress.replaceAll("& #41;", ")"); Map geocoding = gdMapGeocodingUtil.geocoding(endAddress); if(Integer.valueOf(geocoding.get("status").toString()) != 0){ return ResultUtil.error("收货地址有误,无法查询具体地址信息"); } if(((List)geocoding.get("data")).size() == 0){ return ResultUtil.error("无法查询具体地址信息"); } String location = ((List)geocoding.get("data")).get(0); OrderLogistics orderLogistics = new OrderLogistics(); Company query = companyCityService.query(placementLon, placementLat); if(null == query){ return ResultUtil.error("该地点暂无企业服务"); } // TODO: 2023/11/4 无法修改 Map distance = gdMapElectricFenceUtil.getDistance(startLon + "," + startLat, location, 1); double distance1 = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); Map query1 = systemPriceMapper.query(query.getId(), type, null, null); if(null != query1){ if(type == 4){ JSONObject jsonObject = JSON.parseObject(query1.get("content").toString()); if(cargoType == 1){//普通 Double num10 = jsonObject.getDouble("num10"); if(distance1 > num10){ return ResultUtil.error("距离已超出服务距离"); } } if(cargoType == 2){//贵重 Double num21 = jsonObject.getDouble("num21"); if(distance1 > num21){ return ResultUtil.error("距离已超出服务距离"); } } } } orderLogistics.setCompanyId(query.getId()); orderLogistics.setType(type); orderLogistics.setUserId(uid); orderLogistics.setOrderNum(this.getOrderNum()); orderLogistics.setCargoType(cargoType); orderLogistics.setCargoNumber(cargoNumber); orderLogistics.setUserImg(userImg); orderLogistics.setRemark(remark); orderLogistics.setPlacementLon(Double.valueOf(placementLon)); orderLogistics.setPlacementLat(Double.valueOf(placementLat)); Map geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat); orderLogistics.setPlacementAddress(geocode.get("address")); orderLogistics.setStartLon(Double.valueOf(startLon)); orderLogistics.setStartLat(Double.valueOf(startLat)); orderLogistics.setStartAddress(startAddress); orderLogistics.setEndLon(Double.valueOf(location.split(",")[0])); orderLogistics.setEndLat(Double.valueOf(location.split(",")[1])); orderLogistics.setEndAddress(endAddress); orderLogistics.setUrgent(urgent); orderLogistics.setRecipient(recipient); orderLogistics.setRecipientPhone(recipientPhone); orderLogistics.setMileage(0D); orderLogistics.setIsReassign(1); orderLogistics.setReassignNotice(0); ResultUtil> price = this.getPrice(distance1, type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]); if(price.getCode() != 200){ return price; } Map data = price.getData(); orderLogistics.setOrderMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) + tipMoney); orderLogistics.setTravelMoney(cargoType == 1 ? data.get("ordinary") : data.get("precious")); if(type == 5){ orderLogistics.setOrderMoney(((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber) + tipMoney); orderLogistics.setTravelMoney((cargoType == 1 ? data.get("ordinary") : data.get("precious")) * cargoNumber); } orderLogistics.setTipMoney(tipMoney); orderLogistics.setState(7);//待支付 orderLogistics.setInsertTime(new Date()); orderLogistics.setTravelTime(travelTime); orderLogistics.setOrderSource(orderSource); orderLogistics.setIsDelete(1); /// 新增预计送达时间 if (ToolUtil.isNotEmpty(arriveTime)){ orderLogistics.setArriveTimeExpect(DateUtil.getDate(arriveTime, "yyyy-MM-dd HH:mm:ss")); } /// 生成取件码 String random = ""; for(int i = 0; i < 6; i++){ random += Double.valueOf(Math.random() * 10).intValue(); } orderLogistics.setPickUpCode(random); this.insert(orderLogistics); //添加消息 systemNoticeService.addSystemNotice(1, "您的"+ (type == 4 ? "同城" : "跨城") + "小件物流订单已下单成功,我们正在为您指派司机,请稍后!", orderLogistics.getUserId(), 1); BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setId(orderLogistics.getId()); return ResultUtil.success(baseWarpper); } /** * 获取价格 * @param type * @return * @throws Exception */ public ResultUtil> getPrice(Double dist, Integer type, String startLon, String startLat, String endLon, String endLat) throws Exception{ Company query = companyCityService.query(startLon, startLat); if(null == query){ return ResultUtil.error("预约取货点暂无企业服务"); } Double price1 = 0D; Double price2 = 0D; if(type == 4){//同城 Map query1 = systemPriceMapper.query(query.getId(), type, null, null); // TODO: 2023/11/4 已优化 if(null == dist){ Map distance = gdMapElectricFenceUtil.getDistance(startLon + "," + startLat, endLon + "," + endLat, 1); String distance1 = distance.get("distance"); dist = Double.valueOf(distance1) / 1000; } String content = String.valueOf(query1.get("content")); JSONObject jsonObject = JSON.parseObject(content); if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num1")) < 0){ price1 = jsonObject.getDouble("num2"); } if(dist.compareTo(0D) >= 0 && dist.compareTo(jsonObject.getDouble("num12")) < 0){ price2 = jsonObject.getDouble("num13"); } if(dist.compareTo(jsonObject.getDouble("num3")) >= 0 && dist.compareTo(jsonObject.getDouble("num4")) < 0){ price1 = jsonObject.getDouble("num5"); } if(dist.compareTo(jsonObject.getDouble("num14")) >= 0 && dist.compareTo(jsonObject.getDouble("num15")) < 0){ price2 = jsonObject.getDouble("num16"); } if(dist.compareTo(jsonObject.getDouble("num6")) >= 0 && dist.compareTo(jsonObject.getDouble("num7")) < 0){ price1 = jsonObject.getDouble("num8"); } if(dist.compareTo(jsonObject.getDouble("num17")) >= 0 && dist.compareTo(jsonObject.getDouble("num18")) < 0){ price2 = jsonObject.getDouble("num19"); } if(dist.compareTo(jsonObject.getDouble("num9")) >= 0 && dist.compareTo(jsonObject.getDouble("num10")) < 0){ price1 = jsonObject.getDouble("num11"); } if(dist.compareTo(jsonObject.getDouble("num10")) >= 0){ price1 = jsonObject.getDouble("num11"); } if(dist.compareTo(jsonObject.getDouble("num20")) >= 0 && dist.compareTo(jsonObject.getDouble("num21")) < 0){ price2 = jsonObject.getDouble("num22"); } if(dist.compareTo(jsonObject.getDouble("num21")) >= 0){ price2 = jsonObject.getDouble("num22"); } }else{ Map query1 = systemPriceMapper.query(query.getId(), type, null, null); String content = String.valueOf(query1.get("content")); JSONObject jsonObject = JSON.parseObject(content); price1 = jsonObject.getDouble("num1"); price2 = jsonObject.getDouble("num2"); } Map map = new HashMap<>(); map.put("ordinary", price1);//普通 map.put("precious", price2);//贵重 return ResultUtil.success(map); } /** * 推送抢单数据 * @param orderLogistics * @throws Exception */ public void pushOrder(OrderLogistics orderLogistics) throws Exception{ new Thread(new Runnable() { @Override public void run() { try { Integer id = orderLogistics.getId(); orderIds.add(orderLogistics.getId());//添加记录,防止调用接口重复提醒无人接单 String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE"); List integers = new ArrayList<>(); if(ToolUtil.isNotEmpty(vehicle)){ integers = JSON.parseArray(vehicle).toJavaList(Integer.class); } OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); List querys = pushOrderService.querys(null, 1, openCity.getId());//用专车的推单配置 for(int i = 1; i <= querys.size() + 15; i++){ // OrderLogistics orderLogistics = orderLogisticsMapper.selectById(id); // if (null == orderLogistics || orderLogistics.getState() > 1) { // break; // } int finalI = i; PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); int i2 = pushOrder.getPushTime() / 10; if(i2==0){ i2=1; } for (int i1 = 0; i1 < i2 ; i1++) { OrderLogistics orderLogistics1 = orderLogisticsMapper.selectById(id); if (orderLogistics1.getState() > 1) { break; } //获取匹配的司机 List list = driverService.queryIdleDriver1(orderLogistics.getType(), orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 if (list.size() > 0) { double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) lastIndex = lastIndex == 0 ? list.size() : lastIndex; 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(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), pushOrder.getPushTime()); } } Thread.sleep(10000);//设置等待时间 Integer state = orderLogistics.getState(); if (state > 1) { orderIds.remove(orderLogistics.getId()); return; } if (i == querys.size() + 15 && state == 1) { orderIds.remove(orderLogistics.getId()); } } } } catch (Exception e) { e.printStackTrace(); } } }).start(); } /** * 订单支付 * @param payType * @param orderId * @param type * @return * @throws Exception */ @Override public ResultUtil payLogisticsOrder(Integer payType, Integer orderId, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); if(orderLogistics.getState() != 7){ return ResultUtil.error("订单已完成支付,不允许重复支付", ""); } Integer uid = orderLogistics.getUserId(); Double orderMoney = orderLogistics.getOrderMoney(); UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(new Object()); if(payType == 1){//微信支付 String outTradeNo = orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); } String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; resultUtil = ResultUtil.success(response); paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, paymentCode, 1);//添加预支付数据 } if(payType == 2){//支付宝支付 resultUtil = payMoneyUtil.alipay("小件物流下单支付", "小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, "", 1);//添加预支付数据 } if(payType == 3){//余额支付 if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ return ResultUtil.error("余额不足,无法完成支付", ""); } userInfo.setBalanceChangeType(BalanceChangeType.CONSUME.getCode()); userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流下单", orderMoney, 2, 1, 1, 4, orderId); userInfoService.updateById(userInfo); orderLogistics.setState(1);//小件物流先支付后司机抢单 orderLogistics.setPayType(3); orderLogistics.setPayMoney(orderMoney); // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单支付,谢谢使用!", uid, 1); this.pushOrder(orderLogistics);//推单 } this.updateById(orderLogistics); return resultUtil; } @Override public ResultUtil payLogisticsOrder1(Integer payType, Integer orderId, Integer objectId, Integer objectType, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); if(orderLogistics.getState() != 7){ return ResultUtil.error("订单已完成支付,不允许重复支付", ""); } Integer uid = orderLogistics.getUserId(); Double orderMoney = orderLogistics.getOrderMoney(); UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(new Object()); orderLogistics.setCouponMoney(0D);//初始化历史数据 orderLogistics.setCouponId(null); //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != objectId && objectType == 1){ userCouponRecord = userCouponRecordService.selectById(objectId); if(userCouponRecord.getCompanyId() != orderLogistics.getCompanyId()){ return ResultUtil.error("优惠券不能用于此订单", ""); } if(userCouponRecord.getState() == 2){ return ResultUtil.error("优惠券已使用", ""); } if(userCouponRecord.getState() == 3){ return ResultUtil.error("优惠券已过期", ""); } if(userCouponRecord.getCouponUseType() != 0){ return ResultUtil.error("优惠券不能用于此类型订单", ""); } if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ return ResultUtil.error("优惠券不能用于此订单", ""); } orderMoney = orderMoney - userCouponRecord.getMoney(); orderLogistics.setCouponMoney(userCouponRecord.getMoney()); orderLogistics.setCouponId(objectId); } //打车卡 UserTaxiCard userTaxiCard = null; if(null != objectId && objectType == 2){ userTaxiCard = userTaxiCardService.selectById(objectId); TaxiCard taxiCard = taxiCardService.selectById(userTaxiCard.getTaxiCardId()); if(taxiCard.getTaxiCardType() == 1 && userTaxiCard.getCompanyId() != orderLogistics.getCompanyId()){ return ResultUtil.error("打车卡不能用于此订单", ""); } if(System.currentTimeMillis() > userTaxiCard.getEndTime().getTime()){ return ResultUtil.error("打车卡已过期", ""); } List integers = JSON.parseObject(userTaxiCard.getContent()).getJSONArray("businessTypes").toJavaList(Integer.class); if(!integers.contains(orderLogistics.getType())){ return ResultUtil.error("打车卡不能用于此类型订单", ""); } Double yh = 0D; JSONObject jsonObject = JSON.parseObject(userTaxiCard.getContent()); if(userTaxiCard.getType() == 5){//{"businessTypes":[4,5],"discount":5} Double discount = jsonObject.getDouble("discount"); yh = new BigDecimal(orderLogistics.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); } orderMoney = orderMoney - yh; orderLogistics.setTaxiCardId(userTaxiCard.getTaxiCardId()); orderLogistics.setUserTaxiCardId(objectId); orderLogistics.setDiscountAmount(yh); } orderMoney = orderMoney < 0 ? 0 : orderMoney; orderMoney =new BigDecimal(orderMoney).setScale(2,RoundingMode.HALF_UP).doubleValue(); if(payType == 1){//微信支付 if(orderMoney == 0){ return ResultUtil.error("请使用余额支付"); } String outTradeNo = orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); } String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; resultUtil = ResultUtil.success(response); paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, paymentCode, 1);//添加预支付数据 } if(payType == 2){//支付宝支付 if(orderMoney == 0){ return ResultUtil.error("请使用余额支付"); } resultUtil = payMoneyUtil.alipay("小件物流下单支付", "小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, "", 1);//添加预支付数据 } if(payType == 3){//余额支付 if (userInfo.getBalance() == null || userInfo.getBalance() < orderMoney) { return ResultUtil.error("余额不足,无法完成支付"); } // if(orderMoney>0) { // resultUtil = appOrderController.moneyPay(orderId, userInfo.getId(), orderMoney); // if (resultUtil.getCode() == 500) { // return ResultUtil.error("电子余额不足,无法完成支付"); // } // } userInfo.setBalanceChangeType(BalanceChangeType.CONSUME.getCode()); userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流下单", orderMoney, 2, 1, 1, 4, orderId); userInfoService.updateById(userInfo); orderLogistics.setState(1);//小件物流先支付后司机抢单 orderLogistics.setPayType(3); orderLogistics.setPayMoney(orderMoney); //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } //处理打车卡 if(null != userTaxiCard){ userTaxiCardService.updateById(userTaxiCard); } //添加已收入明细(司机端完成后添加) // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单支付,谢谢使用!", uid, 1); this.pushOrder(orderLogistics);//推单 }else if(payType == 4){ if(orderMoney == 0){ return ResultUtil.error("请使用余额支付"); } Double payMoney = orderLogistics.getOrderMoney(); Integer integer = paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 4, orderMoney, "", 1);//添加预支付数据 resultUtil = appOrderController.placeAnOrder(new BigDecimal(orderMoney), 4,orderId,5,integer); } this.updateById(orderLogistics); return resultUtil; } @Autowired private AppOrderController appOrderController; /** * 补差价支付 * @param payType * @param orderId * @param type * @return * @throws Exception */ @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public ResultUtil payLogisticsOrder_(Integer payType, Integer orderId, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); Integer uid = orderLogistics.getUserId(); OrderLogisticsSpread orderLogisticsSpread = orderLogisticsSpreadService.selectOne(new EntityWrapper().eq("orderLogisticsId", orderId)); Double orderMoney = orderLogisticsSpread.getPrice(); UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(new Object()); if(payType == 1){//微信支付 String outTradeNo = "SPREAD_" + orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); } String recordCode = cbyzxOrderPayHelper.extractRecordCode(response); String paymentCode = ToolUtil.isNotEmpty(recordCode) ? recordCode : outTradeNo; paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, paymentCode, 1);//添加预支付数据 resultUtil = ResultUtil.success(response); } if(payType == 2){//支付宝支付 resultUtil = payMoneyUtil.alipay("小件物流补差价", "小件物流补差价", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderLogisticsSpread"); paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 2, orderMoney, "", 1);//添加预支付数据 } if(payType == 3) {//余额支付 if (userInfo.getBalance() == null || userInfo.getBalance() < orderMoney) { return ResultUtil.error("余额不足,无法完成支付"); } // resultUtil= appOrderController.moneyPay(orderId,userInfo.getId(),orderMoney); // if(resultUtil.getCode()==500){ // return ResultUtil.error("电子余额不足,无法完成支付"); // } userInfo.setBalanceChangeType(BalanceChangeType.CONSUME.getCode()); userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流补差价", orderMoney, 2, 1, 1, 4, orderId); userInfoService.updateById(userInfo); orderLogistics.setState(12);//已支付差价 this.updateById(orderLogistics); orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + orderMoney); orderLogistics.setTravelMoney(orderLogistics.getTravelMoney() + orderMoney); orderLogistics.setPayMoney(orderLogistics.getPayMoney() + orderMoney); orderLogisticsSpread.setPayMoney(orderMoney); orderLogisticsSpread.setPayTime(new Date()); orderLogisticsSpread.setPayType(3); orderLogisticsSpreadService.updateById(orderLogisticsSpread); //添加已收入明细 Company company = companyService.selectById(orderLogistics.getCompanyId()); Double speMoney = orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney(); BigDecimal d = null; BigDecimal c = null; if(company.getIsSpeFixedOrProportional() == 2){//固定 d = new BigDecimal(speMoney.compareTo(orderMoney) > 0 ? orderMoney : speMoney); c = new BigDecimal(orderMoney).subtract(d); } if(company.getIsSpeFixedOrProportional() == 1){//比例 d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100)), new MathContext(2, RoundingMode.HALF_EVEN)); c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } Income income = incomeService.selectOne(new EntityWrapper().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType())); income.setMoney(income.getMoney() + d.doubleValue()); incomeService.updateById(income); income = incomeService.selectOne(new EntityWrapper().eq("userType", 2).eq("objectId", orderLogistics.getDriverId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType())); income.setMoney(income.getMoney() + c.doubleValue()); incomeService.updateById(income); Driver driver = driverService.selectById(orderLogistics.getDriverId()); driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); systemNoticeService.addSystemNotice(1, "您已使用余额成功完成小件物流订单差价支付,谢谢使用!", uid, 1); } if(payType==4){ Integer integer = paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 4, orderMoney, "", 1); resultUtil = appOrderController.placeAnOrder(new BigDecimal(orderMoney), 4,orderId,13,integer); } this.updateById(orderLogistics); return resultUtil; } @Override public void payOrderLogisticsCallback(Integer id, String order_id, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(id); PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, Integer.valueOf(id), orderLogistics.getType(), type, 1); if(null != query){ //添加交易明细 transactionDetailsService.saveData(orderLogistics.getUserId(), (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流下单", query.getAmount(), 2, 1, 1, orderLogistics.getType(), query.getOrderId()); orderLogistics.setState(1);//先支付后抢单 orderLogistics.setPayType(type); orderLogistics.setPayMoney(query.getAmount()); this.updateById(orderLogistics); UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分 userInfoService.updateById(userInfo); //处理优惠券和红包 if(null != orderLogistics.getCouponId()){ UserCouponRecord userCouponRecord = userCouponRecordService.selectById(orderLogistics.getCouponId()); userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } //处理打车卡 if(null != orderLogistics.getUserTaxiCardId()){ UserTaxiCard userTaxiCard = userTaxiCardService.selectById(orderLogistics.getUserTaxiCardId()); } query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); //添加已收入明细(司机端完成后添加) // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : (type==2?"支付宝":"云闪付")) + "成功完成小件物流订单支付,谢谢使用!", orderLogistics.getUserId(), 1); this.pushOrder(orderLogistics);//推单 }else{ System.err.println("预支付数据异常(orderId = " + id + ")"); } } @Override public void payOrderLogisticsSpreadCallback(Integer id, String order_id, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(id); OrderLogisticsSpread orderLogisticsSpread = orderLogisticsSpreadService.selectOne(new EntityWrapper().eq("orderLogisticsId", id)); PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, Integer.valueOf(id), orderLogistics.getType(), type, 1); if(null != query){ //添加交易明细 transactionDetailsService.saveData(orderLogistics.getUserId(), (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流补差价", query.getAmount(), 2, 1, 1, 4, query.getOrderId()); orderLogistics.setState(12);//待取货 orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + query.getAmount()); orderLogistics.setTravelMoney(orderLogistics.getTravelMoney() + query.getAmount()); orderLogistics.setPayMoney(orderLogistics.getPayMoney() + query.getAmount()); orderLogisticsSpread.setPayMoney(query.getAmount()); orderLogisticsSpread.setPayTime(new Date()); orderLogisticsSpread.setPayType(3); orderLogisticsSpreadService.updateById(orderLogisticsSpread); UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分 userInfoService.updateById(userInfo); query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); //添加已收入明细 Company company = companyService.selectById(orderLogistics.getCompanyId()); Double speMoney = orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney(); BigDecimal d = BigDecimal.ZERO; BigDecimal c = BigDecimal.ZERO; if(company.getIsSpeFixedOrProportional() == 2){//固定 d = new BigDecimal(speMoney); c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } if(company.getIsSpeFixedOrProportional() == 1){//比例 d = new BigDecimal(query.getAmount()).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100)), new MathContext(2, RoundingMode.HALF_EVEN)); c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); } // Income income = incomeService.selectOne(new EntityWrapper().eq("userType", 1).eq("objectId", orderLogistics.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType())); // income.setMoney(income.getMoney() + d.doubleValue()); // incomeService.updateById(income); // income = incomeService.selectOne(new EntityWrapper().eq("userType", 2).eq("objectId", orderLogistics.getDriverId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType())); // income.setMoney(income.getMoney() + c.doubleValue()); // incomeService.updateById(income); Driver driver = driverService.selectById(orderLogistics.getDriverId()); driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信": (type==2?"支付宝":"云闪付")) + "成功完成小件物流订单差价支付,谢谢使用!", orderLogistics.getUserId(), 1); this.updateById(orderLogistics); }else{ System.err.println("预支付数据异常(orderId = " + id + ")"); } } /** * 获取首页订单数量 * @param uid * @return * @throws Exception */ @Override public int queryLogisticsNumber(Integer uid) throws Exception { return orderLogisticsMapper.queryLogisticsNumber(uid); } /** * 获取个人中心订单列表 * @param uid * @param pageNum * @param size * @return * @throws Exception */ @Override public List> queryMyOrderList(Integer uid, Integer type, Integer pageNum, Integer size) throws Exception { pageNum = (pageNum - 1) * size; List> maps = orderLogisticsMapper.queryMyOrderList(uid, type, pageNum, size); return maps; } /** * 获取历史消费记录 * @param uid * @return */ @Override public List> queryMyTravelRecord(Integer uid) { return orderLogisticsMapper.queryMyTravelRecord(uid); } @Override public List> queryInvoiceOrder(Integer type, Date startTime, Date endTime, Double startMoney, Double endMoney, Integer uid, Integer orderType) throws Exception { startTime = dateUtil.getStartOrEndDate(startTime, "start"); endTime = dateUtil.getStartOrEndDate(endTime, "end"); return orderLogisticsMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid, orderType); } @Override public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception { if(ToolUtil.isNotEmpty(remark)){ if(ToolUtil.isNotEmpty(remark)){ List sensitiveWords = sensitiveWordsMapper.selectList(null); for(SensitiveWords s : sensitiveWords){ remark = remark.replaceAll(s.getContent(), "***"); } } } OrderLogistics orderLogistics = this.selectById(id); Integer integer = null; if(null == orderLogistics){ return ResultUtil.error("取消订单失败,订单信息有误"); } if(orderLogistics.getState() >= 5 && orderLogistics.getState() != 7 && orderLogistics.getState() != 8 && orderLogistics.getState() != 11){ return ResultUtil.error("订单已取消,请刷新页面"); } if(orderLogistics.getState() == 7){ integer = orderCancelService.saveData(orderLogistics.getId(), orderLogistics.getType(), reason, remark, null, null, 2, 1, orderLogistics.getUserId()); orderLogistics.setState(10); this.updateById(orderLogistics); //添加消息 systemNoticeService.addSystemNotice(1, "您已成功取消小件物流订单,谢谢使用!", orderLogistics.getUserId(), 1); Map map = new HashMap<>(); map.put("id", integer); return ResultUtil.success(map); } // 回退优惠券 Integer couponId = orderLogistics.getCouponId(); //回退支付金额 if(null != orderLogistics.getPayType() && null != orderLogistics.getPayMoney()) {//已支付 if(orderLogistics.getPayType() == 3){//余额支付 UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); userInfo.setBalanceChangeType(BalanceChangeType.REFUND.getCode()); userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney()); userInfoService.updateById(userInfo); appOrderController.createAllocationReqUser(1, orderLogistics.getUserId(), 1,orderLogistics.getPayMoney()); UserCouponRecord userCouponRecord = userCouponRecordService.selectById(couponId); userCouponRecord.setState(1); userCouponRecordService.updateById(userCouponRecord); orderLogistics.setCouponMoney(0.00); }else{ //调用回退接口 PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getPayType(), 2); System.out.println(query); boolean b = false; System.out.println("支付方式:"+query.getPayType()); if(query.getPayType() == 1){//微信 Map map = payMoneyUtil.wxRefund(query.getCode(), orderLogistics.getId() + "_" + orderLogistics.getType(), query.getAmount().toString(), query.getAmount().toString(), "/base/cancleOrderWXPay"); System.out.println("map:"+map); if(!"SUCCESS".equals(map.get("return_code"))){ return ResultUtil.error(map.get("return_msg")); } } if(query.getPayType()==4){ UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); userInfo.setBalanceChangeType(BalanceChangeType.REFUND.getCode()); userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney()); userInfoService.updateById(userInfo); appOrderController.createAllocationReqUser(1, orderLogistics.getUserId(), 1,orderLogistics.getPayMoney()); // 退款 System.out.println("云闪付退款"); UserCouponRecord userCouponRecord = userCouponRecordService.selectById(couponId); userCouponRecord.setState(1); userCouponRecordService.updateById(userCouponRecord); orderLogistics.setCouponMoney(0.00); // TODO 设置优惠券id回滚 // orderLogistics.setCouponId(null); }else if(query.getPayType()==2){//支付宝 Map map = payMoneyUtil.aliRefund(query.getCode(), query.getAmount().toString()); UserCouponRecord userCouponRecord = userCouponRecordService.selectById(couponId); userCouponRecord.setState(1); userCouponRecordService.updateById(userCouponRecord); orderLogistics.setCouponMoney(0.00); if(!"10000".equals(map.get("code"))){ return ResultUtil.error(map.get("msg")); } } // Map merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), orderLogistics.getId() + "_" + orderLogistics.getType(), orderLogistics.getOrderNum()); // if (Integer.valueOf(merrefund.get("code").toString()) == 0) { // Map refundqry = icbcPayUtil.refundqry("", query.getCode(), orderLogistics.getOrderNum()); // if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 0) {//成功 // b = true; // } // if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 1) {//失败 // return ResultUtil.error("订单取消失败(退款不成功)"); // } // if (Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 2) {//未知 // return ResultUtil.error("退款返回未知异常"); // // } // } if(b){ } } //添加交易明细 transactionDetailsService.saveData(orderLogistics.getUserId(), (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId()); integer = orderCancelService.saveData(orderLogistics.getId(), orderLogistics.getType(), reason, remark, null, null, 2, 1, orderLogistics.getUserId()); orderLogistics.setState(10); this.updateById(orderLogistics); //添加负的收入明细 // List incomes = incomeService.selectList(new EntityWrapper().eq("type", 2).eq("incomeId", id).eq("orderType", orderLogistics.getType())); // for(Income income : incomes){ // if(income.getUserType() == 2){//处理司机的收入 // Driver driver = driverService.selectById(income.getObjectId()); // driver.setBalance(driver.getBalance() - income.getMoney()); // driver.setBusinessMoney(driver.getBusinessMoney() - income.getMoney()); // driver.setLaveBusinessMoney(driver.getLaveBusinessMoney() - income.getMoney()); // driverService.updateById(driver); // } // Income income1 = new Income(); // BeanUtils.copyProperties(income, income1); // income1.setMoney(income.getMoney() * -1); // income1.setId(null); // income1.setInsertTime(new Date()); // incomeService.insert(income1); // } } if(null != orderLogistics.getDriverId()){ new Thread(new Runnable() { @Override public void run() { pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); } //添加消息 systemNoticeService.addSystemNotice(1, "您已成功取消小件物流订单,谢谢使用!", orderLogistics.getUserId(), 1); Map map = new HashMap<>(); map.put("id", integer); return ResultUtil.success(map); } /** * 获取行政区域数据 * @return * @throws Exception */ @Override public Map queryRegion() throws Exception { Map map = new HashMap<>(); List querys = regionMapper.querys(0); Map map1 = new HashMap<>(); Map map2 = new HashMap<>(); Map map3 = new HashMap<>(); for(Region region : querys){ map1.put(Integer.valueOf(region.getCode()), region.getName()); List querys1 = regionMapper.querys(region.getId()); for(Region region1 : querys1){ map2.put(Integer.valueOf(region1.getCode()), region1.getName()); List querys2 = regionMapper.querys(region1.getId()); for(Region region2 : querys2) { map3.put(Integer.valueOf(region2.getCode()), region2.getName()); } } } map.put("province_list", map1); map.put("city_list", map2); map.put("county_list", map3); return map; } /** * 获取行政区域 * @param parentId * @return * @throws Exception */ @Override public List queryRegions(Integer parentId) throws Exception { return regionMapper.querys(parentId); } @Override public Map queryBalance(Integer orderId, Integer uid) throws Exception { Map map = new HashMap<>(); UserInfo userInfo = userInfoService.selectById(uid); map.put("balance", userInfo.getBalance()); map.put("coupon", 0); return map; } @Resource private UserActivityDiscount1Mapper userActivityDiscount1Mapper; @Autowired private IUserRedPacketRecordService userRedPacketRecordService; @Override public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception { UserInfo userInfo = userInfoService.selectById(uid); PreferentialDataVo preferentialDataVo = new PreferentialDataVo(); preferentialDataVo.setBalance(userInfo.getBalance()); OrderLogistics orderLogistics = this.selectById(orderId); Integer ids = userInfoService.getDiscount(); if(ids!=null){ List userActivityId = userActivityDiscount1Mapper.selectList(new EntityWrapper().eq("userActivityId", ids)); if(userActivityId.size()>0){ preferentialDataVo.setDiscount(userActivityId.get(0).getLogistics()); } } // 查出当前用户的红包 并将订单的修改 List userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper().eq("userId", uid).eq("state", 1).le("money",orderLogistics.getOrderMoney()).gt("expirationTime", new Date()).gt("endTime", new Date())); if(userRedPacketRecords.size()>0){ preferentialDataVo.setRedPacket(userRedPacketRecords.get(0).getMoney()); orderLogistics.setRedPacketId(userRedPacketRecords.get(0).getId()); orderLogistics.setRedPacketMoney(userRedPacketRecords.get(0).getMoney()); this.updateById(orderLogistics); } //获取优惠券中最优数据 List list = userCouponRecordService.selectList(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("state", 1).le("money",orderLogistics.getOrderMoney()).in("couponUseType", Arrays.asList(0)).eq("userId", uid).where("now() < expirationTime")); Integer id = null; Double price = 0d; Integer type = 0; for (UserCouponRecord userCouponRecord : list){ if(userCouponRecord.getCouponType() == 1){//抵扣券 if(price.compareTo(userCouponRecord.getMoney()) < 0){ price = userCouponRecord.getMoney(); id = userCouponRecord.getId(); type = 1; } }else{//满减券 if(orderLogistics.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) >= 0 && price.compareTo(userCouponRecord.getMoney()) < 0){ price = userCouponRecord.getMoney(); id = userCouponRecord.getId(); type = 1; } } } //获取打车卡中最优数 Map geocode = gdMapGeocodingUtil.geocode(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); if(null == companyCity){ companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); } if(null == companyCity){ companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); } List userTaxiCards = userTaxiCardService.selectList(new EntityWrapper().like("companyCityId", "%" + companyCity.getId() + "%") .in("type", Arrays.asList(5)).eq("userId", uid).where("now() between startTime and endTime")); //全国卡 List taxiCards = taxiCardService.selectList(new EntityWrapper().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1)); if(taxiCards.size() > 0) { List userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper().eq("userId", uid) .in("type", Arrays.asList(5)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); userTaxiCards.addAll(userTaxiCards2); } Map map = getOptimalTaxiCards(orderLogistics, price, id, type, userTaxiCards); price = Double.valueOf(map.get("price").toString()); id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null; type = Integer.valueOf(map.get("type").toString()); //亲密账户 List userTaxiCards_ = new ArrayList<>(); List bindUserId = userUserService.selectList(new EntityWrapper().eq("bindUserId", uid)); CompanyCity finalCompanyCity = companyCity; bindUserId.forEach(userUser -> { List userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper().in("type", Arrays.asList(5)) .like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime")); userTaxiCards_.addAll(userTaxiCards1); //全国卡 if(taxiCards.size() > 0) { List userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper().eq("userId", userUser.getUserId()) .in("type", Arrays.asList(5)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); userTaxiCards_.addAll(userTaxiCards2); } }); map = getOptimalTaxiCards(orderLogistics, price, id, type, userTaxiCards_); price = Double.valueOf(map.get("price").toString()); id = null != map.get("id") ? Integer.valueOf(map.get("id").toString()) : null; type = Integer.valueOf(map.get("type").toString()); if(price<=orderLogistics.getOrderMoney() || type==2){ preferentialDataVo.setObjectId(id); preferentialDataVo.setDiscountAmount(price); preferentialDataVo.setType(type); } return preferentialDataVo; } public Map getOptimalTaxiCards(OrderLogistics orderLogistics, Double price, Integer id, Integer type, List userTaxiCards) throws Exception{ Map map = new HashMap<>(); for(UserTaxiCard t : userTaxiCards){ if(t.getType() != 5){//物流打折卡{"businessTypes":[4,5],"discount":5} continue; } JSONObject jsonObject = JSON.parseObject(t.getContent()); List integers = jsonObject.getJSONArray("businessTypes").toJavaList(Integer.class); if(!integers.contains(orderLogistics.getType())){ continue; } Double discount = jsonObject.getDouble("discount"); double v = new BigDecimal(orderLogistics.getOrderMoney()).multiply(new BigDecimal((10 - discount) / 10)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); if(price.compareTo(v) < 0){ price = v; id = t.getId(); type = 2; } } map.put("price", price); map.put("id", id); map.put("type", type); return map; } @Override public List queryByState(Integer uid, Integer... state) throws Exception { return this.baseMapper.queryByState(uid, state); } @Override public List queryCouponList(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { pageNum = (pageNum - 1) * size; OrderLogistics orderLogistics = this.selectById(orderId); List rows = new ArrayList<>(); List list = userCouponRecordService.selectList(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()) .eq("state", 1).in("couponUseType", Arrays.asList(0)).eq("userId", uid).where("expirationTime >= now()")); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (UserCouponRecord userCouponRecord : list){ if(userCouponRecord.getCouponType() == 2){//满减券 if(orderLogistics.getOrderMoney().compareTo(userCouponRecord.getFullMoney()) < 0){ continue; } } CouponsListVo couponsListVo = new CouponsListVo(); couponsListVo.setId(userCouponRecord.getId()); couponsListVo.setDataType(1); couponsListVo.setMoney(userCouponRecord.getMoney()); couponsListVo.setUserType(userCouponRecord.getCouponUseType()); couponsListVo.setTime(sdf.format(userCouponRecord.getExpirationTime())); couponsListVo.setType(userCouponRecord.getCouponType()); couponsListVo.setFullMoney(userCouponRecord.getFullMoney()); couponsListVo.setState(userCouponRecord.getState()); Company company = companyService.selectById(userCouponRecord.getCompanyId()); couponsListVo.setCompany(company.getName()); rows.add(couponsListVo); } Map geocode = gdMapGeocodingUtil.geocode(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); if(null == companyCity){ companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); } if(null == companyCity){ companyCity = companyCityService.selectOne(new EntityWrapper().eq("companyId", orderLogistics.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); } List userTaxiCards = userTaxiCardService.selectList(new EntityWrapper().eq("userId", uid) .in("type", Arrays.asList(5)).like("companyCityId", "%" + companyCity.getId() + "%").where("now() between startTime and endTime")); //全国卡 List taxiCards = taxiCardService.selectList(new EntityWrapper().eq("taxiCardType", 2).in("type", Arrays.asList(5)).eq("state", 1)); if(taxiCards.size() > 0) { List userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper().eq("userId", uid) .in("type", Arrays.asList(5)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); userTaxiCards.addAll(userTaxiCards1); } //亲密账户 List bindUserId = userUserService.selectList(new EntityWrapper().eq("bindUserId", uid)); CompanyCity finalCompanyCity = companyCity; bindUserId.forEach(userUser -> { List taxiCardPayments1 = userTaxiCardService.selectList(new EntityWrapper().in("type", Arrays.asList(5)) .like("companyCityId", "%" + finalCompanyCity.getId() + "%").eq("userId", userUser.getUserId()).where("now() between startTime and endTime")); userTaxiCards.addAll(taxiCardPayments1); //全国卡 if(taxiCards.size() > 0) { List userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper().eq("userId", userUser.getUserId()) .in("type", Arrays.asList(5)).in("taxiCardId", taxiCards.stream().map(TaxiCard::getId).collect(Collectors.toList())).where("now() between startTime and endTime")); userTaxiCards.addAll(userTaxiCards1); } }); for(UserTaxiCard t : userTaxiCards){ try { CouponsListVo couponsListVo = new CouponsListVo(); couponsListVo.setId(t.getId()); couponsListVo.setDataType(2); couponsListVo.setUserType(1); couponsListVo.setTime(sdf.format(t.getEndTime())); couponsListVo.setState(1); couponsListVo.setTaxiCardType(t.getType()); Company company = companyService.selectById(t.getCompanyId()); couponsListVo.setCompany(company.getName()); couponsListVo.setName(taxiCardService.selectById(t.getTaxiCardId()).getName()); JSONObject jsonObject = JSON.parseObject(t.getContent()); JSONArray businessTypes = jsonObject.getJSONArray("businessTypes"); if(!businessTypes.toJavaList(Integer.class).contains(orderLogistics.getType())){ continue; } if(t.getType() == 5){//{"businessTypes":[4,5],"discount":5} couponsListVo.setMoney(jsonObject.getDouble("discount")); couponsListVo.setType(1); } String str = ""; TaxiCard taxiCard = taxiCardService.selectById(t.getTaxiCardId()); if(taxiCard.getTaxiCardType() == 1){ String[] split = taxiCard.getCompanyCityId().split(";"); for(String c : split){ CompanyCity companyCity1 = companyCityService.selectById(c); if(ToolUtil.isNotEmpty(companyCity1.getAreaCode())){ Region region = regionService.selectOne(new EntityWrapper().eq("code", companyCity1.getAreaCode())); str += region.getName() + ";"; continue; } if(ToolUtil.isNotEmpty(companyCity1.getCityCode())){ Region region = regionService.selectOne(new EntityWrapper().eq("code", companyCity1.getCityCode())); str += region.getName() + ";"; continue; } if(ToolUtil.isNotEmpty(companyCity1.getProvinceCode())){ Region region = regionService.selectOne(new EntityWrapper().eq("code", companyCity1.getProvinceCode())); str += region.getName() + ";"; continue; } } }else{ str = "全国;"; } couponsListVo.setCity(str.substring(0, str.length() - 1)); rows.add(couponsListVo); }catch (Exception e){ e.printStackTrace(); } } Collections.sort(rows, new Comparator() { public int compare(CouponsListVo s1, CouponsListVo s2) { return Integer.compare(s1.getId(), s2.getId()); } }); if(rows.size() >= (pageNum + 1) * size){ rows = rows.subList(pageNum, pageNum + size); }else if(pageNum < rows.size() && rows.size() < (pageNum + 1) * size){ rows = rows.subList(pageNum, rows.size()); }else{ rows = new ArrayList<>(); } rows = rows.stream().filter(e->e.getMoney()<=orderLogistics.getOrderMoney()|| e.getDataType()==2).collect(Collectors.toList()); return rows; } public synchronized String getOrderNum() throws Exception{ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); return "LO" + sdf.format(new Date()) + UUIDUtil.getRandomCode(5); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception { UserInfo userInfo = userInfoService.selectById(uid); OrderLogistics orderLogistics = this.selectById(orderId); ResultUtil resultUtil = ResultUtil.success(); if(payType == 1){//微信支付 String outTradeNo = "THANK_" + orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, money); if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); } String recordCode = cbyzxOrderPayHelper.extractRecordCode(response); String paymentCode = ToolUtil.isNotEmpty(recordCode) ? recordCode : outTradeNo; paymentRecordService.saveData(3, uid, 1, orderId, orderLogistics.getType(), 1, money, paymentCode, 1);//添加预支付数据 resultUtil = ResultUtil.success(response); } if(payType == 2){//支付宝支付 resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee"); paymentRecordService.saveData(1, uid, 1, orderId, orderLogistics.getType(), 2, money, "", 1);//添加预支付数据 } if(payType == 3) {//余额支付 if (userInfo.getBalance() == null || userInfo.getBalance() < money) { return ResultUtil.error("余额不足,无法完成支付"); } // resultUtil= appOrderController.moneyPay(orderId,userInfo.getId(),money); // if(resultUtil.getCode()==500){ // return ResultUtil.error("电子余额不足,无法完成支付"); // } userInfo.setBalanceChangeType(BalanceChangeType.CONSUME.getCode()); userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城小件物流-" : "跨城小件物流-") + "感谢费", money, 2, 1, 1, orderLogistics.getType(), orderId); userInfoService.updateById(userInfo); orderLogistics.setThankYouFee(money); this.updateById(orderLogistics); //添加已收入明细 incomeService.saveData(2, orderLogistics.getDriverId(), 6, orderLogistics.getId(), orderLogistics.getType(), money); Driver driver = driverService.selectById(orderLogistics.getDriverId()); driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1); } if(payType==4){ Double payMoney = orderLogistics.getThankYouFee(); Integer integer = paymentRecordService.saveData(1, uid, 1, orderId, orderLogistics.getType(), 4, money, "", 1); resultUtil = appOrderController.placeAnOrder(new BigDecimal(money), 4,orderId,10,integer); } return resultUtil; } @Override public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); PaymentRecord query = paymentRecordService.query(3, userInfo.getId(), 1, orderId, orderLogistics.getType(), payType, 1); query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); OpenCity openCity = openCityService.openCity1(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); SysIntegral query1 = sysIntegralMapper.query(openCity.getId()); userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分 //添加交易明细 transactionDetailsService.saveData(userInfo.getId(), (orderLogistics.getType() == 4 ? "同城小件物流-" : "跨城小件物流-") + "感谢费", query.getAmount(), 2, 1, 1, orderLogistics.getType(), orderId); userInfoService.updateById(userInfo); orderLogistics.setThankYouFee(query.getAmount()); this.updateById(orderLogistics); //添加已收入明细 incomeService.saveData(2, orderLogistics.getDriverId(), 6, orderLogistics.getId(), orderLogistics.getType(), query.getAmount()); Driver driver = driverService.selectById(orderLogistics.getDriverId()); driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(query.getAmount())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : (payType==2?"支付宝":"云闪付")) + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1); } @Override public List getUnpayLogisticsOrders(Integer uid) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.eq("userId", uid); wrapper.eq("state", 7); List orderLogisticsList = this.selectList(wrapper); List unPayOrderVOList = new ArrayList<>(); for (OrderLogistics orderLogistics:orderLogisticsList) { UnPayOrderVO unPayOrderVO = new UnPayOrderVO(); //添加司机信息 DriverInfoWarpper driverInfoWarpper = new DriverInfoWarpper(); Driver driver = driverService.selectById(orderLogistics.getDriverId()); BeanUtils.copyProperties(driver, driverInfoWarpper); unPayOrderVO.setDriverInfoWarpper(driverInfoWarpper); //其余信息 BeanUtils.copyProperties(orderLogistics, unPayOrderVO); unPayOrderVOList.add(unPayOrderVO); } return unPayOrderVOList; } }