From 8c55ab2701c99cec16eff92a26fefdf77fcdd28f Mon Sep 17 00:00:00 2001 From: liujie <liujie> Date: 星期一, 25 九月 2023 16:17:44 +0800 Subject: [PATCH] app接口修改 --- cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java | 319 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 285 insertions(+), 34 deletions(-) diff --git a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java index 6a309f0..5bcce9e 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java +++ b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java @@ -1,5 +1,6 @@ package com.dsh.other.service.impl; +import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -11,11 +12,15 @@ import com.dsh.other.feignclient.activity.CouponClient; import com.dsh.other.feignclient.activity.UserCouponClient; import com.dsh.other.feignclient.activity.model.Coupon; +import com.dsh.other.feignclient.activity.model.QueryUserCouponByIdAndUserId; import com.dsh.other.feignclient.activity.model.UserCoupon; +import com.dsh.other.feignclient.model.SiteChangeStateVO; import com.dsh.other.mapper.SiteMapper; import com.dsh.other.model.*; import com.dsh.other.service.*; import com.dsh.other.util.*; +import io.swagger.models.auth.In; +import org.aspectj.weaver.ast.Var; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -55,6 +60,8 @@ @Autowired private PayMoneyUtil payMoneyUtil; + @Autowired + private SiteMapper siteMapper; @@ -103,7 +110,29 @@ querySiteInfoVo.setStoreLon(store.getLon()); querySiteInfoVo.setStoreLat(store.getLat()); querySiteInfoVo.setStorePhone(store.getPhone()); + querySiteInfoVo.setImgs(site.getImgs()); querySiteInfoVo.setDistance(0D); + querySiteInfoVo.setCashPriceOne(site.getCashPriceOne()); + if(site.getPlayPaiCoinOne()!=null){ + querySiteInfoVo.setPlayPaiCoinOne(site.getPlayPaiCoinOne().intValue()); + } + + querySiteInfoVo.setIntroduce(site.getIntroduce()); + ArrayList<String> nextName = new ArrayList<>(); + ArrayList<String> halfName = new ArrayList<>(); + String nextName1 = site.getNextName(); + String halfName1 = site.getHalfName(); + querySiteInfoVo.setIshalf(site.getIshalf()); + String[] split = nextName1.split(","); + for (String s : split) { + nextName.add(s); + } + String[] split1 = halfName1.split(","); + for (String s : split1) { + halfName.add(s); + } + querySiteInfoVo.setHalfName(halfName); + querySiteInfoVo.setNextName(nextName); if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){ Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat()); double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); @@ -132,20 +161,29 @@ e.setTime(sdf.parse(day + " " + site.getAppointmentEndTime())); int hour = e.get(Calendar.HOUR_OF_DAY); + int minute = e.get(Calendar.MINUTE); + List<QuerySiteTimes> list = new ArrayList<>(); + + SimpleDateFormat sdfs = new SimpleDateFormat("HH:mm"); + while (true){ - int s_hour = s.get(Calendar.HOUR_OF_DAY); - int s_minute = s.get(Calendar.MINUTE); - String start = s_hour + ":" + s_minute; + + String start = sdfs.format(s.getTime()); s.set(Calendar.MINUTE, s.get(Calendar.MINUTE) + 30); + int e_hour = s.get(Calendar.HOUR_OF_DAY); + int e_minute = s.get(Calendar.MINUTE); - String end = e_hour + ":" + e_minute; + + String end = sdfs.format(s.getTime()); QuerySiteTimes querySiteTimes = new QuerySiteTimes(); + querySiteTimes.setTime(start + "-" + end); + querySiteTimes.setSelectable(1); SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("siteId", id).eq("state", 1) @@ -179,12 +217,6 @@ 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]; @@ -197,10 +229,9 @@ } } - String s_time = split[0]; String e_time = split[split.length - 1]; - s_time = s_time.substring(s_time.lastIndexOf("-")); + s_time = s_time.substring(0,s_time.lastIndexOf("-")); String[] s1 = e_time.split(" "); e_time = s1[0] + " " + s1[1].split("-")[1]; SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @@ -208,6 +239,9 @@ 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(); } @@ -215,7 +249,7 @@ //校验优惠券 Long couponId = reservationSite.getCouponId(); if(null != couponId && reservationSite.getPayType() != 3){ - UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); + UserCoupon userCoupon = userCouponClient.queryUserCouponById(new QueryUserCouponByIdAndUserId(reservationSite.getCouponId(),uid)); if(userCoupon.getStatus() == 2){ return ResultUtil.error("优惠券已被核销"); } @@ -225,9 +259,10 @@ return ResultUtil.error("优惠券已过期"); } if(coupon.getType() == 1){//满减 +// {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} JSONObject jsonObject = JSON.parseObject(coupon.getContent()); - Double num1 = jsonObject.getDouble("num1"); - Double num2 = jsonObject.getDouble("num2"); + Double num1 = jsonObject.getDouble("conditionalAmount"); + Double num2 = jsonObject.getDouble("deductionAmount"); if(payMoney.compareTo(num1) <= 0){ return ResultUtil.error("该优惠券无法使用"); } @@ -236,7 +271,7 @@ } if(coupon.getType() == 2){//代金券 JSONObject jsonObject = JSON.parseObject(coupon.getContent()); - Double num1 = jsonObject.getDouble("num1"); + Double num1 = jsonObject.getDouble("conditionalAmount"); if(payMoney.compareTo(num1) <= 0){ return ResultUtil.error("该优惠券无法使用"); } @@ -256,6 +291,7 @@ 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()); @@ -266,10 +302,15 @@ siteBooking.setStatus(0); siteBooking.setState(1); siteBooking.setInsertTime(new Date()); + + // 2.0 + siteBooking.setNextName(reservationSite.getNextName()); + siteBooking.setIsHalf(reservationSite.getIsHalf()); + siteBooking.setHalfName(reservationSite.getHalfName()); siteBookingService.save(siteBooking); if(reservationSite.getPayType() == 1){//微信支付 - return weChatPaymentSite(uid, payMoney, siteBooking); + return weChatPaymentSite(payMoney, siteBooking); } if(reservationSite.getPayType() == 2){//支付宝支付 return aliPaymentSite(payMoney, siteBooking); @@ -283,12 +324,11 @@ /** * 课程微信支付 - * @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", ""); @@ -322,13 +362,6 @@ 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)){ @@ -390,13 +423,6 @@ 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)){ @@ -422,7 +448,7 @@ /** - * 玩湃币支付课程 + * 玩湃币支付 * @param appUser * @param paymentPrice * @return @@ -437,4 +463,229 @@ 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; + 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){ + + queryMySiteVo.setPlayPaiCoin(site.getPlayPaiCoin() * split.length); + } + } + return queryMySiteVos; + } + + + /** + * 取消我的预约场地 + * @param id + * @return + * @throws Exception + */ + @Override + public ResultUtil cancelMySite(Integer uid, Integer id) throws Exception { + SiteBooking siteBooking = siteBookingService.getById(id); + + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + Date startTime = siteBooking.getStartTime(); + if(format.format(new Date()).equals(format.format(startTime))){ + return ResultUtil.error("预约当天,不能取消"); + } + 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(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(),siteBooking.getAppUserId())); + 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(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(),appUser.getId())); + 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.getPlayPaiCoin()).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(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(),appUser.getId())); + Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); + if(coupon.getType() == 1){//满减 +// {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} + 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(); + } + 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(); + } + userCoupon.setStatus(2); + userCouponClient.updateUserCoupon(userCoupon); + } + if(null != couponId && payType == 3){ + UserCoupon userCoupon = userCouponClient.queryUserCouponById(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(),appUser.getId())); + 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(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(),siteBooking.getAppUserId())); + Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); + if(coupon.getType() == 1){//满减 +// {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} + 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(); + } + 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(); + } + } + map.put("cash", payMoney); + return ResultUtil.success(map); + } + + @Override + public Object changeState(SiteChangeStateVO vo) { + + List<Integer> siteIds = vo.getSiteIds(); + Integer type = vo.getType(); + return siteMapper.changeState(siteIds,type); + + } } -- Gitblit v1.7.1