项目总结-商品购买流程

news2024/10/7 8:24:59

(1)添加购物车

 

Controller:

 CartService:

 实现类:

 CartDetail detail=dao.queryByCdid(cid,gds.getId());

CartDao:

//获取详情对象
	@Select("select * from t_cartdetail where cid=#{cid} and gid=#{gid}")
	@ResultType(CartDetail.class)
	public CartDetail queryByCdid(@Param("cid") int cid, @Param("gid") int gid);

 return dao.insertDetail(cd)>0;

//购物车添加商品
	@Insert("insert into t_cartdetail(cid,gid,num,money) values(#{cid},#{gid},#{num},#{money})")
	public int insertDetail(CartDetail cd);

return dao.updateDetail(detail)>0;

//修改购物车中数量
	@Update("update t_cartdetail set num=${num},money=${money} where cid=#{cid} and gid=#{gid}")
	public int updateDetail(CartDetail cartdetail);

(2)查看购物车

CartService:

实现类:

CarDao 

购物车详情表  cid购物车id  gid商品id   num 购买数量

商品表:num 商品库存量 

 

SELECT cd.num,cd.money,cd.gid,
g.name,g.price,g.num as num2,g.picture 
FROM t_cartdetail cd 
LEFT JOIN t_goods g 
ON cd.gid=g.id  
WHERE cd.cid=#{cid}
//购物车的数据
	@Select("SELECT cd.num,cd.money,cd.gid,g.name,g.price,g.num as num2,g.picture FROM t_cartdetail cd LEFT JOIN t_goods g ON cd.gid=g.id  WHERE cd.cid=#{cid}")
	@ResultType(ViewCart.class)
	public List<ViewCart> queryCart(int cid);

(3)删除购物车商品

CartService:

实现类:CarDao:

//清空购物车
	@Delete("delete from  t_cartdetail where cid=#{cid} ")
	public int deleteDetailByCid(int cid);

//删除购物车中的商品
	@Delete("delete from  t_cartdetail where cid=#{cid} and gid=#{gid}")
	public int deleteDetail(@Param("cid") int cid, @Param("gid") int gid);

(4)购物车+ - 按钮

CartService:

实现类:

CartDao:

//获取详情对象
	@Select("select * from t_cartdetail where cid=#{cid} and gid=#{gid}")
	@ResultType(CartDetail.class)
	public CartDetail queryByCdid(@Param("cid") int cid, @Param("gid") int gid);
//修改购物车中数量
	@Update("update t_cartdetail set num=${num},money=${money} where cid=#{cid} and gid=#{gid}")
	public int updateDetail(CartDetail cartdetail);

+  :传递num:1

- :传递num:-1

前端: 

这里有两个num 

num2:商品库存的数量 

num:购买商品的数量

<table class="table table-bordered table-striped table-hover">
 				<tr>
 					<th>图片</th>
 					<th>商品名称</th>
 					<th>价格</th>
 					<th>数量</th>
 					<th>小计</th>
 					<th>操作</th>
 				</tr>
 				<c:set value="0" var="sum"></c:set>

 				<c:forEach items="${carts}" var="c" varStatus="i">
				<c:if test="${c.num2 <= 0 || c.num2 < c.num}">
					<button class="sxsp" type="button" class="btn btn-default" onclick="clearCart2(${c.gid})">删除</button>
				</c:if>

					<c:if test="${c.num2 > 0 || c.num2 >= c.num}">
	 				<tr>
						<th><img style="width: 30px;height: auto" src="${pageContext.request.contextPath}/fmwimages/${c.picture}"></th>
	 					<th>${c.name}</th>
	 					<th>${c.price}</th>
	 					<th width="100px">
		 					<div class="input-group">
		 						<span class="input-group-btn">
		 						<!--数量-1  -->
		 							<button class="btn btn-default" type="button" 
		 							onclick="mNum(${c.gid},${c.price},${i.count})">-
		 							</button>
		 						</span>

		 						<input type="text" class="form-control" id="num_count${i.count}" value="${c.num}" readonly="readonly" style="width:50px;text-align:center;">
								<c:if test="${c.num < c.num2}">
								<span class="input-group-btn">
		 						<!-- 数量+1 -->
		 							<button class="btn btn-default" type="button" onclick="pNum(${c.gid},${c.price},${i.count})">+</button>
		 						</span>
								</c:if>
		 						<c:if test="${c.num >= c.num2}">
								<span class="input-group-btn">
		 						<!-- 数量+1 -->
		 							<button style="pointer-events:none" class="btn btn-default disabled" type="button" onclick="pNum(${c.gid},${c.price},${i.count})">+</button>
		 						</span>
							</c:if>
	 						</div>
	 					</th>
	 					<th>${c.money}元</th>
	 					<th>
	 						<button type="button" class="btn btn-default" onclick="clearCart(${c.gid})">删除</button>
	 					</th>
	 				</tr>
	 				<c:set var="sum" value="${sum+c.money}"></c:set>
					</c:if>
 				</c:forEach>
			</table>

js

<script type="text/javascript">
	//数量+1
	function pNum(gid,p,no){
		var nums = $("#num_count"+no).val();
		$.ajax({
			url:"updateCartNum?gid="+gid+"&num=1&price="+p,
			method:"get",
			success:function(){
				location.href = "getCart";
			},
			error:function(){
				alert("服务器异常");
			}
		})
	}
	//数量-1  如果删除为0 
	function mNum(gid,p,no){
		var num = -1; //数量
		var nums = $("#num_count"+no).val();
		//验证是否需要删除
		if(Number(nums)<=1){
			if(confirm("确认要删除吗?")){
				/* num = 0; */
				location.href="clearCart?gid="+gid;
				return;
			}else{
				return;
			}
		}
		//异步
		$.ajax({
			url:"updateCartNum?gid="+gid+"&num="+num+"&price="+p,
			method:"get",
			success:function(){
				location.href = "getCart";
			},
			error:function(){
				alert("服务器异常");
			}
		})
	}
	function clearCart(gid){
		if(confirm("确认要删除吗")){
			location.href="clearCart?gid="+gid;
		}
	}
	function clearCart2(gid){
			location.href="clearCart?gid="+gid;
	}

	$(function (){
		$(".sxsp").click();
	})
</script>

(5)获取订单

 

OrderController: 

type=2为购物车下单

CarService 

//购物车的数据
	@Select("SELECT cd.num,cd.money,cd.gid,g.name,g.price,g.num as num2,g.picture FROM t_cartdetail cd LEFT JOIN t_goods g ON cd.gid=g.id  WHERE cd.cid=#{cid}")
	@ResultType(ViewCart.class)
	public List<ViewCart> queryCart(int cid);

UserAddressService: 

实现类:

UserAddressDao:

//查询地址
	@Select("select * from t_useraddress where uid=#{uid} order by flag desc")
	@ResultType(UserAddress.class)
	public List<UserAddress> queryByUid(int uid);

(6)提交订单

res = service.insertDirect(user.getId(), oid, aid, (CartDetail) session.getAttribute("direct")); 

 

实现类 

 

dao.insert(order);

//新增 订单
	@Insert("insert into t_order(id,uid,uaid,money,createtime,flag) values(#{id},#{uid},#{uaid},#{money},now(),1)")
	public int insert(Order order);
dao.insertDetail(detail);

 

 

//新增 订单详情
	@Insert("insert into t_orderdetail(oid,gid,money,num) values(#{oid},#{gid},#{money},#{num})")
	public int insertDetail(OrderDetail detail);
goodsDao.updateGoodsNum(cd.getNum(),cd.getGid());

 

GoodDao

//修改商品数量
	@Update("update t_goods set num = num - #{num} where id = #{id}")
	int updateGoodsNum(@Param("num") int num,@Param("id") int id);

 res = service.save(oid, user.getId(), aid);

实现类: 

CartDao:

//获取用户的购物车详情
	@Select("select cd.* from t_cartdetail cd left join t_cart c on cd.cid=c.id where c.uid=#{uid}")
	@ResultType(CartDetail.class)
	public List<CartDetail> queryByDetail(int uid);

OrderDao 

//新增 订单详情
	@Insert("insert into t_orderdetail(oid,gid,money,num) values(#{oid},#{gid},#{money},#{num})")
	public int insertDetail(OrderDetail detail);

 

GoodDao:

//修改商品数量
	@Update("update t_goods set num = num - #{num} where id = #{id}")
	int updateGoodsNum(@Param("num") int num,@Param("id") int id);

 

cartDao.deleteDetailByCid(cds.get(0).getCid());

//清空购物车
	@Delete("delete from  t_cartdetail where cid=#{cid} ")
	public int deleteDetailByCid(int cid);

 cartDao.updateEmpty(cds.get(0).getCid());

//清空购物车
	@Update("update t_cart set money=0 where id=#{id}")
	public int updateEmpty(int id);

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

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

相关文章

buu第五页 wp

[RootersCTF2019]babyWeb 预期解 一眼就是sql注入&#xff0c;发现过滤了 UNION SLEEP " OR - BENCHMARK盲注没法用了&#xff0c;因为union被过滤&#xff0c;堆叠注入也不考虑&#xff0c;发现报错有回显&#xff0c;尝试报错注入。 尝试&#xff1a; 1||(updatex…

ubuntu20.04下安装nc

前言 nc在网络渗透测试中非常好用&#xff0c;这里的主要记一下Ubuntu20.04中nc的安装 编译安装 第一种方式是自己编译安装&#xff0c;先下载安装包 nc.zip wget http://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1.tar.gz/download -O netcat-0.7.…

anyproxy 的安装和抓包使用

简介 AnyProxy是阿里开发的开源的代理服务器&#xff0c;主要特性包括&#xff1a; 基于Node.js&#xff0c;开放二次开发能力&#xff0c;允许自定义请求处理逻辑支持Https的解析提供GUI界面&#xff0c;用以观察请求 安装运行Anyproxy 首先需要电脑由安装 node&#xff0…

H3C SecParh堡垒机 data_provider.php 远程命令执行漏洞

构造poc执行远程命令&#xff1a; /audit/data_provider.php?ds_y2019&ds_m04&ds_d02&ds_hour09&ds_min40&server_cond&service$(id)&identity_cond&query_typeall&formatjson&browsetrue漏洞证明&#xff1a; 文笔生疏&#xff0c…

【大模型应用开发教程】02_LangChain介绍

LangChain介绍 什么是 LangChain1. 模型输入/输出2. 数据连接3. 链&#xff08;Chain&#xff09;4. 记忆&#xff08;Meomory&#xff09;5. 代理&#xff08;Agents&#xff09;6.回调&#xff08;Callback&#xff09;在哪里传入回调 ?你想在什么时候使用这些东西呢&#x…

1024常玩到的漏洞(第十六课)

1024常玩到的两个漏洞(第十六课) 漏洞扫描工具 1024渗透OpenVas扫描工具使用(第十四课)-CSDN博客 流程 一 ms12-020漏洞分析 MS12-020漏洞是一种远程桌面协议(RDP)漏洞。在攻击者利用该漏洞之前,它需要将攻击者的计算机连接到受害者的计算机上。攻击者可以通过向受害者计算…

跟着NatureMetabolism学作图:R语言ggplot2转录组差异表达火山图

论文 Independent phenotypic plasticity axes define distinct obesity sub-types https://www.nature.com/articles/s42255-022-00629-2#Sec15 s42255-022-00629-2.pdf 论文中没有公开代码&#xff0c;但是所有作图数据都公开了&#xff0c;我们可以试着用论文中提供的数据…

Linux进程与线程的内核实现

进程描述符task_struct 进程描述符&#xff08;struct task_struct&#xff09;pid与tgid进程id编号分配规则内存管理mm_struct进程与文件,文件系统 进程,线程创建的本质 clone函数原型线程创建的实现进程创建的实现 总结 进程描述符task_struct 进程描述符&#xff08;st…

自动驾驶的商业应用和市场前景

自动驾驶技术已经成为了交通运输领域的一项重要创新。它不仅在改善交通安全性和效率方面具有巨大潜力&#xff0c;还为各种商业应用提供了新的机会。本文将探讨自动驾驶在交通运输中的潜力&#xff0c;自动驾驶汽车的制造商和技术公司&#xff0c;以及自动驾驶的商业模式和市场…

Git GUI工具:SourceTree代码管理

Git GUI工具&#xff1a;SourceTree SourceTreeSourceTree的安装SourceTree的使用 总结 SourceTree 当我们对Git的提交、分支已经非常熟悉&#xff0c;可以熟练使用命令操作Git后&#xff0c;再使用GUI工具&#xff0c;就可以更高效。 Git有很多图形界面工具&#xff0c;这里…

JAVA高级教程Java 泛型(10)

目录 三、泛型的使用泛型类泛型接口泛型方法 四、泛型在集合中的使用1、使用泛型来创建set2、使用泛型来创建HashSet3、使用equals&#xff0c;hashCode的使用Person 类HashSet的使用泛型TreeSet的使用泛型comparator实现定制比较(比较器) 三、泛型的使用 泛型类语法 类名T表示…

散列表:如何打造一个工业级水平的散列表?

文章来源于极客时间前google工程师−王争专栏。 散列表的查询效率并不能笼统地说成是O(1)。它跟散列函数、装载因子、散列冲突等都有关系。如果散列函数设计得不好&#xff0c;或者装载因子过高&#xff0c;都可能导致散列冲突发生的概率升高&#xff0c;查询效率下降。 极端情…

在ESP32上使用Arduino(Arduino as an ESP-IDF component)

目录 前言 原理说明 操作步骤 下载esp-arduino 安装esp-arduino 工程里配置arduino 1、勾选该选项&#xff0c;工程将作为一个标准的arduino程序工作 2、不勾选该选型&#xff0c;工程将作为一个传统的嵌入式项目开发&#xff0c; 前言 Arduino拥有丰富的各类库&#…

一款WPF开发的网易云音乐客户端 - DMSkin-CloudMusic

前言 今天推荐一款基于DMSkin框架开发的网易云音乐播放器&#xff1a;DMSkin-CloudMusic。 DMSkin 框架介绍 DMSkin是一个开源的WPF样式UI框架&#xff0c;可以帮助开发者快速创建漂亮的用户界面。 下载体验 下载地址&#xff1a;https://github.com/944095635/DMSkin-Clou…

如何使用vim粘贴鼠标复制的内容

文章目录 一、使用步骤1.找到要编辑的配置文件2.找到目标文件3.再回到vim编辑器 一、使用步骤 1.找到要编辑的配置文件 用sudo vim /etc/apt/sources.list编辑软件源配置文件 sudo vim /etc/apt/sources.listvim 在默认的情况下当鼠标选中的时候进入的 Visual 模式&#xff…

加法器:如何像搭乐高一样搭电路(上)?

目录 背景 异或门和半加器 全加器 小结 补充阅读 背景 上一讲&#xff0c;我们看到了如何通过电路&#xff0c;在计算机硬件层面设计最基本的单元&#xff0c;门电路。我给你看的门电路非常简单&#xff0c;只能做简单的 “与&#xff08;AND&#xff09;”“或&#xff…

UG\NX二次开发 获取用户默认设置中的绘图信息 UF_PLOT_ask_session_job_options

文章作者:里海 来源网站:《里海NX二次开发3000例专栏》 感谢粉丝订阅 感谢 m0_58724732 订阅本专栏,非常感谢。 简介 UG\NX二次开发 获取用户默认设置中的绘图信息 UF_PLOT_ask_session_job_options 效果 代码 #include "me.hp

window11安装Python环境

python环境安装 访问Python官网:https://www.python.org/ 点击downloads按钮&#xff0c;在下拉框中选择系统类型(windows/Mac OS/Linux等) 选择下载最新版本的Python cmd命令如果出现版本号以及>>>则表示安装成功 如果出现命令行中输入python出现如下错误 可能…

【SSA-RFR预测】基于麻雀算法优化随机森林回归预测研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

【JavaEE重点知识归纳】第11节:认识异常

目录 一&#xff1a;异常的概念和体系结构 1.概念 2.体系结构 3.异常分类 二&#xff1a;异常的处理 1.防御式编程 2.异常的抛出 3.异常的捕获 4.异常的处理流程 三&#xff1a;自定义异常 一&#xff1a;异常的概念和体系结构 1.概念 &#xff08;1&#xff09;在…