|  |  |  | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 取消订单 | 
|---|
|  |  |  | order.setStatu(Dictionary.ORDER_STATU_YQX); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return sysOrderDao.update(order); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); | 
|---|
|  |  |  | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); | 
|---|
|  |  |  | // 若是退款,则取负数 | 
|---|
|  |  |  | if (SysOrder.ORDER_TYPE_REFUND==sourceOrder.getOrderType()) { | 
|---|
|  |  |  | if (Dictionary.ORDER_STATU_TK.equals(sourceOrder.getStatu())) { | 
|---|
|  |  |  | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); | 
|---|
|  |  |  | flow.setAmount(flow.getAmount().negate()); | 
|---|
|  |  |  | flow.setOrderId(sourceOrder.getOldOrderId()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 | 
|---|