| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.api.config.filter.IFilterConfig; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.request.AlipayTradeOrderSettleRequest; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | @Resource |
| | | private UserCouponClient userCouponClient; |
| | | |
| | | |
| | | @Resource |
| | | private CouponClient couponClient; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private ISiteBookingService iSiteBookingService; |
| | | @Autowired |
| | | private ITSitePriceService sitePriceService; |
| | | |
| | | @Autowired |
| | | private ISiteService siteService; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | SiteType siteType = siteTypeService.getById(site.getSiteTypeId()); |
| | | Store store = storeService.getById(site.getStoreId()); |
| | | QuerySiteInfoVo querySiteInfoVo = new QuerySiteInfoVo(); |
| | | if (site.getTargetAudience().contains("1")) { |
| | | querySiteInfoVo.setTargetAudience(1); |
| | | } |
| | | if (site.getTargetAudience().contains("2")) { |
| | | querySiteInfoVo.setTargetAudience(2); |
| | | } |
| | | if (site.getTargetAudience().contains("1") && site.getTargetAudience().contains("2")) { |
| | | querySiteInfoVo.setTargetAudience(3); |
| | | } |
| | | |
| | | querySiteInfoVo.setId(site.getId()); |
| | | querySiteInfoVo.setTypeName(site.getTypeName()); |
| | | querySiteInfoVo.setName(site.getName()); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取场地预约日期数据 |
| | | * |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<QuerySiteTimes> querySiteTimes(Integer id, String day, String halfName, String siteName) throws Exception { |
| | | public List<QuerySiteTimes> querySiteTimes(Integer id, String day, String halfName, String siteName, Integer targetAudience) throws Exception { |
| | | |
| | | System.out.println("=======date======" + day); |
| | | List<String> strings = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | |
| | | System.out.println("=======siteBookings======" + siteBookings); |
| | | System.out.println("=======已预约列表======" + siteBookings); |
| | | for (SiteBooking siteBooking : siteBookings) { |
| | | |
| | | |
| | |
| | | if (siteBooking.getIsHalf() == 2) { |
| | | for (String s : split) { |
| | | String convertedValue = s.substring(11); |
| | | strings.add(convertedValue); |
| | | strings.add(convertedValue + (siteBooking.getTargetAudience() != null ? "," + siteBooking.getTargetAudience() : ",1")); |
| | | } |
| | | } else { |
| | | if (halfName == null) { |
| | | for (String s : split) { |
| | | String convertedValue = s.substring(11); |
| | | strings.add(convertedValue); |
| | | strings.add(convertedValue + (siteBooking.getTargetAudience() != null ? "," + siteBooking.getTargetAudience() : ",1")); |
| | | } |
| | | } |
| | | |
| | | if (siteBooking.getHalfName().equals(halfName)) { |
| | | for (String s : split) { |
| | | String convertedValue = s.substring(11); |
| | | strings.add(convertedValue); |
| | | strings.add(convertedValue + (siteBooking.getTargetAudience() != null ? "," + siteBooking.getTargetAudience() : ",1")); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | System.out.println("======strings=======" + strings); |
| | | |
| | | |
| | | List<QuerySiteTimes> timeRanges = new ArrayList<>(); |
| | | System.out.println("======已经预约时间段=======" + strings); |
| | | |
| | | |
| | | Site site = siteService.getById(id); |
| | | System.out.println("================" + site); |
| | | String appointmentStartTime = site.getAppointmentStartTime(); |
| | | String appointmentEndTime = site.getAppointmentEndTime(); |
| | | |
| | | String currentTime = appointmentStartTime; |
| | | while (currentTime.compareTo(appointmentEndTime) < 0) { |
| | | String nextTime = null; |
| | | if ("智慧场地".equals(site.getTypeName())) { |
| | | nextTime = getNextTimeOne(currentTime); |
| | | } else { |
| | | nextTime = getNextTime(currentTime); |
| | | } |
| | | |
| | | |
| | | String timeRange = currentTime + "-" + nextTime; |
| | | QuerySiteTimes orderDto = new QuerySiteTimes(); |
| | | orderDto.setTime(timeRange); |
| | | |
| | | LocalTime currentTime1 = LocalTime.now(); |
| | | LocalTime targetTime = LocalTime.parse(currentTime); |
| | | |
| | | boolean hasExceeded = currentTime1.isAfter(targetTime); |
| | | // if (hasExceeded){ |
| | | // orderDto.setSelectable(0); |
| | | // } |
| | | if (strings.contains(timeRange)) { |
| | | |
| | | orderDto.setSelectable(0); |
| | | } else { |
| | | |
| | | String stime = day + " " + currentTime; |
| | | String etime = day + " " + nextTime; |
| | | orderDto.setSelectable(1); |
| | | // 查出lock |
| | | List<SiteLock> list = siteLockService.list(new LambdaQueryWrapper<SiteLock>().eq(SiteLock::getSiteId, id)); |
| | | for (SiteLock siteLock : list) { |
| | | boolean stringDateBetween = DateComparisonExample.isStringDateBetween(stime + " - " + etime, siteLock.getStartTime(), siteLock.getEndTime()); |
| | | if (stringDateBetween) { |
| | | orderDto.setSelectable(0); |
| | | } |
| | | if (DateComparisonExample.isStringWithinTimeRange(stime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | orderDto.setSelectable(0); |
| | | } |
| | | if (DateComparisonExample.isStringWithinTimeRange(etime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | orderDto.setSelectable(0); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | timeRanges.add(orderDto); |
| | | currentTime = nextTime; |
| | | List<QuerySiteTimes> timeRanges = new ArrayList<>(); |
| | | day = day.split(";")[0].split(" ")[0]; |
| | | LocalDate date = LocalDate.parse(day); |
| | | DayOfWeek dayOfWeek = date.getDayOfWeek(); |
| | | // 通过日期 确定周X 查询设置的可以约时间段和金额 封装基础时间段数据 |
| | | LambdaQueryWrapper<TSitePrice> tSitePriceLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | tSitePriceLambdaQueryWrapper.eq(TSitePrice::getSiteId, id); |
| | | tSitePriceLambdaQueryWrapper.orderByAsc(TSitePrice::getStartTime); |
| | | tSitePriceLambdaQueryWrapper.eq(TSitePrice::getTargetAudience, targetAudience); |
| | | tSitePriceLambdaQueryWrapper.eq(TSitePrice::getDayOfWeek, dayOfWeek.getValue()); |
| | | if (StringUtils.hasLength(halfName)) { |
| | | tSitePriceLambdaQueryWrapper.eq(TSitePrice::getFieldType, 2); |
| | | } else { |
| | | tSitePriceLambdaQueryWrapper.eq(TSitePrice::getFieldType, 1); |
| | | } |
| | | System.out.println("-------------" + timeRanges); |
| | | List<TSitePrice> sitePrice = sitePriceService.list(tSitePriceLambdaQueryWrapper); |
| | | |
| | | |
| | | for (TSitePrice tSitePrice : sitePrice) { |
| | | QuerySiteTimes querySiteTimes = new QuerySiteTimes(); |
| | | querySiteTimes.setTime(tSitePrice.getStartTime().substring(0, tSitePrice.getStartTime().length() - 3) + "-" + tSitePrice.getEndTime().substring(0, tSitePrice.getEndTime().length() - 3)); |
| | | querySiteTimes.setSelectable(1); |
| | | querySiteTimes.setSelectCount(0); |
| | | querySiteTimes.setSelectMaxCount(site.getWalkinCapacity()); |
| | | querySiteTimes.setIsReserve(0); |
| | | querySiteTimes.setCashPrice(tSitePrice.getCashPrice()); |
| | | querySiteTimes.setCoinPrice(tSitePrice.getCoinPrice()); |
| | | String temp = tSitePrice.getStartTime().substring(0, tSitePrice.getStartTime().length() - 3) + "-" + tSitePrice.getEndTime().substring(0, tSitePrice.getEndTime().length() - 3); |
| | | String timePriceStart = day + " " + tSitePrice.getStartTime().substring(0, tSitePrice.getStartTime().length() - 3); |
| | | String timePriceEnd = day + " " + tSitePrice.getEndTime().substring(0, tSitePrice.getEndTime().length() - 3); |
| | | // 已经预约了 判断是散客模式还是订场模式 |
| | | Integer flag = 0; |
| | | // 散客预约人数 |
| | | Integer count = 0; |
| | | for (String time : strings) { |
| | | // 先判断时间是否和预约时间有交集 |
| | | String s = time.split(",")[1]; |
| | | String timeRange = time.split(",")[0]; |
| | | String[] split = timeRange.split("-"); |
| | | String bookingStart = day + " " + split[0]; |
| | | String bookingEnd = day + " " + split[1]; |
| | | if (!isTimePeriodsIntersect(timePriceStart, timePriceEnd, bookingStart, bookingEnd)) { |
| | | // 不相交 |
| | | } else { |
| | | if (s.equals("1")) { |
| | | // 订场 不可再预约了 |
| | | querySiteTimes.setIsReserve(1); |
| | | querySiteTimes.setSelectable(0); |
| | | flag = 1; |
| | | break; |
| | | } |
| | | count++; |
| | | } |
| | | } |
| | | querySiteTimes.setSelectCount(count); |
| | | if (flag == 0) { |
| | | // 当前时间段还没有预约 |
| | | Integer walkinCapacity = site.getWalkinCapacity(); |
| | | // 计算散客预约人数和最大散客容纳数 |
| | | System.err.println("预约人数" + count); |
| | | System.err.println("最大散客容纳数" + walkinCapacity); |
| | | if (walkinCapacity <= count) { |
| | | // 不可预约 也不能散客 |
| | | System.err.println("不可预约 也不能散客"); |
| | | querySiteTimes.setSelectable(0); |
| | | querySiteTimes.setIsReserve(0); |
| | | }else{ |
| | | if (targetAudience==2){ |
| | | // 散客只能预约当前时间段 |
| | | Date now = new Date(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | String nowStr = simpleDateFormat.format(now); |
| | | // 判断当前时间有没有在timePriceStart和timePriceEnd之间 |
| | | if (DateComparisonExample.isStringWithinTimeRange(nowStr, simpleDateFormat.parse(timePriceStart), simpleDateFormat.parse(timePriceEnd))) { |
| | | querySiteTimes.setSelectable(1); |
| | | }else{ |
| | | querySiteTimes.setSelectable(0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 查出lock |
| | | List<SiteLock> list = siteLockService.list(new LambdaQueryWrapper<SiteLock>().eq(SiteLock::getSiteId, id)); |
| | | for (SiteLock siteLock : list) { |
| | | String stime = day + " " + tSitePrice.getStartTime().substring(0, tSitePrice.getStartTime().length() - 3); |
| | | String etime = day + " " + tSitePrice.getEndTime().substring(0, tSitePrice.getEndTime().length() - 3); |
| | | boolean stringDateBetween = DateComparisonExample.isStringDateBetween(stime + " - " + etime, siteLock.getStartTime(), siteLock.getEndTime()); |
| | | if (stringDateBetween) { |
| | | System.err.println("11111预约开始" + stime + "预约结束" + etime); |
| | | querySiteTimes.setSelectable(0); |
| | | querySiteTimes.setIsReserve(1); |
| | | } |
| | | if (DateComparisonExample.isStringWithinTimeRange(stime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | System.err.println("22222预约开始" + stime + "预约结束" + etime); |
| | | |
| | | querySiteTimes.setSelectable(0); |
| | | querySiteTimes.setIsReserve(1); |
| | | } |
| | | if (DateComparisonExample.isStringWithinTimeRange(etime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | System.err.println("33333预约开始" + stime + "预约结束" + etime); |
| | | |
| | | querySiteTimes.setSelectable(0); |
| | | querySiteTimes.setIsReserve(1); |
| | | } |
| | | } |
| | | timeRanges.add(querySiteTimes); |
| | | } |
| | | System.out.println("封装后的基础时间段和价格" + site); |
| | | |
| | | // System.out.println("================" + site); |
| | | // String appointmentStartTime = site.getAppointmentStartTime(); |
| | | // String appointmentEndTime = site.getAppointmentEndTime(); |
| | | // |
| | | // String currentTime = appointmentStartTime; |
| | | // while (currentTime.compareTo(appointmentEndTime) < 0) { |
| | | // String nextTime = null; |
| | | // if ("智慧场地".equals(site.getTypeName())) { |
| | | // nextTime = getNextTimeOne(currentTime); |
| | | // } else { |
| | | // nextTime = getNextTime(currentTime); |
| | | // } |
| | | // |
| | | // |
| | | // String timeRange = currentTime + "-" + nextTime; |
| | | // QuerySiteTimes orderDto = new QuerySiteTimes(); |
| | | // orderDto.setTime(timeRange); |
| | | // |
| | | // LocalTime currentTime1 = LocalTime.now(); |
| | | // LocalTime targetTime = LocalTime.parse(currentTime); |
| | | // |
| | | // boolean hasExceeded = currentTime1.isAfter(targetTime); |
| | | //// if (hasExceeded){ |
| | | //// orderDto.setSelectable(0); |
| | | //// } |
| | | // if (strings.contains(timeRange)) { |
| | | // |
| | | // orderDto.setSelectable(0); |
| | | // } else { |
| | | // |
| | | // String stime = day + " " + currentTime; |
| | | // String etime = day + " " + nextTime; |
| | | // orderDto.setSelectable(1); |
| | | // // 查出lock |
| | | // List<SiteLock> list = siteLockService.list(new LambdaQueryWrapper<SiteLock>().eq(SiteLock::getSiteId, id)); |
| | | // for (SiteLock siteLock : list) { |
| | | // boolean stringDateBetween = DateComparisonExample.isStringDateBetween(stime + " - " + etime, siteLock.getStartTime(), siteLock.getEndTime()); |
| | | // if (stringDateBetween) { |
| | | // orderDto.setSelectable(0); |
| | | // } |
| | | // if (DateComparisonExample.isStringWithinTimeRange(stime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | // orderDto.setSelectable(0); |
| | | // } |
| | | // if (DateComparisonExample.isStringWithinTimeRange(etime, siteLock.getStartTime(), siteLock.getEndTime())) { |
| | | // orderDto.setSelectable(0); |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // |
| | | // } |
| | | // |
| | | // |
| | | // timeRanges.add(orderDto); |
| | | // currentTime = nextTime; |
| | | // } |
| | | System.out.println("----最后封装的时间段数据------" + timeRanges); |
| | | |
| | | return timeRanges; |
| | | |
| | | |
| | | } |
| | | /** |
| | | * 判断两个时间段是否有交集 |
| | | * @param start1 第一个时间段开始时间 |
| | | * @param end1 第一个时间段结束时间 |
| | | * @param start2 第二个时间段开始时间 |
| | | * @param end2 第二个时间段结束时间 |
| | | * @return 如果有交集返回true,否则返回false |
| | | */ |
| | | private boolean isTimePeriodsIntersect(String start1, String end1, String start2, String end2) { |
| | | // 首先判断是否有任何形式的重叠(包括端点) |
| | | boolean hasOverlap = start1.compareTo(end2) <= 0 && end1.compareTo(start2) >= 0; |
| | | |
| | | // 判断是否仅仅是端点相接 |
| | | boolean onlyTouching = start1.compareTo(end2) == 0 || end1.compareTo(start2) == 0; |
| | | |
| | | // 有重叠且不是仅仅端点相接才算真正的交集 |
| | | return hasOverlap && !onlyTouching; |
| | | } |
| | | // public static void main(String[] args) { |
| | | // String temp = "09:00-09:30"; |
| | | // List<String> strings = new ArrayList<>(); |
| | | // strings.add("09:00-09:30,1"); |
| | | // List<String> booking = strings.stream().filter(e -> e.split(",")[0].equals(temp)).collect(Collectors.toList()); |
| | | // |
| | | // System.err.println( booking); |
| | | // } |
| | | |
| | | |
| | | public static String getNextTime(String currentTime) { |
| | |
| | | Site site = this.getById(reservationSite.getId()); |
| | | AppUser appUser = appUserClient.queryAppUser(uid); |
| | | String[] split = reservationSite.getTimes().split(";"); |
| | | // 所选时间段 所需总计金额 |
| | | BigDecimal money = BigDecimal.ZERO; |
| | | BigDecimal playCoin = BigDecimal.ZERO; |
| | | for (String s : split) { |
| | | String day = s.split(" ")[0]; |
| | | String time = s.split(" ")[1]; |
| | | List<QuerySiteTimes> querySiteTimes = querySiteTimes(reservationSite.getId(), day, reservationSite.getHalfName(), reservationSite.getNextName()); |
| | | String bookingStart = day + " " + time.split("-")[0]; |
| | | String bookingEnd = day + " " + time.split("-")[1]; |
| | | List<QuerySiteTimes> querySiteTimes = querySiteTimes(reservationSite.getId(), day, reservationSite.getHalfName(), reservationSite.getNextName(), reservationSite.getTargetAudience()); |
| | | for (QuerySiteTimes querySiteTime : querySiteTimes) { |
| | | if (querySiteTime.getTime().equals(time) && querySiteTime.getSelectable() == 0) { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段已被使用"); |
| | | String timePriceStart = day + " " + querySiteTime.getTime().split("-")[0]; |
| | | String timePriceEnd = day + " " + querySiteTime.getTime().split("-")[1]; |
| | | if (!isTimePeriodsIntersect(timePriceStart, timePriceEnd, bookingStart, bookingEnd)) { |
| | | // 时间不相交 |
| | | } else if (querySiteTime.getSelectable() == 0) { |
| | | if (querySiteTime.getIsReserve() == 1) { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段已被使用"); |
| | | } else { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段散客人数已满"); |
| | | } |
| | | } |
| | | if (querySiteTime.getTime().equals(time)) { |
| | | money = money.add(querySiteTime.getCashPrice()); |
| | | playCoin = playCoin.add(querySiteTime.getCoinPrice()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | String s_time = split[0]; |
| | | String e_time = split[split.length - 1]; |
| | |
| | | e_time = s1[0] + " " + s1[1].split("-")[1]; |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | Double payMoney = 0D; |
| | | if (reservationSite.getPayType() == 3) { |
| | | if (reservationSite.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoinOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | if (appUser.getPlayPaiCoins().compareTo(payMoney.intValue()) < 0) { |
| | | |
| | | if (appUser.getPlayPaiCoins().compareTo(playCoin.intValue()) < 0) { |
| | | return new ResultUtil(3, "玩湃币不足"); |
| | | } |
| | | } else { |
| | | if (reservationSite.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getCashPriceOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | } |
| | | |
| | |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | if (payMoney.compareTo(num1) < 0) { |
| | | if (money.compareTo(new BigDecimal(num1)) < 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | if (userCoupon != null && coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (payMoney.compareTo(num1) <= 0) { |
| | | if (money.compareTo(new BigDecimal(num1)) <= 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | |
| | | siteBooking.setBooker(reservationSite.getBooker()); |
| | | siteBooking.setPhone(reservationSite.getPhone()); |
| | | siteBooking.setPayType(reservationSite.getPayType()); |
| | | siteBooking.setPayMoney(payMoney); |
| | | siteBooking.setPayMoney(money.setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | siteBooking.setUserCouponId(reservationSite.getCouponId()); |
| | | siteBooking.setStatus(0); |
| | | siteBooking.setState(1); |
| | | siteBooking.setTargetAudience(reservationSite.getTargetAudience()); |
| | | siteBooking.setInsertTime(new Date()); |
| | | |
| | | siteBooking.setNextName(reservationSite.getNextName()); |
| | |
| | | |
| | | |
| | | if (reservationSite.getPayType() == 1) {//微信支付 |
| | | ResultUtil resultUtil = weChatPaymentSite(payMoney, siteBooking); |
| | | ResultUtil resultUtil = weChatPaymentSite(money.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), siteBooking); |
| | | return resultUtil; |
| | | } |
| | | if (reservationSite.getPayType() == 2) {//支付宝支付 |
| | | return aliPaymentSite(payMoney, siteBooking); |
| | | return aliPaymentSite(money.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), siteBooking); |
| | | } |
| | | if (reservationSite.getPayType() == 3) {//玩湃币支付 |
| | | if (reservationSite.getIsHalf() == 2) { |
| | | return playPaiCoinPaymentSite(appUser, Double.valueOf(site.getPlayPaiCoin()), siteBooking); |
| | | } else { |
| | | return playPaiCoinPaymentSite(appUser, site.getPlayPaiCoinOne(), siteBooking); |
| | | } |
| | | return playPaiCoinPaymentSite(appUser, playCoin.setScale(2, RoundingMode.HALF_EVEN).doubleValue(), siteBooking); |
| | | |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | private String smidVx = "2088330203191220";//平台微信商户号 |
| | | |
| | | /** |
| | | * 课程微信支付 |
| | | * |
| | |
| | | String code = siteBooking.getOrderNo(); |
| | | Integer id = siteBooking.getId(); |
| | | Site byId = siteService.getById(siteBooking.getSiteId()); |
| | | // 是否分账 0否1是 |
| | | int isFenZhang= 1; |
| | | String merchantNumber = ""; |
| | | if (byId.getOperatorId()==null || byId.getOperatorId()==0){ |
| | | Store store = storeService.getById(byId.getStoreId()); |
| | | if (store.getOperatorId() == null || store.getOperatorId() == 0) { |
| | | // 平台 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地-"+isFenZhang, id.toString(), code, paymentPrice.toString(), |
| | | "/base/site/weChatPaymentSiteCallback", "APP", ""); |
| | | return weixinpay; |
| | | }else{ |
| | | String smidVx= operatorUserService.getmerchantNumberByOperatorId(byId.getOperatorId()); |
| | | if (!StringUtils.hasLength(smidVx)){ |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地", id.toString(), code, paymentPrice.toString(), |
| | | "/base/site/weChatPaymentSiteCallback", "APP", ""); |
| | | return weixinpay; |
| | | } else { |
| | | String smidVx = operatorUserService.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | if (!StringUtils.hasLength(smidVx)) { |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | return payMoneyUtil.weixinpayV3(smidVx,"预约场地" |
| | | ,code,"/base/site/weChatPaymentSiteCallback1", |
| | | paymentPrice.toString(),id.toString()); |
| | | return payMoneyUtil.weixinpayV3(smidVx, "预约场地" |
| | | , code, "/base/site/weChatPaymentSiteCallback1", |
| | | paymentPrice.toString(), id.toString()); |
| | | } |
| | | |
| | | |
| | |
| | | private IOperatorUserService operatorUserService; |
| | | @Autowired |
| | | private StoreClient storeClient; |
| | | |
| | | /** |
| | | * 课程支付宝支付 |
| | | * |
| | |
| | | Store byId = storeService.getById(storeId); |
| | | Integer operatorId = byId.getOperatorId(); |
| | | String smid1 = ""; |
| | | if (operatorId == null ){ |
| | | if (operatorId == null) { |
| | | // 平台的门店 |
| | | smid1 = smid; |
| | | }else if (operatorId == 0){ |
| | | } else if (operatorId == 0) { |
| | | smid1 = smid; |
| | | }else{ |
| | | } else { |
| | | smid1 = siteService.getmerchantNumberAliByOperatorId(operatorId); |
| | | |
| | | } |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid1,"预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback"); |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid1, "预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback"); |
| | | System.out.println("预约场地----" + alipay.getCode()); |
| | | // if (alipay.getCode() == 200) { |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // try { |
| | | // int num = 1; |
| | | // int wait = 0; |
| | | // while (num <= 10) { |
| | | // int min = 5000; |
| | | // wait += (min * num); |
| | | // Thread.sleep(wait); |
| | | // SiteBooking siteBooking = siteBookingService.getById(id); |
| | | // if (siteBooking.getStatus() != 0) { |
| | | // break; |
| | | // } |
| | | // AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | // if (resultUtil.getCode().equals("10000") && siteBooking.getStatus() == 0) { |
| | | // /** |
| | | // * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | // * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | // * TRADE_SUCCESS(交易支付成功)、 |
| | | // * TRADE_FINISHED(交易结束,不可退款) |
| | | // */ |
| | | //// Map<String, String> data1 = resultUtil.getData(); |
| | | //// String s = data1.get("tradeStatus"); |
| | | // String tradeNo = resultUtil.getTradeNo(); |
| | | // String s = resultUtil.getTradeStatus(); |
| | | // System.out.println("ssssss" + s); |
| | | // if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) { |
| | | // break; |
| | | // } |
| | | // if ("TRADE_SUCCESS".equals(s)) { |
| | | // siteBooking.setPayTime(new Date()); |
| | | // siteBooking.setStatus(1); |
| | | // siteBooking.setPayOrderNo(tradeNo); |
| | | // siteBookingService.updateById(siteBooking); |
| | | // System.err.println("======完成支付"); |
| | | // // 判断预约的门店 属于哪个运营商 |
| | | // Integer storeId = siteBooking.getStoreId(); |
| | | // Store byId = storeService.getById(storeId); |
| | | // Integer operatorId = byId.getOperatorId(); |
| | | // String smid1 = ""; |
| | | // if (operatorId == null || operatorId == 0){ |
| | | // // 平台的门店 不冻结资金不做分账处理 |
| | | // payMoneyUtil.confirm1(smid1,code,tradeNo,paymentPrice.toString()); |
| | | // }else{ |
| | | // smid1 = siteService.getSMIDByOperatorId(operatorId); |
| | | // payMoneyUtil.confirm(smid1,code,tradeNo,paymentPrice.toString()); |
| | | // // 分账 |
| | | // extracted(operatorId, new BigDecimal(paymentPrice.toString()), tradeNo); |
| | | // } |
| | | // |
| | | // break; |
| | | // } |
| | | // if ("WAIT_BUYER_PAY".equals(s)) { |
| | | // num++; |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }).start(); |
| | | // } |
| | | if (alipay.getCode() == 200) { |
| | | String finalSmid = smid1; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Thread.sleep(wait); |
| | | SiteBooking siteBooking = siteBookingService.getById(id); |
| | | if (siteBooking.getStatus() != 0) { |
| | | break; |
| | | } |
| | | AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | if (resultUtil.getCode().equals("10000") && siteBooking.getStatus() == 0) { |
| | | /** |
| | | * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | * TRADE_SUCCESS(交易支付成功)、 |
| | | * TRADE_FINISHED(交易结束,不可退款) |
| | | */ |
| | | // Map<String, String> data1 = resultUtil.getData(); |
| | | // String s = data1.get("tradeStatus"); |
| | | String tradeNo = resultUtil.getTradeNo(); |
| | | String s = resultUtil.getTradeStatus(); |
| | | System.out.println("ssssss" + s); |
| | | if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) { |
| | | break; |
| | | } |
| | | if ("TRADE_SUCCESS".equals(s)) { |
| | | siteBooking.setPayTime(new Date()); |
| | | siteBooking.setStatus(1); |
| | | siteBooking.setPayOrderNo(tradeNo); |
| | | siteBookingService.updateById(siteBooking); |
| | | System.err.println("======完成支付"); |
| | | Thread.sleep(30000); |
| | | payMoneyUtil.confirm(finalSmid, code, tradeNo, paymentPrice.toString()); |
| | | break; |
| | | } |
| | | if ("WAIT_BUYER_PAY".equals(s)) { |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | return alipay; |
| | | } |
| | | |
| | |
| | | String randomCode = UUIDUtil.getRandomCode(16); |
| | | |
| | | String proportionByOperatorId = operatorUserService.getOne(new QueryWrapper<OperatorUser>() |
| | | .eq("operatorId",operatorId)).getAlipayProportion(); |
| | | .eq("operatorId", operatorId)).getAlipayProportion(); |
| | | // 支付宝分账比例 |
| | | String s1 = proportionByOperatorId.split(",")[1]; |
| | | double i = Double.parseDouble(s1); |
| | |
| | | " \"royalty_parameters\":[" + |
| | | " {" + |
| | | " \"royalty_type\":\"transfer\"," + |
| | | " \"trans_out\":\"" + storeClient.getSMIDByOperatorId(operatorId)+ "\"," + |
| | | " \"trans_out\":\"" + storeClient.getSMIDByOperatorId(operatorId) + "\"," + |
| | | " \"trans_out_type\":\"userId\"," + |
| | | " \"trans_in_type\":\"userId\"," + |
| | | " \"trans_in\":\"" + smid + "\"," + |
| | |
| | | System.out.println("调用失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 玩湃币支付 |
| | | * |
| | |
| | | List<QueryMySiteVo> queryMySiteVos = this.baseMapper.queryMySite(uid, status, pageNo, pageSize); |
| | | for (QueryMySiteVo queryMySiteVo : queryMySiteVos) { |
| | | SiteBooking siteBooking = siteBookingService.getById(queryMySiteVo.getId()); |
| | | Site site = this.getById(siteBooking.getSiteId()); |
| | | String[] split = siteBooking.getTimes().split(";"); |
| | | if (site != null) { |
| | | if (queryMySiteVo.getIsHalf() == 1) { |
| | | queryMySiteVo.setPlayPaiCoin((int) (site.getPlayPaiCoinOne() * split.length)); |
| | | // 所选时间段 所需总计金额 |
| | | BigDecimal money = BigDecimal.ZERO; |
| | | BigDecimal playCoin = BigDecimal.ZERO; |
| | | for (String s : split) { |
| | | |
| | | } else { |
| | | queryMySiteVo.setPlayPaiCoin(site.getPlayPaiCoin() * split.length); |
| | | |
| | | String day = s.split(" ")[0]; |
| | | String time = s.split(" ")[1]; |
| | | String bookingStart = day + " " + time.split("-")[0]; |
| | | String bookingEnd = day + " " + time.split("-")[1]; |
| | | List<QuerySiteTimes> querySiteTimes = querySiteTimes(siteBooking.getId(), day, siteBooking.getHalfName(), siteBooking.getNextName(), siteBooking.getTargetAudience()); |
| | | for (QuerySiteTimes querySiteTime : querySiteTimes) { |
| | | String timePriceStart = day + " " + querySiteTime.getTime().split("-")[0]; |
| | | String timePriceEnd = day + " " + querySiteTime.getTime().split("-")[1]; |
| | | // if (!isTimePeriodsIntersect(timePriceStart, timePriceEnd, bookingStart, bookingEnd)) { |
| | | // // 时间不相交 |
| | | // } else if (querySiteTime.getSelectable() == 0) { |
| | | // if (querySiteTime.getIsReserve() == 1) { |
| | | // return ResultUtil.error("【" + s + "】" + |
| | | // "时间段已被使用"); |
| | | // } else { |
| | | // return ResultUtil.error("【" + s + "】" + |
| | | // "时间段散客人数已满"); |
| | | // } |
| | | // } |
| | | if (querySiteTime.getTime().equals(time)) { |
| | | money = money.add(querySiteTime.getCashPrice()); |
| | | playCoin = playCoin.add(querySiteTime.getCoinPrice()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | queryMySiteVo.setPlayPaiCoin(playCoin.setScale(0, RoundingMode.DOWN).intValue()); |
| | | } |
| | | return queryMySiteVos; |
| | | } |
| | |
| | | if (siteBooking.getStatus() != 1 && siteBooking.getStatus() != 2) { |
| | | return ResultUtil.error("不能进行取消操作"); |
| | | } |
| | | Integer storeId = siteBooking.getStoreId(); |
| | | Store store = storeService.getById(storeId); |
| | | |
| | | if (siteBooking.getPayType() == 1) {//微信支付 |
| | | if (StringUtils.hasLength(siteBooking.getFenzhangNo())){ |
| | | // 是分账订单 如果分账金额不为0 那么回退分账金额 |
| | | if (siteBooking.getFenzhangAmount()!=null && siteBooking.getFenzhangAmount().compareTo(BigDecimal.ZERO)>0){ |
| | | String randomCode = UUIDUtil.getRandomCode(16); |
| | | String randomCode1 = UUIDUtil.getRandomCode(16); |
| | | if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){ |
| | | // 微信商户号 |
| | | String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId()); |
| | | ResultUtil resultUtil = payMoneyUtil.fenzhangRefund(siteBooking.getFenzhangNo(), siteBooking.getFenzhangAmount().multiply(new BigDecimal("100")), s2, randomCode, randomCode1); |
| | | if (!resultUtil.getCode().equals(200)){ |
| | | System.err.println("分账回退失败 原因是:"+resultUtil.getMsg()+resultUtil.getData()); |
| | | }else{ |
| | | siteBooking.setFenzhangRefundNo(resultUtil.getMsg()); |
| | | siteBookingService.updateById(siteBooking); |
| | | } |
| | | |
| | | } |
| | | if (store.getOperatorId() != null && store.getOperatorId() != 0) { |
| | | String smidVx = operatorUserService.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | if (!StringUtils.hasLength(smidVx)) { |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | } |
| | | Map<String, String> map = payMoneyUtil.wxRefund(siteBooking.getPayOrderNo(), siteBooking.getOrderNo(), siteBooking.getPayMoney().toString(), |
| | | siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback"); |
| | | if (null == map) { |
| | | return ResultUtil.error("取消退款异常"); |
| | | } |
| | | String return_code = map.get("return_code"); |
| | | if (!"SUCCESS".equals(return_code)) { |
| | | return ResultUtil.error(map.get("return_msg")); |
| | | } |
| | | siteBooking.setCancelUserId(uid); |
| | | siteBookingService.updateById(siteBooking); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);// 退款单号 |
| | | // 运营商退款 |
| | | payMoneyUtil.weixinRefundV3(smidVx, code, siteBooking.getPayOrderNo(), siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback1"); |
| | | } else { |
| | | Map<String, String> map = payMoneyUtil.wxRefund(siteBooking.getPayOrderNo(), siteBooking.getOrderNo(), siteBooking.getPayMoney().toString(), |
| | | siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback"); |
| | | if (null == map) { |
| | | return ResultUtil.error("取消退款异常"); |
| | | } |
| | | String return_code = map.get("return_code"); |
| | | if (!"SUCCESS".equals(return_code)) { |
| | | return ResultUtil.error(map.get("return_msg")); |
| | | } |
| | | siteBooking.setCancelUserId(uid); |
| | | siteBookingService.updateById(siteBooking); |
| | | |
| | | TBackRecord tBackRecord = new TBackRecord(); |
| | | tBackRecord.setMoney(siteBooking.getPayMoney()); |
| | | tBackRecord.setUserId(siteBooking.getAppUserId()); |
| | | tBackRecord.setTime(new Date()); |
| | | backRecordService.save(tBackRecord); |
| | | TBackRecord tBackRecord = new TBackRecord(); |
| | | tBackRecord.setMoney(siteBooking.getPayMoney()); |
| | | tBackRecord.setUserId(siteBooking.getAppUserId()); |
| | | tBackRecord.setTime(new Date()); |
| | | backRecordService.save(tBackRecord); |
| | | } |
| | | |
| | | |
| | | } |
| | | if (siteBooking.getPayType() == 2) {//支付宝 |
| | |
| | | Site site = this.getById(siteBooking.getSiteId()); |
| | | AppUser appUser = appUserClient.queryAppUser(uid); |
| | | String[] split = siteBooking.getTimes().split(";"); |
| | | Double payMoney = 0D; |
| | | if (payType == 3) { |
| | | // payMoney = new BigDecimal(site.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if (appUser.getPlayPaiCoins().compareTo(payMoney.intValue()) < 0) { |
| | | return ResultUtil.error("玩湃币不足"); |
| | | } |
| | | |
| | | if (siteBooking.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoinOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | } else { |
| | | if (siteBooking.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getCashPriceOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | // 所选时间段 所需总计金额 |
| | | BigDecimal money = BigDecimal.ZERO; |
| | | BigDecimal playCoin = BigDecimal.ZERO; |
| | | for (String s : split) { |
| | | String day = s.split(" ")[0]; |
| | | String time = s.split(" ")[1]; |
| | | String bookingStart = day + " " + time.split("-")[0]; |
| | | String bookingEnd = day + " " + time.split("-")[1]; |
| | | List<QuerySiteTimes> querySiteTimes = querySiteTimes(siteBooking.getId(), day, siteBooking.getHalfName(), siteBooking.getNextName(), siteBooking.getTargetAudience()); |
| | | for (QuerySiteTimes querySiteTime : querySiteTimes) { |
| | | String timePriceStart = day + " " + querySiteTime.getTime().split("-")[0]; |
| | | String timePriceEnd = day + " " + querySiteTime.getTime().split("-")[1]; |
| | | if (!isTimePeriodsIntersect(timePriceStart, timePriceEnd, bookingStart, bookingEnd)) { |
| | | // 时间不相交 |
| | | } else if (querySiteTime.getSelectable() == 0) { |
| | | if (querySiteTime.getIsReserve() == 1) { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段已被使用"); |
| | | } else { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段散客人数已满"); |
| | | } |
| | | } |
| | | if (querySiteTime.getTime().equals(time)) { |
| | | money = money.add(querySiteTime.getCashPrice()); |
| | | playCoin = playCoin.add(querySiteTime.getCoinPrice()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | if (coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | siteBooking.setOrderNo(sdf.format(new Date()) + UUIDUtil.getNumberRandom(3)); |
| | | siteBooking.setPayType(payType); |
| | | siteBooking.setPayMoney(payMoney); |
| | | siteBooking.setPayMoney(money.doubleValue()); |
| | | if (payType == 3) { |
| | | siteBooking.setUserCouponId(null); |
| | | } |
| | | siteBookingService.updateById(siteBooking); |
| | | if (payType == 1) {//微信支付 |
| | | return weChatPaymentSite(payMoney, siteBooking); |
| | | return weChatPaymentSite(money.doubleValue(), siteBooking); |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | return aliPaymentSite(payMoney, siteBooking); |
| | | return aliPaymentSite(money.doubleValue(), siteBooking); |
| | | } |
| | | if (payType == 3) {//玩湃币支付 |
| | | return playPaiCoinPaymentSite(appUser, payMoney, siteBooking); |
| | | return playPaiCoinPaymentSite(appUser, playCoin.doubleValue(), siteBooking); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | Site site = this.getById(siteBooking.getSiteId()); |
| | | String[] split = siteBooking.getTimes().split(";"); |
| | | Map<String, Double> map = new HashMap<>(); |
| | | Double payMoney = new BigDecimal(site.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | |
| | | |
| | | if (siteBooking.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getPlayPaiCoinOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | |
| | | map.put("playPaiCoin", payMoney); |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | |
| | | if (siteBooking.getIsHalf() == 2) { |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } else { |
| | | payMoney = new BigDecimal(site.getCashPriceOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | // 所选时间段 所需总计金额 |
| | | BigDecimal money = BigDecimal.ZERO; |
| | | BigDecimal playCoin = BigDecimal.ZERO; |
| | | for (String s : split) { |
| | | String day = s.split(" ")[0]; |
| | | String time = s.split(" ")[1]; |
| | | String bookingStart = day + " " + time.split("-")[0]; |
| | | String bookingEnd = day + " " + time.split("-")[1]; |
| | | List<QuerySiteTimes> querySiteTimes = querySiteTimes(siteBooking.getId(), day, siteBooking.getHalfName(), siteBooking.getNextName(), siteBooking.getTargetAudience()); |
| | | for (QuerySiteTimes querySiteTime : querySiteTimes) { |
| | | String timePriceStart = day + " " + querySiteTime.getTime().split("-")[0]; |
| | | String timePriceEnd = day + " " + querySiteTime.getTime().split("-")[1]; |
| | | if (!isTimePeriodsIntersect(timePriceStart, timePriceEnd, bookingStart, bookingEnd)) { |
| | | // 时间不相交 |
| | | } else if (querySiteTime.getSelectable() == 0) { |
| | | if (querySiteTime.getIsReserve() == 1) { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段已被使用"); |
| | | } else { |
| | | return ResultUtil.error("【" + s + "】" + |
| | | "时间段散客人数已满"); |
| | | } |
| | | } |
| | | if (querySiteTime.getTime().equals(time)) { |
| | | money = money.add(querySiteTime.getCashPrice()); |
| | | playCoin = playCoin.add(querySiteTime.getCoinPrice()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //校验优惠券 |
| | |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | if (coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | } |
| | | map.put("cash", payMoney); |
| | | switch (siteBooking.getPayType()){ |
| | | case 1: |
| | | map.put("cash", money.doubleValue()); |
| | | break; |
| | | case 2: |
| | | map.put("cash", money.doubleValue()); |
| | | break; |
| | | case 3: |
| | | map.put("playPaiCoin", money.doubleValue()); |
| | | } |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | |
| | | public String getSMIDByOperatorId(Integer id) { |
| | | return siteMapper.getSMIDByOperatorId(id); |
| | | } |
| | | |
| | | @Override |
| | | public String getmerchantNumberByOperatorId(Integer id) { |
| | | return siteMapper.getmerchantNumberByOperatorId(id); |