Commit 055a150d authored by shiyu's avatar shiyu

限购

parent 458d6bd5
package com.wwdz.ch.db.domain.distribution; package com.wwdz.ch.db.domain.distribution;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import com.xxdxxs.entity.Entity; import com.xxdxxs.entity.Entity;
import lombok.Data; import lombok.Data;
/** /**
* @author shiyu * @author shiyu
* @date 2024/01/24 * @date 2024/02/19
*/ */
@Data @Data
public class SupplierItem implements Entity { public class SupplierItem implements Entity {
...@@ -69,6 +71,11 @@ public class SupplierItem implements Entity { ...@@ -69,6 +71,11 @@ public class SupplierItem implements Entity {
*/ */
private Boolean isDeleted; private Boolean isDeleted;
/**
* 限购数量
*/
private Integer buyLimitNum;
/** /**
* 商品图片,分号分隔 * 商品图片,分号分隔
*/ */
...@@ -104,6 +111,7 @@ public class SupplierItem implements Entity { ...@@ -104,6 +111,7 @@ public class SupplierItem implements Entity {
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);
sb.append(", isDeleted=").append(isDeleted); sb.append(", isDeleted=").append(isDeleted);
sb.append(", buyLimitNum=").append(buyLimitNum);
sb.append(", images=").append(images); sb.append(", images=").append(images);
sb.append(", videos=").append(videos); sb.append(", videos=").append(videos);
sb.append(", description=").append(description); sb.append(", description=").append(description);
...@@ -136,6 +144,7 @@ public class SupplierItem implements Entity { ...@@ -136,6 +144,7 @@ public class SupplierItem implements Entity {
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted())) && (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()))
&& (this.getBuyLimitNum() == null ? other.getBuyLimitNum() == null : this.getBuyLimitNum().equals(other.getBuyLimitNum()))
&& (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages())) && (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages()))
&& (this.getVideos() == null ? other.getVideos() == null : this.getVideos().equals(other.getVideos())) && (this.getVideos() == null ? other.getVideos() == null : this.getVideos().equals(other.getVideos()))
&& (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription())); && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()));
...@@ -157,6 +166,7 @@ public class SupplierItem implements Entity { ...@@ -157,6 +166,7 @@ public class SupplierItem implements Entity {
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode()); result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
result = prime * result + ((getBuyLimitNum() == null) ? 0 : getBuyLimitNum().hashCode());
result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode()); result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode());
result = prime * result + ((getVideos() == null) ? 0 : getVideos().hashCode()); result = prime * result + ((getVideos() == null) ? 0 : getVideos().hashCode());
result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode()); result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
...@@ -183,6 +193,7 @@ public class SupplierItem implements Entity { ...@@ -183,6 +193,7 @@ public class SupplierItem implements Entity {
createTime("create_time", "createTime", "TIMESTAMP", false), createTime("create_time", "createTime", "TIMESTAMP", false),
updateTime("update_time", "updateTime", "TIMESTAMP", false), updateTime("update_time", "updateTime", "TIMESTAMP", false),
isDeleted("is_deleted", "isDeleted", "BIT", false), isDeleted("is_deleted", "isDeleted", "BIT", false),
buyLimitNum("buy_limit_num", "buyLimitNum", "INTEGER", false),
images("images", "images", "LONGVARCHAR", false), images("images", "images", "LONGVARCHAR", false),
videos("videos", "videos", "LONGVARCHAR", false), videos("videos", "videos", "LONGVARCHAR", false),
description("description", "description", "LONGVARCHAR", false); description("description", "description", "LONGVARCHAR", false);
......
...@@ -1751,6 +1751,138 @@ public class SupplierItemExample { ...@@ -1751,6 +1751,138 @@ public class SupplierItemExample {
addCriterion("is_deleted not between", value1, value2, "isDeleted"); addCriterion("is_deleted not between", value1, value2, "isDeleted");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andBuyLimitNumIsNull() {
addCriterion("buy_limit_num is null");
return (Criteria) this;
}
public Criteria andBuyLimitNumIsNotNull() {
addCriterion("buy_limit_num is not null");
return (Criteria) this;
}
public Criteria andBuyLimitNumEqualTo(Integer value) {
addCriterion("buy_limit_num =", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumEqualToColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num = ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumNotEqualTo(Integer value) {
addCriterion("buy_limit_num <>", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumNotEqualToColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num <> ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumGreaterThan(Integer value) {
addCriterion("buy_limit_num >", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumGreaterThanColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num > ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumGreaterThanOrEqualTo(Integer value) {
addCriterion("buy_limit_num >=", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumGreaterThanOrEqualToColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num >= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumLessThan(Integer value) {
addCriterion("buy_limit_num <", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumLessThanColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num < ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumLessThanOrEqualTo(Integer value) {
addCriterion("buy_limit_num <=", value, "buyLimitNum");
return (Criteria) this;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table supplier_item
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public Criteria andBuyLimitNumLessThanOrEqualToColumn(SupplierItem.Column column) {
addCriterion(new StringBuilder("buy_limit_num <= ").append(column.getEscapedColumnName()).toString());
return (Criteria) this;
}
public Criteria andBuyLimitNumIn(List<Integer> values) {
addCriterion("buy_limit_num in", values, "buyLimitNum");
return (Criteria) this;
}
public Criteria andBuyLimitNumNotIn(List<Integer> values) {
addCriterion("buy_limit_num not in", values, "buyLimitNum");
return (Criteria) this;
}
public Criteria andBuyLimitNumBetween(Integer value1, Integer value2) {
addCriterion("buy_limit_num between", value1, value2, "buyLimitNum");
return (Criteria) this;
}
public Criteria andBuyLimitNumNotBetween(Integer value1, Integer value2) {
addCriterion("buy_limit_num not between", value1, value2, "buyLimitNum");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="is_deleted" jdbcType="BIT" property="isDeleted" /> <result column="is_deleted" jdbcType="BIT" property="isDeleted" />
<result column="buy_limit_num" jdbcType="INTEGER" property="buyLimitNum" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.wwdz.ch.db.domain.distribution.SupplierItem"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.wwdz.ch.db.domain.distribution.SupplierItem">
<result column="images" jdbcType="LONGVARCHAR" property="images" /> <result column="images" jdbcType="LONGVARCHAR" property="images" />
...@@ -80,7 +81,7 @@ ...@@ -80,7 +81,7 @@
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price, id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price,
stock, create_time, update_time, is_deleted stock, create_time, update_time, is_deleted, buy_limit_num
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
images, videos, description images, videos, description
...@@ -136,7 +137,8 @@ ...@@ -136,7 +137,8 @@
</when> </when>
<otherwise> <otherwise>
id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price, id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price,
stock, create_time, update_time, is_deleted, images, videos, description stock, create_time, update_time, is_deleted, buy_limit_num, images, videos, description
</otherwise> </otherwise>
</choose> </choose>
from supplier_item from supplier_item
...@@ -170,7 +172,8 @@ ...@@ -170,7 +172,8 @@
</when> </when>
<otherwise> <otherwise>
id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price, id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price,
stock, create_time, update_time, is_deleted, images, videos, description stock, create_time, update_time, is_deleted, buy_limit_num, images, videos, description
</otherwise> </otherwise>
</choose> </choose>
from supplier_item from supplier_item
...@@ -193,13 +196,15 @@ ...@@ -193,13 +196,15 @@
insert into supplier_item (`name`, supplier_id, is_on_sale, insert into supplier_item (`name`, supplier_id, is_on_sale,
sort, top_image, distribution_price, sort, top_image, distribution_price,
supply_price, stock, create_time, supply_price, stock, create_time,
update_time, is_deleted, images, update_time, is_deleted, buy_limit_num,
videos, description) images, videos, description
)
values (#{name,jdbcType=VARCHAR}, #{supplierId,jdbcType=BIGINT}, #{isOnSale,jdbcType=BIT}, values (#{name,jdbcType=VARCHAR}, #{supplierId,jdbcType=BIGINT}, #{isOnSale,jdbcType=BIT},
#{sort,jdbcType=INTEGER}, #{topImage,jdbcType=VARCHAR}, #{distributionPrice,jdbcType=BIGINT}, #{sort,jdbcType=INTEGER}, #{topImage,jdbcType=VARCHAR}, #{distributionPrice,jdbcType=BIGINT},
#{supplyPrice,jdbcType=BIGINT}, #{stock,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{supplyPrice,jdbcType=BIGINT}, #{stock,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT}, #{images,jdbcType=LONGVARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{isDeleted,jdbcType=BIT}, #{buyLimitNum,jdbcType=INTEGER},
#{videos,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR}) #{images,jdbcType=LONGVARCHAR}, #{videos,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR}
)
</insert> </insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.distribution.SupplierItem"> <insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.distribution.SupplierItem">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
...@@ -240,6 +245,9 @@ ...@@ -240,6 +245,9 @@
<if test="isDeleted != null"> <if test="isDeleted != null">
is_deleted, is_deleted,
</if> </if>
<if test="buyLimitNum != null">
buy_limit_num,
</if>
<if test="images != null"> <if test="images != null">
images, images,
</if> </if>
...@@ -284,6 +292,9 @@ ...@@ -284,6 +292,9 @@
<if test="isDeleted != null"> <if test="isDeleted != null">
#{isDeleted,jdbcType=BIT}, #{isDeleted,jdbcType=BIT},
</if> </if>
<if test="buyLimitNum != null">
#{buyLimitNum,jdbcType=INTEGER},
</if>
<if test="images != null"> <if test="images != null">
#{images,jdbcType=LONGVARCHAR}, #{images,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -340,6 +351,9 @@ ...@@ -340,6 +351,9 @@
<if test="record.isDeleted != null"> <if test="record.isDeleted != null">
is_deleted = #{record.isDeleted,jdbcType=BIT}, is_deleted = #{record.isDeleted,jdbcType=BIT},
</if> </if>
<if test="record.buyLimitNum != null">
buy_limit_num = #{record.buyLimitNum,jdbcType=INTEGER},
</if>
<if test="record.images != null"> <if test="record.images != null">
images = #{record.images,jdbcType=LONGVARCHAR}, images = #{record.images,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -368,6 +382,7 @@ ...@@ -368,6 +382,7 @@
create_time = #{record.createTime,jdbcType=TIMESTAMP}, create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
is_deleted = #{record.isDeleted,jdbcType=BIT}, is_deleted = #{record.isDeleted,jdbcType=BIT},
buy_limit_num = #{record.buyLimitNum,jdbcType=INTEGER},
images = #{record.images,jdbcType=LONGVARCHAR}, images = #{record.images,jdbcType=LONGVARCHAR},
videos = #{record.videos,jdbcType=LONGVARCHAR}, videos = #{record.videos,jdbcType=LONGVARCHAR},
description = #{record.description,jdbcType=LONGVARCHAR} description = #{record.description,jdbcType=LONGVARCHAR}
...@@ -388,7 +403,8 @@ ...@@ -388,7 +403,8 @@
stock = #{record.stock,jdbcType=INTEGER}, stock = #{record.stock,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP}, create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP}, update_time = #{record.updateTime,jdbcType=TIMESTAMP},
is_deleted = #{record.isDeleted,jdbcType=BIT} is_deleted = #{record.isDeleted,jdbcType=BIT},
buy_limit_num = #{record.buyLimitNum,jdbcType=INTEGER}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
...@@ -429,6 +445,9 @@ ...@@ -429,6 +445,9 @@
<if test="isDeleted != null"> <if test="isDeleted != null">
is_deleted = #{isDeleted,jdbcType=BIT}, is_deleted = #{isDeleted,jdbcType=BIT},
</if> </if>
<if test="buyLimitNum != null">
buy_limit_num = #{buyLimitNum,jdbcType=INTEGER},
</if>
<if test="images != null"> <if test="images != null">
images = #{images,jdbcType=LONGVARCHAR}, images = #{images,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -454,6 +473,7 @@ ...@@ -454,6 +473,7 @@
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
is_deleted = #{isDeleted,jdbcType=BIT}, is_deleted = #{isDeleted,jdbcType=BIT},
buy_limit_num = #{buyLimitNum,jdbcType=INTEGER},
images = #{images,jdbcType=LONGVARCHAR}, images = #{images,jdbcType=LONGVARCHAR},
videos = #{videos,jdbcType=LONGVARCHAR}, videos = #{videos,jdbcType=LONGVARCHAR},
description = #{description,jdbcType=LONGVARCHAR} description = #{description,jdbcType=LONGVARCHAR}
...@@ -471,7 +491,8 @@ ...@@ -471,7 +491,8 @@
stock = #{stock,jdbcType=INTEGER}, stock = #{stock,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
is_deleted = #{isDeleted,jdbcType=BIT} is_deleted = #{isDeleted,jdbcType=BIT},
buy_limit_num = #{buyLimitNum,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.distribution.SupplierItemExample" resultMap="BaseResultMap"> <select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.distribution.SupplierItemExample" resultMap="BaseResultMap">
...@@ -528,7 +549,8 @@ ...@@ -528,7 +549,8 @@
</when> </when>
<otherwise> <otherwise>
id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price, id, `name`, supplier_id, is_on_sale, sort, top_image, distribution_price, supply_price,
stock, create_time, update_time, is_deleted, images, videos, description stock, create_time, update_time, is_deleted, buy_limit_num, images, videos, description
</otherwise> </otherwise>
</choose> </choose>
from supplier_item from supplier_item
...@@ -540,5 +562,4 @@ ...@@ -540,5 +562,4 @@
</if> </if>
limit 1 limit 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -77,12 +77,28 @@ public class DistributionOrderServiceImpl implements DistributionOrderService { ...@@ -77,12 +77,28 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
if (distributorShareRecord == null) { if (distributorShareRecord == null) {
return Result.failed("该分享链接无效"); return Result.failed("该分享链接无效");
} }
if (!distributorShareRecord.getEnabled()) {
return Result.failed("该分享链接已失效");
}
//查询商品信息,检查商品库存 //查询商品信息,检查商品库存
SupplierItem supplierItem = supplierItemDao.findById(distributorShareRecord.getItemId()); SupplierItem supplierItem = supplierItemDao.findById(distributorShareRecord.getItemId());
int stock = supplierItem.getStock(); int stock = supplierItem.getStock();
if (stock <= 0) { if (stock <= 0) {
return Result.failed("商品库存不足"); return Result.failed("商品库存不足");
} }
//商品限购数量
int buyLimitNum = supplierItem.getBuyLimitNum() == null ? 5 : supplierItem.getBuyLimitNum();
//检查该购买者是否超出限购数量
//1.查询购买者对该商品的历史购买记录
List<DistributionOrder> distributionOrders = distributionOrderDao.findByBuyerId(dto.getBuyerId());
int buyNum = 0;
if (!CollectionUtils.isEmpty(distributionOrders)) {
buyNum = distributionOrders.stream().mapToInt(DistributionOrder::getItemNum).sum();
}
if (buyNum + dto.getItemNum() > buyLimitNum) {
return Result.failed("超出购买上限,不能下单");
}
String distributionOrderId = IdUtils.getOrderNumber(DISTRIBUTION_ORDER_PREFIX); String distributionOrderId = IdUtils.getOrderNumber(DISTRIBUTION_ORDER_PREFIX);
DistributionOrderRequestDto prePayDto = new DistributionOrderRequestDto(); DistributionOrderRequestDto prePayDto = new DistributionOrderRequestDto();
prePayDto.setDistributionOrderId(distributionOrderId); prePayDto.setDistributionOrderId(distributionOrderId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment