From c4650572e6dc6c6efb6e1c61c11dcae0706105c7 Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期二, 04 六月 2024 21:11:20 +0800 Subject: [PATCH] Merge branch '2.0' of http://120.76.84.145:10101/gitblit/r/java/IgoTravel into 2.0 --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 175 insertions(+), 47 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java index d9f38a1..bbcb17b 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java @@ -20,6 +20,7 @@ import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.*; import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo; +import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil; import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil; import com.stylefeng.guns.modular.system.util.GoogleMap.ReverseGeocodeVo; import com.stylefeng.guns.modular.system.util.Tingg.TinggPayUtil; @@ -196,6 +197,18 @@ @Autowired private IPhoneService phoneService; + + @Autowired + private IRedEnvelopePaymentSettingsService redEnvelopePaymentSettingsService; + + @Autowired + private FleetEngineUtil fleetEngineUtil; + + @Resource + private CarModelMapper carModelMapper; + + @Autowired + private ICarService carService; @@ -342,6 +355,26 @@ orderPrivateCar.setIsReassign(1); orderPrivateCar.setIsDelete(1); this.insert(orderPrivateCar); + + + Integer vehicleId = null; + if(null != orderPrivateCar.getDriverId()){ + Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); + vehicleId = driver.getCarId(); + //查询车辆信息,没有则创建信息 + String vehicles = fleetEngineUtil.getVehicles(vehicleId); + if(ToolUtil.isEmpty(vehicles)){ + Car car = carService.selectById(vehicleId); + CarModel carModel = carModelMapper.selectById(car.getCarModelId()); + fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), driver.getCarId()); + fleetEngineUtil.updateVehicles("ONLINE", carModel.getSeat() - 1, car.getCarLicensePlate(), driver.getCarId()); + } + + } + //创建行程数据 + fleetEngineUtil.createTrip(vehicleId, 1, 1, orderPrivateCar.getId(), + orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(), orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString()); + if(orderSource == 2){//扫码下单 new Thread(new Runnable() { @@ -349,7 +382,6 @@ public void run() { pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); - pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); } }).start(); } @@ -426,7 +458,6 @@ public void run() { pushUtil.pushOrderState(1, uid, orderPrivateCar.getId(), 1, 2, 0); pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderPrivateCar.getId(), 1, 2, 0); - pushUtil.pushDriverPosition(orderPrivateCar.getId(), 1); } }).start(); } @@ -438,21 +469,21 @@ if(orderPrivateCar.getState() == 1){ this.pushOrder(orderPrivateCar); }else{ - //接单后定时任务判断司机是否去接乘客,没有则推送提醒 - CancleOrder cancleOrder = cancleOrderService.query(orderPrivateCar.getCompanyId()); - if(null != cancleOrder){ - JSONObject object = JSON.parseObject(cancleOrder.getContent()); - long time = object.getInteger("driverTimeout") * 60000L; - new Timer().schedule(new TimerTask() { - @Override - public void run() { - OrderPrivateCar orderPrivateCar1 = OrderPrivateCarServiceImpl.this.selectById(orderPrivateCar.getId()); - if(orderPrivateCar1.getState() == 2){ - pushUtil.pushDriverTimeOut(1, orderPrivateCar1.getUserId(), orderPrivateCar1.getId(), 1); - } - } - }, time); - } +// //接单后定时任务判断司机是否去接乘客,没有则推送提醒 +// CancleOrder cancleOrder = cancleOrderService.query(orderPrivateCar.getCompanyId()); +// if(null != cancleOrder){ +// JSONObject object = JSON.parseObject(cancleOrder.getContent()); +// long time = object.getInteger("driverTimeout") * 60000L; +// new Timer().schedule(new TimerTask() { +// @Override +// public void run() { +// OrderPrivateCar orderPrivateCar1 = OrderPrivateCarServiceImpl.this.selectById(orderPrivateCar.getId()); +// if(orderPrivateCar1.getState() == 2){ +// pushUtil.pushDriverTimeOut(1, orderPrivateCar1.getUserId(), orderPrivateCar1.getId(), 1); +// } +// } +// }, time); +// } } @@ -651,6 +682,7 @@ orderPrivateCar.setGetoffAddress(address); orderPrivateCar.setGetoffTime(new Date()); orderPrivateCar.setEndServiceTime(new Date()); + orderPrivateCar.setCancelMidway(1); }else{ orderPrivateCar.setState(10); } @@ -662,6 +694,7 @@ orderPrivateCar.setGetoffAddress(address); orderPrivateCar.setGetoffTime(new Date()); orderPrivateCar.setEndServiceTime(new Date()); + orderPrivateCar.setCancelMidway(1); } orderPrivateCar.setOldState(6); orderPrivateCar.setState(12); @@ -683,6 +716,10 @@ driver.setState(2); driverService.updateById(driver); } + + //修改行程信息 + fleetEngineUtil.updateTrip("CANCELED", null, null, 1, orderPrivateCar.getId(), null, null, null, null); + //添加消息 systemNoticeService.addSystemNotice(1, language == 1 ? "您已成功取消出行订单,谢谢使用!" : language == 2 ? "You've cancelled the ride order successfully, thank you for using I-GO " : "Vous avez annulé la commande de course avec succès, merci d’utiliser I-GO", orderPrivateCar.getUserId(), 1); @@ -957,7 +994,7 @@ @Override - public ResultUtil payPrivateCarOrder(Integer payType, Integer bankCardId, Integer orderId, Integer couponId, Integer type, Integer language) throws Exception { + public ResultUtil payPrivateCarOrder(Integer payType, Integer bankCardId, Integer orderId, Integer couponId, Integer redDeduction, Integer type, Integer language) throws Exception { OrderPrivateCar orderPrivateCar = this.selectById(orderId); if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ 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.", ""); @@ -991,6 +1028,9 @@ //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ + if(null != redDeduction && 1 == redDeduction){ + return ResultUtil.error(language == 1 ? "优惠券和红包不能同时使用" : language == 2 ? "Coupons and lucky-promo cannot be used at the same time." : "Les coupons et les bonus ne peuvent pas être utilisés en même temps", ""); + } userCouponRecord = userCouponRecordService.selectById(couponId); if(!userCouponRecord.getCompanyId().equals(orderPrivateCar.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.", ""); @@ -1014,12 +1054,62 @@ orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); //计算红包 - UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderPrivateCar.getCompanyId(), 1, 1, orderMoney); - if(null != query && query.getMoney().compareTo(orderMoney) < 0){ - orderMoney = orderMoney - query.getMoney(); - orderPrivateCar.setRedPacketMoney(query.getMoney()); - orderPrivateCar.setRedPacketId(query.getId()); + 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", orderPrivateCar.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))); + orderPrivateCar.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; + } + } + orderPrivateCar.setRedPacketId(jsonArray.toJSONString()); + }else{ + orderPrivateCar.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; + } + } + orderPrivateCar.setRedPacketId(jsonArray.toJSONString()); + } + } } + if(payType == 1){//手机支付 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -1089,18 +1179,29 @@ orderPrivateCar.setPayType(3); orderPrivateCar.setPayMoney(orderMoney); orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); - + //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } - if(null != query){ - query.setState(2); - query.setEndTime(new Date()); - userRedPacketRecordService.updateById(query); + if(null != orderPrivateCar.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.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); + } } + if(orderPrivateCar.getIsplatPay()==1){ //添加已收入明细 Company company = companyService.selectById(orderPrivateCar.getCompanyId()); @@ -1445,18 +1546,28 @@ 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 != query){ - query.setState(2); - query.setEndTime(new Date()); - userRedPacketRecordService.updateById(query); - - Double money = query.getMoney(); + if(null != orderPrivateCar.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.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 = orderPrivateCar.getRedPacketMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 7, orderPrivateCar.getId(), 1, 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 != orderPrivateCar.getDiscountMoney() && 0 < orderPrivateCar.getDiscountMoney()){ Double money = orderPrivateCar.getDiscountMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, money); @@ -1508,7 +1619,8 @@ Double maxPrice = jsonObject.getDouble("maxPrice"); Integer type1 = jsonObject.getInteger("type"); if(1 == type1){ - List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", driver.getId()).isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')")); + List<SettlementDetail> settlementDetailList = settlementDetailService.selectList(new EntityWrapper<SettlementDetail>().eq("driverId", driver.getId()) + .isNull("settlementRecordId").last(" and DATE_FORMAT(now(), '%Y-%m-%d') = DATE_FORMAT(createTime, '%Y-%m-%d')")); BigDecimal total = new BigDecimal(0); for (SettlementDetail detail : settlementDetailList) { total = total.add(new BigDecimal(detail.getPrice())); @@ -1849,10 +1961,7 @@ }else{//随机金额 Double startMoney = Double.valueOf(String.valueOf(query.get("startMoney"))); Double endMoney = Double.valueOf(String.valueOf(query.get("endMoney"))); - int i = new BigDecimal(endMoney).subtract(new BigDecimal(startMoney)).intValue(); - Random random = new Random(); - int num = random.nextInt(i); - money = new BigDecimal(startMoney).add(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); + money = new BigDecimal(startMoney + (Math.random() * (endMoney - startMoney))).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); } //判断当前红包是否大于剩余可领取总金额 if(money.compareTo(Double.valueOf(query.get("lavePrice").toString())) > 0){ @@ -1867,10 +1976,10 @@ //添加临时红包数据 UserRedPacketRecord userRedPacketRecord = new UserRedPacketRecord(); userRedPacketRecord.setMoney(money); + userRedPacketRecord.setRemainingAmount(money); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(String.valueOf(query.get("effective")))); - userRedPacketRecord.setExpirationTime(calendar.getTime()); userRedPacketRecord.setInsertTime(new Date()); userRedPacketRecord.setCompanyId(Integer.valueOf(String.valueOf(query.get("companyId")))); userRedPacketRecord.setState(0); @@ -1908,6 +2017,9 @@ query.setState(1); query.setRedPacketActivityId(id.getId()); userRedPacketRecordService.updateById(query); + + String content = 1 == language ? ("您收到一个额度为GHS " + money + " 的红包,请查收") : 2 == language ? "You have received a lucky promo of GHS " + money + ", please check" : "Vous avez reçu un bonus de GHS " + money + ", veuillez vérifier"; + systemNoticeService.addSystemNotice(1, content, query.getUserId(), 1); UserInfo userInfo = userInfoService.selectById(orderPrivateCar.getUserId()); if(ToolUtil.isNotEmpty(userInfo.getEmail())){ @@ -1921,7 +2033,7 @@ Element user_chinese = document.getElementById("user_chinese"); user_chinese.text("您好 " + userInfo.getNickName() + ","); Element time_chinese = document.getElementById("time_chinese"); - time_chinese.text("此活动有效期在 " + DateUtil.conversionFormat(language, sdf.format(query.getInsertTime())) + " 至 " + DateUtil.conversionFormat(language, sdf.format(query.getExpirationTime())) + ",详情请查看I-GO平台"); + time_chinese.text("此活动有效期在 " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " 至 " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ",详情请查看I-GO平台"); } if(2 == language){ document.getElementById("chinese").remove(); @@ -1930,7 +2042,7 @@ Element user_english = document.getElementById("user_english"); user_english.text("Hello " + userInfo.getNickName() + ","); Element time_english = document.getElementById("time_english"); - time_english.text("You could use it from " + DateUtil.conversionFormat(language, sdf.format(query.getInsertTime())) + " to " + DateUtil.conversionFormat(language, sdf.format(query.getExpirationTime())) + ",check more details on the app."); + time_english.text("You could use it from " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " to " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ",check more details on the app."); } if(3 == language){ document.getElementById("chinese").remove(); @@ -1939,7 +2051,7 @@ Element user_french = document.getElementById("user_french"); user_french.text("Bonjour " + userInfo.getNickName() + ","); Element time_french = document.getElementById("time_french"); - time_french.text("Cette promotion est valable du " + DateUtil.conversionFormat(language, sdf.format(query.getInsertTime())) + " au " + DateUtil.conversionFormat(language, sdf.format(query.getExpirationTime())) + ". Veuillez consulter la plateforme i-go pour plus de détails."); + time_french.text("Cette promotion est valable du " + DateUtil.conversionFormat(language, sdf.format(id.getStartTime())) + " au " + DateUtil.conversionFormat(language, sdf.format(id.getEndTime())) + ". Veuillez consulter la plateforme i-go pour plus de détails."); } EmailUtil.send(userInfo.getEmail(), language == 1 ? "红包活动" : language == 2 ? "Lucky-promo activities" : "Activités bonus", document.html()); @@ -2067,10 +2179,19 @@ userCouponRecordService.updateById(userCouponRecord); } if(null != orderPrivateCar.getRedPacketId()){ - UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderPrivateCar.getRedPacketId()); - userRedPacketRecord.setState(2); - userRedPacketRecord.setEndTime(new Date()); - userRedPacketRecordService.updateById(userRedPacketRecord); + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.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); + } } @@ -2487,6 +2608,13 @@ }else{ map.put("receipt", ""); } + Integer companyId = 1; + if(null != map.get("driverId")){ + companyId = Integer.valueOf(String.valueOf(map.get("companyId"))); + } + CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", companyId)); + JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent()); + map.put("timeOutCancel", jsonObject.getIntValue("driverTimeout")); return map; } -- Gitblit v1.7.1