无关风月
3 天以前 6e23a1d4d7c2e56f229b5391efdc38210f70fc8d
manage/src/main/java/com/jilongda/manage/controller/TOrderController.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jilongda.common.Ticket.TAddOptometryVO;
import com.jilongda.common.Ticket.TOptometryDetailVO;
import com.jilongda.common.Ticket.TOrderGoodsPrintVO;
import com.jilongda.common.Ticket.TicketUtil;
import com.jilongda.common.basic.ApiResult;
@@ -182,6 +183,8 @@
    }
    @Autowired
    private TTicketService tTicketService;
    @Autowired
    private TStoreService storeService;
    @ApiOperation(value = "添加订单")
    @PostMapping(value = "/addOrder")
    public ApiResult addOrder(@RequestBody TOrderDTO dto) {
@@ -219,10 +222,11 @@
                }else {
                    split = orderGood.getLLens().split(",");
                }
                TBrand brand = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName())
                        .eq(TBrand::getType, 2).one();
                TLensSeries lensSeries = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName())
                        .eq(TLensSeries::getBrandId, brand.getId()).one();
//                TBrand brand = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName())
//                        .eq(TBrand::getType, 2).one();
                TLensSeries lensSeries = lensSeriesService.lambdaQuery()
                        .eq(TLensSeries::getId, orderGood.getSeriesId())
                        .one();
                TLensGoods one = lensGoodsService.lambdaQuery()
                        .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, lensSeries.getId())
                        .eq(StringUtils.hasLength(orderGood.getRefractiveIndex()),TLensGoods::getRefractiveIndex, orderGood.getRefractiveIndex())
@@ -232,50 +236,59 @@
                        .one();
                if (one!=null){
                    if (one.getTotal()-1<0 && lensSeries.getType()==1 ){
                        return ApiResult.failed("库存不足");
                        if (StringUtils.hasLength(orderGood.getRightLens())){
                            orderService.removeById(dto);
                            return ApiResult.failed("镜片(R)库存不足,请重新选择");
                        }else{
                            orderService.removeById(dto);
                            return ApiResult.failed("镜片(L)库存不足,请重新选择");
                        }
                    }
                    // 减少对应库存
                    one.setTotal(one.getTotal()-1);
                    tLensGoods.add(one);
//                    // 生成销售订单主表
//
//                    TWarehousing tWarehousing = new TWarehousing();
//                    tWarehousing.setStatus(5);
//                    tWarehousing.setType(2);
//                    tWarehousing.setStoreId(dto.getStoreId());
//                    tWarehousing.setRemark("销售订单-镜片");
//                    tWarehousing.setOrderNum(dto.getId()+"");
//                    warehousingService.save(tWarehousing);
//                    // 生成明细记录
//                    TLensWarehousingDetail tLensWarehousingDetail = new TLensWarehousingDetail();
//                    tLensWarehousingDetail.setBrand(orderGood.getBrandName());
//                    TSupplier supplier = supplierService.getById(lensSeries.getSupplierId());
//                    if (supplier!=null){
//                        tLensWarehousingDetail.setSupplier(supplier.getName());
//                    }
//                    tLensWarehousingDetail.setSeries(lensSeries.getName());
//                    tLensWarehousingDetail.setRefractiveIndex(orderGood.getRefractiveIndex());
//                    if (StringUtils.hasLength(orderGood.getLLens())){
//                        tLensWarehousingDetail.setBallMirror(orderGood.getLLens().split(",")[0]);
//                        tLensWarehousingDetail.setColumnMirror(orderGood.getLLens().split(",")[0]);
//                    }
//                    if (StringUtils.hasLength(orderGood.getRLens())){
//                        tLensWarehousingDetail.setBallMirror(orderGood.getRLens().split(",")[0]);
//                        tLensWarehousingDetail.setColumnMirror(orderGood.getRLens().split(",")[0]);
//                    }
//                    tLensWarehousingDetail.setType(orderGood.getType());
//                    tLensWarehousingDetail.setTotal(1);
//                    tLensWarehousingDetail.setSeriesId(lensSeries.getId());
//                    tLensWarehousingDetail.setWarehousingId(tWarehousing.getId());
//                    tLensWarehousingDetail.setOrderId(dto.getId());
//                    lensWarehousingDetailService.save(tLensWarehousingDetail);
                    // 生成销售订单主表
                    TWarehousing tWarehousing = new TWarehousing();
                    tWarehousing.setStatus(5);
                    tWarehousing.setType(2);
                    tWarehousing.setStoreId(dto.getStoreId());
                    tWarehousing.setRemark("销售订单-镜片");
                    tWarehousing.setOrderNum(dto.getId()+"");
                    warehousingService.save(tWarehousing);
                    // 生成明细记录
                    TLensWarehousingDetail tLensWarehousingDetail = new TLensWarehousingDetail();
                    tLensWarehousingDetail.setBrand(orderGood.getBrandName());
                    TSupplier supplier = supplierService.getById(lensSeries.getSupplierId());
                    if (supplier!=null){
                        tLensWarehousingDetail.setSupplier(supplier.getName());
                    }
                    tLensWarehousingDetail.setSeries(lensSeries.getName());
                    tLensWarehousingDetail.setRefractiveIndex(orderGood.getRefractiveIndex());
                    if (StringUtils.hasLength(orderGood.getLLens())){
                        tLensWarehousingDetail.setBallMirror(orderGood.getLLens().split(",")[0]);
                        tLensWarehousingDetail.setColumnMirror(orderGood.getLLens().split(",")[0]);
                    }
                    if (StringUtils.hasLength(orderGood.getRLens())){
                        tLensWarehousingDetail.setBallMirror(orderGood.getRLens().split(",")[0]);
                        tLensWarehousingDetail.setColumnMirror(orderGood.getRLens().split(",")[0]);
                    }
                    tLensWarehousingDetail.setType(orderGood.getType());
                    tLensWarehousingDetail.setTotal(1);
                    tLensWarehousingDetail.setSeriesId(lensSeries.getId());
                    tLensWarehousingDetail.setWarehousingId(tWarehousing.getId());
                    tLensWarehousingDetail.setOrderId(dto.getId());
                    lensWarehousingDetailService.save(tLensWarehousingDetail);
                }else {
                    return ApiResult.failed("商品库存不足");
                    if (lensSeries.getType()==1){
                        orderService.removeById(dto);
                        return ApiResult.failed("商品库存不足");
                    }
                }
            }else{
                TModel one1 = modelService.lambdaQuery().eq(TModel::getName, orderGood.getModelName())
                        .eq(TModel::getColor, orderGood.getColor()).one();
                TModel one1 = modelService.lambdaQuery()
                        .eq(TModel::getId, orderGood.getModelId()).one();
                BigDecimal cost = one1.getCost();
                orderGood.setCost(cost);
                TFrameGoods one = frameGoodsService.lambdaQuery()
@@ -283,7 +296,8 @@
                        .eq(TFrameGoods::getColor, orderGood.getColor()).one();
                if (one!=null){
                    if (one.getTotal()-1<0){
                        return ApiResult.failed("库存不足");
                        orderService.removeById(dto);
                        return ApiResult.failed("镜架库存不足,请重新选择");
                    }
                    // 增加对应库存
                    one.setTotal(one.getTotal()-1);
@@ -320,7 +334,8 @@
                    frameWarehousingDetailService.save(tFrameWarehousingDetail);
                }else{
                    return ApiResult.failed("商品库存不足");
                    orderService.removeById(dto);
                    return ApiResult.failed("镜架库存不足,请重新选择");
                }
            }
        }
@@ -328,13 +343,17 @@
            if (dto.getCouponId()!=null){
                TCouponReceive couponReceive = couponReceiveService.getById(dto.getCouponId());
                if (couponReceive==null){
                    orderService.removeById(dto);
                    return ApiResult.failed("优惠券不存在");
                }
                List<TCouponReceive> couponReceives = couponReceiveService.lambdaQuery()
                        .eq(TCouponReceive::getUserId, dto.getUserId())
                        .eq(TCouponReceive::getCouponId, couponReceive.getCouponId())
                        .orderByDesc(TCouponReceive::getCreateTime).list();
                if (couponReceives.isEmpty())return ApiResult.failed("优惠券不存在");
                if (couponReceives.isEmpty()){
                    orderService.removeById(dto);
                    return ApiResult.failed("优惠券不存在");
                }
                TCouponReceive tCouponReceive = couponReceives.get(0);
                tCouponReceive.setStatus(2);
                tCouponReceive.setUseTime(LocalDateTime.now());
@@ -374,16 +393,16 @@
        frameGoodsService.updateBatchById(tFrameGoods);
        TAddOptometryVO tAddOptometryVO = new TAddOptometryVO();
        TTicket tTicket = tTicketService.lambdaQuery().eq(TTicket::getStoreId, dto.getStoreId())
                .eq(TTicket::getType,1)
                .eq(TTicket::getType,2)
                .eq(TTicket::getStatus, 1).list().stream().findFirst().orElse(null);
        if (tTicket==null){
            orderService.removeById(dto);
            return ApiResult.failed("当前门店未绑定小票机");
        }
        tAddOptometryVO.setSn(tTicket.getCloudId()+"");
        tAddOptometryVO.setPhone(dto.getPhone());
        List<TOrderGoods> orderGoods1 = dto.getOrderGoods();
        ArrayList<TOrderGoodsPrintVO> tOrderGoodsPrintVOS = new ArrayList<>();
        // 复制
        for (TOrderGoods orderGood : orderGoods1) {
            TOrderGoodsPrintVO tOrderGoodsPrintVO = new TOrderGoodsPrintVO();
            BeanUtils.copyProperties(orderGood,tOrderGoodsPrintVO);
@@ -404,6 +423,16 @@
        String format = simpleDateFormat.format(new Date());
        tAddOptometryVO.setTime(format);
        tAddOptometryVO.setMachiningCode(dto.getMachiningCode());
        List<TOptometryDetailVO> tOptometryDetailVOS = new ArrayList<>();
        for (TOptometryDetail optometryDetail : dto.getOptometryDetails()) {
            TOptometryDetailVO tOptometryDetailVO = new TOptometryDetailVO();
            BeanUtils.copyProperties(optometryDetail,tOptometryDetailVO);
            tOptometryDetailVOS.add(tOptometryDetailVO);
        }
        tAddOptometryVO.setOptometryDetailVOS(tOptometryDetailVOS);
        tAddOptometryVO.setShopName(storeService.getById(dto.getStoreId()).getName());
        System.err.println("加工单数据");
        System.err.println(tAddOptometryVO);
        if (dto.getIsMachining()==1){
            // 打印加工单
            TicketUtil.printMatch(tAddOptometryVO);