feat:优化涨价

This commit is contained in:
dzc committed 2026-03-29 21:37:23 +08:00
1 parent 4e5afdc272
commit 9317daa90d
15 files changed
+249 -170

No files matched your search

@@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
@@ -26,182 +27,184 @@ import java.time.LocalDateTime;
public class CanteenSpuEntity extends Model<CanteenSpuEntity> {
/**
* 商品 SPU 编号,自增
*/
/**
* 商品 SPU 编号,自增
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="商品 SPU 编号,自增")
@Schema(description = "商品 SPU 编号,自增")
private Long id;
/**
* 商品名称
*/
@Schema(description="商品名称")
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String name;
/**
* 商品简介
*/
@Schema(description="商品简介")
/**
* 商品简介
*/
@Schema(description = "商品简介")
private String introduction;
/**
* 商品详情
*/
@Schema(description="商品详情")
/**
* 商品详情
*/
@Schema(description = "商品详情")
private String description;
/**
* 商品分类编号
*/
@Schema(description="商品分类编号")
/**
* 商品分类编号
*/
@Schema(description = "商品分类编号")
private Long categoryId;
/**
* 商品封面图
*/
@Schema(description="商品封面图")
/**
* 商品封面图
*/
@Schema(description = "商品封面图")
private String picUrl;
/**
* 商品轮播图地址
数组,以逗号分隔
最多上传15张
*/
@Schema(description="商品轮播图")
/**
* 商品轮播图地址
* 数组,以逗号分隔
* 最多上传15张
*/
@Schema(description = "商品轮播图")
private String sliderPicUrls;
/**
* 排序字段
*/
@Schema(description="排序字段")
/**
* 排序字段
*/
@Schema(description = "排序字段")
private Integer sort;
/**
* 商品状态: 1 上架(开启) 0 下架(禁用) -1 回收
*/
@Schema(description="商品状态: 1 上架(开启) 0 下架(禁用) -1 回收")
/**
* 商品状态: 1 上架(开启) 0 下架(禁用) -1 回收
*/
@Schema(description = "商品状态: 1 上架(开启) 0 下架(禁用) -1 回收")
private Integer status;
/**
* 规格类型:0 单规格 1 多规格
*/
@Schema(description="规格类型:0 单规格 1 多规格")
/**
* 规格类型:0 单规格 1 多规格
*/
@Schema(description = "规格类型:0 单规格 1 多规格")
private Boolean specType;
/**
* 商品价格,单位使用:分
*/
@Schema(description="商品价格,单位使用:分")
/**
* 商品价格,单位使用:分
*/
@Schema(description = "商品价格,单位使用:分")
// @JsonSerialize(using = MoneySerializer.class) // 分 -> 元
// @JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer price;
/**
* 市场价,单位使用:分
*/
@Schema(description="市场价,单位使用:分")
/**
* 市场价,单位使用:分
*/
@Schema(description = "市场价,单位使用:分")
// @JsonSerialize(using = MoneySerializer.class) // 分 -> 元
// @JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer marketPrice;
/**
* 成本价,单位: 分
*/
@Schema(description="成本价,单位: 分")
/**
* 成本价,单位: 分
*/
@Schema(description = "成本价,单位: 分")
// @JsonSerialize(using = MoneySerializer.class) // 分 -> 元
// @JsonDeserialize(using = MoneyDeserializer.class) // 元 -> 分
private Integer costPrice;
/**
* 库存
*/
@Schema(description="库存")
/**
* 库存
*/
@Schema(description = "库存")
private Integer stock;
/**
* 赠送积分
*/
@Schema(description="赠送积分")
/**
* 赠送积分
*/
@Schema(description = "赠送积分")
private Integer giveIntegral;
/**
* 商品销量
*/
@Schema(description="商品销量")
/**
* 商品销量
*/
@Schema(description = "商品销量")
private Integer salesCount;
/**
* 虚拟销量
*/
@Schema(description="虚拟销量")
/**
* 虚拟销量
*/
@Schema(description = "虚拟销量")
private Integer virtualSalesCount;
/**
* 商品点击量
*/
@Schema(description="商品点击量")
/**
* 商品点击量
*/
@Schema(description = "商品点击量")
private Integer browseCount;
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "是否删除 -1:已删除 0:正常")
private String delFlag;
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "是否删除 -1:已删除 0:正常")
private String delFlag;
/**
* 系统类型 2每日 3在线订餐
*/
@Schema(description="系统类型 2每日 3在线订餐")
/**
* 系统类型 2每日 3在线订餐
*/
@Schema(description = "系统类型 2每日 3在线订餐")
private Long systemType;
/**
* 商户编号
*/
@Schema(description="商户编号")
/**
* 商户编号
*/
@Schema(description = "商户编号")
private Long merchantId;
/**
* 部门id
*/
@Schema(description="部门id")
/**
* 部门id
*/
@Schema(description = "部门id")
private Long deptId;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建人")
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 更新人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="更新人")
/**
* 更新人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新人")
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="更新时间")
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新时间")
private LocalDateTime updateTime;
/**
* 租户编号
*/
@Schema(description="租户编号")
/**
* 租户编号
*/
@Schema(description = "租户编号")
private Long tenantId;
@Schema(description="是否显示")
private String isShow;
@Schema(description = "是否显示")
private String isShow;
@Schema(description = "是否涨价")
private String isPriceIncreased;
}
@@ -1,5 +1,6 @@
package com.bsd.pjcloud.canteen.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@@ -44,4 +45,9 @@ public class ADCanteenDailyMenuListVO {
* 排序
*/
private Integer sort;
/**
* 是否涨价
*/
private String isPriceIncreased;
}
@@ -15,71 +15,72 @@ public class ADCanteenSpuListVO {
/**
* 商品 SPU 编号,自增
*/
@Schema(description="商品 SPU 编号,自增")
@Schema(description = "商品 SPU 编号,自增")
private Long id;
/**
* 商品名称
*/
@Schema(description="商品名称")
@Schema(description = "商品名称")
private String name;
/**
* 商品分类编号
*/
@Schema(description="商品分类编号")
@Schema(description = "商品分类编号")
private Long categoryId;
/**
* 商品封面图
*/
@Schema(description="商品封面图")
@Schema(description = "商品封面图")
private String picUrl;
/**
* 商品价格,单位使用:分
*/
@Schema(description="商品价格,单位使用:分")
@Schema(description = "商品价格,单位使用:分")
private Integer price;
/**
* 市场价,单位使用:分
*/
@Schema(description="市场价,单位使用:分")
@Schema(description = "市场价,单位使用:分")
private Integer marketPrice;
/**
* 库存
*/
@Schema(description="库存")
@Schema(description = "库存")
private Integer stock;
/**
* 商品销量
*/
@Schema(description="商品销量")
@Schema(description = "商品销量")
private Integer salesCount;
/**
* 商户编号
*/
@Schema(description="商户编号")
@Schema(description = "商户编号")
private Long merchantId;
/**
* 部门id
*/
@Schema(description="部门id")
@Schema(description = "部门id")
private Long deptId;
@Schema(description = "是否涨价")
private String isPriceIncreased;
@Schema(description="餐段类型")
@Schema(description = "餐段类型")
private String categoryType;
}
@@ -46,6 +46,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
private final CanteenCategoryMapper canteenCategoryMapper;
private final CanteenStockMapper canteenStockMapper;
private final CanteenOnlineSpuMapper canteenOnlineSpuMapper;
@Override
public Object selectFoodList(LambdaQueryWrapper<CanteenSpuEntity> wrapper) {
return baseMapper.selectListByScope(wrapper, DataScope.of());
@@ -59,11 +60,11 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
// 查询当前库存
CanteenSpuEntity spu = baseMapper.selectById(item.getId());
if (spu == null) {
R.failed(spu.getName()+"商品不存在");
R.failed(spu.getName() + "商品不存在");
}
// 检查库存是否足够
if (item.getIncrCount() < 0 && Math.abs(item.getIncrCount()) > spu.getStock()) {
R.failed(spu.getName()+"库存不足,无法完成操作");
R.failed(spu.getName() + "库存不足,无法完成操作");
}
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
// if (item.getIncrCount() <= 0) {
@@ -89,7 +90,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
Map<Long, List<CanteenCategoryEntity>> listMap = canteenCategoryEntities.stream().collect(Collectors.groupingBy(CanteenCategoryEntity::getId));
bean.forEach(item -> {
if (null!=listMap.get(item.getCategoryId()).get(0).getCategoryType()){
if (null != listMap.get(item.getCategoryId()).get(0).getCategoryType()) {
item.setCategoryType(listMap.get(item.getCategoryId()).get(0).getCategoryType());
}
});
@@ -127,7 +128,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
LambdaQueryWrapper<CanteenCategoryEntity> canteenCategoryEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
canteenCategoryEntityLambdaQueryWrapper.like(CanteenCategoryEntity::getCategoryType, canteenDailySpuDTO.getHourType());
List<CanteenCategoryEntity> canteenCategoryEntities = canteenCategoryMapper.selectList(canteenCategoryEntityLambdaQueryWrapper);
List<Long> caIds = canteenCategoryEntities.stream().map(CanteenCategoryEntity::getId).collect(Collectors.toList());
List<Long> caIds = canteenCategoryEntities.stream().map(CanteenCategoryEntity::getId).collect(Collectors.toList());
wrapper.in(!CollectionUtils.isEmpty(caIds), CanteenSpuEntity::getCategoryId, caIds);
// wrapper.orderByAsc(CanteenSpuEntity::getSort);
@@ -164,32 +165,32 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
// 查询SPU分页数据
Page<CanteenSpuEntity> pageData = baseMapper.selectPageByScope(page, wrapper, DataScope.of());
List<CanteenSpuEntity> records = pageData.getRecords();
// 构建返回的VO列表
List<CanteenSpuStockVO> resultList = new ArrayList<>();
if (!CollectionUtils.isEmpty(records)) {
// 获取所有SPU ID
List<Long> spuIds = records.stream()
.map(CanteenSpuEntity::getId)
.collect(Collectors.toList());
// 查询对应的库存信息
LambdaQueryWrapper<CanteenStockEntity> stockWrapper = Wrappers.lambdaQuery();
stockWrapper.in(CanteenStockEntity::getItemId, spuIds);
stockWrapper.eq(CanteenStockEntity::getItemType, "2"); // 假设"成品"表示菜品的类型
List<CanteenStockEntity> stockList = canteenStockMapper.selectList(stockWrapper);
// 将库存信息映射到SPU ID
Map<Long, CanteenStockEntity> stockMap = stockList.stream()
.collect(Collectors.toMap(CanteenStockEntity::getItemId, stock -> stock, (v1, v2) -> v1));
// 构建返回结果
for (CanteenSpuEntity spu : records) {
CanteenSpuStockVO vo = new CanteenSpuStockVO();
vo.setName(spu.getName());
vo.setPicUrl(spu.getPicUrl());
// 设置库存信息
CanteenStockEntity stock = stockMap.get(spu.getId());
if (stock != null) {
@@ -205,11 +206,11 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
vo.setInventoryUpperLimit(0);
vo.setInventoryLowerLimit(0);
}
resultList.add(vo);
}
}
// 构建分页返回对象
Page<CanteenSpuStockVO> resultPage = new Page<>();
resultPage.setRecords(resultList);
@@ -217,7 +218,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
resultPage.setSize(pageData.getSize());
resultPage.setCurrent(pageData.getCurrent());
resultPage.setPages(pageData.getPages());
return resultPage;
}
@@ -226,6 +227,7 @@ public class CanteenSpuServiceImpl extends ServiceImpl<CanteenSpuMapper, Canteen
LambdaQueryWrapper<CanteenSpuEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.like(StrUtil.isNotBlank(canteenSpu.getName()), CanteenSpuEntity::getName, canteenSpu.getName());
wrapper.eq(Objects.nonNull(canteenSpu.getCategoryId()), CanteenSpuEntity::getCategoryId, canteenSpu.getCategoryId());
wrapper.eq(Objects.nonNull(canteenSpu.getIsPriceIncreased()), CanteenSpuEntity::getIsPriceIncreased, canteenSpu.getIsPriceIncreased());
wrapper.orderByAsc(CanteenSpuEntity::getSort).orderByDesc(CanteenSpuEntity::getId);
LambdaQueryWrapper<CanteenOnlineSpuEntity> canteenOnlineSpuEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -28,6 +28,7 @@
<result property="stock" column="stock"/>
<result property="sort" column="sort"/>
<result property="hourType" column="hour_type"/>
<result property="isPriceIncreased" column="is_price_increased"/>
</resultMap>
<select id="selectTimeFood" resultType="com.bsd.pjcloud.canteen.vo.DailyMenuVO">
SELECT
@@ -63,6 +64,7 @@
sp.stock,
sp.category_id,
sp.sort,
sp.is_price_increased,
t.dept_id,
t.create_by
FROM canteen_daily_menu t
@@ -73,6 +73,9 @@ public class HardCreateOrderDto {
@Schema(description = "钱包id")
private Long walletId;
@Schema(description = "额外价格(分)")
private Integer extraPrice;
@Schema(description = "离线支付是否成功")
private Boolean offlinePaySuccess;
}
@@ -24,4 +24,7 @@ public class HardCreateCarDto {
// TODO 超市特有
@Schema(description = "重量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20798")
private BigDecimal productWeight;
@Schema(description = "是否额外收费")
private Boolean isPriceIncreased;
}
@@ -83,6 +83,12 @@ public class HardCarEntity extends Model<HardCarEntity> {
@Schema(description = "重量")
private BigDecimal productWeight;
/**
* 是否为优惠商品
*/
@Schema(description = "是否为优惠商品")
private String isDiscountsProduct;
/**
* 总价(分)
*/
@@ -21,6 +21,7 @@ import com.bsd.pjcloud.hard.api.dto.order.app.HardAppCreateFarmerOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.app.HardAppCreateOrderDto;
import com.bsd.pjcloud.hard.api.entity.order.HardCarEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
import com.bsd.pjcloud.hard.api.vo.order.HardCreateHardQrCodeScanOrderVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
import com.bsd.pjcloud.thirdparty.dto.ks.KsRecognitionCallbackDto;
@@ -121,7 +122,7 @@ public interface HardOrderService extends IService<HardOrderEntity> {
Integer computeExtraPrice(Integer price, MchManageVo mch, SysUser sysUser);
Integer computeExtraPriceV2(Integer totalPrice, Long mchId, String hourType, Long userId, Long userDeptId);
Integer computeExtraPriceV2(List<HardCarVo> carList, Long mchId, String hourType, Long userId, Long userDeptId);
/**
* 核销二维码
@@ -42,21 +42,20 @@ import com.bsd.pjcloud.hard.api.vo.wechat.WechantRefunCallbackVo;
import com.bsd.pjcloud.hard.api.vo.wechat.WechatRefundVo;
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleLogMapper;
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleMapper;
import com.bsd.pjcloud.hard.mapper.order.HardCarMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.*;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundDto;
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargeService;
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletSettingService;
import com.bsd.pjcloud.wallet.api.vo.WalletXfjDiscounts;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -573,9 +572,30 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
if (ObjectUtil.equals(order.getHardType(), HardTypeEnum.CANTEEN.getType()) && ObjectUtil.isNotEmpty(order.getExtraPrice()) && order.getExtraPrice() > 0) {
int noRefundPrice = order.getPayPrice() - order.getExtraPrice() - refundPrice;
if (noRefundPrice >= 0) {
Integer noRefundExtraPrice = hardOrderService.computeExtraPriceV2(noRefundPrice, order.getMerchantId(), order.getHourType(), order.getUserId(), order.getUserDeptId());
if (noRefundExtraPrice == 0) {
refundPrice += order.getExtraPrice();
// 查询购物车
List<HardCarVo> carList = hardCarService.getByOrderId(order.getId());
List<HardCarVo> extraCarList = new ArrayList<>();
for (HardAfterSaleCarEntity product : dto.getCarList()) {
HardCarVo targetCarProduct = carList.stream().filter(item -> ObjectUtil.equals(item.getProductId(), product.getProductId())).findFirst().orElse(null);
if (ObjectUtil.isEmpty(targetCarProduct)) continue;
if (product.getProductCount() <= 0) continue;
HardCarVo entity = BeanUtils.toBean(targetCarProduct, HardCarVo.class);
entity.setProductCount(product.getProductCount());
if (ObjectUtil.isNotEmpty(entity.getProductCount()) && !ObjectUtil.equals(entity.getProductCount(), 0)) {
// 按数量
int itemTotalPrice = entity.getProductCount() * entity.getProductPrice();
entity.setTotalPrice((long) itemTotalPrice);
} else if (ObjectUtil.isNotEmpty(entity.getProductWeight()) && entity.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) {
// 按重量
// 向上取整
int itemTotalPrice = entity.getProductWeight().multiply(BigDecimal.valueOf(entity.getProductPrice())).setScale(0, RoundingMode.CEILING).intValue();
entity.setTotalPrice((long) itemTotalPrice);
}
extraCarList.add(entity);
}
Integer noRefundExtraPrice = hardOrderService.computeExtraPriceV2(extraCarList, order.getMerchantId(), order.getHourType(), order.getUserId(), order.getUserDeptId());
if (noRefundExtraPrice > 0) {
refundPrice += noRefundExtraPrice;
}
}
}
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.canteen.api.feign.RemoteCanteenSpuService;
import com.bsd.pjcloud.canteen.api.feign.RemoteOnlineCanteenSpuService;
import com.bsd.pjcloud.canteen.entity.CanteenSpuEntity;
import com.bsd.pjcloud.canteen.vo.app.CanteenOnlineSpuAppVO;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.hard.api.constant.HardProductNatureEnum;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
@@ -319,6 +320,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
int totalPrice = v.getProductCount() * spu.getPrice();
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
item.setProductId(spu.getId());
item.setProductName(spu.getName());
item.setProductPrice(spu.getPrice());
@@ -329,6 +332,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
item.setProductCount(v.getProductCount());
item.setProductWeight(new BigDecimal(0));
item.setIsDiscountsProduct(isPriceIncreased);
carObjectList.add(item);
});
}
@@ -340,6 +344,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
int totalPrice = v.getProductCount() * spu.getPrice();
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
item.setProductId(spu.getId());
item.setProductName(spu.getName());
item.setProductPrice(spu.getPrice());
@@ -350,6 +356,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
item.setProductCount(v.getProductCount());
item.setProductWeight(new BigDecimal(0));
item.setIsDiscountsProduct(isPriceIncreased);
carObjectList.add(item);
});
}
@@ -370,6 +377,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
Integer price = getSupermarket(sku);
int totalPrice = 0;
totalPrice = v.getProductCount() * price;
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
// 找到spu
ShopSpuDetailAppVo spu = spuList.stream().filter(i -> ObjectUtil.equals(i.getId(), sku.getSpuId())).findFirst().orElse(null);
item.setProductId(sku.getId());
@@ -378,6 +387,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
item.setProductNature(HardProductNatureEnum.DEFAULT.getType());
item.setProductCount(v.getProductCount());
item.setProductWeight(BigDecimal.ZERO);
item.setIsDiscountsProduct(isPriceIncreased);
if (ObjectUtil.isNotEmpty(spu)) {
item.setProductName(spu.getProductName());
item.setProductPic(spu.getPicUrl());
@@ -401,6 +411,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
// 按重量
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue();
}
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
item.setProductId(spu.getId());
item.setProductName(spu.getProductName());
item.setProductPrice(price);
@@ -411,6 +423,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
item.setProductCount(v.getProductCount());
item.setProductWeight(v.getProductWeight());
item.setIsDiscountsProduct(isPriceIncreased);
carObjectList.add(item);
});
}
@@ -435,6 +448,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
// 按重量
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue();
}
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
item.setProductId(spu.getId());
item.setProductName(spu.getName());
item.setProductPrice(price);
@@ -445,6 +460,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
item.setProductCount(v.getProductCount());
item.setProductWeight(v.getProductWeight());
item.setIsDiscountsProduct(isPriceIncreased);
carObjectList.add(item);
});
}
@@ -478,6 +494,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
// 按重量
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue();
}
String isPriceIncreased = ObjectUtil.isNotEmpty(v.getIsPriceIncreased()) && v.getIsPriceIncreased() ? YesNoEnum.YES.getCode() : YesNoEnum.NO.getCode();
item.setProductId(sku.getId());
item.setProductName(spu.getTitle());
item.setProductPrice(price);
@@ -490,6 +508,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
item.setProductCount(v.getProductCount());
item.setProductWeight(v.getProductWeight());
item.setIsDiscountsProduct(isPriceIncreased);
carObjectList.add(item);
}
@@ -302,8 +302,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
}
int totalPrice = 0, extraPrice = 0, payPrice = 0;
totalPrice = hardCarService.computerCarTotalPrice(dto.getSysType(), dto.getOrderType(), dto.getList());
if (isExtraPrice) {
extraPrice = computeExtraPriceV2(totalPrice, mch.getId(), String.valueOf(dto.getHourType()), sysUser.getUserId(), sysUser.getDeptId());
if (isExtraPrice && ObjectUtil.isNotEmpty(dto.getExtraPrice())) {
extraPrice = dto.getExtraPrice();
}
payPrice = totalPrice + extraPrice;
if (isWalletPay) {
@@ -1137,14 +1137,34 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
@Override
public Integer computeExtraPriceV2(Integer totalPrice, Long mchId, String hourType, Long userId, Long userDeptId) {
public Integer computeExtraPriceV2(List<HardCarVo> carList, Long mchId, String hourType, Long userId, Long userDeptId) {
if (ObjectUtil.isEmpty(carList)) {
return 0;
}
List<WalletXfjDiscounts> discountsList = walletSettingService.remoteGetDiscountsList(String.valueOf(mchId), userId, userDeptId).getData();
if (ObjectUtil.isEmpty(discountsList)) {
return 0;
}
return discountsList.stream()
.filter(item -> ObjectUtil.equals(item.getHourType(), String.valueOf(hourType)))
.map(item -> item.computedDiscountsExtraPrice(totalPrice))
.map(item -> {
boolean specialDishEnable = ObjectUtil.isNotEmpty(item.getSpecialDishEnable()) && ObjectUtil.equals(item.getSpecialDishEnable(), YesNoEnum.YES.getCode());
long totalPrice = 0L;
// 特色菜不额外收费
if (!specialDishEnable) {
totalPrice = carList.stream()
.filter(v -> ObjectUtil.isNotEmpty(v.getIsDiscountsProduct()) && ObjectUtil.equals(v.getIsDiscountsProduct(), YesNoEnum.YES.getCode()))
.map(HardCarEntity::getTotalPrice)
.reduce(Long::sum).orElse(0L);
}
// 特色菜额外收费
else if (specialDishEnable) {
totalPrice = carList.stream()
.map(HardCarEntity::getTotalPrice)
.reduce(Long::sum).orElse(0L);
}
return item.computedDiscountsExtraPrice((int) totalPrice);
})
.reduce(Integer::sum).orElse(0);
}
@@ -2,23 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.hard.mapper.order.HardCarMapper">
<resultMap id="hardCarMap" type="com.bsd.pjcloud.hard.api.entity.order.HardCarEntity">
<id property="id" column="id"/>
<result property="parentCarId" column="parent_car_id"/>
<result property="productId" column="product_id"/>
<result property="productName" column="product_name"/>
<result property="productPic" column="product_pic"/>
<result property="productPrice" column="product_price"/>
<result property="productCount" column="product_count"/>
<result property="productWeight" column="product_weight"/>
<result property="totalPrice" column="total_price"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
<sql id="selectA">
select a.id,
@@ -30,6 +13,7 @@
a.product_nature,
a.product_count,
a.product_weight,
a.is_discounts_product,
a.total_price,
a.create_by,
a.create_time,
@@ -41,6 +25,9 @@
<sql id="whereA">
a.del_flag = '0'
<if test="dto.isDiscountsProduct != null and dto.isDiscountsProduct != '' ">
and is_discounts_product = #{dto.isDiscountsProduct}
</if>
<if test="dto.createTimeStr != null and dto.createTimeStr != '' ">
<choose>
<when test="dto.createTimeType != null and dto.createTimeType != '' ">
@@ -43,6 +43,11 @@ public class WalletXfjDiscounts {
*/
private Double extraPer;
/**
* 特色菜是否额外收费
*/
private String specialDishEnable;
public int computedDiscountsExtraPrice(int totalPrice) {
if (totalPrice <= basePrice) return 0;
double rate = ObjectUtil.isEmpty(extraPer) ? 1.0 : extraPer;
@@ -95,6 +95,7 @@ public class WalletSettingServiceImpl extends ServiceImpl<WalletSettingMapper, W
entity.setType(WalletXfjDiscountsEnum.JZ_DISCOUNT.getCode());
entity.setExtraPer(item.getExtraPer());
entity.setBasePrice(item.getBasePrice());
entity.setSpecialDishEnable(item.getSpecialDishEnable());
return entity;
}).toList()
);