Authored by tanling

订单列表

  1 +package com.yohoufo.order.common;
  2 +
  3 +public enum ButtonShow {
  4 +
  5 + CANCEL_ORDER("cancel_order","取消订单"),
  6 + NOW_BUY("now_buy", "立即支付"),
  7 + CONFIRM_DELIVERY("confirm_delivery", "确认收货"),
  8 + SHOW_DETAIL("show_detail", "查看详情"),
  9 + BUY_AGAIN("buy_again", "再次购买"),
  10 + DEL_ORDER("del_order", "删除"),
  11 + SHOW_EXPRESS("show_express", "查看物流"),
  12 + ;
  13 +
  14 + String code;
  15 + String value;
  16 +
  17 + ButtonShow(String code,String value) {
  18 + this.code = code;
  19 + this.value = value;
  20 + }
  21 +}
@@ -31,12 +31,12 @@ public enum OrderListType { @@ -31,12 +31,12 @@ public enum OrderListType {
31 31
32 String desc; 32 String desc;
33 33
34 - List<Integer> status; 34 + List<Integer> statusQuery;
35 35
36 - OrderListType(int type, String desc, List<Integer> status) { 36 + OrderListType(int type, String desc, List<Integer> statusQuery) {
37 this.type = type; 37 this.type = type;
38 this.desc = desc; 38 this.desc = desc;
39 - this.status = status; 39 + this.statusQuery = statusQuery;
40 } 40 }
41 41
42 /** 42 /**
@@ -57,11 +57,7 @@ public enum OrderListType { @@ -57,11 +57,7 @@ public enum OrderListType {
57 return type; 57 return type;
58 } 58 }
59 59
60 - public String getDesc() {  
61 - return desc;  
62 - }  
63 -  
64 - public List<Integer> getStatus() {  
65 - return status; 60 + public List<Integer> getStatusQuery() {
  61 + return statusQuery;
66 } 62 }
67 } 63 }
1 package com.yohoufo.order.common; 1 package com.yohoufo.order.common;
2 2
  3 +import java.util.Arrays;
  4 +import java.util.List;
  5 +
3 public enum OrderStatus { 6 public enum OrderStatus {
4 7
5 - // 14:支付前取消,15:超时未支付取消,16:已支付,卖家发货前取消;17:客服取消  
6 - WAITING_PAY(0, "未付款"),  
7 - HAS_PAYED(1, "已付款"),  
8 - SELLER_SEND_OUT(2, "商品调拨中(卖家发货,可查物流)"),  
9 - PLATFORM_CHECKING(3, "有货平台鉴定中"),  
10 - WAITING_RECEIVE(4, "待收货"),  
11 - DONE(5, "已完成"),  
12 - SELLER_CANCEL_BEFORE_PAY(10, "买家付款前卖家取消"),  
13 - SELLER_CANCEL_AFTER_PAY(11, "买家付款后卖家取消"),  
14 - SEND_OUT_TIMEOUT(12, "超时未发货取消"),  
15 - CHECKING_FAKE(13, "鉴定不通过取消"),  
16 - BUYER_CANCEL_BEFORE_PAY(14, "支付前取消"),  
17 - BUYER_CANCEL_TIMEOUT(15, "超时未支付取消"),  
18 - CUSTOMER_SERVICE(17, "客服取消") 8 + WAITING_PAY(0,
  9 + "未付款",
  10 + "待付款",
  11 + Arrays.asList(ButtonShow.CANCEL_ORDER, ButtonShow.NOW_BUY)),
  12 +
  13 + HAS_PAYED(1,
  14 + "已付款",
  15 + "商品调拨中",
  16 + Arrays.asList(ButtonShow.SHOW_DETAIL)),
  17 +
  18 + SELLER_SEND_OUT(2,
  19 + "商品调拨中(卖家发货,可查物流)",
  20 + "商品调拨中",
  21 + Arrays.asList(ButtonShow.SHOW_DETAIL)),
  22 +
  23 + PLATFORM_CHECKING(3,
  24 + "有货平台鉴定中",
  25 + "有货平台鉴定中",
  26 + Arrays.asList(ButtonShow.SHOW_DETAIL)),
  27 +
  28 + WAITING_RECEIVE(4,
  29 + "待收货",
  30 + "待收货",
  31 + Arrays.asList(ButtonShow.SHOW_EXPRESS, ButtonShow.CONFIRM_DELIVERY)),
  32 +
  33 + DONE(5,
  34 + "已完成",
  35 + "交易成功",
  36 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  37 +
  38 + SELLER_CANCEL_BEFORE_PAY(10,
  39 + "买家付款前卖家取消",
  40 + "交易失败",
  41 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  42 +
  43 + SELLER_CANCEL_AFTER_PAY(11,
  44 + "买家付款后卖家取消",
  45 + "交易失败",
  46 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  47 +
  48 + SEND_OUT_TIMEOUT(12,
  49 + "超时未发货取消",
  50 + "交易失败",
  51 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  52 +
  53 + CHECKING_FAKE(13,
  54 + "鉴定不通过取消",
  55 + "交易失败",
  56 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  57 +
  58 + BUYER_CANCEL_BEFORE_PAY(14,
  59 + "支付前取消",
  60 + "交易失败",
  61 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  62 +
  63 + BUYER_CANCEL_TIMEOUT(15,
  64 + "超时未支付取消",
  65 + "交易失败",
  66 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER)),
  67 +
  68 + CUSTOMER_SERVICE(17,
  69 + "客服取消",
  70 + "交易失败",
  71 + Arrays.asList(ButtonShow.SHOW_DETAIL, ButtonShow.BUY_AGAIN, ButtonShow.DEL_ORDER))
19 ; 72 ;
20 73
21 int code; 74 int code;
22 75
23 String desc; 76 String desc;
24 77
25 - OrderStatus(int code, String desc) { 78 + String listStatusStr;
  79 +
  80 + List<ButtonShow> buttonList;
  81 +
  82 +
  83 + /**
  84 + *
  85 + * @param code db中code
  86 + * @param desc db中code的含义
  87 + * @param listStatusStr 订单列表中状态显示
  88 + * @param buttonList 订单列表显示的按钮
  89 + */
  90 + OrderStatus(int code, String desc, String listStatusStr, List<ButtonShow> buttonList) {
26 this.code = code; 91 this.code = code;
27 this.desc = desc; 92 this.desc = desc;
  93 + this.listStatusStr = listStatusStr;
  94 + this.buttonList = buttonList;
28 } 95 }
29 96
30 public int getCode() { 97 public int getCode() {
31 return code; 98 return code;
32 } 99 }
33 100
34 - public void setCode(int code) {  
35 - this.code = code; 101 + public List<ButtonShow> getButtonList() {
  102 + return buttonList;
  103 + }
  104 +
  105 + public String getListStatusStr() {
  106 + return listStatusStr;
  107 + }
  108 +
  109 + public static OrderStatus getOrderStatus(int code){
  110 + for(OrderStatus v : values()){
  111 + if(v.code == code){
  112 + return v;
  113 + }
  114 + }
  115 + return null;
36 } 116 }
37 } 117 }
@@ -2,6 +2,7 @@ package com.yohoufo.order.controller; @@ -2,6 +2,7 @@ package com.yohoufo.order.controller;
2 2
3 import com.yohoufo.common.ApiResponse; 3 import com.yohoufo.common.ApiResponse;
4 import com.yohoufo.order.request.OrderListRequest; 4 import com.yohoufo.order.request.OrderListRequest;
  5 +import com.yohoufo.order.response.OrderInfoListRsp;
5 import com.yohoufo.order.service.IBuyerOrderService; 6 import com.yohoufo.order.service.IBuyerOrderService;
6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RequestMapping;
@@ -34,11 +35,14 @@ public class BuyerOrderController { @@ -34,11 +35,14 @@ public class BuyerOrderController {
34 @RequestParam(value = "page", required = false, defaultValue = "1") int page, 35 @RequestParam(value = "page", required = false, defaultValue = "1") int page,
35 @RequestParam(value = "limit", required = false, defaultValue = "10") int limit) { 36 @RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
36 37
37 - OrderListRequest orderListRequest = new OrderListRequest();  
38 - orderListRequest.setUid(uid);  
39 - orderListRequest.setType(type);  
40 - orderListRequest.setPage(page);  
41 - orderListRequest.setLimit(limit);  
42 - return null; 38 + OrderListRequest orderListRequest = OrderListRequest.builder()
  39 + .uid(uid)
  40 + .type(type)
  41 + .page(page)
  42 + .limit(limit)
  43 + .build();
  44 + OrderInfoListRsp orderInfoListRsp = buyerOrderService.getOrderList(orderListRequest);
  45 +
  46 + return new ApiResponse.ApiResponseBuilder().code(200).data(orderInfoListRsp).message("订单列表").build();
43 } 47 }
44 } 48 }
1 package com.yohoufo.order.response; 1 package com.yohoufo.order.response;
2 2
  3 +import com.yohoufo.order.common.ButtonShow;
3 import lombok.Data; 4 import lombok.Data;
4 5
  6 +import java.util.List;
  7 +
5 @Data 8 @Data
6 public class OrderInfo { 9 public class OrderInfo {
7 10
@@ -32,4 +35,17 @@ public class OrderInfo { @@ -32,4 +35,17 @@ public class OrderInfo {
32 * 35 *
33 */ 36 */
34 int leftTime; 37 int leftTime;
  38 +
  39 +
  40 + int status;
  41 +
  42 + /**
  43 + * 列表中状态显示
  44 + */
  45 + String statuStr;
  46 +
  47 + /**
  48 + * 按钮显示
  49 + */
  50 + List<ButtonShow> buttons;
35 } 51 }
  1 +package com.yohoufo.order.response;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Data;
  5 +import lombok.NoArgsConstructor;
  6 +import lombok.experimental.Builder;
  7 +
  8 +import java.util.List;
  9 +
  10 +@Data
  11 +@Builder
  12 +@NoArgsConstructor
  13 +@AllArgsConstructor
  14 +public class OrderInfoListRsp {
  15 +
  16 + List<OrderInfo> data;
  17 +
  18 + // 页码
  19 + private int currPage;
  20 + // 每页记录数
  21 + private int limit;
  22 +
  23 + // 总记录数
  24 + private int total;
  25 + // 当前页记录数
  26 + private int currTotal;
  27 + // 页数
  28 + private int pageSize;
  29 +
  30 +}
1 package com.yohoufo.order.service; 1 package com.yohoufo.order.service;
2 2
  3 +import com.yohoufo.order.request.OrderListRequest;
  4 +import com.yohoufo.order.response.OrderInfoListRsp;
  5 +
3 public interface IBuyerOrderService { 6 public interface IBuyerOrderService {
  7 +
  8 +
  9 + /**
  10 + * 订单列表
  11 + * @param request
  12 + * @return
  13 + */
  14 + public OrderInfoListRsp getOrderList(OrderListRequest request);
4 } 15 }
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
  3 +import com.google.common.collect.Lists;
3 import com.yoho.core.rest.client.ServiceCaller; 4 import com.yoho.core.rest.client.ServiceCaller;
4 import com.yoho.error.ServiceError; 5 import com.yoho.error.ServiceError;
5 import com.yoho.error.exception.ServiceException; 6 import com.yoho.error.exception.ServiceException;
  7 +import com.yohoufo.common.utils.DateUtil;
6 import com.yohoufo.dal.order.BuyerOrderGoodsMapper; 8 import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
7 import com.yohoufo.dal.order.BuyerOrderMapper; 9 import com.yohoufo.dal.order.BuyerOrderMapper;
8 import com.yohoufo.dal.order.SellerOrderGoodsMapper; 10 import com.yohoufo.dal.order.SellerOrderGoodsMapper;
@@ -10,8 +12,10 @@ import com.yohoufo.dal.order.model.BuyerOrder; @@ -10,8 +12,10 @@ import com.yohoufo.dal.order.model.BuyerOrder;
10 import com.yohoufo.dal.order.model.BuyerOrderGoods; 12 import com.yohoufo.dal.order.model.BuyerOrderGoods;
11 import com.yohoufo.dal.order.model.SellerOrderGoods; 13 import com.yohoufo.dal.order.model.SellerOrderGoods;
12 import com.yohoufo.order.common.OrderListType; 14 import com.yohoufo.order.common.OrderListType;
  15 +import com.yohoufo.order.common.OrderStatus;
13 import com.yohoufo.order.request.OrderListRequest; 16 import com.yohoufo.order.request.OrderListRequest;
14 import com.yohoufo.order.response.OrderInfo; 17 import com.yohoufo.order.response.OrderInfo;
  18 +import com.yohoufo.order.response.OrderInfoListRsp;
15 import com.yohoufo.order.service.IBuyerOrderService; 19 import com.yohoufo.order.service.IBuyerOrderService;
16 import com.yohoufo.order.common.OrderCodeType; 20 import com.yohoufo.order.common.OrderCodeType;
17 import com.yohoufo.order.common.SkupStatus; 21 import com.yohoufo.order.common.SkupStatus;
@@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
52 SellerOrderGoodsMapper sellerOrderGoodsMapper; 56 SellerOrderGoodsMapper sellerOrderGoodsMapper;
53 57
54 58
55 - public void getOrderList(OrderListRequest request){ 59 + /**
  60 + * 订单列表
  61 + * @param request
  62 + * @return
  63 + */
  64 + public OrderInfoListRsp getOrderList(OrderListRequest request){
56 65
57 - if (request.getUid() < 0){  
58 - logger.warn("getOrderList uid is {}", request.getUid());  
59 - throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);  
60 - } 66 + // check and init请求参数
  67 + List<Integer> statusQuery = initOrderListRequest(request);
61 68
62 - OrderListType orderListType = OrderListType.getOrderListType(request.getType());  
63 - if (orderListType == null){  
64 - logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());  
65 - throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);  
66 - }  
67 -  
68 - request.setPage(request.getPage() > 0 ? request.getPage() : 1);  
69 - request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );  
70 -  
71 -  
72 - int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), orderListType.getStatus()); 69 + int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), statusQuery);
73 70
74 int limit = request.getLimit(); 71 int limit = request.getLimit();
75 int offset = (request.getPage() - 1) * limit; 72 int offset = (request.getPage() - 1) * limit;
76 73
77 - List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), orderListType.getStatus(),offset, limit); 74 + List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), statusQuery,offset, limit);
78 75
79 List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList()); 76 List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
80 77
@@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
82 List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList); 79 List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
83 Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity())); 80 Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
84 81
85 -  
86 List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList()); 82 List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
87 // seller_order_goods ===> 商品信息 83 // seller_order_goods ===> 商品信息
88 List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups); 84 List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups);
89 Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity())); 85 Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
90 86
  87 + List<OrderInfo> data = Lists.newArrayList();
91 88
92 buyerOrderList.stream().forEach(buyerOrder -> { 89 buyerOrderList.stream().forEach(buyerOrder -> {
93 - OrderInfo orderInfo = new OrderInfo();  
94 - orderInfo.setOrderCode(buyerOrder.getOrderCode());  
95 - orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString()); 90 + OrderInfo orderInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
  91 + if (orderInfo == null) return;
96 92
97 - BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());  
98 - if (buyerOrderGoods == null){  
99 - return;  
100 - }  
101 - orderInfo.setSkup(buyerOrderGoods.getSkup()); 93 + data.add(orderInfo);
102 94
103 - SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());  
104 - orderInfo.setProductName(sellerOrderGoods.getProductName());  
105 - orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());  
106 - orderInfo.setColorName(sellerOrderGoods.getColorName());  
107 - orderInfo.setSizeName(sellerOrderGoods.getSizeName());  
108 -  
109 - // 订单状态显示 95 + });
110 96
111 - // 按钮显示 97 + OrderInfoListRsp orderInfoListRsp = OrderInfoListRsp.builder()
  98 + .data(data)
  99 + .currPage(request.getPage())
  100 + .limit(limit)
  101 + .total(total)
  102 + .currTotal(data.size())
  103 + .pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1)).build();
112 104
  105 + return orderInfoListRsp;
113 106
  107 + }
114 108
  109 + /**
  110 + * 获取返回结果
  111 + * @param buyerOrderGoodsMap
  112 + * @param sellerOrderGoodsMap
  113 + * @param buyerOrder
  114 + * @return
  115 + */
  116 + private OrderInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
  117 + Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
  118 + BuyerOrder buyerOrder) {
  119 +
  120 + /**
  121 + * 1.查询 buyer_order
  122 + * 2.查询 buyer_order_goods ==> skup
  123 + * 3.查询 seller_order_goods
  124 + */
  125 + OrderInfo orderInfo = new OrderInfo();
  126 + orderInfo.setOrderCode(buyerOrder.getOrderCode());
  127 + orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
  128 + // 订单中状态显示
  129 + orderInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
  130 + OrderStatus orderStatus = OrderStatus.getOrderStatus(orderInfo.getStatus());
  131 + orderInfo.setStatuStr(orderStatus == null ? "" : orderStatus.getListStatusStr());
  132 +
  133 + // 按钮显示
  134 + orderInfo.setButtons(orderStatus == null ? Lists.newArrayList() : orderStatus.getButtonList());
  135 +
  136 + // 当订单状态是待付款, 显示leftTime
  137 + if (orderInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
  138 + orderInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
  139 + }
115 140
116 - }); 141 + BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
  142 + if (buyerOrderGoods == null){
  143 + return null;
  144 + }
  145 + orderInfo.setSkup(buyerOrderGoods.getSkup());
117 146
  147 + SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
  148 + if (sellerOrderGoods == null){
  149 + return null;
  150 + }
  151 + orderInfo.setProductName(sellerOrderGoods.getProductName());
  152 + orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
  153 + orderInfo.setColorName(sellerOrderGoods.getColorName());
  154 + orderInfo.setSizeName(sellerOrderGoods.getSizeName());
  155 + return orderInfo;
  156 + }
118 157
  158 + /**
  159 + * 根据type获取 指定的状态
  160 + * @param request
  161 + * @return
  162 + */
  163 + private List<Integer> initOrderListRequest(OrderListRequest request) {
  164 + if (request.getUid() < 0){
  165 + logger.warn("getOrderList uid is {}", request.getUid());
  166 + throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
  167 + }
119 168
  169 + OrderListType orderListType = OrderListType.getOrderListType(request.getType());
  170 + if (orderListType == null){
  171 + logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
  172 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  173 + }
120 174
  175 + request.setPage(request.getPage() > 0 ? request.getPage() : 1);
  176 + request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
  177 + return orderListType.getStatusQuery();
121 } 178 }
122 } 179 }