ADD file via upload

main
pjhmizn49 1 year ago
parent f56b5df6ca
commit 15b48df584

@ -0,0 +1,694 @@
package com.example.flower.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.flower.entity.*;
import com.example.flower.service.*;
import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.flower.unit.JWTUtil;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
@RestController
@RequestMapping("/order")
public class OrderController {
@Resource
private OrderService orderService;
@Resource
private DiscountService discountService;
@Resource
private FlowerService flowerService;
@Resource
private PackService packService;
@Resource
private GiftService giftService;
@Resource
private UserService userService;
@PostMapping("/list") //orderList获取所有花卉信息列表
public JSONObject orderList(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
JSONObject jsonObject1 = new JSONObject();
int page=param.getIntValue("page");
int page_size=param.getIntValue("page_size");
List<Order> orderList = orderService.orderList(page,page_size).getList();
jsonObject1.put("page_number", orderService.orderList(page,page_size).getPages());
jsonObject1.put("total", orderService.orderList(page,page_size).getTotal());
int size=orderList.size();
JSONObject[] objects = new JSONObject[size];
for(int i = 0;i<size;i++){
objects[i]=new JSONObject();
objects[i].put("order_id", orderList.get(i).getOrder_id());
objects[i].put("user_id", orderList.get(i).getUser_id());
objects[i].put("order_type", orderList.get(i).getOrder_type());
objects[i].put("order_price", orderList.get(i).getOrder_price());
objects[i].put("order_delivery_number",orderList.get(i).getOrder_delivery_number());
objects[i].put("order_time", orderList.get(i).getOrder_time());
objects[i].put("order_time_pay",orderList.get(i).getOrder_time_pay());
objects[i].put("order_time_delivery", orderList.get(i).getOrder_time_delivery());
objects[i].put("order_time_receive", orderList.get(i).getOrder_time_receive());
objects[i].put("order_address",orderList.get(i).getOrder_address());
objects[i].put("order_phone",orderList.get(i).getOrder_phone());
objects[i].put("order_state", orderList.get(i).getOrder_state());
objects[i].put("order_method", orderList.get(i).getOrder_method());
objects[i].put("trans_fee",orderList.get(i).getTrans_fee());
objects[i].put("order_discount",orderList.get(i).getOrder_discount());
objects[i].put("order_seen",orderList.get(i).getOrder_seen());
}
jsonObject1.put("orders",objects);
jsonObject.put("code",200 );
jsonObject.put("msg","token认证成功!" );
jsonObject.put("data",jsonObject1);
return jsonObject;
}
@PostMapping("/query") //orderListByQuery查询订单信息列表
public JSONObject orderListByQuery(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
JSONObject jsonObject1 = new JSONObject();
int page=param.getIntValue("page");
int page_size=param.getIntValue("page_size");
int order_id;
try {
order_id = param.getIntValue("order_id");
}catch (Exception e){
order_id = 0;
}
List<Order> orderList = orderService.orderListByQuery(page,page_size,order_id).getList();
jsonObject1.put("page_number", orderService.orderListByQuery(page,page_size,order_id).getPages());
jsonObject1.put("total", orderService.orderListByQuery(page,page_size,order_id).getTotal());
int size=orderList.size();
JSONObject[] objects = new JSONObject[size];
for(int i = 0;i<size;i++){
objects[i]=new JSONObject();
objects[i].put("order_id", orderList.get(i).getOrder_id());
objects[i].put("user_id", orderList.get(i).getUser_id());
objects[i].put("order_type", orderList.get(i).getOrder_type());
objects[i].put("order_price", orderList.get(i).getOrder_price());
objects[i].put("order_delivery_number",orderList.get(i).getOrder_delivery_number());
objects[i].put("order_time", orderList.get(i).getOrder_time());
objects[i].put("order_time_pay",orderList.get(i).getOrder_time_pay());
objects[i].put("order_time_delivery", orderList.get(i).getOrder_time_delivery());
objects[i].put("order_time_receive", orderList.get(i).getOrder_time_receive());
objects[i].put("order_address",orderList.get(i).getOrder_address());
objects[i].put("order_phone",orderList.get(i).getOrder_phone());
objects[i].put("order_state", orderList.get(i).getOrder_state());
objects[i].put("order_method", orderList.get(i).getOrder_method());
objects[i].put("trans_fee",orderList.get(i).getTrans_fee());
objects[i].put("order_discount",orderList.get(i).getOrder_discount());
objects[i].put("order_seen",orderList.get(i).getOrder_seen());
}
jsonObject1.put("orders",objects);
jsonObject.put("code",200 );
jsonObject.put("msg","token认证成功!" );
jsonObject.put("data",jsonObject1);
return jsonObject;
}
@PostMapping("/deletePer") //orderDeletePer删除单个订单
public JSONObject orderDeletePer(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
int flag = orderService.orderDeletePer(param.getIntValue("order_id"));
if(flag==1){
jsonObject.put("code",200 );
jsonObject.put("msg","成功" );
}
else {
jsonObject.put("code",403 );
jsonObject.put("msg","删除失败" );
}
return jsonObject;
}
@PostMapping("/deleteMul") //orderDeleteMul批量删除订单
public JSONObject orderDeleteMul(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
//获取请求参数
JSONArray order_ids = param.getJSONArray("order_ids");
int [] ids = new int[order_ids.size()];
//把userid中的数据进行类型转换并存入到int数组中
for (int i = 0; i < order_ids.size(); i++) {
ids[i] = Integer.parseInt(order_ids.getString(i));
}
int result = orderService.orderDeleteMul(ids);
if(result == ids.length){
jsonObject.put("code",200);
jsonObject.put("msg","批量删除成功,删除了"+result+"条订单数据");
}else{
jsonObject.put("code",403);
jsonObject.put("msg","批量删除失败,删除了"+result+"条订单数据");
}
return jsonObject;
}
@PostMapping("/modify") //orderModify订单状态修改
public JSONObject orderModify(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
int order_id = param.getIntValue("order_id");
int state = param.getIntValue("state"); // 支付1/发货2/收货3/取消4/退款5
String order_delivery_number = param.getString("order_delivery_number"); //送货上门-发货-快递单号
if(!(state==1 || state==2 || state==3 || state==4 || state==5)){ //订单状态码错误
jsonObject.put("code",403 );
jsonObject.put("msg","订单状态码错误" );
return jsonObject;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 格式化
Date date = new Date();
String time = sdf.format(date);
int flag = orderService.orderModify(order_id,state,time,order_delivery_number);
if(flag==1){
jsonObject.put("code",200 );
jsonObject.put("msg","修改成功" );
}
else{
jsonObject.put("code",403 );
jsonObject.put("msg","修改失败" );
}
return jsonObject;
}
@PostMapping("/detail/flower") //花卉订单详情
public JSONObject orderDetailFlower(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
int order_id = param.getIntValue("order_id");
Order order = orderService.orderInfo(order_id);
if(order == null){
jsonObject.put("code",403);
jsonObject.put("msg","获取订单信息失败!");
jsonObject.put("data",null);
return jsonObject;
}
jsonObject.put("code",200);
jsonObject.put("msg","获取订单信息成功!");
//订单信息
JSONObject jsonObject_order = new JSONObject();
jsonObject_order.put("order_id",order.getOrder_id());
jsonObject_order.put("user_id",order.getUser_id());
jsonObject_order.put("order_type",order.getOrder_type());
jsonObject_order.put("order_price",order.getOrder_price());
jsonObject_order.put("order_delivery_number",order.getOrder_delivery_number());
jsonObject_order.put("order_time",order.getOrder_time());
jsonObject_order.put("order_time_pay",order.getOrder_time_pay());
jsonObject_order.put("order_time_delivery",order.getOrder_time_delivery());
jsonObject_order.put("order_time_receive",order.getOrder_time_receive());
jsonObject_order.put("order_address",order.getOrder_address());
jsonObject_order.put("order_phone",order.getOrder_phone());
jsonObject_order.put("order_state",order.getOrder_state());
jsonObject_order.put("order_method",order.getOrder_method());
jsonObject_order.put("trans_fee",order.getTrans_fee());
try{
jsonObject_order.put("order_discount_name",discountService.discountInfo(order.getOrder_discount()).getDiscount_name());
jsonObject_order.put("order_discount_num",discountService.discountInfo(order.getOrder_discount()).getDiscount_num());
}catch (Exception e){
jsonObject_order.put("order_discount_name",null);
jsonObject_order.put("order_discount_num",null);
}
//花卉信息
List<Order_Detail_Flower> order_details = orderService.orderDetailFlower(order_id);
int size=order_details.size();
JSONObject[] jsonObject_flower = new JSONObject[size];
for(int i=0;i<size;i++){
Flower flower = flowerService.flowerInfo(order_details.get(i).getFlower_id());
jsonObject_flower[i] = new JSONObject();
jsonObject_flower[i].put("flower_id",flower.getFlower_id());
jsonObject_flower[i].put("flower_name",flower.getFlower_name());
jsonObject_flower[i].put("flower_price",flower.getFlower_price());
jsonObject_flower[i].put("number",order_details.get(i).getNumber());
double sumP = 0.00; //包装金额小计
//包装信息
if(order_details.get(i).getPack_ids() ==null || Objects.equals(order_details.get(i).getPack_ids(), "")){
jsonObject_flower[i].put("packs",null);
jsonObject_flower[i].put("sum",String.format("%.2f", flower.getFlower_price() * order_details.get(i).getNumber()) ); //花卉+包装 金额小计
}
else{
//数组拆分
String[] pack_ids_string = order_details.get(i).getPack_ids().split(",");
int [] pack_ids_int = new int[pack_ids_string.length];
for(int j=0;j<pack_ids_string.length;j++){
if(pack_ids_string[j]!=null)
pack_ids_int[j] = Integer.parseInt(pack_ids_string[j].trim());
}
JSONObject[] object_pack = new JSONObject[pack_ids_int.length];
for(int k=0;k<pack_ids_int.length;k++){
Pack pack = packService.packInfo(pack_ids_int[k]);
object_pack[k] = new JSONObject();
object_pack[k].put("pack_id",pack.getPack_id());
object_pack[k].put("pack_name",pack.getPack_name());
object_pack[k].put("pack_price",pack.getPack_price());
sumP += pack.getPack_price();
}
jsonObject_flower[i].put("sum",(flower.getFlower_price()+sumP) * order_details.get(i).getNumber()); //花卉+包装 金额小计
jsonObject_flower[i].put("packs",object_pack);
}
}
jsonObject_order.put("flowers",jsonObject_flower);
jsonObject.put("data",jsonObject_order);
System.out.println(jsonObject);
return jsonObject;
}
@PostMapping("/detail/gift") //换赠订单详情
public JSONObject orderDetailGift(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
int order_id = param.getIntValue("order_id");
Order order = orderService.orderInfo(order_id);
if(order == null){
jsonObject.put("code",403);
jsonObject.put("msg","获取订单信息失败!");
jsonObject.put("data",null);
return jsonObject;
}
jsonObject.put("code",200);
jsonObject.put("msg","获取订单信息成功!");
//订单信息
JSONObject jsonObject_order = new JSONObject();
jsonObject_order.put("order_id",order.getOrder_id());
jsonObject_order.put("user_id",order.getUser_id());
jsonObject_order.put("order_type",order.getOrder_type());
jsonObject_order.put("order_price",order.getOrder_price());
jsonObject_order.put("order_delivery_number",order.getOrder_delivery_number());
jsonObject_order.put("order_time",order.getOrder_time());
jsonObject_order.put("order_time_pay",order.getOrder_time_pay());
jsonObject_order.put("order_time_delivery",order.getOrder_time_delivery());
jsonObject_order.put("order_time_receive",order.getOrder_time_receive());
jsonObject_order.put("order_address",order.getOrder_address());
jsonObject_order.put("order_phone",order.getOrder_phone());
jsonObject_order.put("order_state",order.getOrder_state());
jsonObject_order.put("order_method",order.getOrder_method());
jsonObject_order.put("trans_fee",order.getTrans_fee());
//赠品信息
List<Order_Detail_Gift> order_details = orderService.orderDetailGift(order_id);
int size=order_details.size();
JSONObject[] jsonObject_gift = new JSONObject[size];
for(int i=0;i<size;i++){
Gift gift = giftService.giftInfo(order_details.get(i).getGift_id());
jsonObject_gift[i] = new JSONObject();
jsonObject_gift[i].put("gift_id",gift.getGift_id());
jsonObject_gift[i].put("gift_name",gift.getGift_name());
jsonObject_gift[i].put("gift_point",gift.getGift_point());
jsonObject_gift[i].put("number",order_details.get(i).getNumber());
jsonObject_gift[i].put("sum",order_details.get(i).getNumber() * gift.getGift_point());
}
jsonObject_order.put("gifts",jsonObject_gift);
jsonObject.put("data",jsonObject_order);
System.out.println(jsonObject);
return jsonObject;
}
@PostMapping("/statistic") //订单统计相关
public JSONObject orderStatistic(@RequestHeader String Authorization){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
jsonObject.put("code",200);
jsonObject.put("msg","统计信息成功");
JSONObject jsonObject_top = new JSONObject();
jsonObject_top.put("order_pay_num",orderService.order_pay_num());
jsonObject_top.put("order_ok_num",orderService.order_ok_num());
jsonObject_top.put("order_today_money",orderService.order_today_money());
jsonObject_top.put("order_month_money",orderService.order_month_money());
jsonObject_top.put("order_delivery_num",orderService.order_delivery_num());
jsonObject_top.put("order_refund_num",orderService.order_refund_num());
//月度成交金额折线图
JSONObject jsonObject_middle = new JSONObject();
int month = LocalDate.now().getMonthValue();
int year = LocalDate.now().getYear();
for(int i=1;i<=month;i++){
String time;
if(i<10)
time = year+"-0"+i;
else
time = year+"-"+i;
jsonObject_middle.put(i+"月",orderService.order_month_line(time));
}
//销售榜top3 柱状图
List<Rank> rankList1 = orderService.order_flower_top3();
JSONObject[] jsonObject_bottom1 = new JSONObject[rankList1.size()];
for(int i=0;i<rankList1.size();i++){
jsonObject_bottom1[i]=new JSONObject();
jsonObject_bottom1[i].put("name", rankList1.get(i).getName());
jsonObject_bottom1[i].put("value", rankList1.get(i).getValue());
}
//类别销售量饼图
List<Rank> rankList2 = orderService.order_class_rank();
JSONObject[] jsonObject_bottom2 = new JSONObject[rankList2.size()];
for(int i=0;i<rankList2.size();i++){
jsonObject_bottom2[i]=new JSONObject();
jsonObject_bottom2[i].put("name", rankList2.get(i).getName());
jsonObject_bottom2[i].put("value", rankList2.get(i).getValue());
}
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("data_top",jsonObject_top);
jsonObject1.put("data_middle",jsonObject_middle);
jsonObject1.put("data_bottom1",jsonObject_bottom1);
jsonObject1.put("data_bottom2",jsonObject_bottom2);
jsonObject.put("data",jsonObject1);
return jsonObject;
}
// 前台
@PostMapping("/add") //orderAdd添加订单
public JSONObject orderAdd(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
JSONArray shoppingData = param.getJSONArray("shoppingData");
for(int i=0;i<shoppingData.size();i++){
Order order = new Order();
Claims claims = JWTUtil.getBodyByToken(Authorization);
int user_id = (int) claims.get("id");
order.setUser_id(user_id);
order.setOrder_type(param.getIntValue("order_type"));
double flower_price = shoppingData.getJSONObject(i).getDoubleValue("flower_price");
int number = shoppingData.getJSONObject(i).getIntValue("number");
double trans_fee = param.getDoubleValue("trans_fee");
double pack_total_price = shoppingData.getJSONObject(i).getDoubleValue("pack_total_price");
order.setOrder_price( (flower_price + pack_total_price) * number + trans_fee);
order.setOrder_address(param.getString("order_address"));
order.setOrder_phone(param.getString("order_phone"));
order.setOrder_state(1); //默认支付成功,状态待发货
order.setOrder_method(Integer.parseInt(param.getString("order_method")));
order.setTrans_fee(trans_fee);
order.setOrder_discount(param.getIntValue("order_discount"));
order.setOrder_seen(1); //默认用户可见
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 格式化
Date date = new Date();
String order_time = sdf.format(date);
String order_time_pay = sdf.format(date);
order.setOrder_time(order_time);
order.setOrder_time_pay(order_time_pay);
orderService.orderAdd(order);
int order_id = order.getOrder_id();
//添加信息至detail表
if(order.getOrder_type()==0){ //商品订单
Order_Detail_Flower order_detail_flower = new Order_Detail_Flower();
order_detail_flower.setOrder_id(order_id);
order_detail_flower.setFlower_id(shoppingData.getJSONObject(i).getIntValue("flower_id"));
order_detail_flower.setNumber(shoppingData.getJSONObject(i).getIntValue("number"));
//增加销量
flowerService.flowerAddNum(order_detail_flower.getFlower_id(),order_detail_flower.getNumber());
//增加会员积分
User user = userService.userInfo(user_id);
if(user.getUser_role()==1) { //用户是会员
int addPoint = (int) param.getDoubleValue("order_price");
int point = user.getMember_point();
user.setMember_point(point+addPoint);
userService.userModifyPoint(user);
}
JSONArray packs = shoppingData.getJSONObject(i).getJSONArray("pack");
if(packs==null){
order_detail_flower.setPack_ids("");
}
else{
int[] pack_ids_int = new int[packs.size()];
for(int j=0;j<packs.size();j++){
pack_ids_int[j] = packs.getJSONObject(j).getIntValue("pack_id");
}
String pack_ids_string = Arrays.toString(pack_ids_int).replace("[","").replace("]","").replace(" ","");
order_detail_flower.setPack_ids(pack_ids_string);
}
orderService.orderAdd_flower(order_detail_flower);
}
else if (order.getOrder_type()==1) { //换赠订单
Order_Detail_Gift order_detail_gift = new Order_Detail_Gift();
order_detail_gift.setOrder_id(order_id);
order_detail_gift.setGift_id(shoppingData.getJSONObject(i).getIntValue("gift_id"));
order_detail_gift.setNumber(shoppingData.getJSONObject(i).getIntValue("number"));
orderService.orderAdd_gift(order_detail_gift);
//减赠品库存
giftService.giftModifyStock(order_detail_gift.getGift_id(),order_detail_gift.getNumber());
//减会员积分
User user = userService.userInfo(user_id);
int subPoint = (int) param.getDoubleValue("order_price");
int point = user.getMember_point();
user.setMember_point(point-subPoint);
userService.userModifyPoint(user);
}
}
jsonObject.put("code",200 );
jsonObject.put("msg","成功" );
return jsonObject;
}
@PostMapping("/userListFlower") //userListFlower获取用户所有商品订单
public JSONObject orderUserListFlower(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
JSONObject jsonObject1 = new JSONObject();
int page=param.getIntValue("page");
int page_size=param.getIntValue("page_size");
Claims claims = JWTUtil.getBodyByToken(Authorization);
int user_id = (int) claims.get("id");
List<Order> orderUserListAll = orderService.orderUserListFlower(page,page_size,user_id).getList();
jsonObject1.put("page_number", orderService.orderUserListFlower(page,page_size,user_id).getPages());
jsonObject1.put("total", orderService.orderUserListFlower(page,page_size,user_id).getTotal());
int size=orderUserListAll.size();
JSONObject[] objects = new JSONObject[size];
for(int i = 0;i<size;i++){
objects[i]=new JSONObject();
int order_id = orderUserListAll.get(i).getOrder_id();
objects[i].put("order_id", order_id);
objects[i].put("order_type", orderUserListAll.get(i).getOrder_type());
objects[i].put("order_price", orderUserListAll.get(i).getOrder_price());
objects[i].put("order_state", orderUserListAll.get(i).getOrder_state());
objects[i].put("trans_fee",orderUserListAll.get(i).getTrans_fee());
//商品订单
List<Order_Detail_Flower> order_details = orderService.orderDetailFlower(order_id);
Flower flower = flowerService.flowerInfo(order_details.get(0).getFlower_id());
objects[i].put("flower_id",flower.getFlower_id());
objects[i].put("flower_name",flower.getFlower_name());
objects[i].put("flower_price",flower.getFlower_price());
objects[i].put("flower_pic",flower.getFlower_pic());
objects[i].put("number",order_details.get(0).getNumber());
//包装信息
if(order_details.get(0).getPack_ids() ==null || Objects.equals(order_details.get(0).getPack_ids(), "")){
objects[i].put("packs",null);
}
else{
//数组拆分
String[] pack_ids_string = order_details.get(0).getPack_ids().split(",");
int [] pack_ids_int = new int[pack_ids_string.length];
for(int k=0;k<pack_ids_string.length;k++){
if(pack_ids_string[k]!=null)
pack_ids_int[k] = Integer.parseInt(pack_ids_string[k].trim());
}
JSONObject[] object_pack = new JSONObject[pack_ids_int.length];
for(int k=0;k<pack_ids_int.length;k++){
Pack pack = packService.packInfo(pack_ids_int[k]);
object_pack[k] = new JSONObject();
object_pack[k].put("pack_id",pack.getPack_id());
object_pack[k].put("pack_name",pack.getPack_name());
object_pack[k].put("pack_price",pack.getPack_price());
}
objects[i].put("packs",object_pack);
}
}
jsonObject1.put("orders",objects);
jsonObject.put("code",200 );
jsonObject.put("msg","成功!" );
jsonObject.put("data",jsonObject1);
return jsonObject;
}
@PostMapping("/userListGift") //orderUserListGift获取用户所有换赠订单
public JSONObject orderUserListGift(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
JSONObject jsonObject1 = new JSONObject();
int page=param.getIntValue("page");
int page_size=param.getIntValue("page_size");
Claims claims = JWTUtil.getBodyByToken(Authorization);
int user_id = (int) claims.get("id");
List<Order> orderUserListAll = orderService.orderUserListGift(page,page_size,user_id).getList();
jsonObject1.put("page_number", orderService.orderUserListGift(page,page_size,user_id).getPages());
jsonObject1.put("total", orderService.orderUserListGift(page,page_size,user_id).getTotal());
int size=orderUserListAll.size();
JSONObject[] objects = new JSONObject[size];
for(int i = 0;i<size;i++){
objects[i]=new JSONObject();
int order_id = orderUserListAll.get(i).getOrder_id();
objects[i].put("order_id", order_id);
objects[i].put("order_type", orderUserListAll.get(i).getOrder_type());
objects[i].put("order_price", orderUserListAll.get(i).getOrder_price());
objects[i].put("order_state", orderUserListAll.get(i).getOrder_state());
objects[i].put("trans_fee",orderUserListAll.get(i).getTrans_fee());
//换赠订单
List<Order_Detail_Gift> order_details = orderService.orderDetailGift(order_id);
Gift gift = giftService.giftInfo(order_details.get(0).getGift_id());
objects[i].put("gift_id",gift.getGift_id());
objects[i].put("gift_name",gift.getGift_name());
objects[i].put("gift_point",gift.getGift_point());
objects[i].put("gift_pic",gift.getGift_pic());
objects[i].put("number",order_details.get(0).getNumber());
}
jsonObject1.put("orders",objects);
jsonObject.put("code",200 );
jsonObject.put("msg","成功!" );
jsonObject.put("data",jsonObject1);
return jsonObject;
}
@PostMapping("/userDelete") //orderUserDelete用户删除订单仅不可见
public JSONObject orderUserDelete(@RequestHeader String Authorization, @RequestBody JSONObject param){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
int flag = orderService.orderUserDelete(param.getIntValue("order_id"));
if(flag==1){
jsonObject.put("code",200 );
jsonObject.put("msg","成功!" );
}
else {
jsonObject.put("code",403 );
jsonObject.put("msg","删除失败!" );
}
return jsonObject;
}
@PostMapping("/userOrderCount") //用户订单统计相关
public JSONObject userOrderCount(@RequestHeader String Authorization){
JSONObject jsonObject = new JSONObject();
if(!JWTUtil.checkToken(Authorization)){ //token认证失败
JWTUtil.checkTokenFailed(jsonObject);
return jsonObject;
}
Claims claims = JWTUtil.getBodyByToken(Authorization);
int user_id = (int) claims.get("id");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("order_send",orderService.orderUserSend(user_id));
jsonObject1.put("order_receive",orderService.orderUserReceive(user_id));
jsonObject1.put("order_pay",orderService.orderUserPay(user_id));
jsonObject.put("code",200);
jsonObject.put("msg","统计信息成功");
jsonObject.put("data",jsonObject1);
return jsonObject;
}
}
Loading…
Cancel
Save