| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.BalanceChangeRecordClient; |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.enums.OrderStatus; |
| | | import com.ruoyi.order.enums.OrderType; |
| | | import com.ruoyi.order.mapper.OrderGoodMapper; |
| | | import com.ruoyi.order.mapper.OrderMapper; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderBalancePayment; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import com.ruoyi.order.model.RefundPass; |
| | | import com.ruoyi.order.service.CommissionService; |
| | | import com.ruoyi.order.service.OrderBalancePaymentService; |
| | | import com.ruoyi.order.service.OrderService; |
| | | import com.ruoyi.order.service.RefundPassService; |
| | | import com.ruoyi.order.util.ExpressDeliveryUtil; |
| | | import com.ruoyi.order.util.payment.PaymentUtil; |
| | | import com.ruoyi.order.util.payment.model.RefundCallbackResult; |
| | | import com.ruoyi.order.util.payment.model.RefundResult; |
| | | import com.ruoyi.order.util.vo.QueryKD100Vo; |
| | | import com.ruoyi.order.vo.*; |
| | | import com.ruoyi.other.api.domain.*; |
| | |
| | | |
| | | @Resource |
| | | private GoodsClient goodsClient; |
| | | |
| | | @Resource |
| | | private RefundPassService refundPassService; |
| | | |
| | | |
| | | |
| | |
| | | orderGoodsVO.setType(goods.getType()); |
| | | orderGoodsVO.setGoodsPic(goods.getHomePagePicture()); |
| | | orderGoodsVO.setSellingPrice(goods.getSellingPrice()); |
| | | orderGoodsVO.setIntegral(goods.getIntegral()); |
| | | orderGoodsVO.setOriginalPrice(goods.getOriginalPrice()); |
| | | goodsList.add(orderGoodsVO); |
| | | } |
| | | |
| | | |
| | | |
| | | // 收货地址 |
| | | String addressJson = order.getAddressJson(); |
| | | UserAddress userAddress = new UserAddress(); |
| | |
| | | userAddress = JSONObject.parseObject(addressJson, UserAddress.class); |
| | | |
| | | } |
| | | |
| | | // 优惠券 |
| | | String couponJson = order.getCouponJson(); |
| | | CouponInfo couponInfo = new CouponInfo(); |
| | |
| | | if (StringUtils.isNotEmpty(activityJson)){ |
| | | orderActivityInfo = JSONObject.parseObject(activityJson, OrderActivityInfo.class); |
| | | } |
| | | |
| | | OrderDetailVO orderDetailVO = new OrderDetailVO(); |
| | | |
| | | if (CollectionUtil.isNotEmpty(orderGoods)){ |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void writeOff(String code,Integer shopId) { |
| | | public void writeOff(String id,Integer shopId) { |
| | | LoginUser loginUserApplet = tokenService.getLoginUserApplet(); |
| | | Order order = orderMapper.selectOne(new LambdaQueryWrapper<Order>() |
| | | .eq(Order::getId, code)); |
| | | Order order = orderMapper.selectById(id); |
| | | boolean check = check(order, shopId, loginUserApplet.getUserid()); |
| | | if (!check){ |
| | | throw new ServiceException("订单不存在"); |
| | | } |
| | | order.setOrderStatus(OrderStatus.COMPLETED.getCode()); |
| | | orderMapper.updateById(order); |
| | | Integer orderType = order.getOrderType(); |
| | | |
| | | // 售后设置 |
| | | R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(5); |
| | |
| | | String content = baseSetting.getContent(); |
| | | JSONObject jsonObject = JSONObject.parseObject(content); |
| | | Long days = jsonObject.getLong("days"); |
| | | commissionService.addToCommissionDelayQueue(order.getId(), LocalDateTime.now().plusDays(days)); |
| | | order.setOrderStatus(OrderStatus.COMPLETED.getCode()); |
| | | order.setIsCommission(0); |
| | | order.setAfterSaleTime(LocalDateTime.now().plusDays(days)); |
| | | order.setEndTime(LocalDateTime.now()); |
| | | orderMapper.updateById(order); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OrderPageListVo> getOrderPageList(OrderPageList orderPageList) { |
| | | public PageInfo<OrderPageListVo> getOrderPageList(OrderPageList orderPageList) { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userid).getData(); |
| | | if(2 == sysUser.getRoleType()){ |
| | |
| | | } |
| | | } |
| | | |
| | | List<OrderPageListVo> list = this.baseMapper.getOrderPageList(orderPageList); |
| | | PageInfo<OrderPageListVo> pageInfo = new PageInfo(orderPageList.getPageCurr(), orderPageList.getPageSize()); |
| | | |
| | | List<OrderPageListVo> list = this.baseMapper.getOrderPageList(pageInfo, orderPageList); |
| | | for (OrderPageListVo orderPageListVo : list) { |
| | | Long appUserId = orderPageListVo.getAppUserId(); |
| | | AppUser appUser = appUserClient.getAppUserById(appUserId); |
| | | orderPageListVo.setUserName(appUser.getName()); |
| | | orderPageListVo.setPhone(appUser.getPhone()); |
| | | if(null != appUser){ |
| | | orderPageListVo.setUserName(appUser.getName()); |
| | | orderPageListVo.setPhone(appUser.getPhone()); |
| | | } |
| | | RefundPass one = refundPassService.getOne(new LambdaQueryWrapper<RefundPass>().eq(RefundPass::getOrderId, orderPageListVo.getId()).eq(RefundPass::getDelFlag, 0).last(" order by create_time desc limit 0, 1")); |
| | | orderPageListVo.setRefundPassId(null != one ? one.getId().toString() : null); |
| | | } |
| | | return list; |
| | | return pageInfo.setRecords(list); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序取消订单 |
| | | * @param orderId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R cancel(Long orderId) { |
| | | Order order = this.getById(orderId); |
| | | if(null == order){ |
| | | return R.fail("取消失败"); |
| | | } |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | if(!order.getAppUserId().equals(userid)){ |
| | | return R.fail("取消失败"); |
| | | } |
| | | if(!Arrays.asList(1, 2, 3).contains(order.getOrderStatus())){ |
| | | return R.fail("订单取消失败"); |
| | | } |
| | | if(null != order.getAfterSaleTime() && LocalDateTime.now().isAfter(order.getAfterSaleTime())){ |
| | | return R.fail("订单取消失败"); |
| | | } |
| | | order.setOrderStatus(5); |
| | | R r = refundPayMoney(order); |
| | | if(200 == r.getCode()){ |
| | | this.updateById(order); |
| | | } |
| | | return r; |
| | | } |
| | | |
| | | /** |
| | | * 确认发货操作 |
| | | * @param orderId |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R confirmDelivery(String orderId, String code) { |
| | | public R confirmDelivery(Long orderId, String code) { |
| | | Order order = this.getById(orderId); |
| | | if(1 == order.getPayStatus()){ |
| | | return R.fail("订单还未完成支付"); |
| | |
| | | @Override |
| | | public R cancelOrder(Long orderId) { |
| | | Order order = this.getById(orderId); |
| | | if(Arrays.asList(4, 5, 6, 7, 8).contains(order.getOrderStatus())){ |
| | | if(Arrays.asList(5, 6, 7).contains(order.getOrderStatus())){ |
| | | return R.fail("无效的操作"); |
| | | } |
| | | if(LocalDateTime.now().isAfter(order.getAfterSaleTime())){ |
| | | return R.fail("订单取消失败"); |
| | | } |
| | | order.setOrderStatus(5); |
| | | this.updateById(order); |
| | | R r = refundPayMoney(order); |
| | | if(200 == r.getCode()){ |
| | | this.updateById(order); |
| | | } |
| | | return r; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 返回订单支付金额和回退积分和会员等级 |
| | | * @param order |
| | | */ |
| | | public R refundPayMoney(Order order){ |
| | | //开始退款 |
| | | Integer payMethod = order.getPayMethod(); |
| | | BigDecimal paymentAmount = order.getPaymentAmount(); |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | if(1 == payMethod){ |
| | | //微信退款 |
| | | RefundResult refund = PaymentUtil.refund(order.getOrderNumber(), "R" + order.getOrderNumber(), paymentAmount.doubleValue(), "/order/order/refundPayMoneyCallback"); |
| | | if("100".equals(refund.getRa_Status())){ |
| | | order.setRefundStatus(1); |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail(refund.getRc_CodeMsg()); |
| | | } |
| | | } |
| | | if(2 == payMethod){ |
| | | //余额退款 |
| | | OrderBalancePayment orderBalancePayment = orderBalancePaymentService.getOne(new LambdaQueryWrapper<OrderBalancePayment>().eq(OrderBalancePayment::getOrderId, orderId)); |
| | | OrderBalancePayment orderBalancePayment = orderBalancePaymentService.getOne(new LambdaQueryWrapper<OrderBalancePayment>().eq(OrderBalancePayment::getOrderId, order.getId())); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | appUser.setTotalRedPacketAmount(appUser.getTotalRedPacketAmount().add(orderBalancePayment.getRedPacketAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setTotalDistributionAmount(appUser.getTotalDistributionAmount().add(orderBalancePayment.getDistributionAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | if(null != orderBalancePayment){ |
| | | appUser.setTotalRedPacketAmount(appUser.getTotalRedPacketAmount().add(orderBalancePayment.getRedPacketAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setTotalDistributionAmount(appUser.getTotalDistributionAmount().add(orderBalancePayment.getDistributionAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | } |
| | | appUser.setBalance(balance.add(paymentAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setShopAmount(appUser.getShopAmount().subtract(paymentAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | |
| | | //查询最后一次的消费订单 |
| | | Order order1 = this.getOne(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, order.getAppUserId()).eq(Order::getPayStatus, 2).eq(Order::getDelFlag, 0).in(Order::getOrderStatus, Arrays.asList(2, 3, 4, 8)).ne(Order::getId, order.getId()).last(" order by create_time desc limit 0, 1")); |
| | | if(null != order1){ |
| | | appUser.setLastShopTime(order1.getCreateTime()); |
| | | }else{ |
| | | appUser.setLastShopTime(LocalDateTime.MIN); |
| | | } |
| | | |
| | | //构建账户余额流水明细 |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setOrderId(orderId); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setAppUserId(order.getAppUserId()); |
| | | balanceChangeRecord.setChangeType(6); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | if(3 == payMethod){ |
| | | //积分退款 |
| | | appUser.setLavePoint(appUser.getLavePoint() + order.getPoint()); |
| | | |
| | | //开始运费退款,积分支付,运费是单独进行支付的,所以需要单独退款 |
| | | if(null != order.getExpressAmount() && BigDecimal.ZERO.compareTo(order.getExpressAmount()) < 0){ |
| | | BigDecimal expressAmount = order.getExpressAmount(); |
| | | if(1 == order.getExpressPayMethod()){ |
| | | //微信退款 |
| | | RefundResult refund = PaymentUtil.refund(order.getOrderNumber(), "R" + order.getOrderNumber(), expressAmount.doubleValue(), "/order/order/refundExpressPayMoneyCallback"); |
| | | if("100".equals(refund.getRa_Status())){ |
| | | order.setRefundStatus(1); |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail(refund.getRc_CodeMsg()); |
| | | } |
| | | } |
| | | if(2 == order.getExpressPayMethod()){ |
| | | //余额退款 |
| | | OrderBalancePayment orderBalancePayment = orderBalancePaymentService.getOne(new LambdaQueryWrapper<OrderBalancePayment>().eq(OrderBalancePayment::getOrderId, orderId)); |
| | | OrderBalancePayment orderBalancePayment = orderBalancePaymentService.getOne(new LambdaQueryWrapper<OrderBalancePayment>().eq(OrderBalancePayment::getOrderId, order.getId())); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | appUser.setTotalRedPacketAmount(appUser.getTotalRedPacketAmount().add(orderBalancePayment.getRedPacketAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setTotalDistributionAmount(appUser.getTotalDistributionAmount().add(orderBalancePayment.getDistributionAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | if(null != orderBalancePayment){ |
| | | appUser.setTotalRedPacketAmount(appUser.getTotalRedPacketAmount().add(orderBalancePayment.getRedPacketAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setTotalDistributionAmount(appUser.getTotalDistributionAmount().add(orderBalancePayment.getDistributionAmount()).setScale(2, RoundingMode.HALF_EVEN)); |
| | | } |
| | | appUser.setBalance(balance.add(expressAmount).setScale(2, RoundingMode.HALF_EVEN)); |
| | | //构建账户余额流水明细 |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setOrderId(orderId); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setAppUserId(order.getAppUserId()); |
| | | balanceChangeRecord.setChangeType(6); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | } |
| | | |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | //积分退款 |
| | | appUser.setLavePoint(appUser.getLavePoint() + order.getPoint()); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() + order.getPoint()); |
| | | UserPoint userPoint1 = new UserPoint(); |
| | | userPoint1.setType(11); |
| | | userPoint1.setObjectId(order.getId()); |
| | | List<UserPoint> data = userPointClient.getUserPointList(userPoint1).getData(); |
| | | Integer transferablePoint = order.getPoint(); |
| | | if(data.size() > 0){ |
| | | UserPoint userPoint = data.get(0); |
| | | transferablePoint = Integer.valueOf(userPoint.getExtention()); |
| | | } |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() + transferablePoint); |
| | | |
| | | //构建积分流水明细 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(11); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(order.getPoint()); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(order.getAppUserId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | //退回获得的消费积分 |
| | | //需要先检查会员等级时候回回退,使用回退后的会员等级查询配置 |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | Integer getPoint = order.getGetPoint(); |
| | | boolean vipDemotion = vipDemotion(appUser.getShopPoint() - getPoint, appUser.getVipId()); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(vipDemotion ? appUser.getVipId() - 1 : appUser.getVipId()).getData(); |
| | | int earnPoint1 = getPoint; |
| | | int earnPoint1 = 0; |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = getPoint / (100 - pointSetting.getBuyPoint()); |
| | | earnPoint1 = new BigDecimal(getPoint).divide(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser.setLavePoint(lavePoint - getPoint); |
| | | appUser.setShopPoint(appUser.getShopPoint() - earnPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() - earnPoint1); |
| | | appUser.setShopPoint(appUser.getShopPoint() - getPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() - getPoint); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() - earnPoint1); |
| | | appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() - earnPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() - earnPoint1); |
| | | } |
| | | appUser.setTotalPoint(appUser.getTotalPoint() - getPoint); |
| | | if(vipDemotion){ |
| | | appUser.setVipId(appUser.getVipId() - 1); |
| | | } |
| | | |
| | | //构建积分流水明细 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(11); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | Integer point = appUser.getLavePoint() - lavePoint; |
| | | userPoint.setVariablePoint(point >= 0 ? point : point * -1); |
| | | userPoint.setVariablePoint(getPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(order.getAppUserId()); |
| | | userPoint.setObjectId(orderId); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | appUserClient.editAppUserById(appUser); |
| | | |
| | | order.setRefundStatus(2); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 取消订单后回调处理 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R refundPayMoneyCallback(RefundCallbackResult refundCallbackResult) { |
| | | String code = refundCallbackResult.getR3_RefundOrderNo().substring(1); |
| | | Order order = this.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() == 1 || order.getOrderStatus() == 6){ |
| | | return R.ok(); |
| | | } |
| | | order.setRefundCode(refundCallbackResult.getR5_RefundTrxNo()); |
| | | order.setRefundStatus(2); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | this.updateById(order); |
| | | |
| | | //退回获得的消费积分 |
| | | //需要先检查会员等级时候回回退,使用回退后的会员等级查询配置 |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | Integer getPoint = order.getGetPoint(); |
| | | boolean vipDemotion = vipDemotion(appUser.getShopPoint() - getPoint, appUser.getVipId()); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(vipDemotion ? appUser.getVipId() - 1 : appUser.getVipId()).getData(); |
| | | int earnPoint1 = 0; |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = new BigDecimal(getPoint).divide(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser.setShopPoint(appUser.getShopPoint() - getPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() - getPoint); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() - earnPoint1); |
| | | appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() - earnPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() - earnPoint1); |
| | | } |
| | | appUser.setTotalPoint(appUser.getTotalPoint() - getPoint); |
| | | if(vipDemotion){ |
| | | appUser.setVipId(appUser.getVipId() - 1); |
| | | } |
| | | |
| | | //构建积分流水明细 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(getPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(order.getAppUserId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | appUserClient.editAppUserById(appUser); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 取消订单快递费回退 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R refundExpressPayMoneyCallback(RefundCallbackResult refundCallbackResult) { |
| | | String code = refundCallbackResult.getR3_RefundOrderNo().substring(1); |
| | | Order order = this.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() == 1 || order.getOrderStatus() == 6){ |
| | | return R.ok(); |
| | | } |
| | | order.setRefundCode(refundCallbackResult.getR5_RefundTrxNo()); |
| | | order.setRefundStatus(2); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | this.updateById(order); |
| | | |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | //积分退款 |
| | | appUser.setLavePoint(appUser.getLavePoint() + order.getPoint()); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() + order.getPoint()); |
| | | UserPoint userPoint1 = new UserPoint(); |
| | | userPoint1.setType(11); |
| | | userPoint1.setObjectId(order.getId()); |
| | | List<UserPoint> data = userPointClient.getUserPointList(userPoint1).getData(); |
| | | Integer transferablePoint = order.getPoint(); |
| | | if(data.size() > 0){ |
| | | UserPoint userPoint = data.get(0); |
| | | transferablePoint = Integer.valueOf(userPoint.getExtention()); |
| | | } |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() + transferablePoint); |
| | | |
| | | //构建积分流水明细 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(11); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(order.getPoint()); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(order.getAppUserId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | |
| | | //退回获得的消费积分 |
| | | //需要先检查会员等级时候回回退,使用回退后的会员等级查询配置 |
| | | lavePoint = appUser.getLavePoint(); |
| | | Integer getPoint = order.getGetPoint(); |
| | | boolean vipDemotion = vipDemotion(appUser.getShopPoint() - getPoint, appUser.getVipId()); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(vipDemotion ? appUser.getVipId() - 1 : appUser.getVipId()).getData(); |
| | | int earnPoint1 = 0; |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = new BigDecimal(getPoint).divide(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); |
| | | } |
| | | appUser.setShopPoint(appUser.getShopPoint() - getPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() - getPoint); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() - earnPoint1); |
| | | appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() - earnPoint1); |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() - earnPoint1); |
| | | } |
| | | appUser.setTotalPoint(appUser.getTotalPoint() - getPoint); |
| | | if(vipDemotion){ |
| | | appUser.setVipId(appUser.getVipId() - 1); |
| | | } |
| | | |
| | | //构建积分流水明细 |
| | | userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(getPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(order.getAppUserId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | appUserClient.editAppUserById(appUser); |
| | | |
| | | order.setRefundStatus(2); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 会员降级检测 |
| | | */ |
| | |
| | | VipSetting vipSetting = vipSettingClient.getVipSetting(vipId).getData(); |
| | | Integer vipLevelUpShopRole = vipSetting.getVipLevelUpShopRole(); |
| | | Integer vipLevelUpShop = vipSetting.getVipLevelUpShop(); |
| | | if(1 == vipLevelUpShopRole && shopPoint < vipLevelUpShop){ |
| | | return true; |
| | | } |
| | | return false; |
| | | return 1 == vipLevelUpShopRole && shopPoint < vipLevelUpShop; |
| | | } |
| | | |
| | | |
| | |
| | | return R.fail("无效的操作"); |
| | | } |
| | | order.setOrderStatus(4); |
| | | R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(5); |
| | | if (R.isError(baseSettingR)) { |
| | | return R.fail("售后设置获取失败"); |
| | | } |
| | | BaseSetting baseSetting = baseSettingR.getData(); |
| | | if (baseSetting == null) { |
| | | return R.fail("售后设置获取失败"); |
| | | } |
| | | String content = baseSetting.getContent(); |
| | | JSONObject jsonObject = JSONObject.parseObject(content); |
| | | Long days = jsonObject.getLong("days"); |
| | | order.setAfterSaleTime(LocalDateTime.now().plusDays(days)); |
| | | this.updateById(order); |
| | | return R.ok(); |
| | | } |
| | |
| | | orderInfo.setOrderStatus(order.getOrderStatus()); |
| | | orderInfo.setCreateTime(order.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | orderInfo.setUserName(appUser.getName()); |
| | | orderInfo.setPhone(appUser.getPhone()); |
| | | orderInfo.setOrderType(order.getOrderType() == 1 ? "服务" : (StringUtils.isNotEmpty(order.getExpressJson()) ? "单品-快递配送" : "单品-自提")); |
| | | if(null != appUser){ |
| | | orderInfo.setUserName(appUser.getName()); |
| | | orderInfo.setPhone(appUser.getPhone()); |
| | | } |
| | | orderInfo.setOrderType(order.getOrderType() == 1 ? "服务" : (StringUtils.isNotEmpty(order.getAddressJson()) ? "单品-快递配送" : "单品-上门自提")); |
| | | Shop shop = shopClient.getShopById(order.getShopId()).getData(); |
| | | if(null != shop){ |
| | | orderInfo.setShopName(shop.getName()); |
| | |
| | | orderInfo.setGoodsJson(JSON.toJSONString(goodsJson)); |
| | | return orderInfo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取商品销售数量 |
| | | * @param goodsId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getGoodsSaleNum(Integer goodsId, Integer type) { |
| | | return this.baseMapper.getGoodsSaleNum(goodsId, type); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取店铺订单数量 |
| | | * @param shopId |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getShopSaleNum(Integer shopId, Integer type) { |
| | | return this.baseMapper.getShopSaleNum(shopId, type); |
| | | } |
| | | } |