| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.core.pojo.PaginationVO; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.system.app.dto.OrderListDto; |
| | | import com.matrix.system.app.vo.OrderDetailAchieveItemVo; |
| | | import com.matrix.system.app.vo.OrderDetailItemVo; |
| | | import com.matrix.system.app.vo.OrderDetailVo; |
| | | import com.matrix.system.app.vo.RankingVo; |
| | | import com.matrix.system.common.bean.BusParameterSettings; |
| | | import com.matrix.system.common.bean.SysUsers; |
| | | 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.constance.SystemConstance; |
| | | 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.hievEnum.PayMethodEnum; |
| | | import com.matrix.system.hive.dto.GoodsSealLimitDto; |
| | | import com.matrix.system.hive.dto.MoneyCardOperationDto; |
| | | import com.matrix.system.hive.dto.ProjUseOperationDto; |
| | | import com.matrix.system.hive.dto.SysOrderItemDto; |
| | | import com.matrix.system.hive.plugin.util.CollectionUtils; |
| | | import com.matrix.core.tools.DateUtil; |
| | | import com.matrix.system.hive.plugin.util.MoneyUtil; |
| | | import com.matrix.system.hive.pojo.CzXkVo; |
| | | import com.matrix.system.hive.pojo.ShoppingCarItem; |
| | | import com.matrix.system.hive.pojo.ShoppingCarItemsVo; |
| | | import com.matrix.system.hive.service.AchieveNewService; |
| | | import com.matrix.system.hive.service.CodeService; |
| | | import com.matrix.system.hive.service.ShoppingGoodsService; |
| | | import com.matrix.system.hive.service.SysOrderService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import com.matrix.system.hive.service.*; |
| | | import com.matrix.system.score.service.ScoreVipDetailService; |
| | | import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgParam; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @date 2016-07-03 20:53 |
| | |
| | | @Autowired |
| | | private SysOrderItemDao orderItemDao; |
| | | @Autowired |
| | | private SysProjUseDao sysProjUseDao; |
| | | @Autowired |
| | | private SysStoreInfoDao storeInfoDao; |
| | | @Autowired |
| | | private CodeService codeService; |
| | | private SysProjUseService sysProjUseService; |
| | | |
| | | @Autowired |
| | | SysVipInfoDao sysVipInfoDao; |
| | | @Autowired |
| | | SysOutStoreDao sysOutStoreDao; |
| | | SysOutStoreService sysOutStoreService; |
| | | @Autowired |
| | | SysOutStoreItemDao sysOutStoreItemDao; |
| | | @Autowired |
| | | MoneyCardUseFlowDao moneyCardUseFlowDao; |
| | | |
| | | @Autowired |
| | | ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | @Autowired |
| | | SysVipLevelDao sysVipLevelDao; |
| | | |
| | |
| | | private AchieveNewService achieveNewService; |
| | | |
| | | @Autowired |
| | | private WarehouseDao warehouseDao; |
| | | private AchieveNewDao achieveNewDao; |
| | | |
| | | |
| | | @Autowired |
| | | private ShoppingGoodsService shoppingGoodsService; |
| | | |
| | | @Autowired |
| | | private SysOrderFlowDao sysOrderFlowDao; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao parameterSettingsDao; |
| | | |
| | | @Autowired |
| | | private AsyncMessageManager asyncMessageManager; |
| | | |
| | | @Autowired |
| | | private OperationLogService operationLogService; |
| | | |
| | | @Autowired |
| | | private SysVipInfoService sysVipInfoService; |
| | | |
| | | @Autowired |
| | | private SysOrderServiceHelper sysOrderServiceHelper; |
| | | |
| | | |
| | | @Autowired |
| | | MoneyCardUseService moneyCardUseService; |
| | | |
| | | |
| | | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓业务代码区↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder checkAndSaveOrder(SysOrder sysOrder) { |
| | | |
| | | if (Objects.isNull(sysOrder.getId())) { |
| | | LogUtil.info("新增正向订单"); |
| | | return sysOrderServiceHelper.saveOrder(sysOrder); |
| | | } else { |
| | | LogUtil.info("修改订单"); |
| | | return sysOrderServiceHelper.modifyOrder(sysOrder); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 取消订单 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelOrder(Long id) { |
| | | |
| | | SysOrder order = sysOrderDao.selectById(id); |
| | | |
| | | if (order.getStatu().equals(Dictionary.ORDER_STATU_DFK)) { |
| | | //待付款订单取消 |
| | | cancelDFKOrder(order); |
| | | } else { |
| | | //已付款订单取消 |
| | | cancelYFKOrder(order); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 已付款订单取消 |
| | | * |
| | | * @param order |
| | | */ |
| | | private void cancelYFKOrder(SysOrder order) { |
| | | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | //一个订单只能被取消一次 |
| | | if (Dictionary.ORDER_STATU_YQX.equals(order.getStatu())) { |
| | | throw new GlobleException("订单已取消"); |
| | | } |
| | | |
| | | //储值卡退款 |
| | | sysOrderServiceHelper.returnMoneyCardPay(order); |
| | | |
| | | //套餐项目取消 |
| | | List<SysOrderItem> sysOrderItems = orderItemDao.selectByOrderId(order.getId()); |
| | | for (SysOrderItem orderItem : sysOrderItems) { |
| | | // 充值卡类型退款 |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(orderItem.getType())) { |
| | | //删除购买的充值卡 |
| | | moneyCardUseService.deleteByOrderItemId(orderItem.getId()); |
| | | } else if (Dictionary.SHOPPING_GOODS_TYPE_XM.equals(orderItem.getType()) |
| | | || Dictionary.SHOPPING_GOODS_TYPE_TC.equals(orderItem.getType())) { |
| | | // 项目套餐退款 |
| | | // 删除套餐项目使用情况 |
| | | sysProjUseService.deleteByOrderItemId(orderItem.getId()); |
| | | } |
| | | } |
| | | |
| | | //删除出库单,恢复库存 |
| | | SysOutStore sysOutStore = new SysOutStore(); |
| | | sysOutStore.setOrderId(order.getId()); |
| | | List<SysOutStore> sysOutStores = sysOutStoreService.findByModel(sysOutStore); |
| | | if (sysOutStores.size() == 1) { |
| | | sysOutStore = sysOutStores.get(0); |
| | | sysOutStoreService.cancelOutStore(sysOutStore.getId()); |
| | | } |
| | | |
| | | // 删除业绩 |
| | | achieveNewService.removeByOrderId(order.getId()); |
| | | |
| | | // 删除收款记录 |
| | | sysOrderFlowDao.deleteByOrderId(order.getId()); |
| | | |
| | | //删除积分 |
| | | scoreVipDetailService.removeByBusinessId(order.getVipId(), order.getId()); |
| | | |
| | | // 取消订单 |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | sysOrderDao.update(order); |
| | | |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(order.getCompanyId(), order.getShopId(), sysUsers.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CANCEL, |
| | | order.getId(), |
| | | order.getOrderNo(), |
| | | order.getVipId(), |
| | | "已付款取消订单"); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 待付款订单取消 |
| | | * |
| | | * @param order |
| | | */ |
| | | private void cancelDFKOrder(SysOrder order) { |
| | | |
| | | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | order.setArrears(0D); |
| | | |
| | | //发送微信公众号提醒 |
| | | UniformMsgParam uniformMsgParam = new UniformMsgParam(order.getCompanyId(), UniformMsgParam.GZH_DDQX); |
| | | uniformMsgParam.put("orderId", order.getId()); |
| | | asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG, uniformMsgParam); |
| | | |
| | | sysOrderDao.update(order); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(order.getCompanyId(), order.getShopId(), sysUsers.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CANCEL, |
| | | order.getId(), |
| | | order.getOrderNo(), |
| | | order.getVipId(), |
| | | "未付款取消订单"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * jyy 收款 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void payOrder(SysOrder pageOrder) throws GlobleException { |
| | | |
| | | //校验订单是否满足收款条件 |
| | | checkOrderAblePay(pageOrder); |
| | | |
| | | // 更新订单主表信息 |
| | | payEndUpdateOrderInfo(pageOrder); |
| | | |
| | | //添加支付流水 |
| | | sysOrderServiceHelper.addOrderFlow(pageOrder, false); |
| | | |
| | | //扣除储值卡余额 |
| | | sysOrderServiceHelper.cardPaySk(pageOrder); |
| | | |
| | | // 设置会员充值卡使用情况 |
| | | sysOrderServiceHelper.addMoneyCardUse(pageOrder); |
| | | // 改变客户项目套餐使用情况 |
| | | sysOrderServiceHelper.addTaocanProj(pageOrder); |
| | | |
| | | // 新增出库单 |
| | | sysOrderServiceHelper.addOutStore(pageOrder); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(pageOrder); |
| | | |
| | | //设置会员积分 |
| | | sysOrderServiceHelper.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 payEndUpdateOrderInfo(SysOrder pageOrder) { |
| | | LogUtil.info("付款更新订单信息 id={}", pageOrder.getId()); |
| | | 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(); |
| | | |
| | | BigDecimal cashPayAmount = flows.stream() |
| | | .filter(item -> (!item.getPayMethod().equals("储值卡")) && (!item.getPayMethod().equals("欠款"))) |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | BigDecimal cardPayAmount = flows.stream() |
| | | .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); |
| | | // 设置用户为成交客户 |
| | | sysVipInfoService.updateDealStatus(pageOrder.getVipId(), BooleanEnum.TRUE.getValue()); |
| | | } |
| | | |
| | | /** |
| | | * 检查订单是否满足支付条件 |
| | | * |
| | | * @param pageOrder |
| | | */ |
| | | private void checkOrderAblePay(SysOrder pageOrder) { |
| | | |
| | | SysOrder checkOrder = sysOrderDao.selectById(pageOrder.getId()); |
| | | |
| | | //状态校验 |
| | | if (!Dictionary.ORDER_STATU_DFK.equals(checkOrder.getStatu())) { |
| | | throw new GlobleException("该订单已经收过款,请刷新页面再试!"); |
| | | } |
| | | |
| | | //检查交易限制调整 |
| | | 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); |
| | | |
| | | LogUtil.info("订单满足支付条件 id={}", pageOrder.getId()); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 检查业绩设置是否合理 |
| | | * 1、每个订单明细都要有至少一个对应的业绩 |
| | | * 2、每个订单明细的同类型业绩金额之和不能大于明细支付金额 |
| | | * |
| | | * @param pageOrder |
| | | */ |
| | | private void checkOrderAchieve(SysOrder pageOrder) { |
| | | |
| | | pageOrder.getItems().forEach(item -> { |
| | | |
| | | if (CollectionUtil.isEmpty(item.getAchieveList())) { |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | throw GlobleException.instance(shopGoods.getName() + "缺少设置业绩"); |
| | | } |
| | | |
| | | //按业绩类型分组后比较支付金额与业绩金额是否相等 |
| | | Map<String, List<AchieveNew>> achieveTypeMap = item.getAchieveList().stream().collect(Collectors.groupingBy(AchieveNew::getAchieveType)); |
| | | Set<Map.Entry<String, List<AchieveNew>>> entries = achieveTypeMap.entrySet(); |
| | | 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) { |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | throw GlobleException.instance(shopGoods.getName() + "," + entrie.getKey() + "业绩金额与收款金额不一致"); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 补交 |
| | | * |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月19日 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void updateAfterMoney(SysOrder pageOrder) { |
| | | SysOrder sourceOrder = sysOrderDao.selectById(pageOrder.getId()); |
| | | |
| | | //添加支付流水 |
| | | sysOrderServiceHelper.addOrderFlow(pageOrder, true); |
| | | |
| | | //扣除储值卡余额 |
| | | sysOrderServiceHelper.cardPaySk(pageOrder); |
| | | |
| | | |
| | | double refundTotal = 0D; |
| | | double cardPayTotal = 0D; |
| | | double cashPayTotal = 0D; |
| | | for (SysOrderFlow flow : pageOrder.getFlows()) { |
| | | // 若使用储值卡付款 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | cardPayTotal += flow.getAmount().doubleValue(); |
| | | } else { |
| | | cashPayTotal += flow.getAmount().doubleValue(); |
| | | } |
| | | refundTotal += flow.getAmount().doubleValue(); |
| | | } |
| | | |
| | | if (refundTotal == pageOrder.getArrears()) { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | } else { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | } |
| | | sourceOrder.setArrears(sourceOrder.getArrears() - refundTotal); |
| | | sourceOrder.setCardPay(sourceOrder.getCardPay() == null ? 0 : sourceOrder.getCardPay() + cardPayTotal); |
| | | sourceOrder.setCashPay(sourceOrder.getCashPay() == null ? 0 : sourceOrder.getCashPay() + cashPayTotal); |
| | | sysOrderDao.update(sourceOrder); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员卡充值 |
| | | * |
| | | * @param czVo |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder moneyCardCz(CzXkVo czVo) { |
| | | |
| | | // 新增一个充值订单 |
| | | SysOrder order = sysOrderServiceHelper.createCzOrder(czVo); |
| | | |
| | | //新增会员卡金额 |
| | | MoneyCardUse cardUser = moneyCardUseDao.selectVipCard(czVo.getVipId()); |
| | | MoneyCardOperationDto moneyCardOperationDto = new MoneyCardOperationDto(); |
| | | moneyCardOperationDto.setRealMoney(czVo.getBjmoney()); |
| | | moneyCardOperationDto.setGiftMoney(czVo.getGiftMoney()); |
| | | moneyCardOperationDto.setCarUseId(cardUser.getId()); |
| | | moneyCardOperationDto.setOrderId(order.getId()); |
| | | moneyCardOperationDto.setOrderNo(order.getOrderNo()); |
| | | moneyCardOperationDto.setType(MoneyCardUseFlow.USE_TYPE_CZ); |
| | | |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | moneyCardOperationDto.setUpdateUser(user.getSuId()); |
| | | moneyCardUseService.changeMoneyCard(Arrays.asList(moneyCardOperationDto)); |
| | | |
| | | // 更新订单主表信息 |
| | | payEndUpdateOrderInfo(order); |
| | | |
| | | //添加支付流水 |
| | | sysOrderServiceHelper.addOrderFlow(order, false); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(order); |
| | | |
| | | //设置会员积分 |
| | | sysOrderServiceHelper.addVipScore(order); |
| | | |
| | | return order; |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public SysOrder findSysOrderTjByVipId(Long vipId) { |
| | | return sysOrderDao.selectVipOrderInfoTotal(vipId); |
| | | } |
| | | |
| | | @Override |
| | | public List<OrderDetailVo> findApiOrderListInPage(OrderListDto orderListDto, PaginationVO pageVo) { |
| | | return sysOrderDao.selectApiOrderListInPage(orderListDto, pageVo); |
| | | } |
| | | |
| | | @Override |
| | | public int findApiOrderListTotal(OrderListDto orderListDto) { |
| | | return sysOrderDao.selectApiOrderListTotal(orderListDto); |
| | | } |
| | | |
| | | @Override |
| | | public OrderDetailVo findApiOrderDetailByOrderId(Long orderId) { |
| | | OrderDetailVo orderDetail = sysOrderDao.selectApiOrderDetailById(orderId); |
| | | |
| | | if (orderDetail == null) { |
| | | throw new GlobleException("该订单不存在"); |
| | | } |
| | | |
| | | List<OrderDetailItemVo> items = orderItemDao.selectApiOrderDetailItemsByOrderId(orderId); |
| | | if (CollectionUtils.isNotEmpty(items)) { |
| | | for (OrderDetailItemVo item : items) { |
| | | List<OrderDetailAchieveItemVo> achieveItems = achieveNewDao.selectApiOrderItemAchieve(item.getId()); |
| | | item.setAchieves(achieveItems); |
| | | } |
| | | } |
| | | |
| | | orderDetail.setItems(items); |
| | | return orderDetail; |
| | | } |
| | | |
| | | @Override |
| | | public List<RankingVo> findApiShopAchieveRanking(SysOrder sysOrder) { |
| | | return sysOrderDao.selectShopAchieveRanking(sysOrder); |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void orderTk(SysOrder sysOrder) { |
| | | |
| | | //创建并保存退款订单 |
| | | sysOrder = sysOrderServiceHelper.createTkOrder(sysOrder); |
| | | // 添加订单收款流水 |
| | | sysOrderServiceHelper.addOrderFlow(sysOrder, false); |
| | | //退款退套餐退项目 |
| | | refundProjUse(sysOrder); |
| | | //删除积分 |
| | | SysOrder oldOrder = sysOrderDao.selectById(sysOrder.getOldOrderId()); |
| | | scoreVipDetailService.removeByBusinessId(oldOrder.getVipId(), oldOrder.getId()); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(sysOrder); |
| | | |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.ORDER_TK, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId()); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 退款退项目,套餐,卡项 |
| | | * |
| | | * @param sysOrder |
| | | */ |
| | | private void refundProjUse(SysOrder sysOrder) { |
| | | |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | //记录需要退库存的产品 |
| | | List<SysOrderItem> returnGoodsList = new ArrayList<>(); |
| | | //需要退的套餐和项目 |
| | | List<ProjUseOperationDto> projUseDtoList = Lists.newArrayList(); |
| | | //需要退的储值卡 |
| | | List<MoneyCardOperationDto> moneyCardOperationDtos = Lists.newArrayList(); |
| | | |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(item.getType()) && Dictionary.FLAG_YES_Y.equals(item.getIsReturnStore())) { |
| | | |
| | | returnGoodsList.add(item); |
| | | |
| | | } else if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(item.getType()) |
| | | || Dictionary.SHOPPING_GOODS_TYPE_XM.equals(item.getType())) { |
| | | ProjUseOperationDto dto = new ProjUseOperationDto(); |
| | | dto.setGoodsId(item.getGoodsId()); |
| | | dto.setCount(item.getRefundCount()); |
| | | dto.setOrderItemId(item.getOldItemId()); |
| | | dto.setUpdateUserId(user.getSuId()); |
| | | projUseDtoList.add(dto); |
| | | |
| | | }else if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(item.getType())) { |
| | | MoneyCardOperationDto moneyCardOperationDto = new MoneyCardOperationDto(); |
| | | moneyCardOperationDto.setOrderId(sysOrder.getId()); |
| | | moneyCardOperationDto.setOrderNo(sysOrder.getOrderNo()); |
| | | moneyCardOperationDto.setOrderItemId(item.getOldItemId()); |
| | | moneyCardOperationDto.setType(MoneyCardUseFlow.USE_TYPE_ORDRE_TK); |
| | | moneyCardOperationDto.setUpdateUser(user.getSuId()); |
| | | moneyCardOperationDto.setOrderNo(sysOrder.getOrderNo()); |
| | | moneyCardOperationDto.setRealMoney(item.getZkPrice()); |
| | | moneyCardOperationDtos.add(moneyCardOperationDto); |
| | | } |
| | | } |
| | | |
| | | BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, sysOrder.getCompanyId()); |
| | | // if (AppConstance.IS_Y.equals(manageStockSetting.getParamValue())) { |
| | | if (BooleanEnum.TRUE.getValue() == manageStockSetting.getIntParamValue()) { |
| | | // 家居产品退库存 |
| | | if (CollectionUtils.isNotEmpty(returnGoodsList)) { |
| | | LogUtil.info("订单退款:退产品库存:{}", JSON.toJSONString(returnGoodsList)); |
| | | sysOrderServiceHelper.refundInstore(returnGoodsList); |
| | | } |
| | | } |
| | | |
| | | if(CollUtil.isNotEmpty(projUseDtoList)){ |
| | | LogUtil.info("订单退款:退套餐项目:{}", JSON.toJSONString(projUseDtoList)); |
| | | sysProjUseService.projectTk(projUseDtoList); |
| | | } |
| | | |
| | | if(CollUtil.isNotEmpty(moneyCardOperationDtos)){ |
| | | LogUtil.info("订单退款:储值卡:{}", JSON.toJSONString(moneyCardOperationDtos)); |
| | | moneyCardUseService.moneyCardTk(moneyCardOperationDtos); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal findVipArrearsByVipId(Long vipId) { |
| | | return sysOrderDao.selectArrearsByVipId(vipId); |
| | | } |
| | | |
| | | |
| | | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓===增删改查代码区↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
| | | |
| | | |
| | | @Override |
| | | public int add(SysOrder sysOrder) { |
| | |
| | | |
| | | @Override |
| | | public List<SysOrder> findInPage(SysOrder sysOrder, PaginationVO pageVo) { |
| | | if(pageVo!=null){ |
| | | if (pageVo != null) { |
| | | pageVo.setSort("desc"); |
| | | pageVo.setSort("orderTime"); |
| | | } |
| | |
| | | public SysOrder findById(Long id) { |
| | | return sysOrderDao.selectById(id); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public SysOrder checkAndSaveOrder(SysOrder sysOrder) { |
| | | |
| | | // 收款改变订单状态 |
| | | /** |
| | | * 判断订单条目的一个付款情况 |
| | | */ |
| | | // 计算现金支付金额 |
| | | double xjMoney = 0.0; |
| | | // 计算卡支付总额 |
| | | double cardMoney = 0.0; |
| | | // 计算订单折扣金额,收款情况下 计算订单总额 |
| | | double zkTotal = 0.0; |
| | | /** |
| | | * 记录本次消费的卡,防止扣除多次消费记录 |
| | | */ |
| | | ArrayList<Long> userCard = new ArrayList<Long>(); |
| | | |
| | | // 页面的pageOrder 参数只包含支付金额信息,不带有购买商品 |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | item.setType(shoppingGoods.getGoodType()); |
| | | if (item.getZkPrice() == 0) { |
| | | item.setIsFree(Dictionary.FLAG_YES); |
| | | } |
| | | |
| | | |
| | | // 如果支付方式是非现金则记录现金支付金额 |
| | | if (!item.getPayMethod().equals(PayMethodEnum.VIP_CARD.getCode())) { |
| | | xjMoney = MoneyUtil.add(xjMoney, item.getPayMoney()); |
| | | item.setCashPay(item.getPayMoney()); |
| | | } else { |
| | | cardMoney = MoneyUtil.add(cardMoney, item.getPayMoney()); |
| | | item.setCardPay(item.getPayMoney()); |
| | | |
| | | } |
| | | |
| | | |
| | | // 订单欠款减去支付金额 设置实际欠款 |
| | | Double itemZkTotal = MoneyUtil.mul(item.getZkPrice(), Double.valueOf(item.getCount())); |
| | | zkTotal=MoneyUtil.add(zkTotal, itemZkTotal); |
| | | item.setArrears(MoneyUtil.sub(itemZkTotal, item.getPayMoney())); |
| | | |
| | | |
| | | // 如果存在欠款,将条目状态设置为欠款 |
| | | if (item.getArrears() > 0) { |
| | | item.setStatus(Dictionary.ORDER_STATU_QK); |
| | | } else if (item.getArrears() < 0) { |
| | | item.setPayMoney(item.getZkPrice()); |
| | | item.setStatus(Dictionary.ORDER_STATU_DFK); |
| | | } else { |
| | | item.setStatus(Dictionary.ORDER_STATU_DFK); |
| | | } |
| | | } |
| | | double arrears; |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | // 如果是收款,收款可以改变订单价格,所以需要求和出 订单折后价来计算本次欠款 |
| | | arrears = MoneyUtil.sub(zkTotal, MoneyUtil.add(cardMoney, xjMoney)); |
| | | sysOrder.setZkTotal(zkTotal); |
| | | sysOrder.setArrears(arrears); |
| | | sysOrder.setCardPay(cardMoney); |
| | | sysOrder.setCashPay(xjMoney); |
| | | sysOrder.setStatu(Dictionary.ORDER_STATU_DFK); |
| | | sysOrder.setCompanyId(user.getCompanyId()); |
| | | |
| | | sysOrder.setPayTime(new Date()); |
| | | if(sysOrder.getId()==null){ |
| | | //新增订单 |
| | | sysOrder.setOrderNo(codeService.getOrderCode()); |
| | | sysOrderDao.insert(sysOrder); |
| | | |
| | | }else{ |
| | | //更新订单 |
| | | sysOrderDao.update(sysOrder); |
| | | //删除原有订单明细 |
| | | orderItemDao.deleteByOrderId(sysOrder.getId()); |
| | | } |
| | | |
| | | sysOrder.getItems().forEach(sysOrderItem -> { |
| | | sysOrderItem.setOrderId(sysOrder.getId()); |
| | | orderItemDao.insert(sysOrderItem); |
| | | }); |
| | | |
| | | return sysOrder; |
| | | } |
| | | |
| | | /** |
| | | * 取消订单 |
| | | * 本方法无法退回多次不同卡项收款的订单 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int cancelOrder(Long id) { |
| | | |
| | | SysOrder order = sysOrderDao.selectById(id); |
| | | if (order.getStatu().equals(Dictionary.ORDER_STATU_DFK)) { |
| | | |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | order.setArrears(0D); |
| | | return sysOrderDao.update(order); |
| | | |
| | | } else { |
| | | |
| | | //一个订单只能被取消一次 |
| | | if (Dictionary.ORDER_STATU_YQX.equals(order.getStatu())) { |
| | | throw new GlobleException("订单已取消"); |
| | | } |
| | | |
| | | List<SysOrderItem> sysOrderItems = orderItemDao.selectByOrderId(id); |
| | | |
| | | for (SysOrderItem orderItem : sysOrderItems) { |
| | | |
| | | //非现金收款退回扣卡余额 |
| | | if (StringUtils.isNotBlank(orderItem.getPayMethodDetail())) { |
| | | |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(Long.parseLong(orderItem.getPayMethodDetail())); |
| | | MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); |
| | | |
| | | if (moneyCardUse != null) { |
| | | |
| | | // 根据订单明细判断是赠送金额购买还是本金购买 |
| | | |
| | | moneyCardUseFlow.setTotal(orderItem.getCardPay()); |
| | | moneyCardUse.setRealMoney(MoneyUtil.add(moneyCardUse.getRealMoney(), orderItem.getCardPay())); |
| | | //TODO 目前无法退回到具体的赠送金额还是本金 |
| | | |
| | | if (!moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_YES_Y)) { |
| | | if(moneyCardUse.getLastCount()!=null) { |
| | | moneyCardUse.setLastCount(moneyCardUse.getLastCount() + 1); |
| | | moneyCardUseFlow.setTimes(1); |
| | | } |
| | | } |
| | | moneyCardUseDao.update(moneyCardUse); |
| | | //插入充值卡变动流水 |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | moneyCardUseFlow.setOrderNo(order.getOrderNo()); |
| | | moneyCardUseFlow.setCarUseId(moneyCardUse.getId()); |
| | | moneyCardUseFlow.setVipId(order.getVipId()); |
| | | moneyCardUseFlow.setType(MoneyCardUseFlow.USE_TYPE_ORDRE_CANCEL); |
| | | moneyCardUseFlow.setCreateTime(new Date()); |
| | | moneyCardUseFlow.setOperationId(user.getSuId()); |
| | | moneyCardUseFlow.setContent(moneyCardUse.getChangeRemark()); |
| | | moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney()+moneyCardUse.getRealMoney()); |
| | | moneyCardUseFlowDao.insert(moneyCardUseFlow); |
| | | } |
| | | } |
| | | // 充值卡类型退款 |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(orderItem.getType())) { |
| | | |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(orderItem.getGoodsId()); |
| | | |
| | | |
| | | //删除购买的充值卡 |
| | | moneyCardUseDao.deleteByOrderItemId(orderItem.getId()); |
| | | |
| | | } else if (Dictionary.SHOPPING_GOODS_TYPE_XM.equals(orderItem.getType()) |
| | | || Dictionary.SHOPPING_GOODS_TYPE_TC.equals(orderItem.getType())) { |
| | | // 项目套餐退款 |
| | | // 删除套餐项目使用情况 |
| | | sysProjUseDao.deleteByOrderItemId(orderItem.getId()); |
| | | |
| | | |
| | | } else if (Dictionary.SHOPPING_GOODS_TYPE_ZHK.equals(orderItem.getType())) { |
| | | // 综合卡 |
| | | // 删除套餐项目使用情况 |
| | | sysProjUseDao.deleteByOrderItemId(orderItem.getId()); |
| | | // 删除充值卡 |
| | | moneyCardUseDao.deleteByOrderItemId(orderItem.getId()); |
| | | |
| | | } |
| | | } |
| | | |
| | | //删除出库单,恢复库存 |
| | | SysOutStore sysOutStore = new SysOutStore(); |
| | | sysOutStore.setOrderId(order.getId()); |
| | | List<SysOutStore> sysOutStores = sysOutStoreDao.selectByModel(sysOutStore); |
| | | if (sysOutStores.size() == 1) { |
| | | sysOutStore = sysOutStores.get(0); |
| | | List<SysOutStoreItem> outStoreItemList = sysOutStoreItemDao.selectByOrderId(sysOutStore.getId()); |
| | | for (SysOutStoreItem item : outStoreItemList) { |
| | | SysStoreInfo sysStoreInfo = storeInfoDao.selectById(item.getStoreId()); |
| | | sysStoreInfo.setStoreTotal(sysStoreInfo.getStoreTotal() + item.getAmount()); |
| | | //更新库存 |
| | | storeInfoDao.update(sysStoreInfo); |
| | | } |
| | | sysOutStoreDao.deleteById(sysOutStore.getId()); |
| | | sysOutStoreItemDao.deleteByOrderId(sysOutStore.getId()); |
| | | } |
| | | // 删除业绩 |
| | | AchieveNew achieveNew = new AchieveNew(); |
| | | achieveNew.setOrderId(id); |
| | | achieveNewService.removeByModel(achieveNew); |
| | | // 取消订单 |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | return sysOrderDao.update(order); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建订单 lk |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int createOrder(HttpSession session, ShoppingCarItemsVo car) { |
| | | |
| | | if (car.getCarItems().size() < 1) { |
| | | throw new GlobleException("没用选择购买产品"); |
| | | } |
| | | // 获取会员信息,判断等级 获取相应家居折扣 |
| | | SysVipInfo info = (SysVipInfo) WebUtil.getSession().getAttribute(SystemConstance.CURRENT_CUSTOMER); |
| | | |
| | | //获取折扣----- |
| | | Double zk = zk = 1.0; |
| | | //验证商品是否只购买了一次 |
| | | checkBuyOnce(car, info.getId()); |
| | | |
| | | SysOrder order = new SysOrder(); |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | order.setShopId(user.getShopId()); |
| | | order.setOrderNo(codeService.getOrderCode()); |
| | | order.setVipId(info.getId()); |
| | | order.setOrderTime(new Date()); |
| | | order.setRemark(car.getRemark()); |
| | | order.setStaffId(user.getSuId()); |
| | | order.setIsCross(2 + ""); |
| | | order.setChangeId(car.getChangeId()); |
| | | order.setStatu(Dictionary.ORDER_STATU_DFK); |
| | | order.setCardPay(0.00); |
| | | order.setCashPay(0.00); |
| | | order.setBeatuyId(car.getBeatuyId() + ""); |
| | | // 根据美疗师id查询美疗师姓名 |
| | | if (car.getBeatuyId() != null) { |
| | | String beatuyName = shopStaffInfoDao.selectById(car.getBeatuyId()).getSuName(); |
| | | System.out.println("美疗师:" + beatuyName); |
| | | order.setBeatuyName(beatuyName); |
| | | } |
| | | int i = sysOrderDao.insert(order); |
| | | // 创建订单明细,并计算总价与折扣总价 |
| | | // 总价 |
| | | double total = 0; |
| | | double zkTotal = 0; |
| | | int count = 0; |
| | | // 设置订单条目 |
| | | for (ShoppingCarItem carItem : car.getCarItems()) { |
| | | // 检测最大销售数量 |
| | | checkIsArrivedMax(carItem); |
| | | SysOrderItem orderItem = new SysOrderItem(); |
| | | orderItem.setOrderId(order.getId()); |
| | | orderItem.setCount(carItem.getCount()); |
| | | orderItem.setIsFree(carItem.getIsFree()); |
| | | orderItem.setType(carItem.getType()); |
| | | orderItem.setStatus(Dictionary.ORDER_STATU_DFK); |
| | | // 新增明细 |
| | | // 设置商品id |
| | | orderItem.setGoodsId(carItem.getGoodsId()); |
| | | // 设置assembleId |
| | | orderItem.setAssembleId(carItem.getAssembleId()); |
| | | // 如果是家居产品的话,要取出组合sku中的价格 |
| | | double p = carItem.getShoppingGoods().getSealPice(); |
| | | orderItem.setPrice(p); |
| | | if (carItem.getIsFree().equals(Dictionary.FLAG_NO)) { |
| | | orderItem.setZkPrice(MoneyUtil.mul(p, zk)); |
| | | } else { |
| | | // 如果是免费,则设置为0.0 |
| | | orderItem.setZkPrice(0.0); |
| | | } |
| | | |
| | | |
| | | orderItemDao.insert(orderItem); |
| | | total = MoneyUtil.add(total, |
| | | MoneyUtil.mul(orderItem.getPrice(), Double.parseDouble(carItem.getCount() + ""))); |
| | | zkTotal = MoneyUtil.add(zkTotal, |
| | | MoneyUtil.mul(orderItem.getZkPrice(), Double.parseDouble(carItem.getCount() + ""))); |
| | | } |
| | | |
| | | // 设置订单总价与折后价 |
| | | order.setTotal(total); |
| | | order.setZkTotal(zkTotal); |
| | | order.setArrears(zkTotal); |
| | | sysOrderDao.update(order); |
| | | return i; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证商品是否购买过一次 |
| | | * |
| | | * @Title: checkBuyOnce @author:jyy @param car void 返回类型 @date |
| | | * 2016年9月22日 上午10:05:33 @throws |
| | | */ |
| | | private void checkBuyOnce(ShoppingCarItemsVo car, Long vipId) { |
| | | for (ShoppingCarItem carItem : car.getCarItems()) { |
| | | if (shoppingGoodsDao.selectBuyCount(carItem.getGoodsId(), vipId) > 0) { |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(carItem.getGoodsId()); |
| | | throw new GlobleException(goods.getName() + "只能购买一次!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * jyy 收款 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateReceiptMoney(SysOrder pageOrder) throws GlobleException { |
| | | |
| | | |
| | | if (!Dictionary.ORDER_STATU_DFK.equals(pageOrder.getStatu())) { |
| | | throw new GlobleException("该订单已经收过款,请刷新页面再试!"); |
| | | } |
| | | |
| | | // 获取用户信息 |
| | | SysVipInfo vipInfo = sysVipInfoDao.selectById(pageOrder.getVipId()); |
| | | if (SysVipInfo.UNDEAL_VIP == vipInfo.getIsDeal()) { |
| | | //非成交客户下单更新客户为成交客户 |
| | | vipInfo.setIsDeal(SysVipInfo.DEAL_VIP); |
| | | sysVipInfoDao.update(vipInfo); |
| | | } |
| | | |
| | | changeOrderStatu(pageOrder); |
| | | // 设置会员充值卡使用情况 |
| | | addMoneyCardUse(pageOrder); |
| | | |
| | | // 新增出库单 |
| | | addOutStore(pageOrder); |
| | | |
| | | // 改变客户项目套餐使用情况 |
| | | addTaocanProj(pageOrder); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(pageOrder); |
| | | |
| | | setShopSelCount(pageOrder); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 收款改变订单状态,划扣金额 |
| | | * @author:姜友瑶 |
| | | */ |
| | | private void changeOrderStatu(SysOrder sourceOrder) { |
| | | |
| | | boolean haQk=false; |
| | | |
| | | for(SysOrderItem sysOrderItem:sourceOrder.getItems()){ |
| | | |
| | | if(!sysOrderItem.getStatus().equals(Dictionary.ORDER_STATU_QK)){ |
| | | SysOrderItem updateItem=new SysOrderItem(); |
| | | updateItem.setId(sysOrderItem.getId()); |
| | | updateItem.setStatus(Dictionary.ORDER_STATU_YFK); |
| | | |
| | | if (sysOrderItem.getPayMethod().equals(Dictionary.PAY_TYPE_MOENY_CARD ) ) { |
| | | |
| | | if(sysOrderItem.getPayMethodDetail()!=null){ |
| | | // 查询要支付的充值卡 |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(Long.parseLong(sysOrderItem.getPayMethodDetail())); |
| | | // 扣除付款卡金额并添加流水 |
| | | cardPaySk(moneyCardUse, sourceOrder, sysOrderItem); |
| | | }else{ |
| | | throw new GlobleException("请选择支付的会员卡"); |
| | | } |
| | | |
| | | |
| | | } |
| | | orderItemDao.update(updateItem); |
| | | }else { |
| | | haQk=true; |
| | | } |
| | | } |
| | | //更新收款状态 |
| | | if(haQk){ |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | }else{ |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | } |
| | | |
| | | sysOrderDao.update(sourceOrder); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证商品是否达到最大发卡限制 |
| | | * |
| | | * @author jiangyouyao |
| | | */ |
| | | private void checkIsArrivedMax(ShoppingCarItem carItem) { |
| | | // 获取该商品的最大购买数量 |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(carItem.getGoodsId()); |
| | | Integer maxNum = shopGoods.getCarMaxSaleCount(); |
| | | // 最大发卡数量为0代表不做限制 |
| | | if (maxNum != null && maxNum != 0) { |
| | | // 查询该商品已经被购买的次数 |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId()); |
| | | buyNum = (buyNum == null ? 0 : buyNum); |
| | | if ((buyNum + carItem.getCount()) > maxNum) { |
| | | |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量,还剩【" + (maxNum - buyNum) + "】件"); |
| | | } |
| | | if ((buyNum + carItem.getCount()) == maxNum) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | | shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN); |
| | | shoppingGoodsDao.update(shopGoods); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 使用充值卡付款操作 |
| | | * |
| | | * @param sourceOrder |
| | | * @param userCard |
| | | * @param orderItem |
| | | * @param temp 设置是否扣除使用次数 true 扣除 |
| | | */ |
| | | private void cardPaySk(MoneyCardUse moneyCardUse, SysOrder sourceOrder, |
| | | SysOrderItem orderItem) { |
| | | // 判断商品是否在充值卡的限制购买,判断分类 |
| | | if (!isInBangding(moneyCardUse, orderItem.getGoodsId())) { |
| | | throw new GlobleException(shoppingGoodsDao.selectById(orderItem.getGoodsId()).getName() + "不在" |
| | | + moneyCardUse.getCardName() + "优惠中"); |
| | | } |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | Double balance = moneyCardUse.getRealMoney(); |
| | | if (moneyCardUse.getGiftMoney() != null) { |
| | | balance = MoneyUtil.add(balance, moneyCardUse.getGiftMoney()); |
| | | } |
| | | // 判断金额是否足够支付 |
| | | if (balance >= orderItem.getPayMoney()) { |
| | | |
| | | MoneyCardUseFlow moneyCardUseFlow=new MoneyCardUseFlow(); |
| | | |
| | | // 余额充足先从本金中扣除 |
| | | if (moneyCardUse.getRealMoney() >= orderItem.getPayMoney()) { |
| | | double surplus = MoneyUtil.sub(moneyCardUse.getRealMoney(), orderItem.getPayMoney()); |
| | | moneyCardUse.setRealMoney(surplus); |
| | | moneyCardUseFlow.setTotal(0-orderItem.getPayMoney()); |
| | | |
| | | } else { |
| | | // 本金不够 |
| | | double surplus = MoneyUtil.sub(orderItem.getPayMoney(), moneyCardUse.getRealMoney()); |
| | | moneyCardUseFlow.setTotal(0- moneyCardUse.getRealMoney()); |
| | | // 扣除所有本金 |
| | | moneyCardUse.setRealMoney(0D); |
| | | moneyCardUse.setGiftMoney(MoneyUtil.sub(moneyCardUse.getGiftMoney(), surplus)); |
| | | // 只要是用了赠送金额购买的就视为赠送套餐 18-12-01 jyy |
| | | orderItem.setIsFree(Dictionary.FLAG_YES); |
| | | moneyCardUseFlow.setGiftMoney(0-surplus); |
| | | } |
| | | |
| | | //设置卡项使用流水 |
| | | moneyCardUseFlow.setCarUseId(moneyCardUse.getId()); |
| | | moneyCardUseFlow.setOrderNo(sourceOrder.getOrderNo()); |
| | | moneyCardUseFlow.setVipId(sourceOrder.getVipId()); |
| | | moneyCardUseFlow.setTimes(-1); |
| | | moneyCardUseFlow.setType(MoneyCardUseFlow.USE_TYPE_CONSUMER); |
| | | moneyCardUseFlow.setCreateTime(new Date()); |
| | | moneyCardUseFlow.setOperationId(user.getSuId()); |
| | | moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney()+moneyCardUse.getRealMoney()); |
| | | moneyCardUseFlowDao.insert(moneyCardUseFlow); |
| | | |
| | | } else { |
| | | throw new GlobleException(moneyCardUse.getCardName() + "余额不足"); |
| | | } |
| | | |
| | | // 达到使用次数后自动清空余额 |
| | | if (!moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_YES_Y) |
| | | && moneyCardUse.getLastCount() <= 0) { |
| | | moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y); |
| | | moneyCardUse.setLastCount(0); |
| | | moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_WX); |
| | | } |
| | | if (moneyCardUse.getRealMoney().equals(0D) && moneyCardUse.getGiftMoney().equals(0D)) { |
| | | moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y); |
| | | moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_WX); |
| | | } |
| | | |
| | | ShoppingGoods shoppingGoods = shoppingGoodsService.findById(moneyCardUse.getGoodsId()); |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(shoppingGoods, 2, moneyCardUse.getFailTime()); |
| | | moneyCardUse.setFailTime(invalidTime); |
| | | // 更新充值卡信息 |
| | | moneyCardUseDao.update(moneyCardUse); |
| | | } |
| | | |
| | | /** |
| | | * @param moneyCardUse |
| | | * @param goodsId |
| | | * @return 返回类型 boolean |
| | | * 判断商品是否在充值卡的优惠中 |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月19日 |
| | | */ |
| | | private boolean isInBangding(MoneyCardUse moneyCardUse, Long goodsId) { |
| | | // 如果是一卡通则肯定在绑定范围内 |
| | | |
| | | if (moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_YES_Y)) { |
| | | return true; |
| | | } else { |
| | | // 不是一卡通, |
| | | // 比较分类 |
| | | MoneyCardAssemble moneyCardAssemble = new MoneyCardAssemble(); |
| | | moneyCardAssemble.setCardId(moneyCardUse.getGoodsId()); |
| | | List<MoneyCardAssemble> cardAssembleList = moneyCardAssembleDao.selectByModel(moneyCardAssemble); |
| | | ShoppingGoods yhGoods = shoppingGoodsDao.selectById(goodsId); |
| | | boolean flag = false; |
| | | for (MoneyCardAssemble cardAssemble : cardAssembleList) { |
| | | // 比较类型 |
| | | if (cardAssemble.getType().equals(Dictionary.CZK_ASSEMBLE_FL)) { |
| | | if (yhGoods.getCateId().equals(cardAssemble.getCateId())) { |
| | | flag = true; |
| | | break; |
| | | } |
| | | } else { |
| | | // 比较绑定 |
| | | if (yhGoods.getId().equals(cardAssemble.getGoodsId())) { |
| | | flag = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置销量 |
| | | * |
| | | * @param sourceOrder |
| | | */ |
| | | public void setShopSelCount(SysOrder sourceOrder) { |
| | | for (SysOrderItem item : sourceOrder.getItems()) { |
| | | // 正真实销量 |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | if (goods.getRealSealCount() == null) { |
| | | goods.setRealSealCount(item.getCount()); |
| | | } else { |
| | | goods.setRealSealCount(goods.getRealSealCount() + item.getCount()); |
| | | } |
| | | shoppingGoodsDao.update(goods); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param sourceOrder 如果购买了充值卡设置会员的充值卡 |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月19日 |
| | | */ |
| | | public void addMoneyCardUse(SysOrder sourceOrder) { |
| | | |
| | | List<SysOrderItem> orderItemList = sourceOrder.getItems(); |
| | | for (SysOrderItem sysOrderItem : orderItemList) { |
| | | // 如果购买的是充值卡 |
| | | if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_CZK)) { |
| | | |
| | | ShoppingGoods moneyCar = shoppingGoodsDao.selectById(sysOrderItem.getGoodsId()); |
| | | MoneyCardUse moneyCardUse = new MoneyCardUse(); |
| | | moneyCardUse.setVipId(sourceOrder.getVipId()); |
| | | moneyCardUse.setGiftMoney(moneyCar.getReferencePice()); |
| | | moneyCardUse.setRealMoney(moneyCar.getSealPice()); |
| | | moneyCardUse.setGoodsId(moneyCar.getId()); |
| | | moneyCardUse.setIsOver(Dictionary.FLAG_NO_N); |
| | | moneyCardUse.setOrderItemId(sysOrderItem.getId()); |
| | | moneyCardUse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); |
| | | moneyCardUse.setCardName(moneyCar.getName()); |
| | | |
| | | if (Dictionary.FLAG_YES.equals(moneyCar.getCarIsAll())) { |
| | | moneyCardUse.setIsVipCar(Dictionary.FLAG_YES_Y); |
| | | } else { |
| | | // 非会籍卡 |
| | | moneyCardUse.setIsVipCar(Dictionary.FLAG_NO_N); |
| | | } |
| | | |
| | | // 是否为赠送 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_YES)) { |
| | | moneyCardUse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | } else { |
| | | moneyCardUse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } |
| | | if (moneyCar.getCarUseCount() == null || moneyCar.getCarUseCount() == 0) { |
| | | moneyCardUse.setUseTotal(999999999); |
| | | moneyCardUse.setLastCount(999999999); |
| | | } else { |
| | | moneyCardUse.setUseTotal(moneyCar.getCarUseCount()); |
| | | moneyCardUse.setLastCount(moneyCar.getCarUseCount()); |
| | | } |
| | | moneyCardUse.setVipId(sourceOrder.getVipId()); |
| | | // if (moneyCar.getValidity() == null || moneyCar.getValidity() == 0) { |
| | | // // 设置失效时间 |
| | | // Calendar cal = Calendar.getInstance(); |
| | | // cal.set(2200, 1, 1); |
| | | // moneyCardUse.setFailTime(cal.getTime()); |
| | | // } else { |
| | | // moneyCardUse.setFailTime(DateUtil.nextNDate(new Date(), 30 * moneyCar.getValidity())); |
| | | // } |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null); |
| | | moneyCardUse.setFailTime(invalidTime); |
| | | |
| | | moneyCardUseDao.insert(moneyCardUse); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月19日 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void updateAfterMoney(SysOrder pageOrder) { |
| | | |
| | | SysOrder sourceOrder = sysOrderDao.selectById(pageOrder.getId()); |
| | | |
| | | boolean haQk=false; |
| | | |
| | | double cardPayTotal=0D; |
| | | double carshPayTotal=0D; |
| | | |
| | | |
| | | for(SysOrderItem pageItem:pageOrder.getItems()){ |
| | | SysOrderItem sourceItem=orderItemDao.selectById(pageItem.getId()); |
| | | |
| | | //结清 |
| | | if(sourceItem.getArrears() == pageItem.getPayMoney()){ |
| | | |
| | | sourceItem.setStatus(Dictionary.ORDER_STATU_YFK); |
| | | }else if(sourceItem.getArrears() > pageItem.getPayMoney()) { |
| | | //未结清 |
| | | sourceItem.setStatus(Dictionary.ORDER_STATU_QK); |
| | | haQk=true; |
| | | }else if(sourceItem.getArrears() < pageItem.getPayMoney()) { |
| | | |
| | | throw new GlobleException("支付金额不能大于欠款金额"); |
| | | |
| | | } |
| | | |
| | | //更新卡支付 |
| | | if (!pageItem.getPayMethod().equals(Dictionary.PAY_TYPE_MOENY)) { |
| | | // 查询要支付的充值卡 |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(Long.parseLong(pageItem.getPayMethod())); |
| | | // 扣除付款卡金额并添加流水 |
| | | cardPaySk(moneyCardUse, sourceOrder, pageItem); |
| | | sourceItem.setCardPay((sourceItem.getCardPay()==null?0:sourceItem.getCardPay())+pageItem.getPayMoney()); |
| | | cardPayTotal+=pageItem.getPayMoney(); |
| | | }else{ |
| | | carshPayTotal+=pageItem.getPayMoney(); |
| | | sourceItem.setCashPay((sourceItem.getCashPay()==null?0:sourceItem.getCashPay())+pageItem.getPayMoney()); |
| | | } |
| | | |
| | | //更新订单明细状态 |
| | | sourceItem.setArrears(sourceItem.getArrears()-pageItem.getPayMoney()); |
| | | |
| | | orderItemDao.update(sourceItem); |
| | | |
| | | } |
| | | //更新收款状态 |
| | | if(haQk){ |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | }else{ |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | } |
| | | |
| | | sourceOrder.setArrears(sourceOrder.getArrears()-carshPayTotal-cardPayTotal); |
| | | sourceOrder.setCardPay(sourceOrder.getCardPay()+cardPayTotal); |
| | | sourceOrder.setCashPay(sourceOrder.getCashPay()+carshPayTotal); |
| | | sysOrderDao.update(sourceOrder); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(pageOrder); |
| | | |
| | | } |
| | | |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao parameterSettingsDao; |
| | | |
| | | /** |
| | | * @param order 新增出库单并更新本店库存 |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月2日 |
| | | */ |
| | | @Override |
| | | public void addOutStore(SysOrder order) { |
| | | |
| | | List<SysOutStoreItem> storeItemList = new ArrayList<>(); |
| | | |
| | | for (SysOrderItem sysOrderItem : order.getItems()) { |
| | | |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP.equals(sysOrderItem.getType())) { |
| | | |
| | | SysOutStoreItem storeItem = new SysOutStoreItem(); |
| | | storeItem.setSkuId(sysOrderItem.getGoodsId()); |
| | | storeItem.setAmount(Double.valueOf(sysOrderItem.getCount())); |
| | | storeItemList.add(storeItem); |
| | | |
| | | } else if (ShoppingGoods.SHOPPING_GOODS_TYPE_TC.equals(sysOrderItem.getType()) |
| | | |
| | | || ShoppingGoods.SHOPPING_GOODS_TYPE_ZHK.equals(sysOrderItem.getType())) { |
| | | |
| | | List<ShoppingGoodsAssemble> goodsList = new ArrayList<>(); |
| | | |
| | | goodsList.addAll(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP)); |
| | | |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_ZHK.equals(sysOrderItem.getType())) { |
| | | //综合卡处理,中的套餐,中的家居产品 |
| | | List<ShoppingGoodsAssemble> zhkAssemble = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_TC); |
| | | zhkAssemble.forEach(item -> { |
| | | goodsList.addAll(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(item.getAssembleGoodId(), ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP)); |
| | | }); |
| | | } |
| | | |
| | | goodsList.forEach(item -> { |
| | | SysOutStoreItem storeItem = new SysOutStoreItem(); |
| | | storeItem.setSkuId(item.getAssembleGoodId()); |
| | | storeItem.setAmount(Double.valueOf(item.getTotal())); |
| | | storeItemList.add(storeItem); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | if (CollectionUtils.isNotEmpty(storeItemList)) { |
| | | Long warehouseId = warehouseDao.findShopWarehouse(order.getShopId()).get(0).getId(); |
| | | SysOutStore outStore = new SysOutStore(); |
| | | outStore.setOutStoreNo(codeService.getOutStoreCode()); |
| | | outStore.setOrderId(order.getId()); |
| | | outStore.setShopId(order.getShopId()); |
| | | outStore.setShopId(order.getShopId()); |
| | | outStore.setStaffId(order.getStaffId()); |
| | | outStore.setType(Dictionary.OUT_STORE_JJCPCK); |
| | | outStore.setServiceNo(order.getOrderNo()); |
| | | outStore.setTime(new Date()); |
| | | outStore.setCheckStatus(Dictionary.CHECK_STATUS_DSH); |
| | | outStore.setCompanyId(order.getCompanyId()); |
| | | sysOutStoreDao.insert(outStore); |
| | | |
| | | //出库明细,根据批次维度定义 |
| | | List<SysOutStoreItem> realOutStoreItemList = new ArrayList<>(); |
| | | |
| | | storeItemList.forEach(outStoreItem -> { |
| | | |
| | | //设置出库主键 |
| | | outStoreItem.setOutStoreId(outStore.getId()); |
| | | |
| | | //计算库存总数是否满足本次扣减的需求 |
| | | List<SysStoreInfo> stores = storeInfoDao.selectStoInfoBySku(outStoreItem.getSkuId(), warehouseId); |
| | | double sum = stores.stream().mapToDouble(item -> item.getStoreTotal()).sum(); |
| | | if (sum < outStoreItem.getAmount()) { |
| | | ShoppingGoods sysGoods = shoppingGoodsDao.selectById(outStoreItem.getSkuId()); |
| | | if (sysGoods != null) { |
| | | throw new GlobleException("出库失败:【" + sysGoods.getName() + "库存不足】"); |
| | | } else { |
| | | throw new GlobleException("出库失败没有找到出库产品"); |
| | | } |
| | | } |
| | | |
| | | //循环获取所有批次产品,并扣减库存 |
| | | Double number = outStoreItem.getAmount(); |
| | | for (SysStoreInfo storeInfo : stores) { |
| | | Double oldStoreTotal = storeInfo.getStoreTotal(); |
| | | Double surplus = storeInfo.getStoreTotal() - number; |
| | | //更新库存 |
| | | storeInfo.setStoreTotal(surplus < 0 ? 0 : surplus); |
| | | |
| | | //每次扣减库存都创建一个出库记录 |
| | | SysOutStoreItem sysOutStoreItem = new SysOutStoreItem(); |
| | | BeanUtils.copyProperties(outStoreItem, sysOutStoreItem); |
| | | sysOutStoreItem.setStoreId(storeInfo.getId()); |
| | | sysOutStoreItem.setAmount(oldStoreTotal - storeInfo.getStoreTotal()); |
| | | realOutStoreItemList.add(sysOutStoreItem); |
| | | |
| | | storeInfoDao.update(storeInfo); |
| | | //扣除后剩余库存大于0则跳出扣除,否则剩余数量的负数的绝对值就是再次扣减的数量 |
| | | if (surplus > 0) { |
| | | break; |
| | | } else { |
| | | number = Math.abs(surplus); |
| | | } |
| | | } |
| | | }); |
| | | sysOutStoreItemDao.batchInsert(realOutStoreItemList); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 新增项目和套餐的余次 |
| | | * |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月2日 |
| | | */ |
| | | public void addTaocanProj(SysOrder order) { |
| | | List<SysOrderItem> itemList = order.getItems(); |
| | | for (SysOrderItem sysOrderItem : itemList) { |
| | | // 折扣 项目的实际购买除以项目原价,来计算项目的消耗价格 |
| | | // 赠送 计算全额的消耗业绩 |
| | | if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_XM)) { |
| | | createXmProjuse(order, sysOrderItem); |
| | | } else if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_TC)) { |
| | | //每个套餐独立生成一个明细 |
| | | int orderCount = sysOrderItem.getCount(); |
| | | while (orderCount > 0) { |
| | | createTaocanProjUse(order, sysOrderItem, null); |
| | | orderCount--; |
| | | } |
| | | } else if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_ZHK)) { |
| | | addZongheCarUse(order, sysOrderItem); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public void addZongheCarUse(SysOrder order, SysOrderItem sysOrderItem) { |
| | | |
| | | |
| | | //处理一个订单买多次 |
| | | int orderCount = sysOrderItem.getCount(); |
| | | while (orderCount < 0) { |
| | | orderCount--; |
| | | //综合卡中包含的项目 |
| | | List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM); |
| | | assembleList.forEach(item -> { |
| | | createProjuseByAssemble(order, sysOrderItem, item, null); |
| | | }); |
| | | |
| | | //处理综合卡中包含的套餐 |
| | | List<ShoppingGoodsAssemble> zhkAssemble = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_TC); |
| | | zhkAssemble.forEach(taocan -> { |
| | | int assembleCount = taocan.getTotal(); |
| | | while (assembleCount > 0) { |
| | | assembleCount--; |
| | | createTaocanProjUse(order, sysOrderItem, taocan); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 通过组合关系创建用户项目余次 |
| | | */ |
| | | private SysProjUse createProjuseByAssemble(SysOrder order, SysOrderItem sysOrderItem, |
| | | ShoppingGoodsAssemble goodsAssemble, Long taocanId) { |
| | | //计算折扣 |
| | | Double zk=sysOrderItem.getZkPrice()/sysOrderItem.getPrice(); |
| | | |
| | | SysProjUse puse = new SysProjUse(); |
| | | puse.setIsOver(Dictionary.DELETED_N); |
| | | puse.setOrderItemId(sysOrderItem.getId()); |
| | | puse.setProjId(goodsAssemble.getAssembleGoodId()); |
| | | puse.setSurplusCount(goodsAssemble.getTotal()); |
| | | puse.setDeductionNum(goodsAssemble.getDeductionNum()); |
| | | puse.setProjName(goodsAssemble.getShoppingGoods().getName()); |
| | | puse.setVipId(order.getVipId()); |
| | | puse.setStatus(Dictionary.TAOCAN_STATUS_YX); |
| | | puse.setTaocanId(taocanId); |
| | | puse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); |
| | | if (taocanId == null) { |
| | | puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() * zk ); |
| | | } else { |
| | | puse.setPrice(goodsAssemble.getPrice() * zk ); |
| | | } |
| | | puse.setBalance(MoneyUtil.mul(puse.getPrice(), Double.valueOf(puse.getSurplusCount()))); |
| | | // 赠送和打折后金额为0的都视为赠送项目 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0) { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } else { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | } |
| | | // 设置失效时间 |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(2200, 1, 1); |
| | | puse.setFailTime(cal.getTime()); |
| | | sysProjUseDao.insert(puse); |
| | | return puse; |
| | | } |
| | | |
| | | |
| | | private void createTaocanProjUse(SysOrder order, SysOrderItem sysOrderItem, ShoppingGoodsAssemble goodsAssemble) { |
| | | |
| | | //新建套餐 |
| | | SysProjUse taocanProjUse = new SysProjUse(); |
| | | |
| | | ShoppingGoods taocanShoppingGoods = sysOrderItem.getShoppingGoods(); |
| | | |
| | | |
| | | Long projId = sysOrderItem.getGoodsId(); |
| | | |
| | | if (goodsAssemble != null) { |
| | | taocanShoppingGoods = shoppingGoodsDao.selectById(goodsAssemble.getAssembleGoodId()); |
| | | projId = goodsAssemble.getAssembleGoodId(); |
| | | } |
| | | |
| | | taocanProjUse.setProjId(projId); |
| | | taocanProjUse.setIsOver(Dictionary.DELETED_N); |
| | | taocanProjUse.setOrderItemId(sysOrderItem.getId()); |
| | | |
| | | taocanProjUse.setProjName(taocanShoppingGoods.getName()); |
| | | taocanProjUse.setVipId(order.getVipId()); |
| | | taocanProjUse.setStatus(Dictionary.TAOCAN_STATUS_YX); |
| | | taocanProjUse.setType(Dictionary.SHOPPING_GOODS_TYPE_TC); |
| | | taocanProjUse.setIsCourse(taocanShoppingGoods.getIsCourse()); |
| | | taocanProjUse.setIsInfinite(taocanShoppingGoods.getIsInfinite()); |
| | | // 赠送和打折后金额为0的都视为赠送项目 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0) { |
| | | taocanProjUse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } else { |
| | | taocanProjUse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | } |
| | | // 失效时间 |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(taocanShoppingGoods, 1, null); |
| | | taocanProjUse.setFailTime(invalidTime); |
| | | sysProjUseDao.insert(taocanProjUse); |
| | | //计划次数 |
| | | int surplusCount=0; |
| | | //总余额 |
| | | Double sumBanance = 0D; |
| | | //创建套餐绑定的项目 |
| | | List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(projId, ShoppingGoods.SHOPPING_GOODS_TYPE_XM); |
| | | for (ShoppingGoodsAssemble assemble : assembleList) { |
| | | SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId()); |
| | | sumBanance += tempUse.getBalance(); |
| | | surplusCount+=tempUse.getSurplusCount(); |
| | | } |
| | | if(Dictionary.FLAG_NO_N.equals(taocanShoppingGoods.getIsCourse())){ |
| | | //固定套餐,剩余次数等于绑定项目的次数 |
| | | taocanProjUse.setSurplusCount(surplusCount); |
| | | }else{ |
| | | //任选套餐剩余次数等于最大使用次数 |
| | | taocanProjUse.setSurplusCount(taocanShoppingGoods.getCarUseCount()); |
| | | } |
| | | //合计套餐余额 |
| | | taocanProjUse.setBalance(sumBanance); |
| | | sysProjUseDao.update(taocanProjUse); |
| | | } |
| | | |
| | | /** |
| | | * 根据订单创建用户项目使用情况 |
| | | * |
| | | * @param order |
| | | * @param sysOrderItem |
| | | */ |
| | | private void createXmProjuse(SysOrder order, SysOrderItem sysOrderItem) { |
| | | SysProjUse puse = new SysProjUse(); |
| | | puse.setIsOver(Dictionary.DELETED_N); |
| | | puse.setOrderItemId(sysOrderItem.getId()); |
| | | puse.setProjId(sysOrderItem.getGoodsId()); |
| | | puse.setSurplusCount(sysOrderItem.getCount()); |
| | | puse.setVipId(order.getVipId()); |
| | | puse.setStatus(Dictionary.TAOCAN_STATUS_YX); |
| | | puse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); |
| | | puse.setBalance(MoneyUtil.add(sysOrderItem.getCardPay(), sysOrderItem.getCashPay())); |
| | | puse.setPrice(sysOrderItem.getZkPrice()); |
| | | puse.setProjName(sysOrderItem.getShoppingGoods().getName()); |
| | | // 赠送和打折后金额为0的都视为赠送项目 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0) { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } else { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | } |
| | | // 设置失效时间 |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null); |
| | | puse.setFailTime(invalidTime); |
| | | sysProjUseDao.insert(puse); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员卡充值 |
| | | * @param czVo |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder updateAddCardMoney(CzXkVo czVo) { |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | SysVipInfo vip = (SysVipInfo) WebUtil.getSession().getAttribute(SystemConstance.CURRENT_CUSTOMER); |
| | | czVo.setVipId(vip.getId()); |
| | | |
| | | //更新会员会员卡金额 |
| | | MoneyCardUse cardUser = moneyCardUseDao.selectVipCard(vip.getId()); |
| | | cardUser.setRealMoney(MoneyUtil.add(cardUser.getRealMoney(), czVo.getBjmoney())); |
| | | cardUser.setGiftMoney(MoneyUtil.add(cardUser.getGiftMoney(), czVo.getGiftMoney())); |
| | | moneyCardUseDao.update(cardUser); |
| | | |
| | | |
| | | // 为会员新增积分 |
| | | SysVipInfo vipInfo = sysVipInfoDao.selectById(cardUser.getVipId()); |
| | | vipInfo.setPointAll(vipInfo.getPointAll() == null ? 0 : vipInfo.getPointAll() + czVo.getJf()); |
| | | sysVipInfoDao.update(vipInfo); |
| | | |
| | | |
| | | // 新增一个充值订单 |
| | | SysOrder order = new SysOrder(); |
| | | order.setArrears(0D); |
| | | order.setTotal(czVo.getBjmoney()); |
| | | order.setZkTotal(czVo.getBjmoney()); |
| | | order.setCashPay(czVo.getBjmoney()); |
| | | order.setShopId(user.getShopId()); |
| | | order.setOrderNo(codeService.getOrderCode()); |
| | | order.setVipId(czVo.getVipId()); |
| | | Date orderTime = new Date(); |
| | | if (StringUtils.isNotBlank(czVo.getDateTime())) { |
| | | orderTime = DateUtil.stringToDateNew(czVo.getDateTime(), DateUtil.DATE_FORMAT_DD); |
| | | } |
| | | order.setOrderTime(orderTime); |
| | | order.setPayTime(orderTime); |
| | | order.setRemark(cardUser.getCardName()); |
| | | order.setStaffId(user.getSuId()); |
| | | order.setIsCross(2 + ""); |
| | | order.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | sysOrderDao.insert(order); |
| | | |
| | | SysOrderItem orderItem = new SysOrderItem(); |
| | | orderItem.setOrderId(order.getId()); |
| | | orderItem.setOrderNo(order.getOrderNo()); |
| | | orderItem.setArrears(0D); |
| | | ShoppingGoods shoppingGoods= shoppingGoodsDao.selectVipCzGoods(); |
| | | orderItem.setGoodsId(shoppingGoods.getId()); |
| | | orderItem.setPayMethod(Dictionary.PAY_TYPE_MOENY); |
| | | orderItem.setCashPay(czVo.getBjmoney()); |
| | | orderItem.setZkPrice(czVo.getBjmoney()); |
| | | orderItem.setCardPay(0D); |
| | | orderItem.setType(Dictionary.SHOPPING_GOODS_TYPE_CZK); |
| | | orderItem.setCount(1); |
| | | orderItem.setIsFree(Dictionary.FLAG_NO); |
| | | orderItem.setPrice(czVo.getBjmoney()); |
| | | orderItem.setStatus(Dictionary.ORDER_STATU_YFK); |
| | | orderItem.setAchaeveList(czVo.getAchaeveList()); |
| | | orderItemDao.insert(orderItem); |
| | | |
| | | |
| | | //设置卡项使用流水 |
| | | MoneyCardUseFlow moneyCardUseFlow=new MoneyCardUseFlow(); |
| | | moneyCardUseFlow.setTotal(czVo.getBjmoney()); |
| | | moneyCardUseFlow.setGiftMoney(czVo.getGiftMoney()); |
| | | moneyCardUseFlow.setCarUseId(czVo.getCardId()); |
| | | moneyCardUseFlow.setVipId(czVo.getVipId()); |
| | | moneyCardUseFlow.setType(MoneyCardUseFlow.USE_TYPE_CZ); |
| | | moneyCardUseFlow.setOrderNo(order.getOrderNo()); |
| | | moneyCardUseFlow.setCreateTime(new Date()); |
| | | moneyCardUseFlow.setOperationId(user.getSuId()); |
| | | moneyCardUseFlow.setBalance(cardUser.getGiftMoney()+cardUser.getRealMoney()); |
| | | moneyCardUseFlowDao.insert(moneyCardUseFlow); |
| | | |
| | | |
| | | // 添加员工业绩 |
| | | achieveNewService.addAchaeveByOrder(order); |
| | | return order; |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public SysOrder findSysOrderTjByVipId(Long vipId) { |
| | | return sysOrderDao.selectVipOrderInfoTotal(vipId); |
| | | } |
| | | } |