| 
					
				 | 
			
			
				@@ -22,7 +22,9 @@ import com.yonge.cooleshow.biz.dal.vo.UserOrderVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.common.service.IdGeneratorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.toolset.utils.collection.MapUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.toolset.utils.obj.ObjectUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.beanutils.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -53,20 +55,22 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private UserOrderPaymentService orderPaymentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private PaymentSdk paymentSdk; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private IdGeneratorService idGeneratorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //验证订单是否可以下单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private static final Map<String, Function<OrderReq, HttpResponseResult<OrderCheckRes>>> checkOrder = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final Map<OrderTypeEnum, Function<OrderReq, HttpResponseResult<OrderCheckRes>>> checkOrder = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //插入订单后执行 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private static final Map<String, Consumer<UserOrderVo>> orderAfter = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderAfter = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PostConstruct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void init() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //vip开通缴费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        checkOrder.put(OrderTypeEnum.VIP.getCode(), vipCardRecordService::checkOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        checkOrder.put(OrderTypeEnum.VIP, vipCardRecordService::checkOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //vip开通缴费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        orderAfter.put(OrderTypeEnum.VIP.getCode(), vipCardRecordService::orderAfter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderAfter.put(OrderTypeEnum.VIP, vipCardRecordService::orderAfter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -137,6 +141,11 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return HttpResponseResult.failed("订单状态异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void orderCallback(String data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /*** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 处理待支付订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @author liweifan 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -157,7 +166,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         deviceInfo.setDevice_ip(payReq.getIpAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         paymentReq.setDevice_info(deviceInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        paymentReq.setNotify_url("异步通知地址"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //todo 异步通知地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //paymentReq.setNotify_url("异步通知地址"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (PayChannelEnum.wx_lite.equals(payReq.getPayChannel())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Map<String, Object> expend = new HashMap<>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -169,16 +179,10 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OrderPayRes orderPayRes = new OrderPayRes(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderPayRes.setPay_amt(detail.getActualPrice().setScale(2).toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        orderPayRes.setPay_info( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                MapUtil.populateMap(new HashMap<>(), res.get("expend")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .get("pay_info").toString() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        UserOrderPayment orderPayment = insertOrderPayment(res, payReq); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String pay_info =  ((JSONObject)res.get("expend")).getString("pay_info"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPayRes.setPay_info(pay_info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //入订单付款表,同时修改订单状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserOrderPayment orderPayment = insertOrderPayment(res, payReq); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return HttpResponseResult.succeed(orderPayRes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -187,28 +191,15 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderPayment.setOrderNo(payReq.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderPayment.setPayChannel(payReq.getPayChannel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setTransNo(res.get("id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setPayAmt( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    new BigDecimal(res.get("pay_amt").toString()).setScale(2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            String pay_info = MapUtil.populateMap(new HashMap<>(), res.get("expend")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .get("pay_info").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setPayInfo(pay_info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setStatus(PayStatusEnum.pending); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //保存异常信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<String, Object> errMsg = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            errMsg.put("error_code", res.get("error_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            errMsg.put("error_type", res.get("error_type")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            errMsg.put("error_msg", res.get("error_msg")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            errMsg.put("status", res.get("status")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            errMsg.put("invalid_param", res.get("invalid_param")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setPayFailMsg(JSONObject.toJSONString(errMsg)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orderPayment.setStatus(PayStatusEnum.failed); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPayment.setTransNo(res.get("id").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPayment.setPayAmt( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                new BigDecimal(res.get("pay_amt").toString()).setScale(2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String pay_info =  ((JSONObject)res.get("expend")).getString("pay_info"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPayment.setPayInfo(pay_info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPayment.setStatus(PayStatusEnum.pending); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orderPaymentService.save(orderPayment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return orderPayment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -233,8 +224,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private UserOrderVo insertOrder(OrderReq orderReq, OrderCheckRes data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrder userOrder = new UserOrder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //todo 订单号生产规则 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        userOrder.setOrderNo("123"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //订单号生成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long orderNo = idGeneratorService.generatorId("userOrder"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setOrderNo(orderNo.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         userOrder.setUserId(orderReq.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         userOrder.setMerchId(data.getMerchId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         userOrder.setOrderName(orderReq.getOrderName()); 
			 |