Merge branch 'master' of http://git.yoho.cn/ufo/yohoufo-fore
Showing
33 changed files
with
149 additions
and
41 deletions
@@ -25,9 +25,7 @@ public class SellerOrderAutoCancelDelayMsgConsumer extends AbsOrderAutoCancelDel | @@ -25,9 +25,7 @@ public class SellerOrderAutoCancelDelayMsgConsumer extends AbsOrderAutoCancelDel | ||
25 | public void cancel(OrderCancelEvent orderCancelEvent) { | 25 | public void cancel(OrderCancelEvent orderCancelEvent) { |
26 | int uid = orderCancelEvent.getUid(); | 26 | int uid = orderCancelEvent.getUid(); |
27 | long orderCode = orderCancelEvent.getOrderCode(); | 27 | long orderCode = orderCancelEvent.getOrderCode(); |
28 | - SellerOrderStatus targetSOStatus; | ||
29 | - targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL; | ||
30 | - sellerOrderCancelService.doCancelBeforeBuyAction(uid, orderCode, targetSOStatus); | 28 | + sellerOrderCancelService.cancelByTimeout(uid, orderCode); |
31 | } | 29 | } |
32 | 30 | ||
33 | @Override | 31 | @Override |
@@ -9,6 +9,7 @@ import com.yohoufo.dal.order.SellerOrderMapper; | @@ -9,6 +9,7 @@ import com.yohoufo.dal.order.SellerOrderMapper; | ||
9 | import com.yohoufo.dal.order.SellerOrderMetaMapper; | 9 | import com.yohoufo.dal.order.SellerOrderMetaMapper; |
10 | import com.yohoufo.dal.order.model.BuyerOrderMeta; | 10 | import com.yohoufo.dal.order.model.BuyerOrderMeta; |
11 | import com.yohoufo.dal.order.model.SellerOrder; | 11 | import com.yohoufo.dal.order.model.SellerOrder; |
12 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
12 | import com.yohoufo.dal.order.model.SellerOrderMeta; | 13 | import com.yohoufo.dal.order.model.SellerOrderMeta; |
13 | import com.yohoufo.order.common.OrderCodeType; | 14 | import com.yohoufo.order.common.OrderCodeType; |
14 | import com.yohoufo.order.common.SellerOrderStatus; | 15 | import com.yohoufo.order.common.SellerOrderStatus; |
@@ -17,6 +18,7 @@ import com.yohoufo.order.constants.OrderConstant; | @@ -17,6 +18,7 @@ import com.yohoufo.order.constants.OrderConstant; | ||
17 | import com.yohoufo.order.model.OrderInfo; | 18 | import com.yohoufo.order.model.OrderInfo; |
18 | import com.yohoufo.order.model.request.PaymentRequest; | 19 | import com.yohoufo.order.model.request.PaymentRequest; |
19 | import com.yohoufo.order.model.response.PrepayResponse; | 20 | import com.yohoufo.order.model.response.PrepayResponse; |
21 | +import com.yohoufo.order.service.proxy.ProductProxyService; | ||
20 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
21 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
22 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
@@ -36,6 +38,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -36,6 +38,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
36 | @Autowired | 38 | @Autowired |
37 | SellerOrderMetaMapper sellerOrderMetaMapper; | 39 | SellerOrderMetaMapper sellerOrderMetaMapper; |
38 | 40 | ||
41 | + @Autowired | ||
42 | + private ProductProxyService productProxyService; | ||
39 | 43 | ||
40 | /** | 44 | /** |
41 | * 更新订单状态 | 45 | * 更新订单状态 |
@@ -46,13 +50,16 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -46,13 +50,16 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
46 | SellerOrder sellerOrder = new SellerOrder(); | 50 | SellerOrder sellerOrder = new SellerOrder(); |
47 | sellerOrder.setOrderCode(orderInfo.getOrderCode()); | 51 | sellerOrder.setOrderCode(orderInfo.getOrderCode()); |
48 | sellerOrder.setUid(orderInfo.getUid()); | 52 | sellerOrder.setUid(orderInfo.getUid()); |
49 | - sellerOrder.setStatus(SellerOrderStatus.HAS_PAYED.getCode()); | 53 | + SellerOrderStatus sellerOrderStatus = SellerOrderStatus.HAS_PAYED; |
54 | + sellerOrder.setStatus(sellerOrderStatus.getCode()); | ||
50 | 55 | ||
51 | - orderInfo.setStatus(SellerOrderStatus.HAS_PAYED.getCode()); | 56 | + orderInfo.setStatus(sellerOrderStatus.getCode()); |
52 | 57 | ||
53 | sellerOrderMapper.updateByOrderCode(sellerOrder); | 58 | sellerOrderMapper.updateByOrderCode(sellerOrder); |
54 | // | 59 | // |
55 | - | 60 | + SellerOrderGoods tsog = new SellerOrderGoods(); |
61 | + tsog.setId(orderInfo.getSkup()); | ||
62 | + productProxyService.syncSkup(tsog,sellerOrderStatus.getSkupStatus()); | ||
56 | } | 63 | } |
57 | 64 | ||
58 | 65 | ||
@@ -156,7 +163,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -156,7 +163,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
156 | 163 | ||
157 | /** | 164 | /** |
158 | * 获取订单情报 | 165 | * 获取订单情报 |
159 | - * @param request | 166 | + * @param orderCode |
160 | * @return | 167 | * @return |
161 | */ | 168 | */ |
162 | public OrderInfo getOrderInfo(long orderCode, int uid) { | 169 | public OrderInfo getOrderInfo(long orderCode, int uid) { |
@@ -187,7 +194,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -187,7 +194,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
187 | 194 | ||
188 | /** | 195 | /** |
189 | * 获取订单情报 | 196 | * 获取订单情报 |
190 | - * @param request | 197 | + * @param orderCode |
191 | * @return | 198 | * @return |
192 | */ | 199 | */ |
193 | public OrderInfo getOrderInfo(long orderCode) { | 200 | public OrderInfo getOrderInfo(long orderCode) { |
@@ -72,50 +72,88 @@ public class SellerOrderCancelService { | @@ -72,50 +72,88 @@ public class SellerOrderCancelService { | ||
72 | //case 1: 未支付时 | 72 | //case 1: 未支付时 |
73 | //case 2: 支付完成,没有买家下单 | 73 | //case 2: 支付完成,没有买家下单 |
74 | //case 3: 支付完成,有买家下单 | 74 | //case 3: 支付完成,有买家下单 |
75 | - doCancel(uid, orderCode); | 75 | + cancel(uid, orderCode); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | - private int doCancel(int uid, long orderCode){ | 79 | + public int cancel(int uid, long orderCode){ |
80 | int result = 0; | 80 | int result = 0; |
81 | SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); | 81 | SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); |
82 | 82 | ||
83 | - | 83 | + if (Objects.isNull(sellerOrder)){ |
84 | + return result; | ||
85 | + } | ||
84 | Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); | 86 | Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); |
85 | if (Objects.isNull(status)){ | 87 | if (Objects.isNull(status)){ |
86 | return result; | 88 | return result; |
87 | } | 89 | } |
90 | + logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status); | ||
88 | //target seller Order Status | 91 | //target seller Order Status |
89 | SellerOrderStatus targetSOStatus; | 92 | SellerOrderStatus targetSOStatus; |
90 | //case 1: 未支付时 | 93 | //case 1: 未支付时 |
91 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ | 94 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ |
92 | targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY; | 95 | targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY; |
93 | - doCancelBeforeBuyAction(uid, orderCode, targetSOStatus); | ||
94 | - | 96 | + result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus); |
95 | } | 97 | } |
96 | 98 | ||
97 | //case 2: 支付完成,没有买家下单 | 99 | //case 2: 支付完成,没有买家下单 |
98 | //case 3: 支付完成,有买家下单 | 100 | //case 3: 支付完成,有买家下单 |
99 | if (SellerOrderStatus.HAS_PAYED.getCode() == status){ | 101 | if (SellerOrderStatus.HAS_PAYED.getCode() == status){ |
100 | - doCancelAfterBuyAction(sellerOrder); | 102 | + result = cancelAfterPayAction(sellerOrder); |
101 | } | 103 | } |
102 | 104 | ||
103 | return result; | 105 | return result; |
104 | } | 106 | } |
105 | 107 | ||
106 | - public int doCancelBeforeBuyAction(int uid, long orderCode, SellerOrderStatus targetSOStatus){ | 108 | + |
109 | + public int cancelByTimeout(int uid, long orderCode){ | ||
110 | + int result = 0; | ||
111 | + SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); | ||
112 | + | ||
113 | + if (Objects.isNull(sellerOrder)){ | ||
114 | + return result; | ||
115 | + } | ||
116 | + Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); | ||
117 | + if (Objects.isNull(status)){ | ||
118 | + return result; | ||
119 | + } | ||
120 | + logger.info("in seller timeout cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status); | ||
121 | + //target seller Order Status | ||
122 | + SellerOrderStatus targetSOStatus; | ||
123 | + //case 1: 未支付时 | ||
124 | + if (SellerOrderStatus.WAITING_PAY.getCode() == status){ | ||
125 | + targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL; | ||
126 | + result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus); | ||
127 | + } | ||
128 | + | ||
129 | + return result; | ||
130 | + } | ||
131 | + | ||
132 | + private int cancelBeforePayAction(int uid, long orderCode,Integer skup, SellerOrderStatus targetSOStatus){ | ||
133 | + logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}", | ||
134 | + uid, orderCode, targetSOStatus); | ||
107 | SellerOrder target = new SellerOrder(); | 135 | SellerOrder target = new SellerOrder(); |
108 | target.setOrderCode(orderCode); | 136 | target.setOrderCode(orderCode); |
109 | target.setUid(uid); | 137 | target.setUid(uid); |
110 | target.setStatus(targetSOStatus.getCode()); | 138 | target.setStatus(targetSOStatus.getCode()); |
111 | - return doCancelBeforeBuyAction(target, targetSOStatus); | 139 | + target.setSkup(skup); |
140 | + return cancelBeforePayAction(target, targetSOStatus); | ||
112 | } | 141 | } |
113 | 142 | ||
114 | - | ||
115 | - private int doCancelBeforeBuyAction(SellerOrder target, SellerOrderStatus targetSOStatus){ | 143 | + /** |
144 | + * | ||
145 | + * @param target | ||
146 | + * @param targetSOStatus | ||
147 | + * @return | ||
148 | + */ | ||
149 | + private int cancelBeforePayAction(SellerOrder target, SellerOrderStatus targetSOStatus){ | ||
150 | + /**case 1: 未支付时 | ||
151 | + * actions as blow: | ||
152 | + * 1. sellerOrder | ||
153 | + * 2. sellerOrderGoods | ||
154 | + * 3. 同步product skup状态 | ||
155 | + */ | ||
116 | int result = 0; | 156 | int result = 0; |
117 | - int uid = target.getUid(); | ||
118 | - long orderCode = target.getOrderCode(); | ||
119 | 157 | ||
120 | //update seller order | 158 | //update seller order |
121 | if (Objects.nonNull(targetSOStatus)){ | 159 | if (Objects.nonNull(targetSOStatus)){ |
@@ -126,10 +164,10 @@ public class SellerOrderCancelService { | @@ -126,10 +164,10 @@ public class SellerOrderCancelService { | ||
126 | //refund earnestMoney | 164 | //refund earnestMoney |
127 | //sync skup | 165 | //sync skup |
128 | if (result>0) { | 166 | if (result>0) { |
129 | - double earnestMoney = target.getEarnestMoney().doubleValue(); | ||
130 | - PaymentRequest refundReq = PaymentRequest.builder().uid(uid).orderCode(orderCode) | ||
131 | - .refundAmount(earnestMoney).build(); | ||
132 | - paymentService.refund(refundReq); | 167 | + SellerOrderGoods sogCondition = new SellerOrderGoods(); |
168 | + sogCondition.setId(target.getSkup()); | ||
169 | + sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode()); | ||
170 | + sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition); | ||
133 | //sync skup | 171 | //sync skup |
134 | SellerOrderGoods tsog = new SellerOrderGoods(); | 172 | SellerOrderGoods tsog = new SellerOrderGoods(); |
135 | tsog.setId(target.getSkup()); | 173 | tsog.setId(target.getSkup()); |
@@ -138,27 +176,49 @@ public class SellerOrderCancelService { | @@ -138,27 +176,49 @@ public class SellerOrderCancelService { | ||
138 | return result; | 176 | return result; |
139 | } | 177 | } |
140 | 178 | ||
141 | - private int doCancelAfterBuyAction(SellerOrder sellerOrder){ | 179 | + private int cancelAfterPayButNotBuyAction(SellerOrder sellerOrder){ |
180 | + /**case 2: 支付完成,没有买家下单 | ||
181 | + * actions as blow: | ||
182 | + * 1. sellerOrder | ||
183 | + * 2. sellerOrderGoods | ||
184 | + * 3. 同步product skup状态 | ||
185 | + */ | ||
142 | final int sellerUid = sellerOrder.getUid(); | 186 | final int sellerUid = sellerOrder.getUid(); |
143 | final long orderCode = sellerOrder.getOrderCode(); | 187 | final long orderCode = sellerOrder.getOrderCode(); |
188 | + logger.info("in seller cancel when Seller Pay But Not Buy Action, uid {}, orderCode {}", | ||
189 | + sellerUid, orderCode); | ||
144 | int result = 0; | 190 | int result = 0; |
145 | - List<Integer> sellerCanCancelStatus; | ||
146 | - int canCancelCnt = 0; | ||
147 | - //target Buyer Order Status | ||
148 | - Integer targetBOStatus; | ||
149 | - | ||
150 | - //查询买家订单,状态是支付成功的 | ||
151 | - sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode()); | ||
152 | - canCancelCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus); | ||
153 | SellerOrderStatus targetSOStatus; | 191 | SellerOrderStatus targetSOStatus; |
154 | - //case 2: 支付完成,没有买家下单 | ||
155 | - if (canCancelCnt == 0){ | ||
156 | - targetSOStatus = SellerOrderStatus.PLAY_SELF; | ||
157 | - result = doCancelBeforeBuyAction(sellerUid, orderCode, targetSOStatus); | ||
158 | - return result; | 192 | + |
193 | + targetSOStatus = SellerOrderStatus.PLAY_SELF; | ||
194 | + result = cancelBeforePayAction(sellerUid, orderCode, sellerOrder.getSkup(), targetSOStatus); | ||
195 | + //refund earnestMoney | ||
196 | + if (result>0){ | ||
197 | + double earnestMoney = sellerOrder.getEarnestMoney().doubleValue(); | ||
198 | + PaymentRequest refundReq = PaymentRequest.builder().uid(sellerUid) | ||
199 | + .orderCode(orderCode) | ||
200 | + .refundAmount(earnestMoney).build(); | ||
201 | + paymentService.refund(refundReq); | ||
159 | } | 202 | } |
160 | - //case 3: 支付完成,有买家下单 | ||
161 | - List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, canCancelCnt); | 203 | + return result; |
204 | + } | ||
205 | + | ||
206 | + private int cancelAfterPayExistBuyAction(SellerOrder sellerOrder,List<Integer> sellerCanCancelStatus, | ||
207 | + int buyOrderCnt){ | ||
208 | + /** | ||
209 | + * case 3: 支付完成,有买家下单 | ||
210 | + * actions as blow: | ||
211 | + * 1. buyerOrder | ||
212 | + * 2. sellerOrder | ||
213 | + * 3. sellerOrderGoods | ||
214 | + * 4. 瓜分保证金 | ||
215 | + */ | ||
216 | + final int sellerUid = sellerOrder.getUid(); | ||
217 | + final long orderCode = sellerOrder.getOrderCode(); | ||
218 | + logger.info("in seller cancel After Pay while Exist Buy Action, uid {}, orderCode {}", | ||
219 | + sellerUid, orderCode); | ||
220 | + int result = 0; | ||
221 | + List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, buyOrderCnt); | ||
162 | List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList()); | 222 | List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList()); |
163 | 223 | ||
164 | if (orderCodes.size() > 1){ | 224 | if (orderCodes.size() > 1){ |
@@ -166,11 +226,14 @@ public class SellerOrderCancelService { | @@ -166,11 +226,14 @@ public class SellerOrderCancelService { | ||
166 | } | 226 | } |
167 | //actions of buyer order and related | 227 | //actions of buyer order and related |
168 | //update buyer Order | 228 | //update buyer Order |
229 | + //target Buyer Order Status | ||
230 | + Integer targetBOStatus; | ||
169 | targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(); | 231 | targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(); |
170 | result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond()); | 232 | result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond()); |
171 | - //TODO 分赃(分账) | 233 | + |
172 | 234 | ||
173 | //update seller order | 235 | //update seller order |
236 | + SellerOrderStatus targetSOStatus; | ||
174 | targetSOStatus = SellerOrderStatus.PLAY_BUYER; | 237 | targetSOStatus = SellerOrderStatus.PLAY_BUYER; |
175 | SellerOrder target = new SellerOrder(); | 238 | SellerOrder target = new SellerOrder(); |
176 | target.setOrderCode(orderCode); | 239 | target.setOrderCode(orderCode); |
@@ -179,6 +242,46 @@ public class SellerOrderCancelService { | @@ -179,6 +242,46 @@ public class SellerOrderCancelService { | ||
179 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 242 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
180 | result += sellerOrderMapper.updateByOrderCode(target); | 243 | result += sellerOrderMapper.updateByOrderCode(target); |
181 | 244 | ||
245 | + //TODO 分赃(分账) 有待考虑使用2比对 | ||
246 | + if(result == 2){ | ||
247 | + | ||
248 | + } | ||
249 | + return result; | ||
250 | + } | ||
251 | + | ||
252 | + private int cancelAfterPayAction(SellerOrder sellerOrder){ | ||
253 | + | ||
254 | + final int sellerUid = sellerOrder.getUid(); | ||
255 | + final long orderCode = sellerOrder.getOrderCode(); | ||
256 | + logger.info("in seller cancel After Buy Action, uid {}, orderCode {}", | ||
257 | + sellerUid, orderCode); | ||
258 | + int result = 0; | ||
259 | + List<Integer> sellerCanCancelStatus; | ||
260 | + int buyOrderCnt; | ||
261 | + | ||
262 | + | ||
263 | + //查询买家订单,状态是支付成功的 | ||
264 | + sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode()); | ||
265 | + buyOrderCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus); | ||
266 | + if (buyOrderCnt == 0){ | ||
267 | + /**case 2: 支付完成,没有买家下单 | ||
268 | + * actions as blow: | ||
269 | + * 1. sellerOrder | ||
270 | + * 2. sellerOrderGoods | ||
271 | + * 3. 同步product skup状态 | ||
272 | + */ | ||
273 | + result = cancelAfterPayButNotBuyAction(sellerOrder); | ||
274 | + return result; | ||
275 | + } | ||
276 | + /** | ||
277 | + * case 3: 支付完成,有买家下单 | ||
278 | + * actions as blow: | ||
279 | + * 1. buyerOrder | ||
280 | + * 2. sellerOrder | ||
281 | + * 3. sellerOrderGoods | ||
282 | + * 4. 瓜分保证金 | ||
283 | + */ | ||
284 | + result = cancelAfterPayExistBuyAction(sellerOrder, sellerCanCancelStatus, buyOrderCnt); | ||
182 | return result; | 285 | return result; |
183 | } | 286 | } |
184 | 287 |
-
Please register or login to post a comment