| | |
| | | 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.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.common.dao.SysUsersDao; |
| | |
| | | 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 javax.servlet.http.HttpSession; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | @Autowired |
| | | MoneyCardUseFlowDao moneyCardUseFlowDao; |
| | | |
| | | @Autowired |
| | | ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | @Autowired |
| | | SysVipLevelDao sysVipLevelDao; |
| | | |
| | |
| | | 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()); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | // 删除收款记录 |
| | | sysOrderFlowDao.deleteByOrderId(id); |
| | | |
| | | //删除积分 |
| | | scoreVipDetailService.removeByBusinessId(null,order.getVipId(), order.getId()); |
| | | |
| | | // 取消订单 |
| | | order.setStatu(Dictionary.ORDER_STATU_YQX); |
| | | |
| | | |
| | | return sysOrderDao.update(order); |
| | | } |
| | | |
| | |
| | | |
| | | setShopSelCount(pageOrder); |
| | | |
| | | //设置会员积分 |
| | | addVipScore(pageOrder); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 设置会员消费积分 |
| | | * @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()); |
| | | cashScore[0]= cashPayAmount.divide(scoreSetting0).intValue(); |
| | | |
| | | if(StringUtils.isNotBlank(cashConsumption.getParamValue1())){ |
| | | BigDecimal scoreSetting1 = new BigDecimal(cashConsumption.getParamValue1()); |
| | | cashScore[1]= cashPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(cashConsumption.getParamValue2())){ |
| | | BigDecimal scoreSetting2 = new BigDecimal(cashConsumption.getParamValue2()); |
| | | 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()); |
| | | cardScore[0]= cardPayAmount.divide(scoreSetting0).intValue(); |
| | | |
| | | if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue1())){ |
| | | BigDecimal scoreSetting1 = new BigDecimal(principalBalanceConsumption.getParamValue1()); |
| | | cardScore[1]= cardPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue2())){ |
| | | BigDecimal scoreSetting2 = new BigDecimal(principalBalanceConsumption.getParamValue2()); |
| | | 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()); |
| | | giftScore[0]= giftPayAmount.divide(scoreSetting0).intValue(); |
| | | |
| | | if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue1())){ |
| | | BigDecimal scoreSetting1 = new BigDecimal(bonusBalanceConsumption.getParamValue1()); |
| | | giftScore[1]= giftPayAmount.divide(scoreSetting1).intValue(); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue2())){ |
| | | BigDecimal scoreSetting2 = new BigDecimal(bonusBalanceConsumption.getParamValue2()); |
| | | 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(null, |
| | | 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(null, |
| | | 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(null, |
| | | topVipInfo.getId(), |
| | | pageOrder.getStaffId(), |
| | | pageOrder.getShopId(), |
| | | topParentScore, |
| | | pageOrder.getId(), |
| | | ScoreVipDetail.SCORE_VIP_TYPE_CASH, |
| | | "推荐消费奖励" |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | addOrderFlow(sysOrder); |
| | | //退款退套餐退项目 |
| | | refundProjUse(sysOrder); |
| | | //删除积分 |
| | | scoreVipDetailService.removeByBusinessId(null,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 |