package com.itheima.web.servlet;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import com.google.gson.Gson;
import com.itheima.domain.Cart;
import com.itheima.domain.CartItem;
import com.itheima.domain.Category;
import com.itheima.domain.Order;
import com.itheima.domain.OrderItem;
import com.itheima.domain.PageBean;
import com.itheima.domain.Product;
import com.itheima.domain.User;
import com.itheima.service.ProductService;
import com.itheima.utils.CommonsUtils;
import com.itheima.utils.JedisPoolUtils;
import com.itheima.utils.PaymentUtil;
import redis.clients.jedis.Jedis;
public class PrdocutServlet extends BaseServlet {
//获得我的订单
public void myOrders(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
ProductService service = new ProductService();
//查询该用户的所有的订单信息(单表查询orders表)
//集合中的每一个Order对象的数据是不完整的 缺少List<OrderItem> orderItems数据
List<Order> orderList = service.findAllOrders(user.getUid());
//循环所有的订单 为每个订单填充订单项集合信息
if(orderList!=null){
for(Order order : orderList){
//获得每一个订单的oid
String oid = order.getOid();
//查询该订单的所有的订单项---mapList封装的是多个订单项和该订单项中的商品的信息
List<Map<String, Object>> mapList = service.findAllOrderItemByOid(oid);
//将mapList转换成List<OrderItem> orderItems
for(Map<String,Object> map : mapList){
try {
//从map中取出count subtotal 封装到OrderItem中
OrderItem item = new OrderItem();
//item.setCount(Integer.parseInt(map.get("count").toString()));
BeanUtils.populate(item, map);
//从map中取出pimage pname shop_price 封装到Product中
Product product = new Product();
BeanUtils.populate(product, map);
//将product封装到OrderItem
item.setProduct(product);
//将orderitem封装到order中的orderItemList中
order.getOrderItems().add(item);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
//orderList封装完整了
request.setAttribute("orderList", orderList);
request.getRequestDispatcher("/order_list.jsp").forward(request, response);
}
//确认订单---更新收获人信息+在线支付
public void confirmOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1、更新收货人信息
Map<String, String[]> properties = request.getParameterMap();
Order order = new Order();
try {
BeanUtils.populate(order, properties);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
ProductService service = new ProductService();
service.updateOrderAdrr(order);
//2、在线支付
/*if(pd_FrpId.equals("ABC-NET-B2C")){
//介入农行的接口
}else if(pd_FrpId.equals("ICBC-NET-B2C")){
//接入工行的接口
}*/
//.......
//只接入一个接口,这个接口已经集成所有的银行接口了 ,这个接口是第三方支付平台提供的
//接入的是易宝支付
// 获得 支付必须基本数据
String orderid = request.getParameter("oid");
//String money = order.getTotal()+"";//支付金额
String money = "0.01";//支付金额
// 银行
String pd_FrpId = request.getParameter("pd_FrpId");
// 发给支付公司需要哪些数据
String p0_Cmd = "Buy";
String p1_MerId = ResourceBundle.getBundle("merchantInfo").getString("p1_MerId");
String p2_Order = orderid;
String p3_Amt = money;
String p4_Cur = "CNY";
String p5_Pid = "";
String p6_Pcat = "";
String p7_Pdesc = "";
// 支付成功回调地址 ---- 第三方支付公司会访问、用户访问
// 第三方支付可以访问网址
String p8_Url = ResourceBundle.getBundle("merchantInfo").getString("callback");
String p9_SAF = "";
String pa_MP = "";
String pr_NeedResponse = "1";
// 加密hmac 需要密钥
String keyValue = ResourceBundle.getBundle("merchantInfo").getString(
"keyValue");
String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt,
p4_Cur, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP,
pd_FrpId, pr_NeedResponse, keyValue);
String url = "https://www.yeepay.com/app-merchant-proxy/node?pd_FrpId="+pd_FrpId+
"&p0_Cmd="+p0_Cmd+
"&p1_MerId="+p1_MerId+
"&p2_Order="+p2_Order+
"&p3_Amt="+p3_Amt+
"&p4_Cur="+p4_Cur+
"&p5_Pid="+p5_Pid+
"&p6_Pcat="+p6_Pcat+
"&p7_Pdesc="+p7_Pdesc+
"&p8_Url="+p8_Url+
"&p9_SAF="+p9_SAF+
"&pa_MP="+pa_MP+
"&pr_NeedResponse="+pr_NeedResponse+
"&hmac="+hmac;
//重定向到第三方支付平台
response.sendRedirect(url);
}
//提交订单
public void submitOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
//目的:封装好一个Order对象 传递给service层
Order order = new Order();
//1、private String oid;//该订单的订单号
String oid = CommonsUtils.getUUID();
order.setOid(oid);
//2、private Date ordertime;//下单时间
order.setOrdertime(new Date());
//3、private double total;//该订单的总金额
//获得session中的购物车
Cart cart = (Cart) session.getAttribute("cart");
double total = cart.getTotal();
order.setTotal(total);
//4、private int state;//订单支付状态 1代表已付款 0代表未付款
order.setState(0);
//5、private String address;//收货地址
order.setAddress(null);
//6、private String name;//收货人
order.setName(null);
//7、private String telephone;//收货人电话
order.setTelephone(null);
//8、private User user;//该订单属于哪个用户
order.setUser(user);
//9、该订单中有多少订单项List<OrderItem> orderItems = new ArrayList<OrderItem>();
//获得购物车中的购物项的集合map
Map<String, CartItem> cartItems = cart.getCartItems();
for(Map.Entry<String, CartItem> entry : cartItems.entrySet()){
//取出每一个购物项
CartItem cartItem = entry.getValue();
//创建新的订单项
OrderItem orderItem = new OrderItem();
//1)private String itemid;//订单项的id
orderItem.setItemid(CommonsUtils.getUUID());
//2)private int count;//订单项内商品的购买数量
orderItem.setCount(cartItem.getBuyNum());
//3)private double subtotal;//订单项小计
orderItem.setSubtotal(cartItem.getSubtotal());
//4)private Product product;//订单项内部的商品
orderItem.setProduct(cartItem.getProduct());
//5)private Order order;//该订单项属于哪个订单
orderItem.setOrder(order);
//将该订单项添加到订单的订单项集合中
order.getOrderItems().add(orderItem);
}
//order对象封装完毕
//传递数据到service层
ProductService service = new ProductService();
service.submitOrder(order);
session.setAttribute("order", order);
//页面跳转
response.sen
没有合适的资源?快使用搜索试试~ 我知道了~
源代码-网上商城之HeimaShop-5.rar
共499个文件
jpg:180个
gif:66个
png:58个
需积分: 5 0 下载量 161 浏览量
2023-08-20
09:00:18
上传
评论
收藏 27.41MB RAR 举报
温馨提示
一、功能的演示 1.用户模块 用户注册功能 发送邮件 激活用户 表单的校验 用户的登录功能 自动登录 用户的注销功能 2.商品模块 首页热门商品和最新商品功能 商品分类 商品的列表(分页) 商品详细信息 浏览记录功能 3.购物车模块 将商品加入购物车 展示购物车功能 4.订单模块(多表和事务) 提交订单 展示订单 在线支付。。 5.后台的分类的模块 分类信息的增删改查 6.后台的商品模块 商品的信息的增删改查(文件上传) 7.后台的订单的模块 所有的订单的信息展示。。 二、一般项目开发流程(公司之间是有差异) 1)确定项目需求-----拿下一个项目 2)编写《需求说明书》----不涉及技术,只涉及业务需求 3)编写《概要设计说明书》----- 涉及技术的的宏观的内容,数据库设计,页面原型 4)编写《详细设计说明书》----- 相当于伪代码 5)编码阶段coding----根据《详细设计说明书》--- 单元测试 6)联测-----项目组内部的行为 7)测试组进行全面的专业测试----《测试报告》 8)上线(测试阶段) 9)维护和二次开发 三、网上商城项目的环境的搭建 (1)创建项
资源推荐
资源详情
资源评论
收起资源包目录
源代码-网上商城之HeimaShop-5.rar (499个子文件)
common.css.bak 20KB
cmb.bmp 6KB
hx.bmp 6KB
gf.bmp 6KB
cmbc.bmp 6KB
pingan.bmp 6KB
zx.bmp 6KB
sfz.bmp 6KB
ccb.bmp 6KB
icbc.bmp 6KB
bj.bmp 6KB
post.bmp 6KB
bc.bmp 6KB
zheshang.bmp 6KB
abc.bmp 6KB
beijingnongshang.bmp 6KB
bcc.bmp 6KB
ningbo.bmp 6KB
dy.bmp 6KB
cib.bmp 6KB
sh.bmp 6KB
bh.bmp 6KB
shpd.bmp 6KB
nanjing.bmp 6KB
guangda.bmp 6KB
PrdocutServlet.class 14KB
ProductDao.class 6KB
ProductService.class 5KB
AdminAddProductServlet.class 5KB
PaymentUtil.class 4KB
RegisterServlet.class 3KB
UserServlet.class 3KB
CallbackServlet.class 3KB
AdminServlet.class 3KB
AdminDao.class 3KB
AutoLoginFilter.class 3KB
Order.class 3KB
UserDao.class 2KB
Product.class 2KB
User.class 2KB
JedisPoolUtils.class 2KB
UserLoginPrivilegeFilter.class 2KB
DataSourceUtils.class 2KB
MailUtils.class 2KB
AdminServiceImpl.class 2KB
PageBean.class 2KB
BeanFactory.class 2KB
UserService.class 2KB
CheckUsernameServlet.class 2KB
MD5Utils.class 2KB
BaseServlet.class 2KB
OrderItem.class 1KB
ActiveServlet.class 1KB
RegisterServlet$1.class 1KB
Cart.class 1KB
CartItem.class 992B
Category.class 719B
MailUtils$1.class 672B
AdminService.class 601B
CommonsUtils.class 468B
.classpath 841B
org.eclipse.wst.common.component 479B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 144KB
bootstrap.min.css 120KB
bootstrap.min.css 120KB
product.css 29KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
common.css 20KB
Style1.css 13KB
index.css 9KB
datepicker.css 5KB
cart.css 3KB
slider.css 2KB
register.css 2KB
login.css 2KB
popup_layer.css 932B
dtree.css 795B
style.css 786B
left.css 220B
glyphicons-halflings-regular.eot 20KB
loading.gif 20KB
common.gif 14KB
common.gif 14KB
loading_bar.gif 11KB
product.gif 9KB
product.gif 9KB
product.gif 9KB
logo.gif 8KB
logo1.gif 8KB
member.gif 7KB
review.gif 7KB
cart.gif 6KB
cart.gif 6KB
index.gif 5KB
logo.gif 3KB
logo.gif 3KB
article.gif 3KB
info.gif 3KB
共 499 条
- 1
- 2
- 3
- 4
- 5
资源评论
常驻客栈
- 粉丝: 1w+
- 资源: 1366
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- Docker在Ubuntu16.04上安装和部署Apache Storm
- test_kong.zip
- springboot权限验证学习-下
- SeetaFace6人脸质量评估C++代码实现Demo
- OCAuxiliaryTools
- 制药公司QC顶岗实习专题报告
- Rust 全面指南:从基础到高级,一网打尽 Rust 的编程知识
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功