mitao
2024-06-06 3d2b51ea4520533de5e78f88dddf5b5c7dce4247
meiya-rest/src/main/java/com/sinata/rest/modular/member/shop/ShopController.java
@@ -1,24 +1,17 @@
package com.sinata.rest.modular.member.shop;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sinata.common.enums.EnumMemberGrade;
import com.sinata.common.enums.mall.EnumMallOrderState;
import com.sinata.rest.common.ApiUtils;
import com.sinata.rest.modular.auth.util.ThreadPoolUtil;
import com.sinata.rest.modular.mall.controller.vo.VoMallOrder;
import com.sinata.rest.modular.mall.controller.vo.VoMallOrderDetail;
import com.sinata.rest.modular.mall.dao.NoticeMapper;
import com.sinata.rest.modular.mall.model.MallOrder;
import com.sinata.rest.modular.mall.model.MallOrderDetail;
import com.sinata.rest.modular.mall.model.MallOrderDetailUse;
import com.sinata.rest.modular.mall.service.IMallCommissionSettlementService;
import com.sinata.rest.modular.mall.service.IMallOrderDetailService;
import com.sinata.rest.modular.mall.service.IMallOrderService;
import com.sinata.rest.modular.member.model.MemUser;
import com.sinata.rest.modular.member.model.MemUserRelation;
import com.sinata.rest.modular.member.controller.common.body.BodyMallOrderDetailUse;
import com.sinata.rest.modular.member.service.IMallOrderDetailUseService;
import com.sinata.rest.modular.member.service.IMemMerchantService;
import com.sinata.rest.modular.member.service.IMemUserRelationService;
@@ -30,12 +23,11 @@
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;
import java.util.List;
@Slf4j
@RestController
@@ -90,7 +82,7 @@
    @GetMapping(value = "/detail")
    @ApiOperation(value = "获取订单详细", notes = "获取订单详细", response = VoMallOrder.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单编号", defaultValue = "1", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "orderNo", value = "订单编号", dataType = "String", paramType = "query", required = true),
    })
    public Object detail(String orderNo) {
        VoMallOrder order = orderService.getOrderByOrderNo(orderNo);
@@ -105,7 +97,7 @@
//    @PostMapping(value = "/userTest")
//    @ApiOperation(value = "订单-核销分佣test")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "orderNo", value = "订单编号", defaultValue = "1", dataType = "String", paramType = "query", required = true),
//            @ApiImplicitParam(name = "orderNo", value = "订单编号", dataType = "String", paramType = "query", required = true),
//    })
//    public Object userTest(String orderNo) {
//        // 核销订单-分佣
@@ -142,73 +134,40 @@
//    }
    @PostMapping(value = "/use")
    @ApiOperation(value = "订单核销", notes = "获取订单详细", response = VoMallOrder.class)
    public Object use(@RequestBody MallOrderDetailUse useDetail) {
        VoMallOrder order = orderService.getOrderByOrderNo(useDetail.getOrderNo());
        if (Objects.isNull(order)) {
            throw new IllegalArgumentException("错误的订单信息");
    @ApiOperation(value = "订单核销", notes = "订单核销", response = VoMallOrder.class)
    public Object use(@RequestBody MallOrderDetailUse orderDetailUse) {
        BodyMallOrderDetailUse body = BeanUtil.toBean(orderDetailUse, BodyMallOrderDetailUse.class);
        try {
            return orderService.use(body);
        } catch (Exception e) {
            return ApiUtils.returnNG(null, e.getMessage());
        }
        if(!order.getMerchantId().equals(ThreadPoolUtil.getUserId())){
            throw new IllegalArgumentException("该订单不是此门店的预约订单");
        }
        Long nowTime = System.currentTimeMillis();
        if ((Objects.nonNull(order.getStartTime()) && Objects.nonNull(order.getEndTime())
                && (nowTime.compareTo(order.getEndTime().getTime()) > 0
                || nowTime.compareTo(order.getStartTime().getTime()) < 0))) {
            throw new IllegalArgumentException("未到核销时间");
        }
        if (!order.getState().equals(EnumMallOrderState.WAIT_CHECK.index)
                && !order.getState().equals(EnumMallOrderState.USE.index)) {
            throw new IllegalArgumentException("订单状态无法被核销");
        }
        LambdaQueryWrapper<MallOrderDetail> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(MallOrderDetail::getOrderDetailNo, useDetail.getOrderDetailNo());
        MallOrderDetail orderDetail = orderDetailService.getOne(queryWrapper2);
        Integer useNumber = orderDetail.getUseNum() + useDetail.getUseNum();
        if (useNumber > orderDetail.getGoodsNum()) {
            throw new IllegalArgumentException("核销信息错误请检查");
        }
        //添加核销记录
        MallOrderDetailUse detailUse = new MallOrderDetailUse();
        BeanUtils.copyProperties(orderDetail, detailUse);
        detailUse.setId(null);
        detailUse.setUseNum(useDetail.getUseNum());
        detailUse.setUseTime(new Date());
        mallOrderDetailUseService.save(detailUse);
        //添加核销时间
        MallOrderDetail updateOrder = new MallOrderDetail();
        updateOrder.setUseNum(useNumber);
        updateOrder.setUseTime(new Date());
        UpdateWrapper<MallOrderDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("order_detail_no", orderDetail.getOrderDetailNo());
        orderDetailService.update(updateOrder, updateWrapper);
    }
        LambdaQueryWrapper<MallOrderDetail> orderWrapper = new LambdaQueryWrapper<>();
        orderWrapper.eq(MallOrderDetail::getOrderNo, useDetail.getOrderNo());
        orderWrapper.last("and use_num <> goods_num");
        List<MallOrderDetail> detailList = orderDetailService.list(orderWrapper);
        if (detailList.size() == 0) {
            //修改订单状态
            MallOrder mallOrder = new MallOrder();
            mallOrder.setState(EnumMallOrderState.SUCCESS.index);
            mallOrder.setOrderNo(orderDetail.getOrderNo());
            orderService.updateById(mallOrder);
            // 核销订单-分佣
            mallCommissionSettlementService.commissionSettlement(mallOrder.getOrderNo());
        } else {
            //修改订单状态
            MallOrder mallOrder = new MallOrder();
            mallOrder.setState(EnumMallOrderState.USE.index);
            mallOrder.setOrderNo(orderDetail.getOrderNo());
            orderService.updateById(mallOrder);
    @PostMapping(value = "/useGroup")
    @ApiOperation(value = "套餐订单核销", notes = "套餐订单核销")
    public Object useGroup(@RequestBody BodyMallOrderDetailUse body) {
        try {
            return orderService.use(body);
        } catch (Exception e) {
            return ApiUtils.returnNG(null, e.getMessage());
        }
    }
        //插入预约通知
        if(Objects.nonNull(order.getMerchantId())){
            noticeMapper.addMerchantNotice(order.getMerchantId(),2,"您有新的核销订单");
    @PostMapping(value = "/useGroupBatch")
    @ApiOperation(value = "套餐订单核销(批量)", notes = "套餐订单核销(批量)")
    public Object useGroupBatch(@RequestBody List<BodyMallOrderDetailUse> list) {
        try {
            Boolean use = true;
            for (BodyMallOrderDetailUse body : list) {
                if (use) {
                    use = orderService.use(body);
                }
            }
            return use;
        } catch (Exception e) {
            return ApiUtils.returnNG(null, e.getMessage());
        }
        return Boolean.TRUE;
    }
    @PostMapping(value = "/useList")