src/main/java/cc/mrbird/febs/common/enumerates/StarRatingEnum.java
@@ -63,6 +63,34 @@ return code; } /** * 获取商品可以设置的最小价格 * @return */ public Integer getMinValue(){ Integer totalMinvalue = 0; for(StarRatingEnum starRatingEnum : StarRatingEnum.values()){ if(starRatingEnum.minValue < totalMinvalue){ totalMinvalue = starRatingEnum.minValue; } } return totalMinvalue; } /** * 获取商品可以设置的最大价格 * @return */ public Integer getMaxValue(){ Integer totalMaxValue = 0; for(StarRatingEnum starRatingEnum : StarRatingEnum.values()){ if(starRatingEnum.maxValue > totalMaxValue){ totalMaxValue = starRatingEnum.maxValue; } } return totalMaxValue; } public static void main(String[] args) { String s = StarRatingEnum.NORMAL.belongStarRating(String.valueOf(100)); System.out.println(s); src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java
@@ -19,10 +19,6 @@ @ApiModelProperty(value = "商品ID", example = "1") private Long goodsId; @NotNull(message = "参数不能为空") @ApiModelProperty(value = "地址ID", example = "1") private Long addressId; @ApiModelProperty(value = "门店ID", example = "1") private Long shopId; @@ -37,8 +33,5 @@ @ApiModelProperty(value = "配送方式 1:快递寄送2:到店自提") private Integer deliverType; @ApiModelProperty(value = "商品明细") private List<AddOrderItemDto> items; } src/main/java/cc/mrbird/febs/mall/dto/MallGoodsQueryDto.java
@@ -40,4 +40,7 @@ @ApiModelProperty(value = "1-付费商品 2-积分商品") private Integer goodsType; @ApiModelProperty(value = " 1 :普通 | 2:一星 3:二星| 4:三星") private Integer starRating; } src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -112,15 +112,22 @@ //新增商品 MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto); mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED); //根据商品原价获取商品星级 String originalPrice = mallGoods.getOriginalPrice(); String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice); //根据商品现价获取商品星级 String presentPrice = mallGoods.getPresentPrice(); Integer minValue = StarRatingEnum.NORMAL.getMinValue(); Integer maxValue = StarRatingEnum.NORMAL.getMaxValue(); if(new BigDecimal(presentPrice).compareTo(new BigDecimal(minValue)) < 0 || new BigDecimal(presentPrice).compareTo(new BigDecimal(maxValue)) > 0){ return new FebsResponse().fail().message("商品现价不能小于"+ minValue + "不能大于" + maxValue); } String starRating = StarRatingEnum.NORMAL.belongStarRating(presentPrice); mallGoods.setStarRating(starRating); //根据商品原价获取商品补贴金额 //根据商品现价获取商品补贴金额 DataDictionaryCustom subsidyPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SUBSIDY_PERCENT.getType() , DataDictionaryEnum.SUBSIDY_PERCENT.getCode()); BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(originalPrice)).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(presentPrice)).setScale(2, BigDecimal.ROUND_DOWN); mallGoods.setSubsidyAmount(subsidyAmount); // if (mallGoods.getHasCarriage() == 2) { // mallGoods.setCarriage(BigDecimal.ZERO); @@ -356,15 +363,23 @@ // if (mallGoods.getHasCarriage() == 2) { // mallGoods.setCarriage(BigDecimal.ZERO); // } //根据商品原价获取商品星级 String originalPrice = mallGoods.getOriginalPrice(); String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice); //根据商品现价获取商品星级 String presentPrice = mallGoods.getPresentPrice(); Integer minValue = StarRatingEnum.NORMAL.getMinValue(); Integer maxValue = StarRatingEnum.NORMAL.getMaxValue(); if(new BigDecimal(presentPrice).compareTo(new BigDecimal(minValue)) < 0 || new BigDecimal(presentPrice).compareTo(new BigDecimal(maxValue)) > 0){ return new FebsResponse().fail().message("商品现价不能小于"+ minValue + "不能大于" + maxValue); } String starRating = StarRatingEnum.NORMAL.belongStarRating(presentPrice); mallGoods.setStarRating(starRating); //根据商品原价获取商品补贴金额 //根据商品现价获取商品补贴金额 DataDictionaryCustom subsidyPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SUBSIDY_PERCENT.getType() , DataDictionaryEnum.SUBSIDY_PERCENT.getCode()); BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(originalPrice)).setScale(2, BigDecimal.ROUND_DOWN); BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(presentPrice)).setScale(2, BigDecimal.ROUND_DOWN); mallGoods.setSubsidyAmount(subsidyAmount); mallGoodsMapper.updateById(mallGoods); src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -99,6 +99,9 @@ if(memberLevelCode < goodsStarCode){ throw new FebsException("会员等级不够"); } if (MallGoods.ISSALE_STATUS_DISABLED.equals(goods.getIsSale())) { throw new FebsException(goods.getGoodsName() + "已下架"); } /** * 会员一天最多下单次数 */ @@ -114,102 +117,32 @@ throw new FebsException("会员今日已无法购买"); } // MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); // if (address == null) { // throw new FebsException("地址不存在"); // } String orderNo = MallUtils.getOrderNum(); MallOrderInfo orderInfo = new MallOrderInfo(); orderInfo.setOrderNo(orderNo); orderInfo.setOrderTime(new Date()); orderInfo.setMemberId(member.getId()); orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue()); // orderInfo.setName(address.getName()); // orderInfo.setAddress(address.getArea() + address.getAddress()); // orderInfo.setPhone(address.getPhone()); // orderInfo.setLatitude(address.getLatitude()); // orderInfo.setLongitude(address.getLongitude()); orderInfo.setRemark(addOrderDto.getRemark()); orderInfo.setOrderType(addOrderDto.getOrderType()); //补贴金额 orderInfo.setSubsidyAmount(goods.getSubsidyAmount()); if (CollUtil.isEmpty(addOrderDto.getItems())) { throw new FebsException("参数错误"); } // int deliverType = ObjectUtil.isEmpty(addOrderDto.getDeliverType()) ? 1 : addOrderDto.getDeliverType(); // if(2 == deliverType){ // if(ObjectUtil.isEmpty(addOrderDto.getShopId())){ // throw new FebsException("请选择门店"); // } // Long shopId = addOrderDto.getShopId(); // MallShopApply mallShopApply = mallShopApplyMapper.selectById(shopId); // if(ObjectUtil.isEmpty(mallShopApply)){ // throw new FebsException("请选择门店"); // } // if(MallShopApply.APPLY_AGREE != mallShopApply.getStatus()){ // throw new FebsException("请选择门店"); // } // orderInfo.setShopId(shopId); // } this.baseMapper.insert(orderInfo); BigDecimal total = BigDecimal.ZERO; BigDecimal carriage = BigDecimal.ZERO; for (AddOrderItemDto item : addOrderDto.getItems()) { MallOrderItem orderItem = new MallOrderItem(); // 积分商品提交订单 if (addOrderDto.getOrderType() == 2) { MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId()); if (mallGoods.getStock() < item.getCnt()) { throw new FebsException(mallGoods.getGoodsName() + "库存不足"); } if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { throw new FebsException(mallGoods.getGoodsName() + "已下架"); } BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt())); orderItem.setAmount(amount); orderItem.setCnt(item.getCnt()); orderItem.setOrderId(orderInfo.getId()); orderItem.setPrice(mallGoods.getScore()); orderItem.setGoodsId(mallGoods.getId()); orderItem.setGoodsName(mallGoods.getGoodsName()); orderItem.setStyleName(mallGoods.getGoodsName()); orderItem.setSkuName(mallGoods.getGoodsName()); orderItem.setSkuImage(mallGoods.getThumb()); total = total.add(amount); } else { MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); List<MallGoodsSku> mallGoodsSkus = mallGoodsSkuMapper.selectSkuByGoodsId(goods.getId()); for (MallGoodsSku sku : mallGoodsSkus) { MallOrderItem orderItem = new MallOrderItem(); if (sku == null) { throw new FebsException("购买商品或sku不存在"); } if (sku.getStock() < item.getCnt()) { if (sku.getStock() < 1) { throw new FebsException(sku.getSkuName() + "库存不足"); } MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); // 零撸专区购买 if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); if (CollUtil.isNotEmpty(items)) { throw new FebsException("无法重复领取同一个商品"); } } if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { throw new FebsException(mallGoods.getGoodsName() + "已下架"); } BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(1)); orderItem.setAmount(amount); orderItem.setCnt(item.getCnt()); orderItem.setCnt(1); orderItem.setOrderId(orderInfo.getId()); orderItem.setPrice(sku.getPresentPrice()); orderItem.setGoodsId(sku.getGoodsId()); @@ -218,31 +151,20 @@ orderItem.setStyleName(sku.getStyleName()); orderItem.setSkuName(sku.getSkuName()); orderItem.setSkuImage(sku.getSkuImage()); orderItem.setIsNormal(mallGoods.getIsNormal()); orderItem.setIsNormal(goods.getIsNormal()); orderItem.setCostPrice(sku.getCostPrice()); total = total.add(amount); carriage = carriage.add(mallGoods.getCarriage()); sku.setStock(sku.getStock() - item.getCnt()); sku.setSkuVolume(sku.getSkuVolume() + item.getCnt()); sku.setStock(sku.getStock() - 1); sku.setSkuVolume(sku.getSkuVolume() + 1); mallGoodsSkuMapper.updateById(sku); if (addOrderDto.getType() == 1) { mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); } } mallOrderItemMapper.insert(orderItem); mallOrderItemMapper.insert(orderItem); } orderInfo.setAmount(total); // if(2 == deliverType){ // orderInfo.setDeliverType(2); // orderInfo.setCarriage(BigDecimal.ZERO); // }else{ // orderInfo.setDeliverType(1); // orderInfo.setCarriage(carriage); // } BigDecimal presentPrice = new BigDecimal(goods.getPresentPrice()).setScale(2,BigDecimal.ROUND_DOWN); orderInfo.setAmount(presentPrice); this.baseMapper.updateById(orderInfo); agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); src/main/resources/mapper/modules/MallGoodsMapper.xml
@@ -96,6 +96,18 @@ <if test="record.goodsType == 3"> and a.present_price = 0 </if> <if test="record.starRating == 1"> and a.star_rating = '普通' </if> <if test="record.starRating == 2"> and a.star_rating = '一星' </if> <if test="record.starRating == 3"> and a.star_rating = '二星' </if> <if test="record.starRating == 4"> and a.star_rating = '三星' </if> <if test="record.categoryId != null and record.categoryId != ''"> and (c.id = #{record.categoryId} or c.parent_id=#{record.categoryId}) </if> src/main/resources/templates/febs/views/modules/goods/goodsAddNew.html
@@ -14,8 +14,8 @@ <div class="layui-tab-content"> <div class="layui-tab-item layui-show"> <blockquote class="layui-elem-quote blue-border">基本信息设置</blockquote> <div class="layui-form-mid layui-word-aux">商品新增后,会自动计算补贴金额,按商品原价的5%计算</div> <div class="layui-form-mid layui-word-aux">商品新增后,会自动计算星级等级,按商品原价设置</div> <div class="layui-form-mid layui-word-aux">商品新增后,会自动计算补贴金额,按商品现价计算</div> <div class="layui-form-mid layui-word-aux">商品新增后,会自动计算星级等级,按商品现价设置</div> <div class="layui-row layui-col-space10 layui-form-item"> <div class="layui-col-lg6"> <label class="layui-form-label febs-form-item-require">商品名称:</label> @@ -181,7 +181,6 @@ <label class="layui-form-label febs-form-item-require">现价:</label> <div class="layui-input-block"> <input type="text" name="presentPrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> <div class="layui-form-mid layui-word-aux">现价设置为0进入零撸专区</div> </div> </div> </div> @@ -212,7 +211,7 @@ <div class="layui-col-lg6"> <label class="layui-form-label">开启多规格:</label> <div class="layui-input-block"> <input type="radio" name="isSku" value="1" title="是" lay-filter="isSku" /> <!-- <input type="radio" name="isSku" value="1" title="是" lay-filter="isSku" />--> <input type="radio" name="isSku" value="2" title="否" lay-filter="isSku" checked /> </div> </div> src/main/resources/templates/febs/views/modules/goods/goodsUpdateNew.html
@@ -235,8 +235,8 @@ <div class="layui-col-lg6"> <label class="layui-form-label">开启多规格:</label> <div class="layui-input-block"> <input type="radio" name="isSku" value="1" title="是" lay-filter="isSku"/> <!-- <input type="radio" name="isSku" value="1" title="是"--> <!-- lay-filter="isSku"/>--> <input type="radio" name="isSku" value="2" title="否" lay-filter="isSku" checked/> </div>