| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.google.common.collect.Lists; |
| | | import com.matrix.component.asyncmessage.AsyncMessageManager; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.exception.GlobleException; |
| | |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.common.dao.SysUsersDao; |
| | | import com.matrix.system.common.service.OperationLogService; |
| | | import com.matrix.system.constance.Dictionary; |
| | | import com.matrix.system.enums.BooleanEnum; |
| | | import com.matrix.system.enums.OperationButtonEnum; |
| | | import com.matrix.system.enums.OperationFunctionEnum; |
| | | import com.matrix.system.hive.bean.*; |
| | | import com.matrix.system.hive.dao.*; |
| | | import com.matrix.system.hive.dto.GoodsSealLimitDto; |
| | | import com.matrix.system.hive.dto.SysOrderItemDto; |
| | | import com.matrix.system.hive.plugin.util.CollectionUtils; |
| | | import com.matrix.system.hive.plugin.util.MoneyUtil; |
| | | import com.matrix.system.hive.pojo.CzXkVo; |
| | |
| | | @Autowired |
| | | private AsyncMessageManager asyncMessageManager; |
| | | |
| | | @Autowired |
| | | private OperationLogService operationLogService; |
| | | |
| | | @Autowired |
| | | private SysVipInfoService sysVipInfoService; |
| | | |
| | | @Autowired |
| | | private SysOrderServiceHelper sysOrderServiceHelper; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public int add(SysOrder sysOrder) { |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder checkAndSaveOrder(SysOrder sysOrder) { |
| | | |
| | | // 计算订单折扣金额,收款情况下 计算订单总额 |
| | |
| | | //新增订单 |
| | | sysOrder.setOrderNo(codeService.getOrderCode()); |
| | | sysOrderDao.insert(sysOrder); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CREATE, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId()); |
| | | |
| | | } else { |
| | | //更新订单 |
| | | sysOrderDao.update(sysOrder); |
| | | //删除原有订单明细 |
| | | orderItemDao.deleteByOrderId(sysOrder.getId()); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.UPDATE, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId(), |
| | | "修改订单内容"); |
| | | } |
| | | |
| | | sysOrder.getItems().forEach(sysOrderItem -> { |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int cancelOrder(Long id) { |
| | | public void cancelOrder(Long id) { |
| | | |
| | | SysOrder order = sysOrderDao.selectById(id); |
| | | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | if (order.getStatu().equals(Dictionary.ORDER_STATU_DFK)) { |
| | | |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | |
| | | //发送微信公众号提醒 |
| | | UniformMsgParam uniformMsgParam = new UniformMsgParam(order.getCompanyId(), UniformMsgParam.GZH_DDQX); |
| | | uniformMsgParam.put("orderId", order.getId()); |
| | | asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); |
| | | asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG, uniformMsgParam); |
| | | |
| | | return sysOrderDao.update(order); |
| | | |
| | | sysOrderDao.update(order); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(order.getCompanyId(), order.getShopId(),sysUsers.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CANCEL, |
| | | order.getId(), |
| | | order.getOrderNo(), |
| | | order.getVipId(), |
| | | "未付款取消订单"); |
| | | } else { |
| | | |
| | | //一个订单只能被取消一次 |
| | |
| | | |
| | | // 取消订单 |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | return sysOrderDao.update(order); |
| | | sysOrderDao.update(order); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(order.getCompanyId(), order.getShopId(),sysUsers.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CANCEL, |
| | | order.getId(), |
| | | order.getOrderNo(), |
| | | order.getVipId(), |
| | | "已付款取消订单"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateReceiptMoney(SysOrder pageOrder) throws GlobleException { |
| | | |
| | | if (!Dictionary.ORDER_STATU_DFK.equals(pageOrder.getStatu())) { |
| | | throw new GlobleException("该订单已经收过款,请刷新页面再试!"); |
| | | } |
| | | |
| | | |
| | | //校验订单是否满足收款条件 |
| | | checkOrder(pageOrder); |
| | | |
| | | |
| | | // 更新收款时间 |
| | | // 更新订单主表信息 |
| | | updateOrderInfo(pageOrder); |
| | | |
| | | // 获取用户信息 |
| | | SysVipInfo vipInfo = sysVipInfoDao.selectById(pageOrder.getVipId()); |
| | | if (SysVipInfo.UNDEAL_VIP == vipInfo.getIsDeal()) { |
| | | //非成交客户下单更新客户为成交客户 |
| | | vipInfo.setIsDeal(SysVipInfo.DEAL_VIP); |
| | | sysVipInfoDao.update(vipInfo); |
| | | } |
| | | // 设置用户为成交客户 |
| | | sysVipInfoService.updateDealStatus(pageOrder.getVipId(), BooleanEnum.TRUE.getValue()); |
| | | |
| | | //添加支付流水 |
| | | addOrderFlow(pageOrder); |
| | | sysOrderServiceHelper.addOrderFlow(pageOrder); |
| | | |
| | | // 设置会员充值卡使用情况 |
| | | addMoneyCardUse(pageOrder); |
| | |
| | | //设置会员积分 |
| | | addVipScore(pageOrder); |
| | | |
| | | //保存订单收款日志 |
| | | saveOrderSkLog(pageOrder); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保存订单收款日志 |
| | | * @param pageOrder |
| | | */ |
| | | private void saveOrderSkLog(SysOrder pageOrder) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | operationLogService.saveOperation(pageOrder.getCompanyId(), pageOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.ORDER_SK, |
| | | pageOrder.getId(), |
| | | pageOrder.getOrderNo(), |
| | | pageOrder.getVipId()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 付款后更新订单信息 |
| | | * |
| | | * @param pageOrder |
| | | */ |
| | | private void updateOrderInfo(SysOrder pageOrder) { |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | pageOrder.setCashierId(user.getSuId()); |
| | | |
| | | pageOrder.setPayTime(new Date()); |
| | | |
| | | pageOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | List<SysOrderFlow> flows = pageOrder.getFlows(); |
| | | |
| | |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | BigDecimal cardPayAmount = flows.stream() |
| | | .filter(item -> item.getPayMethod().equals("储值卡") && item.getIsGift().equals("N")) |
| | | .filter(item -> item.getPayMethod().equals("储值卡")) |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | pageOrder.setCardPay(cardPayAmount.doubleValue()); |
| | | pageOrder.setCashPay(cashPayAmount.doubleValue()); |
| | | //欠款金额在流水处理中处理了 |
| | | |
| | | for (SysOrderFlow flow : pageOrder.getFlows()) { |
| | | //欠款处理 |
| | | if (SysOrderFlow.PAY_METHOD_ARREARS.equals(flow.getPayMethod())) { |
| | | pageOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | pageOrder.setArrears(flow.getAmount().doubleValue()); |
| | | } |
| | | } |
| | | |
| | | double sum = flows.stream().mapToDouble(item -> item.getAmount().doubleValue()).sum(); |
| | | |
| | | if (sum > 0 && cardPayAmount.doubleValue() == 0 && cashPayAmount.doubleValue() == 0) { |
| | | throw new GlobleException("订单更新失败,支付金额计算错误,请联系管理员"); |
| | | } |
| | | |
| | | |
| | | sysOrderDao.update(pageOrder); |
| | | |
| | | |
| | | } |
| | | |
| | | private void checkOrder(SysOrder pageOrder) { |
| | | |
| | | SysOrder checkOrder = sysOrderDao.selectById(pageOrder.getId()); |
| | | |
| | | //状态校验 |
| | | if (!Dictionary.ORDER_STATU_DFK.equals(checkOrder.getStatu())) { |
| | | throw new GlobleException("该订单已经收过款,请刷新页面再试!"); |
| | | } |
| | | |
| | | //检查交易限制调整 |
| | | checkSealLimit(pageOrder); |
| | | GoodsSealLimitDto goodsSealLimitDto = new GoodsSealLimitDto(); |
| | | goodsSealLimitDto.setVipId(pageOrder.getVipId()); |
| | | goodsSealLimitDto.setSysOrderItemDtoList(Lists.newArrayList()); |
| | | pageOrder.getItems().forEach(e->{ |
| | | goodsSealLimitDto.getSysOrderItemDtoList().add(BeanUtil.copyProperties(e, SysOrderItemDto.class)); |
| | | }); |
| | | shoppingGoodsService.checkGoodsSealLimit(goodsSealLimitDto); |
| | | |
| | | //检查业绩设置 |
| | | checkOrderAchieve(pageOrder); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 检查业绩设置是否合理 |
| | |
| | | entries.forEach(entrie -> { |
| | | double sum = entrie.getValue().stream().mapToDouble(AchieveNew::getGoodsCash).sum(); |
| | | //todo 目前使用js计算金额可能存在精度的误差展示用0.1屏蔽 |
| | | if (Math.abs(sum- (item.getZkPrice()*item.getCount()) )>0.1) { |
| | | if (Math.abs(sum - (item.getZkPrice() * item.getCount())) > 0.1) { |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | throw GlobleException.instance(shopGoods.getName() + "," + entrie.getKey() + "业绩金额与收款金额不一致"); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 检查产品销售次数 |
| | | */ |
| | | private void checkSealLimit(SysOrder pageOrder) { |
| | | pageOrder.getItems().forEach(item -> { |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | |
| | | //最大销售次数检测 |
| | | Integer maxNum = shopGoods.getCarMaxSaleCount(); |
| | | if (maxNum != null && maxNum != 0) { |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(), null); |
| | | if ((buyNum + item.getCount()) > maxNum) { |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); |
| | | } |
| | | if ((buyNum + item.getCount()) == maxNum) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | | shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN); |
| | | shoppingGoodsDao.update(shopGoods); |
| | | } |
| | | } |
| | | } |
| | | //每人限购次数检测 |
| | | Integer onceCount = shopGoods.getIsOnce(); |
| | | if (onceCount != null && onceCount != 0) { |
| | | Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(), pageOrder.getVipId()); |
| | | |
| | | if ((buyOnceCount + item.getCount()) > onceCount) { |
| | | throw new GlobleException(shopGoods.getName() + "每人限购" + onceCount + "次"); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建支付流水 |
| | | * |
| | | * @author:姜友瑶 |
| | | */ |
| | | private void addOrderFlow(SysOrder sourceOrder) { |
| | | |
| | | |
| | | //处理支付流水 |
| | | int flowCount = 1; |
| | | for (SysOrderFlow flow : sourceOrder.getFlows()) { |
| | | //支付内容摘要设置 |
| | | Long goodsId = sourceOrder.getItems().get(0).getGoodsId(); |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); |
| | | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); |
| | | // 若是退款,则取负数 |
| | | if (SysOrder.ORDER_TYPE_REFUND == sourceOrder.getOrderType()) { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); |
| | | flow.setAmount(flow.getAmount().negate()); |
| | | flow.setOrderId(sourceOrder.getOldOrderId()); |
| | | } else { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_BUY); |
| | | flow.setOrderId(sourceOrder.getId()); |
| | | } |
| | | |
| | | //欠款处理 |
| | | if (SysOrderFlow.PAY_METHOD_ARREARS.equals(flow.getPayMethod())) { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | sourceOrder.setArrears(flow.getAmount().doubleValue()); |
| | | sysOrderDao.update(sourceOrder); |
| | | } |
| | | |
| | | //统计储值卡支付 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); |
| | | //修改储值卡余额 |
| | | cardPaySk(moneyCardUse, sourceOrder, flow); |
| | | } else { |
| | | throw new GlobleException("无效的储值卡支付方式"); |
| | | } |
| | | } |
| | | |
| | | flow.setFlowNo(codeService.getFlowCode() + "-" + flowCount); |
| | | flow.setVipId(sourceOrder.getVipId()); |
| | | flow.setShopId(sourceOrder.getShopId()); |
| | | flow.setCompanyId(sourceOrder.getCompanyId()); |
| | | sysOrderFlowDao.insert(flow); |
| | | flowCount++; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | * @date 2016年9月19日 |
| | | */ |
| | | public void addMoneyCardUse(SysOrder sourceOrder) { |
| | | |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | List<SysOrderItem> orderItemList = sourceOrder.getItems(); |
| | | for (SysOrderItem sysOrderItem : orderItemList) { |
| | | // 如果购买的是充值卡 |
| | |
| | | moneyCardUse.setFailTime(invalidTime); |
| | | |
| | | moneyCardUseDao.insert(moneyCardUse); |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); |
| | | if (zsConsumeAchieve) { |
| | | //赠送情况下,如果收款金额大于0,就是赠送金额划扣的情况,金额即为划扣的折扣金额 |
| | | if(sysOrderItem.getZkPrice()>0){ |
| | | if (sysOrderItem.getZkPrice() > 0) { |
| | | puse.setPrice(sysOrderItem.getZkPrice()); |
| | | }else{ |
| | | } else { |
| | | puse.setPrice(sysOrderItem.getShoppingGoods().getSealPice()); |
| | | } |
| | | } else { |
| | |
| | | |
| | | order.setFlows(czVo.getFlows()); |
| | | |
| | | addOrderFlow(order); |
| | | sysOrderServiceHelper.addOrderFlow(order); |
| | | |
| | | // 添加员工业绩 |
| | | achieveNewService.addAchaeveByOrder(order); |
| | |
| | | |
| | | |
| | | // 添加订单收款流水 |
| | | addOrderFlow(sysOrder); |
| | | sysOrderServiceHelper.addOrderFlow(sysOrder); |
| | | //退款退套餐退项目 |
| | | refundProjUse(sysOrder); |
| | | //删除积分 |
| | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(sysOrder); |
| | | |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.ORDER_TK, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId()); |
| | | |
| | | } |
| | | |
| | | private void addRefundOrderFlow(SysOrder sourceOrder) { |