From a075cdd2f76fae321ecf95dce363141ade30f0f1 Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期五, 12 四月 2024 22:37:58 +0800 Subject: [PATCH] 新增加功能 --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java | 946 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 587 insertions(+), 359 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 6f79b4a..cd0ef18 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 @@ -6,11 +6,13 @@ 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; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService; +import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.system.dao.*; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; @@ -24,6 +26,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; @@ -34,7 +37,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; @@ -83,7 +92,8 @@ @Autowired private IUserInfoService userInfoService; - + @Resource + private UserActivityDiscount1Mapper userActivityDiscount1Mapper; @Autowired private IPaymentRecordService paymentRecordService; @@ -139,6 +149,12 @@ @Autowired private IPhoneService phoneService; + + @Autowired + private ICancleOrderService cancleOrderService; + + @Autowired + private RestTemplate internalRestTemplate; @@ -175,19 +191,16 @@ * @throws Exception */ @Override - public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer uid, Integer language) throws Exception { - FindPlaceFromTextVo findplacefromtext = GoogleMapUtil.textsearch(endAddress); - if(null == findplacefromtext){ - return ResultUtil.error(language == 1 ? "收货地址有误,无法查询具体地址信息" : language == 2 ? "The delivery address is incorrect, and the specific address information cannot be queried" : "L’adresse de livraison est incorrecte, impossible de vérifier l’adresse spécifique"); - } - Double lng = findplacefromtext.getLng(); - Double lat = findplacefromtext.getLat(); - ResultUtil<Map<String, Double>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language); + public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endLonLat, String endAddress, Integer uid, Integer language) throws Exception { + String[] split = endLonLat.split(","); + Double lng = Double.valueOf(split[0]); + Double lat = Double.valueOf(split[1]); + ResultUtil<Map<String, Object>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language); if(price.getCode() != 200){ return price; } Integer i = this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId", uid).eq("isDelete", 1)); - Map<String, Double> map = price.getData(); + Map<String, Object> map = price.getData(); map.put("first", i.doubleValue()); return price; } @@ -201,18 +214,25 @@ * @return * @throws Exception */ - public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endAddress, Integer language) throws Exception{ - FindPlaceFromTextVo findplacefromtext = GoogleMapUtil.textsearch(endAddress); - if(null == findplacefromtext){ - return ResultUtil.error(language == 1 ? "收货地址有误,无法查询具体地址信息" : language == 2 ? "The delivery address is incorrect, and the specific address information cannot be queried" : "L’adresse de livraison est incorrecte, impossible de vérifier l’adresse spécifique"); - } - Double lng = findplacefromtext.getLng(); - Double lat = findplacefromtext.getLat(); - ResultUtil<Map<String, Double>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language); + public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endLonLat, String endAddress, Integer language) throws Exception{ + String[] split = endLonLat.split(","); + Double lng = Double.valueOf(split[0]); + Double lat = Double.valueOf(split[1]); + ResultUtil<Map<String, Object>> price = this.getPrice1(type, startLonLat.split(",")[0], startLonLat.split(",")[1], lng.toString(), lat.toString(), language); if(price.getCode() == 200 && type == 5){ - Map<String, Double> data = price.getData(); - data.put("ordinary", data.get("ordinary") * number); - data.put("precious", data.get("precious") * number); + Map<String, Object> data = price.getData(); + Double ordinary = Double.valueOf(data.get("ordinary").toString()); + Double precious = Double.valueOf(data.get("precious").toString()); + data.put("ordinary", ordinary * number); + data.put("precious", precious * number); + } + if(price.getCode() == 200){ + Map<String, Object> data = price.getData(); + Double ordinary = Double.valueOf(data.get("ordinary").toString()); + Double precious = Double.valueOf(data.get("precious").toString()); + Double discountMoney = Double.valueOf(data.get("discountMoney").toString()); + data.put("ordinary", ordinary - discountMoney); + data.put("precious", precious - discountMoney); } return price; } @@ -242,7 +262,7 @@ */ @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, Integer language) throws Exception { + String recipientPhone, String endLonLat, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, Integer uid, Integer language) throws Exception { startAddress = startAddress.replaceAll("& #40;", "("); startAddress = startAddress.replaceAll("& #41;", ")"); endAddress = endAddress.replaceAll("& #40;", "("); @@ -250,7 +270,7 @@ OrderLogistics orderLogistics = new OrderLogistics(); Company query = companyCityService.query1(placementLon, placementLat); if(null == query){ - return ResultUtil.error(language == 1 ? "该地点暂无企业服务" : language == 2 ? "No corporate services are available at this location" : "Aucun service d’entreprise n’est disponible pour cet emplacement"); + return ResultUtil.error(language == 1 ? "该地点暂无企业服务" : language == 2 ? "No service yet at this area" : "Pas encore de service dans cette zone"); } orderLogistics.setCompanyId(query.getId()); orderLogistics.setType(type); @@ -263,7 +283,7 @@ orderLogistics.setPlacementLat(Double.valueOf(placementLat)); ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(placementLat), Double.valueOf(placementLon)); if(null == reverseGeocode){ - return ResultUtil.error(language == 1 ? "解析地址出错" : language == 2 ? "Resolve address error" : "Erreur dans la résolution de l’adresse"); + return ResultUtil.error(language == 1 ? "解析地址出错" : language == 2 ? "Address resolution error" : "Erreur de résolution d’adresse"); } String address = reverseGeocode.getAddress(); @@ -271,12 +291,10 @@ orderLogistics.setStartLon(Double.valueOf(startLon)); orderLogistics.setStartLat(Double.valueOf(startLat)); orderLogistics.setStartAddress(startAddress); - FindPlaceFromTextVo findplacefromtext = GoogleMapUtil.textsearch(endAddress); - if(null == findplacefromtext){ - return ResultUtil.error(language == 1 ? "收货地址有误,无法查询具体地址信息" : language == 2 ? "The delivery address is incorrect, and the specific address information cannot be queried" : "L’adresse de livraison est incorrecte, impossible de vérifier l’adresse spécifique"); - } - Double lng = findplacefromtext.getLng(); - Double lat = findplacefromtext.getLat(); + + String[] split = endLonLat.split(","); + Double lng = Double.valueOf(split[0]); + Double lat = Double.valueOf(split[1]); orderLogistics.setEndLon(lng); orderLogistics.setEndLat(lat); orderLogistics.setEndAddress(endAddress); @@ -286,17 +304,31 @@ orderLogistics.setMileage(0D); orderLogistics.setIsReassign(1); orderLogistics.setReassignNotice(0); - ResultUtil<Map<String, Double>> price = this.getPrice1(type, String.valueOf(startLon), String.valueOf(startLat), lng.toString(), lat.toString(), language); + ResultUtil<Map<String, Object>> price = this.getPrice1(type, String.valueOf(startLon), String.valueOf(startLat), lng.toString(), lat.toString(), language); 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); + Map<String, Object> data = price.getData(); + Double ordinary = Double.valueOf(data.get("ordinary").toString()); + Double precious = Double.valueOf(data.get("precious").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 = 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){ + orderLogistics.setOrderMoney(((cargoType == 1 ? ordinary : precious) * cargoNumber) + tipMoney); + orderLogistics.setTravelMoney((cargoType == 1 ? ordinary : precious) * cargoNumber); + } + orderLogistics.setDiscount(discount); + orderLogistics.setDiscountMoney(discountMoney); + orderLogistics.setActivityId(activityId); orderLogistics.setTipMoney(tipMoney); orderLogistics.setState(7);//待支付 orderLogistics.setInsertTime(new Date()); @@ -307,8 +339,8 @@ //添加消息 systemNoticeService.addSystemNotice(1, language == 1 ? "您的市内包裹订单已下单成功,我们正在为您指派司机,请稍后!" : - language == 2 ? "Your parcel order has been successfully placed, we are assigning a driver for you, please wait!" - : "Votre commande de colis a bien été passée, nous vous assignons un chauffeur, veuillez patienter!", orderLogistics.getUserId(), 1); + language == 2 ? "You've placed the delivery order successfully, we are assigning you a driver, please wait." + : "Vous avez passé la commande de livraison avec succès, nous vous attribuons un chauffeur, veuillez patienter.", orderLogistics.getUserId(), 1); BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setId(orderLogistics.getId()); @@ -366,22 +398,25 @@ - public ResultUtil<Map<String, Double>> getPrice1(Integer type, String startLon, String startLat, String endLon, String endLat, Integer language) throws Exception{ + public ResultUtil<Map<String, Object>> getPrice1(Integer type, String startLon, String startLat, String endLon, String endLat, Integer language) throws Exception{ Company query = companyCityService.query1(startLon, startLat); if(null == query){ return ResultUtil.error(language == 1 ? "预约取货点暂无企业服务" : language == 2 ? - "There is no enterprise service at the reservation pickup point" : "Prise de rendez-vous point de collecte pas encore disponible pour les entreprises"); + "No service yet at the reserved pickup point." : "Les points de ramassage prévus ne sont pas disponibles pour le moment."); } Double price1 = 0D; Double price2 = 0D; + Double discount = null; + Double discountMoney = 0D; + Integer activityId = null; if(type == 4){//同城 Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null); DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(startLat), Double.valueOf(startLon), Double.valueOf(endLat), Double.valueOf(endLon)); if(null == distancematrix){ - return ResultUtil.error(language == 1 ? "计算距离出错" : language == 2 ? "Error in distance calculation" : "Erreur de calcul des distances"); + return ResultUtil.error(language == 1 ? "计算距离出错" : language == 2 ? "Errors in computing distance" : "Erreurs dans le calcul de la distance"); } if(distancematrix.getDistance() == 0){ - return ResultUtil.error(language == 1 ? "未获取到有效的距离" : language == 2 ? "A valid distance was not obtained" : "La distance effective n’est pas acquise"); + return ResultUtil.error(language == 1 ? "未获取到有效的距离" : language == 2 ? "Not obtaining available distance" : "Ne pas obtenir la distance disponible"); } String content = String.valueOf(query1.get("content")); JSONObject jsonObject = JSON.parseObject(content); @@ -400,7 +435,7 @@ price1 = jsonObject.getDouble("num11"); } if(dist.compareTo(jsonObject.getDouble("num10")) > 0){ - return ResultUtil.error(language == 1 ? "超出可服务范围" : language == 2 ? "Out of service range" : "Au-delà du service disponible"); + return ResultUtil.error(language == 1 ? "超出可服务范围" : language == 2 ? "Beyond service range" : "Au-delà de la portée de service"); } }else{ Map<String, Object> query1 = systemPriceMapper.query(query.getId(), type, null); @@ -409,9 +444,23 @@ price1 = jsonObject.getDouble("num1"); price2 = jsonObject.getDouble("num2"); } - Map<String, Double> map = new HashMap<>(); + + //计算折扣 + UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(query.getId()); + if(null != query2){ + activityId = query2.getId(); + discount = query2.getLogistics(); + if(null != discount){ + discountMoney = new BigDecimal(price1).multiply(new BigDecimal(discount / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); + } + } + + Map<String, Object> map = new HashMap<>(); map.put("ordinary", price1);//普通 map.put("precious", price2);//贵重 + map.put("discount", discount);//折扣 + map.put("discountMoney", discountMoney);//折扣金额 + map.put("activityId", activityId);//折扣活动id return ResultUtil.success(map); } @@ -439,6 +488,7 @@ PushOrder pushOrder = pushOrderService.querys(i, 1, query.getId()).get(0); //获取空闲司机 List<Driver> list = driverService.queryIdleDriver(orderLogistics.getType(), null, orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 + System.err.println("【" + orderLogistics.getId() + "】空闲司机:" + JSON.toJSONString(list)); if(list.size() > 0){ double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) @@ -486,10 +536,10 @@ * @throws Exception */ @Override - public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId, Integer type, Integer language) throws Exception { + public ResultUtil payLogisticsOrder(Integer payType, Integer bankCardId, Integer orderId,Integer couponId, 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, no double payment is allowed" : "La commande a été payée, aucun paiement en double n’est autorisé", ""); + 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.", ""); } Integer uid = orderLogistics.getUserId(); Double orderMoney = orderLogistics.getOrderMoney(); @@ -498,6 +548,36 @@ } UserInfo userInfo = userInfoService.selectById(uid); ResultUtil resultUtil = ResultUtil.success(""); + orderLogistics.setCouponMoney(0D);//初始化历史数据 + orderLogistics.setCouponId(null); + //计算优惠券 + UserCouponRecord userCouponRecord = null; + if(null != couponId){ + 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.", ""); + } + if(userCouponRecord.getState() == 2){ + return ResultUtil.error(language == 1 ? "优惠券已使用" : language == 2 ? "Coupon has been used." : "Le coupon a été utilisé.", ""); + } + if(userCouponRecord.getState() == 3){ + return ResultUtil.error(language == 1 ? "优惠券已过期" : language == 2 ? "Coupon is expired." : "Le coupon a expiré.", ""); + } + if(userCouponRecord.getCouponUseType() != 0 && userCouponRecord.getCouponUseType() != 4){ + return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", ""); + } + if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ + return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", ""); + } + orderMoney = orderMoney - userCouponRecord.getMoney(); + orderLogistics.setCouponMoney(userCouponRecord.getMoney()); + orderLogistics.setCouponId(couponId); + } + //折扣 + if(null != orderLogistics.getActivityId()){ + orderMoney = orderMoney - orderLogistics.getDiscountMoney(); + } + orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); if(payType == 1) {//手机支付 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -553,13 +633,20 @@ if(payType == 3){//余额支付 if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ - return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient account balance" : "Solde de compte insuffisant", ""); + return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant", ""); } userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 + + //处理优惠券 + if(null != userCouponRecord){ + userCouponRecord.setState(2); + userCouponRecord.setEndTime(new Date()); + userCouponRecordService.updateById(userCouponRecord); + } //添加交易明细 transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId); @@ -576,15 +663,23 @@ pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0); } }).start(); + systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单支付,谢谢使用!" : language == 2 - ? "You have successfully completed the parcel order payment, thank you for using!" : - "Vous avez terminé avec succès le paiement de la commande de colis, merci de l’utiliser!", uid, 1); + ? "You've paid for the delivery order successfully, thank you for using I-GO" : + "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); this.pushOrder(orderLogistics);//推单 } if(payType == 4){//现金支付 SysIntegral query1 = sysIntegralMapper.query(orderLogistics.getCompanyId()); userInfo.setIntegral(userInfo.getIntegral() + (orderMoney.intValue() * query1.getIntegral()));//积分 + + //处理优惠券和红包 + if(null != userCouponRecord){ + userCouponRecord.setState(2); + userCouponRecord.setEndTime(new Date()); + userCouponRecordService.updateById(userCouponRecord); + } //添加交易明细 transactionDetailsService.saveData(uid, "包裹下单支付", orderMoney, 2, 1, 1, 4, orderId); @@ -594,173 +689,6 @@ orderLogistics.setDriverPay(1); orderLogistics.setPayType(4); orderLogistics.setPayMoney(orderMoney); - - if(ToolUtil.isNotEmpty(userInfo.getEmail())){ - new Thread(new Runnable() { - @Override - public void run() { - try { - String path = templatePath + "user/receiptLogistics.html"; - Document document = Jsoup.parse(new File(path), "UTF-8"); - SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); - Driver driver = driverService.selectById(orderLogistics.getDriverId()); - if(1 == language){ - document.getElementById("english").remove(); - document.getElementById("french").remove(); - Element title_chinese = document.getElementById("title_chinese"); - title_chinese.text(sdf2.format(orderLogistics.getTravelTime()) + ",您在I-GO1个订单消费GHS " + orderLogistics.getPayMoney()); - Element xcf_chinese = document.getElementById("xcf_chinese"); - xcf_chinese.text("GHS " + orderLogistics.getOrderMoney()); - Element xj_chinese = document.getElementById("xj_chinese"); - xj_chinese.text("GHS " + orderLogistics.getOrderMoney()); - Element pay_type_chinese = document.getElementById("pay_type_chinese"); - pay_type_chinese.text("现金"); - Element pay_money_chinese = document.getElementById("pay_money_chinese"); - pay_money_chinese.text("GHS " + orderLogistics.getPayMoney()); - Element pdf_chinese = document.getElementById("pdf_chinese"); - pdf_chinese.attr("href", "http://182.160.16.251:80/user/base/order/uploadReceiptPdf?orderId=" + orderId + "&orderType=4"); - Element lost_item_chinese = document.getElementById("lost_item_chinese"); - lost_item_chinese.attr("href", "http://182.160.16.251:81/mailbox/user/lossGoods.html?language=" + language + "&orderId=" + orderId + "&orderType=4"); -// Element track_chinese = document.getElementById("track_chinese"); -// track_chinese.attr("href", "http://182.160.16.251:81/mailbox/user/location.html"); - Element pay_time_chinese = document.getElementById("pay_time_chinese"); - pay_time_chinese.text(sdf1.format(orderLogistics.getTravelTime())); - Elements driver_chinese = document.getElementsByClass("driver_chinese"); - for (int i = 0; i < driver_chinese.size(); i++) { - Element element = driver_chinese.get(i); - element.text(driver.getFirstName() + "." + driver.getLastName()); - } - Element start_address_chinese = document.getElementById("start_address_chinese"); - start_address_chinese.text(orderLogistics.getStartAddress()); - Element end_address_chinese = document.getElementById("end_address_chinese"); - end_address_chinese.text(orderLogistics.getEndAddress()); - Phone phone = phoneService.selectOne(new EntityWrapper<Phone>().eq("type", 2).eq("companyId", driver.getCompanyId())); - Element server_tel_chinese = document.getElementById("server_tel_chinese"); - server_tel_chinese.attr("href", "tel:" + (null != phone ? phone.getPhone() : "")); - } - if(2 == language){ - document.getElementById("chinese").remove(); - document.getElementById("french").remove(); - Element title_english = document.getElementById("title_english"); - title_english.text(sdf2.format(orderLogistics.getTravelTime()) + ",You spent GHS " + orderLogistics.getPayMoney() + " on the trip "); - Element xcf_english = document.getElementById("xcf_english"); - xcf_english.text("GHS " + orderLogistics.getOrderMoney()); - Element xj_english = document.getElementById("xj_english"); - xj_english.text("GHS " + orderLogistics.getOrderMoney()); - Element pay_type_english = document.getElementById("pay_type_english"); - pay_type_english.text("cash"); - Element pay_money_english = document.getElementById("pay_money_english"); - pay_money_english.text("GHS " + orderLogistics.getPayMoney()); - Element pdf_english = document.getElementById("pdf_english"); - pdf_english.attr("href", "http://182.160.16.251:80/user/base/order/uploadReceiptPdf?orderId=" + orderId + "&orderType=4"); - Element lost_item_english = document.getElementById("lost_item_english"); - lost_item_english.attr("href", "http://182.160.16.251:81/mailbox/user/lossGoods.html?language=" + language + "&orderId=" + orderId + "&orderType=4"); -// Element track_english = document.getElementById("track_english"); -// track_english.attr("href", "http://182.160.16.251:81/mailbox/user/location.html"); - Element pay_time_english = document.getElementById("pay_time_english"); - pay_time_english.text(sdf1.format(orderLogistics.getTravelTime())); - Elements driver_english = document.getElementsByClass("driver_english"); - for (int i = 0; i < driver_english.size(); i++) { - Element element = driver_english.get(i); - element.text(driver.getFirstName() + "." + driver.getLastName()); - } - Element start_address_english = document.getElementById("start_address_english"); - start_address_english.text(orderLogistics.getStartAddress()); - Element end_address_english = document.getElementById("end_address_english"); - end_address_english.text(orderLogistics.getEndAddress()); - Phone phone = phoneService.selectOne(new EntityWrapper<Phone>().eq("type", 2).eq("companyId", driver.getCompanyId())); - Element server_tel_english = document.getElementById("server_tel_english"); - server_tel_english.attr("href", "tel:" + (null != phone ? phone.getPhone() : "")); - } - if(3 == language){ - document.getElementById("chinese").remove(); - document.getElementById("english").remove(); - Element title_french = document.getElementById("title_french"); - title_french.text(sdf2.format(orderLogistics.getTravelTime()) + ",Vous consommez GHS " + orderLogistics.getPayMoney() + " sur votre commande i-go1 le "); - Element xcf_french = document.getElementById("xcf_french"); - xcf_french.text("GHS " + orderLogistics.getOrderMoney()); - Element xj_french = document.getElementById("xj_french"); - xj_french.text("GHS " + orderLogistics.getOrderMoney()); - Element pay_type_french = document.getElementById("pay_type_french"); - pay_type_french.text("espèces"); - Element pay_money_french = document.getElementById("pay_money_french"); - pay_money_french.text("GHS " + orderLogistics.getPayMoney()); - Element pdf_french = document.getElementById("pdf_french"); - pdf_french.attr("href", "http://182.160.16.251:80/user/base/order/uploadReceiptPdf?orderId=" + orderId + "&orderType=4"); - Element lost_item_french = document.getElementById("lost_item_french"); - lost_item_french.attr("href", "http://182.160.16.251:81/mailbox/user/lossGoods.html?language=" + language + "&orderId=" + orderId + "&orderType=4"); -// Element track_french = document.getElementById("track_french"); -// track_french.attr("href", "http://182.160.16.251:81/mailbox/user/location.html"); - Element pay_time_french = document.getElementById("pay_time_french"); - pay_time_french.text(sdf1.format(orderLogistics.getTravelTime())); - Elements driver_french = document.getElementsByClass("driver_french"); - for (int i = 0; i < driver_french.size(); i++) { - Element element = driver_french.get(i); - element.text(driver.getFirstName() + "." + driver.getLastName()); - } - Element start_address_french = document.getElementById("start_address_french"); - start_address_french.text(orderLogistics.getStartAddress()); - Element end_address_french = document.getElementById("end_address_french"); - end_address_french.text(orderLogistics.getEndAddress()); - Phone phone = phoneService.selectOne(new EntityWrapper<Phone>().eq("type", 2).eq("companyId", driver.getCompanyId())); - Element server_tel_french = document.getElementById("server_tel_french"); - server_tel_french.attr("href", "tel:" + (null != phone ? phone.getPhone() : "")); - } - - EmailUtil.send(userInfo.getEmail(), language == 1 ? "包裹收据" : language == 2 ? "Parcel receipt" : "Réception de colis", document.html()); - - //开始生成pdf收据和html收据 - File file = new File("/usr/local/nginx/html/files/html/"); - if(!file.exists()){ - file.mkdirs(); - } - file = new File("/usr/local/nginx/html/files/html/parcel_receipt_" + orderId + ".html"); - if(!file.exists()){ - file.createNewFile(); - } - FileWriter fileWriter = new FileWriter(file); - fileWriter.write(document.html()); - fileWriter.flush(); - fileWriter.close(); - FileInputStream fileInputStream = new FileInputStream(file); - File file1 = new File("/usr/local/nginx/html/files/pdf/"); - if(!file1.exists()){ - file1.mkdirs(); - } - file1 = new File("/usr/local/nginx/html/files/pdf/parcel_receipt_" + orderId + ".pdf"); - if(!file1.exists()){ - file1.createNewFile(); - } - FileOutputStream fileOutputStream = new FileOutputStream(file1); - HtmlToPdfUtils.convertToPdf(fileInputStream, "IGO", fileOutputStream); - - String link ="http://182.160.16.251:81/files/html/parcel_receipt_" + orderId + ".html"; - TEmail tEmail = new TEmail(); - tEmail.setLink(link); - tEmail.setUserId(uid); - tEmail.setType(1); - tEmail.setName(language == 1 ? "包裹收据" : language == 2 ? "Parcel receipt" : "Réception de colis"); - tEmail.setOrderId(orderId); - tEmail.setCreateTime(new Date()); - int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date())-1; - String week = EmailUtil.getWeek(language, i); - tEmail.setWeek(week); - boolean am = cn.hutool.core.date.DateUtil.isAM(new Date()); - if(am){ - tEmail.setAmOrPm(language==1?"上午":language==2?"AM":"Dans la matinée"); - }else { - tEmail.setAmOrPm(language==1?"下午":language==2?"PM":"après-midi"); - } - emailService.insert(tEmail); - - }catch (Exception e){ - e.printStackTrace(); - } - } - }).start(); - } - // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 new Thread(new Runnable() { @@ -772,8 +700,8 @@ }).start(); systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单支付,谢谢使用!" : language == 2 - ? "You have successfully completed the parcel order payment, thank you for using!" : - "Vous avez terminé avec succès le paiement de la commande de colis, merci de l’utiliser!", uid, 1); + ? "You've paid for the delivery order successfully, thank you for using I-GO" : + "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); this.pushOrder(orderLogistics);//推单 } @@ -841,7 +769,7 @@ if(payType == 3){//余额支付 if(userInfo.getBalance() == null || userInfo.getBalance() < orderMoney){ - return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient account balance" : "Solde de compte insuffisant"); + return ResultUtil.error(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant"); } userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(orderMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); @@ -897,8 +825,8 @@ }).start(); systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单差价支付,谢谢使用!" : language == 2 - ? "You have successfully completed the difference payment of parcel order, thank you for using!" - : "Vous avez complété avec succès le paiement de la différence de commande de colis, merci de l’utiliser!", uid, 1); + ? "You've paid for the difference of delivery order successfully, thank you for using I-GO" + : "Vous avez payé la différence de commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); } if(payType == 4){//现金支付 @@ -919,30 +847,31 @@ 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); - c = new BigDecimal(orderMoney).subtract(d); - } - if(company.getIsSpeFixedOrProportional() == 1){//比例 - d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); - c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); - } - - Income income = incomeService.selectOne(new EntityWrapper<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.getCompanyId()).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); +// Company company = companyService.selectById(orderLogistics.getCompanyId()); +// Double speMoney = orderLogistics.getType() == 4 ? company.getSameLogisticsMoney() : company.getCrossLogisticsMoney(); +// BigDecimal d = BigDecimal.ZERO; +// BigDecimal c = BigDecimal.ZERO; +// if(company.getIsSpeFixedOrProportional() == 2){//固定 +// d = new BigDecimal(speMoney); +// c = new BigDecimal(orderMoney).subtract(d); +// } +// if(company.getIsSpeFixedOrProportional() == 1){//比例 +// d = new BigDecimal(orderMoney).multiply(new BigDecimal(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN))); +// c = new BigDecimal(orderMoney).subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN); +// } +// +// Income income = incomeService.selectOne(new EntityWrapper<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.getCompanyId()).eq("type", 2).eq("incomeId", orderLogistics.getId()).eq("orderType", orderLogistics.getType())); +// System.out.println("小件物流补差价income======"+income); +// 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() { @@ -954,8 +883,8 @@ }).start(); systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单差价支付,谢谢使用!" : language == 2 - ? "You have successfully completed the difference payment of parcel order, thank you for using!" - : "Vous avez complété avec succès le paiement de la différence de commande de colis, merci de l’utiliser!", uid, 1); + ? "You've paid for the difference of delivery order successfully, thank you for using I-GO" + : "Vous avez payé la différence de commande de livraison avec succès, merci d’utiliser I-GO", uid, 1); } @@ -982,6 +911,14 @@ 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); + } + query.setState(2); query.setCode(order_id); paymentRecordService.updateById(query); @@ -996,8 +933,8 @@ systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单支付,谢谢使用!" : language == 2 - ? "You have successfully completed the parcel order payment, thank you for using!" : - "Vous avez terminé avec succès le paiement de la commande de colis, merci de l’utiliser!", orderLogistics.getUserId(), 1); + ? "You've paid for the delivery order successfully, thank you for using I-GO" : + "Vous avez payé la commande de livraison avec succès, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); this.pushOrder(orderLogistics);//推单 }else{ @@ -1071,8 +1008,8 @@ }).start(); systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功完成包裹订单差价支付,谢谢使用!" : language == 2 - ? "You have successfully completed the difference payment of parcel order, thank you for using!" - : "Vous avez complété avec succès le paiement de la différence de commande de colis, merci de l’utiliser!", orderLogistics.getUserId(), 1); + ? "You've paid for the difference of delivery order successfully, thank you for using I-GO" + : "Vous avez payé la différence de commande de livraison avec succès, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); }else{ System.err.println("预支付数据异常(orderId = " + id + ")"); } @@ -1107,12 +1044,25 @@ pageNum = (pageNum - 1) * size; List<Map<String, Object>> maps = orderLogisticsMapper.queryMyOrderList(uid, pageNum, size, language); for (Map<String, Object> map : maps) { + if(null != map.get("orderTime")){ + String orderTime = map.get("orderTime").toString(); + map.put("orderTime", DateUtil.conversionFormat(language, orderTime)); + } + if(null != map.get("time")){ + String time = map.get("time").toString(); + map.put("time", DateUtil.conversionFormat(language, time)); + } Integer orderId = Integer.valueOf(String.valueOf(map.get("orderId"))); Integer state = Integer.valueOf(String.valueOf(map.get("state"))); if(state == 6){ map.put("receipt", "http://182.160.16.251:81/files/html/parcel_receipt_" + orderId + ".html"); }else{ map.put("receipt", ""); + } + if(state == 7){ + Double discountMoney = Double.valueOf(map.get("discountMoney").toString()); + Double orderMoney = Double.valueOf(map.get("orderMoney").toString()); + map.put("orderMoney", orderMoney - discountMoney); } } return maps; @@ -1125,22 +1075,37 @@ * @return */ @Override - public List<Map<String, Object>> queryMyTravelRecord(Integer uid) { - return orderLogisticsMapper.queryMyTravelRecord(uid); + public List<Map<String, Object>> queryMyTravelRecord(Integer language, Integer uid) { + List<Map<String, Object>> list = orderLogisticsMapper.queryMyTravelRecord(uid); + for (Map<String, Object> map : list) { + if(null != map.get("time")){ + String time = map.get("time").toString(); + map.put("time", DateUtil.conversionFormat(language, time)); + } + } + return list; } @Override - public List<Map<String, Object>> queryInvoiceOrder(Integer type, Date startTime, Date endTime, Double startMoney, Double endMoney, Integer uid, Integer orderType) throws Exception { + public List<Map<String, Object>> queryInvoiceOrder(Integer language, Integer type, Date startTime, Date endTime, Double startMoney, Double endMoney, Integer uid, Integer orderType) throws Exception { startTime = dateUtil.getStartOrEndDate(startTime, "start"); endTime = dateUtil.getStartOrEndDate(endTime, "end"); - return orderLogisticsMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid, orderType); + List<Map<String, Object>> list = orderLogisticsMapper.queryInvoiceOrder(type, startTime, endTime, startMoney, endMoney, uid, orderType); + for (Map<String, Object> map : list) { + map.put("orderName", language == 1 ? "包裹订单" : language == 2 ? "Delivery" : "Livraison"); + if(null != map.get("time")){ + String time = map.get("time").toString(); + map.put("time", DateUtil.conversionFormat(language, time)); + } + } + return list; } @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); @@ -1154,106 +1119,59 @@ OrderLogistics orderLogistics = this.selectById(id); Integer integer = null; if(null == orderLogistics){ - return ResultUtil.error(language == 1 ? "取消订单失败,订单信息有误" : language == 2 ? "Failed to cancel the order, the order information is incorrect" : "Échec de l'annulation de la commande, les informations de la commande sont incorrectes"); + 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){ - return ResultUtil.error(language == 1 ? "取消订单失败,不合法的操作" : language == 2 ? "Cancel order failed, illegal operation" : "Échec de l'annulation de la commande, opération illégale"); + 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); - 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()); + }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); } - 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(), 1, 2); - 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()); + 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()){ @@ -1266,8 +1184,8 @@ } //添加消息 - systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功取消包裹订单,谢谢使用!" : language == 2 ? "You have successfully cancelled your parcel order, thank you for using!" - : "Vous avez annulé avec succès votre commande de colis, merci de l’utiliser!", orderLogistics.getUserId(), 1); + systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功取消包裹订单,谢谢使用!" : language == 2 ? "You've cancelled the delivery order successfully, thank you for using I-GO " + : "Vous avez annulé la commande de livraison avec succès, merci d’utiliser I-GO", orderLogistics.getUserId(), 1); Map<String, Object> map = new HashMap<>(); map.put("id", integer); return ResultUtil.success(map); @@ -1322,13 +1240,31 @@ Map<String, Object> map = new HashMap<>(); UserInfo userInfo = userInfoService.selectById(uid); map.put("balance", userInfo.getBalance()); - map.put("coupon", 0); + OrderLogistics orderLogistics = this.selectById(orderId); + UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderLogistics.getCompanyId()); + double v = orderLogistics.getOrderMoney(); + if(null != query2){ + Integer orderNum=this.selectCount(new EntityWrapper<OrderLogistics>().eq("userId",orderLogistics.getUserId()).eq("activityId",query2.getId()).last(" and to_days(getoffTime) = to_days(now())")); + if(query2.getDistance()*1000>orderLogistics.getMileage() && query2.getOrderNum()>orderNum){ + Double special = query2.getSpecial(); + orderLogistics.setDiscount(special); + Double orderMoney = orderLogistics.getOrderMoney(); + v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); + } + } + int i = userCouponRecordService.queryAvailable(uid, orderLogistics.getCompanyId(), 1, 4, v); + i = i + userCouponRecordService.queryAvailable(uid, orderLogistics.getCompanyId(), 1, 0, v); + map.put("coupon", i); return map; } @Override - public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception { + public Map<String, Object> queryOrderInfo(Integer language, Integer orderId) throws Exception { Map<String, Object> map = orderLogisticsMapper.queryOrderInfo(orderId); + if(null != map.get("travelTime")){ + String travelTime = map.get("travelTime").toString(); + map.put("travelTime", DateUtil.conversionFormat1(language, travelTime)); + } Integer state = Integer.valueOf(String.valueOf(map.get("state"))); OrderLogistics orderLogistics = this.selectById(orderId); if(null != map.get("reassignNotice") && Integer.valueOf(String.valueOf(map.get("reassignNotice"))) == 2){//改派完成,重新获取了新的司机数据,开始修改数据防止继续调用 @@ -1361,11 +1297,303 @@ @Override - public List<Map<String, Object>> queryCoupon(Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { + public List<Map<String, Object>> queryCoupon(Integer language, Integer orderId, Integer uid, Integer pageNum, Integer size) throws Exception { OrderLogistics orderLogistics = this.selectById(orderId); - List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney(), pageNum, size); - List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney(), pageNum, size); + List<Map<String, Object>> list = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 4, orderLogistics.getOrderMoney() - orderLogistics.getDiscountMoney(), pageNum, size); + List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(language, uid, orderLogistics.getCompanyId(), 1, 0, orderLogistics.getOrderMoney() - orderLogistics.getDiscountMoney(), pageNum, size); 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