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

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

(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"><spanaria-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.xdnf.cn/news/146763.html

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

相关文章

C++_多态

C_多态 多态的概念 通俗来讲&#xff0c;就是多种形态。多态分为编译时多态&#xff08;静态多态&#xff09;和运行时多态&#xff08;动态多态&#xff09;。 编译时多态主要就是函数重载和函数模板&#xff0c;他们传不同类型的参数就可以调用不同的函数&#xff0c;通过…

简单有效关于msvcp140.dll丢失的解决方法,msvcp140.dll

这篇文章将和大家分享几种msvcp140.dll丢失的解决方法&#xff0c;分析解决方法为什么能够通过这种方法进行修复成功&#xff0c;有效的将丢失的msvcp140.dll文件进行修复完成。 msvcp140.dll丢失&#xff1f;简单有效的解决途径 一、重新安装相关软件 原理 许多应用程序在安…

研究生数学建模竞赛E题思路模型参考文献高速公路应急车道紧急启用模型——高速公路饱和路段动态应急车道开放决策模型研究

1 概述 动态应急车道 ( Hard Shoulder Running ) 作为 调整路段交通流运行现状的重要管理手段&#xff0c; 可以在短时间内提供道路供给&#xff0c; 有效提升瓶颈路段的通行 能力。 早在 21 世纪初 &#xff0c; 欧美国家就已经通过开放 应急车道缓解的方式来解决路段的交…

2024最受人追捧的电脑远程控制软件推荐!首选这五款!好用、连接稳定、安全性高!

在2024年&#xff0c;电脑远程控制软件市场上涌现了众多受欢迎且功能强大的选择。 以下是根据最新信息推荐的五款好用、连接稳定、安全性高的电脑远程控制软件&#xff1a; 1. 安企神 特点&#xff1a;它是全球知名的远程控制软件&#xff0c;以其稳定性和可靠性著称。 它支…

C++——初步认识C++和namespace的用法

1.编程语言排行榜 我们通过排行可以看出 C在变成语言中还是占据着重要的地位 2.C在工作领域中的应用 1.PC客户端开发。⼀般是开发Windows上的桌面软件&#xff0c;比如WPS之类的&#xff0c;技术栈的话⼀般是C和 QT&#xff0c;QT 是⼀个跨平台的 C图形用户界面&#xff08;G…

sourceTree使用脚本一键push代码到gerrit

问题 在gerrit,我们无法直接把代码push到对应的分支。需要把代码push到 HEAD:refs/for/branch,review通过后再submit到分支。所以无法直接使用sourceTree上的推送按钮来push代码。但是可以通过自定义操作和脚本来实现这一功能。 脚本编写 新建文本文档写入以下内容&#xff…

fmql之ubuntu添加dhcp服务

按照官方指示&#xff1a;【在文末】 2024-08-22 buildroot linux 使用wpa_supplicant -B -i wlan0 切换WIFI 设备之后无法上网的问题。解决方法&#xff0c;使用udhcpc -i wlan0 命令-CSDN博客 网口连接路由器&#xff0c;然后发现路由器分配了ip&#xff0c;但是板卡没有配置…

VulnHub-Narak靶机笔记

Narak靶机笔记 概述 Narak是一台Vulnhub的靶机&#xff0c;其中有简单的tftp和webdav的利用&#xff0c;以及motd文件的一些知识 靶机地址&#xff1a; https://pan.baidu.com/s/1PbPrGJQHxsvGYrAN1k1New?pwda7kv 提取码: a7kv 当然你也可以去Vulnhub官网下载 一、nmap扫…

写作练习(一)

一、reply Z-Library The aim is to express gratitude and practice writing, and as a record. 二、Original letter As a college student of computer and a blogger, Z-Library is always a part of my study, which provide many books that I need pay a lost of time …

安捷伦Agilent/keysight 53220A参数资料 通用频率计 计数器

Agilent 53220A&#xff0c;Keysight 53220A&#xff0c;通用频率计数器/计时器&#xff0c;350 MHz&#xff0c;12 位&#xff0c;100 ps 53220A 350 MHz 通用频率计数器/计时器是一款双通道频率计数器&#xff0c;能够执行所需的全部频率和时间间隔测量。它可以添加可选的射…

突破常规:如何利用动态系统思维彻底变革你的团队!

引言 在现代社会中&#xff0c;变化是唯一不变的。面对快速发展的科技和瞬息万变的市场环境&#xff0c;企业和开发团队必须具备适应性和灵活性。动态系统思维作为一种理解和应对复杂系统中变化的方法&#xff0c;提供了有效的解决方案。本文将探讨动态系统思维在敏捷方法中的应…

load jsonl File with OpenAI API request results to pandas data.frame

题意&#xff1a;将包含 OpenAI API 请求结果的 jsonl 文件加载到 pandas DataFrame 中 问题背景&#xff1a; I have a large data set containing around 500k observation. It has a string variable that I want to create an embedding for. I used the OpenAI API to cr…

AI入门系列 | 如何优雅地下载最前沿的模型?

​简介 一片白云横谷口&#xff0c;几多归鸟尽迷巢。 小伙伴们好&#xff0c;我是微信公众号《小窗幽记机器学习》的小编&#xff1a;卖铁观音的小男孩。本系列主要基于过往经历&#xff0c;总结当时自身环境中实操经验。倘若能够顺便帮到他人&#xff0c;也是善莫大焉。 本文…

[已更新]2024数学建模研赛华为杯E题详细思路代码成品文章研究生数学建模数模辅导

截止2024.8.21 12点 已更新e全部小问的建模和问题一的代码 ####https://docs.qq.com/doc/DVU9YYUFLWlNOY3pyE题: 问题1&#xff1a;统计四个观测点的交通流参数随时间的变化规律 为了统计交通流参数&#xff08;如车流密度、流量和速度&#xff09;&#xff0c;首先需要从视…

猫咪检测系统源码分享

猫咪检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer Vision …

Easypoi模板导出

Easypoi模板导出 优点 快速导出&#xff1a;使用预定义的Excel模板&#xff0c;可以快速导出数据&#xff0c;特别是在数据量大的情况下。简化代码&#xff1a;通过模板导出&#xff0c;减少了编写大量POI代码的需要&#xff0c;使得代码更简洁易懂。灵活性&#xff1a;模板可…

Camunda如何共享流程定义但不共享流程实例?

文章目录 一、项目场景二、问题描述三、解决方案方案一&#xff1a;官方实例化共享定义的方法1. 部署共享定义2. 在查询中包含共享的定义3. 实例化共享定义 方案二&#xff1a;自定义TenantIdProvider方法&#xff0c;将租户id作为变量添加到启动的实例中1. 采用自定义的Tenant…

PHP API 框架:构建高效API的利器

在当今快速发展的互联网时代&#xff0c;API&#xff08;应用程序编程接口&#xff09;已成为连接不同应用程序和服务的关键。PHP&#xff0c;作为一种流行的服务器端脚本语言&#xff0c;提供了多种强大的框架来简化API的开发。本文将介绍PHP API框架的重要性&#xff0c;以及…

Linux笔记---简单指令

1. 使用的环境 博主使用的是华为云服务器xshell终端的方式学习的&#xff0c;因为据说这样的方式比较接近以后的工作环境。 其中云服务器安装的是Ubuntu操作系统(以Linux为内核&#xff0c;适合新手学习Linux的一个版本) 这里的云服务器不一定使用华为的&#xff0c;但是我在…

论文推荐——犹豫直觉模糊偏好关系积性一致性及其在群决策中的应用

犹豫直觉模糊偏好关系积性一致性及其在群决策中的应用 论文全文 论文全文 论文最巧妙的地方就是修正了积性一致性的条件&#xff0c;使得修复方法完全满足互补条件&#xff0c;也算对大佬的工作做了一个很好的修补。