wangyingyang

fix refund

...@@ -36,10 +36,10 @@ public class ClientOrderController { ...@@ -36,10 +36,10 @@ public class ClientOrderController {
36 } 36 }
37 37
38 @ApiOperation(value = "院区端已撤销订单") 38 @ApiOperation(value = "院区端已撤销订单")
39 - @PostMapping("/client/orders/canceled/pagination") 39 + @PostMapping("/client/orders/refund/pagination")
40 @ResponseStatus(HttpStatus.OK) 40 @ResponseStatus(HttpStatus.OK)
41 - public OrderPageResult<OrderDto> getCanceledOrderByByPagination(@Valid @RequestBody OrderDbDTO.QueryCanceledOrderByPaginationDto queryOrderDto) { 41 + public OrderPageResult<OrderDto> getRefundOrderByByPagination(@Valid @RequestBody OrderDbDTO.QueryRefundOrderByPaginationDto queryOrderDto) {
42 - return orderService.getCanceledOrdersByPagination(queryOrderDto); 42 + return orderService.getRefundOrdersByPagination(queryOrderDto);
43 } 43 }
44 44
45 } 45 }
......
...@@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor; ...@@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor;
12 import lombok.extern.slf4j.Slf4j; 12 import lombok.extern.slf4j.Slf4j;
13 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.http.HttpStatus; 14 import org.springframework.http.HttpStatus;
15 +import org.springframework.http.MediaType;
15 import org.springframework.validation.annotation.Validated; 16 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.PathVariable; 17 import org.springframework.web.bind.annotation.PathVariable;
17 import org.springframework.web.bind.annotation.PostMapping; 18 import org.springframework.web.bind.annotation.PostMapping;
...@@ -54,9 +55,9 @@ public class PayController { ...@@ -54,9 +55,9 @@ public class PayController {
54 } 55 }
55 56
56 @ApiOperation(value = "支付撤销") 57 @ApiOperation(value = "支付撤销")
57 - @PostMapping(value = "/pay/cancel") 58 + @PostMapping(value = "/pay/refund", produces = MediaType.TEXT_HTML_VALUE)
58 @ResponseStatus(HttpStatus.OK) 59 @ResponseStatus(HttpStatus.OK)
59 - public boolean cancel(@Valid @RequestBody PayDTO.PayCancelRequestDto payCancelRequestDto) { 60 + public String cancel(@Valid @RequestBody PayDTO.PayRefundRequestDto payRefundRequestDto) {
60 - return payServiceClient.cancelOrder(payCancelRequestDto); 61 + return payServiceClient.orderPayRefund(payRefundRequestDto);
61 } 62 }
62 } 63 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -36,7 +36,13 @@ public enum ErrorCodeEnum implements BaseEnum { ...@@ -36,7 +36,13 @@ public enum ErrorCodeEnum implements BaseEnum {
36 36
37 ORDER_CANCEL(406000009, "订单已自动取消"), 37 ORDER_CANCEL(406000009, "订单已自动取消"),
38 38
39 - ORDER_PAY_CANCEL_FAILED(406000010, "支付撤销失败") 39 + ORDER_PAY_REFUND_FAILED(406000010, "支付撤销失败"),
40 +
41 + ORDER_NOT_FOUND(406000011, "订单未找到"),
42 +
43 + ORDER_NOT_ONLINE_PAY(406000012, "该订单不是在线支付"),
44 +
45 + ORDER_NOT_SUCCESS(406000013, "该订单未支付成功")
40 ; 46 ;
41 private final int code; 47 private final int code;
42 48
......
...@@ -65,7 +65,7 @@ public class OrderDbDTO { ...@@ -65,7 +65,7 @@ public class OrderDbDTO {
65 65
66 @Data 66 @Data
67 @ApiModel(description = "查询已撤销订单Dto") 67 @ApiModel(description = "查询已撤销订单Dto")
68 - public static class QueryCanceledOrderByPaginationDto { 68 + public static class QueryRefundOrderByPaginationDto {
69 private Integer enterpriseId; 69 private Integer enterpriseId;
70 private Integer clientId; 70 private Integer clientId;
71 private Integer pn; 71 private Integer pn;
...@@ -406,7 +406,7 @@ public class OrderDbDTO { ...@@ -406,7 +406,7 @@ public class OrderDbDTO {
406 @ApiModelProperty(value = "支付时间") 406 @ApiModelProperty(value = "支付时间")
407 private String payTime; 407 private String payTime;
408 408
409 - @ApiModelProperty(value = "支付状态,1=待支付,2=支付中,3=支付成功,4=支付失败,5=支付取消") 409 + @ApiModelProperty(value = "支付状态,1=待支付,2=支付中,3=支付成功,4=支付失败,5=支付取消, 6=支付已撤销")
410 private Integer payStatus; 410 private Integer payStatus;
411 411
412 @ApiModelProperty(value = "支付失败原因") 412 @ApiModelProperty(value = "支付失败原因")
......
...@@ -26,14 +26,12 @@ public class PayDTO { ...@@ -26,14 +26,12 @@ public class PayDTO {
26 } 26 }
27 27
28 @Data 28 @Data
29 - @ApiModel(description = "支付请求dto") 29 + @ApiModel(description = "支付撤销请求dto")
30 @NoArgsConstructor 30 @NoArgsConstructor
31 @AllArgsConstructor 31 @AllArgsConstructor
32 - public static class PayCancelRequestDto { 32 + public static class PayRefundRequestDto {
33 -// private String clientId;
34 private Integer orderId; 33 private Integer orderId;
35 private String hospitalCode; 34 private String hospitalCode;
36 -// private String price;
37 } 35 }
38 36
39 @Data 37 @Data
......
...@@ -9,9 +9,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.OrderAndDetailsDto; ...@@ -9,9 +9,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.OrderAndDetailsDto;
9 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto; 9 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto;
10 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto; 10 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto;
11 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDto; 11 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDto;
12 -import com.infoloop.tianting.model.dto.OrderDbDTO.QueryCanceledOrderByPaginationDto;
13 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto; 12 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto;
14 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto; 13 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto;
14 +import com.infoloop.tianting.model.dto.OrderDbDTO.QueryRefundOrderByPaginationDto;
15 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto; 15 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto;
16 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderResponse; 16 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderResponse;
17 import com.infoloop.tianting.model.dto.OrderDbDTO.getMenuOrderCountDto; 17 import com.infoloop.tianting.model.dto.OrderDbDTO.getMenuOrderCountDto;
...@@ -22,8 +22,8 @@ public interface OrderService { ...@@ -22,8 +22,8 @@ public interface OrderService {
22 OrderAndDetailsDto getOrdersByCustomerId(Integer customerId); 22 OrderAndDetailsDto getOrdersByCustomerId(Integer customerId);
23 OrderAndDetailsDto getOrdersByCondition(QueryOrderByConditionDto queryOrderDto); 23 OrderAndDetailsDto getOrdersByCondition(QueryOrderByConditionDto queryOrderDto);
24 OrderPageResult<OrderDto> getOrdersByPagination(QueryOrderByPaginationDto queryOrderDto); 24 OrderPageResult<OrderDto> getOrdersByPagination(QueryOrderByPaginationDto queryOrderDto);
25 - OrderPageResult<OrderDto> getCanceledOrdersByPagination( 25 + OrderPageResult<OrderDto> getRefundOrdersByPagination(
26 - QueryCanceledOrderByPaginationDto queryOrderDto); 26 + QueryRefundOrderByPaginationDto queryOrderDto);
27 List<OrderDetailDto> getOrderDetailsByOrderId(Integer orderId); 27 List<OrderDetailDto> getOrderDetailsByOrderId(Integer orderId);
28 CreateOrderResponse createOrder(CreateOrderDto createOrderDto); 28 CreateOrderResponse createOrder(CreateOrderDto createOrderDto);
29 CreateOrderResponse orderCreation(OperatorCreateOrderDto createOrderDto); 29 CreateOrderResponse orderCreation(OperatorCreateOrderDto createOrderDto);
......
...@@ -64,9 +64,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.MealDetailDto; ...@@ -64,9 +64,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.MealDetailDto;
64 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto; 64 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto;
65 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto; 65 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto;
66 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailOperationDto; 66 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailOperationDto;
67 -import com.infoloop.tianting.model.dto.OrderDbDTO.QueryCanceledOrderByPaginationDto;
68 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto; 67 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto;
69 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto; 68 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto;
69 +import com.infoloop.tianting.model.dto.OrderDbDTO.QueryRefundOrderByPaginationDto;
70 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto; 70 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto;
71 import com.infoloop.tianting.server.UserAuthData; 71 import com.infoloop.tianting.server.UserAuthData;
72 import com.infoloop.tianting.server.WebSocketServer; 72 import com.infoloop.tianting.server.WebSocketServer;
...@@ -463,7 +463,7 @@ public class OrderServiceRpcClient { ...@@ -463,7 +463,7 @@ public class OrderServiceRpcClient {
463 .setPageNo(queryOrderDto.getPn()) 463 .setPageNo(queryOrderDto.getPn())
464 .setPageSize(queryOrderDto.getPz()) 464 .setPageSize(queryOrderDto.getPz())
465 .setShouldFilterStatus(true) 465 .setShouldFilterStatus(true)
466 - .setShouldFilterIsCanceled(false) 466 + .setShouldFilterPayStatus(false)
467 .setStatus(queryOrderDto.getStatus()) 467 .setStatus(queryOrderDto.getStatus())
468 .setEnterpriseId(queryOrderDto.getEnterpriseId()) 468 .setEnterpriseId(queryOrderDto.getEnterpriseId())
469 .setClientId(queryOrderDto.getClientId()) 469 .setClientId(queryOrderDto.getClientId())
...@@ -472,15 +472,15 @@ public class OrderServiceRpcClient { ...@@ -472,15 +472,15 @@ public class OrderServiceRpcClient {
472 return orderServiceRpcBlockingStub.queryClientCustomerOrdersByPagination(request); 472 return orderServiceRpcBlockingStub.queryClientCustomerOrdersByPagination(request);
473 } 473 }
474 474
475 - public QueryClientCustomerOrdersByPaginationRpcResponse queryCanceledClientCustomerOrdersByPagination( 475 + public QueryClientCustomerOrdersByPaginationRpcResponse queryRefundClientCustomerOrdersByPagination(
476 - QueryCanceledOrderByPaginationDto queryOrderDto) { 476 + QueryRefundOrderByPaginationDto queryOrderDto) {
477 final var request = QueryClientCustomerOrdersByPaginationRpcRequest.newBuilder() 477 final var request = QueryClientCustomerOrdersByPaginationRpcRequest.newBuilder()
478 .setKeyword(queryOrderDto.getKeyword() == null ? "" : queryOrderDto.getKeyword()) 478 .setKeyword(queryOrderDto.getKeyword() == null ? "" : queryOrderDto.getKeyword())
479 .setPageNo(queryOrderDto.getPn()) 479 .setPageNo(queryOrderDto.getPn())
480 .setPageSize(queryOrderDto.getPz()) 480 .setPageSize(queryOrderDto.getPz())
481 .setShouldFilterStatus(false) 481 .setShouldFilterStatus(false)
482 - .setShouldFilterIsCanceled(true) 482 + .setShouldFilterPayStatus(true)
483 - .setIsCanceled(true) 483 + .setPayStatus(PayStatusEnum.REFUND)
484 .setEnterpriseId(queryOrderDto.getEnterpriseId()) 484 .setEnterpriseId(queryOrderDto.getEnterpriseId())
485 .setClientId(queryOrderDto.getClientId()) 485 .setClientId(queryOrderDto.getClientId())
486 .addAllStallIds(queryOrderDto.getStallIds()) 486 .addAllStallIds(queryOrderDto.getStallIds())
......
...@@ -18,9 +18,8 @@ import com.infoloop.tianting.config.BusinessConfig; ...@@ -18,9 +18,8 @@ import com.infoloop.tianting.config.BusinessConfig;
18 import com.infoloop.tianting.context.LoginContextHolder; 18 import com.infoloop.tianting.context.LoginContextHolder;
19 import com.infoloop.tianting.exception.ClientEndExceptions; 19 import com.infoloop.tianting.exception.ClientEndExceptions;
20 import com.infoloop.tianting.exception.ErrorCodeEnum; 20 import com.infoloop.tianting.exception.ErrorCodeEnum;
21 -import com.infoloop.tianting.model.dto.PayDTO.CancelPayResponseDto;
22 -import com.infoloop.tianting.model.dto.PayDTO.PayCancelRequestDto;
23 import com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto; 21 import com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto;
22 +import com.infoloop.tianting.model.dto.PayDTO.PayRefundRequestDto;
24 import com.infoloop.tianting.model.dto.PayDTO.PayResponseDto; 23 import com.infoloop.tianting.model.dto.PayDTO.PayResponseDto;
25 import com.infoloop.tianting.model.dto.PayDTO.ThirdPartyPayInformRequestDto; 24 import com.infoloop.tianting.model.dto.PayDTO.ThirdPartyPayInformRequestDto;
26 import com.infoloop.tianting.model.dto.PaymentCallbackDTO; 25 import com.infoloop.tianting.model.dto.PaymentCallbackDTO;
...@@ -168,118 +167,133 @@ public class PayServiceClient { ...@@ -168,118 +167,133 @@ public class PayServiceClient {
168 log.error("Order not found, orderId: {}", orderId); 167 log.error("Order not found, orderId: {}", orderId);
169 return false; 168 return false;
170 } 169 }
171 - if (orderById.getPayStatus() != PayStatusEnum.TO_PAY 170 +
172 - && orderById.getPayStatus() != PayStatusEnum.IN_PROGRESS) { 171 + final var transType = paymentCallbackResult.getTransType();
173 - log.error("Order status is not TO_PAY or IN_PROGRESS, orderId: {}", orderId); 172 + if (transType.equals("00")) {
174 - return true; 173 + if (orderById.getPayStatus() != PayStatusEnum.TO_PAY
175 - } 174 + && orderById.getPayStatus() != PayStatusEnum.IN_PROGRESS) {
176 - long payTime; 175 + log.error("Order status is not TO_PAY or IN_PROGRESS, orderId: {}", orderId);
177 - try { 176 + return true;
178 - payTime =
179 - DateUtil.parseDate(paymentCallbackResult.getTransDate(), "yyyyMMddHHmmss").getTime();
180 - } catch (ParseException e) {
181 - log.error("Failed to parse TransDate: {}", paymentCallbackResult.getTransDate(), e);
182 - throw new IllegalArgumentException("支付时间格式错误: " + paymentCallbackResult.getTransDate(), e);
183 - }
184 - BigDecimal realAmount;
185 - try {
186 - realAmount = Convert.toBigDecimal(paymentCallbackResult.getRealAmount());
187 - if (realAmount == null) {
188 - throw new NumberFormatException("RealAmount is null or empty");
189 } 177 }
190 - } catch (NumberFormatException e) { 178 + long payTime;
191 - log.error("Invalid RealAmount value: {}", paymentCallbackResult.getRealAmount(), e); 179 + try {
192 - throw new IllegalArgumentException("支付金额错误: " + paymentCallbackResult.getRealAmount(), e); 180 + payTime =
193 - } 181 + DateUtil.parseDate(paymentCallbackResult.getTransDate(), "yyyyMMddHHmmss").getTime();
194 - final var build = 182 + } catch (ParseException e) {
195 - ClientCustomerOrderModification.newBuilder() 183 + log.error("Failed to parse TransDate: {}", paymentCallbackResult.getTransDate(), e);
196 - .setId(orderId) 184 + throw new IllegalArgumentException("支付时间格式错误: " + paymentCallbackResult.getTransDate(), e);
197 - .setShouldUpdatePayTime(true) 185 + }
198 - .setPayTime(payTime) 186 + BigDecimal realAmount;
199 - .setShouldUpdatePayPrice(true) 187 + try {
200 - .setPayPrice(realAmount.multiply(new BigDecimal("100")).intValue()) 188 + realAmount = Convert.toBigDecimal(paymentCallbackResult.getRealAmount());
201 - .setShouldUpdatePayStatus(true) 189 + if (realAmount == null) {
202 - .setPayStatus(PayStatusEnum.SUCCEED) 190 + throw new NumberFormatException("RealAmount is null or empty");
203 - .setShouldUpdateStatus(true) 191 + }
204 - .setStatus(OrderStatusEnum.PREPARING) 192 + } catch (NumberFormatException e) {
205 - .setShouldUpdateTransactionId(true) 193 + log.error("Invalid RealAmount value: {}", paymentCallbackResult.getRealAmount(), e);
206 - .setTransactionId(paymentCallbackResult.getTransSN()) 194 + throw new IllegalArgumentException("支付金额错误: " + paymentCallbackResult.getRealAmount(), e);
207 - .build(); 195 + }
208 - final var updateResponse = 196 + final var build =
209 - orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build); 197 + ClientCustomerOrderModification.newBuilder()
210 - log.info("callback updateClientCustomerOrder result: {}", updateResponse.getIsUpdated()); 198 + .setId(orderId)
211 - if (updateResponse.getIsUpdated()) { 199 + .setShouldUpdatePayTime(true)
212 - final var orderPaymentSuccessData = 200 + .setPayTime(payTime)
213 - OrderPaymentSuccessData.builder() 201 + .setShouldUpdatePayPrice(true)
214 - .orderId(orderById.getId()) 202 + .setPayPrice(realAmount.multiply(new BigDecimal("100")).intValue())
215 - .orderCode(orderById.getOrderCode()) 203 + .setShouldUpdatePayStatus(true)
216 - .createTime(DateUtil.formatDate(orderById.getCreatedAt(), DateUtil.Y_M_D_H_M_S)) 204 + .setPayStatus(PayStatusEnum.SUCCEED)
217 - .payTime(DateUtil.formatDate(orderById.getPayTime(), DateUtil.Y_M_D_H_M_S)) 205 + .setShouldUpdateStatus(true)
218 - .build(); 206 + .setStatus(OrderStatusEnum.PREPARING)
219 - final var data = 207 + .setShouldUpdateTransactionId(true)
220 - SocketMessage.<OrderPaymentSuccessData>builder() 208 + .setTransactionId(paymentCallbackResult.getTransSN())
221 - .type(MessageTypeEnum.ORDER)
222 - .noticeType(NoticeTypeEnum.ORDER_PAYMENT_SUCCESS)
223 - .subject(NoticeTypeEnum.ORDER_PAYMENT_SUCCESS.getDescription())
224 - .message("您的订单:" + orderById.getOrderCode() + " 支付成功啦,快去查看吧~")
225 - .data(orderPaymentSuccessData)
226 .build(); 209 .build();
227 - WebSocketServer.sendMessageToUser( 210 + final var updateResponse =
228 - UserSessionKey.builder() 211 + orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build);
229 - .userId(orderById.getOpenId()) 212 + log.info("callback updateClientCustomerOrder result: {}", updateResponse.getIsUpdated());
230 - .userType(UserTypeEnum.MICRO) 213 + if (updateResponse.getIsUpdated()) {
231 - .build(), 214 + final var orderPaymentSuccessData =
232 - data); 215 + OrderPaymentSuccessData.builder()
233 - if (LocalDate.now().equals(DateUtil.toLocalDate(orderById.getMealTime()))) { 216 + .orderId(orderById.getId())
234 - final var orderCreateSuccessData = 217 + .orderCode(orderById.getOrderCode())
235 - OrderCreateSuccessData.builder().orderId(orderById.getId()).build(); 218 + .createTime(DateUtil.formatDate(orderById.getCreatedAt(), DateUtil.Y_M_D_H_M_S))
236 - final var createOrderData = 219 + .payTime(DateUtil.formatDate(orderById.getPayTime(), DateUtil.Y_M_D_H_M_S))
237 - SocketMessage.<OrderCreateSuccessData>builder() 220 + .build();
221 + final var data =
222 + SocketMessage.<OrderPaymentSuccessData>builder()
238 .type(MessageTypeEnum.ORDER) 223 .type(MessageTypeEnum.ORDER)
239 - .noticeType(NoticeTypeEnum.ORDER_CREATED) 224 + .noticeType(NoticeTypeEnum.ORDER_PAYMENT_SUCCESS)
240 - .subject(NoticeTypeEnum.ORDER_CREATED.getDescription()) 225 + .subject(NoticeTypeEnum.ORDER_PAYMENT_SUCCESS.getDescription())
241 - .message("有新的订单下单成功啦,快去查看吧~") 226 + .message("您的订单:" + orderById.getOrderCode() + " 支付成功啦,快去查看吧~")
242 - .data(orderCreateSuccessData) 227 + .data(orderPaymentSuccessData)
243 .build(); 228 .build();
244 - final var clientOperatorIds = 229 + WebSocketServer.sendMessageToUser(
245 - clientResourceTagServiceRpcClient 230 + UserSessionKey.builder()
246 - .getOperatorIdsByStallIds(List.of(orderById.getStallId())).stream() 231 + .userId(orderById.getOpenId())
247 - .map(SingleResourceLabelEntityRefsResponse::getEntityId) 232 + .userType(UserTypeEnum.MICRO)
248 - .distinct() 233 + .build(),
249 - .collect(Collectors.toList()); 234 + data);
250 - final var enterpriseOperatorIds = 235 + if (LocalDate.now().equals(DateUtil.toLocalDate(orderById.getMealTime()))) {
251 - enterpriseResourceServiceRpcClient.getOperatorIdsByStallId( 236 + final var orderCreateSuccessData =
252 - orderById.getEnterpriseId(), orderById.getStallId()); 237 + OrderCreateSuccessData.builder().orderId(orderById.getId()).build();
253 - final var userAuthData = new ArrayList<UserAuthData>(); 238 + final var createOrderData =
254 - userAuthData.addAll( 239 + SocketMessage.<OrderCreateSuccessData>builder()
255 - clientOperatorIds.stream() 240 + .type(MessageTypeEnum.ORDER)
256 - .map( 241 + .noticeType(NoticeTypeEnum.ORDER_CREATED)
257 - e -> 242 + .subject(NoticeTypeEnum.ORDER_CREATED.getDescription())
258 - UserAuthData.builder() 243 + .message("有新的订单下单成功啦,快去查看吧~")
259 - .operatorId(e) 244 + .data(orderCreateSuccessData)
260 - .userType(UserTypeEnum.CLIENT) 245 + .build();
261 - .build()) 246 + final var clientOperatorIds =
262 - .collect(Collectors.toList())); 247 + clientResourceTagServiceRpcClient
263 - userAuthData.addAll( 248 + .getOperatorIdsByStallIds(List.of(orderById.getStallId())).stream()
264 - enterpriseOperatorIds.stream() 249 + .map(SingleResourceLabelEntityRefsResponse::getEntityId)
265 - .map(e -> UserAuthData.builder().operatorId(e).userType(UserTypeEnum.KDS).build()) 250 + .distinct()
266 - .collect(Collectors.toList())); 251 + .collect(Collectors.toList());
267 - log.info("received userAuthData:{}", JsonUtil.writeAsJson(userAuthData)); 252 + final var enterpriseOperatorIds =
268 - try { 253 + enterpriseResourceServiceRpcClient.getOperatorIdsByStallId(
269 - WebSocketServer.sendMessageByUserTypes( 254 + orderById.getEnterpriseId(), orderById.getStallId());
270 - List.of(UserTypeEnum.CLIENT, UserTypeEnum.KDS), userAuthData, createOrderData); 255 + final var userAuthData = new ArrayList<UserAuthData>();
271 - } catch (IOException e) { 256 + userAuthData.addAll(
272 - log.error("Failed to send message to user", e); 257 + clientOperatorIds.stream()
258 + .map(
259 + e ->
260 + UserAuthData.builder()
261 + .operatorId(e)
262 + .userType(UserTypeEnum.CLIENT)
263 + .build())
264 + .collect(Collectors.toList()));
265 + userAuthData.addAll(
266 + enterpriseOperatorIds.stream()
267 + .map(e -> UserAuthData.builder().operatorId(e).userType(UserTypeEnum.KDS).build())
268 + .collect(Collectors.toList()));
269 + log.info("received userAuthData:{}", JsonUtil.writeAsJson(userAuthData));
270 + try {
271 + WebSocketServer.sendMessageByUserTypes(
272 + List.of(UserTypeEnum.CLIENT, UserTypeEnum.KDS), userAuthData, createOrderData);
273 + } catch (IOException e) {
274 + log.error("Failed to send message to user", e);
275 + }
273 } 276 }
274 } 277 }
278 + return updateResponse.getIsUpdated();
279 + } else {
280 + final var build =
281 + ClientCustomerOrderModification.newBuilder()
282 + .setId(orderId)
283 + .setShouldUpdatePayStatus(true)
284 + .setPayStatus(PayStatusEnum.REFUND)
285 + .build();
286 + final var updateResponse =
287 + orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build);
288 + log.info("callback updateClientCustomerOrder result: {}", updateResponse.getIsUpdated());
289 + return updateResponse.getIsUpdated();
275 } 290 }
276 - return updateResponse.getIsUpdated();
277 } catch (JsonProcessingException e) { 291 } catch (JsonProcessingException e) {
278 log.error("Failed to parse XML response, raw XML: {}", paymentCallbackDTO.getPayResult(), e); 292 log.error("Failed to parse XML response, raw XML: {}", paymentCallbackDTO.getPayResult(), e);
279 - throw new RuntimeException("支付通知结果解析失败", e); 293 + throw new RuntimeException("支付/退款通知结果解析失败", e);
280 } catch (Exception e) { 294 } catch (Exception e) {
281 log.error("Unexpected error in callback, request: {}", paymentCallbackDTO, e); 295 log.error("Unexpected error in callback, request: {}", paymentCallbackDTO, e);
282 - throw new RuntimeException("支付通知处理失败", e); 296 + throw new RuntimeException("支付/退款通知处理失败", e);
283 } 297 }
284 } 298 }
285 299
...@@ -305,20 +319,20 @@ public class PayServiceClient { ...@@ -305,20 +319,20 @@ public class PayServiceClient {
305 return updateResponse.getIsUpdated(); 319 return updateResponse.getIsUpdated();
306 } 320 }
307 321
308 - public boolean cancelOrder(PayCancelRequestDto payCancelRequestDto) { 322 + public String orderPayRefund(PayRefundRequestDto payRefundRequestDto) {
309 - Integer orderId = payCancelRequestDto.getOrderId(); 323 + Integer orderId = payRefundRequestDto.getOrderId();
310 final var orderById = orderServiceRpcClient.getOrderById(orderId); 324 final var orderById = orderServiceRpcClient.getOrderById(orderId);
311 if (orderById == null) { 325 if (orderById == null) {
312 log.error("Order not found, orderId: {}", orderId); 326 log.error("Order not found, orderId: {}", orderId);
313 - return false; 327 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_NOT_FOUND);
314 } 328 }
315 if (orderById.getOnlinePay() != OnlinePayEnum.ONLINE) { 329 if (orderById.getOnlinePay() != OnlinePayEnum.ONLINE) {
316 log.info("Order {} is not online pay.", orderId); 330 log.info("Order {} is not online pay.", orderId);
317 - return false; 331 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_NOT_ONLINE_PAY);
318 } 332 }
319 if (orderById.getPayStatus() != PayStatusEnum.SUCCEED) { 333 if (orderById.getPayStatus() != PayStatusEnum.SUCCEED) {
320 log.info("Order {} pay is not succeed.", orderId); 334 log.info("Order {} pay is not succeed.", orderId);
321 - return false; 335 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_NOT_SUCCESS);
322 } 336 }
323 LocalDate today = LocalDate.now(); 337 LocalDate today = LocalDate.now();
324 LocalDate tomorrow = today.plusDays(1); 338 LocalDate tomorrow = today.plusDays(1);
...@@ -326,7 +340,7 @@ public class PayServiceClient { ...@@ -326,7 +340,7 @@ public class PayServiceClient {
326 LocalDateTime orderPayTime = DateUtil.toLocalDateTime(orderById.getPayTime()); 340 LocalDateTime orderPayTime = DateUtil.toLocalDateTime(orderById.getPayTime());
327 if (!orderPayTime.isBefore(tomorrowZero)) { 341 if (!orderPayTime.isBefore(tomorrowZero)) {
328 log.info("Order {} pay is beyond cancel time.", orderId); 342 log.info("Order {} pay is beyond cancel time.", orderId);
329 - return false; 343 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED);
330 } 344 }
331 345
332 String appId = businessConfig.getPayClientId(); 346 String appId = businessConfig.getPayClientId();
...@@ -337,7 +351,7 @@ public class PayServiceClient { ...@@ -337,7 +351,7 @@ public class PayServiceClient {
337 String payContentStr = 351 String payContentStr =
338 orderById.getId() 352 orderById.getId()
339 + "^" 353 + "^"
340 - + "01(退款)" 354 + + "01"
341 + "^" 355 + "^"
342 + "" 356 + ""
343 + "^" 357 + "^"
...@@ -351,7 +365,7 @@ public class PayServiceClient { ...@@ -351,7 +365,7 @@ public class PayServiceClient {
351 + "^" 365 + "^"
352 + orderById.getTransactionId() 366 + orderById.getTransactionId()
353 + "^" 367 + "^"
354 - + payCancelRequestDto.getHospitalCode() 368 + + payRefundRequestDto.getHospitalCode()
355 + "^" 369 + "^"
356 + "" 370 + ""
357 + "^" 371 + "^"
...@@ -378,36 +392,13 @@ public class PayServiceClient { ...@@ -378,36 +392,13 @@ public class PayServiceClient {
378 new Request.Builder().url(url).get().build(); 392 new Request.Builder().url(url).get().build();
379 Response payResponse = client.newCall(request).execute(); 393 Response payResponse = client.newCall(request).execute();
380 if (payResponse.code() != 200) { 394 if (payResponse.code() != 200) {
381 - log.error("cancel order pay failed, resp http code:" + payResponse.code()); 395 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED);
382 - return false;
383 - }
384 - String cancelPayJsonData = payResponse.body().string();
385 - log.info("cancel order pay resp:" + cancelPayJsonData);
386 - ObjectMapper objectMapper = new ObjectMapper();
387 - objectMapper.configure(Feature.ALLOW_MISSING_VALUES, true);
388 - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
389 - objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES, false);
390 -
391 - CancelPayResponseDto payResponseDto =
392 - objectMapper.readValue(cancelPayJsonData, CancelPayResponseDto.class);
393 -
394 - if (payResponseDto.getCode() != 0) {
395 - log.error("cancel order pay failed, resp code:" + payResponseDto.getCode());
396 - throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_CANCEL_FAILED);
397 - } else {
398 - // 更新订单撤销状态
399 - final var build =
400 - ClientCustomerOrderModification.newBuilder()
401 - .setId(orderId)
402 - .setShouldUpdateIsCanceled(true)
403 - .setIsCanceled(true)
404 - .build();
405 - orderServiceRpcClient.updateClientCustomerOrderPaymentResult(orderById, build);
406 - return true;
407 } 396 }
397 + String htmlContent = payResponse.body().string();
398 + return htmlContent;
408 } catch (Exception e) { 399 } catch (Exception e) {
409 log.error(e.getMessage()); 400 log.error(e.getMessage());
410 - throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_CANCEL_FAILED); 401 + throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_PAY_REFUND_FAILED);
411 } 402 }
412 } 403 }
413 } 404 }
......
...@@ -36,9 +36,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.OrderCountByStatusDto; ...@@ -36,9 +36,9 @@ import com.infoloop.tianting.model.dto.OrderDbDTO.OrderCountByStatusDto;
36 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto; 36 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailBatchUpdateDto;
37 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto; 37 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDetailDto;
38 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDto; 38 import com.infoloop.tianting.model.dto.OrderDbDTO.OrderDto;
39 -import com.infoloop.tianting.model.dto.OrderDbDTO.QueryCanceledOrderByPaginationDto;
40 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto; 39 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByConditionDto;
41 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto; 40 import com.infoloop.tianting.model.dto.OrderDbDTO.QueryOrderByPaginationDto;
41 +import com.infoloop.tianting.model.dto.OrderDbDTO.QueryRefundOrderByPaginationDto;
42 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto; 42 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderDto;
43 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderResponse; 43 import com.infoloop.tianting.model.dto.OrderDbDTO.UpdateOrderResponse;
44 import com.infoloop.tianting.model.dto.OrderDbDTO.getMenuOrderCountDto; 44 import com.infoloop.tianting.model.dto.OrderDbDTO.getMenuOrderCountDto;
...@@ -515,9 +515,9 @@ public class OrderServiceImpl implements OrderService { ...@@ -515,9 +515,9 @@ public class OrderServiceImpl implements OrderService {
515 } 515 }
516 516
517 @Override 517 @Override
518 - public OrderPageResult<OrderDto> getCanceledOrdersByPagination( 518 + public OrderPageResult<OrderDto> getRefundOrdersByPagination(
519 - QueryCanceledOrderByPaginationDto queryOrderDto) { 519 + QueryRefundOrderByPaginationDto queryOrderDto) {
520 - final var response = orderServiceRpcClient.queryCanceledClientCustomerOrdersByPagination(queryOrderDto); 520 + final var response = orderServiceRpcClient.queryRefundClientCustomerOrdersByPagination(queryOrderDto);
521 final var customerIds = response.getResponsesList().stream().map(SingleClientCustomerOrderRpcResponse::getCustomerId).collect(Collectors.toList()); 521 final var customerIds = response.getResponsesList().stream().map(SingleClientCustomerOrderRpcResponse::getCustomerId).collect(Collectors.toList());
522 final var customerResponse = clientCustomerServiceRpcClient.getClientCustomersByIds( 522 final var customerResponse = clientCustomerServiceRpcClient.getClientCustomersByIds(
523 queryOrderDto.getEnterpriseId(), customerIds); 523 queryOrderDto.getEnterpriseId(), customerIds);
......
...@@ -74,6 +74,7 @@ enum PayStatusEnum { ...@@ -74,6 +74,7 @@ enum PayStatusEnum {
74 SUCCEED = 3; 74 SUCCEED = 3;
75 FAILED = 4; 75 FAILED = 4;
76 PAY_CANCELED = 5; 76 PAY_CANCELED = 5;
77 + REFUND = 6;
77 } 78 }
78 79
79 enum CloseTimeType { 80 enum CloseTimeType {
...@@ -181,8 +182,8 @@ message QueryClientCustomerOrdersByPaginationRpcRequest { ...@@ -181,8 +182,8 @@ message QueryClientCustomerOrdersByPaginationRpcRequest {
181 int32 pageNo = 6; 182 int32 pageNo = 6;
182 int32 pageSize = 7; 183 int32 pageSize = 7;
183 repeated int32 stallIds = 8; 184 repeated int32 stallIds = 8;
184 - bool shouldFilterIsCanceled = 9; 185 + bool shouldFilterPayStatus = 9;
185 - bool isCanceled = 10; 186 + PayStatusEnum payStatus = 10;
186 } 187 }
187 188
188 message OrderCountByStatus { 189 message OrderCountByStatus {
......
...@@ -34,43 +34,43 @@ okhttp.max-idle-connections=10 ...@@ -34,43 +34,43 @@ okhttp.max-idle-connections=10
34 okhttp.keep-alive-duration=300 34 okhttp.keep-alive-duration=300
35 35
36 ##GRPC\u914D\u7F6E 36 ##GRPC\u914D\u7F6E
37 -grpc.order-service.url=localhost 37 +grpc.order-service.url=115.190.92.112
38 -grpc.order-service.port=4096 38 +grpc.order-service.port=4065
39 39
40 -grpc.menu-service.url=47.101.193.136 40 +grpc.menu-service.url=115.190.92.112
41 grpc.menu-service.port=3017 41 grpc.menu-service.port=3017
42 42
43 -grpc.sku-service.url=47.101.193.136 43 +grpc.sku-service.url=115.190.92.112
44 grpc.sku-service.port=3027 44 grpc.sku-service.port=3027
45 45
46 -grpc.category-service.url=47.101.193.136 46 +grpc.category-service.url=115.190.92.112
47 grpc.category-service.port=3027 47 grpc.category-service.port=3027
48 48
49 -grpc.client-customer-service.url=47.101.193.136 49 +grpc.client-customer-service.url=115.190.92.112
50 grpc.client-customer-service.port=3031 50 grpc.client-customer-service.port=3031
51 51
52 -grpc.client-inventory-service.url=47.101.193.136 52 +grpc.client-inventory-service.url=115.190.92.112
53 grpc.client-inventory-service.port=3037 53 grpc.client-inventory-service.port=3037
54 54
55 -grpc.meal-service.url=47.101.193.136 55 +grpc.meal-service.url=115.190.92.112
56 grpc.meal-service.port=3017 56 grpc.meal-service.port=3017
57 57
58 -grpc.delivery-service.url=47.101.193.136 58 +grpc.delivery-service.url=115.190.92.112
59 grpc.delivery-service.port=3017 59 grpc.delivery-service.port=3017
60 60
61 grpc.operator-service.url=115.190.92.112 61 grpc.operator-service.url=115.190.92.112
62 grpc.operator-service.port=3031 62 grpc.operator-service.port=3031
63 63
64 -grpc.woperator-service.url=47.101.193.136 64 +grpc.woperator-service.url=115.190.92.112
65 grpc.woperator-service.port=3028 65 grpc.woperator-service.port=3028
66 66
67 -grpc.enterprise-resource-service.url=47.101.193.136 67 +grpc.enterprise-resource-service.url=115.190.92.112
68 grpc.enterprise-resource-service.port=3026 68 grpc.enterprise-resource-service.port=3026
69 69
70 -grpc.client-resource-service.url=47.101.193.136 70 +grpc.client-resource-service.url=115.190.92.112
71 grpc.client-resource-service.port=3019 71 grpc.client-resource-service.port=3019
72 72
73 -grpc.meizhongyihe-service.url=47.101.193.136 73 +grpc.meizhongyihe-service.url=115.190.92.112
74 grpc.meizhongyihe-service.port=3040 74 grpc.meizhongyihe-service.port=3040
75 75
76 miniprogram.appId=wx40ec496d73b58ec6 76 miniprogram.appId=wx40ec496d73b58ec6
......