| | |
| | | import com.supersavedriving.user.modular.system.util.*; |
| | | import com.supersavedriving.user.modular.system.util.GaoDe.MapUtil; |
| | | import com.supersavedriving.user.modular.system.util.GaoDe.model.District; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.model.*; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.util.Transfer; |
| | | import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest; |
| | | import com.supersavedriving.user.modular.system.util.juhe.WeatherUtil; |
| | | import com.supersavedriving.user.modular.system.util.mongodb.model.Location; |
| | | import com.supersavedriving.user.modular.system.warpper.*; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.geo.Circle; |
| | | import org.springframework.data.geo.Distance; |
| | | import org.springframework.data.geo.Metrics; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Autowired |
| | | private IEvaluateService evaluateService; |
| | | |
| | | @Autowired |
| | | private IRevenueService revenueService; |
| | | |
| | | @Autowired |
| | | private IAgentService agentService; |
| | | |
| | | @Autowired |
| | | private IPlatformRechargeRecordService platformRechargeRecordService; |
| | | |
| | | @Autowired |
| | | private IDivisionRecordService divisionRecordService; |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath;//支付回调网关地址 |
| | | |
| | | |
| | | |
| | | |
| | |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(estimatedCosts.getStartLng().toString(), estimatedCosts.getStartLat().toString()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>() |
| | | .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') ")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | Order order = getOrderPrice(1, d, 0, new Order(), city); |
| | |
| | | } |
| | | |
| | | //恶劣天气 |
| | | boolean badWeather = WeatherUtil.isBadWeather(city); |
| | | if(badWeather){ |
| | | order.setBadWeatherDistance(num5);//恶劣天气公里 |
| | | order.setBadWeatherPrice(num6);//恶劣天气费 |
| | | if(distance.compareTo(num7) > 0){ |
| | | BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7)); |
| | | BigDecimal multiply = subtract.multiply(new BigDecimal(num8)); |
| | | order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里 |
| | | order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费 |
| | | } |
| | | systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8)); |
| | | if(null != systemConfig){ |
| | | JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent()); |
| | | Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价 |
| | | if(1 == num11){ |
| | | boolean badWeather = WeatherUtil.isBadWeather(city); |
| | | if(badWeather){ |
| | | order.setBadWeatherDistance(num5);//恶劣天气公里 |
| | | order.setBadWeatherPrice(num6);//恶劣天气费 |
| | | if(distance.compareTo(num7) > 0){ |
| | | BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7)); |
| | | BigDecimal multiply = subtract.multiply(new BigDecimal(num8)); |
| | | order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里 |
| | | order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费 |
| | | } |
| | | |
| | | double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额) |
| | | if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额 |
| | | order.setBadWeatherPrice(num9);//恶劣天气费 |
| | | order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费 |
| | | }else{ |
| | | BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add)); |
| | | order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费 |
| | | double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额) |
| | | if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额 |
| | | order.setBadWeatherPrice(num9);//恶劣天气费 |
| | | order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费 |
| | | }else{ |
| | | BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add)); |
| | | order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //计算总金额 |
| | | BigDecimal bigDecimal = new BigDecimal(order.getStartPrice() + order.getOverDrivePrice() + order.getLongDistancePrice() + order.getOverLongDistancePrice() + |
| | |
| | | if(null != order){ |
| | | return ResultUtil.error("您还有正在进行的订单"); |
| | | } |
| | | |
| | | String startAddress = travelOrder.getStartAddress(); |
| | | startAddress = startAddress.replaceAll("& #40;", "("); |
| | | startAddress = startAddress.replaceAll("& #41;", ")"); |
| | | travelOrder.setStartAddress(startAddress); |
| | | if(ToolUtil.isNotEmpty(travelOrder.getEndAddress())){ |
| | | String endAddress = travelOrder.getEndAddress(); |
| | | endAddress = endAddress.replaceAll("& #40;", "("); |
| | | endAddress = endAddress.replaceAll("& #41;", ")"); |
| | | travelOrder.setEndAddress(endAddress); |
| | | } |
| | | |
| | | order = new Order(); |
| | | BeanUtils.copyProperties(travelOrder, order); |
| | | if(ToolUtil.isEmpty(travelOrder.getUserPhone())){ |
| | |
| | | order.setUserName(appUser.getNickname()); |
| | | } |
| | | order.setUserId(uid); |
| | | order.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3)); |
| | | order.setSource(1); |
| | | order.setHallOrder(0); |
| | | order.setStatus(1); |
| | |
| | | } |
| | | d = Double.valueOf(distance.get("distance")) / 1000; |
| | | order.setEstimatedMileage(d); |
| | | order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60); |
| | | } |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>() |
| | | .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') ")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | order = getOrderPrice(1, d, 0, order, city); |
| | |
| | | |
| | | for (Integer i = 0; i < travelOrder.getDriverNum(); i++) { |
| | | order.setId(null); |
| | | order.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3)); |
| | | this.insert(order); |
| | | |
| | | //推送状态 |
| | | pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState()); |
| | | if(null != travelOrder.getDriverId()){ |
| | | pushUtil.pushOrderStatus(travelOrder.getDriverId(), 2, order.getId(), order.getState()); |
| | | if(null != order.getDriverId()){ |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order.getId()); |
| | | pushOrderInfoWarpper.setState(order.getState()); |
| | | pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); |
| | | }else{ |
| | | //推单 |
| | | pushOrder(order); |
| | |
| | | |
| | | //1 |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLat), Double.valueOf(startLng)); |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat)); |
| | | Double num = num3 / 1000;//范围公里 |
| | | //构造半径 |
| | | Distance distanceR = new Distance(num, Metrics.KILOMETERS); |
| | |
| | | List<Location> locations = mongoTemplate.find(query, Location.class); |
| | | List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); |
| | | Integer driver = null; |
| | | YouTuiDriver youTuiDriver1 = null; |
| | | if(driverIds.size() > 0){ |
| | | List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds).last(" and now() < failureTime")); |
| | | List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds) |
| | | .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime")); |
| | | Double d = null; |
| | | for (YouTuiDriver youTuiDriver : youTuiDrivers) { |
| | | String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | Driver driver1 = driverService.selectById(youTuiDriver.getDriverId()); |
| | | if(driver1.getServerStatus() == 2){ |
| | | continue; |
| | | } |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | |
| | | if(d == null || d.compareTo(wgs84) > 0){ |
| | | d = wgs84; |
| | | driver = youTuiDriver.getDriverId(); |
| | | youTuiDriver1 = youTuiDriver; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){ |
| | | youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1); |
| | | youTuiDriverService.updateById(youTuiDriver1); |
| | | } |
| | | |
| | | //开始范围查找 |
| | | if(null == driver){ |
| | | for (int i = 1; i < 4; i++) { |
| | | if(null != driver){ |
| | | break; |
| | | } |
| | | num = jsonObject.getDouble("num" + i) / 1000;//范围公里 |
| | | //构造半径 |
| | | distanceR = new Distance(num, Metrics.KILOMETERS); |
| | |
| | | Double score = null; |
| | | Double d = null; |
| | | for (Driver driver1 : drivers) { |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大 |
| | | integral = driver1.getIntegral(); |
| | | score = driver1.getScore(); |
| | |
| | | continue; |
| | | } |
| | | if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离 |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | if(d == null || d.compareTo(wgs84) > 0){ |
| | |
| | | cancelOrder.setStatus(1); |
| | | cancelOrder.setCreateTime(new Date()); |
| | | cancelOrderService.insert(cancelOrder); |
| | | order.setState(301); |
| | | this.updateById(order); |
| | | AppUser appUser = appUserService.selectById(uid); |
| | | appUser.setCancelCount(appUser.getCancelCount() + 1); |
| | | appUserService.updateById(appUser); |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | if(null != driver){ |
| | | driver.setServerStatus(1); |
| | | driverService.updateById(driver); |
| | | } |
| | | |
| | | pushUtil.pushOrderStatus(uid, 1, orderId, order.getState()); |
| | | if(null != order.getDriverId()){ |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order.getId()); |
| | | pushOrderInfoWarpper.setState(order.getState()); |
| | | pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public OrderInfoWarpper queryOrderInfo(Integer uid, Long orderId) throws Exception { |
| | | return this.baseMapper.queryOrderInfo(uid, orderId); |
| | | OrderInfoWarpper orderInfoWarpper = this.baseMapper.queryOrderInfo(uid, orderId); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7)); |
| | | if(null != systemConfig){ |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | orderInfoWarpper.setServiceCell(jsonObject.getString("num1")); |
| | | } |
| | | String value = redisUtil.getValue("DRIVER" + orderInfoWarpper.getDriverId()); |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | String[] split = value.split(","); |
| | | orderInfoWarpper.setDriverLon(split[0]); |
| | | orderInfoWarpper.setDriverLat(split[1]); |
| | | } |
| | | return orderInfoWarpper; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | d = Double.valueOf(distance.get("distance")) / 1000; |
| | | order.setEstimatedMileage(d); |
| | | order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60); |
| | | } |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getStartLng().toString(), order.getStartLat().toString()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district")); |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>() |
| | | .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') ")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | Order order1 = new Order(); |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId, Integer payType) throws Exception { |
| | | public OrderPriceWarpper queryOrderPrice(Integer uid, Long orderId) throws Exception { |
| | | Order order = this.selectById(orderId); |
| | | OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); |
| | | BeanUtils.copyProperties(order, orderPriceWarpper); |
| | |
| | | Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); |
| | | if(null != coupon){ |
| | | orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); |
| | | orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); |
| | | orderPriceWarpper.setCouponId(coupon.getId()); |
| | | } |
| | | //再算折扣(余额完全可以抵扣费用才能有折扣) |
| | | if(payType == 1 && appUser.getAccountBalance() > orderMoney){//使用余额抵扣 |
| | | orderPriceWarpper.setDiscount(appUser.getHavDiscount() == 0 ? 0 : 9D); |
| | | orderPriceWarpper.setDiscountAmount(orderMoney * 0.1); |
| | | orderPriceWarpper.setPayType(2);//余额支付 |
| | | orderMoney = orderMoney - orderPriceWarpper.getDiscountAmount(); |
| | | } |
| | | if(payType == 0){//不使用余额抵扣 |
| | | orderPriceWarpper.setDiscount(0D); |
| | | orderPriceWarpper.setDiscountAmount(0D); |
| | | orderPriceWarpper.setPayType(1);//微信支付 |
| | | } |
| | | if(payType == 1 && appUser.getAccountBalance() > 0 && appUser.getAccountBalance() < orderMoney){//使用余额抵扣部分 |
| | | orderPriceWarpper.setDiscount(0D); |
| | | orderPriceWarpper.setDiscountAmount(0D); |
| | | orderPriceWarpper.setPayType(4);//微信+余额 |
| | | orderMoney = orderMoney - appUser.getAccountBalance(); |
| | | } |
| | | orderPriceWarpper.setDiscount(0D); |
| | | orderPriceWarpper.setDiscountAmount(0D); |
| | | orderPriceWarpper.setPayType(1);//微信支付 |
| | | orderPriceWarpper.setPayMoney(orderMoney); |
| | | return orderPriceWarpper; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重新计算费用明细 |
| | | * @param orderId |
| | | * @param couponId |
| | | * @param payType |
| | | * @param balance |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public OrderPriceWarpper calculationOfExpenses(Integer uid, Long orderId, Integer couponId, Integer payType, Double balance) throws Exception { |
| | | Order order = this.selectById(orderId); |
| | | OrderPriceWarpper orderPriceWarpper = new OrderPriceWarpper(); |
| | | BeanUtils.copyProperties(order, orderPriceWarpper); |
| | | AppUser appUser = appUserService.selectById(uid); |
| | | orderPriceWarpper.setBalance(appUser.getAccountBalance()); |
| | | orderPriceWarpper.setDiscount(0D); |
| | | orderPriceWarpper.setDiscountAmount(0D); |
| | | orderPriceWarpper.setPayType(1);//微信支付 |
| | | Double orderMoney = order.getOrderMoney(); |
| | | //先算优惠券 |
| | | Coupon coupon = userToCouponService.queryCoupon(uid, orderMoney); |
| | | if(null != coupon && null == couponId){ |
| | | orderMoney = orderMoney - coupon.getCouponPreferentialAmount(); |
| | | orderPriceWarpper.setDiscountedPrice(coupon.getCouponPreferentialAmount()); |
| | | orderPriceWarpper.setCouponId(coupon.getId()); |
| | | } |
| | | if(null != couponId){ |
| | | UserToCoupon userToCoupon = userToCouponService.selectById(couponId); |
| | | Coupon coupon1 = couponService.selectById(userToCoupon.getCouponId()); |
| | | orderMoney = orderMoney - coupon1.getCouponPreferentialAmount(); |
| | | orderPriceWarpper.setDiscountedPrice(coupon1.getCouponPreferentialAmount()); |
| | | orderPriceWarpper.setCouponId(couponId); |
| | | } |
| | | if(payType == 1 && appUser.getHavDiscount() == 1){//使用余额抵扣 |
| | | orderPriceWarpper.setDiscount(9D); |
| | | orderPriceWarpper.setDiscountAmount(orderMoney * 0.1); |
| | | orderMoney = orderMoney * 0.9; |
| | | } |
| | | if(payType == 0){//不使用余额抵扣 |
| | | orderPriceWarpper.setPayType(1); |
| | | } |
| | | if(payType == 1 && balance >= orderMoney){//使用余额抵扣 |
| | | orderPriceWarpper.setPayType(2); |
| | | } |
| | | if(payType == 1 && balance < orderMoney){//使用余额抵扣部分 |
| | | orderPriceWarpper.setPayType(4); |
| | | } |
| | | orderPriceWarpper.setPayMoney(orderMoney); |
| | | return orderPriceWarpper; |
| | | } |
| | | |
| | | /** |
| | | * 获取订单支付页面优惠券列表 |
| | |
| | | order.setPayMoney(payMoney); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + order.getId(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | // this.updateById(order); |
| | | |
| | | |
| | | |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(payMoney * 100)); |
| | | paymentOrder.setOrderName("代驾服务费"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(""); |
| | | paymentOrder.setOpenid(appUser.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("服务费"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(""); |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/order/orderPayCallback"); |
| | | paymentOrder.setParameter1(order.getId().toString()); |
| | | |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | String payCode = jsonObject.getString("payCode"); |
| | | this.updateById(order); |
| | | return weixinpay; |
| | | return ResultUtil.success(payCode); |
| | | } |
| | | |
| | | |
| | |
| | | * @param appUser |
| | | * @return |
| | | */ |
| | | public ResultUtil balancePayment(Order order, AppUser appUser, Integer couponId){ |
| | | public ResultUtil balancePayment(Order order, AppUser appUser, Integer couponId) throws Exception{ |
| | | Double payMoney = order.getOrderMoney(); |
| | | if(null != couponId){ |
| | | UserToCoupon userToCoupon = userToCouponService.selectById(couponId); |
| | |
| | | order.setState(108); |
| | | this.updateById(order); |
| | | |
| | | pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); |
| | | if(null != order.getDriverId()) { |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order.getId()); |
| | | pushOrderInfoWarpper.setState(order.getState()); |
| | | pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(appUser.getId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(appUser.getAccountBalance()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(2); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setExplain("代驾服务费"); |
| | | appUser.setAccountBalance(appUser.getAccountBalance() - payMoney); |
| | | accountChangeDetail.setNewData(appUser.getAccountBalance()); |
| | | appUserService.updateById(appUser); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | |
| | | //处理佣金和收入记录 |
| | | saveCommission(order); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | payMoney = payMoney > appUser.getAccountBalance() ? payMoney - appUser.getAccountBalance() : 0D; |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(1); |
| | | accountChangeDetail.setUserId(appUser.getId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(appUser.getAccountBalance()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(2); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setExplain("代驾服务费"); |
| | | appUser.setAccountBalance(appUser.getAccountBalance() > payMoney ? appUser.getAccountBalance() - payMoney : 0); |
| | | accountChangeDetail.setNewData(appUser.getAccountBalance()); |
| | |
| | | if(0 < payMoney){//还需要调起微信支付 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String out_trade_no = sdf.format(new Date()) + order.getId(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpay("代驾服务费", "", out_trade_no, payMoney.toString(), "/base/order/orderPayCallback", "JSAPI", appUser.getOpenid()); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10){ |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | if(order1.getState() != 107){ |
| | | return; |
| | | } |
| | | PaymentOrder paymentOrder = new PaymentOrder(); |
| | | paymentOrder.setBizOrderId(out_trade_no); |
| | | paymentOrder.setAmount(String.valueOf(payMoney * 100)); |
| | | paymentOrder.setOrderName("代驾服务费"); |
| | | paymentOrder.setPayType("WX_MINI"); |
| | | paymentOrder.setTransferType("0"); |
| | | paymentOrder.setAsynSplitFlag("1"); |
| | | paymentOrder.setAppid(""); |
| | | paymentOrder.setOpenid(appUser.getOpenid()); |
| | | paymentOrder.setTerminalIp(InetAddress.getLocalHost().getHostAddress()); |
| | | List<PaymentOrderGood> goodsDetail = new ArrayList<>(); |
| | | PaymentOrderGood paymentOrderGood = new PaymentOrderGood(); |
| | | paymentOrderGood.setGoodsName("服务费"); |
| | | goodsDetail.add(paymentOrderGood); |
| | | paymentOrder.setGoodsDetail(goodsDetail); |
| | | paymentOrder.setFrontUrl(""); |
| | | paymentOrder.setNotifyUrl(callbackPath + "/base/order/orderPayCallback"); |
| | | paymentOrder.setParameter1(order.getId().toString()); |
| | | |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | if(resultUtil.getCode() == 200){ |
| | | Map<String, String> map = resultUtil.getData(); |
| | | String trade_type = map.get("trade_type"); |
| | | String trade_state = map.get("trade_state"); |
| | | String transaction_id = map.get("transaction_id"); |
| | | if("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){ |
| | | AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId()); |
| | | Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | appUser1.setAccountBalance(appUser1.getAccountBalance() + b); |
| | | appUserService.updateById(appUser1); |
| | | TrhRequest<PaymentOrder> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(paymentOrder, PaymentOrder.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | String payCode = jsonObject.getString("payCode"); |
| | | this.updateById(order); |
| | | return ResultUtil.success(payCode); |
| | | |
| | | accountChangeDetailService.deleteById(accountChangeDetail.getId()); |
| | | return; |
| | | } |
| | | if("SUCCESS".equals(trade_state)){ |
| | | order1.setPayTime(new Date()); |
| | | order1.setState(108); |
| | | order1.setOrderNo(transaction_id); |
| | | OrderServiceImpl.this.updateById(order1); |
| | | |
| | | //处理抽成及收入 |
| | | return; |
| | | } |
| | | if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){ |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | return weixinpay; |
| | | // |
| | | // |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // try { |
| | | // int num = 1; |
| | | // int wait = 0; |
| | | // while (num <= 10){ |
| | | // int min = 5000; |
| | | // wait += (min * num); |
| | | // Order order1 = OrderServiceImpl.this.selectById(order.getId()); |
| | | // if(order1.getState() != 107){ |
| | | // return; |
| | | // } |
| | | // |
| | | // /** |
| | | // * SUCCESS--支付成功 |
| | | // * REFUND--转入退款 |
| | | // * NOTPAY--未支付 |
| | | // * CLOSED--已关闭 |
| | | // * REVOKED--已撤销(刷卡支付) |
| | | // * USERPAYING--用户支付中 |
| | | // * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | // * ACCEPT--已接收,等待扣款 |
| | | // */ |
| | | // ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(out_trade_no, ""); |
| | | // if(resultUtil.getCode() == 200){ |
| | | // Map<String, String> map = resultUtil.getData(); |
| | | // String trade_type = map.get("trade_type"); |
| | | // String trade_state = map.get("trade_state"); |
| | | // String transaction_id = map.get("transaction_id"); |
| | | // if("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){ |
| | | // AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | // AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId()); |
| | | // Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | // appUser1.setAccountBalance(appUser1.getAccountBalance() + b); |
| | | // appUserService.updateById(appUser1); |
| | | // |
| | | // accountChangeDetailService.deleteById(accountChangeDetail.getId()); |
| | | // return; |
| | | // } |
| | | // if("SUCCESS".equals(trade_state)){ |
| | | // order1.setPayTime(new Date()); |
| | | // order1.setState(108); |
| | | // order1.setOrderNo(transaction_id); |
| | | // OrderServiceImpl.this.updateById(order1); |
| | | // |
| | | // //处理抽成及收入 |
| | | // saveCommission(order1); |
| | | // return; |
| | | // } |
| | | // if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){ |
| | | // Thread.sleep(wait); |
| | | // num++; |
| | | // } |
| | | // }else{ |
| | | // Thread.sleep(wait); |
| | | // num++; |
| | | // } |
| | | // if(10 == num){ |
| | | // AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId()); |
| | | // AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId()); |
| | | // Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData(); |
| | | // appUser1.setAccountBalance(appUser1.getAccountBalance() + b); |
| | | // appUserService.updateById(appUser1); |
| | | // |
| | | // accountChangeDetailService.deleteById(accountChangeDetail.getId()); |
| | | // } |
| | | // } |
| | | // }catch (Exception e){ |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }).start(); |
| | | // return weixinpay; |
| | | } |
| | | order.setPayTime(new Date()); |
| | | this.updateById(order); |
| | | // order.setPayTime(new Date()); |
| | | // this.updateById(order); |
| | | |
| | | |
| | | return ResultUtil.success(); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | order.setOrderNo(transaction_id); |
| | | this.updateById(order); |
| | | //添加收入明细 |
| | | saveCommission(order); |
| | | |
| | | pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState()); |
| | | if(null != order.getDriverId()) { |
| | | PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); |
| | | pushOrderInfoWarpper.setId(order.getId()); |
| | | pushOrderInfoWarpper.setState(order.getState()); |
| | | pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); |
| | | } |
| | | |
| | | //支付成功---->异步分账----->10s钟后再进行确认收货 |
| | | //确认收货后才能进行提现(结算接口) |
| | | //异步分账 |
| | | List<Revenue> revenues = revenueService.selectList(new EntityWrapper<Revenue>().eq("orderId", order.getId())); |
| | | Complete complete = new Complete(); |
| | | complete.setOriginalMerOrderId(transaction_id); |
| | | complete.setNotifyUrl(callbackPath + "/base/order/ledgerCallback"); |
| | | List<PamentOrderUser> splitList = new ArrayList<>(); |
| | | for (Revenue revenue : revenues) { |
| | | if(revenue.getUserType() == 2){//司机 |
| | | Driver driver = driverService.selectById(revenue.getUserId()); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(driver.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(revenue.getAmount().toString()); |
| | | pamentOrderUser.setSplitType("2"); |
| | | splitList.add(pamentOrderUser); |
| | | |
| | | DivisionRecord divisionRecord = new DivisionRecord(); |
| | | divisionRecord.setUserType(1); |
| | | divisionRecord.setUserId(revenue.getUserId()); |
| | | divisionRecord.setOrderId(order.getId()); |
| | | divisionRecord.setMerOrderId(transaction_id); |
| | | divisionRecord.setSourceType(1); |
| | | divisionRecord.setAmount(revenue.getAmount()); |
| | | divisionRecord.setMerchantNumber(driver.getMerchantNumber()); |
| | | divisionRecord.setState(1); |
| | | divisionRecord.setCreateTime(new Date()); |
| | | divisionRecordService.insert(divisionRecord); |
| | | } |
| | | if(revenue.getUserType() == 3){//代理商 |
| | | Agent agent = agentService.selectById(revenue.getUserId()); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(agent.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(revenue.getAmount().toString()); |
| | | pamentOrderUser.setSplitType("2"); |
| | | splitList.add(pamentOrderUser); |
| | | |
| | | DivisionRecord divisionRecord = new DivisionRecord(); |
| | | divisionRecord.setUserType(2); |
| | | divisionRecord.setUserId(revenue.getUserId()); |
| | | divisionRecord.setOrderId(order.getId()); |
| | | divisionRecord.setMerOrderId(transaction_id); |
| | | divisionRecord.setSourceType(1); |
| | | divisionRecord.setAmount(revenue.getAmount()); |
| | | divisionRecord.setMerchantNumber(agent.getMerchantNumber()); |
| | | divisionRecord.setState(1); |
| | | divisionRecord.setCreateTime(new Date()); |
| | | divisionRecordService.insert(divisionRecord); |
| | | } |
| | | |
| | | } |
| | | complete.setSplitList(splitList); |
| | | TrhRequest<Complete> request = new TrhRequest(); |
| | | InterfaceResponse execute = request.execute(complete, Complete.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getResult())){ |
| | | return ResultUtil.error(execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | |
| | | //使用优惠券的情况,通过转账接口将优惠券的收入转到司机电子账簿 |
| | | if(null != order.getCouponId()){ |
| | | List<PlatformRechargeRecord> platformRechargeRecords = platformRechargeRecordService.selectList(new EntityWrapper<PlatformRechargeRecord>().eq("state", 2).last(" and balance > 0 order by payTime")); |
| | | Double discountedPrice = order.getDiscountedPrice(); |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | for (PlatformRechargeRecord platformRechargeRecord : platformRechargeRecords) { |
| | | if(discountedPrice == 0){ |
| | | break; |
| | | } |
| | | |
| | | if(platformRechargeRecord.getBalance().compareTo(discountedPrice) >= 0){ |
| | | discountedPrice = 0D; |
| | | platformRechargeRecord.setBalance(platformRechargeRecord.getBalance() - discountedPrice); |
| | | platformRechargeRecordService.updateById(platformRechargeRecord); |
| | | }else{ |
| | | |
| | | } |
| | | |
| | | Transfer transfer = new Transfer(); |
| | | transfer.setDepositMerOrderId("6831518911582834611"); |
| | | transfer.setToUserId(driver.getMerchantNumber()); |
| | | transfer.setAmount(discountedPrice.toString()); |
| | | transfer.setOrderName(""); |
| | | transfer.setNotifyUrl(""); |
| | | transfer.setParameter1(order.getId().toString()); |
| | | |
| | | TrhRequest<Transfer> request1 = new TrhRequest(); |
| | | InterfaceResponse execute1 = request1.execute(transfer, Transfer.SERVICE_CODE); |
| | | if(!"0000".equals(execute1.getResult())){ |
| | | return ResultUtil.error(execute1.getMsg()); |
| | | } |
| | | JSONObject jsonObject1 = JSON.parseObject(execute1.getResult()); |
| | | String status1 = jsonObject1.getString("status"); |
| | | if("2".equals(status1)){ |
| | | return ResultUtil.error("失败"); |
| | | } |
| | | if("0".equals(status1)){ |
| | | return ResultUtil.error("处理中"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | evaluate.setUserId(uid); |
| | | evaluateService.insert(evaluate); |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | driver.setScore((driver.getScore() + score) / 2); |
| | | driver.setScore(((null == driver.getScore() ? 0 : driver.getScore()) + score) / 2); |
| | | if(score == 5){//司机积分奖励 |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null != systemConfig){ |
| | |
| | | |
| | | //增加积分变动记录 |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | } |
| | | } |
| | | if(score < 3){//差评扣减积分 |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); |
| | | if(null != systemConfig){ |
| | | //{"num1":"10:00","num2":"14:00","num3":10,"num4":10,"num5":10,"num6":10,"num7":10,"num8":10,"num9":5,"num10":5} |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | Integer num9 = jsonObject.getInteger("num9"); |
| | | |
| | | //增加积分变动记录 |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(order.getDriverId()); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | accountChangeDetail.setOldData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetail.setType(2); |
| | | accountChangeDetail.setExplain("差评扣减积分"); |
| | | driver.setIntegral(driver.getIntegral() - num9); |
| | | accountChangeDetail.setNewData(driver.getIntegral().doubleValue()); |
| | | accountChangeDetailService.insert(accountChangeDetail); |
| | | } |
| | | } |
| | | driverService.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理订单收入及分佣抽成 |
| | | * @param order |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public void saveCommission(Order order) throws Exception{ |
| | | //司机收入和代理商抽成(先分佣,后抽成) |
| | | //司机分佣和司机推荐用户首单奖励都在平台的抽佣中扣除,剩余的为平台抽佣。 |
| | | Driver driver = driverService.selectById(order.getDriverId()); |
| | | AppUser appUser = appUserService.selectById(order.getUserId()); |
| | | Double payMoney = order.getPayMoney(); |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 3)); |
| | | if(null != systemConfig){ |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | Double num3 = jsonObject.getDouble("num3"); |
| | | if(order.getPayMoney() >= num2){ |
| | | payMoney = payMoney - num3;//司机收入 |
| | | SystemConfig systemConfig1 = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 2)); |
| | | if(null != systemConfig1){ |
| | | JSONObject jsonObject1 = JSON.parseObject(systemConfig1.getContent()); |
| | | //司机推荐首单收入 |
| | | List<Integer> state = Arrays.asList(108, 109); |
| | | int count = this.selectCount(new EntityWrapper<Order>().eq("userId", appUser.getId()).eq("status", 1).in("state", state)); |
| | | if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && count == 1){ |
| | | Double num1 = jsonObject1.getDouble("num1"); |
| | | num1 = (num3 >= num1 ? num1 : num3); |
| | | |
| | | if(num1 > 0){ |
| | | Driver driver1 = driverService.selectById(appUser.getInviterId()); |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num1); |
| | | accountChangeDetail.setNewData(driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num1); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | } |
| | | num3 = (num3 >= num1 ? num3 - num1 : 0); |
| | | } |
| | | |
| | | //开始处理层级抽佣 |
| | | if(null != driver.getInviterType() && driver.getInviterType() == 2){ |
| | | Driver driver1 = driverService.selectById(driver.getInviterId());//一级司机 |
| | | if(null != driver1.getInviterType() && driver1.getInviterType() == 2){ |
| | | Driver driver2 = driverService.selectById(driver1.getInviterId());//二级司机 |
| | | if(null != driver2.getInviterType() && driver2.getInviterType() == 2){ |
| | | Driver driver3 = driverService.selectById(driver2.getInviterId());//三级级司机 |
| | | Double num5 = jsonObject1.getDouble("num5"); |
| | | Double num6 = jsonObject1.getDouble("num6"); |
| | | Double num7 = jsonObject1.getDouble("num7"); |
| | | num5 = (num3 >= num5 ? num5 : num3); |
| | | if(num5 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num5); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num5); |
| | | accountChangeDetail.setNewData(driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num5 ? num3 - num5 : 0); |
| | | } |
| | | num6 = (num3 >= num6 ? num6 : num3); |
| | | if(num6 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver2.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num6); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver2.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver2.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver2.setCommission(driver2.getCommission() + num6); |
| | | accountChangeDetail.setNewData(driver2.getCommission()); |
| | | driverService.updateById(driver2); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num6 ? num3 - num6 : 0); |
| | | } |
| | | num7 = (num3 >= num7 ? num7 : num3); |
| | | if(num7 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver3.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num7); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver3.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver3.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver3.setCommission(driver3.getCommission() + num7); |
| | | accountChangeDetail.setNewData(driver3.getCommission()); |
| | | driverService.updateById(driver3); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num7 ? num3 - num7 : 0); |
| | | } |
| | | }else{ |
| | | Double num3_ = jsonObject1.getDouble("num3"); |
| | | Double num4 = jsonObject1.getDouble("num4"); |
| | | num3_ = (num3 >= num3_ ? num3_ : num3); |
| | | if(num3_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num3_); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num3_); |
| | | accountChangeDetail.setNewData(driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num3_ ? num3 - num3_ : 0); |
| | | } |
| | | num4 = (num3 >= num4 ? num4 : num3); |
| | | if(num4 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver2.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num4); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver2.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver2.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver2.setCommission(driver2.getCommission() + num4); |
| | | accountChangeDetail.setNewData(driver2.getCommission()); |
| | | driverService.updateById(driver2); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num4 ? num3 - num4 : 0); |
| | | } |
| | | } |
| | | }else{ |
| | | Double num2_ = jsonObject1.getDouble("num2"); |
| | | num2_ = (num3 >= num2_ ? num2_ : num3); |
| | | if(num2_ > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(2); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver1.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num2_); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver1.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(5); |
| | | accountChangeDetail.setOldData(driver1.getCommission()); |
| | | accountChangeDetail.setExplain("订单分佣收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver1.setCommission(driver1.getCommission() + num2_); |
| | | accountChangeDetail.setNewData(driver1.getCommission()); |
| | | driverService.updateById(driver1); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | num3 = (num3 >= num2_ ? num3 - num2_ : 0); |
| | | } |
| | | } |
| | | } |
| | | //处理代理商抽佣 |
| | | if(num3 > 0){ |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(1); |
| | | revenue.setUserType(3); |
| | | revenue.setUserId(driver.getAgentId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(num3); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //司机订单收入 |
| | | Revenue revenue = new Revenue(); |
| | | revenue.setType(1); |
| | | revenue.setUserType(2); |
| | | revenue.setUserId(driver.getId()); |
| | | revenue.setOrderId(order.getId()); |
| | | revenue.setAmount(payMoney + order.getDiscountedPrice()); |
| | | revenue.setCreateTime(new Date()); |
| | | revenueService.insert(revenue); |
| | | |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(1); |
| | | accountChangeDetail.setOrderId(order.getId()); |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getCouponBalance()); |
| | | accountChangeDetail.setExplain("订单收入"); |
| | | accountChangeDetail.setCreateTime(new Date()); |
| | | driver.setBalance(driver.getBalance() + payMoney); |
| | | if(null != order.getCouponId()){ |
| | | driver.setCouponBalance(driver.getCouponBalance() + order.getDiscountedPrice()); |
| | | } |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getCouponBalance()); |
| | | driverService.updateById(driver); |
| | | accountChangeDetailService.saveData(accountChangeDetail); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取乘客行程 |
| | | * @param uid |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<OrderListWarpper> queryMyOrder(Integer uid, Integer pageNum, Integer pageSize) throws Exception { |
| | | pageNum = (pageNum - 1) * pageSize; |
| | | return this.baseMapper.queryMyOrder(uid, pageNum, pageSize); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取未开票订单 |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<OrderListWarpper> queryNotInvoiceOrder(Integer uid, NotInvoiceOrder notInvoiceOrder) throws Exception { |
| | | notInvoiceOrder.setPageNum((notInvoiceOrder.getPageNum() - 1) * notInvoiceOrder.getPageSize());; |
| | | return this.baseMapper.queryNotInvoiceOrder(uid, notInvoiceOrder); |
| | | } |
| | | } |