mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-11 06:21:40 +08:00
交易下单4-获取用户登录信息;Price拼写错误改正
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
Target Server Version : 50726
|
Target Server Version : 50726
|
||||||
File Encoding : 65001
|
File Encoding : 65001
|
||||||
|
|
||||||
Date: 03/03/2022 23:08:26
|
Date: 04/03/2022 17:15:21
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
@@ -90,7 +90,7 @@ CREATE TABLE `order_info` (
|
|||||||
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
`id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
`user_id` int(11) NOT NULL DEFAULT 0,
|
`user_id` int(11) NOT NULL DEFAULT 0,
|
||||||
`item_id` int(11) NOT NULL,
|
`item_id` int(11) NOT NULL,
|
||||||
`item_pirce` decimal(10, 2) NOT NULL,
|
`item_price` decimal(10, 2) NOT NULL,
|
||||||
`amount` int(255) NOT NULL,
|
`amount` int(255) NOT NULL,
|
||||||
`order_price` decimal(10, 2) NOT NULL,
|
`order_price` decimal(10, 2) NOT NULL,
|
||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
@@ -90,6 +90,7 @@
|
|||||||
$("#createorder").on("click", function () {
|
$("#createorder").on("click", function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
contentType: "application/x-www-form-urlencoded",
|
||||||
url: "http://localhost:8090/order/createorder",
|
url: "http://localhost:8090/order/createorder",
|
||||||
data: {
|
data: {
|
||||||
"itemId": g_itemVO.id,
|
"itemId": g_itemVO.id,
|
||||||
@@ -98,9 +99,12 @@
|
|||||||
xhrFields: {withCredentials: true},
|
xhrFields: {withCredentials: true},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.status == "success") {
|
if (data.status == "success") {
|
||||||
// TODO
|
alert("下单成功");
|
||||||
} else {
|
} else {
|
||||||
alert("下单失败,原因为" + data.data.errMsg);
|
alert("下单失败,原因为" + data.data.errMsg);
|
||||||
|
if (data.data.errCode == "20003") {
|
||||||
|
window.location.href = "login.html";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
|
@@ -58,6 +58,7 @@
|
|||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.status == "success") {
|
if (data.status == "success") {
|
||||||
alert("登录成功");
|
alert("登录成功");
|
||||||
|
window.location.href = "listitem.html";
|
||||||
} else {
|
} else {
|
||||||
alert("登录失败,原因为" + data.data.errMsg);
|
alert("登录失败,原因为" + data.data.errMsg);
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,16 @@
|
|||||||
package com.cxyxiaomo.flashsale.controller;
|
package com.cxyxiaomo.flashsale.controller;
|
||||||
|
|
||||||
import com.cxyxiaomo.flashsale.error.BusinessException;
|
import com.cxyxiaomo.flashsale.error.BusinessException;
|
||||||
|
import com.cxyxiaomo.flashsale.error.EmBusinessError;
|
||||||
import com.cxyxiaomo.flashsale.response.CommonReturnType;
|
import com.cxyxiaomo.flashsale.response.CommonReturnType;
|
||||||
import com.cxyxiaomo.flashsale.service.OrderService;
|
import com.cxyxiaomo.flashsale.service.OrderService;
|
||||||
import com.cxyxiaomo.flashsale.service.model.OrderModel;
|
import com.cxyxiaomo.flashsale.service.model.OrderModel;
|
||||||
|
import com.cxyxiaomo.flashsale.service.model.UserModel;
|
||||||
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.CrossOrigin;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@Controller("/order")
|
@Controller("/order")
|
||||||
@RequestMapping("/order")
|
@RequestMapping("/order")
|
||||||
@@ -18,10 +20,23 @@ public class OrderController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OrderService orderService;
|
private OrderService orderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest httpServletRequest;
|
||||||
|
|
||||||
// 封装下单请求
|
// 封装下单请求
|
||||||
|
@RequestMapping(value = "/createorder", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||||
|
@ResponseBody
|
||||||
public CommonReturnType createOrder(@RequestParam(name = "itemId") Integer itemId,
|
public CommonReturnType createOrder(@RequestParam(name = "itemId") Integer itemId,
|
||||||
@RequestParam(name = "amount") Integer amount) throws BusinessException {
|
@RequestParam(name = "amount") Integer amount) throws BusinessException {
|
||||||
OrderModel orderModel = orderService.createOrder(null, itemId, amount);
|
// 获取用户登陆状态
|
||||||
|
Boolean isLogin = (Boolean) httpServletRequest.getSession().getAttribute("IS_LOGIN");
|
||||||
|
if (isLogin == null || !isLogin.booleanValue()) {
|
||||||
|
throw new BusinessException(EmBusinessError.USER_NOT_LOGIN, "用户还未登录,不能下单");
|
||||||
|
}
|
||||||
|
// 获取用户的登录信息
|
||||||
|
UserModel userModel = (UserModel) httpServletRequest.getSession().getAttribute("LOGIN_USER");
|
||||||
|
|
||||||
|
OrderModel orderModel = orderService.createOrder(userModel.getId(), itemId, amount);
|
||||||
|
|
||||||
return CommonReturnType.create(null);
|
return CommonReturnType.create(null);
|
||||||
}
|
}
|
||||||
|
@@ -33,11 +33,11 @@ public class OrderDO {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* This field was generated by MyBatis Generator.
|
* This field was generated by MyBatis Generator.
|
||||||
* This field corresponds to the database column order_info.item_pirce
|
* This field corresponds to the database column order_info.item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||||
*/
|
*/
|
||||||
private BigDecimal itemPirce;
|
private BigDecimal itemPrice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -131,26 +131,26 @@ public class OrderDO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was generated by MyBatis Generator.
|
* This method was generated by MyBatis Generator.
|
||||||
* This method returns the value of the database column order_info.item_pirce
|
* This method returns the value of the database column order_info.item_price
|
||||||
*
|
*
|
||||||
* @return the value of order_info.item_pirce
|
* @return the value of order_info.item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||||
*/
|
*/
|
||||||
public BigDecimal getItemPirce() {
|
public BigDecimal getItemPrice() {
|
||||||
return itemPirce;
|
return itemPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method was generated by MyBatis Generator.
|
* This method was generated by MyBatis Generator.
|
||||||
* This method sets the value of the database column order_info.item_pirce
|
* This method sets the value of the database column order_info.item_price
|
||||||
*
|
*
|
||||||
* @param itemPirce the value for order_info.item_pirce
|
* @param itemPrice the value for order_info.item_price
|
||||||
*
|
*
|
||||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||||
*/
|
*/
|
||||||
public void setItemPirce(BigDecimal itemPirce) {
|
public void setItemPrice(BigDecimal itemPrice) {
|
||||||
this.itemPirce = itemPirce;
|
this.itemPrice = itemPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -8,6 +8,7 @@ public enum EmBusinessError implements CommonError {
|
|||||||
// 20000开头为用户信息相关错误定义
|
// 20000开头为用户信息相关错误定义
|
||||||
USER_NOT_EXIST(20001, "用户不存在"),
|
USER_NOT_EXIST(20001, "用户不存在"),
|
||||||
USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
|
USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
|
||||||
|
USER_NOT_LOGIN(20003, "用户还未登录"),
|
||||||
|
|
||||||
// 30000开头为交易信息错误定义
|
// 30000开头为交易信息错误定义
|
||||||
STOCK_NOT_ENOUGH(30001, "库存不足");
|
STOCK_NOT_ENOUGH(30001, "库存不足");
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||||
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
||||||
<result column="item_id" jdbcType="INTEGER" property="itemId" />
|
<result column="item_id" jdbcType="INTEGER" property="itemId" />
|
||||||
<result column="item_pirce" jdbcType="DECIMAL" property="itemPirce" />
|
<result column="item_price" jdbcType="DECIMAL" property="itemPrice" />
|
||||||
<result column="amount" jdbcType="INTEGER" property="amount" />
|
<result column="amount" jdbcType="INTEGER" property="amount" />
|
||||||
<result column="order_price" jdbcType="DECIMAL" property="orderPrice" />
|
<result column="order_price" jdbcType="DECIMAL" property="orderPrice" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@@ -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 Thu Mar 03 22:04:45 CST 2022.
|
This element was generated on Thu Mar 03 22:04:45 CST 2022.
|
||||||
-->
|
-->
|
||||||
id, user_id, item_id, item_pirce, amount, order_price
|
id, user_id, item_id, item_price, amount, order_price
|
||||||
</sql>
|
</sql>
|
||||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||||
<!--
|
<!--
|
||||||
@@ -49,10 +49,10 @@
|
|||||||
This element was generated on Thu Mar 03 22:04:45 CST 2022.
|
This element was generated on Thu Mar 03 22:04:45 CST 2022.
|
||||||
-->
|
-->
|
||||||
insert into order_info (id, user_id, item_id,
|
insert into order_info (id, user_id, item_id,
|
||||||
item_pirce, amount, order_price
|
item_price, amount, order_price
|
||||||
)
|
)
|
||||||
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{itemId,jdbcType=INTEGER},
|
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{itemId,jdbcType=INTEGER},
|
||||||
#{itemPirce,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
|
#{itemPrice,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.OrderDO">
|
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.OrderDO">
|
||||||
@@ -72,8 +72,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
item_id,
|
item_id,
|
||||||
</if>
|
</if>
|
||||||
<if test="itemPirce != null">
|
<if test="itemPrice != null">
|
||||||
item_pirce,
|
item_price,
|
||||||
</if>
|
</if>
|
||||||
<if test="amount != null">
|
<if test="amount != null">
|
||||||
amount,
|
amount,
|
||||||
@@ -92,8 +92,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
#{itemId,jdbcType=INTEGER},
|
#{itemId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="itemPirce != null">
|
<if test="itemPrice != null">
|
||||||
#{itemPirce,jdbcType=DECIMAL},
|
#{itemPrice,jdbcType=DECIMAL},
|
||||||
</if>
|
</if>
|
||||||
<if test="amount != null">
|
<if test="amount != null">
|
||||||
#{amount,jdbcType=INTEGER},
|
#{amount,jdbcType=INTEGER},
|
||||||
@@ -117,8 +117,8 @@
|
|||||||
<if test="itemId != null">
|
<if test="itemId != null">
|
||||||
item_id = #{itemId,jdbcType=INTEGER},
|
item_id = #{itemId,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
<if test="itemPirce != null">
|
<if test="itemPrice != null">
|
||||||
item_pirce = #{itemPirce,jdbcType=DECIMAL},
|
item_price = #{itemPrice,jdbcType=DECIMAL},
|
||||||
</if>
|
</if>
|
||||||
<if test="amount != null">
|
<if test="amount != null">
|
||||||
amount = #{amount,jdbcType=INTEGER},
|
amount = #{amount,jdbcType=INTEGER},
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
update order_info
|
update order_info
|
||||||
set user_id = #{userId,jdbcType=INTEGER},
|
set user_id = #{userId,jdbcType=INTEGER},
|
||||||
item_id = #{itemId,jdbcType=INTEGER},
|
item_id = #{itemId,jdbcType=INTEGER},
|
||||||
item_pirce = #{itemPirce,jdbcType=DECIMAL},
|
item_price = #{itemPrice,jdbcType=DECIMAL},
|
||||||
amount = #{amount,jdbcType=INTEGER},
|
amount = #{amount,jdbcType=INTEGER},
|
||||||
order_price = #{orderPrice,jdbcType=DECIMAL}
|
order_price = #{orderPrice,jdbcType=DECIMAL}
|
||||||
where id = #{id,jdbcType=VARCHAR}
|
where id = #{id,jdbcType=VARCHAR}
|
||||||
|
Reference in New Issue
Block a user