Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
Tankaikai
2024-11-19 14:14:22 +08:00
32 changed files with 368 additions and 498 deletions

View File

@@ -2,10 +2,8 @@ package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.*;
import java.math.BigDecimal;
@Data
public class AddCartDTO {
@@ -19,8 +17,8 @@ public class AddCartDTO {
private Integer shopId;
private String tableId;
@NotNull
@Min(1)
private Integer num;
@DecimalMin("0.01")
private BigDecimal num;
private boolean isPack;
private boolean isGift;
private Integer cartId;

View File

@@ -2,10 +2,8 @@ package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.*;
import java.math.BigDecimal;
@Data
public class AddTemporaryDishesDTO {
@@ -14,11 +12,17 @@ public class AddTemporaryDishesDTO {
@NotNull
private Integer shopId;
private String tableId;
@NotBlank(message = "菜品名不为空")
private String name;
@NotNull(message = "分类不为空")
private Integer categoryId;
@Min(value = 0, message = "价格最低为0")
private BigDecimal price;
@NotNull
@Min(1)
private Integer num;
private boolean isPack;
private boolean isGift;
@DecimalMin(value = "0.01")
private BigDecimal num;
@NotBlank(message = "单位不为空")
private String unit;
private String note;
// 用餐类型
@NotBlank

View File

@@ -2,8 +2,10 @@ package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class ReturnCartDTO {
@@ -13,7 +15,7 @@ public class ReturnCartDTO {
private Integer shopId;
private Long tableId;
@NotNull
@Min(value = 1, message = "最小数量为1")
private Integer num;
@DecimalMin(value = "0.01", message = "最小数量为0.01")
private BigDecimal num;
private String note;
}

View File

@@ -6,6 +6,7 @@ import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
@Data
@@ -17,7 +18,7 @@ public class ReturnOrderDTO {
private Integer id;
@NotNull
@Min(1)
private Integer num;
private BigDecimal num;
}
@NotNull
private Integer orderId;

View File

@@ -2,23 +2,23 @@ package cn.ysk.cashier.dto.shoptable;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class UpdateCartDTO {
@NotNull
private Integer cartId;
@NotNull
private Integer skuId;
@NotNull
private Integer productId;
@NotNull
private Integer shopId;
@NotNull
@Min(0)
private Integer num;
@DecimalMin("0")
private BigDecimal num;
private String note;
private Boolean isPack;
private Boolean isGift;

View File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@@ -36,10 +37,10 @@ public class TbShopShare extends Model<TbShopShare> {
private String invitedImg;
//被邀顶部图
private String beInvitedImg;
//活动开始时间
private Date startTime;
//活动结束时间
private Date endTime;
private String endTime;
//活动开始时间
private String startTime;
//新用户获得券
private String newCoupon;
//邀请num人数 可获奖励券

View File

@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal;
import java.util.List;
public interface TbCashierCartMapper extends BaseMapper<TbCashierCart> {
@@ -47,7 +48,7 @@ public interface TbCashierCartMapper extends BaseMapper<TbCashierCart> {
*/
@Update("update tb_cashier_cart set status=#{status}, total_amount=(number+#{changeNum})*sale_price,number=number+#{changeNum},total_number=total_number+#{changeNum} " +
"where id=#{id}")
int updateNumAmountStatus(Integer id, String status, Integer changeNum);
int updateNumAmountStatus(Integer id, String status, BigDecimal changeNum);
@Select("select a.* from tb_cashier_cart as a left join tb_order_detail as b on a.id=b.cart_id where a.shop_id=#{shopId} and a.status=#{state} and a.created_at>#{time} and b.id is not null;")
List<TbCashierCart> selectPlaceCart(Integer shopId, long time, String state);

View File

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal;
import java.util.List;
public interface TbOrderDetailMapper extends BaseMapper<TbOrderDetail> {
@@ -19,7 +20,7 @@ public interface TbOrderDetailMapper extends BaseMapper<TbOrderDetail> {
*/
@Update("update tb_order_detail set status=#{status}, price_amount=(num+#{changeNum})*price,num=num+#{changeNum} " +
"where id=#{id}")
int updateNumAmountStatus(Integer id, String status, int changeNum);
int updateNumAmountStatus(Integer id, String status, BigDecimal changeNum);
/**
* 查询包含打包费和是否赠送的订单详情信息

View File

@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal;
public interface TbProducSkutMapper extends BaseMapper<TbProductSku> {
@@ -29,5 +31,5 @@ public interface TbProducSkutMapper extends BaseMapper<TbProductSku> {
int decrStockUnCheck(String id, int num);
@Update("update tb_product_sku set real_sales_number=real_sales_number-#{num} WHERE id=#{skuId}")
int decrRealSalesNumber(@Param("skuId") Integer skuId, @Param("num") Integer num);
int decrRealSalesNumber(@Param("skuId") Integer skuId, @Param("num") BigDecimal num);
}

View File

@@ -8,6 +8,8 @@ import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.jpa.repository.Query;
import java.math.BigDecimal;
public interface TbProductMapper extends BaseMapper<TbProduct> {
@Select("select * from tb_product_sku as sku where sku.is_del=0 and sku.is_grounding=1 and sku.is_pause_sale=0 and sku.shop_id=#{shopId} and sku.id=#{skuId}")
@@ -17,11 +19,11 @@ public interface TbProductMapper extends BaseMapper<TbProduct> {
TbProduct selectByIdAndShopId(@Param("shopId") Integer shopId, @Param("id") Integer id);
@Update("update tb_product set stock_number=stock_number+#{addNum} WHERE id=#{id}")
int incrStock(@Param("id") Integer id, @Param("addNum") Integer addNum);
int incrStock(@Param("id") Integer id, @Param("addNum") BigDecimal addNum);
@Update("update tb_product set stock_number=stock_number-#{decrNum} WHERE id=#{productId} and stock_number-#{decrNum} >= 0")
int decrStock(@Param("productId") Integer productId, @Param("decrNum") int decrNum);
int decrStock(@Param("productId") Integer productId, @Param("decrNum") BigDecimal decrNum);
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}")
int decrStockUnCheck(Integer id, int num);
int decrStockUnCheck(Integer id, BigDecimal num);
}

View File

@@ -60,9 +60,11 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
/**
* 根据店就餐模式查询购物车
* @param shopEatTypeInfoDTO 就餐模式
* @param masterId 取餐码
* @param statuses 状态 为空默认查询 create return
* @return 购物车信息
*/
List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId);
List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, TableConstant.OrderInfo.Status... statuses);
/**
* 根据订单id和状态获取购物车数据
@@ -73,5 +75,13 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
boolean updateMemberAndAmountByOrderId(Integer orderId, boolean isMember);
/**
* 根据就餐信息查询购物车信息
* @param shopEatTypeInfoDTO 就餐信息
* @return 购物车信息
*/
TbCashierCart selectOneCartByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer productId, Integer skuId, boolean isGift, boolean isTemp);
}

View File

@@ -1,6 +1,7 @@
package cn.ysk.cashier.mybatis.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.cons.TableConstant;
@@ -108,14 +109,19 @@ public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, T
}
@Override
public List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId) {
public List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, TableConstant.OrderInfo.Status... statuses) {
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId())
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
.in(TbCashierCart::getStatus, "create", "return")
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
if (statuses.length == 0) {
queryWrapper.in(TbCashierCart::getStatus, "create", "return");
}else {
queryWrapper.in(TbCashierCart::getStatus, CollUtil.newArrayList(statuses));
}
// 非堂食校验台桌状态
if (shopEatTypeInfoDTO.isTakeout()) {
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
@@ -139,5 +145,33 @@ public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, T
}
return queryChainWrapper.list();
}
@Override
public TbCashierCart selectOneCartByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer productId, Integer skuId, boolean isGift, boolean isTemp) {
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId())
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.isNull(TbCashierCart::getPlaceNum)
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
.eq(TbCashierCart::getStatus, "create")
.eq(TbCashierCart::getIsGift, isGift)
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
if (isTemp) {
query.isNull(TbCashierCart::getProductId).isNull(TbCashierCart::getSkuId).eq(TbCashierCart::getIsTemporary, 1);
}else {
query.eq(TbCashierCart::getProductId, productId)
.eq(TbCashierCart::getSkuId, skuId);
}
// 外带只查询pc和收银机商品
if (shopEatTypeInfoDTO.isTakeout()) {
query.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
.in(TbCashierCart::getPlatformType, "pc", "cash");
} else {
query.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId());
}
return getOne(query);
}
}

View File

@@ -85,15 +85,15 @@ public class TbCashierCart implements Serializable {
@Column(name = "`number`", nullable = false)
@NotNull
@ApiModelProperty(value = "结余数量")
private Integer number;
private BigDecimal number;
@Column(name = "`total_number`")
@ApiModelProperty(value = "总下单数量")
private Integer totalNumber;
private BigDecimal totalNumber;
@Column(name = "`refund_number`")
@ApiModelProperty(value = "退单数量")
private Integer refundNumber;
private BigDecimal refundNumber;
@Column(name = "`category_id`")
@ApiModelProperty(value = "分类Id")
@@ -168,6 +168,9 @@ public class TbCashierCart implements Serializable {
private Integer userCouponId;
private BigDecimal memberPrice = BigDecimal.ZERO;
private Integer isMember;
// 是否临时菜品
private Integer isTemporary;
private String unit;
public void copy(TbCashierCart source) {
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
@@ -184,9 +187,9 @@ public class TbCashierCart implements Serializable {
totalAmount = packFee;
} else {
if (isMember != null && isMember == 1 && memberPrice != null && memberPrice.compareTo(BigDecimal.ZERO) > 0) {
totalAmount = BigDecimal.valueOf(totalNumber).multiply(memberPrice).add(packFee);
totalAmount = totalNumber.multiply(memberPrice).add(packFee);
} else {
totalAmount = BigDecimal.valueOf(totalNumber).multiply(salePrice).add(packFee);
totalAmount = totalNumber.multiply(salePrice).add(packFee);
}
}
}
@@ -195,14 +198,15 @@ public class TbCashierCart implements Serializable {
* 获取总价不包含打包费
*
*/
public BigDecimal getTotalAmountByNum(Integer num) {
public BigDecimal getTotalAmountByNum(BigDecimal num) {
if (num == null) {
num = totalNumber;
}
if (isMember != null && isMember == 1 && memberPrice != null && memberPrice.compareTo(BigDecimal.ZERO) > 0) {
return BigDecimal.valueOf(num).multiply(memberPrice);
return num.multiply(memberPrice);
} else {
return BigDecimal.valueOf(num).multiply(salePrice);
return num.multiply(salePrice);
}
}
}

View File

@@ -61,7 +61,7 @@ public class TbOrderDetail implements Serializable {
@Column(name = "`num`")
@ApiModelProperty(value = "num")
private Integer num;
private BigDecimal num;
@Column(name = "`product_name`")
@ApiModelProperty(value = "productName")
@@ -103,7 +103,7 @@ public class TbOrderDetail implements Serializable {
@Transient
@ApiModelProperty(value = "退单数量")
@TableField(exist = false)
private Integer refundNumber;
private BigDecimal refundNumber;
@Column(name = "`is_vip`")
@ApiModelProperty(value = "isVip")
@@ -131,6 +131,7 @@ public class TbOrderDetail implements Serializable {
private BigDecimal memberPrice;
private Integer userCouponId;
private Integer isMember;
private Integer isTemporary;
public void copy(TbOrderDetail source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));

View File

@@ -50,9 +50,6 @@ public class TbProduct implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
@Column(name = "`source_path`")
@ApiModelProperty(value = "商品来源 NORMAL普通商品 --,SCORE积分商品")
private String sourcePath="NORMAL";
@Column(name = "`merchant_id`")
@ApiModelProperty(value = "商户Id")
@@ -66,10 +63,6 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "商品名称")
private String name;
@Column(name = "`type`")
@ApiModelProperty(value = "商品类型(属性):REAL- 实物商品 VIR---虚拟商品")
private String type = "REAL";
@Column(name = "`pack_fee`")
@ApiModelProperty(value = "包装费")
private BigDecimal packFee;
@@ -95,10 +88,6 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "商品规格")
private Integer specId;
@Column(name = "`brand_id`")
@ApiModelProperty(value = "品牌Id")
private Integer brandId;
@Column(name = "`short_title`")
@ApiModelProperty(value = "短标题--促销语")
private String shortTitle;
@@ -107,72 +96,31 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "lowMemberPrice")
private BigDecimal lowMemberPrice;
@Column(name = "`unit_snap`")
@ApiModelProperty(value = "单位镜像")
private String unitSnap;
@Column(name = "`share_img`")
@ApiModelProperty(value = "商品分享图")
private String shareImg;
@Column(name = "`images`")
@ApiModelProperty(value = "商品图片(第一张为缩略图,其他为详情)")
private String images;
@Column(name = "`video`")
@ApiModelProperty(value = "商品视频URL地址")
private String video;
@Column(name = "`video_cover_img`")
@ApiModelProperty(value = "视频封面图")
private String videoCoverImg;
@Column(name = "`sort`")
@ApiModelProperty(value = "排序")
private Integer sort = 0;
@Column(name = "`limit_number`")
@ApiModelProperty(value = "0-不限购")
private Integer limitNumber = 0;
@Column(name = "`product_score`")
@ApiModelProperty(value = "商品赚送积分")
private Integer productScore;
@Column(name = "`status`",nullable = false)
@NotNull
@ApiModelProperty(value = "0--待审核 1审核通过 -1审核失败 -2违规下架")
private Integer status = 0;
@Column(name = "`fail_msg`")
@ApiModelProperty(value = "审核失败原因")
private String failMsg;
@Column(name = "`is_recommend`")
@ApiModelProperty(value = "是否推荐,店铺推荐展示")
private Integer isRecommend = 0;
@Column(name = "`is_hot`")
@ApiModelProperty(value = "是否热销")
private Integer isHot = 0;
@Column(name = "`is_new`")
@ApiModelProperty(value = "是否新品")
private Integer isNew;
@Column(name = "`is_on_sale`")
@ApiModelProperty(value = "是否促销1-是0-否")
private Integer isOnSale = 0;
@Column(name = "`is_show`")
@ApiModelProperty(value = "是否展示0-下架 1上架---废弃")
private Integer isShow = 0;
@Column(name = "`type`")
@ApiModelProperty(value = "商品类型(属性):普通商品 normal 套餐商品 package 称重商品 weigh 团购券 coupon")
private String type;
@Column(name = "`type_enum`")
@ApiModelProperty(value = "商品规格:0-单规格 1多规格")
@ApiModelProperty(value = "商品规格:normal-单规格 sku-多规格")
private String typeEnum;
@Column(name = "`is_del`",nullable = false)
@NotNull
@ApiModelProperty(value = "是否回收站 0-否1回收站")
@@ -186,36 +134,6 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "是否暂停销售")
private Integer isPauseSale = 0;
@Column(name = "`is_free_freight`",nullable = false)
@NotNull
@ApiModelProperty(value = "是否免邮1-是 0-否")
private Integer isFreeFreight=1;
@Column(name = "`freight_id`")
@ApiModelProperty(value = "邮费模版")
private Long freightId;
@Column(name = "`strategy_type`")
@ApiModelProperty(value = "商品当前生效策略")
private String strategyType;
@Column(name = "`strategy_id`")
@ApiModelProperty(value = "策略Id")
private Integer strategyId = 1;
@Column(name = "`is_vip`")
@ApiModelProperty(value = "vip专属")
private Integer isVip = 0;
@Column(name = "`is_delete`",nullable = false)
@NotNull
@ApiModelProperty(value = "是否删除")
private Integer isDelete = 0;
@Column(name = "`notice`")
@ApiModelProperty(value = "购买须知")
private String notice;
@Column(name = "`created_at`")
@ApiModelProperty(value = "createdAt")
private Long createdAt;
@@ -224,26 +142,6 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "updatedAt")
private Long updatedAt;
@Column(name = "`base_sales_number`")
@ApiModelProperty(value = "基础出售数量")
private Double baseSalesNumber =0.00;
@Column(name = "`real_sales_number`")
@ApiModelProperty(value = "实际销量")
private Integer realSalesNumber = 0;
@Column(name = "`sales_number`")
@ApiModelProperty(value = "合计销量")
private Integer salesNumber = 0;
@Column(name = "`thumb_count`")
@ApiModelProperty(value = "点赞次数")
private Integer thumbCount = 0;
@Column(name = "`store_count`")
@ApiModelProperty(value = "收藏次数")
private Integer storeCount = 0;
@Column(name = "`furnish_meal`")
@ApiModelProperty(value = "支持堂食")
private Integer furnishMeal = 0;
@@ -260,46 +158,10 @@ public class TbProduct implements Serializable {
@ApiModelProperty(value = "支持虚拟")
private Integer furnishVir = 0;
@Column(name = "`is_combo`")
@ApiModelProperty(value = "是否套餐")
private Integer isCombo =0;
@Column(name = "`group_snap`")
@ApiModelProperty(value = "套餐内容")
private String groupSnap;
@Column(name = "`is_show_cash`")
@ApiModelProperty(value = "isShowCash")
private Integer isShowCash =0;
@Column(name = "`is_show_mall`")
@ApiModelProperty(value = "isShowMall")
private Integer isShowMall = 0;
@Column(name = "`is_need_examine`")
@ApiModelProperty(value = "是否需要审核")
private Integer isNeedExamine = 0;
@Column(name = "`show_on_mall_status`")
@ApiModelProperty(value = "线上商城展示状态0待审核 -1 异常 1正常")
private Integer showOnMallStatus = 1;
@Column(name = "`show_on_mall_time`")
@ApiModelProperty(value = "提交审核时间")
private Long showOnMallTime;
@Column(name = "`show_on_mall_error_msg`")
@ApiModelProperty(value = "线上商城展示失败原因")
private String showOnMallErrorMsg;
@Column(name = "`enable_label`")
@ApiModelProperty(value = "使用标签打印 选择 是 并在 前台>本机设置 勾选打印标签后,收银完成后会自动打印对应数量的标签数")
private Integer enableLabel = 0;
@Column(name = "`tax_config_id`")
@ApiModelProperty(value = "税率")
private String taxConfigId;
@Column(name = "spec_info")
@ApiModelProperty(value = "specInfo")
private String specInfo;

View File

@@ -171,8 +171,8 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
"COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " +
"COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" +
"COALESCE(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END),0), " +
"COALESCE(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END),0))" +
"FROM TbOrderInfo orders " +
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
"WHERE info.shopId = :shopId " +

View File

@@ -34,7 +34,7 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
@Modifying
@Query("update FROM TbProduct pro set pro.stockNumber=pro.stockNumber+:number WHERE pro.id =:productId")
void incrProductStockNumber(Integer productId, Integer number);
void incrProductStockNumber(Integer productId, BigDecimal number);
@Transactional
@Modifying
@@ -44,7 +44,7 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
@Modifying
@Query("update TbProduct set stockNumber=stockNumber+:num where id=:id")
void incrStock(@Param("id") Integer id, @Param("num") Integer num);
void incrStock(@Param("id") Integer id, @Param("num") BigDecimal num);
@Query("select product from TbProduct product where product.shopId=:shopId")

View File

@@ -50,4 +50,16 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
@Modifying
@Query("update TbProductSku set salePrice = :salePrice where productId= :productId")
void upSalePrice(@Param("productId") String productId, @Param("lowPrice") BigDecimal salePrice);
@Query(value =
"SELECT " +
" sum( real_sales_number )," +
" product_id " +
" FROM" +
" tb_product_sku " +
" WHERE" +
" product_id IN :ids" +
" GROUP BY" +
" product_id", nativeQuery = true)
List<Object[]> searchProRealSalesNumber(@Param("ids") List<Integer> ids);
}

View File

@@ -1,12 +1,7 @@
package cn.ysk.cashier.repository.shop;
import javax.persistence.Tuple;
import cn.ysk.cashier.pojo.TbShopUserDutyDetail;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @author lyf
@@ -14,14 +9,4 @@ import java.util.List;
public interface TbShopUserDutyDetailRepository extends JpaRepository<TbShopUserDutyDetail,Integer> {
@Query(value = "SELECT " +
"sum( num ), " +
"product_id " +
"FROM " +
"tb_shop_user_duty_detail " +
"WHERE " +
"product_id IN :ids " +
"GROUP BY " +
"product_id",nativeQuery = true)
List<Object[]> searchUUserDutyDetail(@Param("ids") List<Integer> ids);
}

View File

@@ -310,7 +310,7 @@ public class SummaryServiceImpl implements SummaryService {
}
TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo = detailRepository.queryTbOrderSalesCountByDaysummaryCount(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
TbOrderPayCountVo zongShuLiang = new TbOrderPayCountVo("el-icon-goods", "总数量", "0", tbOrderSalesCountByDayVo.getSalesNum() + tbOrderSalesCountByDayVo.getRefNum());
TbOrderPayCountVo zongShuLiang = new TbOrderPayCountVo("el-icon-goods", "总数量", "0", tbOrderSalesCountByDayVo.getSalesNum().add(tbOrderSalesCountByDayVo.getRefNum()));
TbOrderPayCountVo zong = new TbOrderPayCountVo("el-icon-coin", "总金额", "1", tbOrderSalesCountByDayVo.getSalesAmount());
TbOrderPayCountVo tuidan = new TbOrderPayCountVo("el-icon-goods", "退单量", "0", tbOrderSalesCountByDayVo.getRefNum());
TbOrderPayCountVo tuikuan = new TbOrderPayCountVo("el-icon-money", "退款金额", "1", tbOrderSalesCountByDayVo.getRefAmount());

View File

@@ -178,17 +178,26 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
List<TbFullOrderDetail> details = tbOrderDetailMapper.selectFullInfoByOrderId(tbOrderInfo.getId());
if (!tbOrderInfo.getOrderType().equals("return")) {
List<TbOrderInfo> tbOrderInfos = tbOrderInfoRepository.selTbOrdersBysource(tbOrderInfo.getId(), tbOrderInfo.getShopId());
Map<Integer, Integer> map;
Map<Integer, BigDecimal> map;
if (!CollectionUtils.isEmpty(tbOrderInfos)) {
List<Integer> ids = tbOrderInfos.stream().map(TbOrderInfo::getId).collect(Collectors.toList());
List<TbOrderDetail> refundOrderDetail = tbOrderDetailRepository.searchDetailByOrderIds(ids);
map = refundOrderDetail.stream().collect(Collectors.groupingBy(TbOrderDetail::getProductSkuId, Collectors.summingInt(TbOrderDetail::getNum)));
map = refundOrderDetail.stream()
.collect(Collectors.groupingBy(
TbOrderDetail::getProductSkuId,
Collectors.reducing(
BigDecimal.ZERO,
TbOrderDetail::getNum,
BigDecimal::add
)
));
refundAmount = tbOrderInfos.stream().map(TbOrderInfo::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
} else {
map = new HashMap<>();
}
details.parallelStream().forEach(detail -> {
Integer refundNumber = map.get(detail.getProductSkuId());
BigDecimal refundNumber = map.get(detail.getProductSkuId());
if (refundNumber != null) {
detail.setRefundNumber(refundNumber);
}
@@ -202,7 +211,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
TbOrderDetail seatInfo = null;
ArrayList<TbFullOrderDetail> detailList = new ArrayList<>();
for (TbFullOrderDetail detail : details) {
if (TableConstant.CART_SEAT_ID.equals(detail.getProductId().toString())) {
if (detail.getProductId() != null && TableConstant.CART_SEAT_ID.equals(detail.getProductId().toString())) {
seatInfo = detail;
} else {
detailList.add(detail);

View File

@@ -68,7 +68,6 @@ public class TbProductServiceImpl implements TbProductService {
private final TbProductSkuRepository tbProductSkuRepository;
private final TbShopUnitRepository tbShopUnitRepository;
private final TbProductSpecRepository tbProductSpecRepository;
private final TbProductSkuMapper TbProductSkuMapper;
private final TbProductSkuResultRepository tbProductSkuResultRepository;
private final TbShopCategoryRepository tbShopCategoryRepository;
private final TbShopUserDutyDetailRepository tbShopUserDutyDetailRe;
@@ -149,7 +148,7 @@ public class TbProductServiceImpl implements TbProductService {
//销量
List<Object[]> objects = new ArrayList<>();
if (!productIdInt.isEmpty()) {
objects = tbShopUserDutyDetailRe.searchUUserDutyDetail(productIdInt);
objects = tbProductSkuRepository.searchProRealSalesNumber(productIdInt);
}
//组装
List<TbProductVo> tbProductVoList = new ArrayList<>();
@@ -218,8 +217,10 @@ public class TbProductServiceImpl implements TbProductService {
} else {
for (Object[] o : objects) {
if (((Integer) o[1]).equals(product.getId())) {
BigDecimal bigDecimal = (BigDecimal) o[0];
tbProductVo.setRealSalesNumber(bigDecimal.doubleValue());
if (o[0] != null) {
BigDecimal bigDecimal = (BigDecimal) o[0];
tbProductVo.setRealSalesNumber(bigDecimal.doubleValue());
}
}
}
}
@@ -248,16 +249,16 @@ public class TbProductServiceImpl implements TbProductService {
productNewVo.setLowPrice(product.getLowPrice().toString());
productNewVo.setStockNumber(Double.valueOf(product.getStockNumber()));
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(product.getId().toString());
if ("sku".equals(product.getTypeEnum())){
if(tbProductSkus.size() > 1){
if ("sku".equals(product.getTypeEnum())) {
if (tbProductSkus.size() > 1) {
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
if (maxPrice.compareTo(new BigDecimal(productNewVo.getLowPrice())) == 0) {
productNewVo.setLowPrice("" +productNewVo.getLowPrice());
}else {
productNewVo.setLowPrice("" +productNewVo.getLowPrice() + "~¥" + maxPrice);
productNewVo.setLowPrice("" + productNewVo.getLowPrice());
} else {
productNewVo.setLowPrice("" + productNewVo.getLowPrice() + "~¥" + maxPrice);
}
}else {
productNewVo.setLowPrice("" +productNewVo.getLowPrice());
} else {
productNewVo.setLowPrice("" + productNewVo.getLowPrice());
}
}
ViewConSku viewConSku = new ViewConSku();
@@ -265,7 +266,7 @@ public class TbProductServiceImpl implements TbProductService {
viewConSku.setProductId(product.getId());
Example<ViewConSku> query = Example.of(viewConSku);
List<ViewConSku> skuCons = viewConSkuRepository.findAll(query);
if(product.getTypeEnum().equals("sku")){
if (product.getTypeEnum().equals("sku")) {
//规格填充
productNewVo.setSkuList(convert(tbProductSkus));
//耗材弹窗选项
@@ -276,11 +277,11 @@ public class TbProductServiceImpl implements TbProductService {
}
}
}
productNewVo.setConInfos(CollectionUtils.isEmpty(skuCons)? Collections.emptyList() :skuCons);
productNewVo.setConInfos(CollectionUtils.isEmpty(skuCons) ? Collections.emptyList() : skuCons);
products.add(productNewVo);
}
Map<String, Object> result = PageUtil.toPage(products, page.getTotalElements());
result.put("warnLine",warnLine);
result.put("warnLine", warnLine);
return result;
}
@@ -431,8 +432,6 @@ public class TbProductServiceImpl implements TbProductService {
product.setImages(resources.getImages().toString());
}
product.setIsDel(0);
product.setIsDelete(0);
product.setIsFreeFreight(1);
product.setStatus(1);
product.setCreatedAt(Instant.now().toEpochMilli());
product.setUpdatedAt(Instant.now().toEpochMilli());
@@ -442,7 +441,6 @@ public class TbProductServiceImpl implements TbProductService {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {
product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
product.setIsCombo(1);
}
if (!CollectionUtils.isEmpty(resources.getGroupCategoryId())) {
List<Integer> collect = resources.getGroupCategoryId().stream().map(TbCouponCategoryDto::getId).collect(Collectors.toList());
@@ -530,15 +528,12 @@ public class TbProductServiceImpl implements TbProductService {
}
if (!"group".equals(product.getTypeEnum())) {
if (resources.getCategoryId() == null) throw new BadRequestException("商品分类不可为空");
product.setIsCombo(0);
product.setGroupSnap(null);
if (resources.getNotices() != null && resources.getNotices().getId() != null) {
noticeRepository.deleteById(resources.getNotices().getId());
}
}
product.setIsDel(0);
product.setIsDelete(0);
product.setIsFreeFreight(1);
product.setStatus(1);
product.setUpdatedAt(Instant.now().toEpochMilli());
product.setImages(resources.getImages().toString());
@@ -549,7 +544,8 @@ public class TbProductServiceImpl implements TbProductService {
//套餐内容
if (!resources.getGroupSnap().isEmpty()) {
product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
product.setIsCombo(1);
} else {
throw new BadRequestException("套餐内容不可为空");
}
if (!CollectionUtils.isEmpty(resources.getGroupCategoryId())) {
List<Integer> collect = resources.getGroupCategoryId().stream().map(TbCouponCategoryDto::getId).collect(Collectors.toList());
@@ -613,7 +609,6 @@ public class TbProductServiceImpl implements TbProductService {
}
@Transactional(rollbackFor = Exception.class)
@Override
public void upProSort(TbProductSortCriteria param) {
@@ -746,12 +741,12 @@ public class TbProductServiceImpl implements TbProductService {
}
@Override
public void incrStockNumber(String productId, Integer number) {
public void incrStockNumber(String productId, BigDecimal number) {
tbProductRepository.incrProductStockNumber(Integer.valueOf(productId), number);
}
@Override
public void returnStockByPro(Integer productId, Integer productSkuId, Integer num) {
public void returnStockByPro(Integer productId, Integer productSkuId, BigDecimal num) {
if (productId > 0) {
log.info("开始返还库存订单超时取消商品id{}", productId);
TbProduct product = tbProductRepository.findById(productId).orElse(null);
@@ -770,7 +765,6 @@ public class TbProductServiceImpl implements TbProductService {
queryWrapper.eq("is_del", 0)
.in("type_enum", "sku", "normal")
.eq("shop_id", shopId)
.eq("is_delete", 0)
.eq("status", 1)
.eq("is_pause_sale", 0);

View File

@@ -425,36 +425,45 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("已下单商品仅支持退单操作");
}
if (updateCartDTO.getNum() == 0) {
if (updateCartDTO.getNum().compareTo(BigDecimal.ZERO) == 0) {
cashierCartRepository.deleteById(updateCartDTO.getCartId());
return null;
}
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getSkuId());
TbProduct product = productMapper.selectByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getProductId());
if (product == null || productSku == null) {
throw new BadRequestException("商品不存在或已下架, id: " + updateCartDTO.getSkuId());
TbProduct product = null;
if (updateCartDTO.getProductId() != null && updateCartDTO.getSkuId() != null) {
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getSkuId());
product = productMapper.selectByIdAndShopId(updateCartDTO.getShopId(), updateCartDTO.getProductId());
if (product == null || productSku == null) {
throw new BadRequestException("商品不存在或已下架, id: " + updateCartDTO.getSkuId());
}
tbCashierCart.setCoverImg(product.getCoverImg());
tbCashierCart.setIsSku(product.getTypeEnum());
tbCashierCart.setName(product.getName());
tbCashierCart.setProductId(String.valueOf(product.getId()));
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setSkuId(productSku.getId().toString());
tbCashierCart.setCategoryId(product.getCategoryId());
}
tbCashierCart.setCoverImg(product.getCoverImg());
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setIsSku(product.getTypeEnum());
tbCashierCart.setName(product.getName());
tbCashierCart.setProductId(String.valueOf(product.getId()));
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setSkuId(productSku.getId().toString());
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setTotalAmount(new BigDecimal(updateCartDTO.getNum()).multiply(productSku.getSalePrice()));
tbCashierCart.setSalePrice(tbCashierCart.getSalePrice());
tbCashierCart.setTotalAmount(updateCartDTO.getNum().multiply(tbCashierCart.getSalePrice()));
tbCashierCart.setNote(updateCartDTO.getNote());
if (updateCartDTO.getIsPack() != null) {
if (!updateCartDTO.getIsPack()) {
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setTotalAmount(tbCashierCart.getSalePrice().multiply(BigDecimal.valueOf(updateCartDTO.getNum())));
tbCashierCart.setTotalAmount(tbCashierCart.getSalePrice().multiply(updateCartDTO.getNum()));
} else {
tbCashierCart.setPackFee(new BigDecimal(updateCartDTO.getNum()).multiply(product.getPackFee()));
tbCashierCart.setTotalAmount(tbCashierCart.getSalePrice().multiply(BigDecimal.valueOf(updateCartDTO.getNum()))
if (product != null) {
tbCashierCart.setPackFee(updateCartDTO.getNum().multiply(product.getPackFee()));
}
tbCashierCart.setTotalAmount(tbCashierCart.getSalePrice().multiply(updateCartDTO.getNum())
.add(tbCashierCart.getPackFee()));
}
tbCashierCart.setIsPack(updateCartDTO.getIsPack() ? "true" : "false");
@@ -467,7 +476,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setTotalNumber(updateCartDTO.getNum());
tbCashierCart.setNumber(updateCartDTO.getNum());
tbCashierCart.setCategoryId(product.getCategoryId());
tbCashierCartMapper.updateById(tbCashierCart);
if (tbCashierCart.getOrderId() != null && StrUtil.isNotBlank(updateCartDTO.getNote())) {
@@ -551,14 +559,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setIsPack(String.valueOf(addCartDTO.isPack()));
tbCashierCart.setIsGift(String.valueOf(addCartDTO.isGift()));
tbCashierCart.setSalePrice(productSku.getSalePrice());
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
tbCashierCart.setTotalAmount(addCartDTO.getNum().multiply(productSku.getSalePrice()));
tbCashierCart.setSkuName(productSku.getSpecSnap());
// 设置打包费
if (!addCartDTO.isPack() && !shopEatTypeInfoDTO.isTakeout()) {
tbCashierCart.setPackFee(BigDecimal.ZERO);
} else {
tbCashierCart.setPackFee(product.getPackFee() != null ?
product.getPackFee().multiply(BigDecimal.valueOf(addCartDTO.getNum())) : BigDecimal.ZERO);
product.getPackFee().multiply(addCartDTO.getNum()) : BigDecimal.ZERO);
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
}
@@ -570,22 +578,22 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setCategoryId(product.getCategoryId());
tbCashierCart.setNote(addCartDTO.getNote());
tbCashierCart.setPlatformType(OrderPlatformTypeEnum.PC.getValue());
// tbCashierCart.setIsMember(shopEatTypeInfoDTO.isMemberPrice() && addCartDTO.getVipUserId() == null ? 0 : 1);
tbCashierCart.setIsMember(addCartDTO.getVipUserId() == null ? 0 : 1);
tbCashierCart.setIsMember(shopEatTypeInfoDTO.isMemberPrice() && addCartDTO.getVipUserId() != null ? 1 : 0);
// tbCashierCart.setIsMember(addCartDTO.getVipUserId() == null ? 0 : 1);
if (tbCashierCart.getIsMember() == 1) {
tbCashierCart.setMemberPrice(productSku.getMemberPrice());
}
cashierCartRepository.save(tbCashierCart);
} else {
tbCashierCart.setIsMember(addCartDTO.getVipUserId() == null ? 0 : 1);
tbCashierCart.setIsMember(shopEatTypeInfoDTO.isMemberPrice() && addCartDTO.getVipUserId() != null ? 1 : 0);
tbCashierCart.setNote(addCartDTO.getNote());
tbCashierCart.setTotalAmount(new BigDecimal(addCartDTO.getNum()).multiply(productSku.getSalePrice()));
tbCashierCart.setTotalAmount(addCartDTO.getNum().multiply(productSku.getSalePrice()));
if (!addCartDTO.isPack()) {
tbCashierCart.setPackFee(BigDecimal.ZERO);
} else {
tbCashierCart.setPackFee(new BigDecimal(addCartDTO.getNum()).multiply(product.getPackFee()));
tbCashierCart.setPackFee(addCartDTO.getNum().multiply(product.getPackFee()));
tbCashierCart.setTotalAmount(tbCashierCart.getTotalAmount().add(tbCashierCart.getPackFee()));
}
@@ -602,7 +610,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 设置打包费
if (shopEatTypeInfoDTO.isTakeout()) {
tbCashierCart.setPackFee(product.getPackFee() != null ?
product.getPackFee().multiply(BigDecimal.valueOf(addCartDTO.getNum())) : BigDecimal.ZERO);
product.getPackFee().multiply(addCartDTO.getNum()) : BigDecimal.ZERO);
}
cashierCartMapper.updateById(tbCashierCart);
}
@@ -617,7 +625,58 @@ public class TbShopTableServiceImpl implements TbShopTableService {
@Override
public TbCashierCart addTemporaryDishes(AddTemporaryDishesDTO temporaryDishesDTO) {
return null;
temporaryDishesDTO.setTableId(OrderUseTypeEnum.TAKEOUT.getValue().equals(temporaryDishesDTO.getUseType()) ? null : temporaryDishesDTO.getTableId());
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(temporaryDishesDTO.getShopId(), temporaryDishesDTO.getTableId(), temporaryDishesDTO.getUseType());
TbCashierCart tbCashierCart = mpCashierCartService.selectOneCartByShopEatType(shopEatTypeInfoDTO, temporaryDishesDTO.getMasterId(), null, null, false, true);
// 首次加入
if (tbCashierCart == null) {
tbCashierCart = new TbCashierCart();
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setIsSku("0");
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
tbCashierCart.setTableId(shopEatTypeInfoDTO.getTableId());
}
tbCashierCart.setName(temporaryDishesDTO.getName());
tbCashierCart.setSalePrice(temporaryDishesDTO.getPrice());
tbCashierCart.setMasterId(temporaryDishesDTO.getMasterId());
tbCashierCart.setShopId(String.valueOf(temporaryDishesDTO.getShopId()));
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setIsPack("false");
tbCashierCart.setIsGift("false");
tbCashierCart.setTotalAmount(temporaryDishesDTO.getNum().multiply(temporaryDishesDTO.getPrice()));
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setTotalNumber(temporaryDishesDTO.getNum());
tbCashierCart.setNumber(temporaryDishesDTO.getNum());
tbCashierCart.setCategoryId(String.valueOf(temporaryDishesDTO.getCategoryId()));
tbCashierCart.setNote(temporaryDishesDTO.getNote());
tbCashierCart.setPlatformType(OrderPlatformTypeEnum.PC.getValue());
tbCashierCart.setIsMember(shopEatTypeInfoDTO.isMemberPrice() && temporaryDishesDTO.getVipUserId() != null ? 1 : 0);
tbCashierCart.setIsTemporary(1);
tbCashierCart.setUnit(temporaryDishesDTO.getUnit());
cashierCartRepository.save(tbCashierCart);
} else {
tbCashierCart.setIsMember(temporaryDishesDTO.getVipUserId() == null ? 0 : 1);
tbCashierCart.setNote(temporaryDishesDTO.getNote());
tbCashierCart.setTotalAmount(temporaryDishesDTO.getNum().multiply(temporaryDishesDTO.getPrice()));
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setIsPack("false");
tbCashierCart.setIsGift("false");
tbCashierCart.setTotalNumber(temporaryDishesDTO.getNum());
tbCashierCart.setNumber(temporaryDishesDTO.getNum());
tbCashierCart.setUpdatedAt(DateUtil.current());
tbCashierCart.setIsTemporary(1);
tbCashierCart.setUnit(temporaryDishesDTO.getUnit());
cashierCartMapper.updateById(tbCashierCart);
}
if (StrUtil.isNotBlank(temporaryDishesDTO.getTableId())) {
setRedisTableCartInfo(temporaryDishesDTO.getTableId(), temporaryDishesDTO.getShopId().toString(), Collections.singletonList(tbCashierCart), true);
}
return tbCashierCart;
}
private void setRedisTableCartInfo(String tableId, String shopId, List<TbCashierCart> tbCashierCartList, boolean isAdd) {
@@ -704,7 +763,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("购物车商品不存在或已退单");
}
if (removeCartDTO.getNum() > cashierCart.getNumber()) {
if (removeCartDTO.getNum().compareTo(cashierCart.getNumber()) > 0) {
throw new BadRequestException("最大退菜数量为: {}", cashierCart.getNumber());
}
@@ -732,8 +791,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getShopId, removeCartDTO.getShopId())
.eq(TbOrderDetail::getCartId, cashierCart.getId())
.eq(TbOrderDetail::getProductId, cashierCart.getProductId())
.eq(TbOrderDetail::getProductSkuId, cashierCart.getSkuId())
.eq(TbOrderDetail::getOrderId, cashierCart.getOrderId()));
if (tbOrderDetail == null) {
throw new BadRequestException("购物车商品不存在或已退单");
@@ -755,7 +812,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
returnCart.setNumber(removeCartDTO.getNum());
returnCart.setId(null);
returnCart.setTotalNumber(removeCartDTO.getNum());
BigDecimal returnCartAmount = returnCart.getSalePrice().multiply(BigDecimal.valueOf(returnCart.getNumber()));
BigDecimal returnCartAmount = returnCart.getSalePrice().multiply(returnCart.getNumber());
returnCart.setTotalAmount(returnCartAmount);
returnCart.setStatus("return");
cashierCartMapper.insert(returnCart);
@@ -771,8 +828,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
returnOrderDetail.setRefundRemark(removeCartDTO.getNote());
orderDetailMapper.insert(returnOrderDetail);
cashierCartMapper.updateNumAmountStatus(cashierCart.getId(), cashierCart.getStatus(), -returnCart.getNumber());
orderDetailMapper.updateNumAmountStatus(orderDetail.getId(), orderDetail.getStatus(), -returnCart.getNumber());
cashierCartMapper.updateNumAmountStatus(cashierCart.getId(), cashierCart.getStatus(), returnCart.getNumber().negate());
orderDetailMapper.updateNumAmountStatus(orderDetail.getId(), orderDetail.getStatus(), returnCart.getNumber().negate());
if (TableConstant.OrderInfo.UseType.DINE_IN_AFTER.equalsVals(tbOrderDetail.getUseType()) && !isSeatCart) {
rabbitMsgUtils.printDishesTicket(returnOrderDetail.getOrderId(), true, returnOrderDetail);
}
@@ -782,9 +839,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (cashierCart.getOrderId() != null) {
// 减少订单金额
orderInfoMapper.updateOrderAmount(cashierCart.getOrderId(), orderDetail.getPriceAmount().divide(BigDecimal.valueOf(orderDetail.getNum()), RoundingMode.HALF_UP)
.multiply(BigDecimal.valueOf(removeCartDTO.getNum())), orderDetail.getPackAmount().divide(BigDecimal.valueOf(orderDetail.getNum()), RoundingMode.HALF_UP)
.multiply(BigDecimal.valueOf(removeCartDTO.getNum())));
orderInfoMapper.updateOrderAmount(cashierCart.getOrderId(), orderDetail.getPriceAmount().divide(orderDetail.getNum(), RoundingMode.HALF_UP)
.multiply(removeCartDTO.getNum()), orderDetail.getPackAmount().divide(orderDetail.getNum(), RoundingMode.HALF_UP)
.multiply(removeCartDTO.getNum()));
}
@@ -847,7 +904,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbCashierCart> records = cartPage.getRecords();
ArrayList<Integer> skuIds = new ArrayList<>();
records.forEach(item -> skuIds.add(Integer.valueOf(item.getSkuId())));
records.forEach(item -> {
if (item.getSkuId() != null) {
skuIds.add(Integer.valueOf(item.getSkuId()));
}
});
AtomicReference<TbCashierCart> mealCashierCart = new AtomicReference<>();
@@ -858,7 +919,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
ArrayList<Map<String, Object>> infos = new ArrayList<>();
records.forEach(item -> {
if (item.getProductId().equals("-999")) {
if (item.getProductId() != null && item.getProductId().equals("-999")) {
mealCashierCart.set(item);
return;
}
@@ -927,7 +988,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
* @param skuId sku
* @param addNum 增加的库存数量
*/
public void incrStock(Integer productId, Integer skuId, Integer addNum) {
public void incrStock(Integer productId, Integer skuId, BigDecimal addNum) {
productMapper.incrStock(productId, addNum);
}
@@ -938,7 +999,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
* @param skuId sku
* @param decrNum 减少的数量
*/
public void decrStock(Integer productId, String skuId, int decrNum) {
public void decrStock(Integer productId, String skuId, BigDecimal decrNum) {
TbProduct product = productMapper.selectById(productId);
if (product.getIsStock() == 1) {
if (productMapper.decrStock(productId, decrNum) < 1) {
@@ -983,14 +1044,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (cashierCart.getOrderId() != null) {
String message = redisTemplate.opsForValue().get(RedisConstant.ORDER_PRODUCT_NUM + cashierCart.getId());
if (message != null) {
int lastNum = Integer.parseInt(message);
BigDecimal lastNum = new BigDecimal(message);
// 数量减少, 返还库存
if (lastNum > cashierCart.getNumber()) {
incrStock(Integer.parseInt(cashierCart.getProductId()), Integer.parseInt(cashierCart.getSkuId()), lastNum - cashierCart.getNumber());
if (lastNum.compareTo(cashierCart.getNumber()) > 0) {
incrStock(Integer.parseInt(cashierCart.getProductId()), Integer.parseInt(cashierCart.getSkuId()), lastNum.subtract(cashierCart.getNumber()));
} else {
decrStock(Integer.parseInt(cashierCart.getProductId()), cashierCart.getSkuId(), cashierCart.getNumber() - lastNum);
decrStock(Integer.parseInt(cashierCart.getProductId()), cashierCart.getSkuId(), cashierCart.getNumber().subtract(lastNum));
}
redisTemplate.opsForValue().set(RedisConstant.ORDER_PRODUCT_NUM + cashierCart.getId(), cashierCart.getNumber().toString(), 24 * 60 * 60, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(RedisConstant.ORDER_PRODUCT_NUM + cashierCart.getId(), cashierCart.getNumber().toPlainString(), 24 * 60 * 60, TimeUnit.SECONDS);
}
return false;
@@ -1036,7 +1097,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
*
* @param productSku sku
*/
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer shopId, Integer num) {
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer shopId, BigDecimal num) {
TbShopInfo shopInfo = shopInfoRepository.getById(shopId);
if (product.getWarnLine() == null) {
return;
@@ -1049,9 +1110,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (product.getStockNumber() == null) {
product.setStockNumber(0);
}
if (product.getStockNumber() - num <= product.getWarnLine()) {
if (product.getStockNumber() - num.doubleValue() <= product.getWarnLine()) {
wxMsgUtils.aboardStockMsg(shopInfo.getShopName(), shopId, product.getName(),
product.getStockNumber() - num);
product.getStockNumber() - num.doubleValue());
}
}
@@ -1207,7 +1268,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbUserCouponVo> tbUserCouponVos = couponMap.get(productId);
if (tbUserCouponVos == null || tbUserCouponVos.isEmpty()) return null;
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
if (tbUserCouponVo.getCurrentUseNum() > 0) {
if (tbUserCouponVo.getCurrentUseNum().compareTo(BigDecimal.ZERO) > 0) {
return tbUserCouponVo;
}
}
@@ -1218,22 +1279,22 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbUserCouponVo>> usedCouponMap, BigDecimal discountAmount, ArrayList<TbCashierCart> balanceCartList,
ArrayList<TbActivateOutRecord> outRecords, Integer memberId) {
TbUserCouponVo couponVo = getCanUseCoupon(couponMap, cashierCart.getProductId());
if (couponVo != null && couponVo.getCurrentUseNum() > 0) {
if (couponVo != null && couponVo.getCurrentUseNum().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal currentUseNum;
List<TbUserCouponVo> tbUserCouponVos = usedCouponMap.computeIfAbsent(Integer.valueOf(cashierCart.getProductId()), k -> new ArrayList<>());
tbUserCouponVos.add(couponVo);
TbCashierCart balanceCart = null;
if (cashierCart.getNumber() < couponVo.getCurrentUseNum()) {
if (cashierCart.getNumber().compareTo(couponVo.getCurrentUseNum()) < 0) {
cashierCart.setUserCouponId(couponVo.getId());
discountAmount = discountAmount.add(cashierCart.getTotalAmountByNum(null));
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
currentUseNum = BigDecimal.valueOf(cashierCart.getNumber());
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum().subtract(cashierCart.getNumber()));
currentUseNum = cashierCart.getNumber();
// 优惠券数量小于购物车数量,分割购物车数据
}else if (cashierCart.getNumber() > couponVo.getCurrentUseNum()) {
currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum());
BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber());
int balanceNum = cashierCart.getTotalNumber() - couponVo.getCurrentUseNum();
}else if (cashierCart.getNumber().compareTo(couponVo.getCurrentUseNum()) > 0) {
currentUseNum = couponVo.getCurrentUseNum();
BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber().intValue());
BigDecimal balanceNum = cashierCart.getTotalNumber().subtract(couponVo.getCurrentUseNum());
BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP);
cashierCart.setPackFee(singlePackFee.multiply(currentUseNum));
BigDecimal totalAmountByNum = cashierCart.getTotalAmountByNum(couponVo.getCurrentUseNum());
@@ -1242,14 +1303,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
cashierCart.setTotalNumber(couponVo.getCurrentUseNum());
cashierCart.setUserCouponId(couponVo.getId());
discountAmount = discountAmount.add(totalAmountByNum);
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
currentUseNum = BigDecimal.valueOf(cashierCart.getNumber());
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum().subtract(cashierCart.getNumber()));
currentUseNum = cashierCart.getNumber();
// 创建结余购物车
balanceCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class);
BigDecimal num = BigDecimal.valueOf(balanceNum);
BigDecimal num = balanceNum;
balanceCart.setUserCouponId(null);
balanceCart.setId(null);
balanceCart.setNumber(balanceNum);
@@ -1258,10 +1319,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
balanceCart.setTotalAmount(cashierCart.getTotalAmountByNum(balanceNum).add(singlePackFee.multiply(num)));
balanceCartList.add(balanceCart);
} else {
currentUseNum = BigDecimal.valueOf(cashierCart.getNumber());
currentUseNum =cashierCart.getNumber();
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
cashierCart.setUserCouponId(couponVo.getId());
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum().subtract(cashierCart.getNumber()));
}
// 消耗并返还商品优惠券
Integer shopId = Integer.valueOf(cashierCart.getShopId());
@@ -1291,7 +1352,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
BigDecimal discountAmount = BigDecimal.ZERO;
HashMap<String, List<TbUserCouponVo>> couponMap = new HashMap<>();
couponInfoDTO.getProductCouponMap().values().forEach(item -> {
if (item.getCurrentUseNum() <= 0) {
if (item.getCurrentUseNum().compareTo(BigDecimal.ZERO) <= 0) {
return;
}
List<TbUserCouponVo> tbUserCouponVos = couponMap.get(item.getProId().toString());
@@ -1305,7 +1366,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
});
HashMap<Integer, List<TbUserCouponVo>> usedCouponMap = new HashMap<>();
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
ArrayList<TbCashierCart> resetCouponList = new ArrayList<>();
for (TbCashierCart cashierCart : newCashierCarts) {
if (!couponMap.isEmpty()) {
resetCouponList.add(cashierCart);
cashierCart.setUserCouponId(null);
}
discountAmount = reduceProCoupon(couponMap, cashierCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId);
}
@@ -1314,6 +1380,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
mpCashierCartService.saveBatch(balanceCartList);
}
// 更新购物车信息
if (!resetCouponList.isEmpty()) {
// 取消之前使用的历史券
ArrayList<Integer> resetCartIds = new ArrayList<>();
resetCouponList.forEach(item -> {
if (item.getUserCouponId() == null) {
resetCartIds.add(item.getId());
}
});
if (!resetCartIds.isEmpty()) {
mpCashierCartService.update(new LambdaUpdateWrapper<TbCashierCart>()
.in(TbCashierCart::getId, resetCartIds)
.set(TbCashierCart::getUserCouponId, null));
}
}
mpCashierCartService.updateBatchById(newCashierCarts);
couponInfoDTO.setOutRecordList(outRecords);
@@ -1353,7 +1433,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (couponVo.getNum() < item.getNum()) {
throw new BadRequestException(couponVo.getName() + "数量不足: " + couponVo.getNum());
}
couponVo.setCurrentUseNum(item.getNum());
couponVo.setCurrentUseNum(BigDecimal.valueOf(item.getNum()));
infoDTO.getFullReductionCouponMap().put(couponVo.getId(), couponVo);
return;
}
@@ -1361,7 +1441,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (couponVo == null) {
throw new BadRequestException("存在不可用优惠券");
}
couponVo.setCurrentUseNum(item.getNum());
couponVo.setCurrentUseNum(BigDecimal.valueOf(item.getNum()));
couponVo.setFinalUseNum(item.getNum());
infoDTO.getProductCouponMap().put(item.getUserCouponId(), couponVo);
});
@@ -1490,7 +1570,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
priceDTO.setOriginAmount(priceDTO.getOriginAmount().add(cashierCart.getTotalAmount()));
}
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
TbOrderDetail orderDetail = null;
if (cashierCart.getOrderId() != null) {
orderDetail = oldOrderDetailMap.get(cashierCart.getOrderId().toString() + cashierCart.getId());
@@ -1502,8 +1581,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
priceDTO.getNewOrderDetailList().add(orderDetail);
}
if (Objects.nonNull(productSku)) {
orderDetail.setProductSkuName(productSku.getSpecSnap());
if (cashierCart.getIsTemporary() == null || cashierCart.getIsTemporary() == 0) {
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
if (Objects.nonNull(productSku)) {
orderDetail.setProductSkuName(productSku.getSpecSnap());
}
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
}
orderDetail.setUserCouponId(cashierCart.getUserCouponId());
@@ -1513,8 +1598,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderDetail.setNum(cashierCart.getNumber());
orderDetail.setPrice(cashierCart.getSalePrice());
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
orderDetail.setProductName(cashierCart.getName());
orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId()));
orderDetail.setPackAmount(cashierCart.getPackFee());
@@ -1525,6 +1608,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderDetail.setProductImg(cashierCart.getCoverImg());
orderDetail.setCartId(cashierCart.getId());
orderDetail.setIsMember(cashierCart.getIsMember());
orderDetail.setIsTemporary(cashierCart.getIsTemporary());
orderDetail.setOrderId(orderInfo == null ? null : orderInfo.getId());
priceDTO.getOrderDetailList().add(orderDetail);
}
@@ -1572,7 +1656,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderInfo.setUseType(eatTypeInfoDTO.getUseType());
if (seatCart != null) {
orderInfo.setSeatAmount(seatCart.getTotalAmount());
orderInfo.setSeatCount(seatCart.getNumber());
orderInfo.setSeatCount(seatCart.getNumber().intValue());
}
if (createOrderDTO.getVipUserId() != null) {
orderInfo.setMemberId(String.valueOf(shopUser.getId()));
@@ -1631,7 +1715,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private void updateCartAndStock(List<TbCashierCart> newAddCashierCarts, TbOrderInfo orderInfo, ShopEatTypeInfoDTO shopEatTypeInfoDTO) {
// 更新购物车记录的orderId
for (TbCashierCart cashierCart : newAddCashierCarts) {
if (!"-999".equals(cashierCart.getProductId())) {
// 不为座位费临时菜扣除库存
if (!"-999".equals(cashierCart.getProductId()) && cashierCart.getIsTemporary() != null && cashierCart.getIsTemporary() == 0) {
TbProduct product = productMapper.selectById(cashierCart.getProductId());
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
@@ -1921,7 +2006,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbActivateOutRecord.setGiveId(couponVo.getId());
tbActivateOutRecord.setVipUserId(payDTO.getVipUserId());
tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
tbActivateOutRecord.setUseNum(couponVo.getCurrentUseNum());
tbActivateOutRecord.setUseNum(couponVo.getCurrentUseNum().intValue());
tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
tbActivateOutRecord.setCreateTime(DateUtil.date());
tbActivateOutRecord.setRefNum(0);
@@ -2372,6 +2457,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
}
choseCountDTO.setUseType(!TableConstant.OrderInfo.UseType.TAKEOUT.equalsVals(choseCountDTO.getUseType())
&& StrUtil.isBlank(choseCountDTO.getTableId()) ? TableConstant.OrderInfo.UseType.NONE_TABLE.getValue() : choseCountDTO.getUseType());
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, choseCountDTO.getShopId())
.and(q -> q.eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId).or().eq(TbCashierCart::getMasterId, ""))
@@ -2399,16 +2487,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setNumber(BigDecimal.valueOf(choseCountDTO.getNum()));
tbCashierCart.setTotalNumber(BigDecimal.valueOf(choseCountDTO.getNum()));
tbCashierCart.setUseType(choseCountDTO.getUseType());
tbCashierCartMapper.insert(tbCashierCart);
} else {
tbCashierCart.setMemberPrice(shopInfo.getTableFee());
tbCashierCart.setStatus(TableConstant.CashierCart.Status.CREATE.getValue());
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setNumber(BigDecimal.valueOf(choseCountDTO.getNum()));
tbCashierCart.setTotalNumber(BigDecimal.valueOf(choseCountDTO.getNum()));
tbCashierCart.setUseType(choseCountDTO.getUseType());
tbCashierCartMapper.updateById(tbCashierCart);
}
@@ -2530,7 +2618,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
mpCashierCartService.update(new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getId, item.getId())
.set(TbCashierCart::getPackFee, product.getPackFee() != null ?
product.getPackFee().multiply(BigDecimal.valueOf(item.getNumber())) : BigDecimal.ZERO)
product.getPackFee().multiply(item.getNumber()) : BigDecimal.ZERO)
.set(TbCashierCart::getTableId, null)
.set(TbCashierCart::getUseType, OrderUseTypeEnum.TAKEOUT.getValue())
.set(TbCashierCart::getIsPack, "true"));
@@ -2545,7 +2633,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
TbProduct product = productMap.get(item.getProductId().toString());
// 设置打包费
item.setPackAmount(product.getPackFee() != null ?
product.getPackFee().multiply(BigDecimal.valueOf(item.getNum())) : BigDecimal.ZERO);
product.getPackFee().multiply(item.getNum()) : BigDecimal.ZERO);
});
if (!detailList.isEmpty()) {
@@ -2570,7 +2658,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private HashMap<String, Object> updateReturnOrderInfo(ReturnOrderDTO returnOrderDTO, TbOrderInfo oldOrderInfo, boolean isOnline) {
ArrayList<Integer> detailIds = new ArrayList<>();
HashMap<String, Integer> returnNumMap = new HashMap<>();
HashMap<String, BigDecimal> returnNumMap = new HashMap<>();
returnOrderDTO.getOrderDetails().forEach(item -> {
detailIds.add(item.getId());
returnNumMap.put(item.getId().toString(), item.getNum());
@@ -2592,20 +2680,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (orderDetail.getUserCouponId() != null) {
throw new BadRequestException("选择了优惠券抵扣商品,无法退款");
}
Integer returnNum = returnNumMap.get(orderDetail.getId().toString());
int remainNum = orderDetail.getNum() - returnNum;
if (remainNum < 0) {
BigDecimal returnNum = returnNumMap.get(orderDetail.getId().toString());
BigDecimal remainNum = orderDetail.getNum().subtract(returnNum);
if (remainNum.compareTo(BigDecimal.ZERO) < 0) {
throw new BadRequestException("{}最多可退数量为: {}", orderDetail.getProductName(), orderDetail.getNum());
}
// 将未退款的剩余订单详情重新生成记录
BigDecimal packFee = orderDetail.getPackAmount().divide(BigDecimal.valueOf(orderDetail.getNum()), RoundingMode.HALF_UP);
if (remainNum > 0) {
BigDecimal packFee = orderDetail.getPackAmount().divide(orderDetail.getNum(), RoundingMode.HALF_UP);
if (remainNum.compareTo(BigDecimal.ZERO) > 0) {
// 单个打包费
BigDecimal remainPackFee = packFee.multiply(BigDecimal.valueOf(remainNum));
BigDecimal remainPackFee = packFee.multiply(remainNum);
TbOrderDetail remainOrderDetail = BeanUtil.copyProperties(orderDetail, TbOrderDetail.class);
remainOrderDetail.setNum(remainNum);
remainOrderDetail.setPriceAmount(BigDecimal.valueOf(remainNum).multiply(orderDetail.getPrice())
remainOrderDetail.setPriceAmount(remainNum.multiply(orderDetail.getPrice())
.add(remainPackFee));
remainOrderDetail.setPackAmount(remainPackFee);
remainOrderDetail.setReturnNum("0");
@@ -2614,16 +2702,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
}
returnAmount = returnAmount.add(orderDetail.getPriceAmount()
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
.multiply(BigDecimal.valueOf(returnNum)));
.divide(orderDetail.getNum(), 2, RoundingMode.DOWN)
.multiply(returnNum));
saleAmount = saleAmount.add(orderDetail.getPrice());
packAMount = packAMount.add(orderDetail.getPackAmount()
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
.multiply(BigDecimal.valueOf(returnNum)));
.divide(orderDetail.getNum(), 2, RoundingMode.DOWN)
.multiply(returnNum));
BigDecimal returnPackFee = packFee.multiply(BigDecimal.valueOf(returnNum));
BigDecimal returnPackFee = packFee.multiply(returnNum);
orderDetail.setNum(returnNum);
orderDetail.setPriceAmount(BigDecimal.valueOf(returnNum).multiply(orderDetail.getPrice())
orderDetail.setPriceAmount(returnNum.multiply(orderDetail.getPrice())
.add(returnPackFee));
orderDetail.setPackAmount(returnPackFee);
orderDetail.setRefundNumber(returnNum);
@@ -2702,7 +2790,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
productMapper.incrStock(product.getId(), detail.getNum());
tbProductStockDetail.setLeftNumber(product.getStockNumber());
tbProductStockDetail.setStockNumber(Double.valueOf(detail.getNum()));
tbProductStockDetail.setStockNumber(detail.getNum().doubleValue());
producSkutMapper.decrRealSalesNumber(productSku.getId(), detail.getNum());
}

View File

@@ -8,6 +8,7 @@ import cn.ysk.cashier.dto.product.TbProductDto;
import cn.ysk.cashier.dto.product.TbProductQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.math.BigDecimal;
import java.util.Map;
import java.util.List;
import java.io.IOException;
@@ -96,7 +97,7 @@ public interface TbProductService {
* @param productId 商品id
* @param number 增加数量
*/
void incrStockNumber(String productId, Integer number);
void incrStockNumber(String productId, BigDecimal number);
/**
* 返还库存
@@ -104,7 +105,7 @@ public interface TbProductService {
* @param productSkuId sku
* @param num 数量
*/
void returnStockByPro(Integer productId, Integer productSkuId, Integer num);
void returnStockByPro(Integer productId, Integer productSkuId, BigDecimal num);
Object activateProduct(Integer page, Integer size, Integer categoryId, Integer shopId, Integer productId);
}

View File

@@ -133,10 +133,10 @@ public class WxAccountUtil {
}
public void sendStockMsg(String shopName, String productName, int stock, String openId, ShopWxMsgTypeEnum shopWxMsgTypeEnum, Integer shopId) {
public void sendStockMsg(String shopName, String productName, double stock, String openId, ShopWxMsgTypeEnum shopWxMsgTypeEnum, Integer shopId) {
stock = Math.max(stock, 0);
Integer finalStock = stock;
double finalStock = stock;
Map<String, Object> data = new HashMap<String, Object>() {{
put("thing22", new HashMap<String, Object>() {{
put("value", shopName);

View File

@@ -95,11 +95,11 @@ public class WxMsgUtils {
}
}
public void aboardStockMsg(String shopName, Integer shopId, String proName, Integer stock) {
public void aboardStockMsg(String shopName, Integer shopId, String proName, double stock) {
if (!checkIsOpen(shopId, ShopWxMsgTypeEnum.OPERATION_MSG)) {
return;
}
List<TbShopOpenId> openIds = tbShopOpenIdService.lambdaQuery()
.eq(TbShopOpenId::getShopId, shopId)
.eq(TbShopOpenId::getStatus, 1)

View File

@@ -1,30 +0,0 @@
package cn.ysk.cashier.vo;
import lombok.Data;
import org.hibernate.annotations.Formula;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* @author lyf
*/
@Data
public class ProductExtVO {
private BigInteger productId;
private String productName;
private Object productNum;
private Object amount;
public ProductExtVO(BigInteger productId, String productName, Object productNum, Object amount) {
this.productId = productId;
this.productName = productName;
this.productNum = productNum;
this.amount = amount;
}
public ProductExtVO() {
}
}

View File

@@ -14,14 +14,14 @@ public class TbOrderSalesCountByDayV2Vo {
private String cateName;
private String typeEnum;
private Long salesNum;
private Long refNum;
private BigDecimal salesNum;
private BigDecimal refNum;
private BigDecimal salesAmount;
private BigDecimal refAmount;
List<TbOrderSalesCountByDayV2Vo> skus = new ArrayList<>();
public TbOrderSalesCountByDayV2Vo(String name, Integer productId, String cateName,String typeEnum, Long salesNum, Long refNum, BigDecimal salesAmount, BigDecimal refAmount) {
public TbOrderSalesCountByDayV2Vo(String name, Integer productId, String cateName,String typeEnum, BigDecimal salesNum, BigDecimal refNum, BigDecimal salesAmount, BigDecimal refAmount) {
this.name = name;
this.productId = productId;
this.typeEnum = typeEnum;

View File

@@ -12,21 +12,21 @@ public class TbOrderSalesCountByDayVo {
private String cateName;
private String unitName;
private BigDecimal price;
private Long salesNum;
private Long refNum;
private BigDecimal salesNum;
private BigDecimal refNum;
private BigDecimal salesAmount;
private BigDecimal refAmount;
private Long num;
private BigDecimal num;
private Integer productId;
private Integer productSkuId;
public TbOrderSalesCountByDayVo(Long salesNum, Long refNum) {
public TbOrderSalesCountByDayVo(BigDecimal salesNum, BigDecimal refNum) {
this.salesNum = salesNum;
this.refNum = refNum;
}
public TbOrderSalesCountByDayVo(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
BigDecimal salesNum, BigDecimal refNum, BigDecimal num, BigDecimal salesAmount, BigDecimal refAmount) {
this.productName = productName;
this.productSkuName = productSkuName;
this.cateName = cateName;
@@ -42,7 +42,7 @@ public class TbOrderSalesCountByDayVo {
public TbOrderSalesCountByDayVo(String productName, String productSkuName,
String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount, Integer productId, Integer productSkuId) {
BigDecimal salesNum, BigDecimal refNum, BigDecimal num, BigDecimal salesAmount, BigDecimal refAmount, Integer productId, Integer productSkuId) {
this.productName = productName;
this.productSkuName = productSkuName;
this.cateName = cateName;
@@ -58,7 +58,7 @@ public class TbOrderSalesCountByDayVo {
count();
}
public TbOrderSalesCountByDayVo(Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
public TbOrderSalesCountByDayVo(BigDecimal salesNum, BigDecimal refNum, BigDecimal num, BigDecimal salesAmount, BigDecimal refAmount) {
this.salesNum = salesNum;
this.refNum = refNum;
this.salesAmount = salesAmount;
@@ -68,9 +68,9 @@ public class TbOrderSalesCountByDayVo {
}
public void count(){
if (salesNum == null) salesNum = 0l;
if (refNum == null) refNum = 0l;
salesNum = salesNum - refNum;
if (salesNum == null) salesNum = BigDecimal.ZERO;
if (refNum == null) refNum = BigDecimal.ZERO;
salesNum = salesNum.subtract(refNum);
if (salesAmount == null) salesAmount = BigDecimal.ZERO;
if (refAmount == null) refAmount = BigDecimal.ZERO;
salesAmount = salesAmount.subtract(refAmount);

View File

@@ -14,17 +14,17 @@ public class TbOrderSalesCountByTable {
private String cateName;
private String unitName;
private BigDecimal price;
private Long salesNum;
private Long refNum;
private BigDecimal salesNum;
private BigDecimal refNum;
private BigDecimal salesAmount;
private BigDecimal refAmount;
private Long num;
private BigDecimal num;
private Integer productId;
private Integer productSkuId;
private String tableId;
public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
BigDecimal salesNum, BigDecimal refNum, BigDecimal num, BigDecimal salesAmount, BigDecimal refAmount) {
this.productName = productName;
this.productSkuName = productSkuName;
this.cateName = cateName;
@@ -39,7 +39,7 @@ public class TbOrderSalesCountByTable {
}
public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount,
BigDecimal salesNum, BigDecimal refNum, BigDecimal num, BigDecimal salesAmount, BigDecimal refAmount,
Integer productId, Integer productSkuId, String tableId) {
this.productName = productName;
this.productSkuName = productSkuName;
@@ -58,7 +58,7 @@ public class TbOrderSalesCountByTable {
}
public void count(){
salesNum=salesNum-refNum;
salesNum= salesNum.subtract(refNum);
salesAmount=salesAmount.subtract(refAmount);
}

View File

@@ -25,27 +25,16 @@ public class TbProductVo {
private Integer id;
private String sourcePath;
private String merchantId;
private String shopId;
private String name;
private String type;
private BigDecimal packFee;
private BigDecimal lowPrice;
private Integer unitId;
private String coverImg;
@@ -56,155 +45,54 @@ public class TbProductVo {
private Integer specId;
private Integer brandId;
private String shortTitle;
private BigDecimal lowMemberPrice;
private String unitSnap;
private String shareImg;
private JSONArray images;
private String video;
private String videoCoverImg;
private Integer sort;
private Integer limitNumber;
private Integer productScore;
private Integer status;
private String failMsg;
private Integer isRecommend;
private Integer isHot;
private Integer isNew;
private Integer isOnSale;
private Integer isShow;
private String typeEnum;
private Integer isDel;
private Integer isStock;
private Integer isPauseSale;
private Integer isFreeFreight;
private Long freightId;
private String strategyType;
private Integer strategyId;
private Integer isVip;
private Integer isDelete;
private String notice;
private Long createdAt;
private Long updatedAt;
private Double baseSalesNumber;
//销量
private Double realSalesNumber;
//库存
private Double stockNumber;
private Integer salesNumber;
private Integer thumbCount;
private Integer storeCount;
private Integer furnishMeal;
private Double realSalesNumber;
private Double stockNumber;
private Integer furnishExpress;
private Integer furnishDraw;
private Integer furnishVir;
private Integer isCombo;
private JSONArray groupSnap;
private Integer isShowCash;
private Integer isShowMall;
private Integer isNeedExamine;
private Integer showOnMallStatus;
private Long showOnMallTime;
private String showOnMallErrorMsg;
private Integer enableLabel;
private String taxConfigId;
private String unitName;
private List<TbProductSku> skuList;

View File

@@ -28,7 +28,7 @@ public class TbUserCouponVo {
private String useRestrictions;
private boolean isUse = false;
//当前使用数量
private Integer currentUseNum;
private BigDecimal currentUseNum;
private Integer finalUseNum;
private BigDecimal finalDiscountAmount = new BigDecimal(0);