|  |  |  | 
|---|
|  |  |  | 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.dto.OrderListDto; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysInstoreInfoService sysInstoreInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | BusParameterSettingsDao parameterSettingsDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${evn}") | 
|---|
|  |  |  | private String evn; | 
|---|
|  |  |  | 
|---|
|  |  |  | // 删除收款记录 | 
|---|
|  |  |  | sysOrderFlowDao.deleteByOrderId(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除积分 | 
|---|
|  |  |  | scoreVipDetailService.removeByBusinessId(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()); | 
|---|
|  |  |  | if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | cashScore[0] = cashPayAmount.divide(scoreSetting0).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(cashConsumption.getParamValue1())){ | 
|---|
|  |  |  | BigDecimal scoreSetting1 = new BigDecimal(cashConsumption.getParamValue1()); | 
|---|
|  |  |  | if(scoreSetting1.compareTo(BigDecimal.ZERO)>0){ | 
|---|
|  |  |  | cashScore[1]= cashPayAmount.divide(scoreSetting1).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(cashConsumption.getParamValue2())){ | 
|---|
|  |  |  | BigDecimal scoreSetting2 = new BigDecimal(cashConsumption.getParamValue2()); | 
|---|
|  |  |  | if(scoreSetting2.compareTo(BigDecimal.ZERO)>0){ | 
|---|
|  |  |  | cashScore[2]= cashPayAmount.divide(scoreSetting2).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int [] cardScore={0,0,0}; | 
|---|
|  |  |  | //储值卡本金支付金额 | 
|---|
|  |  |  | BigDecimal cardPayAmount=flows.stream() | 
|---|
|  |  |  | .filter(item->item.getPayMethod().equals("储值卡")&&item.getIsGift().equals("N")) | 
|---|
|  |  |  | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BusParameterSettings principalBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); | 
|---|
|  |  |  | if(cardPayAmount!=null | 
|---|
|  |  |  | &&cardPayAmount.compareTo(BigDecimal.ZERO)>0 | 
|---|
|  |  |  | &&StringUtils.isNotBlank(principalBalanceConsumption.getParamValue())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal scoreSetting0 = new BigDecimal(principalBalanceConsumption.getParamValue()); | 
|---|
|  |  |  | if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | cardScore[0] = cardPayAmount.divide(scoreSetting0).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue1())){ | 
|---|
|  |  |  | BigDecimal scoreSetting1 = new BigDecimal(principalBalanceConsumption.getParamValue1()); | 
|---|
|  |  |  | if(scoreSetting1.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | cardScore[1] = cardPayAmount.divide(scoreSetting1).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(principalBalanceConsumption.getParamValue2())){ | 
|---|
|  |  |  | BigDecimal scoreSetting2 = new BigDecimal(principalBalanceConsumption.getParamValue2()); | 
|---|
|  |  |  | if(scoreSetting2.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | cardScore[2] = cardPayAmount.divide(scoreSetting2).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int [] giftScore={0,0,0}; | 
|---|
|  |  |  | //储值卡本赠送付金额 | 
|---|
|  |  |  | BigDecimal giftPayAmount=flows.stream() | 
|---|
|  |  |  | .filter(item->item.getPayMethod().equals("储值卡")&&item.getIsGift().equals("Y")) | 
|---|
|  |  |  | .map(SysOrderFlow::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); | 
|---|
|  |  |  | BusParameterSettings bonusBalanceConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION, vipInfo.getCompanyId()); | 
|---|
|  |  |  | if(giftPayAmount!=null | 
|---|
|  |  |  | &&giftPayAmount.compareTo(BigDecimal.ZERO)>0 | 
|---|
|  |  |  | &&StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue())){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal scoreSetting0 = new BigDecimal(bonusBalanceConsumption.getParamValue()); | 
|---|
|  |  |  | if(scoreSetting0.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | giftScore[0] = giftPayAmount.divide(scoreSetting0).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue1())){ | 
|---|
|  |  |  | BigDecimal scoreSetting1 = new BigDecimal(bonusBalanceConsumption.getParamValue1()); | 
|---|
|  |  |  | if(scoreSetting1.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | giftScore[1] = giftPayAmount.divide(scoreSetting1).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(bonusBalanceConsumption.getParamValue2())){ | 
|---|
|  |  |  | BigDecimal scoreSetting2 = new BigDecimal(bonusBalanceConsumption.getParamValue2()); | 
|---|
|  |  |  | if(scoreSetting2.compareTo(BigDecimal.ZERO)>0) { | 
|---|
|  |  |  | giftScore[2] = giftPayAmount.divide(scoreSetting2).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int selfScore=cashScore[0]+cardScore[0]+giftScore[0]; | 
|---|
|  |  |  | int parentScore=cashScore[1]+cardScore[1]+giftScore[1]; | 
|---|
|  |  |  | int topParentScore=cashScore[2]+cardScore[2]+giftScore[2]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //添加自己的积分 | 
|---|
|  |  |  | if(selfScore>0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore( | 
|---|
|  |  |  | vipInfo.getId(), | 
|---|
|  |  |  | pageOrder.getStaffId(), | 
|---|
|  |  |  | pageOrder.getShopId(), | 
|---|
|  |  |  | selfScore, | 
|---|
|  |  |  | pageOrder.getId(), | 
|---|
|  |  |  | ScoreVipDetail.SCORE_VIP_TYPE_CASH, | 
|---|
|  |  |  | "消费奖励" | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(vipInfo.getRecommendId()!=null){ | 
|---|
|  |  |  | //推荐注册老带新积分奖励 | 
|---|
|  |  |  | SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId()); | 
|---|
|  |  |  | if(parentScore>0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore( | 
|---|
|  |  |  | referrerVip.getId(), | 
|---|
|  |  |  | pageOrder.getStaffId(), | 
|---|
|  |  |  | pageOrder.getShopId(), | 
|---|
|  |  |  | parentScore, | 
|---|
|  |  |  | pageOrder.getId(), | 
|---|
|  |  |  | ScoreVipDetail.SCORE_VIP_TYPE_CASH, | 
|---|
|  |  |  | "推荐消费奖励" | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //推荐注册二级带新积分奖励 | 
|---|
|  |  |  | if(referrerVip.getRecommendId()!=null){ | 
|---|
|  |  |  | SysVipInfo topVipInfo = sysVipInfoDao.selectById(referrerVip.getRecommendId()); | 
|---|
|  |  |  | if(topParentScore>0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore( | 
|---|
|  |  |  | topVipInfo.getId(), | 
|---|
|  |  |  | pageOrder.getStaffId(), | 
|---|
|  |  |  | pageOrder.getShopId(), | 
|---|
|  |  |  | topParentScore, | 
|---|
|  |  |  | pageOrder.getId(), | 
|---|
|  |  |  | ScoreVipDetail.SCORE_VIP_TYPE_CASH, | 
|---|
|  |  |  | "推荐消费奖励" | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | ShoppingGoods goods = shoppingGoodsDao.selectById(goodsId); | 
|---|
|  |  |  | flow.setFlowContent(goods.getName() + "等" + sourceOrder.getItems().size() + "件产品"); | 
|---|
|  |  |  | // 若是退款,则取负数 | 
|---|
|  |  |  | if (Dictionary.ORDER_STATU_TK.equals(sourceOrder.getStatu())) { | 
|---|
|  |  |  | if (SysOrder.ORDER_TYPE_REFUND== sourceOrder.getOrderType()) { | 
|---|
|  |  |  | flow.setFlowType(SysOrderFlow.FLOW_TYPE_REFUND); | 
|---|
|  |  |  | flow.setAmount(flow.getAmount().negate()); | 
|---|
|  |  |  | flow.setOrderId(sourceOrder.getOldOrderId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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() + "库存不足】"); | 
|---|
|  |  |  | //计算库存总数是否满足本次扣减的需求 | 
|---|
|  |  |  | 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("出库失败没有找到出库产品"); | 
|---|
|  |  |  | } 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("不管理库存"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | orderItem.setPrice(czVo.getBjmoney()); | 
|---|
|  |  |  | orderItem.setStatus(Dictionary.ORDER_STATU_YFK); | 
|---|
|  |  |  | orderItem.setAchieveList(czVo.getAchaeveList()); | 
|---|
|  |  |  | orderItem.setShoppingGoods(shoppingGoods); | 
|---|
|  |  |  | orderItemDao.insert(orderItem); | 
|---|
|  |  |  | List<SysOrderItem> items = new ArrayList<>(); | 
|---|
|  |  |  | items.add(orderItem); | 
|---|
|  |  |  | 
|---|
|  |  |  | moneyCardUseFlowDao.insert(moneyCardUseFlow); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | order.setFlows(czVo.getFlows()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | addOrderFlow(order); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 添加员工业绩 | 
|---|
|  |  |  | achieveNewService.addAchaeveByOrder(order); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return order; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.setPayTime(now); | 
|---|
|  |  |  | sysOrder.setOrderNo(codeService.getRefundOrderNo()); | 
|---|
|  |  |  | sysOrder.setZkTotal(-sysOrder.getZkTotal()); | 
|---|
|  |  |  | sysOrder.setOrderType(SysOrder.ORDER_TYPE_REFUND); | 
|---|
|  |  |  | //新增订单 | 
|---|
|  |  |  | sysOrderDao.insert(sysOrder); | 
|---|
|  |  |  | //插入明细 | 
|---|
|  |  |  | 
|---|
|  |  |  | addOrderFlow(sysOrder); | 
|---|
|  |  |  | //退款退套餐退项目 | 
|---|
|  |  |  | refundProjUse(sysOrder); | 
|---|
|  |  |  | //删除积分 | 
|---|
|  |  |  | scoreVipDetailService.removeByBusinessId(oldOrder.getVipId(), oldOrder.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置业绩 | 
|---|
|  |  |  | achieveNewService.addAchaeveByOrder(sysOrder); | 
|---|
|  |  |  | 
|---|
|  |  |  | shoppingGoodsDao.update(goods); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 家居产品退库存 | 
|---|
|  |  |  | if (CollectionUtils.isNotEmpty(returnGoodsList)) { | 
|---|
|  |  |  | refundInstore(returnGoodsList); | 
|---|
|  |  |  | BusParameterSettings manageStockSetting = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WAREHOUSE_MANAGE_STOCK, sysOrder.getCompanyId()); | 
|---|
|  |  |  | if(AppConstance.IS_Y.equals(manageStockSetting.getParamValue())){ | 
|---|
|  |  |  | // 家居产品退库存 | 
|---|
|  |  |  | if (CollectionUtils.isNotEmpty(returnGoodsList)) { | 
|---|
|  |  |  | refundInstore(returnGoodsList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|