| | |
| | | */ |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import com.matrix.system.hive.bean.ShoppingGoods; |
| | | import com.matrix.system.hive.bean.SysOrder; |
| | | import com.matrix.system.hive.bean.SysOrderFlow; |
| | | import com.matrix.system.hive.dao.ShoppingGoodsDao; |
| | | import com.matrix.system.hive.dao.SysOrderFlowDao; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.google.common.collect.Lists; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.exception.GlobleException; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.core.tools.WebUtil; |
| | | 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.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.MoneyCardOperationDto; |
| | | import com.matrix.system.hive.dto.ProjUseOperationDto; |
| | | import com.matrix.system.hive.plugin.util.CollectionUtils; |
| | | import com.matrix.system.hive.plugin.util.MoneyUtil; |
| | | import com.matrix.system.hive.pojo.CzXkVo; |
| | | import com.matrix.system.hive.service.CodeService; |
| | | import com.matrix.system.hive.service.MoneyCardUseService; |
| | | import com.matrix.system.hive.service.SysInstoreInfoService; |
| | | import com.matrix.system.hive.service.SysProjUseService; |
| | | import com.matrix.system.score.constant.ScoreSettingConstant; |
| | | import com.matrix.system.score.entity.ScoreVipDetail; |
| | | import com.matrix.system.score.service.ScoreVipDetailService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @version: V1.0 |
| | |
| | | |
| | | |
| | | @Autowired |
| | | SysInstoreInfoService sysInstoreInfoService; |
| | | |
| | | @Autowired |
| | | private SysSupplierInfoDao sysSupplierInfoDao; |
| | | |
| | | @Autowired |
| | | ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | @Autowired |
| | | SysVipInfoDao sysVipInfoDao; |
| | | |
| | | @Autowired |
| | | private SysStoreInfoDao storeInfoDao; |
| | | |
| | | @Autowired |
| | | private SysProjUseService sysProjUseService; |
| | | |
| | | @Autowired |
| | | SysOutStoreDao sysOutStoreDao; |
| | | @Autowired |
| | | private CodeService codeService; |
| | | |
| | | @Autowired |
| | | ShoppingGoodsAssembleDao shoppingGoodsAssembleDao; |
| | | |
| | | @Autowired |
| | | SysOutStoreItemDao sysOutStoreItemDao; |
| | | |
| | | @Autowired |
| | | private SysOrderDao sysOrderDao; |
| | | |
| | | @Autowired |
| | | private OperationLogService operationLogService; |
| | | @Autowired |
| | | ShoppingGoodsDao shoppingGoodsDao; |
| | | |
| | | @Autowired |
| | | private SysOrderFlowDao sysOrderFlowDao; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | @Autowired |
| | | private WarehouseDao warehouseDao; |
| | | |
| | | @Autowired |
| | | MoneyCardUseService moneyCardUseService; |
| | | |
| | | @Autowired |
| | | private SysOrderItemDao orderItemDao; |
| | | |
| | | |
| | | @Autowired |
| | | MoneyCardUseDao moneyCardUseDao; |
| | | |
| | | /** |
| | | * 创建支付流水 |
| | | * |
| | | * @author:姜友瑶 |
| | | */ |
| | | public void addOrderFlow(SysOrder sourceOrder) { |
| | | public void addOrderFlow(SysOrder sourceOrder, boolean isBj) { |
| | | |
| | | LogUtil.info("创建支付流水 id={}", sourceOrder.getId()); |
| | | //处理支付流水 |
| | | int flowCount = 1; |
| | | for (SysOrderFlow flow : sourceOrder.getFlows()) { |
| | |
| | | flow.setAmount(flow.getAmount().negate()); |
| | | flow.setOrderId(sourceOrder.getOldOrderId()); |
| | | } else { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_BUY); |
| | | if (isBj) {//jyytodo 优化不能根据isbj来判断流水类型 |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REPAY); |
| | | } else { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_BUY); |
| | | } |
| | | |
| | | flow.setOrderId(sourceOrder.getId()); |
| | | } |
| | | sysOrderFlowDao.insert(flow); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增项目和套餐的余次 |
| | | * |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月2日 |
| | | */ |
| | | public void addTaocanProj(SysOrder order) { |
| | | List<SysOrderItem> itemList = order.getItems(); |
| | | List<ProjUseOperationDto> projUseDtoList = Lists.newArrayList(); |
| | | for (SysOrderItem sysOrderItem : itemList) { |
| | | // 折扣 项目的实际购买除以项目原价,来计算项目的消耗价格 |
| | | // 赠送 计算全额的消耗业绩 |
| | | ProjUseOperationDto projUseOperationDto = new ProjUseOperationDto(); |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0 && !isGiftMoneyPay(order)) { |
| | | projUseOperationDto.setFree(false); |
| | | } else { |
| | | projUseOperationDto.setFree(true); |
| | | } |
| | | if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_TC)) { |
| | | //计算折扣 |
| | | Double zk = sysOrderItem.getZkPrice() / sysOrderItem.getPrice(); |
| | | projUseOperationDto.setTcZk(zk); |
| | | } |
| | | |
| | | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | projUseOperationDto.setPayMoney(sysOrderItem.getZkPrice()); |
| | | projUseOperationDto.setGoodsId(sysOrderItem.getGoodsId()); |
| | | projUseOperationDto.setCount(sysOrderItem.getCount()); |
| | | projUseOperationDto.setVipId(order.getVipId()); |
| | | projUseOperationDto.setOrderItemId(sysOrderItem.getId()); |
| | | projUseOperationDto.setUpdateUserId(sysUsers.getSuId()); |
| | | projUseDtoList.add(projUseOperationDto); |
| | | } |
| | | sysProjUseService.addUserProjUse(projUseDtoList); |
| | | } |
| | | |
| | | /** |
| | | * 全是赠送金额,且配置了赠送金额购买计算为赠送 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isGiftMoneyPay(SysOrder order) { |
| | | BusParameterSettings giftiIsfree = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.SHOP_MANAGE_GIFTISFREE, order.getCompanyId()); |
| | | if (BooleanEnum.TRUE.getValue() == giftiIsfree.getIntParamValue()) { |
| | | return order.getFlows().stream().allMatch(item -> SysOrderFlow.IS_GIFT_Y.equals(item.getIsGift()) |
| | | && item.getAmount().doubleValue() > 0D); |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 使用充值卡付款操作 |
| | | * |
| | | * @param pageOrder |
| | | */ |
| | | public void cardPaySk(SysOrder pageOrder) { |
| | | |
| | | |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | List<SysOrderFlow> flows = pageOrder.getFlows(); |
| | | List<Long> goodsIds = pageOrder.getItems().stream().map(e -> e.getGoodsId()).collect(Collectors.toList()); |
| | | |
| | | List<MoneyCardOperationDto> moneyCardOperationDtos = Lists.newArrayList(); |
| | | |
| | | flows.forEach(flow -> { |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardOperationDto dto = new MoneyCardOperationDto(); |
| | | dto.setOrderNo(pageOrder.getOrderNo()); |
| | | dto.setOrderId(pageOrder.getId()); |
| | | dto.setCount(1); |
| | | dto.setCarUseId(flow.getCardId()); |
| | | dto.setType(MoneyCardUseFlow.USE_TYPE_CONSUMER); |
| | | if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) { |
| | | dto.setGiftMoney(-flow.getAmount().doubleValue()); |
| | | dto.setRealMoney(0D); |
| | | } else { |
| | | dto.setRealMoney(-flow.getAmount().doubleValue()); |
| | | dto.setGiftMoney(0D); |
| | | } |
| | | dto.setUpdateUser(user.getSuId()); |
| | | dto.setGoodsIds(goodsIds); |
| | | moneyCardOperationDtos.add(dto); |
| | | } else { |
| | | throw new GlobleException("无效的储值卡支付方式"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | if (CollectionUtils.isNotEmpty(moneyCardOperationDtos)) { |
| | | LogUtil.info("扣除储值卡余额{}", JSON.toJSONString(moneyCardOperationDtos)); |
| | | moneyCardUseService.changeMoneyCard(moneyCardOperationDtos); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 储值卡退款 |
| | | * @param order |
| | | */ |
| | | public void returnMoneyCardPay(SysOrder order) { |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | List<MoneyCardOperationDto> moneyCardOperationDtos = Lists.newArrayList(); |
| | | |
| | | List<SysOrderFlow> flows = sysOrderFlowDao.selectByOrderId(order.getId()); |
| | | // 非现金收款退回扣卡余额 |
| | | for (SysOrderFlow flow : flows) { |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardOperationDto dto = new MoneyCardOperationDto(); |
| | | dto.setOrderNo(order.getOrderNo()); |
| | | dto.setOrderId(order.getId()); |
| | | dto.setCount(1); |
| | | dto.setCarUseId(flow.getCardId()); |
| | | dto.setType(MoneyCardUseFlow.USE_TYPE_ORDRE_CANCEL); |
| | | if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) { |
| | | dto.setGiftMoney(flow.getAmount().doubleValue()); |
| | | } else { |
| | | dto.setRealMoney(flow.getAmount().doubleValue()); |
| | | } |
| | | dto.setUpdateUser(user.getSuId()); |
| | | moneyCardOperationDtos.add(dto); |
| | | } else { |
| | | throw new GlobleException("无效的储值卡支付方式"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (CollectionUtils.isNotEmpty(moneyCardOperationDtos)) { |
| | | LogUtil.info("退回储值卡余额{}", JSON.toJSONString(moneyCardOperationDtos)); |
| | | moneyCardUseService.changeMoneyCard(moneyCardOperationDtos); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param sourceOrder 如果购买了充值卡设置会员的充值卡 |
| | | * @author:姜友瑶 |
| | | * @date 2016年9月19日 |
| | | */ |
| | | public void addMoneyCardUse(SysOrder sourceOrder) { |
| | | |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | List<MoneyCardOperationDto> moneyCardOperationDtos = Lists.newArrayList(); |
| | | List<SysOrderItem> orderItemList = sourceOrder.getItems(); |
| | | for (SysOrderItem sysOrderItem : orderItemList) { |
| | | // 如果购买的是充值卡 |
| | | if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_CZK)) { |
| | | for (int i = 0; i < sysOrderItem.getCount(); i++) { |
| | | |
| | | MoneyCardOperationDto moneyCardOperationDto = new MoneyCardOperationDto(); |
| | | // 是否为赠送 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_YES)) { |
| | | moneyCardOperationDto.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | } else { |
| | | moneyCardOperationDto.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } |
| | | moneyCardOperationDto.setType(MoneyCardUseFlow.USE_TYPE_GM); |
| | | moneyCardOperationDto.setOrderItemId(sysOrderItem.getId()); |
| | | moneyCardOperationDto.setGoodsId(sysOrderItem.getGoodsId()); |
| | | moneyCardOperationDto.setOrderId(sourceOrder.getId()); |
| | | moneyCardOperationDto.setOrderNo(sourceOrder.getOrderNo()); |
| | | moneyCardOperationDto.setVipId(sourceOrder.getVipId()); |
| | | moneyCardOperationDto.setUpdateUser(user.getSuId()); |
| | | |
| | | moneyCardOperationDtos.add(moneyCardOperationDto); |
| | | } |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(moneyCardOperationDtos)) { |
| | | moneyCardUseService.addVipMoneyCard(moneyCardOperationDtos); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 新增出库单并更新本店库存 |
| | | * jyytodo 继续优化 |
| | | * |
| | | * @param order |
| | | */ |
| | | public void addOutStore(SysOrder order) { |
| | | |
| | | BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, order.getCompanyId()); |
| | | // if (AppConstance.IS_Y.equals(manageStockSetting.getParamValue())) { |
| | | if (BooleanEnum.TRUE.getValue() == manageStockSetting.getIntParamValue()) { |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } else { |
| | | LogUtil.debug("不管理库存"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置会员消费积分 |
| | | * |
| | | * @param pageOrder |
| | | */ |
| | | public void addVipScore(SysOrder pageOrder) { |
| | | |
| | | SysVipInfo vipInfo = sysVipInfoDao.selectById(pageOrder.getVipId()); |
| | | |
| | | List<SysOrderFlow> flows = pageOrder.getFlows(); |
| | | int[] cashScore = {0, 0, 0}; |
| | | //现金支付金额 |
| | | BigDecimal cashPayAmount = flows.stream() |
| | | .filter(item -> (!item.getPayMethod().equals("储值卡")) && (!item.getPayMethod().equals("欠款"))) |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BusParameterSettings cashConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.CASH_CONSUMPTION, vipInfo.getCompanyId()); |
| | | if (cashPayAmount != null |
| | | && cashPayAmount.compareTo(BigDecimal.ZERO) > 0 |
| | | && StringUtils.isNotBlank(cashConsumption.getParamValue())) { |
| | | |
| | | BigDecimal scoreSetting0 = new BigDecimal(cashConsumption.getParamValue()); |
| | | if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { |
| | | cashScore[0] = cashPayAmount.divide(scoreSetting0).intValue(); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(cashConsumption.getParamValue1())) { |
| | | BigDecimal scoreSetting1 = new BigDecimal(cashConsumption.getParamValue1()); |
| | | if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { |
| | | cashScore[1] = cashPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(cashConsumption.getParamValue2())) { |
| | | BigDecimal scoreSetting2 = new BigDecimal(cashConsumption.getParamValue2()); |
| | | if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { |
| | | cashScore[2] = cashPayAmount.divide(scoreSetting2).intValue(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | int[] cardScore = {0, 0, 0}; |
| | | //储值卡本金支付金额 |
| | | BigDecimal cardPayAmount = flows.stream() |
| | | .filter(item -> item.getPayMethod().equals("储值卡") && item.getIsGift().equals("N")) |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | BusParameterSettings principalBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); |
| | | if (cardPayAmount != null |
| | | && cardPayAmount.compareTo(BigDecimal.ZERO) > 0 |
| | | && StringUtils.isNotBlank(principalBalanceConsumption.getParamValue())) { |
| | | |
| | | BigDecimal scoreSetting0 = new BigDecimal(principalBalanceConsumption.getParamValue()); |
| | | if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { |
| | | cardScore[0] = cardPayAmount.divide(scoreSetting0).intValue(); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(principalBalanceConsumption.getParamValue1())) { |
| | | BigDecimal scoreSetting1 = new BigDecimal(principalBalanceConsumption.getParamValue1()); |
| | | if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { |
| | | cardScore[1] = cardPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(principalBalanceConsumption.getParamValue2())) { |
| | | BigDecimal scoreSetting2 = new BigDecimal(principalBalanceConsumption.getParamValue2()); |
| | | if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { |
| | | cardScore[2] = cardPayAmount.divide(scoreSetting2).intValue(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | int[] giftScore = {0, 0, 0}; |
| | | //储值卡本赠送付金额 |
| | | BigDecimal giftPayAmount = flows.stream() |
| | | .filter(item -> item.getPayMethod().equals("储值卡") && item.getIsGift().equals("Y")) |
| | | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BusParameterSettings bonusBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); |
| | | if (giftPayAmount != null |
| | | && giftPayAmount.compareTo(BigDecimal.ZERO) > 0 |
| | | && StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue())) { |
| | | |
| | | BigDecimal scoreSetting0 = new BigDecimal(bonusBalanceConsumption.getParamValue()); |
| | | if (scoreSetting0.compareTo(BigDecimal.ZERO) > 0) { |
| | | giftScore[0] = giftPayAmount.divide(scoreSetting0).intValue(); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue1())) { |
| | | BigDecimal scoreSetting1 = new BigDecimal(bonusBalanceConsumption.getParamValue1()); |
| | | if (scoreSetting1.compareTo(BigDecimal.ZERO) > 0) { |
| | | giftScore[1] = giftPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue2())) { |
| | | BigDecimal scoreSetting2 = new BigDecimal(bonusBalanceConsumption.getParamValue2()); |
| | | if (scoreSetting2.compareTo(BigDecimal.ZERO) > 0) { |
| | | giftScore[2] = giftPayAmount.divide(scoreSetting2).intValue(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | int selfScore = cashScore[0] + cardScore[0] + giftScore[0]; |
| | | int parentScore = cashScore[1] + cardScore[1] + giftScore[1]; |
| | | int topParentScore = cashScore[2] + cardScore[2] + giftScore[2]; |
| | | |
| | | |
| | | //添加自己的积分 |
| | | if (selfScore > 0) { |
| | | scoreVipDetailService.addScore( |
| | | vipInfo.getId(), |
| | | pageOrder.getStaffId(), |
| | | pageOrder.getShopId(), |
| | | selfScore, |
| | | pageOrder.getId(), |
| | | ScoreVipDetail.SCORE_VIP_TYPE_CASH, |
| | | "消费奖励" |
| | | ); |
| | | } |
| | | |
| | | if (vipInfo.getRecommendId() != null) { |
| | | //推荐注册老带新积分奖励 |
| | | SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId()); |
| | | if (parentScore > 0) { |
| | | scoreVipDetailService.addScore( |
| | | referrerVip.getId(), |
| | | pageOrder.getStaffId(), |
| | | pageOrder.getShopId(), |
| | | parentScore, |
| | | pageOrder.getId(), |
| | | ScoreVipDetail.SCORE_VIP_TYPE_CASH, |
| | | "推荐消费奖励" |
| | | ); |
| | | } |
| | | //推荐注册二级带新积分奖励 |
| | | if (referrerVip.getRecommendId() != null) { |
| | | SysVipInfo topVipInfo = sysVipInfoDao.selectById(referrerVip.getRecommendId()); |
| | | if (topParentScore > 0) { |
| | | scoreVipDetailService.addScore( |
| | | topVipInfo.getId(), |
| | | pageOrder.getStaffId(), |
| | | pageOrder.getShopId(), |
| | | topParentScore, |
| | | pageOrder.getId(), |
| | | ScoreVipDetail.SCORE_VIP_TYPE_CASH, |
| | | "推荐消费奖励" |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建订单信息 |
| | | * |
| | | * @param sysOrder |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder saveOrder(SysOrder sysOrder) { |
| | | |
| | | //校验参数 jyytodo |
| | | |
| | | // 计算订单折扣金额,收款情况下 计算订单总额 |
| | | double zkTotal = 0.0; |
| | | // 页面的pageOrder 参数只包含支付金额信息,不带有购买商品 |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | item.setType(shoppingGoods.getGoodType()); |
| | | if (item.getZkPrice() == null) { |
| | | item.setZkPrice(shoppingGoods.getSealPice()); |
| | | } |
| | | |
| | | if (item.getZkPrice() == 0) { |
| | | item.setIsFree(Dictionary.FLAG_YES); |
| | | } |
| | | Double itemZkTotal = MoneyUtil.mul(item.getZkPrice(), Double.valueOf(item.getCount())); |
| | | zkTotal = MoneyUtil.add(zkTotal, itemZkTotal); |
| | | item.setStatus(Dictionary.ORDER_STATU_DFK); |
| | | item.setRefundCount(0); |
| | | } |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | sysOrder.setZkTotal(zkTotal); |
| | | sysOrder.setStatu(Dictionary.ORDER_STATU_DFK); |
| | | sysOrder.setShopId(user.getShopId()); |
| | | sysOrder.setStaffId(user.getSuId()); |
| | | sysOrder.setCompanyId(user.getCompanyId()); |
| | | sysOrder.setOrderTime(new Date()); |
| | | sysOrder.setOrderType(SysOrder.ORDER_TYPE_SEAL); |
| | | |
| | | |
| | | //新增订单 |
| | | sysOrder.setOrderNo(codeService.getOrderCode()); |
| | | sysOrderDao.insert(sysOrder); |
| | | |
| | | //保存单据明细 |
| | | sysOrder.getItems().forEach(sysOrderItem -> { |
| | | sysOrderItem.setOrderId(sysOrder.getId()); |
| | | orderItemDao.insert(sysOrderItem); |
| | | }); |
| | | |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.CREATE, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId()); |
| | | |
| | | return sysOrder; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 修改订单信息 |
| | | * |
| | | * @param sysOrder |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SysOrder modifyOrder(SysOrder sysOrder) { |
| | | // 计算订单折扣金额,收款情况下 计算订单总额 |
| | | double zkTotal = 0.0; |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | item.setType(shoppingGoods.getGoodType()); |
| | | if (item.getZkPrice() == 0) { |
| | | item.setIsFree(Dictionary.FLAG_YES); |
| | | } |
| | | Double itemZkTotal = MoneyUtil.mul(item.getZkPrice(), Double.valueOf(item.getCount())); |
| | | zkTotal = MoneyUtil.add(zkTotal, itemZkTotal); |
| | | } |
| | | sysOrder.setZkTotal(zkTotal); |
| | | //更新订单 |
| | | sysOrderDao.update(sysOrder); |
| | | //删除原有订单明细 |
| | | orderItemDao.deleteByOrderId(sysOrder.getId()); |
| | | sysOrder.getItems().forEach(sysOrderItem -> { |
| | | sysOrderItem.setOrderId(sysOrder.getId()); |
| | | orderItemDao.insert(sysOrderItem); |
| | | }); |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | //保存单据日志 |
| | | operationLogService.saveOperation(sysOrder.getCompanyId(), sysOrder.getShopId(), user.getSuId(), |
| | | OperationFunctionEnum.ORDER, |
| | | OperationButtonEnum.UPDATE, |
| | | sysOrder.getId(), |
| | | sysOrder.getOrderNo(), |
| | | sysOrder.getVipId()); |
| | | |
| | | return sysOrder; |
| | | } |
| | | |
| | | /** |
| | | * 创建充值订单 |
| | | * @param czVo |
| | | * @return |
| | | */ |
| | | public SysOrder createCzOrder(CzXkVo czVo){ |
| | | |
| | | MoneyCardUse cardUser = moneyCardUseDao.selectVipCard(czVo.getVipId()); |
| | | |
| | | SysOrder order= new SysOrder(); |
| | | order.setFlows(czVo.getFlows()); |
| | | order.setVipId(czVo.getVipId()); |
| | | order.setRemark(cardUser.getCardName()); |
| | | |
| | | SysOrderItem orderItem = new SysOrderItem(); |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectVipCzGoods(); |
| | | orderItem.setGoodsId(shoppingGoods.getId()); |
| | | orderItem.setType(Dictionary.SHOPPING_GOODS_TYPE_CZK); |
| | | orderItem.setCount(1); |
| | | orderItem.setIsFree(Dictionary.FLAG_NO); |
| | | orderItem.setZkPrice(czVo.getBjmoney()); |
| | | orderItem.setAchieveList(czVo.getAchaeveList()); |
| | | order.setItems(Arrays.asList(orderItem)); |
| | | saveOrder(order); |
| | | return order; |
| | | } |
| | | |
| | | /** |
| | | * 创建退款订单 |
| | | * @return |
| | | */ |
| | | public SysOrder createTkOrder(SysOrder sysOrder){ |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | //原订单设置为退款状态 |
| | | SysOrder sourceOrder = new SysOrder(); |
| | | sourceOrder.setId(sysOrder.getOldOrderId()); |
| | | sourceOrder.setIsHasRefund(SysOrder.IS_HAS_REFUND_Y); |
| | | sysOrderDao.update(sourceOrder); |
| | | |
| | | sysOrder.setId(null); |
| | | sysOrder.setStaffId(user.getSuId()); |
| | | sysOrder.setCompanyId(user.getCompanyId()); |
| | | sysOrder.setShopId(user.getShopId()); |
| | | sysOrder.setOrderType(SysOrder.ORDER_TYPE_REFUND); |
| | | sysOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | Date now = new Date(); |
| | | sysOrder.setOrderTime(now); |
| | | sysOrder.setPayTime(now); |
| | | sysOrder.setOrderNo(codeService.getRefundOrderNo()); |
| | | sysOrder.setZkTotal(-sysOrder.getZkTotal()); |
| | | |
| | | double cardPayTotal = 0D; |
| | | double cashPayTotal = 0D; |
| | | for (SysOrderFlow flow : sysOrder.getFlows()) { |
| | | // 若使用储值卡付款 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | cardPayTotal += flow.getAmount().doubleValue(); |
| | | } else { |
| | | cashPayTotal += flow.getAmount().doubleValue(); |
| | | } |
| | | } |
| | | sysOrder.setCardPay(0-( sourceOrder.getCardPay() == null ? 0 : sourceOrder.getCardPay() + cardPayTotal)); |
| | | sysOrder.setCashPay(0-(sourceOrder.getCashPay() == null ? 0 : sourceOrder.getCashPay() + cashPayTotal)); |
| | | |
| | | |
| | | //新增订单 |
| | | sysOrderDao.insert(sysOrder); |
| | | //插入明细 |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | |
| | | //更新原订单明细的可退数量 |
| | | SysOrderItem oldItem = orderItemDao.selectById(item.getId()); |
| | | if((oldItem.getRefundCount()+item.getCount()) <= oldItem.getCount()){ |
| | | oldItem.setRefundCount(oldItem.getRefundCount()+item.getCount()); |
| | | orderItemDao.update(oldItem); |
| | | }else{ |
| | | throw new GlobleException("退款数量大于购买数量"); |
| | | } |
| | | //插入新的订单明细 |
| | | item.setCount(-item.getCount()); |
| | | item.setZkPrice(-item.getZkPrice()); |
| | | item.setOrderId(sysOrder.getId()); |
| | | orderItemDao.insert(item); |
| | | } |
| | | LogUtil.info("创建退款订单:{} " , JSON.toJSONString(sysOrder) ) ; |
| | | return sysOrder; |
| | | } |
| | | |
| | | /** |
| | | * 退款入库 |
| | | */ |
| | | public void refundInstore(@NotEmpty List<SysOrderItem> items) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | SysSupplierInfo supplierInfo = new SysSupplierInfo(); |
| | | supplierInfo.setShopId(user.getShopId()); |
| | | supplierInfo = sysSupplierInfoDao.selectByModel(supplierInfo).get(0); |
| | | |
| | | Warehouse warehouse = warehouseDao.findShopWarehouse(user.getShopId()).get(0); |
| | | SysInstoreInfo instoreInfo = new SysInstoreInfo(); |
| | | instoreInfo.setInstoreType(SysInstoreInfo.INSTORE_TYPE_RETURN); |
| | | instoreInfo.setInstoreDate(new Date()); |
| | | instoreInfo.setSupplierId(supplierInfo.getId().toString()); |
| | | instoreInfo.setStoreId(warehouse.getId()); |
| | | instoreInfo.setShopId(user.getShopId()); |
| | | instoreInfo.setCompanyId(user.getCompanyId()); |
| | | |
| | | Double total = 0.0; |
| | | List<SysInstoreDetail> instoreDetails = new ArrayList<>(); |
| | | for (SysOrderItem item : items) { |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | SysInstoreDetail sysInstoreDetail = new SysInstoreDetail(); |
| | | sysInstoreDetail.setAmount(item.getCount().doubleValue()); |
| | | sysInstoreDetail.setPrice(item.getZkPrice()); |
| | | sysInstoreDetail.setSkuId(goods.getId()); |
| | | |
| | | total = MoneyUtil.add(MoneyUtil.mul(Double.parseDouble(sysInstoreDetail.getAmount() + ""), sysInstoreDetail.getPrice()), total); |
| | | sysInstoreDetail.setInstoreId(instoreInfo.getId()); |
| | | // 设置小计 |
| | | sysInstoreDetail.setPriceTotal(MoneyUtil.mul(Double.parseDouble(sysInstoreDetail.getAmount() + ""), sysInstoreDetail.getPrice())); |
| | | instoreDetails.add(sysInstoreDetail); |
| | | |
| | | } |
| | | instoreInfo.setInstoreDetails(instoreDetails); |
| | | instoreInfo.setSumall(total); |
| | | |
| | | sysInstoreInfoService.add(instoreInfo); |
| | | //自动审核单据 |
| | | sysInstoreInfoService.check(instoreInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | } |