mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-10 19:58:14 +08:00
抢购3-promoItemPrice拼写错误就整;前端页面;修Bug
This commit is contained in:
parent
e77065df5d
commit
bad79611bf
@ -11,7 +11,7 @@
|
|||||||
Target Server Version : 50726
|
Target Server Version : 50726
|
||||||
File Encoding : 65001
|
File Encoding : 65001
|
||||||
|
|
||||||
Date: 05/03/2022 12:39:01
|
Date: 05/03/2022 15:19:32
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
@ -108,8 +108,9 @@ CREATE TABLE `promo_info` (
|
|||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`promo_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
`promo_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||||
`start_date` datetime NOT NULL DEFAULT '0000-01-01 00:00:00',
|
`start_date` datetime NOT NULL DEFAULT '0000-01-01 00:00:00',
|
||||||
|
`end_date` datetime NOT NULL DEFAULT '0000-01-01 00:00:00',
|
||||||
`item_id` int(11) NOT NULL DEFAULT 0,
|
`item_id` int(11) NOT NULL DEFAULT 0,
|
||||||
`prome_item_price` decimal(10, 2) NOT NULL DEFAULT 0.00,
|
`promo_item_price` decimal(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
INDEX `item_id`(`item_id`) USING BTREE,
|
INDEX `item_id`(`item_id`) USING BTREE,
|
||||||
CONSTRAINT `promo_info_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
CONSTRAINT `promo_info_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||||
@ -118,7 +119,7 @@ CREATE TABLE `promo_info` (
|
|||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of promo_info
|
-- Records of promo_info
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
INSERT INTO `promo_info` VALUES (1, '小米手机抢购活动', '2022-03-05 14:00:00', 1, 1999.00);
|
INSERT INTO `promo_info` VALUES (1, '小米手机抢购活动', '2022-03-05 14:00:00', '2022-03-05 16:00:00', 5, 1999.00);
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for sequence_info
|
-- Table structure for sequence_info
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
<body class="login">
|
<body class="login">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h3 class="form-title">商品详情</h3>
|
<h3 class="form-title">商品详情</h3>
|
||||||
|
<div id="promoStartDateContainer" class="from-group">
|
||||||
|
<label style="color: blue;" id="promoStatus" class="control-label"></label>
|
||||||
|
<div>
|
||||||
|
<label style="color: red;" class="control-label" id="promoStartDate">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="from-group">
|
<div class="from-group">
|
||||||
<div>
|
<div>
|
||||||
<label class="control-label" id="title">
|
<label class="control-label" id="title">
|
||||||
@ -28,6 +34,12 @@
|
|||||||
<label class="control-label" id="price">
|
<label class="control-label" id="price">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="promoPriceContainer" class="from-group">
|
||||||
|
<label class="control-label">秒杀价格</label>
|
||||||
|
<div>
|
||||||
|
<label style="color: red;" class="control-label" id="promoPrice">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="from-group">
|
<div class="from-group">
|
||||||
<img id="imgUrl" src="" style="width: 200px; height: auto;"/>
|
<img id="imgUrl" src="" style="width: 200px; height: auto;"/>
|
||||||
</div>
|
</div>
|
||||||
@ -77,6 +89,7 @@
|
|||||||
if (data.status == "success") {
|
if (data.status == "success") {
|
||||||
g_itemVO = data.data;
|
g_itemVO = data.data;
|
||||||
reloadDom();
|
reloadDom();
|
||||||
|
setInterval(reloadDom, 300);
|
||||||
} else {
|
} else {
|
||||||
alert("获取信息失败,原因为" + data.data.errMsg);
|
alert("获取信息失败,原因为" + data.data.errMsg);
|
||||||
}
|
}
|
||||||
@ -122,6 +135,28 @@
|
|||||||
$("#price").text(g_itemVO.price);
|
$("#price").text(g_itemVO.price);
|
||||||
$("#imgUrl").attr("src", g_itemVO.imgUrl);
|
$("#imgUrl").attr("src", g_itemVO.imgUrl);
|
||||||
$("#sales").text(g_itemVO.sales);
|
$("#sales").text(g_itemVO.sales);
|
||||||
|
if (g_itemVO.promoStatus == 1) {
|
||||||
|
// 秒杀活动还未开始
|
||||||
|
var startTime = g_itemVO.startDate.replace(new RegExp("-", "gm"), "/");
|
||||||
|
startTime = new Date(startTime).getTime();
|
||||||
|
var nowTime = Date.parse(new Date());
|
||||||
|
var delta = (startTime - nowTime) / 1000;
|
||||||
|
|
||||||
|
if (delta < 1) {
|
||||||
|
// 活动开始了
|
||||||
|
g_itemVO.promoStatus = 2;
|
||||||
|
reloadDom();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#promoStartDate").text("秒杀活动将于 " + g_itemVO.startDate + " 开始" +
|
||||||
|
"倒计时:" + delta + "s");
|
||||||
|
$("#promoPrice").text(g_itemVO.promoPrice);
|
||||||
|
$("#createorder").attr("disabled", true);
|
||||||
|
} else if (g_itemVO.promoStatus == 2) {
|
||||||
|
$("#promoStartDate").text("秒杀正在进行中");
|
||||||
|
$("#promoPrice").text(g_itemVO.promoPrice);
|
||||||
|
$("#createorder").attr("disabled", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -5,12 +5,15 @@ import com.cxyxiaomo.flashsale.error.BusinessException;
|
|||||||
import com.cxyxiaomo.flashsale.response.CommonReturnType;
|
import com.cxyxiaomo.flashsale.response.CommonReturnType;
|
||||||
import com.cxyxiaomo.flashsale.service.ItemService;
|
import com.cxyxiaomo.flashsale.service.ItemService;
|
||||||
import com.cxyxiaomo.flashsale.service.model.ItemModel;
|
import com.cxyxiaomo.flashsale.service.model.ItemModel;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ public class ItemController extends BaseController {
|
|||||||
// 有正在进行或即将进行的秒杀活动
|
// 有正在进行或即将进行的秒杀活动
|
||||||
itemVO.setPromoStatus(itemModel.getPromoModel().getStatus());
|
itemVO.setPromoStatus(itemModel.getPromoModel().getStatus());
|
||||||
itemVO.setPromoId(itemModel.getId());
|
itemVO.setPromoId(itemModel.getId());
|
||||||
itemVO.setStartDate(itemModel.getPromoModel().getStartDate());
|
itemVO.setStartDate(itemModel.getPromoModel().getStartDate().toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
itemVO.setPromoPrice(itemModel.getPromoModel().getPromoPrice());
|
itemVO.setPromoPrice(itemModel.getPromoModel().getPromoPrice());
|
||||||
} else {
|
} else {
|
||||||
itemVO.setPromoStatus(0);
|
itemVO.setPromoStatus(0);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.cxyxiaomo.flashsale.controller.viewobject;
|
package com.cxyxiaomo.flashsale.controller.viewobject;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class ItemVO {
|
public class ItemVO {
|
||||||
@ -37,7 +35,7 @@ public class ItemVO {
|
|||||||
private Integer promoId;
|
private Integer promoId;
|
||||||
|
|
||||||
// 秒杀活动开始时间
|
// 秒杀活动开始时间
|
||||||
private DateTime startDate;
|
private String startDate;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -119,11 +117,11 @@ public class ItemVO {
|
|||||||
this.promoId = promoId;
|
this.promoId = promoId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getStartDate() {
|
public String getStartDate() {
|
||||||
return startDate;
|
return startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartDate(DateTime startDate) {
|
public void setStartDate(String startDate) {
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,11 @@ public class PromoDO {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* This field was generated by MyBatis Generator.
|
* This field was generated by MyBatis Generator.
|
||||||
* This field corresponds to the database column promo_info.prome_item_price
|
* This field corresponds to the database column promo_info.promo_item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
||||||
*/
|
*/
|
||||||
private BigDecimal promeItemPrice;
|
private BigDecimal promoItemPrice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was generated by MyBatis Generator.
|
* This method was generated by MyBatis Generator.
|
||||||
@ -180,25 +180,25 @@ public class PromoDO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was generated by MyBatis Generator.
|
* This method was generated by MyBatis Generator.
|
||||||
* This method returns the value of the database column promo_info.prome_item_price
|
* This method returns the value of the database column promo_info.promo_item_price
|
||||||
*
|
*
|
||||||
* @return the value of promo_info.prome_item_price
|
* @return the value of promo_info.promo_item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
||||||
*/
|
*/
|
||||||
public BigDecimal getPromeItemPrice() {
|
public BigDecimal getPromoItemPrice() {
|
||||||
return promeItemPrice;
|
return promoItemPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was generated by MyBatis Generator.
|
* This method was generated by MyBatis Generator.
|
||||||
* This method sets the value of the database column promo_info.prome_item_price
|
* This method sets the value of the database column promo_info.promo_item_price
|
||||||
*
|
*
|
||||||
* @param promeItemPrice the value for promo_info.prome_item_price
|
* @param promoItemPrice the value for promo_info.promo_item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
|
||||||
*/
|
*/
|
||||||
public void setPromeItemPrice(BigDecimal promeItemPrice) {
|
public void setPromoItemPrice(BigDecimal promoItemPrice) {
|
||||||
this.promeItemPrice = promeItemPrice;
|
this.promoItemPrice = promoItemPrice;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,9 @@ import com.cxyxiaomo.flashsale.service.model.PromoModel;
|
|||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class PromoServiceImpl implements PromoService {
|
public class PromoServiceImpl implements PromoService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -16,11 +18,15 @@ public class PromoServiceImpl implements PromoService {
|
|||||||
@Override
|
@Override
|
||||||
public PromoModel getPromoByItemId(Integer itemId) {
|
public PromoModel getPromoByItemId(Integer itemId) {
|
||||||
// 获取对应商品的秒杀活动信息
|
// 获取对应商品的秒杀活动信息
|
||||||
PromoDO promoDO = promoDOMapper.selectByPrimaryKey(itemId);
|
PromoDO promoDO = promoDOMapper.selectByItemId(itemId);
|
||||||
|
|
||||||
// Data Object -> Model
|
// Data Object -> Model
|
||||||
PromoModel promoModel = convertFromDataObject(promoDO);
|
PromoModel promoModel = convertFromDataObject(promoDO);
|
||||||
|
|
||||||
|
if (promoModel == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 判断秒杀活动是否即将开始或正在进行
|
// 判断秒杀活动是否即将开始或正在进行
|
||||||
if (promoModel.getStartDate().isAfterNow()) {
|
if (promoModel.getStartDate().isAfterNow()) {
|
||||||
promoModel.setStatus(1); // 还未开始
|
promoModel.setStatus(1); // 还未开始
|
||||||
@ -39,6 +45,7 @@ public class PromoServiceImpl implements PromoService {
|
|||||||
}
|
}
|
||||||
PromoModel promoModel = new PromoModel();
|
PromoModel promoModel = new PromoModel();
|
||||||
BeanUtils.copyProperties(promoDO, promoModel);
|
BeanUtils.copyProperties(promoDO, promoModel);
|
||||||
|
promoModel.setPromoPrice(promoDO.getPromoItemPrice());
|
||||||
promoModel.setStartDate(new DateTime(promoDO.getStartDate()));
|
promoModel.setStartDate(new DateTime(promoDO.getStartDate()));
|
||||||
promoModel.setEndDate(new DateTime(promoDO.getEndDate()));
|
promoModel.setEndDate(new DateTime(promoDO.getEndDate()));
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<result column="start_date" jdbcType="TIMESTAMP" property="startDate" />
|
<result column="start_date" jdbcType="TIMESTAMP" property="startDate" />
|
||||||
<result column="end_date" jdbcType="TIMESTAMP" property="endDate" />
|
<result column="end_date" jdbcType="TIMESTAMP" property="endDate" />
|
||||||
<result column="item_id" jdbcType="INTEGER" property="itemId" />
|
<result column="item_id" jdbcType="INTEGER" property="itemId" />
|
||||||
<result column="prome_item_price" jdbcType="DECIMAL" property="promeItemPrice" />
|
<result column="promo_item_price" jdbcType="DECIMAL" property="promoItemPrice" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
<!--
|
<!--
|
||||||
@ -20,7 +20,7 @@
|
|||||||
This element is automatically generated by MyBatis Generator, do not modify.
|
This element is automatically generated by MyBatis Generator, do not modify.
|
||||||
This element was generated on Sat Mar 05 12:55:23 CST 2022.
|
This element was generated on Sat Mar 05 12:55:23 CST 2022.
|
||||||
-->
|
-->
|
||||||
id, promo_name, start_date, end_date, item_id, prome_item_price
|
id, promo_name, start_date, end_date, item_id, promo_item_price
|
||||||
</sql>
|
</sql>
|
||||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
<!--
|
<!--
|
||||||
@ -49,10 +49,10 @@
|
|||||||
This element was generated on Sat Mar 05 12:55:23 CST 2022.
|
This element was generated on Sat Mar 05 12:55:23 CST 2022.
|
||||||
-->
|
-->
|
||||||
insert into promo_info (id, promo_name, start_date,
|
insert into promo_info (id, promo_name, start_date,
|
||||||
end_date, item_id, prome_item_price
|
end_date, item_id, promo_item_price
|
||||||
)
|
)
|
||||||
values (#{id,jdbcType=INTEGER}, #{promoName,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP},
|
values (#{id,jdbcType=INTEGER}, #{promoName,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP},
|
||||||
#{endDate,jdbcType=TIMESTAMP}, #{itemId,jdbcType=INTEGER}, #{promeItemPrice,jdbcType=DECIMAL}
|
#{endDate,jdbcType=TIMESTAMP}, #{itemId,jdbcType=INTEGER}, #{promoItemPrice,jdbcType=DECIMAL}
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.PromoDO">
|
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.PromoDO">
|
||||||
@ -78,8 +78,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
item_id,
|
item_id,
|
||||||
</if>
|
</if>
|
||||||
<if test="promeItemPrice != null">
|
<if test="promoItemPrice != null">
|
||||||
prome_item_price,
|
promo_item_price,
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
@ -98,8 +98,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
#{itemId,jdbcType=INTEGER},
|
#{itemId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="promeItemPrice != null">
|
<if test="promoItemPrice != null">
|
||||||
#{promeItemPrice,jdbcType=DECIMAL},
|
#{promoItemPrice,jdbcType=DECIMAL},
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
@ -123,8 +123,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
item_id = #{itemId,jdbcType=INTEGER},
|
item_id = #{itemId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="promeItemPrice != null">
|
<if test="promoItemPrice != null">
|
||||||
prome_item_price = #{promeItemPrice,jdbcType=DECIMAL},
|
promo_item_price = #{promoItemPrice,jdbcType=DECIMAL},
|
||||||
</if>
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
@ -140,10 +140,10 @@
|
|||||||
start_date = #{startDate,jdbcType=TIMESTAMP},
|
start_date = #{startDate,jdbcType=TIMESTAMP},
|
||||||
end_date = #{endDate,jdbcType=TIMESTAMP},
|
end_date = #{endDate,jdbcType=TIMESTAMP},
|
||||||
item_id = #{itemId,jdbcType=INTEGER},
|
item_id = #{itemId,jdbcType=INTEGER},
|
||||||
prome_item_price = #{promeItemPrice,jdbcType=DECIMAL}
|
promo_item_price = #{promoItemPrice,jdbcType=DECIMAL}
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
<select id="selectByItemId" resultMap="BaseResultMap">
|
<select id="selectByItemId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
select
|
select
|
||||||
<include refid="Base_Column_List" />
|
<include refid="Base_Column_List" />
|
||||||
from promo_info
|
from promo_info
|
||||||
|
Loading…
Reference in New Issue
Block a user