| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.mzl.flower.base.interceptor.CodeDecorator; |
| | | import com.mzl.flower.component.SequenceNo; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | |
| | | import com.mzl.flower.mapper.supplier.StationMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.service.system.CodeService; |
| | | import com.mzl.flower.utils.ExcelExportUtil; |
| | | import com.mzl.flower.utils.UUIDGenerator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | |
| | | @Autowired |
| | | private CodeService codeService; |
| | | |
| | | @Autowired |
| | | private CodeDecorator codeDecorator; |
| | | |
| | | @Autowired |
| | | private OrderItemCheckMapper orderItemCheckMapper; |
| | | |
| | | public String createSales(OrderItemSalesCreateDTO dto){ |
| | | Integer num = dto.getNum(); |
| | | if(num == null || num == 0){ |
| | |
| | | throw new ValidationException("订单商品不存在"); |
| | | } |
| | | |
| | | if(num > oi.getNum()){ |
| | | OrderItemCheck c = orderItemCheckMapper.selectOne(new QueryWrapper<OrderItemCheck>() |
| | | .eq("order_item_id", oi.getId()) |
| | | .eq("type", Constants.CHECK_TYPE.lack.name()) |
| | | .eq("audit_status", Constants.CHECK_AUDIT_STATUS.AGREED.name()) |
| | | ); |
| | | int totalNum = oi.getNum(); |
| | | if(c != null){//需要减去缺货的数量 |
| | | totalNum -= c.getNum(); |
| | | } |
| | | if(num > totalNum){ |
| | | throw new ValidationException("申请数量不能超过总数"); |
| | | } |
| | | |
| | |
| | | |
| | | String userId = SecurityUtils.getUserId(); |
| | | int count = orderItemSalesMapper.selectCount(new QueryWrapper<OrderItemSales>() |
| | | .eq("order_item_id", oi.getId())); |
| | | .eq("order_item_id", oi.getId()) |
| | | .eq("status", Constants.ORDER_SALES_STATUS.AGREED.name()) |
| | | ); |
| | | if(count >= 2){ |
| | | throw new ValidationException("售后申请超过限额"); |
| | | } |
| | |
| | | s.setReason(dto.getReason()); |
| | | s.setStatus(Constants.ORDER_SALES_STATUS.PENDING.name()); |
| | | s.create(userId); |
| | | s.setSalesType(dto.getSalesType()); |
| | | orderItemSalesMapper.insert(s); |
| | | |
| | | return s.getId(); |
| | |
| | | } |
| | | |
| | | public Page<OrderItemSalesNewListDTO> selectSalesList(Page page, OrderItemSalesQueryDTO dto){ |
| | | dto.setOrderStartDate(parseLocalDateTime(dto.getOrderStartDateStr())); |
| | | dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr())); |
| | | dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr())); |
| | | dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr())); |
| | | dto.setOrderStartDate(parseLocalDateTime(dto.getOrderStartDateStr(), true)); |
| | | dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr(), false)); |
| | | dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr(), true)); |
| | | dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr(), false)); |
| | | |
| | | List<OrderItemSalesNewListDTO> ls = orderItemSalesMapper.selectItemSalesList(page, dto); |
| | | |
| | | page.setRecords(ls); |
| | | return page; |
| | | } |
| | | |
| | | public void exportSalesList(HttpServletResponse response, OrderItemSalesQueryDTO dto){ |
| | | dto.setOrderStartDate(parseLocalDateTime(dto.getOrderStartDateStr(), true)); |
| | | dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr(), false)); |
| | | dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr(), true)); |
| | | dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr(), false)); |
| | | |
| | | List<OrderItemSalesNewListDTO> ls = orderItemSalesMapper.selectItemSalesList(null, dto); |
| | | codeDecorator.decorate(ls); |
| | | |
| | | String[] rowsName = new String[]{"集货站", "商品名称", "商品单位", "商品颜色", "商品等级" |
| | | , "商品分类", "收货人", "收货人手机号码", "收货地址", "商品数量", "供应商名称", "商品售价" |
| | | , "总金额", "订单号", "售后单号", "标题", "申请数量", "理由", "实际退款", "审核结果" |
| | | , "申请时间", "平台回复"}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | |
| | | for (OrderItemSalesNewListDTO d : ls) { |
| | | Object[] objs = new Object[rowsName.length]; |
| | | int a = 0; |
| | | objs[a++] = d.getStationName(); |
| | | objs[a++] = d.getFlowerName(); |
| | | objs[a++] = d.getFlowerUnit(); |
| | | objs[a++] = d.getFlowerColor(); |
| | | objs[a++] = d.getFlowerLevelStr(); |
| | | objs[a++] = d.getFlowerCategory(); |
| | | objs[a++] = d.getCustomer(); |
| | | objs[a++] = d.getCustomerTel(); |
| | | objs[a++] = d.getCustomerAddress(); |
| | | objs[a++] = d.getFlowerNum(); |
| | | objs[a++] = d.getSupplierName(); |
| | | objs[a++] = d.getPrice(); |
| | | objs[a++] = d.getTotal(); |
| | | objs[a++] = d.getOrderNo(); |
| | | objs[a++] = d.getSalesNo(); |
| | | objs[a++] = d.getTitle(); |
| | | objs[a++] = d.getNum(); |
| | | objs[a++] = d.getReason(); |
| | | objs[a++] = d.getTotalFee(); |
| | | objs[a++] = d.getStatusStr(); |
| | | objs[a++] = format(d.getCreateTime(), "yyyy-MM-dd HH:mm:ss"); |
| | | objs[a++] = d.getRemarks(); |
| | | |
| | | dataList.add(objs); |
| | | } |
| | | |
| | | ExcelExportUtil excelExportUtil = new ExcelExportUtil("售后申请列表", rowsName, dataList, response); |
| | | try { |
| | | response.addHeader("filename", URLEncoder.encode("售后申请列表.xls", "UTF-8")); |
| | | response.addHeader("Access-Control-Expose-Headers", "filename"); |
| | | excelExportUtil.export(); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | public OrderItemSalesNewDTO getSalesInfo(String id){ |
| | |
| | | rr.setCustomerCity(o.getCustomerCity()); |
| | | rr.setCustomerRegion(o.getCustomerRegion()); |
| | | rr.setCustomerAddress(o.getCustomerAddress()); |
| | | rr.setOrderTime(o.getCreateTime()); |
| | | |
| | | OrderItem oi = orderItemMapper.selectById(sl.getOrderItemId()); |
| | | rr.setFlowerName(oi.getFlowerName()); |
| | |
| | | rr.setSupplierName(oi.getSupplierName()); |
| | | rr.setPrice(oi.getPrice()); |
| | | rr.setTotal(oi.getTotal()); |
| | | rr.setSupplierPrice(oi.getSupplierPrice()); |
| | | rr.setMarkupPartner(oi.getMarkupPartner()); |
| | | |
| | | Long stationId = oi.getStationId(); |
| | | if(stationId != null) { |
| | |
| | | BigDecimal totalFee = feeSupplier.add(feePartner).add(feePlatform).add(feePlatformPack) |
| | | .add(feePlatformCheck).add(feePlatformTransport); |
| | | |
| | | BigDecimal st = oi.getPrice().multiply(new BigDecimal(sl.getNum()));//申请售后的花的金额 |
| | | if(totalFee.doubleValue() > st.doubleValue()){ |
| | | throw new ValidationException("退款金额不能大于商品申请数量的售价"); |
| | | } |
| | | |
| | | List<OrderItemSales> ls = orderItemSalesMapper.selectList(new QueryWrapper<OrderItemSales>() |
| | | .eq("order_item_id", oi.getId()) |
| | | .eq("status", Constants.ORDER_SALES_STATUS.AGREED.name()) |
| | |
| | | } |
| | | preFee = preFee.add(totalFee); |
| | | if(preFee.doubleValue() > oi.getTotal().doubleValue()){ |
| | | throw new ValidationException("退款金额不能大于商品总价"); |
| | | throw new ValidationException("退款总金额不能大于商品总价"); |
| | | } |
| | | |
| | | sl.setRemarks(dto.getRemarks()); |
| | |
| | | orderItemSalesMapper.updateById(sl); |
| | | |
| | | return oi; |
| | | } |
| | | |
| | | private BigDecimal getAmount(BigDecimal amount){ |
| | | return amount == null ? new BigDecimal(0) : amount; |
| | | } |
| | | } |