新峰商城之订单(一):确认页面开发

news2024/9/22 1:05:52

        新峰商城订单从生成到处理结束,主要以下几个流程:

(1)提交订单(商城用户发起)

(2)订单入库(后台逻辑)

(3)支付订单(商城用户发起)

(4)订单处理(确认订单、取消订单、修改订单)

一、订单确认的前置步骤

        通过购物车页面的结算按钮进入订单确认页面,如果购物车中无数据,则提示“购物车中无数据”,数据正常则执行settle()方法并进跳转,跳转路径为/shop-cart/settle,并在此控制器方法中进行订单确认页面中数据的查询和整合,其代码如下所示:

<div class="order_button fr">
    <th:block th:if="${itemsTotal == 0}">
       <input class="order_button_c" type="button" name="tip"
                               onclick="tip()"
                               value="去结算"/>
    </th:block>
    <th:block th:unless="${itemsTotal == 0}">
       <input class="order_button_d" type="button" name="settle"
                               onclick="settle()"
                               value="去结算"/>
    </th:block>
</div>

        其中tip()方法和settle()方法代码如下所示:

/**
     * 购物车中数量为0时提示
     */
function tip() {
        Swal.fire({
            text: "购物车中无数据,无法结算",
            icon: "error",iconColor:"#f05b72",
        });
    }
/**
     * 跳转至结算页面
     */
function settle() {
        window.location.href = '/shop-cart/settle'
    }

二、订单确认页面显示主要数据

        订单确认页不同于购物车中商品数据,还包括用户数据和支付数据,其详细信息如下图所示:

三、订单确认页面控制层

        在ShoppingCartController类中增加settlePage()方法,用于处理/shop-cart/settle请求,并将数据带到订单确认页面进行渲染,代码如下所示:

@GetMapping("/shop-cart/settle")
    public String settlePage(HttpServletRequest request,
                             HttpSession httpSession) {
        int priceTotal = 0;
        //从session中获取用户信息,包括收货信息
        NewBeeMallUserVO user = (NewBeeMallUserVO) httpSession.getAttribute(Constants.MALL_USER_SESSION_KEY);
        List<NewBeeMallShoppingCartItemVO> myShoppingCartItems = newBeeMallShoppingCartService.getMyShoppingCartItems(user.getUserId());
        if (CollectionUtils.isEmpty(myShoppingCartItems)) {
            //无数据则不跳转至结算页
            return "/shop-cart";
        } else {
            //总价
            for (NewBeeMallShoppingCartItemVO newBeeMallShoppingCartItemVO : myShoppingCartItems) {
                priceTotal += newBeeMallShoppingCartItemVO.getGoodsCount() * newBeeMallShoppingCartItemVO.getSellingPrice();
            }
            if (priceTotal < 1) {
                NewBeeMallException.fail("购物项价格异常");
            }
        }
        request.setAttribute("priceTotal", priceTotal);
        request.setAttribute("myShoppingCartItems", myShoppingCartItems);
        return "mall/order-settle";
    }

        此方法查询商品信息并计算总价,然后将priceTotal和myShoppingCartItems两个对象放入request请求中,再跳转到order-settle页面。

四、订单确认页面制作

        在resources/templates/mall目录中新增订单确认页order-settle.html,模板代码如下所示:

<!-- Copyright (c) 2019-2020 十三 all rights reserved. -->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="mall/header::head-fragment('NewBee商城-订单结算','order-detail')">
</head>
<link th:href="@{/mall/css/bootstrap-modal.css}" rel="stylesheet">
<body>
<header th:replace="mall/header::header-fragment"></header>
<!-- nav -->
<nav th:replace="mall/header::nav-fragment"></nav>

<!-- personal -->
<div id="personal">
    <div class="self-info center">

        <!-- sidebar -->
        <div th:replace="mall/personal-sidebar::sidebar-fragment"></div>

        <div class="intro fr">
            <div class="uc-box uc-main-box">
                <div class="uc-content-box order-view-box">
                    <div class="box-hd">
                        <h1 class="title">填写并核对订单信息</h1>
                        <div class="more clearfix">
                            <div class="actions">
                                <a id="saveOrder" class="btn btn-small btn-primary" title="提交订单">提交订单</a>
                            </div>
                        </div>
                    </div>
                    <div class="box-bd">
                        <div class="uc-order-item uc-order-item-pay">
                            <div class="order-detail">

                                <div class="order-summary">
                                    <div class="order-progress">
                                        <ol class="progress-list clearfix progress-list-5">
                                            <li class="step step-done">
                                                <div class="progress"><span class="text">购物车</span></div>
                                                <div class="info"></div>
                                            </li>
                                            <li class="step step-active">
                                                <div class="progress"><span class="text">下单</span></div>
                                                <div class="info"></div>
                                            </li>
                                            <li class="step">
                                                <div class="progress"><span class="text">付款</span></div>
                                                <div class="info"></div>
                                            </li>
                                            <li class="step">
                                                <div class="progress"><span class="text">出库</span></div>
                                                <div class="info"></div>
                                            </li>
                                            <li class="step">
                                                <div class="progress"><span class="text">交易成功</span></div>
                                                <div class="info"></div>
                                            </li>
                                        </ol>
                                    </div>
                                </div>
                                <table class="order-items-table">
                                    <tbody>

                                    <th:block th:each="item : ${myShoppingCartItems}">
                                        <tr>
                                            <td class="col col-thumb">
                                                <div class="figure figure-thumb">
                                                    <a target="_blank" th:href="@{'/goods/detail/'+${item.goodsId}}">
                                                        <img th:src="@{${item.goodsCoverImg}}"
                                                             width="80" height="80" alt="">
                                                    </a>
                                                </div>
                                            </td>
                                            <td class="col col-name">
                                                <p class="name">
                                                    <a target="_blank" th:href="@{'/goods/detail/'+${item.goodsId}}"
                                                       th:text="${item.goodsName}">newbee</a>
                                                </p>
                                            </td>
                                            <td class="col col-price"><p class="price"
                                                                         th:text="${item.sellingPrice+'元 x '+item.goodsCount}">
                                                1299元 × 1</p></td>
                                            <td class="col col-actions">
                                            </td>
                                        </tr>
                                    </th:block>
                                    </tbody>
                                </table>
                            </div>
                            <div id="editAddr" class="order-detail-info">
                                <h3>收货信息</h3>
                                <table class="info-table">
                                    <tbody>
                                    <tr>
                                        <th>收货地址:</th>
                                        <td class="user_address_label"
                                            th:text="${session.newBeeMallUser.address==''?'无':session.newBeeMallUser.address}">
                                            newbee
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="actions">
                                    <a class="btn btn-small btn-line-gray J_editAddr"
                                       href="javascript:openUpdateModal();">修改</a>
                                </div>
                            </div>
                            <div id="editTime" class="order-detail-info">
                                <h3>支付方式</h3>
                                <table class="info-table">
                                    <tbody>
                                    <tr>
                                        <th>支付方式:</th>
                                        <td>在线支付</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="actions">
                                </div>
                            </div>
                            <div class="order-detail-total">
                                <table class="total-table">
                                    <tbody>
                                    <tr>
                                        <th>商品总价:</th>
                                        <td><span class="num" th:text="${priceTotal+'.00'}">1299.00</span>元</td>
                                    </tr>
                                    <tr>
                                        <th>运费:</th>
                                        <td><span class="num">0</span>元</td>
                                    </tr>
                                    <tr>
                                        <th class="total">应付金额:</th>
                                        <td class="total"><span class="num" th:text="${priceTotal+'.00'}">1299.00</span>元
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="personalInfoModal" tabindex="-1" role="dialog"
             aria-labelledby="personalInfoModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h6 class="modal-title" id="personalInfoModalLabel">地址修改</h6>
                    </div>
                    <div class="modal-body">
                        <form id="personalInfoForm">
                            <div class="form-group">
                                <input type="hidden" id="userId" th:value="${session.newBeeMallUser.userId}">
                                <label for="address" class="control-label">收货地址:</label>
                                <input type="text" class="form-control" id="address" name="address"
                                       placeholder="请输入收货地址" th:value="${session.newBeeMallUser.address}"
                                       required="true">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="saveButton">确认</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
</div>


<div th:replace="mall/footer::footer-fragment"></div>

<!-- jQuery -->
<script th:src="@{/admin/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/mall/js/search.js}" type="text/javascript"></script>
<script th:src="@{/admin/plugins/sweetalert2/sweetalert2.all.min.js}"></script>
<script th:src="@{/mall/js/bootstrap3.js}"></script>
<script type="text/javascript">
    $('#saveOrder').click(function () {
        var userAddress = $(".user_address_label").html();
        if (userAddress == '' || userAddress == '无') {
            Swal.fire({
                text: "请填写收货信息",
                icon: "error",iconColor:"#f05b72",
            });
            return;
        }
        if (userAddress.trim().length < 10) {
            Swal.fire({
                text: "请输入正确的收货信息",
                icon: "error",iconColor:"#f05b72",
            });
            return;
        }
        window.location.href = '../saveOrder';
    });

    function openUpdateModal() {
        $('#personalInfoModal').modal('show');
    }

    //绑定modal上的保存按钮
    $('#saveButton').click(function () {
        var address = $("#address").val();
        var userId = $("#userId").val();
        var data = {
            "userId": userId,
            "address": address
        };
        $.ajax({
            type: 'POST',//方法类型
            url: '/personal/updateInfo',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.resultCode == 200) {
                    $('#personalInfoModal').modal('hide');
                    window.location.reload();
                } else {
                    $('#personalInfoModal').modal('hide');
                    Swal.fire({
                        text: result.message,
                        icon: "error",iconColor:"#f05b72",
                    });
                }
                ;
            },
            error: function () {
                Swal.fire({
                    text: '操作失败',
                    icon: "error",iconColor:"#f05b72",
                });
            }
        });
    });
</script>
</body>
</html>

        此页面中主要渲染的数据有收货信息、商品信息、价格信息等数据,收货信息直接读取session对象中的数据,商品信息获取同购物车中的商品数据获取类似,页面读取myShoppingCartItems数据,使用th:each循环语法将商品信息进行渲染。价格信息中运费为0,总价字段直接读取priceTotal字段。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2153791.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

人生小满胜万全

大家好,这里是大话硬件。 最近大家都在讨论房贷利率的问题,昨天晚上看到很多群里在发要降息的小道消息,但是今天早上看到央行发了通告不降息。 下午又在群里看到这个买房对比的截图。对于没买房的人来说,肯定在想,还好当时没有买啊。对于买了房的人来说,可能有些人也在想…

「漏洞复现」灵当CRM marketing/index.php SQL注入漏洞

0x01 免责声明 请勿利用文章内的相关技术从事非法测试&#xff0c;由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失&#xff0c;均由使用者本人负责&#xff0c;作者不为此承担任何责任。工具来自网络&#xff0c;安全性自测&#xff0c;如有侵权请联系删…

Isaac Sim 跑Slam学习过程2024.9.20

# 本文随着时间逐渐增加内容&#xff0c;是学习笔记 # 诶怎么今天Isaac Sim 4.2.0 突然出现了&#xff0c;这哪来的时间再去试试新的.... 没有大佬带...自己学吧 希望使用仿真环境跑定位Slam&#xff0c;现在IMU在Isaac Sim中有现成的传感器模块&#xff0c;GPS则没有&am…

电商ISV 电商SaaS 是什么

Independent Software Vendors的英文缩写&#xff0c;意为“独立软件开发商” 软件即服务(SaaS) 指一种基于云技术的软件交付模式 订阅收费 这些公司叫做ISV软件供应商&#xff0c;通过SaaS服务交付收费 为什么会有电商ISV 从商家角度划分&#xff1a;有独立品牌商家、大商…

MySQL篇(SQL优化)(持续更新迭代)

目录 一、插入数据&#xff1a;Insert 1. 优化方案一&#xff1a;批量插入数据 2. 优化方案二&#xff1a;手动控制事务 3. 优化方案三&#xff1a;主键顺序插入&#xff0c;性能要高于乱序插入 4. 大批量插入数据 5. 案例 5.1. 创建表结构 5.2. 设置参数 5.3. load加载…

计算机毕业设计 基于Python的校园个人闲置物品换购平台 闲置物品交易平台 Python+Django+Vue 前后端分离 附源码 讲解 文档

&#x1f34a;作者&#xff1a;计算机编程-吉哥 &#x1f34a;简介&#xff1a;专业从事JavaWeb程序开发&#xff0c;微信小程序开发&#xff0c;定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事&#xff0c;生活就是快乐的。 &#x1f34a;心愿&#xff1a;点…

Wireshark学习使用记录

wireshark 是一个非常好用的抓包工具&#xff0c;使用 wireshark 工具抓包分析&#xff0c;是学习网络编程必不可少的一项技能。 原理 Wireshark使用的环境大致分为两种:一种是电脑直连互联网的单机环境&#xff0c;另外一种就是应用比较多的互联网环境&#xff0c;也就是连接…

macOS 中搭建 Flutter 开发环境

如果你的 Mac 是 Apple silicon 处理器&#xff0c;那么有些 Flutter 组件就需要通过 Rosetta 2 来转换适配&#xff08;详情&#xff09;。要在 Apple silicon 处理器上运行所有 Flutter 组件&#xff0c;请运行以下指令来安装 Rosetta 2。 sudo softwareupdate --install-ro…

低代码可视化工具-uniapp页面跳转传参-代码生成器

uniapp页面跳转传参 在uni-app中&#xff0c;页面间的跳转和传参是一个常见的需求。uni-app提供了多种页面跳转方式&#xff0c;如uni.navigateTo、uni.redirectTo、uni.reLaunch、uni.switchTab、uni.navigateBack等&#xff0c;每种方式适用于不同的场景。以 页面跳转并传参…

【笔记】第三节 组织与性能

3.1 基本成分 3.2 微观组织特征 0.6-0.8C%碳素钢的组织为珠光体和少量的铁素体。 如何把组织和性能联系起来&#xff1f;德国克虏伯公司的研究——珠光体片间距与渗碳体片层厚度成比例&#xff1a; t s 0 ( ρ 15 ( C % ) − 1 ) ts_0(\frac{\rho}{15(C\%)}-1) ts0​(15(C%)…

【EtherCAT】CiA402简介

目录 1、CiA402是CANopen协议的子协议 2、CiA402是 用于驱动和运动控制的CANopen设备配置文件 3、 CiA402主要由三部分组成 4、CiA介绍 4.1、操作模式 4.2、对象字典 5、一般对象字定义 6、详细对象字定义 7、Profile position mode 8、Homing mode 9、 Position co…

【Unity踩坑】UI Image的fillAmount不起作用

在游戏场景中&#xff0c;我们经常在界面上展示进度条&#xff0c;当然有各种形状的&#xff0c;线性的&#xff0c;长方形的&#xff0c;圆形&#xff0c;环形等等。 Unity中实现这种效果的话&#xff0c;最基本的方法说是改变Image的fillAmout属性。 如果你是初次使用UI Ima…

如何安装1Panel面板并架设一个静态网站

我们通常要架设网站在vps上&#xff0c;就要用到面板&#xff0c;一般是宝塔&#xff0c;但这个面板收费项目较多&#xff0c;用着不太方便。相比宝塔面板&#xff0c;1panel面板是国内功能强大、操作简单、免费易学的Linux服务器管理面板。我们还可以使用一键代码来安装这个面…

新手教学系列——基于统一页面的管理后台设计(二)集成篇

在现代企业级应用中,后台管理系统不仅是业务运营的核心,还承担着数据管理、用户权限控制等重要功能。随着业务规模的不断扩大,系统架构逐渐向微服务转变,多个后端服务模块协同工作,如何高效地集成这些模块,确保系统的稳定性和可维护性,成为开发者亟需解决的问题。在《新…

网络丢包定位记录(一)

数据在Internet上是以数据包为单位传输的&#xff0c;单位为字节&#xff0c;数据在网络上传输&#xff0c;受网络设备&#xff0c;网络质量等原因的影响&#xff0c;使得接收到的数据少于发送出去的数据&#xff0c;造成丢包。 数据包接收、发送原理 发送数据包&#xff1a; …

刷题训练之字符串

> 作者&#xff1a;დ旧言~ > 座右铭&#xff1a;松树千年终是朽&#xff0c;槿花一日自为荣。 > 目标&#xff1a;熟练掌握字符串算法。 > 毒鸡汤&#xff1a;学习&#xff0c;学习&#xff0c;再学习 ! 学&#xff0c;然后知不足。 > 专栏选自&#xff1a;刷题…

2024年9月第3周AI资讯

阅读时间&#xff1a;3-4min 更新时间&#xff1a;2024.9.16-2024.9.20 目录 OpenAI 推出 o1&#xff1a;一种新的“推理”人工智能模型 微软为 Excel 和 Word 添加了更快的 Copilot World Labs 利用 AI 创建 3D 世界 AI 利用文本创建开放世界视频游戏 OpenAI 推出 o1&#x…

ESP32 JTAG 调试

前言 个人邮箱&#xff1a;zhangyixu02gmail.com本人使用的是 Ubuntu 环境&#xff0c;采用 GDB 方式进行调试。对于新手&#xff0c;我个人还是建议参考ESP32S3学习笔记&#xff08;0&#xff09;—— Vscode IDF环境搭建及OpenOCD调试介绍进行图形化的方式调试。如果是希望在…

Java反序列化利用链篇 | URLDNS链

文章目录 URLDNS链调用链分析Payload编写 系列篇其他文章&#xff0c;推荐顺序观看~ Java反序列化利用链篇 | JdbcRowSetImpl利用链分析Java反序列化利用链篇 | CC1链_全网最菜的分析思路Java反序列化利用链篇 | CC1链的第二种方式-LazyMap版调用链Java反序列化利用链篇 | URLD…

【2024华为杯数学建模研赛赛题已出(A-F题)】

华为杯2024年中国研究生数学建模竞赛A-F题已公布 A题 B题 C题 D题 E题 F题