| | |
| | | package com.matrix.system.hive.service.imp; |
| | | |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.exception.GlobleException; |
| | | import com.matrix.core.pojo.PaginationVO; |
| | | import com.matrix.core.tools.DateUtil; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.core.tools.WebUtil; |
| | |
| | | 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.constance.Dictionary; |
| | | import com.matrix.system.constance.SystemConstance; |
| | | import com.matrix.system.hive.bean.*; |
| | | import com.matrix.system.hive.dao.*; |
| | | import com.matrix.system.hive.hievEnum.PayMethodEnum; |
| | | 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.*; |
| | | import com.matrix.system.score.constant.ScoreSettingConstant; |
| | | import com.matrix.system.score.entity.ScoreVipDetail; |
| | | import com.matrix.system.score.service.ScoreVipDetailService; |
| | | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgParam; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.util.*; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @date 2016-07-03 20:53 |
| | |
| | | @Autowired |
| | | MoneyCardUseFlowDao moneyCardUseFlowDao; |
| | | |
| | | @Autowired |
| | | ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | @Autowired |
| | | SysVipLevelDao sysVipLevelDao; |
| | | |
| | |
| | | @Autowired |
| | | private SysInstoreInfoService sysInstoreInfoService; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao parameterSettingsDao; |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | |
| | | @Autowired |
| | | private RabiitMqTemplate rabiitMqTemplate; |
| | | |
| | | |
| | | @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"); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public SysOrder checkAndSaveOrder(SysOrder sysOrder) { |
| | | // 收款改变订单状态 |
| | | |
| | | // 计算订单折扣金额,收款情况下 计算订单总额 |
| | | double zkTotal = 0.0; |
| | |
| | | |
| | | // 订单欠款减去支付金额 设置实际欠款 |
| | | Double itemZkTotal = MoneyUtil.mul(item.getZkPrice(), Double.valueOf(item.getCount())); |
| | | zkTotal=MoneyUtil.add(zkTotal, itemZkTotal); |
| | | zkTotal = MoneyUtil.add(zkTotal, itemZkTotal); |
| | | item.setStatus(orderStatus); |
| | | } |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | sysOrder.setZkTotal(zkTotal); |
| | | sysOrder.setStatu(orderStatus); |
| | | sysOrder.setStaffId(user.getSuId()); |
| | | sysOrder.setCompanyId(user.getCompanyId()); |
| | | SysOrder source = null; |
| | | if (sysOrder.getId() != null) { |
| | | source = sysOrderDao.selectById(sysOrder.getId()); |
| | | } |
| | | sysOrder.setStaffId(source != null ? source.getStaffId() : user.getSuId()); |
| | | sysOrder.setCompanyId(source != null ? source.getCompanyId() : user.getCompanyId()); |
| | | |
| | | sysOrder.setPayTime(new Date()); |
| | | if(sysOrder.getId()==null){ |
| | | |
| | | if (sysOrder.getId() == null) { |
| | | //新增订单 |
| | | sysOrder.setOrderNo(codeService.getOrderCode()); |
| | | sysOrderDao.insert(sysOrder); |
| | | |
| | | }else{ |
| | | } else { |
| | | //更新订单 |
| | | sysOrderDao.update(sysOrder); |
| | | //删除原有订单明细 |
| | |
| | | |
| | | sysOrder.getItems().forEach(sysOrderItem -> { |
| | | sysOrderItem.setOrderId(sysOrder.getId()); |
| | | // 取负数 |
| | | sysOrderItem.setCount(-sysOrderItem.getCount()); |
| | | orderItemDao.insert(sysOrderItem); |
| | | // 调整回来 |
| | | sysOrderItem.setCount(-sysOrderItem.getCount()); |
| | | if (sysOrder.getStatu().equals(Dictionary.ORDER_STATU_TK)) { |
| | | // 取负数 |
| | | sysOrderItem.setCount(-sysOrderItem.getCount()); |
| | | orderItemDao.insert(sysOrderItem); |
| | | // 调整回来 |
| | | sysOrderItem.setCount(-sysOrderItem.getCount()); |
| | | } else { |
| | | orderItemDao.insert(sysOrderItem); |
| | | } |
| | | |
| | | }); |
| | | |
| | | return sysOrder; |
| | |
| | | |
| | | /** |
| | | * 取消订单 |
| | | * 本方法无法退回多次不同卡项收款的订单 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | order.setArrears(0D); |
| | | |
| | | //发送微信公众号提醒 |
| | | UniformMsgParam uniformMsgParam = new UniformMsgParam(order.getCompanyId(), UniformMsgParam.GZH_DDQX); |
| | | uniformMsgParam.put("orderId", order.getId()); |
| | | rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, uniformMsgParam.toJSONString()); |
| | | |
| | | return sysOrderDao.update(order); |
| | | |
| | | } else { |
| | |
| | | throw new GlobleException("订单已取消"); |
| | | } |
| | | |
| | | List<SysOrderItem> sysOrderItems = orderItemDao.selectByOrderId(id); |
| | | List<SysOrderFlow> flows = sysOrderFlowDao.selectByOrderId(id); |
| | | // 非现金收款退回扣卡余额 |
| | | for (SysOrderFlow flow : flows) { |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | |
| | | for (SysOrderItem orderItem : sysOrderItems) { |
| | | |
| | | //非现金收款退回扣卡余额 |
| | | if (StringUtils.isNotBlank(orderItem.getPayMethodDetail())) { |
| | | |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(Long.parseLong(orderItem.getPayMethodDetail())); |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); |
| | | MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); |
| | | |
| | | if (moneyCardUse != null) { |
| | | |
| | | // 根据订单明细判断是赠送金额购买还是本金购买 |
| | | |
| | | moneyCardUseFlow.setTotal(orderItem.getCardPay()); |
| | | moneyCardUse.setRealMoney(MoneyUtil.add(moneyCardUse.getRealMoney(), orderItem.getCardPay())); |
| | | //TODO 目前无法退回到具体的赠送金额还是本金 |
| | | moneyCardUseFlow.setTotal(flow.getAmount().doubleValue()); |
| | | if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) { |
| | | moneyCardUse.setGiftMoney(MoneyUtil.add(moneyCardUse.getGiftMoney(), flow.getAmount().doubleValue())); |
| | | } else { |
| | | moneyCardUse.setRealMoney(MoneyUtil.add(moneyCardUse.getRealMoney(), flow.getAmount().doubleValue())); |
| | | } |
| | | |
| | | if (!moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_YES_Y)) { |
| | | if(moneyCardUse.getLastCount()!=null) { |
| | | if (moneyCardUse.getLastCount() != null) { |
| | | moneyCardUse.setLastCount(moneyCardUse.getLastCount() + 1); |
| | | moneyCardUseFlow.setTimes(1); |
| | | } |
| | |
| | | moneyCardUseFlow.setCreateTime(new Date()); |
| | | moneyCardUseFlow.setOperationId(user.getSuId()); |
| | | moneyCardUseFlow.setContent(moneyCardUse.getChangeRemark()); |
| | | moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney()+moneyCardUse.getRealMoney()); |
| | | moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney() + moneyCardUse.getRealMoney()); |
| | | moneyCardUseFlowDao.insert(moneyCardUseFlow); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<SysOrderItem> sysOrderItems = orderItemDao.selectByOrderId(id); |
| | | for (SysOrderItem orderItem : sysOrderItems) { |
| | | // 充值卡类型退款 |
| | | 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()); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | AchieveNew achieveNew = new AchieveNew(); |
| | | achieveNew.setOrderId(id); |
| | | achieveNewService.removeByModel(achieveNew); |
| | | |
| | | // 删除收款记录 |
| | | sysOrderFlowDao.deleteByOrderId(id); |
| | | |
| | | //删除积分 |
| | | scoreVipDetailService.removeByBusinessId(order.getVipId(), order.getId()); |
| | | |
| | | // 取消订单 |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | return sysOrderDao.update(order); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | //获取折扣----- |
| | | Double zk = zk = 1.0; |
| | | //验证商品是否只购买了一次 |
| | | checkBuyOnce(car, info.getId()); |
| | | |
| | | SysOrder order = new SysOrder(); |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | |
| | | int count = 0; |
| | | // 设置订单条目 |
| | | for (ShoppingCarItem carItem : car.getCarItems()) { |
| | | // 检测最大销售数量 |
| | | checkIsArrivedMax(carItem); |
| | | |
| | | SysOrderItem orderItem = new SysOrderItem(); |
| | | orderItem.setOrderId(order.getId()); |
| | | orderItem.setCount(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 收款 |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateReceiptMoney(SysOrder pageOrder) throws GlobleException { |
| | | |
| | | |
| | | if (!Dictionary.ORDER_STATU_DFK.equals(pageOrder.getStatu())) { |
| | | throw new GlobleException("该订单已经收过款,请刷新页面再试!"); |
| | | } |
| | | |
| | | //检查交易限制调整 |
| | | checkSealLimit(pageOrder); |
| | | |
| | | //交易业绩设置是否合理 |
| | | checkAchieveIsOk(pageOrder); |
| | | |
| | | |
| | | // 更新收款时间 |
| | | pageOrder.setPayTime(new Date()); |
| | | pageOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | sysOrderDao.update(pageOrder); |
| | | |
| | | // 获取用户信息 |
| | | SysVipInfo vipInfo = sysVipInfoDao.selectById(pageOrder.getVipId()); |
| | |
| | | sysVipInfoDao.update(vipInfo); |
| | | } |
| | | |
| | | changeOrderStatu(pageOrder); |
| | | //添加支付流水 |
| | | addOrderFlow(pageOrder); |
| | | |
| | | // 设置会员充值卡使用情况 |
| | | addMoneyCardUse(pageOrder); |
| | | |
| | | // 新增出库单 |
| | | addOutStore(pageOrder); |
| | | |
| | | // 改变客户项目套餐使用情况 |
| | | addTaocanProj(pageOrder); |
| | | |
| | | // 新增出库单 |
| | | addOutStore(pageOrder); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(pageOrder); |
| | | |
| | | setShopSelCount(pageOrder); |
| | | |
| | | //设置会员积分 |
| | | addVipScore(pageOrder); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 收款改变订单状态,划扣金额 |
| | | * @author:姜友瑶 |
| | | * 检查产品销售次数 |
| | | */ |
| | | private void changeOrderStatu(SysOrder sourceOrder) { |
| | | int i = 1; |
| | | String orderStatus = Dictionary.ORDER_STATU_YFK; |
| | | String flowType = SysOrderFlow.FLOW_TYPE_BUY; |
| | | double cashPayTotal = 0D; |
| | | double cardPayTotal = 0D; |
| | | for (SysOrderFlow flow : sourceOrder.getFlows()) { |
| | | flow.setFlowNo(codeService.getFlowCode() + "-" + i); |
| | | Long goodsId = sourceOrder.getItems().get(0).getGoodsId(); |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); |
| | | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); |
| | | private void checkSealLimit(SysOrder pageOrder) { |
| | | pageOrder.getItems().forEach(item->{ |
| | | ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); |
| | | |
| | | if (Dictionary.ORDER_STATU_TK.equals(sourceOrder.getStatu())) { |
| | | flowType = SysOrderFlow.FLOW_TYPE_REFUND; |
| | | // 若是退款,则取负数 |
| | | flow.setAmount(flow.getAmount().negate()); |
| | | flow.setOrderId(sourceOrder.getOldOrderId()); |
| | | } else { |
| | | flow.setOrderId(sourceOrder.getId()); |
| | | //最大销售次数检测 |
| | | Integer maxNum = shopGoods.getCarMaxSaleCount(); |
| | | if (maxNum != null && maxNum != 0) { |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null); |
| | | if ((buyNum + item.getCount()) > maxNum) { |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); |
| | | } |
| | | if ((buyNum + item.getCount()) == maxNum) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | | shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN); |
| | | shoppingGoodsDao.update(shopGoods); |
| | | } |
| | | } |
| | | } |
| | | //每人限购次数检测 |
| | | Integer onceCount = shopGoods.getIsOnce(); |
| | | if(onceCount!=null && onceCount!=0){ |
| | | Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(),pageOrder.getVipId()); |
| | | |
| | | if ((buyOnceCount + item.getCount()) > onceCount) { |
| | | throw new GlobleException(shopGoods.getName() + "每人限购"+onceCount+"次"); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 交易业绩设置是否合理 |
| | | * @param pageOrder |
| | | */ |
| | | private void checkAchieveIsOk(SysOrder pageOrder) { |
| | | double huakouSum = pageOrder.getItems().stream() |
| | | .mapToDouble( |
| | | item -> |
| | | item.getAchieveList().stream() |
| | | .filter(achieveNew -> "划扣".equals(achieveNew.getPayMethod())) |
| | | .mapToDouble(achieve -> achieve.getGoodsCash()).sum() |
| | | ).sum(); |
| | | |
| | | double czkPay= pageOrder.getFlows().stream() |
| | | .filter(sysOrderFlow -> "储值卡".equals(sysOrderFlow.getPayMethod())) |
| | | .mapToDouble(sysOrderFlow ->sysOrderFlow.getAmount().doubleValue()).sum(); |
| | | |
| | | if(czkPay!=huakouSum){ |
| | | throw new GlobleException("划扣业绩不等于储值卡扣款金额,请修改业绩设置!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置会员消费积分 |
| | | * @param pageOrder |
| | | */ |
| | | private 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(); |
| | | } |
| | | |
| | | flow.setVipId(sourceOrder.getVipId()); |
| | | flow.setFlowType(flowType); |
| | | // 若使用储值卡付款 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); |
| | | cardPaySk(moneyCardUse, sourceOrder, flow); |
| | | cardPayTotal += flow.getAmount().doubleValue(); |
| | | 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 (SysOrderFlow.PAY_METHOD_ARREARS.equals(flow.getPayMethod())) { |
| | | orderStatus = Dictionary.ORDER_STATU_QK; |
| | | sourceOrder.setArrears(flow.getAmount().doubleValue()); |
| | | 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 (!SysOrderFlow.PAY_METHOD_ARREARS.equals(flow.getPayMethod()) && !SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | cashPayTotal += flow.getAmount().doubleValue(); |
| | | 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, |
| | | "推荐消费奖励" |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建支付流水 |
| | | * |
| | | * @author:姜友瑶 |
| | | */ |
| | | private void addOrderFlow(SysOrder sourceOrder) { |
| | | |
| | | |
| | | //处理支付流水 |
| | | int flowCount = 1; |
| | | for (SysOrderFlow flow : sourceOrder.getFlows()) { |
| | | //支付内容摘要设置 |
| | | Long goodsId = sourceOrder.getItems().get(0).getGoodsId(); |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); |
| | | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); |
| | | // 若是退款,则取负数 |
| | | if (SysOrder.ORDER_TYPE_REFUND== sourceOrder.getOrderType()) { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); |
| | | flow.setAmount(flow.getAmount().negate()); |
| | | flow.setOrderId(sourceOrder.getOldOrderId()); |
| | | } else { |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_BUY); |
| | | flow.setOrderId(sourceOrder.getId()); |
| | | } |
| | | |
| | | //欠款处理 |
| | | if (SysOrderFlow.PAY_METHOD_ARREARS.equals(flow.getPayMethod())) { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | sourceOrder.setArrears(flow.getAmount().doubleValue()); |
| | | sysOrderDao.update(sourceOrder); |
| | | } |
| | | |
| | | //统计储值卡支付 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); |
| | | //修改储值卡余额 |
| | | cardPaySk(moneyCardUse, sourceOrder, flow); |
| | | }else{ |
| | | throw new GlobleException("无效的储值卡支付方式"); |
| | | } |
| | | } |
| | | |
| | | flow.setFlowNo(codeService.getFlowCode() + "-" + flowCount); |
| | | flow.setVipId(sourceOrder.getVipId()); |
| | | flow.setShopId(sourceOrder.getShopId()); |
| | | flow.setCompanyId(sourceOrder.getCompanyId()); |
| | | sysOrderFlowDao.insert(flow); |
| | | i++; |
| | | flowCount++; |
| | | } |
| | | |
| | | if (Dictionary.ORDER_STATU_TK.equals(sourceOrder.getStatu())) { |
| | | orderStatus = Dictionary.ORDER_STATU_TK; |
| | | } |
| | | |
| | | // 更新收款状态 |
| | | sourceOrder.setStatu(orderStatus); |
| | | sourceOrder.setCardPay(cardPayTotal); |
| | | sourceOrder.setCashPay(cashPayTotal); |
| | | sysOrderDao.update(sourceOrder); |
| | | |
| | | } |
| | | |
| | |
| | | // 最大发卡数量为0代表不做限制 |
| | | if (maxNum != null && maxNum != 0) { |
| | | // 查询该商品已经被购买的次数 |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId()); |
| | | Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null); |
| | | buyNum = (buyNum == null ? 0 : buyNum); |
| | | if ((buyNum + carItem.getCount()) > maxNum) { |
| | | |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量,还剩【" + (maxNum - buyNum) + "】件"); |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); |
| | | } |
| | | if ((buyNum + carItem.getCount()) == maxNum) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | MoneyCardUseFlow moneyCardUseFlow=new MoneyCardUseFlow(); |
| | | MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); |
| | | if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) { |
| | | if(moneyCardUse.getGiftMoney() >= flow.getAmount().doubleValue()) { |
| | | if (moneyCardUse.getGiftMoney() >= flow.getAmount().doubleValue()) { |
| | | double surplus = MoneyUtil.sub(moneyCardUse.getGiftMoney(), flow.getAmount().doubleValue()); |
| | | moneyCardUse.setGiftMoney(surplus); |
| | | |
| | | moneyCardUseFlow.setGiftMoney(0D - flow.getAmount().doubleValue()); |
| | | } else { |
| | | throw new GlobleException(moneyCardUse.getCardName() + "余额不足"); |
| | | } |
| | | } else { |
| | | if(moneyCardUse.getRealMoney() >= flow.getAmount().doubleValue()) { |
| | | if (moneyCardUse.getRealMoney() >= flow.getAmount().doubleValue()) { |
| | | double surplus = MoneyUtil.sub(moneyCardUse.getRealMoney(), flow.getAmount().doubleValue()); |
| | | moneyCardUse.setRealMoney(surplus); |
| | | |
| | | moneyCardUseFlow.setTotal(0 - flow.getAmount().doubleValue()); |
| | | } else { |
| | | throw new GlobleException(moneyCardUse.getCardName() + "余额不足"); |
| | | } |
| | | } |
| | | |
| | | //设置卡项使用流水 |
| | | 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); |
| | | |
| | | // 达到使用次数后自动清空余额 |
| | | 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); |
| | | if (moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_NO_N)) { |
| | | //余额为0时充值卡变为无效 |
| | | 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()); |
| | |
| | | } |
| | | // 更新充值卡信息 |
| | | moneyCardUseDao.update(moneyCardUse); |
| | | //设置卡项使用流水 |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | return true; |
| | | } else { |
| | | // 不是一卡通, |
| | | // 判断卡是否可应用于所有产品 |
| | | ShoppingGoods cardGoods = shoppingGoodsDao.selectById(moneyCardUse.getGoodsId()); |
| | | if (cardGoods != null) { |
| | | if (Dictionary.FLAG_YES.equals(cardGoods.getCarIsAll())) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | // 比较分类 |
| | | MoneyCardAssemble moneyCardAssemble = new MoneyCardAssemble(); |
| | | moneyCardAssemble.setCardId(moneyCardUse.getGoodsId()); |
| | |
| | | // 如果购买的是充值卡 |
| | | if (sysOrderItem.getType().equals(Dictionary.SHOPPING_GOODS_TYPE_CZK)) { |
| | | |
| | | for(int i = 0; i < sysOrderItem.getCount(); i++) { |
| | | for (int i = 0; i < sysOrderItem.getCount(); i++) { |
| | | 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); |
| | | } |
| | | moneyCardUse.setIsVipCar(Dictionary.FLAG_NO_N); |
| | | moneyCardUse.setVipId(sourceOrder.getVipId()); |
| | | |
| | | // 是否为赠送 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_YES)) { |
| | |
| | | } else { |
| | | moneyCardUse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } |
| | | //余次处理 |
| | | if (moneyCar.getCarUseCount() == null || moneyCar.getCarUseCount() == 0) { |
| | | moneyCardUse.setUseTotal(999999999); |
| | | moneyCardUse.setLastCount(999999999); |
| | |
| | | moneyCardUse.setUseTotal(moneyCar.getCarUseCount()); |
| | | moneyCardUse.setLastCount(moneyCar.getCarUseCount()); |
| | | } |
| | | moneyCardUse.setVipId(sourceOrder.getVipId()); |
| | | |
| | | //失效时间处理 |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null); |
| | | moneyCardUse.setFailTime(invalidTime); |
| | | |
| | |
| | | i++; |
| | | } |
| | | |
| | | boolean haQk=false; |
| | | boolean haQk = false; |
| | | |
| | | if (refundTotal == pageOrder.getArrears()) { |
| | | haQk = true; |
| | | } |
| | | |
| | | //更新收款状态 |
| | | if(haQk){ |
| | | if (haQk) { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | }else{ |
| | | } else { |
| | | sourceOrder.setStatu(Dictionary.ORDER_STATU_QK); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao parameterSettingsDao; |
| | | |
| | | /** |
| | | * @param order 新增出库单并更新本店库存 |
| | |
| | | @Override |
| | | public void addOutStore(SysOrder order) { |
| | | |
| | | List<SysOutStoreItem> storeItemList = new ArrayList<>(); |
| | | BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, order.getCompanyId()); |
| | | if(AppConstance.IS_Y.equals(manageStockSetting.getParamValue())){ |
| | | |
| | | for (SysOrderItem sysOrderItem : order.getItems()) { |
| | | List<SysOutStoreItem> storeItemList = new ArrayList<>(); |
| | | |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP.equals(sysOrderItem.getType())) { |
| | | for (SysOrderItem sysOrderItem : order.getItems()) { |
| | | |
| | | SysOutStoreItem storeItem = new SysOutStoreItem(); |
| | | storeItem.setSkuId(sysOrderItem.getGoodsId()); |
| | | storeItem.setAmount(Double.valueOf(sysOrderItem.getCount())); |
| | | storeItemList.add(storeItem); |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP.equals(sysOrderItem.getType())) { |
| | | |
| | | } else if (ShoppingGoods.SHOPPING_GOODS_TYPE_TC.equals(sysOrderItem.getType()) |
| | | SysOutStoreItem storeItem = new SysOutStoreItem(); |
| | | storeItem.setSkuId(sysOrderItem.getGoodsId()); |
| | | storeItem.setAmount(Double.valueOf(sysOrderItem.getCount())); |
| | | storeItemList.add(storeItem); |
| | | |
| | | || ShoppingGoods.SHOPPING_GOODS_TYPE_ZHK.equals(sysOrderItem.getType())) { |
| | | } else if (ShoppingGoods.SHOPPING_GOODS_TYPE_TC.equals(sysOrderItem.getType()) |
| | | |
| | | List<ShoppingGoodsAssemble> goodsList = new ArrayList<>(); |
| | | || ShoppingGoods.SHOPPING_GOODS_TYPE_ZHK.equals(sysOrderItem.getType())) { |
| | | |
| | | goodsList.addAll(shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP)); |
| | | List<ShoppingGoodsAssemble> goodsList = new ArrayList<>(); |
| | | |
| | | 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.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); |
| | | }); |
| | | } |
| | | |
| | | 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); |
| | | 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<>(); |
| | | //出库明细,根据批次维度定义 |
| | | List<SysOutStoreItem> realOutStoreItemList = new ArrayList<>(); |
| | | |
| | | storeItemList.forEach(outStoreItem -> { |
| | | storeItemList.forEach(outStoreItem -> { |
| | | |
| | | //设置出库主键 |
| | | outStoreItem.setOutStoreId(outStore.getId()); |
| | | //设置出库主键 |
| | | 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("出库失败没有找到出库产品"); |
| | | //计算库存总数是否满足本次扣减的需求 |
| | | 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); |
| | | //循环获取所有批次产品,并扣减库存 |
| | | 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); |
| | | //每次扣减库存都创建一个出库记录 |
| | | 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); |
| | | storeInfoDao.update(storeInfo); |
| | | //扣除后剩余库存大于0则跳出扣除,否则剩余数量的负数的绝对值就是再次扣减的数量 |
| | | if (surplus > 0) { |
| | | break; |
| | | } else { |
| | | number = Math.abs(surplus); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | sysOutStoreItemDao.batchInsert(realOutStoreItemList); |
| | | }); |
| | | sysOutStoreItemDao.batchInsert(realOutStoreItemList); |
| | | } |
| | | |
| | | }else{ |
| | | LogUtil.debug("不管理库存"); |
| | | } |
| | | |
| | | |
| | |
| | | //综合卡中包含的项目 |
| | | List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM); |
| | | assembleList.forEach(item -> { |
| | | createProjuseByAssemble(order, sysOrderItem, item, null); |
| | | //TODO 补综合卡逻辑 |
| | | createProjuseByAssemble(order, sysOrderItem, item, null, null); |
| | | }); |
| | | |
| | | //处理综合卡中包含的套餐 |
| | |
| | | * 通过组合关系创建用户项目余次 |
| | | */ |
| | | private SysProjUse createProjuseByAssemble(SysOrder order, SysOrderItem sysOrderItem, |
| | | ShoppingGoodsAssemble goodsAssemble, Long taocanId) { |
| | | ShoppingGoodsAssemble goodsAssemble, Long taocanId, Date failTime) { |
| | | //计算折扣 |
| | | Double zk=sysOrderItem.getZkPrice()/sysOrderItem.getPrice(); |
| | | Double zk = sysOrderItem.getZkPrice() / sysOrderItem.getPrice(); |
| | | |
| | | SysProjUse puse = new SysProjUse(); |
| | | puse.setIsOver(Dictionary.DELETED_N); |
| | |
| | | puse.setTaocanId(taocanId); |
| | | puse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); |
| | | if (taocanId == null) { |
| | | puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() * zk ); |
| | | puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() * zk); |
| | | } else { |
| | | puse.setPrice(goodsAssemble.getPrice() * zk ); |
| | | 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); |
| | | //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗 |
| | | boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); |
| | | if(zsConsumeAchieve){ |
| | | if (taocanId == null) { |
| | | puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() ); |
| | | } else { |
| | | puse.setPrice(goodsAssemble.getPrice()); |
| | | } |
| | | }else{ |
| | | puse.setPrice(0D); |
| | | } |
| | | |
| | | |
| | | } |
| | | // 设置失效时间 |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(2200, 1, 1); |
| | | puse.setFailTime(cal.getTime()); |
| | | puse.setBalance(MoneyUtil.mul(puse.getPrice(), Double.valueOf(puse.getSurplusCount()))); |
| | | puse.setFailTime(failTime); |
| | | sysProjUseDao.insert(puse); |
| | | return puse; |
| | | } |
| | |
| | | taocanProjUse.setIsCourse(taocanShoppingGoods.getIsCourse()); |
| | | taocanProjUse.setIsInfinite(taocanShoppingGoods.getIsInfinite()); |
| | | // 赠送和打折后金额为0的都视为赠送项目 |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0) { |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0 && !isGiftMoneyPay(order)) { |
| | | taocanProjUse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | } else { |
| | | taocanProjUse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | |
| | | taocanProjUse.setFailTime(invalidTime); |
| | | sysProjUseDao.insert(taocanProjUse); |
| | | //计划次数 |
| | | int surplusCount=0; |
| | | 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()); |
| | | SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId(),taocanProjUse.getFailTime()); |
| | | sumBanance += tempUse.getBalance(); |
| | | surplusCount+=tempUse.getSurplusCount(); |
| | | surplusCount += tempUse.getSurplusCount(); |
| | | } |
| | | if(Dictionary.FLAG_NO_N.equals(taocanShoppingGoods.getIsCourse())){ |
| | | if (Dictionary.FLAG_NO_N.equals(taocanShoppingGoods.getIsCourse())) { |
| | | //固定套餐,剩余次数等于绑定项目的次数 |
| | | taocanProjUse.setSurplusCount(surplusCount); |
| | | }else{ |
| | | } else { |
| | | //任选套餐剩余次数等于最大使用次数 |
| | | taocanProjUse.setSurplusCount(taocanShoppingGoods.getCarUseCount()); |
| | | } |
| | |
| | | taocanProjUse.setBalance(sumBanance); |
| | | sysProjUseDao.update(taocanProjUse); |
| | | } |
| | | |
| | | @Autowired |
| | | private SysProjServicesService projServicesService; |
| | | |
| | | /** |
| | | * 根据订单创建用户项目使用情况 |
| | |
| | | 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) { |
| | | if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0 && !isGiftMoneyPay(order)) { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_GM); |
| | | puse.setPrice(sysOrderItem.getZkPrice()); |
| | | } else { |
| | | puse.setSource(Dictionary.TAOCAN_SOURCE_ZS); |
| | | //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗 |
| | | boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); |
| | | if(zsConsumeAchieve){ |
| | | puse.setPrice(sysOrderItem.getShoppingGoods().getSealPice()); |
| | | }else{ |
| | | puse.setPrice(0D); |
| | | } |
| | | |
| | | |
| | | } |
| | | // 设置失效时间 |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null); |
| | | puse.setFailTime(invalidTime); |
| | | puse.setBalance(sysOrderItem.getShoppingGoods().getSealPice()*puse.getSurplusCount()); |
| | | sysProjUseDao.insert(puse); |
| | | } |
| | | |
| | | /** |
| | | * 全是赠送金额,且配置了赠送金额购买计算为赠送 |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isGiftMoneyPay(SysOrder order) { |
| | | BusParameterSettings giftiIsfree = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.SHOP_MANAGE_GIFTISFREE, order.getCompanyId()); |
| | | if(giftiIsfree.getParamValue().equals("是")){ |
| | | return order.getFlows().stream().allMatch(item -> SysOrderFlow.IS_GIFT_Y.equals(item.getIsGift()) |
| | | && item.getAmount().doubleValue() >0D); |
| | | }else{ |
| | | return false; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员卡充值 |
| | | * |
| | | * @param czVo |
| | | */ |
| | | @Override |
| | |
| | | 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()); |
| | | // SysVipInfo vip = (SysVipInfo) WebUtil.getSession().getAttribute(SystemConstance.CURRENT_CUSTOMER); |
| | | // czVo.setVipId(vip.getId()); |
| | | |
| | | //更新会员会员卡金额 |
| | | MoneyCardUse cardUser = moneyCardUseDao.selectVipCard(vip.getId()); |
| | | MoneyCardUse cardUser = moneyCardUseDao.selectVipCard(czVo.getVipId()); |
| | | cardUser.setRealMoney(MoneyUtil.add(cardUser.getRealMoney(), czVo.getBjmoney())); |
| | | cardUser.setGiftMoney(MoneyUtil.add(cardUser.getGiftMoney(), czVo.getGiftMoney())); |
| | | moneyCardUseDao.update(cardUser); |
| | |
| | | order.setRemark(cardUser.getCardName()); |
| | | order.setStaffId(user.getSuId()); |
| | | order.setIsCross(2 + ""); |
| | | order.setOrderType(SysOrder.ORDER_TYPE_SEAL); |
| | | order.setStatu(Dictionary.ORDER_STATU_YFK); |
| | | order.setCompanyId(user.getCompanyId()); |
| | | sysOrderDao.insert(order); |
| | | |
| | | SysOrderItem orderItem = new SysOrderItem(); |
| | | orderItem.setOrderId(order.getId()); |
| | | orderItem.setOrderNo(order.getOrderNo()); |
| | | orderItem.setArrears(0D); |
| | | ShoppingGoods shoppingGoods= shoppingGoodsDao.selectVipCzGoods(); |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectVipCzGoods(); |
| | | orderItem.setGoodsId(shoppingGoods.getId()); |
| | | orderItem.setPayMethod(Dictionary.PAY_TYPE_MOENY); |
| | | orderItem.setCashPay(czVo.getBjmoney()); |
| | |
| | | orderItem.setIsFree(Dictionary.FLAG_NO); |
| | | orderItem.setPrice(czVo.getBjmoney()); |
| | | orderItem.setStatus(Dictionary.ORDER_STATU_YFK); |
| | | orderItem.setAchaeveList(czVo.getAchaeveList()); |
| | | orderItem.setAchieveList(czVo.getAchaeveList()); |
| | | orderItem.setShoppingGoods(shoppingGoods); |
| | | orderItemDao.insert(orderItem); |
| | | List<SysOrderItem> items = new ArrayList<>(); |
| | | items.add(orderItem); |
| | | order.setItems(items); |
| | | |
| | | |
| | | //设置卡项使用流水 |
| | | MoneyCardUseFlow moneyCardUseFlow=new MoneyCardUseFlow(); |
| | | MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); |
| | | moneyCardUseFlow.setTotal(czVo.getBjmoney()); |
| | | moneyCardUseFlow.setGiftMoney(czVo.getGiftMoney()); |
| | | moneyCardUseFlow.setCarUseId(czVo.getCardId()); |
| | |
| | | moneyCardUseFlow.setOrderNo(order.getOrderNo()); |
| | | moneyCardUseFlow.setCreateTime(new Date()); |
| | | moneyCardUseFlow.setOperationId(user.getSuId()); |
| | | moneyCardUseFlow.setBalance(cardUser.getGiftMoney()+cardUser.getRealMoney()); |
| | | moneyCardUseFlow.setBalance(cardUser.getGiftMoney() + cardUser.getRealMoney()); |
| | | moneyCardUseFlowDao.insert(moneyCardUseFlow); |
| | | |
| | | order.setFlows(czVo.getFlows()); |
| | | |
| | | addOrderFlow(order); |
| | | |
| | | // 添加员工业绩 |
| | | achieveNewService.addAchaeveByOrder(order); |
| | | |
| | | return order; |
| | | |
| | | } |
| | |
| | | return sysOrderDao.selectShopAchieveRanking(sysOrder); |
| | | } |
| | | |
| | | @Override |
| | | public List<RankingVo> findStaffSaleAchieveRanking(SysOrder sysOrder) { |
| | | return sysOrderDao.selectStaffSaleAchieveRanking(sysOrder); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void refundOrderMoney(SysOrder pageOrder) { |
| | | public void refundOrderMoney(SysOrder sysOrder) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | // 插入订单流水 |
| | | changeOrderStatu(pageOrder); |
| | | |
| | | List<SysOrderItem> returnItems = new ArrayList<>(); |
| | | for (SysOrderItem item : pageOrder.getItems()) { |
| | | //原订单设置为退款状态 |
| | | SysOrder sourceOrder=new SysOrder(); |
| | | sourceOrder.setId(sysOrder.getOldOrderId()); |
| | | sourceOrder.setIsHasRefund(SysOrder.IS_HAS_REFUND_Y); |
| | | // sourceOrder.setStatu(Dictionary.ORDER_STATU_TK); |
| | | sysOrderDao.update(sourceOrder); |
| | | SysOrder oldOrder=sysOrderDao.selectById( sysOrder.getOldOrderId()); |
| | | |
| | | 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()); |
| | | //新增订单 |
| | | sysOrderDao.insert(sysOrder); |
| | | //插入明细 |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | |
| | | //更新原订单明细的可退数量 |
| | | SysOrderItem oldItem=new SysOrderItem(); |
| | | oldItem.setId(item.getId()); |
| | | oldItem.setRefundCount(item.getCount()); |
| | | orderItemDao.update(oldItem); |
| | | |
| | | //插入新的订单明细 |
| | | item.setId(null); |
| | | item.setCount(-item.getCount()); |
| | | item.setOrderId(sysOrder.getId()); |
| | | orderItemDao.insert(item); |
| | | } |
| | | |
| | | |
| | | // 添加订单收款流水 |
| | | addOrderFlow(sysOrder); |
| | | //退款退套餐退项目 |
| | | refundProjUse(sysOrder); |
| | | //删除积分 |
| | | scoreVipDetailService.removeByBusinessId(oldOrder.getVipId(), oldOrder.getId()); |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(sysOrder); |
| | | |
| | | } |
| | | |
| | | private void addRefundOrderFlow(SysOrder sourceOrder) { |
| | | //处理支付流水 |
| | | int flowCount = 1; |
| | | for (SysOrderFlow flow : sourceOrder.getFlows()) { |
| | | //支付内容摘要设置 |
| | | Long goodsId = sourceOrder.getItems().get(0).getGoodsId(); |
| | | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); |
| | | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); |
| | | // 退款,则取负数 |
| | | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); |
| | | flow.setAmount(flow.getAmount().negate()); |
| | | flow.setOrderId(sourceOrder.getOldOrderId()); |
| | | |
| | | //统计储值卡支付 |
| | | if (SysOrderFlow.PAY_METHOD_CARD.equals(flow.getPayMethod())) { |
| | | if (flow.getCardId() != null) { |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectById(flow.getCardId()); |
| | | //修改储值卡余额 |
| | | cardPaySk(moneyCardUse, sourceOrder, flow); |
| | | }else{ |
| | | throw new GlobleException("无效的储值卡支付方式"); |
| | | } |
| | | } |
| | | |
| | | flow.setFlowNo(codeService.getFlowCode() + "-" + flowCount); |
| | | flow.setVipId(sourceOrder.getVipId()); |
| | | flow.setShopId(sourceOrder.getShopId()); |
| | | flow.setCompanyId(sourceOrder.getCompanyId()); |
| | | sysOrderFlowDao.insert(flow); |
| | | flowCount++; |
| | | } |
| | | } |
| | | |
| | | private void refundCard(MoneyCardUse moneyCardUse, SysOrder sourceOrder, SysOrderFlow flow) { |
| | | SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); |
| | | if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) { |
| | | if (moneyCardUse.getGiftMoney() >= flow.getAmount().doubleValue()) { |
| | | double surplus = MoneyUtil.sub(moneyCardUse.getGiftMoney(), flow.getAmount().doubleValue()); |
| | | moneyCardUse.setGiftMoney(surplus); |
| | | moneyCardUseFlow.setGiftMoney(0D - flow.getAmount().doubleValue()); |
| | | } else { |
| | | throw new GlobleException(moneyCardUse.getCardName() + "余额不足"); |
| | | } |
| | | } else { |
| | | if (moneyCardUse.getRealMoney() >= flow.getAmount().doubleValue()) { |
| | | double surplus = MoneyUtil.sub(moneyCardUse.getRealMoney(), flow.getAmount().doubleValue()); |
| | | moneyCardUse.setRealMoney(surplus); |
| | | moneyCardUseFlow.setTotal(0 - flow.getAmount().doubleValue()); |
| | | } else { |
| | | throw new GlobleException(moneyCardUse.getCardName() + "余额不足"); |
| | | } |
| | | } |
| | | |
| | | if (moneyCardUse.getIsVipCar().equals(Dictionary.FLAG_NO_N)) { |
| | | //余额为0时充值卡变为无效 |
| | | 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()); |
| | | if (shoppingGoods != null) { |
| | | Date invalidTime = shoppingGoodsService.calInvalidTime(shoppingGoods, 2, moneyCardUse.getFailTime()); |
| | | moneyCardUse.setFailTime(invalidTime); |
| | | } |
| | | // 更新充值卡信息 |
| | | moneyCardUseDao.update(moneyCardUse); |
| | | //设置卡项使用流水 |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 退款退项目,套餐,卡项 |
| | | * @param sysOrder |
| | | */ |
| | | private void refundProjUse(SysOrder sysOrder) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | |
| | | //记录需要退库存的产品 |
| | | List<SysOrderItem> returnGoodsList = new ArrayList<>(); |
| | | |
| | | for (SysOrderItem item : sysOrder.getItems()) { |
| | | |
| | | SysProjUse queryProjUse = new SysProjUse(); |
| | | queryProjUse.setIsOver(Dictionary.FLAG_NO_N); |
| | | queryProjUse.setStatus(Dictionary.TAOCAN_STATUS_YX); |
| | | queryProjUse.setOrderItemId(item.getOldItemId()); |
| | | // 修改项目信息 |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_XM.equals(item.getType()) || Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(item.getType())) { |
| | | |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(item.getType())) { |
| | | if (Dictionary.FLAG_YES_Y.equals(item.getIsReturnStore())) { |
| | | returnItems.add(item); |
| | | returnGoodsList.add(item); |
| | | } |
| | | } else { |
| | | SysProjUse sysProjUse = sysProjUseDao.selectByModel(queryProjUse).get(0); |
| | | |
| | | int sub = sysProjUse.getSurplusCount() - item.getCount(); |
| | | sysProjUse.setSurplusCount(sub); |
| | | if (sub <= 0) { |
| | | if (sub < 0) { |
| | | throw new GlobleException("项目余次不足"); |
| | | }else if(sub==0){ |
| | | sysProjUse.setIsOver(Dictionary.FLAG_YES_Y); |
| | | sysProjUse.setStatus(Dictionary.TAOCAN_STATUS_WX); |
| | | } |
| | | sysProjUse.setSurplusCount(sub); |
| | | sysProjUseDao.update(sysProjUse); |
| | | |
| | | SysProjUseFlow sysProjUseFlow = SysProjUseMapper.INSTANCE.projUseToFlow(sysProjUse); |
| | | sysProjUseFlow.setOptionType("退款修改"); |
| | | sysProjUseFlow.setId(null); |
| | |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(item.getType())) { |
| | | queryProjUse.setTaocanId(-1L); |
| | | List<SysProjUse> sysProjUses = sysProjUseDao.selectByModel(queryProjUse); |
| | | if (item.getCount() > sysProjUses.size()) { |
| | | throw new GlobleException("数据异常"); |
| | | } |
| | | |
| | | for(int i = 0; i < item.getCount(); i++) { |
| | | |
| | | for (int i = 0; i < item.getCount(); i++) { |
| | | |
| | | SysProjUse sysProjUse = sysProjUses.get(i); |
| | | sysProjUse.setIsOver(Dictionary.FLAG_YES_Y); |
| | | sysProjUse.setStatus(Dictionary.TAOCAN_STATUS_WX); |
| | | |
| | | sysProjUseDao.update(sysProjUse); |
| | | SysProjUseFlow sysProjUseFlow = SysProjUseMapper.INSTANCE.projUseToFlow(sysProjUse); |
| | | sysProjUseFlow.setOptionType("退款修改"); |
| | |
| | | |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(item.getType())) { |
| | | MoneyCardUse queryCardUse = new MoneyCardUse(); |
| | | queryCardUse.setIsOver(Dictionary.FLAG_NO_N); |
| | | queryCardUse.setStatus(Dictionary.TAOCAN_STATUS_YX); |
| | | queryCardUse.setOrderItemId(item.getOldItemId()); |
| | | |
| | | List<MoneyCardUse> moneyCardUses = moneyCardUseDao.selectByModel(queryCardUse); |
| | | for(int i = 0; i < item.getCount(); i++) { |
| | | for (int i = 0; i < item.getCount(); i++) { |
| | | MoneyCardUse moneyCardUse = moneyCardUses.get(i); |
| | | moneyCardUse.setIsOver(Dictionary.FLAG_YES_Y); |
| | | moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_WX); |
| | |
| | | shoppingGoodsDao.update(goods); |
| | | } |
| | | |
| | | // 家居产品退库存 |
| | | if (CollectionUtils.isNotEmpty(returnItems)) { |
| | | refundInstore(returnItems); |
| | | BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, sysOrder.getCompanyId()); |
| | | if(AppConstance.IS_Y.equals(manageStockSetting.getParamValue())){ |
| | | // 家居产品退库存 |
| | | if (CollectionUtils.isNotEmpty(returnGoodsList)) { |
| | | refundInstore(returnGoodsList); |
| | | } |
| | | } |
| | | |
| | | // 设置业绩 |
| | | achieveNewService.addAchaeveByOrder(pageOrder); |
| | | |
| | | } |
| | | |