From 75a2623173bcc4a235aa1f99f7ef28519186160b Mon Sep 17 00:00:00 2001 From: yanghb <yanghb> Date: 星期五, 21 四月 2023 11:24:25 +0800 Subject: [PATCH] 代码调整 --- UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java | 831 +++++----------------------------------------------------- 1 files changed, 79 insertions(+), 752 deletions(-) diff --git a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java index bf9ab20..d99d38d 100644 --- a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java +++ b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java @@ -1,22 +1,15 @@ 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.util.ToolUtil; -import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper; -import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; -import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService; 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.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.dao.RegionMapper; import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper; import com.stylefeng.guns.modular.system.dao.SysIntegralMapper; @@ -25,12 +18,7 @@ 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.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.IOrderTaxiService; import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; import org.springframework.beans.BeanUtils; @@ -40,10 +28,8 @@ import javax.annotation.Resource; import java.math.BigDecimal; -import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; -import java.util.stream.Collectors; @Service @@ -117,36 +103,6 @@ @Autowired private PayMoneyUtil payMoneyUtil; - - @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; @@ -272,24 +228,6 @@ @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<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12); - if(orderPrivateCars.size() > 0){ - return ResultUtil.error("有未完成的订单"); - } - List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12); - if(list.size() > 0){ - return ResultUtil.error("有未完成的订单"); - } - List<OrderCrossCity> 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;", "("); @@ -357,106 +295,6 @@ 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<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12); - if(orderPrivateCars.size() > 0){ - return ResultUtil.error("有未完成的订单"); - } - List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12); - if(list.size() > 0){ - return ResultUtil.error("有未完成的订单"); - } - List<OrderCrossCity> 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.setUserImg(userImg); - orderLogistics.setRemark(remark); - orderLogistics.setPlacementLon(Double.valueOf(placementLon)); - orderLogistics.setPlacementLat(Double.valueOf(placementLat)); - Map<String, String> geocode = gdMapGeocodingUtil.geocode(placementLon, placementLat); - orderLogistics.setPlacementAddress(geocode.get("address")); - orderLogistics.setStartLon(Double.valueOf(startLon)); - orderLogistics.setStartLat(Double.valueOf(startLat)); - orderLogistics.setStartAddress(startAddress); - Map<String, Object> geocoding = gdMapGeocodingUtil.geocoding(endAddress); - if(Integer.valueOf(geocoding.get("status").toString()) != 0){ - return ResultUtil.error("收货地址有误,无法查询具体地址信息"); - } - if(((List<String>)geocoding.get("data")).size() == 0){ - return ResultUtil.error("无法查询具体地址信息"); - } - String location = ((List<String>)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<Map<String, Double>> price = this.getPrice(type, String.valueOf(startLon), String.valueOf(startLat), location.split(",")[0], location.split(",")[1]); - if(price.getCode() != 200){ - return price; - } - Map<String, Double> 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(com.stylefeng.guns.core.util.DateUtil.parseTime(arriveTime)); - } - - /// 生成取件码 - 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); - } /** * 获取价格 @@ -540,12 +378,11 @@ List<PushOrder> querys = pushOrderService.querys(null, 1, query.getId());//用专车的推单配置 for(int i = 1; i <= querys.size(); i++){ PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0); - //获取匹配的司机 - List<Driver> list = driverService.queryIdleDriver1(orderLogistics.getType(), orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 + //获取空闲司机 + List<Driver> list = driverService.queryIdleDriver(orderLogistics.getType(), null, 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; @@ -567,6 +404,7 @@ break; } if(i == querys.size() && state == 1){ +// pushUtil.pushEndPush(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType()); orderIds.remove(orderLogistics.getId()); } } @@ -592,25 +430,40 @@ public ResultUtil payLogisticsOrder(Integer payType, Integer orderId, Integer type) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); if(orderLogistics.getState() != 7){ - return ResultUtil.error("订单已完成支付,不允许重复支付", ""); + return ResultUtil.error("订单已完成支付,不允许重复支付"); } Integer uid = orderLogistics.getUserId(); Double orderMoney = orderLogistics.getOrderMoney(); UserInfo userInfo = userInfoService.selectById(uid); - ResultUtil resultUtil = ResultUtil.success(new Object()); + ResultUtil resultUtil = ResultUtil.success(); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String out_trade_no = sdf.format(new Date()) + orderLogistics.getType() + orderLogistics.getId(); if(payType == 1){//微信支付 - String app = type == 1 ? "APP" : "JSAPI"; - resultUtil = payMoneyUtil.weixinpay("小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), callbackPath + "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); - paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据 + String appletsOpenId = ""; + String tradeType = "APP"; + if(type == 3){ + appletsOpenId = userInfo.getAppletsOpenId(); + tradeType = "JSAPI"; + if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ + return ResultUtil.error("支付异常,请重新授权登录小程序"); + } + } + resultUtil = payMoneyUtil.weixinpay("完成订单", "", out_trade_no, orderMoney.toString(), callbackPath + "/base/wxPayOrderTaxi", tradeType, appletsOpenId); + if(resultUtil.getCode() == 200){ + paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 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);//添加预支付数据 + resultUtil = payMoneyUtil.alipay("订单完成支付", "支付订单", out_trade_no, orderMoney.toString(), callbackPath + "/base/aliPayOrderTaxi"); + if(resultUtil.getCode() == 200){ + 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("余额不足,无法完成支付", ""); + return ResultUtil.error("余额不足,无法完成支付"); } userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); @@ -619,7 +472,7 @@ userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 - transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流下单", orderMoney, 2, 1, 1, 4, orderId); + transactionDetailsService.saveData(uid, "小件物流下单支付", orderMoney, 2, 1, 1, 4, orderId); userInfoService.updateById(userInfo); orderLogistics.setState(1);//小件物流先支付后司机抢单 @@ -643,135 +496,8 @@ 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<Integer> 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; - if(payType == 1){//微信支付 - if(orderMoney == 0){ - return ResultUtil.error("请使用余额支付"); - } - String app = type == 1 ? "APP" : "JSAPI"; - resultUtil = payMoneyUtil.weixinpay("小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), callbackPath + "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); - paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 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("余额不足,无法完成支付", ""); - } - - userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); - - SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); - 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);//推单 - } - - this.updateById(orderLogistics); - return resultUtil; - } /** * 补差价支付 @@ -788,20 +514,35 @@ OrderLogisticsSpread orderLogisticsSpread = orderLogisticsSpreadService.selectOne(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", orderId)); Double orderMoney = orderLogisticsSpread.getPrice(); UserInfo userInfo = userInfoService.selectById(uid); - ResultUtil resultUtil = ResultUtil.success(new Object()); + ResultUtil resultUtil = ResultUtil.success(); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String out_trade_no = sdf.format(new Date()) + orderLogistics.getType() + orderId; if(payType == 1){//微信支付 - String app = type == 1 ? "APP" : "JSAPI"; - resultUtil = payMoneyUtil.weixinpay("小件物流补差价", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), callbackPath + "/base/wxPayOrderLogisticsSpread", app, userInfo.getAppletsOpenId()); - paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据 + String appletsOpenId = ""; + String tradeType = "APP"; + if(type == 3){ + appletsOpenId = userInfo.getAppletsOpenId(); + tradeType = "JSAPI"; + if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ + return ResultUtil.error("支付异常,请重新授权登录小程序"); + } + } + resultUtil = payMoneyUtil.weixinpay("小件物流补差价", "", out_trade_no, orderMoney.toString(), callbackPath + "/base/wxPayOrderLogisticsSpread", tradeType, appletsOpenId); + if(resultUtil.getCode() == 200){ + paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据 + } } 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);//添加预支付数据 + resultUtil = payMoneyUtil.alipay("小件物流补差价", "支付差价", out_trade_no, orderMoney.toString(), callbackPath + "/base/aliPayOrderLogisticsSpread"); + if(resultUtil.getCode() == 200){ + 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("余额不足,无法完成支付", ""); + return ResultUtil.error("余额不足,无法完成支付"); } userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); @@ -810,7 +551,7 @@ userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 //添加交易明细 - transactionDetailsService.saveData(uid, (orderLogistics.getType() == 4 ? "同城" : "跨城") + "小件物流补差价", orderMoney, 2, 1, 1, 4, orderId); + transactionDetailsService.saveData(uid, "小件物流补差价", orderMoney, 2, 1, 1, 4, orderId); userInfoService.updateById(userInfo); orderLogistics.setState(12);//已支付差价 @@ -824,32 +565,6 @@ 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))).setScale(2, BigDecimal.ROUND_HALF_EVEN); - c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); - } - - Income income = incomeService.selectOne(new EntityWrapper<Income>().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<Income>().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() { @@ -875,7 +590,7 @@ 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()); + transactionDetailsService.saveData(orderLogistics.getUserId(), "完成订单", query.getAmount(), 2, 1, 1, orderLogistics.getType(), query.getOrderId()); orderLogistics.setState(1);//先支付后抢单 orderLogistics.setPayType(type); orderLogistics.setPayMoney(query.getAmount()); @@ -886,26 +601,9 @@ 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() { @@ -933,7 +631,7 @@ 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()); + transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流补差价", query.getAmount(), 2, 1, 1, 4, query.getOrderId()); orderLogistics.setState(4);//待取货 orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + query.getAmount()); @@ -954,31 +652,6 @@ query.setCode(order_id); paymentRecordService.updateById(query); - //添加已收入明细 - 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); - 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))).setScale(2, BigDecimal.ROUND_HALF_EVEN); - c = new BigDecimal(query.getAmount()).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); - } - Income income = incomeService.selectOne(new EntityWrapper<Income>().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<Income>().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 @@ -987,8 +660,6 @@ pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); - - systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成小件物流订单差价支付,谢谢使用!", orderLogistics.getUserId(), 1); this.updateById(orderLogistics); }else{ @@ -1021,9 +692,9 @@ * @throws Exception */ @Override - public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer type, Integer pageNum, Integer size) throws Exception { + public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer pageNum, Integer size) throws Exception { pageNum = (pageNum - 1) * size; - List<Map<String, Object>> maps = orderLogisticsMapper.queryMyOrderList(uid, type, pageNum, size); + List<Map<String, Object>> maps = orderLogisticsMapper.queryMyOrderList(uid, pageNum, size); return maps; } @@ -1060,11 +731,14 @@ } OrderLogistics orderLogistics = this.selectById(id); + if(null == uid){ + uid = orderLogistics.getUserId(); + } Integer integer = null; if(null == orderLogistics){ return ResultUtil.error("取消订单失败,订单信息有误"); } - if(orderLogistics.getState() >= 5 && orderLogistics.getState() != 7 && orderLogistics.getState() != 8 && orderLogistics.getState() != 11){ + if(orderLogistics.getState() > 5 && orderLogistics.getState() != 7 && orderLogistics.getState() != 8 && orderLogistics.getState() != 11){ return ResultUtil.error("取消订单失败,不合法的操作"); } @@ -1079,74 +753,49 @@ return ResultUtil.success(map); } - //回退支付金额 if(null != orderLogistics.getPayType() && null != orderLogistics.getPayMoney()) {//已支付 if(orderLogistics.getPayType() == 3){//余额支付 UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney()); userInfoService.updateById(userInfo); + //添加交易明细 + transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流取消退款", orderLogistics.getPayMoney(), 1, 1, 1, orderLogistics.getType(), orderLogistics.getId()); }else{ //调用回退接口 PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getPayType(), 2); - boolean b = false; + if(null == query){ + return ResultUtil.error("订单还未进行支付"); + } + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String out_trade_no = sdf.format(new Date()) + orderLogistics.getType() + query.getId(); if(query.getPayType() == 1){//微信 - Map<String, String> map = payMoneyUtil.wxRefund(query.getCode(), orderLogistics.getId() + "_" + orderLogistics.getType(), query.getAmount().toString(), query.getAmount().toString(), "/base/cancleOrderWXPay"); - if(!"SUCCESS".equals(map.get("return_code"))){ + Map<String, String> map = payMoneyUtil.wxRefund(query.getCode(), out_trade_no, query.getAmount().toString(), query.getAmount().toString(), callbackPath + "/base/wxRefundCallback"); + String return_code = map.get("return_code"); + if(!"SUCCESS".equals(return_code)){ return ResultUtil.error(map.get("return_msg")); } - }else{//支付宝 + } + if(query.getPayType() == 2){//支付宝 Map<String, String> map = payMoneyUtil.aliRefund(query.getCode(), query.getAmount().toString()); - if(!"10000".equals(map.get("code"))){ + String code = map.get("code"); + if(!"10000".equals(code)){ return ResultUtil.error(map.get("msg")); } - } - - -// Map<String, Object> merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), orderLogistics.getId() + "_" + orderLogistics.getType(), orderLogistics.getOrderNum()); -// if (Integer.valueOf(merrefund.get("code").toString()) == 0) { -// Map<String, Object> 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){ - + query.setRefundState(2); + query.setRefundCode(map.get("trade_no")); + paymentRecordService.updateById(query); + //添加交易明细 + transactionDetailsService.saveData(orderLogistics.getUserId(), "小件物流取消退款", orderLogistics.getPayMoney(), 1, 1, 1, orderLogistics.getType(), orderLogistics.getId()); } } - //添加交易明细 - 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<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().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()){ @@ -1219,331 +868,9 @@ } - @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); - - //获取优惠券中最优数据 - List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("companyId", orderLogistics.getCompanyId()).eq("state", 1).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<String, String> geocode = gdMapGeocodingUtil.geocode(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); - CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); - if(null == companyCity){ - companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); - } - if(null == companyCity){ - companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); - } - List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().like("companyCityId", "%" + companyCity.getId() + "%") - .in("type", Arrays.asList(5)).eq("userId", uid).where("now() between startTime and endTime")); - - //全国卡 - List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(1, 2, 3, 4)).eq("state", 1)); - if(taxiCards.size() > 0) { - List<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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<String, Object> 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<UserTaxiCard> userTaxiCards_ = new ArrayList<>(); - List<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid)); - CompanyCity finalCompanyCity = companyCity; - bindUserId.forEach(userUser -> { - List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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<UserTaxiCard> userTaxiCards2 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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()); - - - preferentialDataVo.setObjectId(id); - preferentialDataVo.setDiscountAmount(price); - preferentialDataVo.setType(type); - return preferentialDataVo; - } - - - public Map<String, Object> getOptimalTaxiCards(OrderLogistics orderLogistics, Double price, Integer id, Integer type, List<UserTaxiCard> userTaxiCards) throws Exception{ - Map<String, Object> map = new HashMap<>(); - for(UserTaxiCard t : userTaxiCards){ - if(t.getType() != 5){//物流打折卡{"businessTypes":[4,5],"discount":5} - continue; - } - JSONObject jsonObject = JSON.parseObject(t.getContent()); - List<Integer> 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<OrderLogistics> queryByState(Integer uid, Integer... state) throws Exception { - return this.baseMapper.queryByState(uid, state); - } - - - @Override - public List<CouponsListVo> queryCouponList(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { - pageNum = (pageNum - 1) * size; - OrderLogistics orderLogistics = this.selectById(orderId); - List<CouponsListVo> rows = new ArrayList<>(); - List<UserCouponRecord> list = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().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<String, String> geocode = gdMapGeocodingUtil.geocode(orderLogistics.getStartLon().toString(), orderLogistics.getStartLat().toString()); - CompanyCity companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("areaCode", geocode.get("districtCode")).eq("state", 1)); - if(null == companyCity){ - companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("cityCode", geocode.get("cityCode")).eq("state", 1)); - } - if(null == companyCity){ - companyCity = companyCityService.selectOne(new EntityWrapper<CompanyCity>().eq("companyId", orderLogistics.getCompanyId()).eq("provinceCode", geocode.get("provinceCode")).eq("state", 1)); - } - List<UserTaxiCard> userTaxiCards = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().eq("userId", uid) - .in("type", Arrays.asList(5)).like("companyCityId", "%" + companyCity.getId() + "%").where("now() between startTime and endTime")); - - //全国卡 - List<TaxiCard> taxiCards = taxiCardService.selectList(new EntityWrapper<TaxiCard>().eq("taxiCardType", 2).in("type", Arrays.asList(5)).eq("state", 1)); - if(taxiCards.size() > 0) { - List<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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<UserUser> bindUserId = userUserService.selectList(new EntityWrapper<UserUser>().eq("bindUserId", uid)); - CompanyCity finalCompanyCity = companyCity; - bindUserId.forEach(userUser -> { - List<UserTaxiCard> taxiCardPayments1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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<UserTaxiCard> userTaxiCards1 = userTaxiCardService.selectList(new EntityWrapper<UserTaxiCard>().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<Region>().eq("code", companyCity1.getAreaCode())); - str += region.getName() + ";"; - continue; - } - if(ToolUtil.isNotEmpty(companyCity1.getCityCode())){ - Region region = regionService.selectOne(new EntityWrapper<Region>().eq("code", companyCity1.getCityCode())); - str += region.getName() + ";"; - continue; - } - if(ToolUtil.isNotEmpty(companyCity1.getProvinceCode())){ - Region region = regionService.selectOne(new EntityWrapper<Region>().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<CouponsListVo>() { - 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<>(); - } - return rows; - } public synchronized String getOrderNum() throws Exception{ int size = this.selectCount(null); return "LOGISTICS" + String.valueOf(1000000 + size + 1).substring(1); - } - - @Override - 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 app = type == 1 ? "APP" : "JSAPI"; - resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId()); - paymentRecordService.saveData(3, uid, 1, orderId, orderLogistics.getType(), 1, money, "", 1);//添加预支付数据 - } - 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("余额不足,无法完成支付", ""); - } - - userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); - - SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); - 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); - } - 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); - - SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); - 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 ? "微信" : "支付宝") + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1); } } -- Gitblit v1.7.1