| | |
| | | Site site = this.getById(reservationSite.getId()); |
| | | AppUser appUser = appUserClient.queryAppUser(uid); |
| | | String[] split = reservationSite.getTimes().split(";"); |
| | | if(reservationSite.getPayType() == 3){ |
| | | Integer playPaiCoin = site.getPlayPaiCoin() * split.length; |
| | | if(appUser.getPlayPaiCoins().compareTo(playPaiCoin) < 0){ |
| | | return ResultUtil.error("玩湃币不足"); |
| | | } |
| | | } |
| | | |
| | | for (String s : split) { |
| | | String day = s.split(" ")[0]; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | String s_time = split[0]; |
| | | String e_time = split[split.length - 1]; |
| | | s_time = s_time.substring(s_time.lastIndexOf("-")); |
| | |
| | | Double payMoney = 0D; |
| | | if(reservationSite.getPayType() == 3){ |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if(appUser.getPlayPaiCoins().compareTo(payMoney.intValue()) < 0){ |
| | | return ResultUtil.error("玩湃币不足"); |
| | | } |
| | | }else{ |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | |
| | | siteBooking.setStoreId(site.getStoreId()); |
| | | siteBooking.setSiteId(reservationSite.getId()); |
| | | siteBooking.setAppUserId(uid); |
| | | siteBooking.setTimes(reservationSite.getTimes()); |
| | | siteBooking.setStartTime(sdf1.parse(s_time)); |
| | | siteBooking.setEndTime(sdf1.parse(e_time)); |
| | | siteBooking.setBooker(reservationSite.getBooker()); |
| | |
| | | siteBookingService.save(siteBooking); |
| | | |
| | | if(reservationSite.getPayType() == 1){//微信支付 |
| | | return weChatPaymentSite(uid, payMoney, siteBooking); |
| | | return weChatPaymentSite(payMoney, siteBooking); |
| | | } |
| | | if(reservationSite.getPayType() == 2){//支付宝支付 |
| | | return aliPaymentSite(payMoney, siteBooking); |
| | |
| | | |
| | | /** |
| | | * 课程微信支付 |
| | | * @param uid |
| | | * @param paymentPrice |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ResultUtil weChatPaymentSite(Integer uid, Double paymentPrice, SiteBooking siteBooking) throws Exception{ |
| | | public ResultUtil weChatPaymentSite(Double paymentPrice, SiteBooking siteBooking) throws Exception{ |
| | | String code = siteBooking.getOrderNo(); |
| | | Integer id = siteBooking.getId(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地", "", code, paymentPrice.toString(), "/base/site/weChatPaymentSiteCallback", "APP", ""); |
| | |
| | | String s = data1.get("trade_state"); |
| | | String transaction_id = data1.get("transaction_id"); |
| | | if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){ |
| | | siteBooking.setState(3); |
| | | siteBookingService.updateById(siteBooking); |
| | | if(null != siteBooking.getUserCouponId()){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(siteBooking.getUserCouponId()); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | break; |
| | | } |
| | | if("SUCCESS".equals(s)){ |
| | |
| | | String s = data1.get("tradeStatus"); |
| | | String tradeNo = data1.get("tradeNo"); |
| | | if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){ |
| | | siteBooking.setState(3); |
| | | siteBookingService.updateById(siteBooking); |
| | | if(null != siteBooking.getUserCouponId()){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(siteBooking.getUserCouponId()); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | break; |
| | | } |
| | | if("TRADE_SUCCESS".equals(s)){ |
| | |
| | | |
| | | |
| | | /** |
| | | * 玩湃币支付课程 |
| | | * 玩湃币支付 |
| | | * @param appUser |
| | | * @param paymentPrice |
| | | * @return |
| | |
| | | siteBookingService.updateById(siteBooking); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取我的场地预约 |
| | | * @param uid |
| | | * @param status |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<QueryMySiteVo> queryMySite(Integer uid, Integer status, Integer pageNo, Integer pageSize) throws Exception { |
| | | pageNo = (pageNo - 1) * pageSize; |
| | | return this.baseMapper.queryMySite(uid, status, pageNo, pageSize); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 取消我的预约场地 |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil cancelMySite(Integer uid, Integer id) throws Exception { |
| | | SiteBooking siteBooking = siteBookingService.getById(id); |
| | | if(siteBooking.getStatus() == 0){ |
| | | return ResultUtil.error("请先进行支付"); |
| | | } |
| | | if(siteBooking.getStatus() != 1 && siteBooking.getStatus() != 2){ |
| | | return ResultUtil.error("不能进行取消操作"); |
| | | } |
| | | if(siteBooking.getPayType() == 1){//微信支付 |
| | | 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 result_code = map.get("result_code"); |
| | | if(!"SUCCESS".equals(result_code)){ |
| | | return ResultUtil.error(map.get("return_msg")); |
| | | } |
| | | siteBooking.setCancelUserId(uid); |
| | | siteBookingService.updateById(siteBooking); |
| | | } |
| | | if(siteBooking.getPayType() == 2){//支付宝 |
| | | Map<String, String> map = payMoneyUtil.aliRefund(siteBooking.getPayOrderNo(), siteBooking.getPayMoney().toString()); |
| | | if(null == map){ |
| | | return ResultUtil.error("取消退款异常"); |
| | | } |
| | | String code = map.get("code"); |
| | | if(!"10000".equals(code)){ |
| | | return ResultUtil.error(map.get("return_msg")); |
| | | } |
| | | String trade_no = map.get("trade_no"); |
| | | siteBooking.setStatus(5); |
| | | siteBooking.setCancelUserId(uid); |
| | | siteBooking.setCancelTime(new Date()); |
| | | siteBooking.setRefundOrderNo(trade_no); |
| | | siteBookingService.updateById(siteBooking); |
| | | if(null != siteBooking.getUserCouponId()){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(siteBooking.getUserCouponId()); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | } |
| | | |
| | | if(siteBooking.getPayType() == 3){//玩湃币 |
| | | AppUser appUser = appUserClient.queryAppUser(siteBooking.getAppUserId()); |
| | | appUser.setPlayPaiCoins(appUser.getPlayPaiCoins() + siteBooking.getPayMoney().intValue()); |
| | | appUserClient.updateAppUser(appUser); |
| | | |
| | | siteBooking.setStatus(5); |
| | | siteBooking.setCancelUserId(uid); |
| | | siteBooking.setCancelTime(new Date()); |
| | | siteBookingService.updateById(siteBooking); |
| | | if(null != siteBooking.getUserCouponId()){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(siteBooking.getUserCouponId()); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | } |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 继续支付我预约的场地 |
| | | * @param id |
| | | * @param payType |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil continuePaymentMySite(Integer uid, Integer id, Integer payType) throws Exception { |
| | | SiteBooking siteBooking = siteBookingService.getById(id); |
| | | if(siteBooking.getStatus() != 0){ |
| | | return ResultUtil.error("不能继续支付"); |
| | | } |
| | | 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.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | if(appUser.getPlayPaiCoins().compareTo(payMoney.intValue()) < 0){ |
| | | return ResultUtil.error("玩湃币不足"); |
| | | } |
| | | }else{ |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | |
| | | //校验优惠券 |
| | | Long couponId = siteBooking.getUserCouponId(); |
| | | if(null != couponId && payType != 3){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); |
| | | Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); |
| | | if(coupon.getType() == 1){//满减 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | if(coupon.getType() == 2){//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | if(null != couponId && payType == 3){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | siteBooking.setOrderNo(sdf.format(new Date()) + UUIDUtil.getNumberRandom(3)); |
| | | siteBooking.setPayType(payType); |
| | | siteBooking.setPayMoney(payMoney); |
| | | if(payType == 3){ |
| | | siteBooking.setUserCouponId(null); |
| | | } |
| | | siteBookingService.updateById(siteBooking); |
| | | if(payType == 1){//微信支付 |
| | | return weChatPaymentSite(payMoney, siteBooking); |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | return aliPaymentSite(payMoney, siteBooking); |
| | | } |
| | | if(payType == 3){//玩湃币支付 |
| | | return playPaiCoinPaymentSite(appUser, payMoney, siteBooking); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取继续支付金额 |
| | | * @param id |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil<Map<String, Double>> queryContinuePaymentMySitePrice(Integer id) throws Exception { |
| | | SiteBooking siteBooking = siteBookingService.getById(id); |
| | | if(siteBooking.getStatus() != 0){ |
| | | return ResultUtil.error("不能继续支付"); |
| | | } |
| | | 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(); |
| | | map.put("playPaiCoin", payMoney); |
| | | payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | |
| | | //校验优惠券 |
| | | Long couponId = siteBooking.getUserCouponId(); |
| | | if(null != couponId){ |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); |
| | | Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); |
| | | if(coupon.getType() == 1){//满减 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | if(coupon.getType() == 2){//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | payMoney = new BigDecimal(payMoney).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
| | | } |
| | | } |
| | | map.put("cash", payMoney); |
| | | return ResultUtil.success(map); |
| | | } |
| | | } |