package com.bjb.domain;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
/**
* 订单持久化类
*
* @author jiangzy
*
*/
@Repository
public class OrderRepository {
private final JdbcTemplate jdbcTemplate;
HashMap<String, Object> hash = new HashMap<String, Object>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Date date = new Date();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = format.format(date);
String sql = null;
@Autowired
public OrderRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
/*
* 获取订单信息
*/
public HashMap<String, Object> myorders(HttpSession httpSession) {
int create_id = (Integer) httpSession.getAttribute("user_id");
// 根据登录者查出自己的订单
sql = "SELECT * FROM deal_order WHERE del_flg = '0' and create_id="
+ create_id + " ORDER BY order_id DESC";
list = jdbcTemplate.queryForList(sql);
hash.put("status", "1");
hash.put("list", list);
hash.put("info", create_id);
return hash;
}
/*
* 添加订单
*/
public HashMap<String, Object> add_order(String id, HttpSession httpSession) {
sql = "SELECT * FROM deal_item left join deal_store on deal_item.store_id = deal_store.store_id WHERE item_id = "
+ id;
list = jdbcTemplate.queryForList(sql);
int item_id = (Integer) list.get(0).get("item_id");
String item_name = (String) list.get(0).get("item_name");
String item_price = (String) list.get(0).get("item_price");
int store_id = (Integer) list.get(0).get("store_id");
String store_name = (String) list.get(0).get("store_name");
int payment_state = 0;
int send_state = 0;
int save_state = 0;
int order_state = 0;
int del_flg = 0;
String create_time = time;
int user_id =(Integer) httpSession.getAttribute("user_id");
String update_time = time;
sql = "insert into deal_order"
+ "(item_id, item_name, item_price, store_id, store_name, payment_state, send_state,save_state,order_state,del_flg,create_time,create_id,update_time,update_id) "
+ "values ("+ item_id+ ",'"+ item_name+ "','"+ item_price+ "',"+ store_id+ ",'"+ store_name+ "',"+ payment_state+ ","+ send_state+ ","+ save_state+ ","
+ order_state+ ","+ del_flg+ ",'"+ create_time+ "',"+ user_id+ ",'"+ update_time + "'," + user_id + ")";
int result = jdbcTemplate.update(sql);
if (result == 1) {
hash.put("status", "1");
hash.put("msg", "success");
} else {
hash.put("status", "1");
hash.put("msg", "添加订单失败!");
}
return hash;
}
/*
* 支付订单
*/
public HashMap<String, Object> pay_order(int order_id,HttpSession httpSession){
sql = "SELECT item_price,store_id FROM deal_order WHERE order_id = "+ order_id;
list = jdbcTemplate.queryForList(sql);
int price =Integer.parseInt((String) list.get(0).get("item_price"));
int store_id =(Integer) ((Map<String, Object>)list.get(0)).get("store_id");
String user_name = ((Map<String,String>)((List)httpSession.getAttribute("LOGIN_INFO")).get(0)).get("user_name");
sql = "SELECT money FROM deal_user WHERE user_name = '"+user_name+"'";
list = jdbcTemplate.queryForList(sql);
int money = Integer.parseInt((String) (list.get(0)).get("money"));
if (money < price) {
hash.put("status", "0");
hash.put("msg", "no money");
}else{
sql = "UPDATE deal_user SET money = money - "+price+" WHERE user_name = '"+user_name+"'";
//更新买家的余额,(用户余额减商品价格)
jdbcTemplate.update(sql);
//更新卖家的余额,(用户未到账余额加商品价格)
sql = "UPDATE deal_store SET road_money = road_money + "+price+" WHERE store_id = "+store_id;
jdbcTemplate.update(sql);
int payment_state = 1;
sql = "update deal_order set payment_state =" + payment_state+ " where order_id =" + order_id;
//更新支付状态
int res = jdbcTemplate.update(sql);
if (res == 1) {
hash.put("status", "1");
hash.put("msg", "支付成功!");
}
}
return hash;
}
/*
* 取消订单
*/
public HashMap<String, Object> cancel_order(int order_id){
int order_state = 2;
sql = "update deal_order set order_state =" + order_state
+ " where order_id =" + order_id;
int result = jdbcTemplate.update(sql);
if (result == 1) {
hash.put("status", "1");
hash.put("msg", "取消成功!");
} else {
hash.put("status", "1");
hash.put("msg", "取消失败!");
}
return hash;
}
/*
* 删除订单
*/
public HashMap<String, Object> del_order(int order_id){
int del_flg = 1;
sql = "update deal_order set del_flg =" + del_flg
+ " where order_id =" + order_id;
int result = jdbcTemplate.update(sql);
if (result == 1) {
hash.put("status", "1");
hash.put("msg", "删除成功!");
} else {
hash.put("status", "1");
hash.put("msg", "删除失败!");
}
return hash;
}
/*
* 获取我的订单列表
*/
public HashMap<String, Object> orders_list(String store_id) {
sql = "SELECT * FROM deal_order WHERE store_id = " + store_id;
list = jdbcTemplate.queryForList(sql);
hash.put("status", "1");
hash.put("msg", list);
return hash;
}
/*
* 发货
*/
public HashMap<String, Object> shipments(int order_id, int user_id) {
int send_state = 1;
sql = "update deal_order set send_state =" + send_state
+ ",update_time ='" + time + "',update_id =" + user_id
+ " where order_id =" + order_id;
int result = jdbcTemplate.update(sql);
if (result == 1) {
hash.put("status", "1");
hash.put("msg", "发货成功!");
} else {
hash.put("status", "1");
hash.put("msg", "发货失败!");
}
return hash;
}
/*
* 收货
*/
public HashMap<String, Object> affirm_goods(int order_id) {
sql = "SELECT item_price,store_id FROM deal_order WHERE order_id = " + order_id;
list = jdbcTemplate.queryForList(sql);
int price =Integer.parseInt((String) list.get(0).get("item_price"));
int store_id =(Integer) ((Map<String, Object>)list.get(0)).get("store_id");
sql = "UPDATE deal_store SET money = money +"+price+",road_money = road_money -"+price +" WHERE store_id = "+store_id;
//将未到账余额转入余额
jdbcTemplate.update(sql);
int save_state = 1;
int order_state = 1;
sql = "update deal_order set save_state =" + save_state+ ", order_state = "+order_state+" where order_id =" + order_id;
//更新订单状态
int res = jdbcTemplate.update(sql);
if (res == 1) {
hash.put("status", "1");
hash.put("msg","收货成功!");
}else {
hash.put("status", "1");
hash.put("msg", "收货失败!");
}
return hash;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Maven之Spring Boot--网络商城系统基础版 (109个子文件)
OrderRepository.class 8KB
ItemRepository.class 5KB
OrderController.class 3KB
ItemController.class 3KB
UserRepository.class 3KB
Order.class 3KB
User.class 3KB
StoreRepository.class 2KB
Store.class 2KB
Item.class 2KB
UserController.class 2KB
TestRepository$1.class 1KB
TestController.class 1KB
TestRepository.class 1KB
StoreController.class 1KB
Test.class 889B
App.class 698B
AppTest.class 611B
AppTest.class 605B
UserService.class 290B
.classpath 543B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 144KB
bootstrap.css 144KB
bootstrap.min.css 120KB
bootstrap.min.css 120KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
style.css 353B
style.css 353B
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
mystore.html 11KB
mystore.html 11KB
myorder.html 6KB
myorder.html 6KB
nve.html 4KB
nve.html 4KB
index.html 3KB
index.html 3KB
login.html 1KB
login.html 1KB
test.html 753B
test.html 753B
hello.html 305B
hello.html 305B
ordermanage.html 0B
error.html 0B
main.html 0B
ordermanage.html 0B
OrderRepository.java 7KB
ItemRepository.java 3KB
ItemController.java 3KB
UserRepository.java 3KB
Order.java 3KB
OrderController.java 3KB
User.java 2KB
Store.java 2KB
Item.java 2KB
TestController.java 1KB
UserController.java 1KB
StoreRepository.java 1KB
TestRepository.java 1KB
StoreController.java 858B
Test.java 490B
App.java 357B
UserService.java 84B
jquery.js 288KB
jquery.js 288KB
jquery.min.js 94KB
jquery.min.js 94KB
jquery-1.9.0.min.js 91KB
jquery-1.9.0.min.js 91KB
bootstrap.js 68KB
bootstrap.js 68KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
common.js 4KB
common.js 4KB
script.js 908B
script.js 908B
.jsdtscope 658B
bootstrap.css.map 381KB
bootstrap.css.map 381KB
bootstrap-theme.css.map 47KB
bootstrap-theme.css.map 47KB
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 124B
org.eclipse.m2e.core.prefs 90B
com.genuitec.eclipse.core.prefs 73B
.project 744B
application.properties 207B
application.properties 207B
db_deal.sql 4KB
db_deal.sql 4KB
Crud.sql 3KB
Crud.sql 3KB
共 109 条
- 1
- 2
资源评论
- 小飞狼2018-04-16初学者自行车
- ChikyoW2018-03-23支持,紫薯布丁
AUQF_zy
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功