|  |  | 
 |  |  |         //检查交易限制调整 | 
 |  |  |         checkSealLimit(pageOrder); | 
 |  |  |  | 
 |  |  |         //交易业绩设置是否合理 | 
 |  |  |         checkAchieveIsOk(pageOrder); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // 更新收款时间 | 
 |  |  |         pageOrder.setPayTime(new Date()); | 
 |  |  | 
 |  |  |      * 检查产品销售次数 | 
 |  |  |      */ | 
 |  |  |     private void checkSealLimit(SysOrder pageOrder) { | 
 |  |  |          pageOrder.getItems().forEach(item->{ | 
 |  |  |              ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); | 
 |  |  |         pageOrder.getItems().forEach(item->{ | 
 |  |  |             ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId()); | 
 |  |  |  | 
 |  |  |              //最大销售次数检测 | 
 |  |  |              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()); | 
 |  |  |             //最大销售次数检测 | 
 |  |  |             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+"次"); | 
 |  |  |                  } | 
 |  |  |              } | 
 |  |  |                 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("划扣业绩不等于储值卡扣款金额,请修改业绩设置!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 设置会员消费积分 | 
 |  |  | 
 |  |  |  | 
 |  |  |         //添加自己的积分 | 
 |  |  |         if(selfScore>0){ | 
 |  |  |                 scoreVipDetailService.addScore( | 
 |  |  |                         vipInfo.getId(), | 
 |  |  |                         pageOrder.getStaffId(), | 
 |  |  |                         pageOrder.getShopId(), | 
 |  |  |                         selfScore, | 
 |  |  |                         pageOrder.getId(), | 
 |  |  |                         ScoreVipDetail.SCORE_VIP_TYPE_CASH, | 
 |  |  |                         "消费奖励" | 
 |  |  |                 ); | 
 |  |  |             scoreVipDetailService.addScore( | 
 |  |  |                     vipInfo.getId(), | 
 |  |  |                     pageOrder.getStaffId(), | 
 |  |  |                     pageOrder.getShopId(), | 
 |  |  |                     selfScore, | 
 |  |  |                     pageOrder.getId(), | 
 |  |  |                     ScoreVipDetail.SCORE_VIP_TYPE_CASH, | 
 |  |  |                     "消费奖励" | 
 |  |  |             ); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if(vipInfo.getRecommendId()!=null){ | 
 |  |  | 
 |  |  |             List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(sysOrderItem.getGoodsId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM); | 
 |  |  |             assembleList.forEach(item -> { | 
 |  |  |                 //TODO 补综合卡逻辑 | 
 |  |  |                 createProjuseByAssemble(order, sysOrderItem, item, null, null); | 
 |  |  |                 createProjuseByAssemble(order, sysOrderItem, item, null, null,null,0); | 
 |  |  |             }); | 
 |  |  |  | 
 |  |  |             //处理综合卡中包含的套餐 | 
 |  |  | 
 |  |  |      * 通过组合关系创建用户项目余次 | 
 |  |  |      */ | 
 |  |  |     private SysProjUse createProjuseByAssemble(SysOrder order, SysOrderItem sysOrderItem, | 
 |  |  |                                                ShoppingGoodsAssemble goodsAssemble, Long taocanId, Date failTime) { | 
 |  |  |                                                ShoppingGoodsAssemble goodsAssemble, Long taocanId, Date failTime,String source,int maxCount) { | 
 |  |  |         //计算折扣 | 
 |  |  |         Double zk = sysOrderItem.getZkPrice() / sysOrderItem.getPrice(); | 
 |  |  |  | 
 |  |  | 
 |  |  |         puse.setIsOver(Dictionary.DELETED_N); | 
 |  |  |         puse.setOrderItemId(sysOrderItem.getId()); | 
 |  |  |         puse.setProjId(goodsAssemble.getAssembleGoodId()); | 
 |  |  |         puse.setSurplusCount(goodsAssemble.getTotal()); | 
 |  |  |         puse.setSurplusCount(goodsAssemble.getTotal()==null?maxCount: goodsAssemble.getTotal()); | 
 |  |  |         puse.setDeductionNum(goodsAssemble.getDeductionNum()); | 
 |  |  |         puse.setProjName(goodsAssemble.getShoppingGoods().getName()); | 
 |  |  |         puse.setVipId(order.getVipId()); | 
 |  |  |         puse.setStatus(Dictionary.TAOCAN_STATUS_YX); | 
 |  |  |         puse.setTaocanId(taocanId); | 
 |  |  |         puse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM); | 
 |  |  |         puse.setSource(source); | 
 |  |  |  | 
 |  |  |         if (taocanId == null) { | 
 |  |  |             puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() * zk); | 
 |  |  |         } else { | 
 |  |  |             puse.setPrice(goodsAssemble.getPrice() * zk); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 赠送和打折后金额为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){ | 
 |  |  |         //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗 | 
 |  |  |         boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE); | 
 |  |  |         if(zsConsumeAchieve){ | 
 |  |  |             if(sysOrderItem.getPrice()<=0){ | 
 |  |  |                 //等于0取原价 | 
 |  |  |                 if (taocanId == null) { | 
 |  |  |                     puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() ); | 
 |  |  |                 } else { | 
 |  |  |                     puse.setPrice(goodsAssemble.getPrice()); | 
 |  |  |                 } | 
 |  |  |             }else{ | 
 |  |  |                 puse.setPrice(0D); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         }else{ | 
 |  |  |             puse.setPrice(0D); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         puse.setBalance(MoneyUtil.mul(puse.getPrice(), Double.valueOf(puse.getSurplusCount()))); | 
 |  |  |         puse.setFailTime(failTime); | 
 |  |  |         sysProjUseDao.insert(puse); | 
 |  |  | 
 |  |  |         //创建套餐绑定的项目 | 
 |  |  |         List<ShoppingGoodsAssemble> assembleList = shoppingGoodsAssembleDao.selectGoodsByShoppingGoodsIdAndType(projId, ShoppingGoods.SHOPPING_GOODS_TYPE_XM); | 
 |  |  |         for (ShoppingGoodsAssemble assemble : assembleList) { | 
 |  |  |             SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId(),taocanProjUse.getFailTime()); | 
 |  |  |             SysProjUse tempUse = createProjuseByAssemble(order, sysOrderItem, assemble, taocanProjUse.getId(),taocanProjUse.getFailTime(),taocanProjUse.getSource(),taocanShoppingGoods.getCarUseCount()); | 
 |  |  |             sumBanance += tempUse.getBalance(); | 
 |  |  |             surplusCount += tempUse.getSurplusCount(); | 
 |  |  |         } | 
 |  |  |         if (Dictionary.FLAG_NO_N.equals(taocanShoppingGoods.getIsCourse())) { | 
 |  |  |             //固定套餐,剩余次数等于绑定项目的次数 | 
 |  |  |             taocanProjUse.setSurplusCount(surplusCount); | 
 |  |  |             //合计套餐余额 | 
 |  |  |             taocanProjUse.setBalance(sumBanance); | 
 |  |  |         } else { | 
 |  |  |             //任选套餐剩余次数等于最大使用次数 | 
 |  |  |             taocanProjUse.setSurplusCount(taocanShoppingGoods.getCarUseCount()); | 
 |  |  |             taocanProjUse.setBalance(sysOrderItem.getZkPrice()); | 
 |  |  |         } | 
 |  |  |         //合计套餐余额 | 
 |  |  |         taocanProjUse.setBalance(sumBanance); | 
 |  |  |  | 
 |  |  |         sysProjUseDao.update(taocanProjUse); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     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())); | 
 |  |  |             return  order.getFlows().stream().allMatch(item -> SysOrderFlow.IS_GIFT_Y.equals(item.getIsGift()) | 
 |  |  |                     && item.getAmount().doubleValue() >0D); | 
 |  |  |         }else{ | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  | 
 |  |  |         sourceOrder.setIsHasRefund(SysOrder.IS_HAS_REFUND_Y); | 
 |  |  | //        sourceOrder.setStatu(Dictionary.ORDER_STATU_TK); | 
 |  |  |         sysOrderDao.update(sourceOrder); | 
 |  |  |         SysOrder oldOrder=sysOrderDao.selectById(   sysOrder.getOldOrderId()); | 
 |  |  |         SysOrder oldOrder=sysOrderDao.selectById(sysOrder.getOldOrderId()); | 
 |  |  |  | 
 |  |  |         sysOrder.setId(null); | 
 |  |  |         sysOrder.setStaffId(user.getSuId()); | 
 |  |  | 
 |  |  |  | 
 |  |  |                     int sub = sysProjUse.getSurplusCount() - item.getCount(); | 
 |  |  |                     if (sub < 0) { | 
 |  |  |                       throw new GlobleException("项目余次不足"); | 
 |  |  |                         throw new GlobleException("项目余次不足"); | 
 |  |  |                     }else if(sub==0){ | 
 |  |  |                         sysProjUse.setIsOver(Dictionary.FLAG_YES_Y); | 
 |  |  |                         sysProjUse.setStatus(Dictionary.TAOCAN_STATUS_WX); | 
 |  |  | 
 |  |  |                 List<SysProjUse> sysProjUses = sysProjUseDao.selectByModel(queryProjUse); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 for (int i = 0; i < item.getCount(); i++) { | 
 |  |  |                 for (int i = 0; i < sysProjUses.size(); i++) { | 
 |  |  |  | 
 |  |  |                     SysProjUse sysProjUse = sysProjUses.get(i); | 
 |  |  |                     sysProjUse.setIsOver(Dictionary.FLAG_YES_Y); |