Commit 2ce89df05dc885f99db85a2fefa078260165bcb9
1 parent
5cde1c03
update:微信支付。
Showing
12 changed files
with
173 additions
and
52 deletions
etrade-order/src/main/java/com/diligrp/etrade/order/api/OrderController.java
... | ... | @@ -372,22 +372,6 @@ public class OrderController { |
372 | 372 | return ParameterDetection.detection(result); |
373 | 373 | } |
374 | 374 | Message message = orderService.orderWeChatPayBatch(orderWeChatPayBatch, OrderOrderType.BUYER_ORDER.getCodeInteger(),OrderOrderState.BUYER_WECHAT_PAY); |
375 | - | |
376 | - //临时代码 | |
377 | - WeChatPayTradeBackDto weChatPayTradeBackDto = (WeChatPayTradeBackDto) message.getData(); | |
378 | - WeChatPayTradeCallBackDto weChatPayTradeCallBackDto = new WeChatPayTradeCallBackDto(); | |
379 | - weChatPayTradeCallBackDto.setPaymentId(weChatPayTradeBackDto.getPaymentId()); | |
380 | - weChatPayTradeCallBackDto.setState(WeChatPayState.SUCCESS.getCode()); | |
381 | - weChatPayTradeCallBackDto.setWhen(LocalDateTime.now()); | |
382 | - List<Order> orderList = orderService.wxChatPayCallBack(weChatPayTradeCallBackDto); | |
383 | - if(CollectionUtils.isEmpty(orderList)){ | |
384 | - return Message.success("没有订单发生变更"); | |
385 | - }else{ | |
386 | - for (Order order : orderList){ | |
387 | - orderService.finishOrder(order); | |
388 | - } | |
389 | - } | |
390 | - //临时代码结束 | |
391 | 375 | return message; |
392 | 376 | } |
393 | 377 | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/dao/OrderMapper.java
... | ... | @@ -125,4 +125,10 @@ public interface OrderMapper extends MybatisMapperSupport { |
125 | 125 | * @return |
126 | 126 | */ |
127 | 127 | OrderDto selectOrderState(String code); |
128 | + | |
129 | + /** | |
130 | + * 更新订单库存为已扣减 | |
131 | + * @param ids | |
132 | + */ | |
133 | + void updateDeductState(@Param("ids")List<Long> ids); | |
128 | 134 | } | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/domain/OrderWeChatPayBatch.java
etrade-order/src/main/java/com/diligrp/etrade/order/model/Order.java
... | ... | @@ -281,6 +281,8 @@ public class Order { |
281 | 281 | |
282 | 282 | /** 运费 */ |
283 | 283 | private Long transportFee; |
284 | + /** 运费 */ | |
285 | + private Integer stockDeductionState; | |
284 | 286 | |
285 | 287 | public Integer getAchieveType() { |
286 | 288 | return achieveType; |
... | ... | @@ -745,4 +747,12 @@ public class Order { |
745 | 747 | public void setTransportFee(Long transportFee) { |
746 | 748 | this.transportFee = transportFee; |
747 | 749 | } |
750 | + | |
751 | + public Integer getStockDeductionState() { | |
752 | + return stockDeductionState; | |
753 | + } | |
754 | + | |
755 | + public void setStockDeductionState(Integer stockDeductionState) { | |
756 | + this.stockDeductionState = stockDeductionState; | |
757 | + } | |
748 | 758 | } |
749 | 759 | \ No newline at end of file | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderGoodsServiceImpl.java
... | ... | @@ -265,6 +265,10 @@ public class OrderGoodsServiceImpl implements OrderGoodsService { |
265 | 265 | @Transactional |
266 | 266 | @Override |
267 | 267 | public void deduct(Order order,Long operateId,String operateName) { |
268 | + //检测是否扣减过,已扣减则不再继续扣减 | |
269 | + if(order.getStockDeductionState()!=null&&order.getStockDeductionState().equals(OrderDeductionState.DEDUCT_FINISH.getCodeInteger())){ | |
270 | + return ; | |
271 | + } | |
268 | 272 | List<ProductDto> realgoods = getProductDtoByOrderId(order.getId(),order.getMarketId(),OrderGoodState.NORMAL.getCodeInteger()); |
269 | 273 | Map<Long,ProductDto> deductGoods = new HashMap<>(); |
270 | 274 | for(ProductDto productDto :realgoods){ |
... | ... | @@ -286,6 +290,7 @@ public class OrderGoodsServiceImpl implements OrderGoodsService { |
286 | 290 | goods.add(stock); |
287 | 291 | try{ |
288 | 292 | stockService.deduct(goods); |
293 | + order.setStockDeductionState(OrderDeductionState.DEDUCT_FINISH.getCodeInteger()); | |
289 | 294 | }catch (StockNotFoundException | InsufficientStockException e){ |
290 | 295 | throw new InsufficientStockException(e.getCode(),"支付失败,"+productDto.getProductName()+"库存不足。"); |
291 | 296 | } |
... | ... | @@ -296,7 +301,16 @@ public class OrderGoodsServiceImpl implements OrderGoodsService { |
296 | 301 | public void deductBatch(List<Order> orders, Long operateId, String operateName) { |
297 | 302 | List<ProductExtDto> realgoods = new ArrayList<>(); |
298 | 303 | for(Order order : orders){ |
304 | + //判断订单是否已经扣减过库存 | |
305 | + if(order.getStockDeductionState()!=null&&OrderDeductionState.DEDUCT_FINISH.getCodeInteger().equals(order.getStockDeductionState())){ | |
306 | + continue; | |
307 | + } | |
299 | 308 | realgoods.addAll(orderGoodsMapper.getProductDtoWithOrder(order.getId(),order.getShopId(),order.getMarketId(),order.getShopCustomerId(),OrderGoodState.NORMAL.getCodeInteger())); |
309 | + //变更订单库存扣减状态 | |
310 | + order.setStockDeductionState(OrderDeductionState.DEDUCT_FINISH.getCodeInteger()); | |
311 | + } | |
312 | + if(realgoods.size()<1){ | |
313 | + return ; | |
300 | 314 | } |
301 | 315 | Map<Long,ProductExtDto> deductGoods = new HashMap<>(); |
302 | 316 | for(ProductExtDto productExtDto :realgoods){ |
... | ... | @@ -318,6 +332,7 @@ public class OrderGoodsServiceImpl implements OrderGoodsService { |
318 | 332 | goods.add(stock); |
319 | 333 | try{ |
320 | 334 | stockService.deduct(goods); |
335 | + | |
321 | 336 | }catch (StockNotFoundException | InsufficientStockException e){ |
322 | 337 | throw new InsufficientStockException(e.getCode(),"支付失败,"+productExtDto.getProductName()+"库存不足。"); |
323 | 338 | } | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderServiceImpl.java
... | ... | @@ -647,6 +647,7 @@ public class OrderServiceImpl implements OrderService { |
647 | 647 | try{ |
648 | 648 | //扣减库存T |
649 | 649 | orderGoodsService.deductBatch(orderMap,orderPayBatch.getPayerCustomerId(),orderPayBatch.getPayerCustomerName()); |
650 | + orderMapper.updateDeductState(orderMap.stream().map(Order::getId).collect(Collectors.toList())); | |
650 | 651 | LOGGER.info("支付完成写入流水"); |
651 | 652 | orderPaymentService.sendSerialRecord(serialRecordDtos); |
652 | 653 | }catch (OrderException oe){ |
... | ... | @@ -791,7 +792,7 @@ public class OrderServiceImpl implements OrderService { |
791 | 792 | weChatPayTradeDto.setAmount(orderWeChatPayBatch.getTotlePayAmount().multiply(NumberTransform.ONE_HUNDERD).longValue()); |
792 | 793 | weChatPayTradeDto.setMarketId(orderWeChatPayBatch.getMarketId()); |
793 | 794 | weChatPayTradeDto.setType(orderWeChatPayBatch.getPayType()); |
794 | - weChatPayTradeDto.setCode(orderWeChatPayBatch.getCode()); | |
795 | + //weChatPayTradeDto.setCode(orderWeChatPayBatch.getCode()); | |
795 | 796 | weChatPayTradeDto.setOutTradeNo(orderWeChatPayBatch.getCodes().get(0)); |
796 | 797 | weChatPayTradeDto.setGoodsDesc(shop.getName()); |
797 | 798 | weChatPayTradeDto.setNotifyUrl(OrderConstant.WECHATPAY_BACK_API); |
... | ... | @@ -832,7 +833,8 @@ public class OrderServiceImpl implements OrderService { |
832 | 833 | } |
833 | 834 | //扣减库存T |
834 | 835 | orderGoodsService.deductBatch(orderList,orderWeChatPayBatch.getPayerCustomerId(),orderWeChatPayBatch.getPayerCustomerName()); |
835 | - | |
836 | + //更新扣减库存状态 | |
837 | + orderMapper.updateDeductState(orderList.stream().map(Order::getId).collect(Collectors.toList())); | |
836 | 838 | //返回数据,由小程序发起微信支付。 |
837 | 839 | return Message.success(weChatPayTradeBackDto); |
838 | 840 | } | ... | ... |
etrade-order/src/main/java/com/diligrp/etrade/order/type/OrderDeductionState.java
0 → 100644
1 | +package com.diligrp.etrade.order.type; | |
2 | + | |
3 | +import com.diligrp.etrade.core.type.IEnumType; | |
4 | + | |
5 | +/** | |
6 | + * 操作类型 | |
7 | + */ | |
8 | +public enum OrderDeductionState implements IEnumType { | |
9 | + UN_DEDUCT("未扣减", 1), | |
10 | + DEDUCT_FINISH("已扣减", 2) | |
11 | + ; | |
12 | + | |
13 | + private String name; | |
14 | + private Integer code; | |
15 | + | |
16 | + private OrderDeductionState(String name, Integer code) { | |
17 | + this.name = name; | |
18 | + this.code = code; | |
19 | + } | |
20 | + | |
21 | + public static OrderDeductionState getByCode(Integer code) { | |
22 | + for (OrderDeductionState temp : OrderDeductionState.values()) { | |
23 | + if (temp.getCodeInteger().equals(code)) { | |
24 | + return temp; | |
25 | + } | |
26 | + } | |
27 | + return null; | |
28 | + } | |
29 | + | |
30 | + public static String getNameByCode(Integer code) { | |
31 | + for (OrderDeductionState temp : OrderDeductionState.values()) { | |
32 | + if (temp.getCodeInteger().equals(code)) { | |
33 | + return temp.getName(); | |
34 | + } | |
35 | + } | |
36 | + return null; | |
37 | + } | |
38 | + | |
39 | + public Integer getCodeInteger() { | |
40 | + return this.code; | |
41 | + } | |
42 | + | |
43 | + public String getName() { | |
44 | + return this.name; | |
45 | + } | |
46 | + | |
47 | + public int getCode() { | |
48 | + return this.code; | |
49 | + } | |
50 | + | |
51 | + public String toString() { | |
52 | + return this.name; | |
53 | + } | |
54 | +} | |
0 | 55 | \ No newline at end of file | ... | ... |
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderMapper.xml
... | ... | @@ -59,6 +59,7 @@ |
59 | 59 | <result column="achieve_address" jdbcType="VARCHAR" property="achieveAddress" /> |
60 | 60 | <result column="achieve_state" jdbcType="INTEGER" property="achieveState" /> |
61 | 61 | <result column="transport_fee" jdbcType="BIGINT" property="transportFee" /> |
62 | + <result column="stock_deduction_state" jdbcType="BIGINT" property="stockDeductionState" /> | |
62 | 63 | </resultMap> |
63 | 64 | <sql id="Base_Column_List"> |
64 | 65 | id, code, mapping_code, market_id, buyer_code, buyer_id,buyer_store_customer_id, buyer_name, buyer_account_id, |
... | ... | @@ -68,7 +69,7 @@ |
68 | 69 | pay_time, order_state, `state`, version, creater_id, creater, created_time, modifier_id, |
69 | 70 | modifier, modified_time, verify_ids, verifier,verify_state, verifier_time, cancel_id, cancel_name, |
70 | 71 | cancel_time, out_time,`source`,totle_seller_fee,district_id,district_name,sub_district_id,sub_district_name,location |
71 | - ,order_status,relation_id,achieve_type,achieve_address,achieve_state,transport_fee | |
72 | + ,order_status,relation_id,achieve_type,achieve_address,achieve_state,transport_fee,stock_deduction_state | |
72 | 73 | </sql> |
73 | 74 | <sql id="Dto_Column_List"> |
74 | 75 | id, |
... | ... | @@ -383,6 +384,15 @@ |
383 | 384 | set order.totle_seller_fee = #{totleSellerFee} |
384 | 385 | where id = #{id,jdbcType=BIGINT} |
385 | 386 | </update> |
387 | + <update id="updateDeductState" parameterType="java.util.List"> | |
388 | + update `order` | |
389 | + set order.stock_deduction_state = 2 | |
390 | + where id in ( | |
391 | + <foreach collection="ids" item="id" separator=","> | |
392 | + #{id} | |
393 | + </foreach> | |
394 | + ) | |
395 | + </update> | |
386 | 396 | |
387 | 397 | <select id="getOrderByCode" resultMap="BaseResultMap"> |
388 | 398 | SELECT | ... | ... |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/PayRpc.java
... | ... | @@ -112,4 +112,31 @@ public interface PayRpc { |
112 | 112 | */ |
113 | 113 | @RequestMapping(value = "/wechat/api/gateway.do?service=wechat.payment.service:exists", method = RequestMethod.POST) |
114 | 114 | Message<WeChatPayFunctionBackDto> checkWeChatPayChannel(@RequestBody WeChatPayFunctionDto requestDto, @RequestHeader HttpHeaders headers); |
115 | + | |
116 | + /** | |
117 | + * 微信杭州银行支付 | |
118 | + * @param requestDto | |
119 | + * @param headers | |
120 | + * @return | |
121 | + */ | |
122 | + @RequestMapping(value = "/wechat/api/gateway.do?service=hzbank.payment.service:prepay", method = RequestMethod.POST) | |
123 | + Message<WeChatPayTradeBackDto> wechatHgPay(@RequestBody WeChatPayTradeDto requestDto, @RequestHeader HttpHeaders headers); | |
124 | + | |
125 | + /** | |
126 | + * 微信杭州银行预支付关闭 | |
127 | + * @param requestDto | |
128 | + * @param headers | |
129 | + * @return | |
130 | + */ | |
131 | + @RequestMapping(value = "/wechat/api/gateway.do?service=hzbank.payment.service:close", method = RequestMethod.POST) | |
132 | + Message<WeChatPayFunctionBackDto> wechatHgPayClose(@RequestBody WeChatPayFunctionDto requestDto, @RequestHeader HttpHeaders headers); | |
133 | + | |
134 | + /** | |
135 | + * 微信杭州银行预支付状态查询 | |
136 | + * @param requestDto | |
137 | + * @param headers | |
138 | + * @return | |
139 | + */ | |
140 | + @RequestMapping(value = "/wechat/api/gateway.do?service=hzbank.payment.service:state", method = RequestMethod.POST) | |
141 | + Message<WeChatPayFunctionBackDto> wechatHgPayCheckState(@RequestBody WeChatPayFunctionDto requestDto, @RequestHeader HttpHeaders headers); | |
115 | 142 | } | ... | ... |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/dto/WeChatPayTradeBackDto.java
... | ... | @@ -40,6 +40,13 @@ public class WeChatPayTradeBackDto { |
40 | 40 | */ |
41 | 41 | private String paySign; |
42 | 42 | |
43 | + // token | |
44 | + private String tokenCode; | |
45 | + // 小程序跳转地址 | |
46 | + private String tokenCodeUrl; | |
47 | + // token过期时间 | |
48 | + private String tokenEnd; | |
49 | + | |
43 | 50 | |
44 | 51 | public String getPaymentId() { |
45 | 52 | return paymentId; |
... | ... | @@ -96,4 +103,28 @@ public class WeChatPayTradeBackDto { |
96 | 103 | public void setPaySign(String paySign) { |
97 | 104 | this.paySign = paySign; |
98 | 105 | } |
106 | + | |
107 | + public String getTokenCode() { | |
108 | + return tokenCode; | |
109 | + } | |
110 | + | |
111 | + public void setTokenCode(String tokenCode) { | |
112 | + this.tokenCode = tokenCode; | |
113 | + } | |
114 | + | |
115 | + public String getTokenCodeUrl() { | |
116 | + return tokenCodeUrl; | |
117 | + } | |
118 | + | |
119 | + public void setTokenCodeUrl(String tokenCodeUrl) { | |
120 | + this.tokenCodeUrl = tokenCodeUrl; | |
121 | + } | |
122 | + | |
123 | + public String getTokenEnd() { | |
124 | + return tokenEnd; | |
125 | + } | |
126 | + | |
127 | + public void setTokenEnd(String tokenEnd) { | |
128 | + this.tokenEnd = tokenEnd; | |
129 | + } | |
99 | 130 | } | ... | ... |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/dto/WeChatPayTradeDto.java
... | ... | @@ -13,10 +13,10 @@ import java.util.List; |
13 | 13 | public class WeChatPayTradeDto { |
14 | 14 | |
15 | 15 | /** |
16 | - * 支付方式-JSAPI, NATIVE等 | |
16 | + * 支付方式-Cashier | |
17 | 17 | */ |
18 | - @NotNull(message = "payType should not be null") | |
19 | - private String type; | |
18 | + | |
19 | + private String type = "Cashier"; | |
20 | 20 | /** |
21 | 21 | * 微信商品描述-微信扫码支付时显示-不超过128个字符 |
22 | 22 | */ | ... | ... |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/resolver/WeChatPayRpcResolver.java
... | ... | @@ -58,21 +58,13 @@ public class WeChatPayRpcResolver { |
58 | 58 | public Message<WeChatPayTradeBackDto> createWeChatPayTrade(WeChatPayTradeDto weChatPayTradeDto){ |
59 | 59 | //创建提交单 |
60 | 60 | weChatPayTradeDto.setNotifyUrl(backBaseUrl+weChatPayTradeDto.getNotifyUrl()); |
61 | + weChatPayTradeDto.setType("Cashier"); | |
61 | 62 | weChatPayTradeDto.setDescription(weChatPayTradeDto.getDescription()==null?"电子交易结算":weChatPayTradeDto.getDescription()); |
62 | 63 | //组装headers |
63 | 64 | HttpHeaders prepareHeaders = creatHeader(weChatPayTradeDto.getMarketId().toString(),PAY_STATE_PREPARE); |
64 | - //临时代码 TODO | |
65 | - WeChatPayTradeBackDto backDto = new WeChatPayTradeBackDto(); | |
66 | - backDto.setPaymentId(new Snowflake().nextIdStr()); | |
67 | - backDto.setPaySign("PaySign"); | |
68 | - backDto.setCodeUrl("codeUrl"); | |
69 | - backDto.setSignType("SignType"); | |
70 | - backDto.setPacket("packet"); | |
71 | - backDto.setNonceStr("NonceStr"); | |
72 | - Message<WeChatPayTradeBackDto> prepareJsonObject = Message.success(backDto); | |
73 | - //Message<WeChatPayTradeBackDto> prepareJsonObject = payRpc.wechatPay(weChatPayTradeDto, prepareHeaders); | |
65 | + Message<WeChatPayTradeBackDto> prepareJsonObject = payRpc.wechatHgPay(weChatPayTradeDto, prepareHeaders); | |
74 | 66 | if(!prepareJsonObject.getCode().equals(200)){ |
75 | - log.info("创建交易入参{},请求体头部为{},请求结果为{}",prepareHeaders,prepareHeaders,prepareJsonObject); | |
67 | + log.info("创建交易入参{},请求体头部为{},请求结果为{}",weChatPayTradeDto,prepareHeaders,prepareJsonObject); | |
76 | 68 | throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "创建交易信息失败:" + prepareJsonObject.getMessage()); |
77 | 69 | }else { |
78 | 70 | return prepareJsonObject; |
... | ... | @@ -87,14 +79,7 @@ public class WeChatPayRpcResolver { |
87 | 79 | public Message<WeChatPayFunctionBackDto> checkWeChatPayState(WeChatPayFunctionDto weChatPayFunctionDto){ |
88 | 80 | //组装headers |
89 | 81 | HttpHeaders prepareHeaders = creatHeader(weChatPayFunctionDto.getMarketId().toString(), PAY_STATE_CHECK); |
90 | - //临时代码 TODO | |
91 | - WeChatPayFunctionBackDto weChatPayFunctionBackDto = new WeChatPayFunctionBackDto(); | |
92 | - weChatPayFunctionBackDto.setState(WeChatPayState.SUCCESS.getCode()); | |
93 | - weChatPayFunctionBackDto.setPaymentId(weChatPayFunctionBackDto.getPaymentId()); | |
94 | - weChatPayFunctionBackDto.setWhen(LocalDateTime.now()); | |
95 | - weChatPayFunctionBackDto.setStateCode("101"); | |
96 | - Message<WeChatPayFunctionBackDto> cancelJsonObject = Message.success(weChatPayFunctionBackDto); | |
97 | - //Message<WeChatPayFunctionBackDto> cancelJsonObject = payRpc.wechatPayCheckState(weChatPayFunctionDto, prepareHeaders); | |
82 | + Message<WeChatPayFunctionBackDto> cancelJsonObject = payRpc.wechatHgPayCheckState(weChatPayFunctionDto, prepareHeaders); | |
98 | 83 | |
99 | 84 | if(!cancelJsonObject.getCode().equals(200)){ |
100 | 85 | log.info("撤销交易入参{},请求体头部为{},请求结果为{}",weChatPayFunctionDto,prepareHeaders,cancelJsonObject); |
... | ... | @@ -110,17 +95,15 @@ public class WeChatPayRpcResolver { |
110 | 95 | * @return true 关闭成功 |
111 | 96 | */ |
112 | 97 | public Boolean closeWeChatPay(WeChatPayFunctionDto weChatPayFunctionDto){ |
113 | - //临时代码 TODO | |
114 | - return true; | |
115 | 98 | //组装headers |
116 | -// HttpHeaders prepareHeaders = creatHeader(weChatPayFunctionDto.getMarketId().toString(), PAY_STATE_CLOSE); | |
117 | -// Message<WeChatPayFunctionBackDto> cancelJsonObject = payRpc.wechatPayClose(weChatPayFunctionDto, prepareHeaders); | |
118 | -// if(!cancelJsonObject.getCode().equals(200)){ | |
119 | -// log.info("关闭微信支付订单入参{},请求体头部为{},请求结果为{}",weChatPayFunctionDto,prepareHeaders,cancelJsonObject); | |
120 | -// throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "关闭微信支付订单失败:" + cancelJsonObject.getMessage()); | |
121 | -// }else { | |
122 | -// return true; | |
123 | -// } | |
99 | + HttpHeaders prepareHeaders = creatHeader(weChatPayFunctionDto.getMarketId().toString(), PAY_STATE_CLOSE); | |
100 | + Message<WeChatPayFunctionBackDto> cancelJsonObject = payRpc.wechatHgPayClose(weChatPayFunctionDto, prepareHeaders); | |
101 | + if(!cancelJsonObject.getCode().equals(200)){ | |
102 | + log.info("关闭微信支付订单入参{},请求体头部为{},请求结果为{}",weChatPayFunctionDto,prepareHeaders,cancelJsonObject); | |
103 | + throw new PlatformServiceException(ErrorCode.SYSTEM_UNKNOWN_ERROR, "关闭微信支付订单失败:" + cancelJsonObject.getMessage()); | |
104 | + }else { | |
105 | + return true; | |
106 | + } | |
124 | 107 | } |
125 | 108 | |
126 | 109 | // /** | ... | ... |