| | |
| | | import com.alipay.api.response.AlipayTradeOrderSettleResponse; |
| | | import com.alipay.api.response.AlipayTradeQueryResponse; |
| | | import com.alipay.api.response.AlipayTradeRoyaltyRelationBindResponse; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | Store s = null; |
| | | Double d = 0D; |
| | | for (Store store : stores) { |
| | | if (store == null || !isValidCoordinate(store.getLon(), store.getLat())) { |
| | | continue; |
| | | } |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | if (s == null || d > wgs84) { |
| | |
| | | d = wgs84; |
| | | } |
| | | } |
| | | joinPlayPaiVo.setName(s.getName()); |
| | | joinPlayPaiVo.setLon(s.getLon()); |
| | | joinPlayPaiVo.setLat(s.getLat()); |
| | | joinPlayPaiVo.setStoreId(s.getId()); |
| | | joinPlayPaiVo.setPhone(s.getPhone()); |
| | | joinPlayPaiVo.setProvince(s.getProvince()); |
| | | joinPlayPaiVo.setProvinceCode(s.getProvinceCode()); |
| | | joinPlayPaiVo.setCity(s.getCity()); |
| | | joinPlayPaiVo.setCityCode(s.getCityCode()); |
| | | if (s != null) { |
| | | joinPlayPaiVo.setName(s.getName()); |
| | | joinPlayPaiVo.setLon(s.getLon()); |
| | | joinPlayPaiVo.setLat(s.getLat()); |
| | | joinPlayPaiVo.setStoreId(s.getId()); |
| | | joinPlayPaiVo.setPhone(s.getPhone()); |
| | | joinPlayPaiVo.setProvince(s.getProvince()); |
| | | joinPlayPaiVo.setProvinceCode(s.getProvinceCode()); |
| | | joinPlayPaiVo.setCity(s.getCity()); |
| | | joinPlayPaiVo.setCityCode(s.getCityCode()); |
| | | } |
| | | } |
| | | return joinPlayPaiVo; |
| | | } |
| | | |
| | | private boolean isValidCoordinate(String lon, String lat) { |
| | | if (ToolUtil.isEmpty(lon) || ToolUtil.isEmpty(lat)) { |
| | | return false; |
| | | } |
| | | try { |
| | | double longitude = Double.parseDouble(lon.trim()); |
| | | double latitude = Double.parseDouble(lat.trim()); |
| | | return Double.isFinite(longitude) && Double.isFinite(latitude) |
| | | && longitude >= -180 && longitude <= 180 |
| | | && latitude >= -90 && latitude <= 90; |
| | | } catch (NumberFormatException e) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | return ResultUtil.error("商品不存在"); |
| | | } |
| | | |
| | | BigDecimal cashAmount = merchandise.getCash() == null ? BigDecimal.ZERO : merchandise.getCash(); |
| | | // 门票优惠后的订单现金应付总额;支付参数必须使用该金额,不能再使用商品原价。 |
| | | BigDecimal ticketPayableCashAmount = null; |
| | | UserCoupon usedCoupon = null; |
| | | if (exchangeType.getGoodsType() == 3 && exchangeType.getCouponId() != null && exchangeType.getCouponId() != 0) { |
| | | if (exchangeType.getExchangeType() == 1) { |
| | | return ResultUtil.error("积分兑换不能使用优惠券"); |
| | | } |
| | | usedCoupon = userConponClient.queryUserCouponById( |
| | | new QueryUserCouponByIdAndUserId(exchangeType.getCouponId(), userIdFormRedis)); |
| | | if (usedCoupon == null || !Integer.valueOf(1).equals(usedCoupon.getStatus())) { |
| | | return ResultUtil.error("优惠券不可用"); |
| | | } |
| | | Coupon coupon = userConponClient.queryCouponById(usedCoupon.getCouponId()); |
| | | if (coupon == null || coupon.getEndTime() == null || !coupon.getEndTime().after(new Date())) { |
| | | return ResultUtil.error("优惠券已过期"); |
| | | } |
| | | if (Integer.valueOf(3).equals(coupon.getUseScope()) |
| | | && (exchangeType.getStoreId() == null || !userConponClient.getCouponStoreIds(coupon.getId()).contains(exchangeType.getStoreId()))) { |
| | | return ResultUtil.error("该优惠券不适用于所选门店"); |
| | | } |
| | | BigDecimal orderCash = cashAmount.multiply(BigDecimal.valueOf(exchangeType.getNums() == null ? 1 : exchangeType.getNums())); |
| | | JSONObject rule = JSON.parseObject(coupon.getContent()); |
| | | if (Integer.valueOf(1).equals(coupon.getType())) { |
| | | BigDecimal condition = rule.getBigDecimal("conditionalAmount"); |
| | | BigDecimal deduction = rule.getBigDecimal("deductionAmount"); |
| | | if (condition == null || deduction == null || orderCash.compareTo(condition) < 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | cashAmount = orderCash.subtract(deduction).max(BigDecimal.ZERO) |
| | | .divide(BigDecimal.valueOf(exchangeType.getNums() == null ? 1 : exchangeType.getNums()), 2, java.math.RoundingMode.HALF_UP); |
| | | } else if (Integer.valueOf(2).equals(coupon.getType())) { |
| | | BigDecimal deduction = rule.getBigDecimal("conditionalAmount"); |
| | | if (deduction == null || orderCash.compareTo(deduction) < 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | ticketPayableCashAmount = orderCash.subtract(deduction).max(BigDecimal.ZERO); |
| | | cashAmount = ticketPayableCashAmount |
| | | .divide(BigDecimal.valueOf(exchangeType.getNums() == null ? 1 : exchangeType.getNums()), 2, java.math.RoundingMode.HALF_UP); |
| | | } else { |
| | | return ResultUtil.error("该优惠券不支持购买门票"); |
| | | } |
| | | } |
| | | |
| | | TAppUser tAppUser = this.baseMapper.selectById(userIdFormRedis); |
| | | |
| | | if (merchandise.getUserPopulation() == 2) { |
| | |
| | | } else { |
| | | goodsNums = exchangeType.getNums(); |
| | | } |
| | | BigDecimal cashPaymentAmount = ticketPayableCashAmount == null |
| | | ? cashAmount.multiply(BigDecimal.valueOf(goodsNums)) |
| | | : ticketPayableCashAmount; |
| | | |
| | | TAppUser user = appUserService.getById(userIdFormRedis); |
| | | if (merchandise.getIntegral() != null) { |
| | |
| | | if (exchangeType.getExchangeType() == 1) { |
| | | pointsMerchandise.setPayStatus(2); |
| | | pointsMerchandise.setPaymentTime(new Date()); |
| | | } else if (cashPaymentAmount.compareTo(BigDecimal.ZERO) == 0) { |
| | | // 优惠券将现金部分完全抵扣时,不能向第三方支付发起 0 元或原价支付。 |
| | | pointsMerchandise.setPayStatus(2); |
| | | pointsMerchandise.setPaymentTime(new Date()); |
| | | } else { |
| | | pointsMerchandise.setPayStatus(1); |
| | | } |
| | |
| | | pointsMerchandise.setCode(code); |
| | | pointsMerchandise.setInsertTime(new Date()); |
| | | pointsMerchandise.setPayType(exchangeType.getExchangeType()); |
| | | pointsMerchandise.setUserCouponId(exchangeType.getGoodsType() == 3 ? exchangeType.getCouponId() : null); |
| | | if (null != merchandise.getIntegral()) { |
| | | pointsMerchandise.setIntegral(merchandise.getIntegral() * goodsNums); |
| | | } |
| | | if (exchangeType.getExchangeType() == 2 || exchangeType.getExchangeType() == 3) { |
| | | pointsMerchandise.setCash(merchandise.getCash()); |
| | | pointsMerchandise.setCash(exchangeType.getGoodsType() == 3 ? cashPaymentAmount : cashAmount); |
| | | pointsMerchandise.setCashPayType(exchangeType.getPayType()); |
| | | } |
| | | |
| | | Double m = new BigDecimal((merchandise.getIntegral() == null ? 0 : merchandise.getIntegral())).add((merchandise.getCash() == null ? BigDecimal.ZERO : merchandise.getCash())).doubleValue(); |
| | | Double m = new BigDecimal((merchandise.getIntegral() == null ? 0 : merchandise.getIntegral())).add(cashAmount).doubleValue(); |
| | | if ((m * goodsNums) == 0) { |
| | | pointsMerchandise.setPayStatus(2); |
| | | pointsMerchandise.setPaymentTime(new Date()); |
| | | } |
| | | returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise); |
| | | if (usedCoupon != null) { |
| | | usedCoupon.setStatus(2); |
| | | userConponClient.updateUserCoupon(usedCoupon); |
| | | } |
| | | if(goodsNums>1){ |
| | | System.err.println("购买商品数量"+goodsNums); |
| | | List<UserPointsMerchandise> userPointsMerchandises = new ArrayList<>(); |
| | | for (int i = 1; i < goodsNums; i++) { |
| | | UserPointsMerchandise userPointsMerchandise = new UserPointsMerchandise(); |
| | | BeanUtils.copyProperties(pointsMerchandise, userPointsMerchandise); |
| | | // 一笔订单只能关联一次优惠券,避免拆分门票后重复计入优惠金额。 |
| | | userPointsMerchandise.setUserCouponId(null); |
| | | if (exchangeType.getGoodsType() == 3) { |
| | | // 门票拆单后仅首条保留订单总实付金额,避免支付/收入统计重复累加。 |
| | | userPointsMerchandise.setCash(BigDecimal.ZERO); |
| | | } |
| | | userPointsMerchandises.add(userPointsMerchandise); |
| | | } |
| | | System.err.println("新增额外购买记录"+userPointsMerchandises); |
| | |
| | | } |
| | | |
| | | } |
| | | if ((m * goodsNums) == 0 && pointsMerchandise.getPayStatus() == 2) { |
| | | if (pointsMerchandise.getPayStatus() == 2 && exchangeType.getExchangeType() != 1 |
| | | && cashPaymentAmount.compareTo(BigDecimal.ZERO) == 0) { |
| | | // 积分+现金商品被优惠券抵扣为零元时,仍需扣除积分;不等待支付回调。 |
| | | if (exchangeType.getExchangeType() == 2 && merchandise.getIntegral() != null |
| | | && merchandise.getIntegral() > 0 |
| | | && !dealAppUserIntegral(userIdFormRedis, tAppUser, merchandise.getIntegral() * goodsNums)) { |
| | | return ResultUtil.error("用户积分不足!"); |
| | | } |
| | | returnModel.setReturnId(returnId); |
| | | return ResultUtil.success(returnModel); |
| | | } |
| | |
| | | break; |
| | | } |
| | | } |
| | | coursePackageOrder.setCashPayment(merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size()))); |
| | | coursePackageOrder.setCashPayment(cashAmount.multiply(new BigDecimal(exchangeType.getStuIds().size()))); |
| | | coursePackageOrder.setPlayPaiCoin(merchandise.getIntegral() * exchangeType.getStuIds().size()); |
| | | coursePackageOrder.setPayUserType(1); |
| | | coursePackageOrder.setPayStatus(1); |
| | |
| | | coursePackageOrder.setInsertTime(new Date()); |
| | | coursePackageOrder.setOrderType(2); |
| | | paymentClient.savePaymentCoursePackage(coursePackageOrder); |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | return WechatPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else if (merchandise.getType() == 1) { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | return WechatPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } else if (merchandise.getType() == 3) { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | return WechatPayment(merchandise.getType(), cashPaymentAmount, code, merchandise.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | return ResultUtil.runErr(); |
| | | } |
| | | case 2: |
| | | if (merchandise.getType() == 2) { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | return AlipayPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else if (merchandise.getType() == 3) { |
| | | return AlipayPayment(merchandise.getType(), cashPaymentAmount, code, merchandise.getId()); |
| | | } else { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | return AlipayPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } |
| | | default: |
| | | break; |
| | |
| | | case 1: |
| | | try { |
| | | if (merchandise.getType() == 2) { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | return WechatPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else if (merchandise.getType() == 3) { |
| | | return WechatPayment(merchandise.getType(), cashPaymentAmount, code, merchandise.getId()); |
| | | } else { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | return WechatPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | return ResultUtil.runErr(); |
| | | } |
| | | case 2: |
| | | if (merchandise.getType() == 2) { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | return AlipayPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else if (merchandise.getType() == 3) { |
| | | return AlipayPayment(merchandise.getType(), cashPaymentAmount, code, merchandise.getId()); |
| | | } else { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | return AlipayPayment(merchandise.getType(), cashAmount.multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } |
| | | default: |
| | | break; |