From 0d5bade502337cab3fc2f96cf2d6891ded35bb77 Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期一, 15 四月 2024 20:50:29 +0800 Subject: [PATCH] 新增加功能 --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java | 631 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 494 insertions(+), 137 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java index fb22ad0..ada1b3e 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java @@ -1,11 +1,13 @@ 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.model.OrderCrossCity; +import com.stylefeng.guns.modular.crossCity.server.impl.OrderCrossCityServiceImpl; import com.stylefeng.guns.modular.smallLogistics.dao.OrderLogisticsMapper; import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics; import com.stylefeng.guns.modular.smallLogistics.model.OrderLogisticsSpread; @@ -25,6 +27,7 @@ import com.stylefeng.guns.modular.system.util.Tingg.model.Results; import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils; import com.stylefeng.guns.modular.system.warpper.BaseWarpper; +import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.model.PaymentRecord; import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService; @@ -35,7 +38,13 @@ import org.jsoup.select.Elements; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.io.File; @@ -141,6 +150,18 @@ @Autowired private IPhoneService phoneService; + + @Autowired + private ICancleOrderService cancleOrderService; + + @Autowired + private RestTemplate internalRestTemplate; + + @Autowired + private IRedEnvelopePaymentSettingsService redEnvelopePaymentSettingsService; + + @Autowired + private IUserRedPacketRecordService userRedPacketRecordService; @@ -209,9 +230,6 @@ Map<String, Object> data = price.getData(); Double ordinary = Double.valueOf(data.get("ordinary").toString()); Double precious = Double.valueOf(data.get("precious").toString()); - Double discount = Double.valueOf(data.get("discount").toString()); - Double discountMoney = Double.valueOf(data.get("discountMoney").toString()); - Integer activityId = Integer.valueOf(data.get("activityId").toString()); data.put("ordinary", ordinary * number); data.put("precious", precious * number); } @@ -219,9 +237,7 @@ Map<String, Object> data = price.getData(); Double ordinary = Double.valueOf(data.get("ordinary").toString()); Double precious = Double.valueOf(data.get("precious").toString()); - Double discount = Double.valueOf(data.get("discount").toString()); Double discountMoney = Double.valueOf(data.get("discountMoney").toString()); - Integer activityId = Integer.valueOf(data.get("activityId").toString()); data.put("ordinary", ordinary - discountMoney); data.put("precious", precious - discountMoney); } @@ -302,9 +318,15 @@ Map<String, Object> data = price.getData(); Double ordinary = Double.valueOf(data.get("ordinary").toString()); Double precious = Double.valueOf(data.get("precious").toString()); - Double discount = Double.valueOf(data.get("discount").toString()); + Double discount = null; + if(null != data.get("discount")){ + discount = Double.valueOf(data.get("discount").toString()); + } Double discountMoney = Double.valueOf(data.get("discountMoney").toString()); - Integer activityId = Integer.valueOf(data.get("activityId").toString()); + Integer activityId = null; + if(null != data.get("activityId")){ + activityId = Integer.valueOf(data.get("activityId").toString()); + } orderLogistics.setOrderMoney((cargoType == 1 ? ordinary : precious) + tipMoney); orderLogistics.setTravelMoney((cargoType == 1 ? ordinary : precious)); if(type == 5){ @@ -521,7 +543,7 @@ * @throws Exception */ @Override - public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId,Integer couponId, Integer type, Integer language) throws Exception { + public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId,Integer couponId, Integer redDeduction, Integer type, Integer language) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); if(orderLogistics.getState() != 7){ return ResultUtil.error(language == 1 ? "订单已完成支付,不允许重复支付" : language == 2 ? "The order has been paid, recurring payments is not allowed." : "La commande a été payée, les paiements récurrents ne sont pas autorisés.", ""); @@ -533,11 +555,18 @@ } UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(""); - orderLogistics.setCouponMoney(0D);//初始化历史数据 - orderLogistics.setCouponId(null); + //折扣 + if(null != orderLogistics.getActivityId()){ + orderMoney = orderMoney - orderLogistics.getDiscountMoney(); + } + //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ + //TODO 待翻译 + if(null != redDeduction && 1 == redDeduction){ + return ResultUtil.error(language == 1 ? "优惠券和红包不能同时使用" : language == 2 ? "" : "", ""); + } userCouponRecord = userCouponRecordService.selectById(couponId); if(userCouponRecord.getCompanyId() != orderLogistics.getCompanyId()){ return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", ""); @@ -558,10 +587,64 @@ orderLogistics.setCouponMoney(userCouponRecord.getMoney()); orderLogistics.setCouponId(couponId); } - //折扣 - if(null != orderLogistics.getActivityId()){ - orderMoney = orderMoney - orderLogistics.getDiscount(); + + //计算红包 + if(null != redDeduction && 1 == redDeduction){ + RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings(); + if(null != redEnvelopePaymentSettings){ + Double total = userRedPacketRecordService.queryRemainingAmount(uid); + List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid) + .eq("state", 1).eq("companyId", orderLogistics.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false)); + if(total.compareTo(orderMoney) >= 0){ + BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio(); + BigDecimal multiply = new BigDecimal(orderMoney).multiply(deductionRatio.divide(new BigDecimal(100))); + orderLogistics.setRedPacketMoney(multiply.doubleValue()); + orderMoney = orderMoney - multiply.doubleValue(); + + //获取红包id + JSONArray jsonArray = new JSONArray(); + for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", userRedPacketRecord.getId()); + BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); + if(multiply.compareTo(remainingAmount) >= 0){ + multiply = multiply.subtract(remainingAmount); + jsonObject.put("money", remainingAmount); + jsonArray.add(jsonObject); + }else{ + userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue()); + jsonObject.put("money", multiply); + jsonArray.add(jsonObject); + break; + } + } + orderLogistics.setRedPacketId(jsonArray.toJSONString()); + }else{ + orderLogistics.setRedPacketMoney(total); + orderMoney = orderMoney - total; + //获取红包id + JSONArray jsonArray = new JSONArray(); + BigDecimal multiply = new BigDecimal(total); + for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", userRedPacketRecord.getId()); + BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); + if(multiply.compareTo(remainingAmount) >= 0){ + multiply = multiply.subtract(remainingAmount); + jsonObject.put("money", remainingAmount); + jsonArray.add(jsonObject); + }else{ + userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue()); + jsonObject.put("money", multiply); + jsonArray.add(jsonObject); + break; + } + } + orderLogistics.setRedPacketId(jsonArray.toJSONString()); + } + } } + orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); if(payType == 1) {//手机支付 @@ -632,6 +715,21 @@ userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } + if(null != orderLogistics.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + userRedPacketRecord.setEndTime(new Date()); + } + userRedPacketRecordService.updateById(userRedPacketRecord); + } + } //添加交易明细 transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId); @@ -654,7 +752,7 @@ "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); this.pushOrder(orderLogistics);//推单 } - + Driver driver = driverService.selectById(orderLogistics.getDriverId()); if(payType == 4){//现金支付 SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 @@ -664,6 +762,34 @@ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); + //添加优惠收入补贴 + Double money = userCouponRecord.getMoney(); + incomeService.saveData(2, orderLogistics.getDriverId(), 5, orderLogistics.getId(), 4, money); + 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); + } + if(null != orderLogistics.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + userRedPacketRecord.setEndTime(new Date()); + } + userRedPacketRecordService.updateById(userRedPacketRecord); + } + Double money = orderLogistics.getRedPacketMoney(); + incomeService.saveData(2, orderLogistics.getDriverId(), 7, orderLogistics.getId(), 4, money); + 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); } //添加交易明细 @@ -903,6 +1029,21 @@ userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } + if(null != orderLogistics.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderLogistics.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + userRedPacketRecord.setEndTime(new Date()); + } + userRedPacketRecordService.updateById(userRedPacketRecord); + } + } query.setState(2); query.setCode(order_id); @@ -1090,7 +1231,7 @@ @Override - public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid, Integer language) throws Exception { + public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid, Double lon, Double lat, String address, Integer language) throws Exception { if(ToolUtil.isNotEmpty(remark)){ if(ToolUtil.isNotEmpty(remark)){ List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null); @@ -1106,133 +1247,57 @@ if(null == orderLogistics){ return ResultUtil.error(language == 1 ? "取消订单失败,订单信息有误" : language == 2 ? "Failed to cancel order, order-information error." : "Échec de l’annulation de la commande, erreur d’information de commande."); } - if(orderLogistics.getState() > 5 && orderLogistics.getState() != 7 && orderLogistics.getState() != 11){ + if(orderLogistics.getState() > 5 && orderLogistics.getState() != 11){ return ResultUtil.error(language == 1 ? "取消订单失败,不合法的操作" : language == 2 ? "Failed to cancel order, illegal operation." : "Échec de l’annulation de la commande, opération illégale."); } - - if(orderLogistics.getState() == 7){ - OrderCancel orderCancel = new OrderCancel(); - orderCancel.setOrderId(id); - orderCancel.setOrderType(orderLogistics.getType()); - orderCancel.setReason(reason); - orderCancel.setRemark(remark); - orderCancel.setState(2); - orderCancel.setInsertTime(new Date()); - orderCancel.setUserType(1); - orderCancelService.insert(orderCancel); + + if(null == orderLogistics.getDriverId()){//没有接单的情况 + integer = orderCancelService.saveData(id, 4, language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", language == 1 ? "无司机接单" : language == 2 ? "No driver to take orders" : "Pas de chauffeur pour prendre les commandes", null, null, 2, 1, uid); orderLogistics.setState(10); this.updateById(orderLogistics); - return ResultUtil.success(); - } - - - //回退支付金额 - if(null != orderLogistics.getPayType() && orderLogistics.getPayType() == 1) {//微信 - OrderCancel orderCancel = new OrderCancel(); - orderCancel.setOrderId(id); - orderCancel.setOrderType(orderLogistics.getType()); - orderCancel.setReason(reason); - orderCancel.setRemark(remark); - orderCancel.setState(1); - orderCancel.setInsertTime(new Date()); - orderCancel.setUserType(1); - orderCancelService.insert(orderCancel); - orderLogistics.setState(10); - this.updateById(orderLogistics); - //调用回退接口 - PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), 1, 2); - if(null == query){ - return ResultUtil.error("支付数据异常,无法完成退款"); + }else { + BaseWarpper data = queryCancleAmount(id, language).getData(); + Double amount = data.getAmount(); + if(0 == amount){ + integer = orderCancelService.saveData(id, 4, reason, remark, null, null, 2, 1, uid); + if(5 == orderLogistics.getState()){ + orderLogistics.setState(6); + orderLogistics.setGetoffLon(lon); + orderLogistics.setGetoffLat(lat); + orderLogistics.setGetoffAddress(address); + orderLogistics.setGetoffTime(new Date()); + orderLogistics.setEndServiceTime(new Date()); + }else{ + orderLogistics.setState(10); + } + this.updateById(orderLogistics); + }else{ + if(5 == orderLogistics.getState()){ + orderLogistics.setGetoffLon(lon); + orderLogistics.setGetoffLat(lat); + orderLogistics.setGetoffAddress(address); + orderLogistics.setGetoffTime(new Date()); + orderLogistics.setEndServiceTime(new Date()); + } + orderLogistics.setOldState(orderLogistics.getState()); + orderLogistics.setState(12); + this.updateById(orderLogistics); + integer = orderCancelService.saveData(id, 4, reason, remark, null, amount, 1, 1, uid); } - UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); - String payerTransactionID = sdf.format(new Date()) + orderCancel.getId(); - PayoutResponse payoutResponse = tinggPayoutUtil.sendPayout(userInfo.getPhoneOperator(), "+" + userInfo.getPhone(), payerTransactionID, query.getAmount().doubleValue(), callbackPath + "/base/orderCancelRefundCallback", "取消订单退款"); - AuthStatus authStatus = payoutResponse.getAuthStatus(); - Results results = payoutResponse.getResults().get(0); - String statusCode = results.getStatusCode(); - if(!"131".equals(authStatus.getAuthStatusCode())){ - return ResultUtil.error(authStatus.getAuthStatusDescription()); - } - if(!"139".equals(statusCode)){ - return ResultUtil.error(results.getStatusDescription()); - } - } - if(null != orderLogistics.getPayType() && orderLogistics.getPayType() == 2){//支付宝 - OrderCancel orderCancel = new OrderCancel(); - orderCancel.setOrderId(id); - orderCancel.setOrderType(orderLogistics.getType()); - orderCancel.setReason(reason); - orderCancel.setRemark(remark); - orderCancel.setState(1); - orderCancel.setInsertTime(new Date()); - orderCancel.setUserType(1); - orderCancelService.insert(orderCancel); - orderLogistics.setState(10); - this.updateById(orderLogistics); - integer = orderCancel.getId(); - //调用回退接口 - PaymentRecord query = paymentRecordService.query(1, orderLogistics.getUserId(), 1, orderLogistics.getId(), orderLogistics.getType(), 2, 2); - if(null == query){ - return ResultUtil.error("支付数据异常,无法完成退款"); - } - UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); - String payerTransactionID = sdf.format(new Date()) + orderCancel.getId(); - PayoutResponse payoutResponse = tinggPayoutUtil.sendPayout(userInfo.getPhoneOperator(), "+" + userInfo.getPhone(), payerTransactionID, query.getAmount().doubleValue(), callbackPath + "/base/orderCancelRefundCallback", "取消订单退款"); - AuthStatus authStatus = payoutResponse.getAuthStatus(); - Results results = payoutResponse.getResults().get(0); - String statusCode = results.getStatusCode(); - if(!"131".equals(authStatus.getAuthStatusCode())){ - return ResultUtil.error(authStatus.getAuthStatusDescription()); - } - if(!"139".equals(statusCode)){ - return ResultUtil.error(results.getStatusDescription()); - } - } - if(null != orderLogistics.getPayType() && orderLogistics.getPayType() == 3){//余额 - UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); - userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney()); - - OrderCancel orderCancel = new OrderCancel(); - orderCancel.setOrderId(id); - orderCancel.setOrderType(orderLogistics.getType()); - orderCancel.setReason(reason); - orderCancel.setRemark(remark); - orderCancel.setState(2); - orderCancel.setInsertTime(new Date()); - orderCancel.setUserType(1); - orderCancelService.insert(orderCancel); - userInfoService.updateById(userInfo); - orderLogistics.setState(10); - this.updateById(orderLogistics); - integer = orderCancel.getId(); - - //添加交易明细 - transactionDetailsService.saveData(orderLogistics.getUserId(), "包裹取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId()); - } - - - if(null != orderLogistics.getPayType() && orderLogistics.getPayType() == 4){//现金 -// UserInfo userInfo = userInfoService.selectById(orderLogistics.getUserId()); -// userInfo.setBalance(userInfo.getBalance() + orderLogistics.getPayMoney()); -// userInfoService.updateById(userInfo); - OrderCancel orderCancel = new OrderCancel(); - orderCancel.setOrderId(id); - orderCancel.setOrderType(orderLogistics.getType()); - orderCancel.setReason(reason); - orderCancel.setRemark(remark); - orderCancel.setState(2); - orderCancel.setInsertTime(new Date()); - orderCancel.setUserType(1); - orderCancelService.insert(orderCancel); - - orderLogistics.setState(10); - this.updateById(orderLogistics); - integer = orderCancel.getId(); - - //添加交易明细 - transactionDetailsService.saveData(orderLogistics.getUserId(), "包裹取消退款", orderLogistics.getPayMoney(), 1, 1, 1, 4, orderLogistics.getId()); + this.deleteTask(id);//删除定时任务 + + new Thread(new Runnable() { + @Override + public void run() { + pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0); + System.err.println("推送取消操作---------------------"); + } + }).start(); + + //修改司机为空闲 + Driver driver = driverService.selectById(orderLogistics.getDriverId()); + driver.setState(2); + driverService.updateById(driver); } if(null != orderLogistics.getDriverId()){ @@ -1365,4 +1430,296 @@ list.addAll(list1); return list; } + + + + /** + * 获取取消需要支付的金额 + * @param id + * @param language + * @return + * @throws Exception + */ + @Override + public ResultUtil<BaseWarpper> queryCancleAmount(Integer id, Integer language) throws Exception { + OrderLogistics orderLogistics = this.selectById(id); + if(null == orderLogistics){ + return ResultUtil.error(language == 1 ? "获取数据失败,订单信息有误" : language == 2 ? "Failed to obtain data, order-information error." : "Impossible d’obtenir les données, erreur d’information de commande. "); + } + BaseWarpper baseWarpper = new BaseWarpper(); + double amount = 0; + CancleOrder query = cancleOrderService.query(orderLogistics.getCompanyId()); + if(null == query || null == orderLogistics.getDriverId()){ + baseWarpper.setAmount(amount); + return ResultUtil.success(baseWarpper); + } + JSONObject object = JSON.parseObject(query.getContent()); + long t = object.getInteger("driverTimeout") * 60000L; + //司机超时未到达起点,免费取消 + if(orderLogistics.getState() < 3 && orderLogistics.getSnatchOrderTime().getTime() + t < System.currentTimeMillis()){ + baseWarpper.setAmount(amount); + return ResultUtil.success(baseWarpper); + } + + JSONObject order = object.getJSONObject("order"); + long m = order.getInteger("orderAcceptanceTime") * 60000L; + //超过免费时间,计算费用 + if(orderLogistics.getSnatchOrderTime().getTime() + m < System.currentTimeMillis()){ + BigDecimal money = order.getBigDecimal("money"); + if(null != orderLogistics.getSetOutTime()){ + //里程费 + BigDecimal mileageFee = order.getBigDecimal("mileageFee").multiply(new BigDecimal(orderLogistics.getMileage() / 1000)); + //时长费 + int s = Double.valueOf((System.currentTimeMillis() - orderLogistics.getSetOutTime().getTime()) / 60000).intValue(); + BigDecimal durationFee = order.getBigDecimal("durationFee").multiply(new BigDecimal(s)); + money = money.add(durationFee).add(mileageFee); + } + amount = money.setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + } + baseWarpper.setAmount(amount); + return ResultUtil.success(baseWarpper); + } + + + /** + * 删除定时任务 + * @param orderId + */ + @Override + public void deleteTask(Integer orderId){ + //发送验证码短信 + HttpHeaders headers = new HttpHeaders(); + // 以表单的方式提交 + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + //将请求头部和参数合成一个请求 + MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); + params.add("orderId", orderId + ""); + params.add("orderType", "4"); + HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); + String s = internalRestTemplate.postForObject("http://driver-server/base/netty/deleteTask", requestEntity, String.class); + JSONObject jsonObject = JSON.parseObject(s, JSONObject.class); + if(jsonObject.getIntValue("code") != 200){ + System.err.println("调用driver-server出错了"); + } + } + + + + + /** + * 取消订单操作 + * @param id + * @return + * @throws Exception + */ + @Override + public ResultUtil cancleOrderPrivateCar(Integer id, Integer payType, Integer bankCardId, Integer cancleId, Integer type, Integer language) throws Exception { + OrderLogistics orderLogistics = this.selectById(id); + Integer uid = orderLogistics.getUserId(); + UserInfo userInfo = userInfoService.selectById(uid); + ResultUtil resultUtil = ResultUtil.success(""); + + if(null == orderLogistics){ + return ResultUtil.error(language == 1 ? "取消订单失败,订单信息有误" : language == 2 ? "Failed to cancel order, order-information error." : "Échec de l’annulation de la commande, erreur d’information de commande.", ""); + } + if(orderLogistics.getState() != 13){ + return ResultUtil.error(language == 1 ? "取消订单失败,不合法的操作" : language == 2 ? "Failed to cancel order, illegal operation." : "Échec de l’annulation de la commande, opération illégale.", ""); + } + OrderCancel orderCancel = null; + if(null == cancleId || cancleId==0){ + orderCancel = orderCancelService.query(id, 4, null, null, 1); + }else{ + orderCancel = orderCancelService.selectById(cancleId); + } + + Double amount = queryCancleAmount(id, language).getData().getAmount(); + if(0 < amount){ + if(payType == 1){//手机支付 + orderCancel.setPayType(1); + orderCancelService.updateById(orderCancel); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String merchantTransactionId = sdf.format(new Date()) + "4" + language + id; + CheckoutRequest checkoutRequest = new CheckoutRequest(); + checkoutRequest.setMsisdn(Long.valueOf(userInfo.getPhone())); + checkoutRequest.setCustomerEmail(userInfo.getEmail()); + checkoutRequest.setAccountNumber(userInfo.getPhone()); + checkoutRequest.setCustomerFirstName(userInfo.getFirstName()); + checkoutRequest.setCustomerLastName(userInfo.getLastName()); + checkoutRequest.setRequestAmount(amount); + checkoutRequest.setMerchantTransactionId(merchantTransactionId); + checkoutRequest.setRequestDescription("Cancel a trip"); + checkoutRequest.setCallbackUrl(callbackPath + "/base/wxCancelOrderTaxi"); + checkoutRequest.setPendingRedirectUrl(""); + checkoutRequest.setSuccessRedirectUrl("http://182.160.16.251:81/payMoney/pages/success.html"); + checkoutRequest.setFailRedirectUrl("http://182.160.16.251:81/payMoney/pages/fail.html"); + resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest); + if(resultUtil.getCode()==200){ + paymentRecordService.saveData(1, null, null, id, 4, 1, amount, null, 1);//添加预支付数据 + } + + } + if(payType == 2){//银行卡支付 + orderCancel.setPayType(2); + orderCancelService.updateById(orderCancel); + BankCard bankCard = bankCardService.selectById(bankCardId); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String merchantTransactionId = sdf.format(new Date()) + "4" + id; + CheckoutRequest checkoutRequest = new CheckoutRequest(); + checkoutRequest.setMsisdn(Long.valueOf(bankCard.getCode())); + checkoutRequest.setCustomerEmail(userInfo.getEmail()); + checkoutRequest.setAccountNumber(bankCard.getCode()); + checkoutRequest.setCustomerFirstName(bankCard.getFirstName()); + checkoutRequest.setCustomerLastName(bankCard.getLastName()); + checkoutRequest.setRequestAmount(amount); + checkoutRequest.setMerchantTransactionId(merchantTransactionId); + checkoutRequest.setRequestDescription("Cancel a trip"); + checkoutRequest.setCallbackUrl(callbackPath + "/base/wxCancelOrderTaxi"); + checkoutRequest.setPendingRedirectUrl(""); + checkoutRequest.setSuccessRedirectUrl("http://182.160.16.251:81/payMoney/pages/success.html"); + checkoutRequest.setFailRedirectUrl("http://182.160.16.251:81/payMoney/pages/fail.html"); + resultUtil = TinggPayUtil.checkoutRequest(checkoutRequest); + if(resultUtil.getCode()==200){ + paymentRecordService.saveData(1, null, null, id, 4, 2, amount, null, 1);//添加预支付数据 + } + + } + if(payType == 3){//余额支付 + if(userInfo.getBalance() != null && userInfo.getBalance() < amount){ + return ResultUtil.error((language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant"), ""); + } + + userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); + //添加交易明细 + transactionDetailsService.saveData(uid, "取消订单", amount, 2, 1, 1, 4, id); + userInfoService.updateById(userInfo); + + //解除小号绑定 + if(orderLogistics.getBindId() != null){ + ChinaMobileUtil.midAxbUnBindSend(orderLogistics.getBindId(),orderLogistics.getTelX()); + } + + if(5 == orderLogistics.getOldState()){ + orderLogistics.setState(6); + }else{ + orderLogistics.setState(10); + } + orderLogistics.setTelX(""); + orderLogistics.setBindId(""); + this.updateById(orderLogistics); + + orderCancel.setState(2); + orderCancel.setPayType(3); + orderCancelService.updateById(orderCancel); + + if(null != orderLogistics.getDriverId()){ + BigDecimal c =new BigDecimal(amount);//司机收入 + incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue()); + 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); + + this.deleteTask(id);//删除定时任务 + pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0); + } + pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0); + + + //添加消息 + systemNoticeService.addSystemNotice(1, language == 1 ? "您已使用余额成功支付取消订单费用,谢谢使用!" : language == 2 + ? "You've paid for cancellation fee with the balance successfully, thank you for using I-GO" + : "Vous avez utilisé avec succès votre solde pour payer les frais d’annulation, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); + } + } + return resultUtil; + } + + + + /** + * 取消订单支付后的处理 + * @param id 订单=id + * @param order_id 工行支付单号 + * @throws Exception + */ + @Override + public void payCancelOrderPrivateCar(Integer id, String order_id, Integer language) throws Exception { + OrderLogistics orderLogistics = this.selectById(id); + PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 4, null, 1); + if(null != query){ + //添加交易明细 + transactionDetailsService.saveData(orderLogistics.getUserId(), "取消订单", query.getAmount(), 2, 1, 1, 4, query.getOrderId()); + + //解除小号绑定 + if(orderLogistics.getBindId() != null){ + ChinaMobileUtil.midAxbUnBindSend(orderLogistics.getBindId(),orderLogistics.getTelX()); + } + if(5 == orderLogistics.getOldState()){ + orderLogistics.setState(6); + }else{ + orderLogistics.setState(10); + } + orderLogistics.setBindId(""); + orderLogistics.setTelX(""); + this.updateById(orderLogistics); + + query.setState(2); + query.setCode(order_id); + paymentRecordService.updateById(query); + + OrderCancel query1 = orderCancelService.query(query.getOrderId(), query.getOrderType(), query.getAmount(), query.getPayType(), 1); + if (null != query1){ + query1.setState(2); + orderCancelService.updateById(query1); + } + + + if(null != orderLogistics.getDriverId()){ + BigDecimal c =new BigDecimal(query.getAmount());//司机收入 + incomeService.saveData(2, orderLogistics.getDriverId(), 3, orderLogistics.getId(), 4, c.doubleValue()); + 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); + this.deleteTask(orderLogistics.getId());//删除定时任务 + + pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0); + } + pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), 4, orderLogistics.getState(), 0); + + //添加消息 + systemNoticeService.addSystemNotice(1, language == 1 ? "您已使用余额成功支付取消订单费用,谢谢使用!" : language == 2 + ? "You've paid for cancellation fee with the balance successfully, thank you for using I-GO" + : "Vous avez utilisé avec succès votre solde pour payer les frais d’annulation, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); + }else{ + System.err.println("预支付数据异常(orderId = " + id + ")"); + } + } + + + /** + * 修改目的地 + * @param orderId + * @param endLon + * @param endLat + * @param endAddress + */ + @Override + public void updateEndAddress(Integer orderId, String endLon, String endLat, String endAddress) { + OrderLogistics orderLogistics = this.selectById(orderId); + if(null != orderLogistics.getDriverId()){ + orderLogistics.setDestination(endAddress); + orderLogistics.setDestinationLat(endLat); + orderLogistics.setDestinationLon(endLon); + this.updateById(orderLogistics); + pushUtil.pushModifyAddress(2, orderLogistics.getDriverId(), orderId, 1, 1); + }else{ + orderLogistics.setEndAddress(endAddress); + orderLogistics.setEndLat(Double.valueOf(endLat)); + orderLogistics.setEndLon(Double.valueOf(endLon)); + this.updateById(orderLogistics); + } + } } -- Gitblit v1.7.1