| | |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.jilongda.common.Ticket.TAddOptometryVO; |
| | | import com.jilongda.common.Ticket.TOrderGoodsPrintVO; |
| | | import com.jilongda.common.Ticket.TicketUtil; |
| | | import com.jilongda.common.basic.ApiResult; |
| | | import com.jilongda.common.basic.PageInfo; |
| | | import com.jilongda.manage.authority.model.SecUser; |
| | | import com.jilongda.manage.authority.service.SecUserService; |
| | | import com.jilongda.manage.dto.TOrderDTO; |
| | | import com.jilongda.manage.model.*; |
| | | import com.jilongda.manage.query.TModelQuery; |
| | | import com.jilongda.manage.query.TOptometryQuery; |
| | | import com.jilongda.manage.query.TOrderQuery; |
| | | import com.jilongda.manage.service.*; |
| | | import com.jilongda.manage.utils.LoginInfoUtil; |
| | | import com.jilongda.manage.vo.TOptometryVO; |
| | | import com.jilongda.manage.vo.TOrderVO; |
| | | import com.jilongda.manage.utils.OssUploadUtil; |
| | | import com.jilongda.manage.vo.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private TFrameGoodsService frameGoodsService; |
| | | @Autowired |
| | | private TLensGoodsService lensGoodsService; |
| | | @Autowired |
| | | private TModelService modelService; |
| | | @Autowired |
| | | private TLensSeriesService lensSeriesService; |
| | | @Autowired |
| | | private TBrandService brandService; |
| | | @Autowired |
| | | private TOptometryService optometryService; |
| | | @Autowired |
| | | private TWarehousingService warehousingService; |
| | | @Autowired |
| | | private TLensWarehousingDetailService lensWarehousingDetailService; |
| | | @Autowired |
| | | private TFrameWarehousingDetailService frameWarehousingDetailService; |
| | | @Autowired |
| | | private TSupplierService supplierService; |
| | | @Autowired |
| | | private TMaterialService materialService; |
| | | @Autowired |
| | | private TLineUpService lineUpService; |
| | | |
| | | @PostMapping("/obs-upload") |
| | | @ApiOperation(value = "文件上传",tags = "管理后台-文件上传") |
| | | public ApiResult<String> uploadOSS(@RequestPart("file") MultipartFile file) { |
| | | try { |
| | | // 上传并返回访问地址 |
| | | String fileName = file.getOriginalFilename(); |
| | | String prefix = fileName.substring(fileName.lastIndexOf(".")); |
| | | long fileSize = file.getSize(); |
| | | String url = OssUploadUtil.ossUpload("eyes/",file); |
| | | return ApiResult.success(url); |
| | | } catch (Exception e) { |
| | | System.err.println("上传文件失败"+e); |
| | | return ApiResult.failed(e.getMessage()); |
| | | } |
| | | } |
| | | @ApiOperation(value = "销售订单分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public ApiResult<PageInfo<TOrderListVO>> pageList(@RequestBody TOrderQuery query) { |
| | | if (StringUtils.hasLength(query.getStartTime())){ |
| | | query.setStartTime(query.getStartTime()+" 00:00:00"); |
| | | query.setEndTime(query.getEndTime()+" 23:59:59"); |
| | | } |
| | | List<Integer> orderIds = new ArrayList<>(); |
| | | // List<Integer> collect = tAppUserService.lambdaQuery() |
| | | // .eq(StringUtils.hasLength(query.getWxName()), TAppUser::getName, query.getWxName()) |
| | | // .eq(StringUtils.hasLength(query.getPhone()), TAppUser::getName, query.getPhone()).list() |
| | | // .stream().map(TAppUser::getId).collect(Collectors.toList()); |
| | | // if (StringUtils.hasLength(query.getWxName())||StringUtils.hasLength(query.getPhone())){ |
| | | // query.setUserIds(collect); |
| | | // if (collect.isEmpty())return ApiResult.success(new PageInfo<>()); |
| | | // } |
| | | List<Integer> collect1 = orderGoodsService.lambdaQuery() |
| | | .eq(StringUtils.hasLength(query.getBrandLens()), TOrderGoods::getBrandName, query.getBrandLens()) |
| | | .eq(StringUtils.hasLength(query.getSeries()), TOrderGoods::getSeriesName, query.getSeries()) |
| | | .eq(query.getType() != null, TOrderGoods::getType, query.getType()) |
| | | .eq(StringUtils.hasLength(query.getRefractiveIndex()), TOrderGoods::getRefractiveIndex, query.getRefractiveIndex()).list() |
| | | .stream().map(TOrderGoods::getOrderId).collect(Collectors.toList()); |
| | | if (StringUtils.hasLength(query.getBrandLens())||StringUtils.hasLength(query.getSeries())||query.getType() != null|| |
| | | StringUtils.hasLength(query.getRefractiveIndex())){ |
| | | orderIds.addAll(collect1); |
| | | } |
| | | List<Integer> collect2 = orderGoodsService.lambdaQuery() |
| | | .eq(StringUtils.hasLength(query.getBrandFrame()), TOrderGoods::getBrandName, query.getBrandFrame()) |
| | | .eq(StringUtils.hasLength(query.getModelName()), TOrderGoods::getModelName, query.getModelName()) |
| | | .eq(StringUtils.hasLength(query.getColor()), TOrderGoods::getColor, query.getColor()).list() |
| | | .stream().map(TOrderGoods::getOrderId).collect(Collectors.toList()); |
| | | if (StringUtils.hasLength(query.getBrandFrame())||StringUtils.hasLength(query.getModelName())|| |
| | | StringUtils.hasLength(query.getColor())){ |
| | | orderIds.addAll(collect2); |
| | | } |
| | | if (StringUtils.hasLength(query.getBrandFrame())||StringUtils.hasLength(query.getModelName())|| |
| | | StringUtils.hasLength(query.getColor())||StringUtils.hasLength(query.getBrandLens())||StringUtils.hasLength(query.getSeries())||query.getType() != null|| |
| | | StringUtils.hasLength(query.getRefractiveIndex())){ |
| | | if (orderIds.isEmpty())return ApiResult.success(new PageInfo<>()); |
| | | } |
| | | return ApiResult.success(orderService.pageList(query)); |
| | | } |
| | | @ApiOperation(value = "查询用户信息") |
| | | @GetMapping(value = "/getUserById") |
| | | public ApiResult getUserById(@RequestParam Integer userId) { |
| | |
| | | |
| | | return ApiResult.success(tCouponReceives); |
| | | } |
| | | |
| | | @Autowired |
| | | private TTicketService tTicketService; |
| | | @ApiOperation(value = "添加订单") |
| | | @PostMapping(value = "/addOrder") |
| | | public ApiResult addOrder(@RequestBody TOrderDTO dto) { |
| | |
| | | if(Objects.nonNull(user)){ |
| | | dto.setStoreId(user.getStoreId()); |
| | | } |
| | | if (dto.getUserId()!=null){ |
| | | TAppUser byId = tAppUserService.getById(dto.getUserId()); |
| | | dto.setName(byId.getName()); |
| | | dto.setPhone(byId.getPhone()); |
| | | |
| | | } |
| | | orderService.save(dto); |
| | | |
| | | |
| | | List<TOrderGoods> orderGoods = dto.getOrderGoods(); |
| | | List<TLensGoods> tLensGoods = new ArrayList<>(); |
| | | List<TFrameGoods> tFrameGoods = new ArrayList<>(); |
| | | for (TOrderGoods orderGood : orderGoods) { |
| | | orderGood.setOrderId(dto.getId()); |
| | | if (StringUtils.hasLength(orderGood.getSeriesName())){ |
| | | // 镜片 |
| | | orderGood.setRLens(orderGood.getRightLens()); |
| | | orderGood.setLLens(orderGood.getLeftLens()); |
| | | String rLens = orderGood.getRLens(); |
| | | String[] split = null; |
| | | if(StringUtils.hasLength(rLens)){ |
| | | split = rLens.split(","); |
| | | if (split.length == 1){ |
| | | |
| | | } |
| | | }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(); |
| | | TLensGoods one = lensGoodsService.lambdaQuery() |
| | | .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, lensSeries.getId()) |
| | | .eq(StringUtils.hasLength(orderGood.getRefractiveIndex()),TLensGoods::getRefractiveIndex, orderGood.getRefractiveIndex()) |
| | | .eq(orderGood.getType()!=null,TLensGoods::getLensType, orderGood.getType()) |
| | | .eq(split.length>0,TLensGoods::getBallMirror, split[0]) |
| | | .eq(split.length>=2,TLensGoods::getColumnMirror, split[1]) |
| | | .one(); |
| | | if (one!=null){ |
| | | if (one.getTotal()-1<0 && lensSeries.getType()==1 ){ |
| | | return ApiResult.failed("库存不足"); |
| | | } |
| | | // 减少对应库存 |
| | | 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); |
| | | |
| | | }else { |
| | | return ApiResult.failed("商品库存不足"); |
| | | } |
| | | }else{ |
| | | TModel one1 = modelService.lambdaQuery().eq(TModel::getName, orderGood.getModelName()) |
| | | .eq(TModel::getColor, orderGood.getColor()).one(); |
| | | BigDecimal cost = one1.getCost(); |
| | | orderGood.setCost(cost); |
| | | TFrameGoods one = frameGoodsService.lambdaQuery() |
| | | .eq(TFrameGoods::getModelId, one1.getId()) |
| | | .eq(TFrameGoods::getColor, orderGood.getColor()).one(); |
| | | if (one!=null){ |
| | | if (one.getTotal()-1<0){ |
| | | return ApiResult.failed("库存不足"); |
| | | } |
| | | // 增加对应库存 |
| | | one.setTotal(one.getTotal()-1); |
| | | tFrameGoods.add(one); |
| | | // 生成销售订单主表 |
| | | TWarehousing tWarehousing = new TWarehousing(); |
| | | tWarehousing.setStatus(5); |
| | | tWarehousing.setType(1); |
| | | tWarehousing.setStoreId(dto.getStoreId()); |
| | | tWarehousing.setRemark("销售订单-镜架"); |
| | | tWarehousing.setOrderNum(dto.getId()+""); |
| | | warehousingService.save(tWarehousing); |
| | | // 生成明细记录 |
| | | TBrand brand = brandService.getById(one1.getBrandId()); |
| | | |
| | | TFrameWarehousingDetail tFrameWarehousingDetail = new TFrameWarehousingDetail(); |
| | | tFrameWarehousingDetail.setWarehousingId(tWarehousing.getId()); |
| | | if (brand!=null){ |
| | | tFrameWarehousingDetail.setBrand(brand.getName()); |
| | | } |
| | | TSupplier supplier = supplierService.getById(one1.getSupplierId()); |
| | | if (supplier!=null){ |
| | | tFrameWarehousingDetail.setSupplier(supplier.getName()); |
| | | } |
| | | TMaterial material = materialService.getById(one1.getMaterialId()); |
| | | if (material!=null){ |
| | | tFrameWarehousingDetail.setMaterial(material.getName()); |
| | | } |
| | | tFrameWarehousingDetail.setTotal(1); |
| | | tFrameWarehousingDetail.setColor(orderGood.getColor()); |
| | | tFrameWarehousingDetail.setModel(one1.getName()); |
| | | tFrameWarehousingDetail.setModelId(one1.getId()); |
| | | tFrameWarehousingDetail.setOrderId(dto.getId()); |
| | | frameWarehousingDetailService.save(tFrameWarehousingDetail); |
| | | |
| | | }else{ |
| | | return ApiResult.failed("商品库存不足"); |
| | | } |
| | | } |
| | | } |
| | | if (dto.getUserId()!=null){ |
| | | if (dto.getCouponId()!=null){ |
| | | TCouponReceive couponReceive = couponReceiveService.getById(dto.getCouponId()); |
| | | if (couponReceive==null){ |
| | | 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("优惠券不存在"); |
| | | TCouponReceive tCouponReceive = couponReceives.get(0); |
| | | tCouponReceive.setStatus(2); |
| | | tCouponReceive.setUseTime(LocalDateTime.now()); |
| | | couponReceiveService.updateById(tCouponReceive); |
| | | } |
| | | } |
| | | List<TOptometryDetail> optometryDetails = dto.getOptometryDetails(); |
| | | if (!CollectionUtils.isEmpty(optometryDetails)){ |
| | | int temp =0; |
| | | if (dto.getUserId()!=null){ |
| | | TOptometry optometry = new TOptometry(); |
| | | long count = lineUpService.count(Wrappers.lambdaQuery(TLineUp.class) |
| | | .eq(TLineUp::getStoreId, dto.getStoreId())); |
| | | optometry.setCode(""+(count+1)); |
| | | optometry.setUserId(dto.getUserId()); |
| | | optometry.setAge(dto.getAge()); |
| | | optometry.setGender(dto.getGender()); |
| | | optometry.setRealName(dto.getRealName()); |
| | | optometry.setPhone(dto.getPhone()); |
| | | optometry.setStoreId(dto.getStoreId()); |
| | | optometry.setStatus(3); |
| | | optometryService.save(optometry); |
| | | temp = optometry.getId(); |
| | | } |
| | | |
| | | |
| | | for (TOptometryDetail optometryDetail : optometryDetails) { |
| | | optometryDetail.setOrderId(dto.getId()); |
| | | if (dto.getUserId()!=null){ |
| | | optometryDetail.setOptometryId(temp); |
| | | } |
| | | } |
| | | optometryDetailService.saveBatch(optometryDetails); |
| | | } |
| | | List<TOrderGoods> orderGoods = dto.getOrderGoods(); |
| | | for (TOrderGoods orderGood : orderGoods) { |
| | | orderGood.setOrderId(dto.getId()); |
| | | orderGoodsService.saveBatch(orderGoods); |
| | | lensGoodsService.updateBatchById(tLensGoods); |
| | | frameGoodsService.updateBatchById(tFrameGoods); |
| | | TAddOptometryVO tAddOptometryVO = new TAddOptometryVO(); |
| | | TTicket tTicket = tTicketService.lambdaQuery().eq(TTicket::getStoreId, dto.getStoreId()) |
| | | .eq(TTicket::getType,1) |
| | | .eq(TTicket::getStatus, 1).list().stream().findFirst().orElse(null); |
| | | if (tTicket==null){ |
| | | return ApiResult.failed("当前门店未绑定小票机"); |
| | | } |
| | | // TODO 周哥 补库存 |
| | | |
| | | return ApiResult.success(); |
| | | 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); |
| | | if (orderGood.getModelId()!=null){ |
| | | TModel byId = modelService.getById(orderGood.getModelId()); |
| | | if (byId!=null){ |
| | | TMaterial byId1 = materialService.getById(byId.getMaterialId()); |
| | | if (byId1!=null){ |
| | | tOrderGoodsPrintVO.setMaterial(byId1.getName()); |
| | | } |
| | | } |
| | | } |
| | | tOrderGoodsPrintVOS.add(tOrderGoodsPrintVO); |
| | | } |
| | | tAddOptometryVO.setOrderGoods(tOrderGoodsPrintVOS); |
| | | tAddOptometryVO.setRemark(dto.getRemark()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | tAddOptometryVO.setTime(format); |
| | | tAddOptometryVO.setMachiningCode(dto.getMachiningCode()); |
| | | if (dto.getIsMachining()==1){ |
| | | // 打印加工单 |
| | | TicketUtil.printMatch(tAddOptometryVO); |
| | | } |
| | | return ApiResult.success(dto.getId()); |
| | | } |
| | | |
| | | @ApiOperation(value = "销售订单详情") |
| | | @GetMapping(value = "/getOrderDetailById") |
| | | public ApiResult getOrderDetailById(@RequestParam Integer orderId) { |
| | | TOrder byId = orderService.getById(orderId); |
| | | |
| | | TOrderVO orderVO = orderService.getOrderDetailById(orderId); |
| | | |
| | | // TODO 周哥 商品信息集合 |
| | | |
| | | // TODO 周哥 验光处方 判断是关联或者手动 |
| | | |
| | | |
| | | List<TOrderGoods> list = orderGoodsService.lambdaQuery().eq(TOrderGoods::getOrderId, orderId).list(); |
| | | orderVO.setOrderGoods(list); |
| | | if (byId.getOptometryId()!=null){ |
| | | // 选择验光单 |
| | | List<TOptometryDetail> list1 = optometryDetailService.lambdaQuery().eq(TOptometryDetail::getOptometryId, byId.getOptometryId()).list(); |
| | | orderVO.setOptometryDetails(list1); |
| | | }else{ |
| | | // 手动填写验光单 |
| | | List<TOptometryDetail> list1 = optometryDetailService.lambdaQuery().eq(TOptometryDetail::getOrderId, orderId).list(); |
| | | orderVO.setOptometryDetails(list1); |
| | | } |
| | | return ApiResult.success(orderVO); |
| | | } |
| | | |