From 9d35ba657fa5e3add766405d76e3ff8c4dcd4ad4 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 04 七月 2020 15:38:00 +0800
Subject: [PATCH] 多系统兼容优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java |  677 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 341 insertions(+), 336 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
index 4e7dfa9..3339eaf 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
@@ -6,6 +6,7 @@
 import javax.annotation.Resource;
 
 import com.yeshi.fanli.entity.SystemEnum;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.NumberUtil;
@@ -55,385 +56,389 @@
 
 @Service
 public class BanLiShopOrderPayServiceImpl implements BanLiShopOrderPayService {
-	@Resource
-	private BanLiShopGoodsSetService banLiShopGoodsSetService;
+    @Resource
+    private BanLiShopGoodsSetService banLiShopGoodsSetService;
 
-	@Resource
-	private BanLiShopGoodsService banLiShopGoodsService;
+    @Resource
+    private BanLiShopGoodsService banLiShopGoodsService;
 
-	@Resource
-	private BanLiShopGoodsClassService banLiShopGoodsClassService;
+    @Resource
+    private BanLiShopGoodsClassService banLiShopGoodsClassService;
 
-	@Resource
-	private RedPackBalanceService redPackBalanceService;
+    @Resource
+    private RedPackBalanceService redPackBalanceService;
 
-	@Resource
-	private BanLiShopOrderService banLiShopOrderService;
+    @Resource
+    private BanLiShopOrderService banLiShopOrderService;
 
-	@Resource
-	private RedPackDetailService redPackDetailService;
+    @Resource
+    private RedPackDetailService redPackDetailService;
 
-	@Resource
-	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+    @Resource
+    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
 
-	@Resource
-	private ConfigService configService;
+    @Resource
+    private ConfigService configService;
 
-	@Resource
-	private AdminUserService adminUserService;
+    @Resource
+    private AdminUserService adminUserService;
 
-	@Resource
-	private RocketMQManager rocketMQManager;
+    @Resource
+    private RocketMQManager rocketMQManager;
 
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
-		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
-		if (order == null) {
-			throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
-		}
-		if (order.getHongBaoPayment() == null)
-			return;
+    @Resource
+    private UserInfoService userInfoService;
 
-		if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
-			throw new BanLiShopOrderException(3, "閲嶅鏀粯");
-		}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
+        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
+        if (order == null) {
+            throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
+        }
+        if (order.getHongBaoPayment() == null)
+            return;
 
-		BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
-		BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService.selectByPrimaryKey(goods.getGoodsClass().getId());
-		BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
-		RedPackDetail detail = null;
-		try {
-			detail = RedPackDetailFactory.createUseByShopOrder(orderId, order.getUid(), goodsClass.getName(),
-					set.getName(), order.getHongBaoPayment());
-		} catch (RedPackDetailException e) {
-			e.printStackTrace();
-		}
+        if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
+            throw new BanLiShopOrderException(3, "閲嶅鏀粯");
+        }
 
-		if (detail == null)
-			throw new RedPackBalanceException(4, "绾㈠寘璇︽儏澶辫触");
-		redPackBalanceService.subRedPack(order.getUid(), order.getHongBaoPayment(), detail);
+        BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
+        BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService.selectByPrimaryKey(goods.getGoodsClass().getId());
+        BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
+        RedPackDetail detail = null;
+        try {
+            detail = RedPackDetailFactory.createUseByShopOrder(orderId, order.getUid(), goodsClass.getName(),
+                    set.getName(), order.getHongBaoPayment());
+        } catch (RedPackDetailException e) {
+            e.printStackTrace();
+        }
 
-		BanLiShopOrder update = new BanLiShopOrder();
-		update.setId(order.getId());
-		update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_PAID);
-		// 鍒ゆ柇鍏朵粬寰呮敮浠橀」鏄惁宸茬粡鏀粯
-		update.setUpdateTime(new Date());
-		if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
-			if ((order.getBalancePaymentState() == null
-					|| order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
-					&& (order.getMoneyPaymentState() == null
-							|| order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯
-			{
-				update.setState(BanLiShopOrder.STATE_PAID);
-				update.setStateDesc("鏀粯鎴愬姛");
-			}
-		banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
-		if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
-			paySuccess(order);
-		}
-	}
+        if (detail == null)
+            throw new RedPackBalanceException(4, "绾㈠寘璇︽儏澶辫触");
+        redPackBalanceService.subRedPack(order.getUid(), order.getHongBaoPayment(), detail);
 
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
-		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
-		if (order == null) {
-			throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
-		}
-		if (order.getMoneyPayment() == null)
-			throw new BanLiShopOrderException(2, "涓嶉渶瑕侀噰鐢ㄧ幇閲戞敮浠�");
+        BanLiShopOrder update = new BanLiShopOrder();
+        update.setId(order.getId());
+        update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_PAID);
+        // 鍒ゆ柇鍏朵粬寰呮敮浠橀」鏄惁宸茬粡鏀粯
+        update.setUpdateTime(new Date());
+        if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
+            if ((order.getBalancePaymentState() == null
+                    || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
+                    && (order.getMoneyPaymentState() == null
+                    || order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯
+            {
+                update.setState(BanLiShopOrder.STATE_PAID);
+                update.setStateDesc("鏀粯鎴愬姛");
+            }
+        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+        if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
+            paySuccess(order);
+        }
+    }
 
-		if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() != BanLiShopOrder.PAY_STATE_NOPAY) {
-			throw new BanLiShopOrderException(3, "閲嶅鏀粯");
-		}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
+        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
+        if (order == null) {
+            throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
+        }
+        if (order.getMoneyPayment() == null)
+            throw new BanLiShopOrderException(2, "涓嶉渶瑕侀噰鐢ㄧ幇閲戞敮浠�");
 
-		if (order.getMoneyPayment().compareTo(money) > 0) {
-			throw new BanLiShopOrderException(4, "鏀粯閲戦涓嶅");
-		}
+        if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() != BanLiShopOrder.PAY_STATE_NOPAY) {
+            throw new BanLiShopOrderException(3, "閲嶅鏀粯");
+        }
 
-		// 鏀粯鎴愬姛
-		BanLiShopOrder update = new BanLiShopOrder();
-		update.setId(order.getId());
-		update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_PAID);
-		// 鍒ゆ柇鍏朵粬寰呮敮浠橀」鏄惁宸茬粡鏀粯
-		update.setUpdateTime(new Date());
-		if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
-			if ((order.getBalancePaymentState() == null
-					|| order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
-					&& (order.getHongBaoPaymentState() == null
-							|| order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯
-			{
-				update.setState(BanLiShopOrder.STATE_PAID);
-				update.setStateDesc("鏀粯鎴愬姛");
-			}
-		banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
-		if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
-			paySuccess(order);
-		}
-	}
+        if (order.getMoneyPayment().compareTo(money) > 0) {
+            throw new BanLiShopOrderException(4, "鏀粯閲戦涓嶅");
+        }
 
-	/**
-	 * 鏀粯鎴愬姛
-	 */
-	private void paySuccess(BanLiShopOrder order) {
-		ThreadUtil.run(new Runnable() {
+        // 鏀粯鎴愬姛
+        BanLiShopOrder update = new BanLiShopOrder();
+        update.setId(order.getId());
+        update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_PAID);
+        // 鍒ゆ柇鍏朵粬寰呮敮浠橀」鏄惁宸茬粡鏀粯
+        update.setUpdateTime(new Date());
+        if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
+            if ((order.getBalancePaymentState() == null
+                    || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
+                    && (order.getHongBaoPaymentState() == null
+                    || order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 鍏朵粬寰呮敮浠橀」宸茬粡鏀粯
+            {
+                update.setState(BanLiShopOrder.STATE_PAID);
+                update.setStateDesc("鏀粯鎴愬姛");
+            }
+        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+        if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
+            paySuccess(order);
+        }
+    }
 
-			@Override
-			public void run() {
-				long[] targetUids = new long[] { 3L, 4L };
-				Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(), SystemEnum.blks);
-				String[] sts = config.getValue().split(",");
-				String account = sts[0];
-				String pwd = sts[1];
-				for (long adminId : targetUids) {
-					AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId);
-					String msg = "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�";
-					boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�", msg);
-				}
-			}
-		});
+    /**
+     * 鏀粯鎴愬姛
+     */
+    private void paySuccess(BanLiShopOrder order) {
+        ThreadUtil.run(new Runnable() {
 
-	}
+            @Override
+            public void run() {
+                SystemEnum system = userInfoService.getUserSystem(order.getUid());
+                long[] targetUids = new long[]{3L, 4L};
+                Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(),system);
+                String[] sts = config.getValue().split(",");
+                String account = sts[0];
+                String pwd = sts[1];
+                for (long adminId : targetUids) {
+                    AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId);
+                    String msg = "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�";
+                    boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�", msg);
+                }
+            }
+        });
 
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void refund(Long orderId) throws BanLiShopOrderException {
-		// 璁㈠崟閫�娆�
-		// 鏌ヨ璁㈠崟鏄惁宸茬粡琚嫆缁�
-		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
-		if (order == null)
-			throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
-		if (order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_FAIL
-				|| order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS)
-			throw new BanLiShopOrderException(2, "璁㈠崟鏈鎷掔粷/璁㈠崟宸查��娆�");
+    }
 
-		BanLiShopOrder update = new BanLiShopOrder();
-		update.setId(order.getId());
-		if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
-			BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
-			BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
-					.selectByPrimaryKey(goods.getGoodsClass().getId());
-			BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
-			// 绾㈠寘閫�娆�
-			RedPackDetail detail = null;
-			try {
-				detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
-						set.getName(), order.getHongBaoPayment());
-			} catch (RedPackDetailException e) {
-				e.printStackTrace();
-			}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void refund(Long orderId) throws BanLiShopOrderException {
+        // 璁㈠崟閫�娆�
+        // 鏌ヨ璁㈠崟鏄惁宸茬粡琚嫆缁�
+        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
+        if (order == null)
+            throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
+        if (order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_FAIL
+                || order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS)
+            throw new BanLiShopOrderException(2, "璁㈠崟鏈鎷掔粷/璁㈠崟宸查��娆�");
 
-			if (detail == null)
-				throw new BanLiShopOrderException(4, "绾㈠寘璇︽儏澶辫触");
-			try {
-				redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
-			} catch (RedPackBalanceException e) {
-				throw new BanLiShopOrderException(5, "绾㈠寘閫�娆惧け璐�");
-			}
-			update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
-			order.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
-		}
+        BanLiShopOrder update = new BanLiShopOrder();
+        update.setId(order.getId());
+        if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
+            BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
+            BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
+                    .selectByPrimaryKey(goods.getGoodsClass().getId());
+            BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
+            // 绾㈠寘閫�娆�
+            RedPackDetail detail = null;
+            try {
+                detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
+                        set.getName(), order.getHongBaoPayment());
+            } catch (RedPackDetailException e) {
+                e.printStackTrace();
+            }
 
-		if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
-			try {
-				boolean success = BanLiShopWXPayUtil.refund(order.getOrderNo(), order.getMoneyPayment());
-				if (success) {
-					update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
-					order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
-					// 鍙戦�侀��娆炬秷鎭�
-					BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
-					Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
-							OrderTopicTagEnum.banLiShopOrderRefund, msg);
-					SendResult result = rocketMQManager.sendNormalMsg(message, 1000 * 60 * 5L,null);
-					if (result == null) {
-						throw new BanLiShopOrderException(8, "娑堟伅鍙戦�佸け璐�");
-					}
-				} else
-					throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�");
-			} catch (WXOrderException e) {
-				throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�");
-			}
-		}
-		// 妫�鏌� 鏄惁閫�娆炬垚鍔�
-		if (order.getMoneyPaymentState() != null
-				&& order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) {
-			try {
-				boolean isS = BanLiShopWXPayUtil.isRefundSuccess(order.getOrderNo());
-				if (isS) {
-					update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
-					order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
-				}
-			} catch (WXOrderException e) {
-				throw new BanLiShopOrderException(7, "寰俊鏀粯閫�娆炬煡璇㈠け璐�");
-			}
-		}
+            if (detail == null)
+                throw new BanLiShopOrderException(4, "绾㈠寘璇︽儏澶辫触");
+            try {
+                redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
+            } catch (RedPackBalanceException e) {
+                throw new BanLiShopOrderException(5, "绾㈠寘閫�娆惧け璐�");
+            }
+            update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+            order.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+        }
 
-		if (update.getHongBaoPaymentState() != null || update.getMoneyPaymentState() != null) {
-			// 鑾峰彇鏁翠釜璁㈠崟鐨勯��娆剧姸鎬�
-			int state = getRefundState(order);
-			update.setState(state);
-			update.setUpdateTime(new Date());
-			banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
-		}
-	}
+        if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
+            try {
+                boolean success = BanLiShopWXPayUtil.refund(order.getOrderNo(), order.getMoneyPayment());
+                if (success) {
+                    update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
+                    order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
+                    // 鍙戦�侀��娆炬秷鎭�
+                    BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
+                    Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
+                            OrderTopicTagEnum.banLiShopOrderRefund, msg);
+                    SendResult result = rocketMQManager.sendNormalMsg(message, 1000 * 60 * 5L, null);
+                    if (result == null) {
+                        throw new BanLiShopOrderException(8, "娑堟伅鍙戦�佸け璐�");
+                    }
+                } else
+                    throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�");
+            } catch (WXOrderException e) {
+                throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�");
+            }
+        }
+        // 妫�鏌� 鏄惁閫�娆炬垚鍔�
+        if (order.getMoneyPaymentState() != null
+                && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) {
+            try {
+                boolean isS = BanLiShopWXPayUtil.isRefundSuccess(order.getOrderNo());
+                if (isS) {
+                    update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+                    order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+                }
+            } catch (WXOrderException e) {
+                throw new BanLiShopOrderException(7, "寰俊鏀粯閫�娆炬煡璇㈠け璐�");
+            }
+        }
 
-	/**
-	 * 鑾峰彇鏁翠釜閫�娆剧姸鎬�
-	 * 
-	 * @param order
-	 * @return
-	 */
-	private int getRefundState(BanLiShopOrder order) {
-		int refundCount = 0;
-		int refundSuccessCount = 0;
+        if (update.getHongBaoPaymentState() != null || update.getMoneyPaymentState() != null) {
+            // 鑾峰彇鏁翠釜璁㈠崟鐨勯��娆剧姸鎬�
+            int state = getRefundState(order);
+            update.setState(state);
+            update.setUpdateTime(new Date());
+            banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+        }
+    }
 
-		if (order.getHongBaoPayment() != null) {
-			refundCount++;
-			if (order.getHongBaoPaymentState() != null
-					&& order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
-				refundSuccessCount++;
-		}
+    /**
+     * 鑾峰彇鏁翠釜閫�娆剧姸鎬�
+     *
+     * @param order
+     * @return
+     */
+    private int getRefundState(BanLiShopOrder order) {
+        int refundCount = 0;
+        int refundSuccessCount = 0;
 
-		if (order.getBalancePayment() != null) {
-			refundCount++;
-			if (order.getBalancePaymentState() != null
-					&& order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
-				refundSuccessCount++;
-		}
+        if (order.getHongBaoPayment() != null) {
+            refundCount++;
+            if (order.getHongBaoPaymentState() != null
+                    && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
+                refundSuccessCount++;
+        }
 
-		if (order.getMoneyPayment() != null) {
-			refundCount++;
-			if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
-				refundSuccessCount++;
-		}
+        if (order.getBalancePayment() != null) {
+            refundCount++;
+            if (order.getBalancePaymentState() != null
+                    && order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
+                refundSuccessCount++;
+        }
 
-		if (refundCount == refundSuccessCount)
-			return BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS;// 閫�娆炬垚鍔�
-		else {
-			if (refundSuccessCount == 0)
-				return BanLiShopOrder.STATE_REJECT;// 閫�娆句腑
-			else
-				return BanLiShopOrder.STATE_REJECT_REFUND_PART_SUCCESS;// 閮ㄥ垎閫�娆炬垚鍔�
-		}
-	}
+        if (order.getMoneyPayment() != null) {
+            refundCount++;
+            if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
+                refundSuccessCount++;
+        }
 
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void charge(Long orderId) throws BanLiShopOrderException {
-		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKey(orderId);
-		if (order == null)
-			throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
-		if (order.getState() != BanLiShopOrder.STATE_PAID) {
-			throw new BanLiShopOrderException(100, "璁㈠崟涓嶆槸澶勪簬浠樻鐘舵��");
-		}
-		if (order.getChargeAccountType() == ChargeTypeEnum.phone) {
-			if (!StringUtil.isMobile(order.getChargeAccount())) {
-				throw new BanLiShopOrderException(101, "鐢佃瘽鍙风爜鏍煎紡涓嶆纭�");
-			}
-		} else if (order.getChargeAccountType() == ChargeTypeEnum.qq) {
-			if (!NumberUtil.isNumeric(order.getChargeAccount())) {
-				throw new BanLiShopOrderException(101, "QQ鍙锋牸寮忛敊璇�");
-			}
-		} else {
-			throw new BanLiShopOrderException(102, "闈炲厖鍊煎晢鍝�");
-		}
-		// 鑾峰彇绂忕鐨勫椁�
-		BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
-		if (set == null) {
-			throw new BanLiShopOrderException(104, "鍟嗗搧濂楅宸蹭笅绾�");
-		}
+        if (refundCount == refundSuccessCount)
+            return BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS;// 閫�娆炬垚鍔�
+        else {
+            if (refundSuccessCount == 0)
+                return BanLiShopOrder.STATE_REJECT;// 閫�娆句腑
+            else
+                return BanLiShopOrder.STATE_REJECT_REFUND_PART_SUCCESS;// 閮ㄥ垎閫�娆炬垚鍔�
+        }
+    }
 
-		if (StringUtil.isNullOrEmpty(set.getChargeFuLuNum())) {
-			throw new BanLiShopOrderException(105, "绂忕鍏呭�糏D涓虹┖");
-		}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void charge(Long orderId) throws BanLiShopOrderException {
+        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKey(orderId);
+        if (order == null)
+            throw new BanLiShopOrderException(1, "璁㈠崟涓嶅瓨鍦�");
+        if (order.getState() != BanLiShopOrder.STATE_PAID) {
+            throw new BanLiShopOrderException(100, "璁㈠崟涓嶆槸澶勪簬浠樻鐘舵��");
+        }
+        if (order.getChargeAccountType() == ChargeTypeEnum.phone) {
+            if (!StringUtil.isMobile(order.getChargeAccount())) {
+                throw new BanLiShopOrderException(101, "鐢佃瘽鍙风爜鏍煎紡涓嶆纭�");
+            }
+        } else if (order.getChargeAccountType() == ChargeTypeEnum.qq) {
+            if (!NumberUtil.isNumeric(order.getChargeAccount())) {
+                throw new BanLiShopOrderException(101, "QQ鍙锋牸寮忛敊璇�");
+            }
+        } else {
+            throw new BanLiShopOrderException(102, "闈炲厖鍊煎晢鍝�");
+        }
+        // 鑾峰彇绂忕鐨勫椁�
+        BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
+        if (set == null) {
+            throw new BanLiShopOrderException(104, "鍟嗗搧濂楅宸蹭笅绾�");
+        }
 
-		// 鏀瑰彉鐘舵�佷负鎴愬姛
-		BanLiShopOrder update = new BanLiShopOrder(order.getId());
-		update.setState(BanLiShopOrder.STATE_SUCCESS);
-		update.setStateDesc("鍏呭�兼垚鍔�");
-		update.setUpdateTime(new Date());
-		update.setSuccessTime(new Date());
-		banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+        if (StringUtil.isNullOrEmpty(set.getChargeFuLuNum())) {
+            throw new BanLiShopOrderException(105, "绂忕鍏呭�糏D涓虹┖");
+        }
 
-		if (order.getHongBaoPayment() != null && order.getHongBaoPayment().compareTo(new BigDecimal(0)) > 0) {
-			// 灏嗙孩鍖呮槑缁嗗鏄�
-			RedPackDetail detail = null;
-			try {
-				detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
-						order.getHongBaoPayment());
-			} catch (RedPackDetailException e) {
-				e.printStackTrace();
-			}
+        // 鏀瑰彉鐘舵�佷负鎴愬姛
+        BanLiShopOrder update = new BanLiShopOrder(order.getId());
+        update.setState(BanLiShopOrder.STATE_SUCCESS);
+        update.setStateDesc("鍏呭�兼垚鍔�");
+        update.setUpdateTime(new Date());
+        update.setSuccessTime(new Date());
+        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
 
-			if (detail != null) {
-				redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true);
-			}
-		}
+        if (order.getHongBaoPayment() != null && order.getHongBaoPayment().compareTo(new BigDecimal(0)) > 0) {
+            // 灏嗙孩鍖呮槑缁嗗鏄�
+            RedPackDetail detail = null;
+            try {
+                detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
+                        order.getHongBaoPayment());
+            } catch (RedPackDetailException e) {
+                e.printStackTrace();
+            }
 
-		// 娑堟伅鍙戦��
-		MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO();
-		dto.setGoodsSetName(order.getOrderGoods().getSetName());
-		dto.setHongBao(order.getHongBaoPayment());
-		dto.setMoney(order.getMoneyPayment());
-		dto.setTime(new Date());
-		userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseSuccess,
-				new Gson().toJson(dto), null);
+            if (detail != null) {
+                redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true);
+            }
+        }
 
-		try {
-			if (Constant.IS_TEST) {
-				FuLuChargeApiUtil.shaXiangCharge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
-						order.getChargeAccount());
-			} else
-				FuLuChargeApiUtil.charge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
-						order.getChargeAccount());
-		} catch (FuLuChargeException e) {
-			throw new BanLiShopOrderException(e.getCode(), e.getMsg());
-		}
-	}
+        // 娑堟伅鍙戦��
+        MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO();
+        dto.setGoodsSetName(order.getOrderGoods().getSetName());
+        dto.setHongBao(order.getHongBaoPayment());
+        dto.setMoney(order.getMoneyPayment());
+        dto.setTime(new Date());
+        userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseSuccess,
+                new Gson().toJson(dto), null);
 
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public void invalidOrderByOrderId(Long orderId, String stateDesc) throws BanLiShopOrderException {
+        try {
+            if (Constant.IS_TEST) {
+                FuLuChargeApiUtil.shaXiangCharge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
+                        order.getChargeAccount());
+            } else
+                FuLuChargeApiUtil.charge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
+                        order.getChargeAccount());
+        } catch (FuLuChargeException e) {
+            throw new BanLiShopOrderException(e.getCode(), e.getMsg());
+        }
+    }
 
-		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
-		if (order == null)
-			return;
-		// 閫�娆�
-		if (order.getState() == BanLiShopOrder.STATE_NO_PAY) {// 鐘舵�佽繕鏄湭鏀粯
-			// 閫�娆剧孩鍖�
-			if (order.getHongBaoPaymentState() != null
-					&& order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
-				BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
-				BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
-						.selectByPrimaryKey(goods.getGoodsClass().getId());
-				BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
-				// 绾㈠寘閫�娆�
-				RedPackDetail detail = null;
-				try {
-					detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
-							set.getName(), order.getHongBaoPayment());
-				} catch (RedPackDetailException e) {
-					e.printStackTrace();
-				}
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void invalidOrderByOrderId(Long orderId, String stateDesc) throws BanLiShopOrderException {
 
-				if (detail == null)
-					throw new BanLiShopOrderException(4, "绾㈠寘璇︽儏澶辫触");
-				try {
-					redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
-				} catch (RedPackBalanceException e) {
-					throw new BanLiShopOrderException(5, "绾㈠寘閫�娆惧け璐�");
-				}
+        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
+        if (order == null)
+            return;
+        // 閫�娆�
+        if (order.getState() == BanLiShopOrder.STATE_NO_PAY) {// 鐘舵�佽繕鏄湭鏀粯
+            // 閫�娆剧孩鍖�
+            if (order.getHongBaoPaymentState() != null
+                    && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
+                BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
+                BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
+                        .selectByPrimaryKey(goods.getGoodsClass().getId());
+                BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
+                // 绾㈠寘閫�娆�
+                RedPackDetail detail = null;
+                try {
+                    detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
+                            set.getName(), order.getHongBaoPayment());
+                } catch (RedPackDetailException e) {
+                    e.printStackTrace();
+                }
 
-				BanLiShopOrder update = new BanLiShopOrder(order.getId());
-				update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
-				update.setUpdateTime(new Date());
-				banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
-			}
+                if (detail == null)
+                    throw new BanLiShopOrderException(4, "绾㈠寘璇︽儏澶辫触");
+                try {
+                    redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
+                } catch (RedPackBalanceException e) {
+                    throw new BanLiShopOrderException(5, "绾㈠寘閫�娆惧け璐�");
+                }
 
-			banLiShopOrderService.invalidOrderByOrderId(orderId, stateDesc);
-		}
+                BanLiShopOrder update = new BanLiShopOrder(order.getId());
+                update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+                update.setUpdateTime(new Date());
+                banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+            }
 
-	}
+            banLiShopOrderService.invalidOrderByOrderId(orderId, stateDesc);
+        }
+
+    }
 
 }

--
Gitblit v1.8.0