huliguo
2025-04-17 19df67e19f23cd2a04d1c7f355e1e656f4140af4
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -5,6 +5,9 @@
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.feignClient.*;
import com.ruoyi.account.api.model.*;
@@ -54,12 +57,12 @@
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.*;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -107,7 +110,10 @@
    private RedisTemplate redisTemplate;
    @Resource
    private  ShopBalanceStatment shopBalanceStatment;
    private  ShopBalanceStatementClient shopBalanceStatementClient;
    @Resource
    private GoodsEvaluateClient goodsEvaluateClient;
    @Resource
    private SystemConfigClient systemConfigClient;
@@ -139,21 +145,35 @@
        OrderGood orderGood = orderGoodMapper.selectOne(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, orderId));
        String goodJson = orderGood.getGoodJson();
        Goods goods = JSONObject.parseObject(goodJson, Goods.class);
        GoodsSeckill goodsSeckill = JSON.parseObject(orderGood.getSeckillJson(), GoodsSeckill.class);
        OrderGoodsVO orderGoodsVO = new OrderGoodsVO();
        BeanUtils.copyProperties(orderGood, orderGoodsVO);
        orderGoodsVO.setGoodsId(goods.getId());
        orderGoodsVO.setGoodsName(goods.getName());
        orderGoodsVO.setGoodsPic(goods.getHomePagePicture());
        orderGoodsVO.setNum(order.getNum());
        if (null!=goodsSeckill){
            orderGoodsVO.setSellingPrice(goodsSeckill.getSellingPrice());
            orderGoodsVO.setIntegral(goodsSeckill.getIntegral());
        }else {
            orderGoodsVO.setSellingPrice(goods.getSellingPrice());
            orderGoodsVO.setIntegral(goods.getIntegral());
        }
        orderGoodsVO.setOriginalPrice(goods.getOriginalPrice());
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        orderDetailVO.setOrderGoodsVO(orderGoodsVO);
        Shop shop = shopR.getData();
        orderDetailVO.setId(order.getId());
        orderDetailVO.setOrderStatus(order.getOrderStatus());
        orderDetailVO.setPoint(order.getPoint());
        orderDetailVO.setPoint(order.getPoint());//使用的积分
        orderDetailVO.setOrderNumber(order.getOrderNumber());
        orderDetailVO.setCreateTime(order.getCreateTime());
        orderDetailVO.setTotalAmount(order.getTotalAmount());
        orderDetailVO.setPointDeductionAmount(order.getPointDeductionAmount());//积分抵扣金额
        orderDetailVO.setPaymentAmount(order.getPaymentAmount());
        orderDetailVO.setShopName(shop.getName());
        orderDetailVO.setShopAddress(shop.getAddress());
@@ -168,6 +188,14 @@
            e.printStackTrace();
            throw new ServiceException("生成核销码失败");
        }
        if(3!=order.getOrderStatus()){
            //不属于未使用的,应该有个核销\取消时间
            orderDetailVO.setEndTime(order.getEndTime());
        }
        //该商品是否被用户评论
        Long evaluateId = goodsEvaluateClient.getEvaluateIdByOrderId(order.getId()).getData();
        orderDetailVO.setEvaluateId(evaluateId);
        return orderDetailVO;
    }
@@ -183,13 +211,19 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void writeOff(String id, Integer shopId, String technicianId) {
    public void writeOff(String id, Integer shopId) {
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        Order order = orderMapper.selectById(id);
        boolean check = check(order, shopId, loginUserApplet.getUserid());
        if (!check) {
        if (order == null) {
            throw new ServiceException("订单不存在");
        }
        if (!order.getShopId().equals(shopId)) {
            throw new ServiceException("该订单与当前扫码门店不一致");
        }
        if (order.getOrderStatus()!=3){
            throw new ServiceException("订单已被核销过");
        }
        // 售后设置
        R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(5);
@@ -207,10 +241,11 @@
        order.setAfterSaleTime(LocalDateTime.now().plusDays(days));
        order.setEndTime(LocalDateTime.now());
        order.setCancellerAppUserId(loginUserApplet.getUserid());
        if (StringUtils.isNotEmpty(technicianId) && !"null".equals(technicianId)) {
//            order.setTechnicianId(Integer.valueOf(technicianId));
        }
        orderMapper.updateById(order);
        //店铺可用金额增加
        Shop shop = shopClient.getShopById(shopId).getData();
        shop.setCanWithdrawMoney(shop.getCanWithdrawMoney().add(order.getTotalAmount()));
        shopClient.updateShop(shop);
    }
@@ -222,7 +257,7 @@
     */
    @Override
    public PageInfo<OrderPageListVo> getOrderPageList(OrderPageList orderPageList) {
        Long userid = tokenService.getLoginUser().getUserid();
       /* Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        if (2 == sysUser.getRoleType()) {
            orderPageList.setShopId(sysUser.getObjectId());
@@ -290,7 +325,8 @@
            }
        }
        return pageInfo.setRecords(list);
        return pageInfo.setRecords(list);*/
        return null;
    }
    /**
@@ -318,9 +354,6 @@
    /**
     * 小程序取消订单
     *
     * @param orderId
     * @return
     */
    @Override
    public R cancel(Long orderId) {
@@ -339,14 +372,9 @@
            return R.fail("订单取消失败");
        }
        order.setOrderStatus(5);
        //todo 商品销售数量
        R r = refundPayMoney(order);
        if (200 == r.getCode()) {
            this.updateById(order);
        }
        R r2 = userPointClient.deleteUserPointCopy(orderId, Arrays.asList(8));//门店业绩
        if (200 != r2.getCode()) { // 项目没有分布式事务,此处报错可能会导致数据不一致
            throw new RuntimeException("订单取消失败");
        }
        return r;
    }
@@ -379,72 +407,92 @@
    /**
     * 返回订单支付金额和回退积分和会员等级
     *
     * @param order
     * 回退积分和返回订单支付金额
     */
    public R refundPayMoney(Order order) {
        //开始退款
        BigDecimal paymentAmount = order.getPaymentAmount();
        AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
        if (BigDecimal.ZERO.compareTo(order.getPaymentAmount()) < 0) {//支付的金额是否大于0
            //微信退款
            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 (!"100".equals(refund.getRa_Status())) {
                return R.fail(refund.getRc_CodeMsg());//退款失败
            }
        }
        if (0 != order.getPoint()) {//使用的积分是否为0
            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 appUser = appUserClient.getAppUserById(order.getAppUserId());
        if (order.getPoint()>0) {
            if(null==appUser.getCancelPoint()){
                appUser.setCancelPoint(0);
            }
            appUser.setTransferablePoint(appUser.getTransferablePoint() + transferablePoint);
            //返回订单抵扣积分
            Integer historicalPoint = appUser.getAvailablePoint();
            Integer availablePoint = appUser.getAvailablePoint() + order.getPoint();//可用积分
            Integer cancelPoint = appUser.getCancelPoint() + order.getPoint();//取消订单积分
            //构建积分流水明细
            if (order.getPoint() > 0) {
                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);
            }
            appUser.setAvailablePoint(availablePoint);
            appUser.setCancelPoint(cancelPoint);
            appUser.setTotalPoint(appUser.getTotalPoint() + order.getPoint());
            appUserClient.editAppUserById(appUser);
            //构建积分流水
            UserPoint userPoint = new UserPoint();
            userPoint.setType(16);//取消订单
            userPoint.setHistoricalPoint(historicalPoint);
            userPoint.setVariablePoint(order.getPoint());
            userPoint.setBalance(availablePoint);
            userPoint.setCreateTime(LocalDateTime.now());
            userPoint.setAppUserId(order.getAppUserId());
            userPoint.setObjectId(order.getId());
            userPointClient.saveUserPoint(userPoint);
        }
        order.setRefundStatus(2);
        order.setRefundTime(LocalDateTime.now());
        orderMapper.updateById(order);
        //todo 退款后店铺积分流水以及退款前店铺积分流水
       /* shopPointClient.deleteShopPointCopy(order.getId(), Arrays.asList(1,2,3));
        shopBalanceStatementClient.deleteShopBalanceStatementCopy(order.getId(), Arrays.asList(1,2,3));
        appUserGiveawayTemporaryClient.delAppUserGiveawayTemporary(order.getId());
        shopGiveawayTemporaryClient.delShopGiveawayTemporary(order.getId());*/
        //商品销售数量
        OrderGood orderGood = orderGoodService.getOne(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
        goodsClient.editGoodsNum(orderGood.getGoodsId(), -1);
        //获取商品json
        Goods good = JSON.parseObject(orderGood.getGoodJson(), Goods.class);
        GoodsSeckill goodsSeckill = JSON.parseObject(orderGood.getSeckillJson(), GoodsSeckill.class);
        //门店减少冻结资金 即减少余额, 冻结资金=余额-可用资金
        Shop shop = shopClient.getShopById(order.getShopId()).getData();
        BigDecimal historicalBalance=shop.getBalance();//历史余额
        BigDecimal variableAmount=BigDecimal.ZERO;//变动金额
        if (null != goodsSeckill) {
            variableAmount=goodsSeckill.getSellingPrice();
        }else {
            variableAmount=good.getSellingPrice();
        }
        BigDecimal balance=shop.getBalance().subtract(variableAmount);//变动后余额
        shop.setBalance(balance);
        shopClient.updateShop(shop);
        //门店余额流水记录
        ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement();
        shopBalanceStatement.setShopId(shop.getId());
        shopBalanceStatement.setShopName(shop.getName());
        shopBalanceStatement.setShopManagerName(shop.getShopManager());
        shopBalanceStatement.setPhone(shop.getPhone());
        shopBalanceStatement.setType(6);//变更类型,订单退款
        shopBalanceStatement.setHistoricalBalance(historicalBalance);
        shopBalanceStatement.setVariableAmount(variableAmount);
        shopBalanceStatement.setCreateTime(LocalDateTime.now());
        shopBalanceStatement.setBalance(balance);
        shopBalanceStatement.setCreateUserId(appUser.getId());
        shopBalanceStatement.setObjectId(order.getId());
        shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement);
        return R.ok();
    }
    /**
     * 取消订单后回调处理
     * 退款后后回调处理
     *
     * @return
     */
@@ -624,25 +672,38 @@
        confirmOrderVo.setCash(good.getSellingPrice());
        confirmOrderVo.setPoint(good.getIntegral());
        //计算活动价格信息
        Price price = getPrice(goodId);
        if (null != price) {
            confirmOrderVo.setCash(price.getCash());
            confirmOrderVo.setOrderPoint(price.getPoint());
            confirmOrderVo.setEndTimeStamp(price.getEndTimeStamp());
        //是否在秒杀活动中
        GetSeckillActivityInfo info = new GetSeckillActivityInfo();
        info.setGoodsId(goodId);
        GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
        if (null != goodsSeckill){
            SeckillActivityInfo activityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(goodsSeckill.getSeckillActivityInfoId()).getData();
            //价格
            confirmOrderVo.setCash(goodsSeckill.getSellingPrice());//秒杀活动价格
            confirmOrderVo.setPoint(goodsSeckill.getIntegral());//秒杀活动积分价格
            confirmOrderVo.setPurchaseLimitNum(activityInfo.getMaxNum());//限购数量
            confirmOrderVo.setEndTimeStamp(activityInfo.getEndTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());//结束时间戳
        }
        //判断是否是积分支付
        if (type == 1) {//现金
            confirmOrderVo.setOrderMoney(confirmOrderVo.getCash());
            Integer availablePoint = appUser.getAvailablePoint();//用户可用积分
            BigDecimal maxPointDeductionAmount = getCashByPoint(availablePoint);//最大可抵扣金额
            //计算积分抵扣的金额  将积分转为金额,去掉小数
            BigDecimal deduction=getCashByPoint(confirmOrderVo.getResidualPoint());
            //实际抵扣金额
            BigDecimal deduction= maxPointDeductionAmount.min(confirmOrderVo.getCash());
            confirmOrderVo.setDeduction(deduction);
        }else {//积分
            confirmOrderVo.setOrderPoint(good.getIntegral());
            confirmOrderVo.setOrderPoint(confirmOrderVo.getPoint());
        }
        //限购检查
        //判断当前数量是否已经超出限购数量(需要计算已经购买的数量)
        if(null == good.getPurchaseLimit() || -1 == good.getPurchaseLimit()){
        if(null == confirmOrderVo.getPurchaseLimitNum() || -1 == confirmOrderVo.getPurchaseLimitNum()){
            confirmOrderVo.setIsPurchaseLimit(false);
            confirmOrderVo.setPurchaseLimitNum(-1);
        }else{
@@ -657,7 +718,7 @@
                sum = orderGoodList.stream().mapToInt(OrderGood::getNum).sum();
            }
            confirmOrderVo.setIsPurchaseLimit((1 + sum) > good.getPurchaseLimit());
            confirmOrderVo.setPurchaseLimitNum(good.getPurchaseLimit() - sum);
            confirmOrderVo.setPurchaseLimitNum(confirmOrderVo.getPurchaseLimitNum() - sum);
        }
        return confirmOrderVo;
@@ -665,7 +726,6 @@
    /**
     * 订单支付
     *
     */
    @Override
    public R orderPayment(OrderPayment orderPayment) {
@@ -674,6 +734,7 @@
        int type=1;//商品类型  1=普通商品,2=秒杀商品
        //商品信息
        Goods goods = goodsClient.getGoodsById(orderPayment.getGoodId()).getData();
        String goodsJson= JSON.toJSONString(goods);
        if (null == goods || 1==goods.getDelFlag()){
            return  R.fail( "商品不存在");
        }
@@ -713,7 +774,7 @@
            return R.fail("支付方式不正确");
        }
        //现金支付的订单总金额
        //订单总金额
        BigDecimal orderMoney = BigDecimal.ZERO;
        //积分支付的订单积分
        Integer orderPoint = 0;
@@ -742,6 +803,7 @@
        }else{
            //积分支付
            orderPoint=goods.getIntegral();
            orderMoney = goods.getSellingPrice();
            Integer availablePoint = appUser.getAvailablePoint();//用户可用积分
            if(availablePoint.compareTo(orderPoint) < 0){
                return R.fail("账户可用积分不足");
@@ -766,7 +828,8 @@
        order.setDelFlag(0);
        order.setCreateTime(LocalDateTime.now());
        orderMapper.insert(order);
        this.save(order);
        //构建订单明细数据
        OrderGood orderGood = new OrderGood();
@@ -777,7 +840,7 @@
        if (2==type){
            orderGood.setSeckillJson(JSON.toJSONString(goodsSeckill));
        }
        orderGood.setGoodJson(JSON.toJSONString(goods));
        orderGood.setGoodJson(goodsJson);
        orderGood.setDelFlag(0);
        orderGood.setCreateTime(LocalDateTime.now());
        orderGood.setCashPayment(orderPayment.getPaymentType()==1 ? 1 : 0);
@@ -792,38 +855,36 @@
        }
        //判断积分是否为零,积分支付
        if (0 != order.getPoint()){
            //积分支付
            Integer lavePoint = appUser.getLavePoint();
            //扣减订单支付积分
            appUser.setLavePoint(appUser.getLavePoint() - orderPoint);
            appUser.setAvailablePoint(appUser.getAvailablePoint() - orderPoint);
            //可转赠积分
            Integer transferablePoint = appUser.getTransferablePoint();
            Integer tra = 0;
            if(transferablePoint > 0){
                tra = transferablePoint - orderPoint;
                appUser.setTransferablePoint(tra >= 0 ? tra : 0);
            }else{
                appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint);
            if (null==appUser.getAvailablePoint()){
                appUser.setAvailablePoint(0);
            }
            //构建积分流水记录
            if(orderPoint > 0){
                UserPoint userPoint = new UserPoint();
                userPoint.setType(11);
                userPoint.setHistoricalPoint(lavePoint);
                userPoint.setVariablePoint(orderPoint);
                userPoint.setBalance(appUser.getLavePoint());
                userPoint.setCreateTime(LocalDateTime.now());
                userPoint.setAppUserId(appUser.getId());
                userPoint.setObjectId(order.getId());
                userPoint.setExtention((tra >= 0 ? orderPoint : transferablePoint) + "");
                userPointClient.saveUserPoint(userPoint);
            if (null==appUser.getExchangePoint()){
                appUser.setExchangePoint(0);
            }
            //积分支付
            Integer historicalPoint = appUser.getAvailablePoint();//历史积分
            Integer availablePoint = historicalPoint - orderPoint;//可用积分
            Integer exchangePoint = appUser.getExchangePoint() + orderPoint;//兑换商品消费积分
            //扣减订单支付积分
            appUser.setAvailablePoint(availablePoint);
            appUser.setExchangePoint(exchangePoint );
            appUser.setTotalPoint(appUser.getTotalPoint() + order.getPoint());//总积分
            //构建积分流水记录
            UserPoint userPoint = new UserPoint();
            userPoint.setType(4);//兑换商品
            userPoint.setHistoricalPoint(historicalPoint);
            userPoint.setVariablePoint(orderPoint);
            userPoint.setBalance(availablePoint);
            userPoint.setCreateTime(LocalDateTime.now());
            userPoint.setAppUserId(appUser.getId());
            userPoint.setObjectId(order.getId());
            userPointClient.saveUserPoint(userPoint);
            //用户积分变动
            appUser.setLastShopTime(LocalDateTime.now());
            appUserClient.editAppUserById(appUser);
/*            //变更等级
            applicationEventPublisher.publishEvent(new PayEvent(JSON.toJSONString(appUser)));*/
        }
        //判断需要支付的金额是否大于0
@@ -845,14 +906,40 @@
        }
        //不需要微信支付,直接修改订支付状态
        //积分支付,不需要微信支付,直接修改订支付状态
        order.setPayStatus(2);
        orderMapper.updateById(order);
        //商品销量增加
        goodsClient.editGoodsNum(orderGood.getGoodsId(), 1);
        //todo 门店增加冻结资金
        //门店增加冻结资金 即增加余额, 冻结资金=余额-可用资金
        Shop shop = shopClient.getShopById(order.getShopId()).getData();
        if (null==shop.getBalance()){
            shop.setBalance(BigDecimal.ZERO);
        }
        BigDecimal historicalBalance=shop.getBalance();//历史余额
        BigDecimal variableAmount=goods.getSellingPrice();//变动金额
        BigDecimal balance=shop.getBalance().add(goods.getSellingPrice());//变动后余额
        shop.setBalance(balance);
        shop.setOrderNumber(shop.getOrderNumber()+1);
        shopClient.updateShop(shop);
        //门店余额流水记录
        ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement();
        shopBalanceStatement.setShopId(shop.getId());
        shopBalanceStatement.setShopName(shop.getName());
        shopBalanceStatement.setShopManagerName(shop.getShopManager());
        shopBalanceStatement.setPhone(shop.getPhone());
        shopBalanceStatement.setType(5);//变更类型,订单收入
        shopBalanceStatement.setHistoricalBalance(historicalBalance);
        shopBalanceStatement.setVariableAmount(variableAmount);
        shopBalanceStatement.setCreateTime(LocalDateTime.now());
        shopBalanceStatement.setBalance(balance);
        shopBalanceStatement.setCreateUserId(appUser.getId());
        shopBalanceStatement.setObjectId(order.getId());
        shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement);
        return R.ok(order.getId().toString());
    }
@@ -868,7 +955,7 @@
        AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
        BigDecimal paymentMoney = order.getPaymentAmount();
        //构建积分流水记录
        //增加用户消费总金额(微信支付金额)
        appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));//消费总金额
        appUser.setLastShopTime(LocalDateTime.now());
        appUserClient.editAppUserById(appUser);
@@ -881,14 +968,40 @@
        order.setSerialNumber(r7TrxNo);
        orderMapper.updateById(order);
        //商店余额改变,增加冻结余额
        Shop shop = shopClient.getShopById(order.getShopId()).getData();
        //商品销量增加
        OrderGood orderGood = orderGoodService.getOne(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
        //商品销量增加
        goodsClient.editGoodsNum(orderGood.getGoodsId(), 1);
        Goods goods = JSON.parseObject(orderGood.getGoodJson(), Goods.class);
        GoodsSeckill goodsSeckill = JSON.parseObject(orderGood.getSeckillJson(), GoodsSeckill.class);
        //门店增加冻结资金 即增加金额, 冻结资金=余额-可用资金
        Shop shop = shopClient.getShopById(order.getShopId()).getData();
        BigDecimal historicalBalance=shop.getBalance();//历史余额
        BigDecimal variableAmount=BigDecimal.ZERO;//变动金额
        if (null != goodsSeckill) {
            variableAmount=goodsSeckill.getSellingPrice();
        }else {
            variableAmount=goods.getSellingPrice();
        }
        BigDecimal balance=shop.getBalance().add(variableAmount);//变动后余额
        shop.setBalance(balance);
        shop.setOrderNumber(shop.getOrderNumber()+1);
        shopClient.updateShop(shop);
        //门店金额变动记录
        ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement();
        shopBalanceStatement.setShopId(shop.getId());
        shopBalanceStatement.setShopName(shop.getName());
        shopBalanceStatement.setShopManagerName(shop.getShopManager());
        shopBalanceStatement.setPhone(shop.getPhone());
        shopBalanceStatement.setType(5);//变更类型,订单收入
        shopBalanceStatement.setHistoricalBalance(historicalBalance);
        shopBalanceStatement.setVariableAmount(variableAmount);
        shopBalanceStatement.setCreateTime(LocalDateTime.now());
        shopBalanceStatement.setBalance(balance);
        shopBalanceStatement.setCreateUserId(appUser.getId());
        shopBalanceStatement.setObjectId(order.getId());
        shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement);
        return R.ok();
    }
@@ -916,10 +1029,136 @@
                    log.error("关闭订单失败:{}---->{}", order.getOrderNumber(), JSON.toJSONString(closeOrderResult));
                }
                redisTemplate.opsForZSet().remove("OrderPayment", order.getOrderNumber());
                //关闭订单后,检查是否先有过积分抵扣了,是的话要返回订单已抵扣的积分,以及用户积分流水的删除
                if (order.getPoint()>0) {
                    //返回订单抵扣积分
                    AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
                    Integer availablePoint = appUser.getAvailablePoint();//可用积分
                    Integer variablePoint = order.getPoint();//变动积分
                    Integer balance = appUser.getAvailablePoint() + order.getPoint();//变动后积分
                    Integer cancelPoint = appUser.getCancelPoint() + order.getPoint();//取消订单积分
                    appUser.setAvailablePoint(availablePoint);
                    appUser.setCancelPoint(cancelPoint);
                    appUser.setTotalPoint(appUser.getTotalPoint() + order.getPoint());
                    //构建积分流水记录
                    UserPoint userPoint = new UserPoint();
                    userPoint.setType(16);//取消订单
                    userPoint.setHistoricalPoint(availablePoint);
                    userPoint.setVariablePoint(variablePoint);
                    userPoint.setBalance(balance);
                    userPoint.setCreateTime(LocalDateTime.now());
                    userPoint.setAppUserId(appUser.getId());
                    userPoint.setObjectId(order.getId());
                    userPointClient.saveUserPoint(userPoint);
                    appUserClient.editAppUserById(appUser);
                }
            }
        }
    }
    @Override
    public IPage<OrderPageListVo> getShopOrderList(String content, Integer status, Integer shopId, Integer pageNum, Integer pageSize) {
        // 创建分页对象
        Page<Order> page = new Page<>(pageNum, pageSize);
        // 构建查询条件
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        // 添加门店ID条件
        if (shopId != null) {
            queryWrapper.eq("shop_id", shopId);
        }
        // 添加订单状态条件
        if (status != null&&status==4) { //4-已完成 8-已评价
            queryWrapper.in("order_status",Arrays.asList(4,8));
        }
        if (status != null&&status!=4) {//3-待核销 5-已取消
            queryWrapper.eq("order_status",status);
        }
        // 模糊查询条件
        if (StringUtils.isNotBlank(content)) {
            // 构建OR条件组:订单编号/商品名/手机号
            queryWrapper.and(wrapper -> wrapper
                    .like("order_number", content)  // 订单编号
                    .or()
                    .like("goods_name", content)  // 商品名
                    .or()
                    .inSql("app_user_id", "select id from t_app_user where phone like '%" + content + "%'")  // 手机号
            );
        }
        // 执行分页查询
        IPage<Order> orderPage = orderMapper.selectPage(page, queryWrapper);
        // 转换为VO对象
        return orderPage.convert(this::convertToOrderListVo);
    }
    @Override
    public R shopCancelOrder(Long orderId) {
        Order order = this.getById(orderId);
        if (Arrays.asList(5, 6, 7).contains(order.getOrderStatus())) {
            return R.fail("无效的操作");
        }
        if (null != order.getAfterSaleTime() && LocalDateTime.now().isAfter(order.getAfterSaleTime())) {
            return R.fail("订单取消失败");
        }
        order.setOrderStatus(5);
        order.setEndTime(LocalDateTime.now());
        R r = refundPayMoney(order);
        if (200 == r.getCode()) {
            this.updateById(order);
        }
        return r;
    }
    /**
     * 后台-工作台-折线图
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<OrderStatisticsDetail> getOrderListGroupByDate(LocalDate startTime, LocalDate endTime) {
        // 查询数据库获取原始数据
        List<OrderStatisticsDetail> rawData = orderMapper.getOrderListGroupByDate(
                startTime.atTime(0,0, 0),
                endTime.atTime(23,59,59)
        );
        // 创建完整日期范围的映射
        Map<LocalDate, OrderStatisticsDetail> dateMap = rawData.stream()
                .collect(Collectors.toMap(
                        OrderStatisticsDetail::getDateTime,
                        Function.identity()
                ));
        // 生成完整日期序列并填充缺失数据
        List<OrderStatisticsDetail> completeList = new ArrayList<>();
        for (LocalDate date = startTime; !date.isAfter(endTime); date = date.plusDays(1)) {
            if (dateMap.containsKey(date)) {
                completeList.add(dateMap.get(date));
            } else {
                completeList.add(new OrderStatisticsDetail(date, 0, BigDecimal.ZERO));
            }
        }
        return completeList;
    }
    private OrderPageListVo convertToOrderListVo(Order order) {
        OrderPageListVo vo = new OrderPageListVo();
        // 复制属性
        BeanUtils.copyProperties(order, vo);
        // 查询用户信息
        AppUser user = appUserClient.getAppUserById(order.getAppUserId());
        if (user != null) {
            vo.setPhone(user.getPhone());
        }
        vo.setIdStr(order.getId().toString());
        return vo;
    }
    public String getNumber(Integer size){
        StringBuilder str = new StringBuilder();
@@ -928,27 +1167,7 @@
        }
        return str.toString();
    }
    /**
     * 根据商品的价格配置体系获取商品当前的价格
     */
    public Price getPrice( Integer goodsId){
        //判断是否有在秒杀活动时间中的商品
        Price price = new Price();
        GetSeckillActivityInfo getSeckillActivityInfo = new GetSeckillActivityInfo();
        getSeckillActivityInfo.setGoodsId(goodsId);
        GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(getSeckillActivityInfo).getData();
        //没有秒杀活动
        if(null == goodsSeckill ){
            return null;
        }
        //秒杀活动价格
        price.setCash(goodsSeckill.getSellingPrice());
        //计算对应积分
        price.setPoint(getPoint(price.getCash()));
        //结束时间
        price.setEndTimeStamp(goodsSeckill.getEndTime());
        return price;
    }
    /**
     * 获取现金对应积分
     */