| | |
| | | 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.StringUtils; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.core.tools.*; |
| | | import com.matrix.system.app.dto.ShoppingGoodsListDto; |
| | | import com.matrix.system.app.vo.ShoppingGoodsDetailVo; |
| | | import com.matrix.system.app.vo.ShoppingGoodsListVo; |
| | | import com.matrix.system.common.bean.SysUsers; |
| | | import com.matrix.system.common.dao.UtilDao; |
| | | import com.matrix.system.common.tools.ServiceUtil; |
| | | import com.matrix.system.constance.Dictionary; |
| | | import com.matrix.system.constance.TableMapping; |
| | | import com.matrix.system.hive.bean.MoneyCardAssemble; |
| | | import com.matrix.system.hive.bean.ShoppingGoods; |
| | | import com.matrix.system.hive.bean.ShoppingGoodsAssemble; |
| | | import com.matrix.system.hive.bean.ShoppingGoodsCategory; |
| | | import com.matrix.system.hive.bean.SysShopInfo; |
| | | import com.matrix.system.hive.dao.MoneyCardAssembleDao; |
| | | import com.matrix.system.hive.dao.ShoppingGoodsAssembleDao; |
| | | import com.matrix.system.hive.dao.ShoppingGoodsDao; |
| | | import com.matrix.system.hive.dao.SysShopInfoDao; |
| | | import com.matrix.system.hive.plugin.message.StringUtil; |
| | | import com.matrix.system.hive.dao.*; |
| | | import com.matrix.system.hive.dto.GoodsSealLimitDto; |
| | | import com.matrix.system.hive.dto.SysOrderItemDto; |
| | | import com.matrix.system.hive.service.ShoppingGoodsService; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.awt.event.WindowStateListener; |
| | | import java.time.LocalDate; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | @Autowired |
| | | private SysShopInfoDao shopInfoDao; |
| | | |
| | | @Autowired |
| | | private SysOrderItemDao orderItemDao; |
| | | |
| | | @Override |
| | | public void checkGoodsSealLimit(GoodsSealLimitDto goodsSealLimitDto) { |
| | | LogUtil.info("开始检测商品销售限制:{}", goodsSealLimitDto.toString()); |
| | | //校验参数不能为空 |
| | | checkGoodsSelLimtParam(goodsSealLimitDto); |
| | | |
| | | goodsSealLimitDto.getSysOrderItemDtoList().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.equals(maxNum)) { |
| | | if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) { |
| | | shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN); |
| | | shoppingGoodsDao.update(shopGoods); |
| | | LogUtil.info("商品达到最大销售数量自动下架:{}", shopGoods.getName()); |
| | | } |
| | | } else if ((buyNum + item.getCount()) > maxNum) { |
| | | throw new GlobleException(shopGoods.getName() + "已超过最大销售数量"); |
| | | } |
| | | } |
| | | //每人限购次数检测 |
| | | Integer onceCount = shopGoods.getIsOnce(); |
| | | if (onceCount != null && onceCount != 0) { |
| | | Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(), goodsSealLimitDto.getVipId()); |
| | | if ((buyOnceCount + item.getCount()) > onceCount) { |
| | | throw new GlobleException(shopGoods.getName() + "每人限购" + onceCount + "次"); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void checkGoodsSelLimtParam(GoodsSealLimitDto goodsSealLimitDto) { |
| | | ParamCheckUtil.requireNonNulls(goodsSealLimitDto, |
| | | goodsSealLimitDto.getVipId(), |
| | | goodsSealLimitDto.getSysOrderItemDtoList()); |
| | | |
| | | |
| | | ParamCheckUtil.requireListElementNonNull(goodsSealLimitDto.getSysOrderItemDtoList(), |
| | | Arrays.asList(SysOrderItemDto::getCount, SysOrderItemDto::getGoodsId)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | SysShopInfo shopInfo = shopInfoDao.selectById(sysUsers.getShopId()); |
| | | |
| | | |
| | | |
| | | if(shopInfo.getShopType()==SysShopInfo.SHOP_TYPE_ZONGBU){ |
| | | if (shopInfo.getShopType() == SysShopInfo.SHOP_TYPE_ZONGBU) { |
| | | shoppingGoods.setHeadquarters(1); |
| | | }else{ |
| | | } else { |
| | | shoppingGoods.setHeadquarters(2); |
| | | } |
| | | |
| | |
| | | shoppingGoods.setReferencePice(0D); |
| | | } |
| | | // 验证套餐卡卡必须填写最大使用次数 |
| | | if (Dictionary.FLAG_YES_Y.equals(shoppingGoods.getIsCourse())) { |
| | | if (Dictionary.FLAG_YES_Y.equals(shoppingGoods.getIsCourse()) && Dictionary.FLAG_NO_N.equals(shoppingGoods.getIsInfinite())) { |
| | | if (shoppingGoods.getCarUseCount() == null) { |
| | | shoppingGoods.setCarUseCount(0); |
| | | } |
| | |
| | | if (shoppingGoods.getReferencePice() == null) { |
| | | shoppingGoods.setReferencePice(0d); |
| | | } |
| | | shoppingGoods.setZjm(StringUtils.toHanyuPinyin(shoppingGoods.getName())+","+StringUtils.toHeadWordHanyuPinyin(shoppingGoods.getName())); |
| | | shoppingGoods.setZjm(StringUtils.toHanyuPinyin(shoppingGoods.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGoods.getName())); |
| | | shoppingGoods.setIsDel(ShoppingGoods.NORMAL); |
| | | //新增销售产品 |
| | | int i = shoppingGoodsDao.insert(shoppingGoods); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | return i; |
| | | } |
| | | |
| | | private void setShoppingGoodsInvalidTime(ShoppingGoods shoppingGoods) { |
| | | // 若未设置购买有效期和消耗有效期,则默认永久有效 |
| | | if (shoppingGoods.getBuyDateNum() == null && shoppingGoods.getUseDateNum() == null) { |
| | | shoppingGoods.setInvalidTime(DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD)); |
| | | } else { |
| | | // 计算失效日期,判断购买有效期和消耗有效期哪个先失效,则为失效日期 |
| | | Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); |
| | | Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); |
| | | if (buyValidDate.after(useValidDate)) { |
| | | shoppingGoods.setInvalidTime(useValidDate); |
| | | } else { |
| | | shoppingGoods.setInvalidTime(buyValidDate); |
| | | } |
| | | // if (shoppingGoods.getBuyDateNum() == null && shoppingGoods.getUseDateNum() == null) { |
| | | // shoppingGoods.setInvalidTime(DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD)); |
| | | // } else { |
| | | // // 计算失效日期,判断购买有效期和消耗有效期哪个先失效,则为失效日期 |
| | | // Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); |
| | | // Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); |
| | | // if (buyValidDate.after(useValidDate)) { |
| | | // shoppingGoods.setInvalidTime(useValidDate); |
| | | // } else { |
| | | // shoppingGoods.setInvalidTime(buyValidDate); |
| | | // } |
| | | // shoppingGoods.setBuyValid(shoppingGoods.getBuyDateNum() + shoppingGoods.getBuyDateUnit()); |
| | | // shoppingGoods.setUseValid(shoppingGoods.getUseDateNum() + shoppingGoods.getUseDateUnit()); |
| | | // } |
| | | |
| | | if (shoppingGoods.getBuyDateNum() != null && StringUtils.isNotBlank(shoppingGoods.getBuyDateUnit())) { |
| | | shoppingGoods.setBuyValid(shoppingGoods.getBuyDateNum() + shoppingGoods.getBuyDateUnit()); |
| | | } else { |
| | | shoppingGoods.setBuyValid(null); |
| | | } |
| | | |
| | | if (shoppingGoods.getUseDateNum() != null && StringUtils.isNotBlank(shoppingGoods.getUseDateUnit())) { |
| | | shoppingGoods.setUseValid(shoppingGoods.getUseDateNum() + shoppingGoods.getUseDateUnit()); |
| | | } else { |
| | | shoppingGoods.setUseValid(null); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_CZK.equals(shoppingGoods.getGoodType())) { |
| | | setCardAssemble(shoppingGoods); |
| | | }else{ |
| | | } else { |
| | | |
| | | //清除原有绑定关系 |
| | | shoppingGoodsAssembleDao.deleteByGoodsId(shoppingGoods.getId()); |
| | | //合并绑定的产品和项目 |
| | | List<ShoppingGoodsAssemble> assembles = new ArrayList<>(); |
| | | if(CollectionUtils.isNotEmpty(shoppingGoods.getAssembleGoods())){ |
| | | if (CollectionUtils.isNotEmpty(shoppingGoods.getAssembleGoods())) { |
| | | assembles.addAll(shoppingGoods.getAssembleGoods()); |
| | | } |
| | | //如果是套餐叠加套餐绑定的项目部分 |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(shoppingGoods.getGoodType())){ |
| | | if (Dictionary.SHOPPING_GOODS_TYPE_TC.equals(shoppingGoods.getGoodType())) { |
| | | assembles.addAll(shoppingGoods.getAssembleProj()); |
| | | } |
| | | |
| | |
| | | case Dictionary.SHOPPING_GOODS_TYPE_TC: |
| | | shoppingGoods.setIsAssemble(Dictionary.FLAG_YES); |
| | | break; |
| | | case Dictionary.SHOPPING_GOODS_TYPE_ZHK: |
| | | shoppingGoods.setIsAssemble(Dictionary.FLAG_YES); |
| | | break; |
| | | } |
| | | } |
| | | |
| | |
| | | shoppingGoods.setWeiImg(Dictionary.DEFAULT_IMG); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | return shoppingGoodsDao.selectByModelData(shoppingGoods); |
| | | } |
| | | |
| | | /** |
| | | * 计算失效时间 |
| | | * |
| | | * @param shoppingGoods |
| | | * @param type 1 - 购买时 2 - 消耗时 |
| | | * @param buyDate 购买日期, 当计算消耗日期时,不能为空 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Date calInvalidTime(ShoppingGoods shoppingGoods, @NotNull Integer type, Date buyDate) { |
| | | if (StringUtils.isBlank(shoppingGoods.getBuyValid()) && StringUtils.isBlank(shoppingGoods.getUseValid()) && shoppingGoods.getInvalidTime() == null) { |
| | | return DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); |
| | | } |
| | | |
| | | if (type == 2 && shoppingGoods.getUseDateNum() == null && StringUtils.isNotBlank(shoppingGoods.getBuyDateUnit())) { |
| | | return DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); |
| | | } |
| | | |
| | | if (type == 2 && buyDate == null) { |
| | | throw new GlobleException("购买日期不能为空"); |
| | | } |
| | | |
| | | Date target = null; |
| | | Date buyValidDate = null; |
| | | if (type == 1) { |
| | | buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit()); |
| | | } else { |
| | | buyValidDate = buyDate; |
| | | } |
| | | |
| | | Date useValidDate = DateUtil.stringToDate("2099-12-31", DateUtil.DATE_FORMAT_DD); |
| | | if (type == 2) { |
| | | useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit()); |
| | | } |
| | | |
| | | if (buyValidDate.after(useValidDate)) { |
| | | target = useValidDate; |
| | | } else { |
| | | target = buyValidDate; |
| | | } |
| | | |
| | | if (shoppingGoods.getInvalidTime() != null) { |
| | | if (target.after(shoppingGoods.getInvalidTime())) { |
| | | target = shoppingGoods.getInvalidTime(); |
| | | } |
| | | } |
| | | return target; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<ShoppingGoodsListVo> findShoppingGoodsListForApi(ShoppingGoodsListDto shoppingGoodsListDto) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | shoppingGoodsListDto.setShopId(user.getShopId()); |
| | | PaginationVO pageVo = new PaginationVO(); |
| | | int offset = (shoppingGoodsListDto.getPageNum() - 1) * shoppingGoodsListDto.getPageSize(); |
| | | int limit = shoppingGoodsListDto.getPageSize(); |
| | | pageVo.setOffset(offset); |
| | | pageVo.setLimit(limit); |
| | | return shoppingGoodsDao.selectShoppingGoodsApiInPage(shoppingGoodsListDto, pageVo); |
| | | } |
| | | |
| | | @Override |
| | | public int findShoppingGoodsListTotalForApi(ShoppingGoodsListDto shoppingGoodsListDto) { |
| | | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | shoppingGoodsListDto.setShopId(user.getShopId()); |
| | | |
| | | return shoppingGoodsDao.selectShopppingGoodsAipTotal(shoppingGoodsListDto); |
| | | } |
| | | |
| | | @Override |
| | | public ShoppingGoodsDetailVo findApiShoppingGoodsDetailById(Long id) { |
| | | ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(id); |
| | | ShoppingGoodsDetailVo goodsDetailVo = goodsToGoodsDetailVo(shoppingGoods); |
| | | |
| | | if (ShoppingGoods.SHOPPING_GOODS_TYPE_TC.equals(shoppingGoods.getGoodType())) { |
| | | List<ShoppingGoodsDetailVo> products = shoppingGoodsAssembleDao.selectGoodsRelationGoodsList(shoppingGoods.getId(), ShoppingGoods.SHOPPING_GOODS_TYPE_JJCP); |
| | | List<ShoppingGoodsDetailVo> proj = shoppingGoodsAssembleDao.selectGoodsRelationGoodsList(shoppingGoods.getId(), ShoppingGoods.SHOPPING_GOODS_TYPE_XM); |
| | | |
| | | goodsDetailVo.setAssembleTaocanProduct(products); |
| | | goodsDetailVo.setAssembleTaocanProj(proj); |
| | | } else if (ShoppingGoods.SHOPPING_GOODS_TYPE_XM.equals(shoppingGoods.getGoodType())) { |
| | | List<ShoppingGoodsDetailVo> products = shoppingGoodsAssembleDao.selectGoodsRelationGoodsList(shoppingGoods.getId(), null); |
| | | goodsDetailVo.setAssembleProj(products); |
| | | } else if (ShoppingGoods.SHOPPING_GOODS_TYPE_CZK.equals(shoppingGoods.getGoodType())) { |
| | | List<ShoppingGoodsDetailVo> cardGoods = moneyCardAssembleDao.selectCardRelationGoods(shoppingGoods.getId()); |
| | | List<ShoppingGoodsCategory> cardCategory = moneyCardAssembleDao.selectCardRelationCategory(shoppingGoods.getId()); |
| | | |
| | | goodsDetailVo.setAssembleProj(cardGoods); |
| | | goodsDetailVo.setCardCategory(cardCategory); |
| | | } |
| | | return goodsDetailVo; |
| | | } |
| | | |
| | | private ShoppingGoodsDetailVo goodsToGoodsDetailVo(ShoppingGoods shoppingGoods) { |
| | | ShoppingGoodsDetailVo goodsDetailVo = new ShoppingGoodsDetailVo(); |
| | | goodsDetailVo.setImg(shoppingGoods.getImg()); |
| | | goodsDetailVo.setGoodsName(shoppingGoods.getName()); |
| | | goodsDetailVo.setGoodsNo(shoppingGoods.getCode()); |
| | | goodsDetailVo.setGoodsType(shoppingGoods.getGoodType()); |
| | | goodsDetailVo.setDesc(shoppingGoods.getDescription()); |
| | | goodsDetailVo.setMaxSaleCnt(shoppingGoods.getCarMaxSaleCount()); |
| | | goodsDetailVo.setLimitBuyCnt(shoppingGoods.getIsOnce()); |
| | | goodsDetailVo.setMaxUseCnt(shoppingGoods.getCarUseCount()); |
| | | goodsDetailVo.setMeasure(shoppingGoods.getMeasure()); |
| | | goodsDetailVo.setVolume(shoppingGoods.getVolume()); |
| | | goodsDetailVo.setSalePrice(BigDecimal.valueOf(shoppingGoods.getSealPice())); |
| | | goodsDetailVo.setSaleCnt(shoppingGoods.getRealSealCount()); |
| | | goodsDetailVo.setGiftPrice(BigDecimal.valueOf(shoppingGoods.getReferencePice() == null ? 0 : shoppingGoods.getReferencePice())); |
| | | return goodsDetailVo; |
| | | } |
| | | } |