| 
					
				 | 
			
			
				@@ -75,6 +75,7 @@ import com.kmall.manager.manager.print.ticket.TicketPrintUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.kmall.manager.manager.redis.JedisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.kmall.manager.manager.wechat.WechatUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.kmall.manager.manager.wechat.wxglobal.dto.WechatGlobalRefundApiResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.qiniu.util.Json; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import okhttp3.Request; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -807,8 +808,6 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         map.put("orderId", order.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryList(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // TODO 退单的库存明细存入表中,准备发送到中控 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<KtoEccsEntity> ktoEccsEntities = new LinkedList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .queryByGoodsIdAndStoreId(order.getStoreId().longValue(), orderGoodsEntity.getGoodsId().longValue()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -819,42 +818,17 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (sellVolume.compareTo(Constant.ZERO) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 sellVolume = Constant.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            GoodsEntity goodsEntity = goodsDao.queryObject(orderGoodsEntity.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            if (goodsEntity != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                stockNum = goodsEntity.getGoodsNumber(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                //还原商户商品库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                resetGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Integer stockNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            GoodsEntity goodsEntity = goodsDao.queryObject(orderGoodsEntity.getGoodsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (goodsEntity != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                stockNum = goodsEntity.getGoodsNumber(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //还原商户商品库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                resetGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (null != storeRelaEntity.getStockNum()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 stockNum = storeRelaEntity.getStockNum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 resetStoreGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user);//还原门店库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            orderGoodsVoList 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            KtoEccsEntity ktoEccsEntity = new KtoEccsEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ktoEccsEntity.setRequestData(JSON.toJSONString(orderGoodsEntity)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ktoEccsEntity.setRequestType("04"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ktoEccsEntity.setSendStatus("00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (user != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ktoEccsEntity.setCreaterSn(user.getUserId() + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ktoEccsEntity.setCreaterSn("9999"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ktoEccsEntity.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ktoEccsEntities.add(ktoEccsEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (ktoEccsEntities.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (ktoEccsEntities.size() > 50) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<List<KtoEccsEntity>> partition = Lists.partition(ktoEccsEntities, 50); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                for (List<KtoEccsEntity> ktoEccs : partition) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ktoEccsService.saveBatch(ktoEccs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ktoEccsService.saveBatch(ktoEccsEntities); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -938,8 +912,6 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             goodsDao.update(goodsEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            storeRelaEntity.setSellVolume(Integer.parseInt(sellVolume.toString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            productStoreRelaDao.update(storeRelaEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             String username = "system"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (user != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 username = user.getUsername(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3217,27 +3189,18 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 pickUpCodeEntity.setPickUpCodeStatus("3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 pickUpCodeService.update(pickUpCodeEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                // 判断该订单是否进入oms系统 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (!arrivedOms(order.getOrderSn())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    // oms无该订单,则直接退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    restoreInventory(order, "收银端退款"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    orderRefund.setRestore(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    // 如果oms有订单,统一进入锁库存情况 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    orderRefund.setRestore(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    toBeRestoreInventory(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //调用免税mall接口退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //HttpUtil.doPostJson() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                restoreInventoryMsMall(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderRefund.setRestore(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orderRefundDao.save(orderRefund);//退款记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 支付宝的退款代码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if (Dict.payFlag.item_alipay.getItem().equals(payFlag)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AliPayMicropayApiResult userRefund = AliPayUtil.aliTradeRefund(order.getOrderSn(), order.getActualPrice().toString(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     "用户退款", order.getStoreId() + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 是否已退款校验 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 String fundChange = userRefund.getFundChange(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3245,9 +3208,8 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     return R.error("资金已退回,请勿重复退款!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                LOGGER.error("[支付宝退款校验出错]",e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             LOGGER.info(userRefund.getSubMsg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             OrderRefundEntity orderRefund = new OrderRefundEntity(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3278,23 +3240,52 @@ public class OrderServiceImpl implements OrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             PickUpCodeEntity pickUpCodeEntity = pickUpCodeService.queryObject(order.getOrderSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             pickUpCodeEntity.setPickUpCodeStatus("3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             pickUpCodeService.update(pickUpCodeEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            // 判断该订单是否进入oms系统 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!arrivedOms(order.getOrderSn())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                // oms无该订单,则直接退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                restoreInventory(order, "收银端退款"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                orderRefund.setRestore(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                // 如果oms有订单,统一进入锁库存情况 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                orderRefund.setRestore(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                toBeRestoreInventory(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //调用免税mall接口退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            restoreInventoryMsMall(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            orderRefund.setRestore(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             orderRefundDao.save(orderRefund);//退款记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return R.ok("退款成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 海控订单退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void restoreInventoryMsMall(OrderEntity order) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //调用CCNET接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String msg = OkHttpUtils.post(JSON.toJSONString(order),OmsMerchPropertiesBuilder.instance().getWxOrderResendUrl() + "/refundOrder",JSON.toJSONString(order),"SSL"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ResponseData responseData = JacksonUtils.fromStringJson(msg, ResponseData.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(responseData.getCode().equalsIgnoreCase("0")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<String, Object> map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SysUserEntity user = ShiroUtils.getUserEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            map.put("orderId", order.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryList(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .queryByGoodsIdAndStoreId(order.getStoreId().longValue(), orderGoodsEntity.getGoodsId().longValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (null == storeRelaEntity || null == storeRelaEntity.getSellVolume()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    storeRelaEntity.setSellVolume(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume() - orderGoodsEntity.getNumber());//销售量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (sellVolume.compareTo(Constant.ZERO) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sellVolume = Constant.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //还原门店库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (null != storeRelaEntity.getStockNum()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Integer stockNum = storeRelaEntity.getStockNum(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    resetStoreGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, responseData.getCode(), user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LOGGER.error(order.getOrderSn()+"[该订单退款失败]"+JSON.toJSONString(order)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void toBeRestoreInventory(OrderEntity order) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |