puzhibing
2 天以前 c7ac989e5a693bf29efb4fbaee16770442ea41a0
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -35,6 +35,7 @@
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.CodeFactoryUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.goods.api.domain.GetLotteryEventList;
import com.ruoyi.goods.api.domain.TLotteryEvent;
import com.ruoyi.goods.api.service.LotteryEventClient;
import com.ruoyi.order.config.WxPayConfiguration;
@@ -405,7 +406,10 @@
        appSureOrderVo.setAppSureOrderGoodsVoList(appSureOrderGoodsVoList);
        appSureOrderVo.setLotteryDraw(false);
        // 返回AppPlaceOrderVo对象
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
        GetLotteryEventList getLotteryEventList = new GetLotteryEventList();
        getLotteryEventList.setActivityType(2);
        getLotteryEventList.setUserId(SecurityUtils.getUserId());
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(getLotteryEventList).getData();
        if (data.size() > 0) {
            BigDecimal finalOrderPayMoney = orderPayMoney;
            List<TLotteryEvent> collect = data.stream().filter(s -> s.getPayMoney().compareTo(finalOrderPayMoney) <= 0).collect(Collectors.toList());
@@ -524,7 +528,10 @@
        appPanicBuyVo.setOrderPayMoney(orderPayMoney);
        appPanicBuyVo.setLotteryDraw(false);
        // 返回AppPlaceOrderVo对象
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
        GetLotteryEventList getLotteryEventList = new GetLotteryEventList();
        getLotteryEventList.setActivityType(2);
        getLotteryEventList.setUserId(SecurityUtils.getUserId());
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(getLotteryEventList).getData();
        if (data.size() > 0) {
            BigDecimal finalOrderPayMoney = orderPayMoney;
            List<TLotteryEvent> collect = data.stream().filter(s -> s.getPayMoney().compareTo(finalOrderPayMoney) <= 0).collect(Collectors.toList());
@@ -868,7 +875,10 @@
        appPlaceOrderVo.setLotteryDraw(false);
        // 返回AppPlaceOrderVo对象
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
        GetLotteryEventList getLotteryEventList = new GetLotteryEventList();
        getLotteryEventList.setActivityType(2);
        getLotteryEventList.setUserId(SecurityUtils.getUserId());
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(getLotteryEventList).getData();
        if (data.size() > 0) {
            BigDecimal finalOrderPayMoney = orderPayMoney;
            List<TLotteryEvent> collect = data.stream().filter(s -> s.getPayMoney().compareTo(finalOrderPayMoney) <= 0).collect(Collectors.toList());
@@ -1361,7 +1371,10 @@
            redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + activityId + "-" + goodsId, surpNum - buyNum);
            appPlaceOrderVo.setLotteryDraw(false);
            // 返回AppPlaceOrderVo对象
            List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
            GetLotteryEventList getLotteryEventList = new GetLotteryEventList();
            getLotteryEventList.setActivityType(2);
            getLotteryEventList.setUserId(SecurityUtils.getUserId());
            List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(getLotteryEventList).getData();
            if (data.size() > 0) {
                BigDecimal finalOrderPayMoney = orderPayMoney;
                List<TLotteryEvent> collect = data.stream().filter(s -> s.getPayMoney().compareTo(finalOrderPayMoney) <= 0).collect(Collectors.toList());
@@ -1649,7 +1662,10 @@
        appPlaceOrderVo.setPrepayId(orderPayment.getPrepayId());
        appPlaceOrderVo.setLotteryDraw(false);
        // 返回AppPlaceOrderVo对象
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(2).getData();
        GetLotteryEventList getLotteryEventList = new GetLotteryEventList();
        getLotteryEventList.setActivityType(2);
        getLotteryEventList.setUserId(SecurityUtils.getUserId());
        List<TLotteryEvent> data = lotteryEventClient.getLotteryEventList(getLotteryEventList).getData();
        if (data.size() > 0) {
            List<TLotteryEvent> collect = data.stream().filter(s -> s.getPayMoney().compareTo(order.getPayMoney()) <= 0).collect(Collectors.toList());
            if (collect.size() > 0) {
@@ -1892,6 +1908,12 @@
                merVerifyOrderVo.setReceiveMoney(BigDecimal.ZERO);
            }
        }
        if(null == merVerifyOrderVo.getRealReceiveMoney()){
            merVerifyOrderVo.setRealReceiveMoney(BigDecimal.ZERO);
        }
        if(null == merVerifyOrderVo.getReceiveMoney()){
            merVerifyOrderVo.setReceiveMoney(BigDecimal.ZERO);
        }
        merVerifyOrderVo.setUnReceiveMoney(merVerifyOrderVo.getRealReceiveMoney().subtract(merVerifyOrderVo.getReceiveMoney()));
        merVerifyOrderVo.setUserId(order.getUserId());
        merVerifyOrderVo.setUserName(member.getRealName());
@@ -1998,9 +2020,9 @@
        }
        Member member = remoteMemberService.getMember(order.getUserId()).getData();
        //获取核销商户
        ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(merVerifyOrderDto.getUserId()).getData();
        Long shopId = shopRelUserVo.getShopId();
        log.info("当前核销员工【" + shopRelUserVo.getUserName() + "】门店ID:" + shopId);
//        ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(merVerifyOrderDto.getUserId()).getData();
        Long shopId = member.getRelationShopId();
//        log.info("当前核销员工【" + shopRelUserVo.getUserName() + "】门店ID:" + shopId);
        //获取订单商品列表
        List<AppUserOrderGoodsPageVo> appUserOrderGoodsPageVoList = orderGoodsService.listAppVoByOrderId(orderId);
        //绑定用户判断核销商户
@@ -2066,38 +2088,13 @@
        ConsumerGoods consumerGoods;
        String consumerGoodsId;
        Goods goods;
        //循环生成商品服务
        List<ConsumerGoods> consumerGoodsList = new ArrayList<>();
        for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) {
            Integer buyNum = appUserOrderGoodsPageVo.getBuyNum();
            //判断是否次数未确认商品 是则创建未确认周期商品服务 否则循环创建商品服务
            if (appUserOrderGoodsPageVo.getCycleNumFlag() == 0) {
                consumerGoods = new ConsumerGoods();
                goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
                consumerGoodsId = IdUtils.simpleUUID();
                consumerGoods.setConsumerGoodsId(consumerGoodsId);
                consumerGoods.setDelFlag(0);
                consumerGoods.setServiceStatus(1);
                consumerGoods.setShopId(order.getShopId());
                consumerGoods.setUserId(order.getUserId());
                consumerGoods.setOrderId(orderId);
                consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                consumerGoods.setUsedNum(0);
                consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                consumerGoods.setGoodsTag(appUserOrderGoodsPageVo.getGoodsTag());
                consumerGoods.setCreateTime(nowTime);
                consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                consumerGoods.setSourceFrom(1);
                consumerGoods.setSureNum(buyNum);
                consumerGoodsList.add(consumerGoods);
            } else {
                for (int i = 0; i < buyNum; i++) {
        if(null != appUserOrderGoodsPageVoList.get(0).getGoodsId()){
            //循环生成商品服务
            List<ConsumerGoods> consumerGoodsList = new ArrayList<>();
            for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) {
                Integer buyNum = appUserOrderGoodsPageVo.getBuyNum();
                //判断是否次数未确认商品 是则创建未确认周期商品服务 否则循环创建商品服务
                if (appUserOrderGoodsPageVo.getCycleNumFlag() == 0) {
                    consumerGoods = new ConsumerGoods();
                    goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
                    consumerGoodsId = IdUtils.simpleUUID();
@@ -2120,11 +2117,38 @@
                    consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                    consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                    consumerGoods.setSourceFrom(1);
                    consumerGoods.setSureNum(buyNum);
                    consumerGoodsList.add(consumerGoods);
                } else {
                    for (int i = 0; i < buyNum; i++) {
                        consumerGoods = new ConsumerGoods();
                        goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
                        consumerGoodsId = IdUtils.simpleUUID();
                        consumerGoods.setConsumerGoodsId(consumerGoodsId);
                        consumerGoods.setDelFlag(0);
                        consumerGoods.setServiceStatus(1);
                        consumerGoods.setShopId(order.getShopId());
                        consumerGoods.setUserId(order.getUserId());
                        consumerGoods.setOrderId(orderId);
                        consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                        consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                        consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                        consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                        consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                        consumerGoods.setUsedNum(0);
                        consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                        consumerGoods.setGoodsTag(appUserOrderGoodsPageVo.getGoodsTag());
                        consumerGoods.setCreateTime(nowTime);
                        consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                        consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                        consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                        consumerGoods.setSourceFrom(1);
                        consumerGoodsList.add(consumerGoods);
                    }
                }
            }
            consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList);
        }
        consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList);
        //生成返回
        MerVerifyOrderVo merVerifyOrderVo = new MerVerifyOrderVo();
        merVerifyOrderVo.setOrderId(orderId);
@@ -2177,25 +2201,27 @@
            order.setNewMemberFlag(0);
        }
        this.saveOrUpdate(order);
        // 订单金额大于0时进行分账
        OrderPayment orderPayment = orderPaymentService.getOne(new QueryWrapper<OrderPayment>()
                .eq("order_id", order.getOrderId()).eq("pay_status", 2)
                .eq("del_flag", 0));
        BigDecimal bigDecimal = orderPayment.getPayMoney().subtract(orderPayment.getFeeAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
        if (bigDecimal.compareTo(BigDecimal.ZERO)>0) {
            // TODO: 2023/10/17  更换分账渠道(汇付天下)
        if(4 != order.getOrderFrom()){
            // 订单金额大于0时进行分账
            OrderPayment orderPayment = orderPaymentService.getOne(new QueryWrapper<OrderPayment>()
                    .eq("order_id", order.getOrderId()).eq("pay_status", 2)
                    .eq("del_flag", 0));
            BigDecimal bigDecimal = orderPayment.getPayMoney().subtract(orderPayment.getFeeAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            if (bigDecimal.compareTo(BigDecimal.ZERO)>0) {
                // TODO: 2023/10/17  更换分账渠道(汇付天下)
//            submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom());
            submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), bigDecimal, order.getOrderFrom());
        }
        //创建支付记录
        if(merVerifyOrderDto.getRelPayMoney().compareTo(BigDecimal.ZERO)>0){
            PayRecord payRecord = new PayRecord();
            payRecord.setDelFlag(0);
            payRecord.setOrderId(order.getOrderId());
            payRecord.setPayMoney(merVerifyOrderDto.getRelPayMoney());
            payRecord.setPayTime(new Date());
            payRecord.setPayType(merVerifyOrderDto.getPayType());
            payRecordService.save(payRecord);
                submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), bigDecimal, order.getOrderFrom());
            }
            //创建支付记录
            if(merVerifyOrderDto.getRelPayMoney().compareTo(BigDecimal.ZERO)>0){
                PayRecord payRecord = new PayRecord();
                payRecord.setDelFlag(0);
                payRecord.setOrderId(order.getOrderId());
                payRecord.setPayMoney(merVerifyOrderDto.getRelPayMoney());
                payRecord.setPayTime(new Date());
                payRecord.setPayType(merVerifyOrderDto.getPayType());
                payRecordService.save(payRecord);
            }
        }
        //更新用户积分和消费统计
        MemberTotalChangeDto memberTotalChangeDto = new MemberTotalChangeDto();
@@ -2337,12 +2363,12 @@
            orderGoods.setBuyNum(1);
            ConsumerGoods consumerGoods = new ConsumerGoods();
            consumerGoods.setUsedNum(1);
            if(null != timeCard){
                //核销一次加一次
                orderGoods.setBuyNum(1);
                orderGoods.setServiceNum(1);
                consumerGoods.setServiceNum(timeCard.getTimesCount());
                consumerGoods.setUsedNum(1);
                consumerGoods.setUseTime(new Date());
            }
            orderGoods.setCycleNumFlag(1);
@@ -2355,7 +2381,7 @@
            consumerGoods.setServiceStatus(1);
            consumerGoods.setShopId(order.getShopId());
            consumerGoods.setUserId(order.getUserId());
            consumerGoods.setOrderId(orderId);
            consumerGoods.setOrderId(order.getOrderId());
            consumerGoods.setOrderGoodsId(orderGoods.getOrderGoodsId());
            consumerGoods.setGoodsName(sku.getTitle());
            consumerGoods.setCycleNumFlag(1);
@@ -2366,7 +2392,7 @@
            //生成返回
            MerVerifyOrderVo merVerifyOrderVo = new MerVerifyOrderVo();
            merVerifyOrderVo.setOrderId(orderId);
            merVerifyOrderVo.setOrderId(order.getOrderId());
            merVerifyOrderVo.setOrderNo(order.getOrderNo());
            merVerifyOrderVo.setOrderStatus(order.getOrderStatus());
            merVerifyOrderVo.setOrderFrom(order.getOrderFrom());
@@ -2435,7 +2461,7 @@
                if (integral > 0) {
                    memberTotalChangeDto.setChangeIntegral(integral);
                    memberTotalChangeDto.setTypeIntegral(1);
                    memberTotalChangeDto.setOrderId(orderId);
                    memberTotalChangeDto.setOrderId(order.getOrderId());
                    memberTotalChangeDto.setOrderNo(order.getOrderNo());
                }
            }
@@ -2461,7 +2487,7 @@
            consumerGoodsService.updateById(consumerGoods);
            //生成返回
            MerVerifyOrderVo merVerifyOrderVo = new MerVerifyOrderVo();
            merVerifyOrderVo.setOrderId(orderId);
            merVerifyOrderVo.setOrderId(order.getOrderId());
            merVerifyOrderVo.setOrderNo(order.getOrderNo());
            merVerifyOrderVo.setOrderStatus(order.getOrderStatus());
            merVerifyOrderVo.setOrderFrom(order.getOrderFrom());
@@ -2628,7 +2654,7 @@
            consumerGoods.setServiceStatus(1);
            consumerGoods.setShopId(order.getShopId());
            consumerGoods.setUserId(order.getUserId());
            consumerGoods.setOrderId(orderId);
            consumerGoods.setOrderId(order.getOrderId());
            consumerGoods.setGoodsId(sku.getSku_id());
            consumerGoods.setOrderGoodsId(orderGoods.getOrderGoodsId());
            consumerGoods.setGoodsName(sku.getTitle());
@@ -2642,7 +2668,7 @@
            consumerGoodsService.save(consumerGoods);
            //生成返回
            MerVerifyOrderVo merVerifyOrderVo = new MerVerifyOrderVo();
            merVerifyOrderVo.setOrderId(orderId);
            merVerifyOrderVo.setOrderId(order.getOrderId());
            merVerifyOrderVo.setOrderNo(order.getOrderNo());
            merVerifyOrderVo.setOrderStatus(order.getOrderStatus());
            merVerifyOrderVo.setOrderFrom(order.getOrderFrom());
@@ -2711,7 +2737,7 @@
                if (integral > 0) {
                    memberTotalChangeDto.setChangeIntegral(integral);
                    memberTotalChangeDto.setTypeIntegral(1);
                    memberTotalChangeDto.setOrderId(orderId);
                    memberTotalChangeDto.setOrderId(order.getOrderId());
                    memberTotalChangeDto.setOrderNo(order.getOrderNo());
                }
            }
@@ -2735,7 +2761,7 @@
            consumerGoodsService.updateById(consumerGoods);
            //生成返回
            MerVerifyOrderVo merVerifyOrderVo = new MerVerifyOrderVo();
            merVerifyOrderVo.setOrderId(orderId);
            merVerifyOrderVo.setOrderId(order.getOrderId());
            merVerifyOrderVo.setOrderNo(order.getOrderNo());
            merVerifyOrderVo.setOrderStatus(order.getOrderStatus());
            merVerifyOrderVo.setOrderFrom(order.getOrderFrom());
@@ -5658,7 +5684,8 @@
        if (memberGiftRecord.getGiftFrom() == 2 && !memberGiftRecord.getShopId().equals(shopId)) {
            throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR);
        }
        merVerifyAwardVo.setUserId(member.getUserId());
        merVerifyAwardVo.setUserName(member.getRealName());
        merVerifyAwardVo.setUserMobile(member.getMobile());
        if (1 == memberGiftRecord.getPrizeFrom()) {