| | |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.GpsCoordinateUtils; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.crossCity.dao.LinePriceMapper; |
| | | import com.stylefeng.guns.modular.crossCity.dao.LineShiftDriverMapper; |
| | |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.stylefeng.guns.modular.taxi.service.impl.OrderTaxiServiceImpl.orderIds; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Map<String, Object> queryBalance(Integer orderId, Integer uid) throws Exception { |
| | | System.err.println(orderId); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | map.put("balance", userInfo.getBalance()); |
| | | OrderCrossCity orderCrossCity = this.selectById(orderId); |
| | | int i = userCouponRecordService.queryAvailable(uid, orderCrossCity.getCompanyId(), 1, 3, orderCrossCity.getOrderMoney()); |
| | | i = i + userCouponRecordService.queryAvailable(uid, orderCrossCity.getCompanyId(), 1, 0, orderCrossCity.getOrderMoney()); |
| | | map.put("coupon", i); |
| | | List<Map<String, Object>> list = userCouponRecordService.queryAvailable_(uid, orderCrossCity.getCompanyId(), 1, 3, orderCrossCity.getOrderMoney()); |
| | | List<Map<String, Object>> list1 = userCouponRecordService.queryAvailable_(uid, orderCrossCity.getCompanyId(), 1, 0, orderCrossCity.getOrderMoney()); |
| | | list.addAll(list1); |
| | | Iterator<Map<String, Object>> iterator = list.iterator(); |
| | | System.err.println(list); |
| | | while (iterator.hasNext()){ |
| | | Map<String, Object> next = iterator.next(); |
| | | if(next.get("type").equals(2) && (Double.valueOf(next.get("money").toString()) > orderCrossCity.getOrderMoney() |
| | | || Double.valueOf(next.get("fullMoney").toString()) > orderCrossCity.getOrderMoney())){ |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | map.put("coupon", list.size()); |
| | | return map; |
| | | } |
| | | |
| | |
| | | List<Map<String, Object>> list = userCouponRecordService.queryCoupon(uid, orderCrossCity.getCompanyId(), 1, 3, orderCrossCity.getOrderMoney(), pageNum, size); |
| | | List<Map<String, Object>> list1 = userCouponRecordService.queryCoupon(uid, orderCrossCity.getCompanyId(), 1, 0, orderCrossCity.getOrderMoney(), pageNum, size); |
| | | list.addAll(list1); |
| | | return list; |
| | | Iterator<Map<String, Object>> iterator = list.iterator(); |
| | | System.err.println(list); |
| | | while (iterator.hasNext()){ |
| | | Map<String, Object> next = iterator.next(); |
| | | if(next.get("type").equals(2) && (Double.valueOf(next.get("money").toString()) > orderCrossCity.getOrderMoney() |
| | | || Double.valueOf(next.get("fullMoney").toString()) > orderCrossCity.getOrderMoney())){ |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | if(CollectionUtils.isEmpty(list)){ |
| | | return list; |
| | | } |
| | | List<Integer> ids = list.stream().map(map -> Integer.parseInt(map.get("id").toString())).collect(Collectors.toList()); |
| | | List<Map<String, Object>> result = userCouponRecordService.queryCouponCrossCity(ids, pageNum, size); |
| | | System.err.println(result); |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | Integer uid = orderCrossCity.getUserId(); |
| | | Double orderMoney = orderCrossCity.getOrderMoney(); |
| | | System.err.println(orderMoney); |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | ResultUtil resultUtil = ResultUtil.success(""); |
| | | orderCrossCity.setCouponMoney(0D);//初始化历史数据 |
| | | orderCrossCity.setCouponId(null); |
| | | |
| | | //计算优惠券 |
| | | BigDecimal payMoney = new BigDecimal(0); |
| | | UserCouponRecord userCouponRecord = null; |
| | | if(null != couponId){ |
| | | userCouponRecord = userCouponRecordService.selectById(couponId); |
| | |
| | | if(userCouponRecord.getCouponType() == 2 && orderMoney.compareTo(userCouponRecord.getFullMoney()) < 0){ |
| | | return ResultUtil.error("优惠券不能用于此订单", ""); |
| | | } |
| | | orderMoney = orderMoney - userCouponRecord.getMoney(); |
| | | payMoney = new BigDecimal(orderMoney.toString()).subtract(new BigDecimal(userCouponRecord.getMoney())); |
| | | System.err.println(payMoney); |
| | | orderCrossCity.setCouponMoney(userCouponRecord.getMoney()); |
| | | orderCrossCity.setCouponId(couponId); |
| | | } |
| | | |
| | | if(payMoney.compareTo(new BigDecimal(0)) == 0 ){ |
| | | payMoney = new BigDecimal(orderMoney.toString()); |
| | | } |
| | | //计算红包 |
| | | UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderCrossCity.getCompanyId(), 1, 3, orderMoney); |
| | | if(null != query && orderMoney.compareTo(query.getMoney()) > 0){ |
| | | orderMoney = orderMoney - query.getMoney(); |
| | | orderCrossCity.setRedPacketMoney(query.getMoney()); |
| | | orderCrossCity.setRedPacketId(query.getId()); |
| | | } |
| | | |
| | | //计算折扣 |
| | | UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderCrossCity.getCompanyId()); |
| | | if(null != query2){ |
| | | Double special = query2.getSpecial(); |
| | | orderCrossCity.setDiscount(special); |
| | | double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | if(orderMoney.compareTo(v) > 0){ |
| | | orderCrossCity.setDiscountMoney(orderMoney - v); |
| | | orderCrossCity.setActivityId(query2.getId()); |
| | | orderMoney = v; |
| | | } |
| | | } |
| | | |
| | | // if(null != query && orderMoney.compareTo(query.getMoney()) > 0){ |
| | | // orderMoney = orderMoney - query.getMoney(); |
| | | // orderCrossCity.setRedPacketMoney(query.getMoney()); |
| | | // orderCrossCity.setRedPacketId(query.getId()); |
| | | // } |
| | | // |
| | | // //计算折扣 |
| | | // UserActivityDiscount1 query2 = userActivityDiscount1Mapper.query(orderCrossCity.getCompanyId()); |
| | | // if(null != query2){ |
| | | // Double special = query2.getSpecial(); |
| | | // orderCrossCity.setDiscount(special); |
| | | // double v = new BigDecimal(orderMoney).multiply(new BigDecimal(special / 10)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | | // if(orderMoney.compareTo(v) > 0){ |
| | | // orderCrossCity.setDiscountMoney(orderMoney - v); |
| | | // orderCrossCity.setActivityId(query2.getId()); |
| | | // orderMoney = v; |
| | | // } |
| | | // } |
| | | if(payType == 1){//微信支付 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String appletsOpenId = null; |
| | |
| | | // resultUtil = ResultUtil.error(map.get("msg"), ""); |
| | | // } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_3_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, orderMoney, "", 1);//添加预支付数据 |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_3_" + UUIDUtil.getRandomCode(5), payMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, Double.valueOf(payMoney.toString()), "", 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | Map<String, String> map = icbcPayUtil.placeAnOrder(orderId + ",3", 10, 5, uid.toString(), "完成订单", orderMoney, callbackPath + "/base/aliPayOrderTaxi", "", type, null); |
| | |
| | | // driverService.updateById(driver); |
| | | |
| | | Company company = companyService.selectById(driver.getFranchiseeId()); |
| | | if(Objects.isNull(company)){ |
| | | company = companyService.selectById(driver.getCompanyId()); |
| | | } |
| | | // 司机收入 |
| | | double moneyTwo; |
| | | // 平台收入 |
| | | double money; |
| | | if(orderCrossCity.getOrderSource() == 2 || orderCrossCity.getOrderSource() == 3){ |
| | | double v = company.getPercentageDeduction() / 100; |
| | | money = v * orderCrossCity.getOrderMoney(); |
| | | moneyTwo = orderCrossCity.getOrderMoney()-money; |
| | | }else { |
| | | money = company.getFixedDeduction(); |
| | | moneyTwo = orderCrossCity.getOrderMoney()-money; |
| | | } |
| | | driver.setBalance(driver.getBalance() + moneyTwo); |
| | | // 新增扣除使用费记录 |
| | | transactionDetailsService.saveDataTaxi(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderCrossCity.getId(),placeOrderWay,company.getId()); |
| | | // 司机订单收入 |
| | | transactionDetailsService.saveDataTaxi(driver.getId(), "完成订单", moneyTwo, 1, 1, 2, 3, orderCrossCity.getId(),placeOrderWay,company.getId()); |
| | | |
| | | driverService.updateById(driver); |
| | | // if(Objects.isNull(company)){ |
| | | // company = companyService.selectById(driver.getCompanyId()); |
| | | // } |
| | | // // 司机收入 |
| | | // double moneyTwo; |
| | | // // 平台收入 |
| | | // double money; |
| | | // if(orderCrossCity.getOrderSource() == 2 || orderCrossCity.getOrderSource() == 3){ |
| | | // double v = company.getPercentageDeduction() / 100; |
| | | // money = v * orderCrossCity.getOrderMoney(); |
| | | // moneyTwo = orderCrossCity.getOrderMoney()-money; |
| | | // }else { |
| | | // money = company.getFixedDeduction(); |
| | | // moneyTwo = orderCrossCity.getOrderMoney()-money; |
| | | // } |
| | | // driver.setBalance(driver.getBalance() + moneyTwo); |
| | | // // 新增扣除使用费记录 |
| | | // transactionDetailsService.saveDataTaxi(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderCrossCity.getId(),placeOrderWay,company.getId()); |
| | | // // 司机订单收入 |
| | | // transactionDetailsService.saveDataTaxi(driver.getId(), "完成订单", moneyTwo, 1, 1, 2, 3, orderCrossCity.getId(),placeOrderWay,company.getId()); |
| | | // |
| | | // driverService.updateById(driver); |
| | | |
| | | // TODO: 2020/5/24 这里需要给司机和用户推送订单状态 |
| | | new Thread(new Runnable() { |
| | |
| | | }).start(); |
| | | |
| | | |
| | | systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成出行订单支付,谢谢使用!", orderCrossCity.getUserId(), 1); |
| | | // systemNoticeService.addSystemNotice(1, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功完成出行订单支付,谢谢使用!", orderCrossCity.getUserId(), 1); |
| | | //添加司机消息提醒 |
| | | systemNoticeService.addSystemNotice(2, "用户已线上完成支付", driver.getId(), 1); |
| | | }else{ |
| | |
| | | if(null == query){ |
| | | return ResultUtil.error("订单还未进行支付"); |
| | | } |
| | | // Map<String, Object> merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), id + "_3", orderCrossCity.getOrderNum()); |
| | | // if(Integer.valueOf(merrefund.get("code").toString()) == 0){ |
| | | // Map<String, Object> refundqry = icbcPayUtil.refundqry("", query.getCode(), orderCrossCity.getOrderNum()); |
| | | // if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 0){//成功 |
| | | // //添加交易明细 |
| | | // transactionDetailsService.saveData(orderCrossCity.getUserId(), "跨城订单取消退款", query.getAmount(), 1, 1, 1, 3, id); |
| | | // } |
| | | // if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 1){//失败 |
| | | // return ResultUtil.error("订单取消失败(退款不成功)"); |
| | | // } |
| | | // if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 2){//未知 |
| | | // return ResultUtil.error("退款返回未知异常"); |
| | | // } |
| | | // } |
| | | Map<String, String> merrefund = payMoneyUtil.wxRefund(query.getCode(), orderCrossCity.getOrderNum(), String.valueOf(query.getAmount()), String.valueOf(query.getAmount()), ""); |
| | | System.err.println("跨城退款数据:::"+merrefund); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderCrossCity.getUserId(), "跨城订单取消退款", query.getAmount(), 1, 1, 1, 3, id); |
| | | integer = orderCancelService.saveData(id, 3, reason, remark, null, null, 2, 1, uid); |
| | | } |
| | | |
| | |
| | | orderServerWarpper.setState(orderCrossCity.getState()); |
| | | orderServerWarpper.setLon(null != value ? value.split(",")[0] : "0.0"); |
| | | orderServerWarpper.setLat(null != value ? value.split(",")[1] : "0.0"); |
| | | value = value == null ? "0.0,0.0" : value; |
| | | double[] doubles = GpsCoordinateUtils.calBD09toGCJ02(Double.parseDouble(value.split(",")[1]), Double.parseDouble(value.split(",")[0])); |
| | | orderServerWarpper.setNextLongitude(String.valueOf(doubles[0])); |
| | | orderServerWarpper.setNextLatitude(String.valueOf(doubles[1])); |
| | | // 起点地址转换 |
| | | doubles = GpsCoordinateUtils.calBD09toGCJ02(orderCrossCity.getStartLat(), orderCrossCity.getStartLon()); |
| | | orderServerWarpper.setStartLat(String.valueOf(doubles[0])); |
| | | orderServerWarpper.setStartLon(String.valueOf(doubles[1])); |
| | | // 终点地址转换 |
| | | doubles = GpsCoordinateUtils.calBD09toGCJ02(orderCrossCity.getEndLat(), orderCrossCity.getEndLon()); |
| | | orderServerWarpper.setEndLat(String.valueOf(doubles[0])); |
| | | orderServerWarpper.setEndLon(String.valueOf(doubles[1])); |
| | | orderServerWarpper.setReassignNotice(orderCrossCity.getReassignNotice()); |
| | | if(orderCrossCity.getState() == 2 || orderCrossCity.getState() == 3){//前往预约地 |
| | | orderServerWarpper.setReservationMileage(d); |
| | |
| | | if(null == distance){ |
| | | System.err.println("查询距离出错了"); |
| | | }else{ |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000),2, BigDecimal.ROUND_HALF_EVEN).toString(); |
| | | t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60),2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; |
| | | } |
| | | orderServerWarpper.setReservationMileage("0"); |
| | | orderServerWarpper.setReservationTime("0"); |
| | |
| | | return orderCrossCityMapper.queryListOrder(driverId, lineShiftId, state, day); |
| | | } |
| | | |
| | | @Override |
| | | public void autoCancelOrder() { |
| | | LocalDateTime localDateTime = LocalDateTime.now(); |
| | | LocalDateTime dateTime = localDateTime.minusMinutes(30); |
| | | String time = dateUtil.localDateTimeToStringHHmm(dateTime); |
| | | List<OrderCrossCity> orderCrossCities = this.selectList(new EntityWrapper<OrderCrossCity>().eq("state", 7).like("insertTime", time)); |
| | | if(!CollectionUtils.isEmpty(orderCrossCities)){ |
| | | for (OrderCrossCity orderCrossCity : orderCrossCities) { |
| | | orderCrossCity.setState(10); |
| | | } |
| | | this.updateBatchById(orderCrossCities); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取订单编号 |
| | | * @return |