mirror of
				https://gitee.com/coder-xiaomo/flashsale
				synced 2025-11-04 14:13:14 +08:00 
			
		
		
		
	交易下单4-获取用户登录信息;Price拼写错误改正
This commit is contained in:
		@@ -11,7 +11,7 @@
 | 
			
		||||
 Target Server Version : 50726
 | 
			
		||||
 File Encoding         : 65001
 | 
			
		||||
 | 
			
		||||
 Date: 03/03/2022 23:08:26
 | 
			
		||||
 Date: 04/03/2022 17:15:21
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
SET NAMES utf8mb4;
 | 
			
		||||
@@ -90,7 +90,7 @@ CREATE TABLE `order_info`  (
 | 
			
		||||
  `id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
 | 
			
		||||
  `user_id` int(11) NOT NULL DEFAULT 0,
 | 
			
		||||
  `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,
 | 
			
		||||
  `order_price` decimal(10, 2) NOT NULL,
 | 
			
		||||
  PRIMARY KEY (`id`) USING BTREE
 | 
			
		||||
 
 | 
			
		||||
@@ -90,6 +90,7 @@
 | 
			
		||||
        $("#createorder").on("click", function () {
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                type: "POST",
 | 
			
		||||
                contentType: "application/x-www-form-urlencoded",
 | 
			
		||||
                url: "http://localhost:8090/order/createorder",
 | 
			
		||||
                data: {
 | 
			
		||||
                    "itemId": g_itemVO.id,
 | 
			
		||||
@@ -98,9 +99,12 @@
 | 
			
		||||
                xhrFields: {withCredentials: true},
 | 
			
		||||
                success: function (data) {
 | 
			
		||||
                    if (data.status == "success") {
 | 
			
		||||
                        // TODO
 | 
			
		||||
                        alert("下单成功");
 | 
			
		||||
                    } else {
 | 
			
		||||
                        alert("下单失败,原因为" + data.data.errMsg);
 | 
			
		||||
                        if (data.data.errCode == "20003") {
 | 
			
		||||
                            window.location.href = "login.html";
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                error: function (data) {
 | 
			
		||||
 
 | 
			
		||||
@@ -58,6 +58,7 @@
 | 
			
		||||
                success: function (data) {
 | 
			
		||||
                    if (data.status == "success") {
 | 
			
		||||
                        alert("登录成功");
 | 
			
		||||
                        window.location.href = "listitem.html";
 | 
			
		||||
                    } else {
 | 
			
		||||
                        alert("登录失败,原因为" + data.data.errMsg);
 | 
			
		||||
                    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,16 @@
 | 
			
		||||
package com.cxyxiaomo.flashsale.controller;
 | 
			
		||||
 | 
			
		||||
import com.cxyxiaomo.flashsale.error.BusinessException;
 | 
			
		||||
import com.cxyxiaomo.flashsale.error.EmBusinessError;
 | 
			
		||||
import com.cxyxiaomo.flashsale.response.CommonReturnType;
 | 
			
		||||
import com.cxyxiaomo.flashsale.service.OrderService;
 | 
			
		||||
import com.cxyxiaomo.flashsale.service.model.OrderModel;
 | 
			
		||||
import com.cxyxiaomo.flashsale.service.model.UserModel;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.web.bind.annotation.CrossOrigin;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
 | 
			
		||||
@Controller("/order")
 | 
			
		||||
@RequestMapping("/order")
 | 
			
		||||
@@ -18,10 +20,23 @@ public class OrderController extends BaseController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    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,
 | 
			
		||||
                                        @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);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -33,11 +33,11 @@ public class OrderDO {
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    private BigDecimal itemPirce;
 | 
			
		||||
    private BigDecimal itemPrice;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
@@ -131,26 +131,26 @@ public class OrderDO {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    public BigDecimal getItemPirce() {
 | 
			
		||||
        return itemPirce;
 | 
			
		||||
    public BigDecimal getItemPrice() {
 | 
			
		||||
        return itemPrice;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    public void setItemPirce(BigDecimal itemPirce) {
 | 
			
		||||
        this.itemPirce = itemPirce;
 | 
			
		||||
    public void setItemPrice(BigDecimal itemPrice) {
 | 
			
		||||
        this.itemPrice = itemPrice;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ public enum EmBusinessError implements CommonError {
 | 
			
		||||
    // 20000开头为用户信息相关错误定义
 | 
			
		||||
    USER_NOT_EXIST(20001, "用户不存在"),
 | 
			
		||||
    USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
 | 
			
		||||
    USER_NOT_LOGIN(20003, "用户还未登录"),
 | 
			
		||||
 | 
			
		||||
    // 30000开头为交易信息错误定义
 | 
			
		||||
    STOCK_NOT_ENOUGH(30001, "库存不足");
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
    <id column="id" jdbcType="VARCHAR" property="id" />
 | 
			
		||||
    <result column="user_id" jdbcType="INTEGER" property="userId" />
 | 
			
		||||
    <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="order_price" jdbcType="DECIMAL" property="orderPrice" />
 | 
			
		||||
  </resultMap>
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
      This element is automatically generated by MyBatis Generator, do not modify.
 | 
			
		||||
      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>
 | 
			
		||||
  <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.
 | 
			
		||||
    -->
 | 
			
		||||
    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}, 
 | 
			
		||||
      #{itemPirce,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
 | 
			
		||||
      #{itemPrice,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
 | 
			
		||||
      )
 | 
			
		||||
  </insert>
 | 
			
		||||
  <insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.OrderDO">
 | 
			
		||||
@@ -72,8 +72,8 @@
 | 
			
		||||
      <if test="itemId != null">
 | 
			
		||||
        item_id,
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="itemPirce != null">
 | 
			
		||||
        item_pirce,
 | 
			
		||||
      <if test="itemPrice != null">
 | 
			
		||||
        item_price,
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="amount != null">
 | 
			
		||||
        amount,
 | 
			
		||||
@@ -92,8 +92,8 @@
 | 
			
		||||
      <if test="itemId != null">
 | 
			
		||||
        #{itemId,jdbcType=INTEGER},
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="itemPirce != null">
 | 
			
		||||
        #{itemPirce,jdbcType=DECIMAL},
 | 
			
		||||
      <if test="itemPrice != null">
 | 
			
		||||
        #{itemPrice,jdbcType=DECIMAL},
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="amount != null">
 | 
			
		||||
        #{amount,jdbcType=INTEGER},
 | 
			
		||||
@@ -117,8 +117,8 @@
 | 
			
		||||
      <if test="itemId != null">
 | 
			
		||||
        item_id = #{itemId,jdbcType=INTEGER},
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="itemPirce != null">
 | 
			
		||||
        item_pirce = #{itemPirce,jdbcType=DECIMAL},
 | 
			
		||||
      <if test="itemPrice != null">
 | 
			
		||||
        item_price = #{itemPrice,jdbcType=DECIMAL},
 | 
			
		||||
      </if>
 | 
			
		||||
      <if test="amount != null">
 | 
			
		||||
        amount = #{amount,jdbcType=INTEGER},
 | 
			
		||||
@@ -138,7 +138,7 @@
 | 
			
		||||
    update order_info
 | 
			
		||||
    set user_id = #{userId,jdbcType=INTEGER},
 | 
			
		||||
      item_id = #{itemId,jdbcType=INTEGER},
 | 
			
		||||
      item_pirce = #{itemPirce,jdbcType=DECIMAL},
 | 
			
		||||
      item_price = #{itemPrice,jdbcType=DECIMAL},
 | 
			
		||||
      amount = #{amount,jdbcType=INTEGER},
 | 
			
		||||
      order_price = #{orderPrice,jdbcType=DECIMAL}
 | 
			
		||||
    where id = #{id,jdbcType=VARCHAR}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user