From f537abe9f3646c739beaf15076246a2f71a347e9 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 20 二月 2025 16:57:55 +0800
Subject: [PATCH] IOS广告增加区域屏蔽

---
 src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java |  379 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 244 insertions(+), 135 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java b/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java
index 35aa27d..d302f30 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java
@@ -2,19 +2,20 @@
 
 import com.alipay.api.AlipayApiException;
 import com.alipay.api.response.AlipayTradeQueryResponse;
-import com.yeshi.buwan.dao.vip.VIPOrderRecordDao;
-import com.yeshi.buwan.domain.vip.OrderType;
-import com.yeshi.buwan.domain.vip.UserVIPInfo;
-import com.yeshi.buwan.domain.vip.VIPOrderRecord;
-import com.yeshi.buwan.domain.vip.VIPPriceType;
+import com.yeshi.buwan.dao.vip.OrderRecordDao;
+import com.yeshi.buwan.dao.vip.VIPPriceDao;
+import com.yeshi.buwan.domain.vip.*;
+import com.yeshi.buwan.dto.order.OrderPaySuccessForm;
 import com.yeshi.buwan.dto.order.PayWayInfoDTO;
 import com.yeshi.buwan.exception.PPTVException;
 import com.yeshi.buwan.exception.goldcorn.GoldCornException;
 import com.yeshi.buwan.exception.order.OrderException;
 import com.yeshi.buwan.exception.order.PayException;
 import com.yeshi.buwan.exception.vip.VIPException;
-import com.yeshi.buwan.pptv.PPTVVipManager;
+import com.yeshi.buwan.exception.vip.VideoBuyRecordException;
+import com.yeshi.buwan.videos.pptv.PPTVVipManager;
 import com.yeshi.buwan.service.inter.order.OrderService;
+import com.yeshi.buwan.service.manager.GoldCornManager;
 import com.yeshi.buwan.util.Constant;
 import com.yeshi.buwan.util.RedisManager;
 import com.yeshi.buwan.util.StringUtil;
@@ -28,6 +29,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.alipay.AlipayH5PayUtil;
 import org.yeshi.utils.entity.wx.WXPayOrderInfoV3;
+import org.yeshi.utils.ios.pay.IOSPayVerifyUtil;
+import org.yeshi.utils.ios.pay.vo.IOSAPPBuyVerifyResult;
 import org.yeshi.utils.wx.WXPayV3Util;
 
 import javax.annotation.Resource;
@@ -42,13 +45,12 @@
 @Service
 public class OrderServiceImpl implements OrderService {
 
-
     private static Logger logger = LoggerFactory.getLogger("OrderService");
 
     private static Logger orderLogger = LoggerFactory.getLogger("order");
 
     @Resource
-    private VIPOrderRecordDao vipOrderRecordDao;
+    private OrderRecordDao vipOrderRecordDao;
 
     @Resource
     private PPTVVipManager pptvVipManager;
@@ -56,20 +58,45 @@
     @Resource
     private RedisManager redisManager;
 
+    @Resource
+    private GoldCornManager goldCornManager;
+
+    @Resource
+    private VIPPriceDao vipPriceDao;
+
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public VIPOrderRecord createOrder(VIPOrderRecord record) throws OrderException {
-        if (record.getMoney() == null || record.getType() == null || record.getOrderType() == null || record.getUid() == null) {
+    public OrderRecord createOrder(OrderRecord record) throws OrderException {
+        if (record.getMoney() == null || (record.getType() == null && record.getVideoCid() == null) || record.getOrderType() == null || record.getUid() == null) {
             throw new OrderException(1, "鍙傛暟涓嶅畬鏁�");
         }
 
         if (record.getState() == null) {
-            record.setState(VIPOrderRecord.STATE_NOT_PAY);
+            record.setState(OrderRecord.STATE_NOT_PAY);
         }
 
         if (record.getCreateTime() == null) {
             record.setCreateTime(new Date());
         }
+
+        if (record.getPayWay() == OrderRecord.PAY_WAY_WX) {
+            if (record.getGoldCorn() != null && record.getGoldCorn() > 0) {
+                if (record.getMoney().compareTo(new BigDecimal("0")) == 0) {
+                    record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN);
+                } else {
+                    record.setPayWay(OrderRecord.PAY_WAY_WX_GOLDCORN);
+                }
+            }
+        } else if (record.getPayWay() == OrderRecord.PAY_WAY_ALIPAY) {
+            if (record.getGoldCorn() != null && record.getGoldCorn() > 0) {
+                if (record.getMoney().compareTo(new BigDecimal("0")) == 0) {
+                    record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN);
+                } else {
+                    record.setPayWay(OrderRecord.PAY_WAY_ALIPAY_GOLDCORN);
+                }
+            }
+        }
+
 
         record.setMoneyPay(false);
         record.setGoldCornPay(false);
@@ -80,33 +107,52 @@
     }
 
     @Transactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(timeoutMills = 30000, name = "buwan-order", rollbackFor = Exception.class)
     @Override
-    public PayWayInfoDTO payOrder(VIPOrderRecord record) throws OrderException, GoldCornException, PayException {
-        //TODO 褰辫璞嗘敮浠�
+    public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException, VIPException, PPTVException, VideoBuyRecordException {
         String orderNo = VIPOrderUtil.getOutOrderNo(record.getOrderType(), record.getId());
         switch (record.getPayWay()) {
-            case VIPOrderRecord
+            case OrderRecord
                     .PAY_WAY_ALIPAY_GOLDCORN:
-                //TODO 鎵e奖瑙嗚眴
+
+                try {
+                    goldCornManager.consumeGoldCorn(record, record.getGoldCorn());
+                } catch (Exception e) {
+                    throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�");
+                }
+                paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()));
+
                 orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId());
-            case VIPOrderRecord
+            case OrderRecord
                     .PAY_WAY_ALIPAY: {
+                if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) {
+                    return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId()));
+                }
                 //鐢熸垚鏀粯瀹濇敮浠樿鍗�
-                String form = VipUtil.getVipChargeAlipayForm(record.getId(), orderNo, record.getMoney());
+                String form = VipUtil.getVipChargeAlipayForm(record.getId(), record.getOrderType(), orderNo, record.getMoney());
                 //鏆傚瓨2鍒嗛挓
                 String id = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis());
                 redisManager.cacheCommonString(id, form, 120);
                 String payUrl = Constant.HOST + "/BuWan/alipay/printPayForm?formId=" + id;
                 orderLogger.info("璁㈠崟鍒涘缓鏀粯瀹濇敮浠橀摼鎺ユ垚鍔燂細id-{} 閾炬帴-{}", record.getId(), payUrl);
-                return new PayWayInfoDTO(VIPOrderRecord
+                return new PayWayInfoDTO(OrderRecord
                         .PAY_WAY_ALIPAY, payUrl);
             }
-            case VIPOrderRecord
+            case OrderRecord
                     .PAY_WAY_WX_GOLDCORN:
-                //TODO 鎵e奖瑙嗚眴
+                try {
+                    goldCornManager.consumeGoldCorn(record, record.getGoldCorn());
+
+                } catch (Exception e) {
+                    throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�");
+                }
+                paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()));
                 orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{} 绫诲瀷-{}", record.getId(), record.getOrderType().name());
-            case VIPOrderRecord
+            case OrderRecord
                     .PAY_WAY_WX: {
+                if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) {
+                    return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId()));
+                }
                 //鐢熸垚寰俊鏀粯璁㈠崟
                 try {
                     String title = "";
@@ -117,167 +163,194 @@
                     }
                     String payUrl = VipUtil.createWXOrder(record.getId(), record.getIpInfo(), orderNo, record.getMoney(), title);
                     orderLogger.info("璁㈠崟鍒涘缓寰俊鏀粯閾炬帴鎴愬姛锛歩d-{} 閾炬帴-{}", record.getId(), payUrl);
-                    return new PayWayInfoDTO(VIPOrderRecord.PAY_WAY_WX, payUrl);
+                    return new PayWayInfoDTO(OrderRecord.PAY_WAY_WX, payUrl);
                 } catch (Exception e) {
                     logger.error("鐢熸垚寰俊鏀粯璁㈠崟鍑洪敊", e);
                     throw new PayException(2, e.getMessage());
                 }
             }
 
-            case VIPOrderRecord.PAY_WAY_GOLDCORN: {
-                //TODO 鎵e奖瑙嗚眴
-                orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId());
+            case OrderRecord.PAY_WAY_GOLDCORN: {
+                try {
+                    goldCornManager.consumeGoldCorn(record, record.getGoldCorn());
+                    orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId());
+                } catch (Exception e) {
+                    throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�");
+                }
+                paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()));
+                return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId()));
             }
-            break;
+            case OrderRecord.PAY_WAY_IAPP:
+                return new PayWayInfoDTO(OrderRecord.PAY_WAY_IAPP, null);
         }
         throw new OrderException(1, "鏀粯鏂瑰紡涓嶅瓨鍦�");
     }
 
-    private int getPayState(VIPOrderRecord record) {
+    private int getPayState(OrderRecord record) {
         switch (record.getPayWay()) {
-            case VIPOrderRecord.PAY_WAY_ALIPAY:
-            case VIPOrderRecord.PAY_WAY_WX:
+            case OrderRecord.PAY_WAY_ALIPAY:
+            case OrderRecord.PAY_WAY_WX:
                 if (record.getMoneyPay() != null && record.getMoneyPay())
-                    return VIPOrderRecord.STATE_PAY;
+                    return OrderRecord.STATE_PAY;
                 else
-                    return VIPOrderRecord.STATE_NOT_PAY;
-            case VIPOrderRecord.PAY_WAY_ALIPAY_GOLDCORN:
-            case VIPOrderRecord.PAY_WAY_WX_GOLDCORN:
+                    return OrderRecord.STATE_NOT_PAY;
+            case OrderRecord.PAY_WAY_ALIPAY_GOLDCORN:
+            case OrderRecord.PAY_WAY_WX_GOLDCORN:
                 if (record.getMoneyPay() != null && record.getMoneyPay() && record.getGoldCornPay() != null && record.getGoldCornPay())
-                    return VIPOrderRecord.STATE_PAY;
+                    return OrderRecord.STATE_PAY;
                 else
-                    return VIPOrderRecord.STATE_NOT_PAY;
-            case VIPOrderRecord.PAY_WAY_GOLDCORN:
+                    return OrderRecord.STATE_NOT_PAY;
+            case OrderRecord.PAY_WAY_GOLDCORN:
                 if (record.getGoldCornPay() != null && record.getGoldCornPay())
-                    return VIPOrderRecord.STATE_PAY;
+                    return OrderRecord.STATE_PAY;
                 else
-                    return VIPOrderRecord.STATE_NOT_PAY;
+                    return OrderRecord.STATE_NOT_PAY;
+            case OrderRecord.PAY_WAY_IAPP:
+                if (record.getMoneyPay())
+                    return OrderRecord.STATE_PAY;
+                else
+                    return OrderRecord.STATE_NOT_PAY;
         }
-        return VIPOrderRecord.STATE_NOT_PAY;
+        return OrderRecord.STATE_NOT_PAY;
     }
 
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public VIPOrderRecord paySuccess(String id, int payWay, BigDecimal payMoney, Date payTime) throws
-            VIPException, PPTVException {
-        orderLogger.info("璁㈠崟鏀粯鎴愬姛鐩殑鎵ц锛歩d-{}锛屾敮浠樻柟寮�-{},鏀粯閲戦-{}锛屾敮浠樻椂闂�-{}", id, payWay, payMoney, payTime.getTime());
+    public OrderRecord paySuccess(OrderPaySuccessForm successForm) throws
+            VIPException, PPTVException, VideoBuyRecordException, OrderException {
+        orderLogger.info("璁㈠崟鏀粯鎴愬姛鐩殑鎵ц锛歩d-{}锛屾敮浠樻柟寮�-{},鏀粯閲戦-{}锛屾敮浠樻椂闂�-{}", successForm.getId(), successForm.getPayWay(), successForm.getPayMoney(), successForm.getPayTime());
 
         Session session = vipOrderRecordDao.getSession();
 
         //淇敼璁板綍
-        Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(VIPOrderRecord.class).setCacheable(false).setParameter(0, id);
-        List<VIPOrderRecord> list = query.list();
+        Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, successForm.getId());
+        List<OrderRecord> list = query.list();
+        if (list == null || list.size() == 0)
+            throw new OrderException(10, "璁㈠崟涓嶅瓨鍦�");
 
-        if (list != null && list.size() > 0) {
-            VIPOrderRecord record = list.get(0);
-            if (record.getState() != VIPOrderRecord.STATE_NOT_PAY)
-                throw new VIPException(1, "璁㈠崟鏈浜庡緟鏀粯鐘舵��");
+        OrderRecord record = list.get(0);
+        if (record.getState() != OrderRecord.STATE_NOT_PAY)
+            throw new OrderException(1, "璁㈠崟鏈浜庡緟鏀粯鐘舵��");
 
 
-            if (record.getPayWay() != VIPOrderRecord.PAY_WAY_GOLDCORN) {
-                record.setPayMoney(payMoney);
-                record.setMoneyPay(true);
-            } else {
-                record.setGoldCornPay(true);
-            }
-
-            record.setPayTime(payTime);
-            record.setUpdateTime(new Date());
-            record.setState(getPayState(record));
-
-            //宸茬粡鏀粯鎴愬姛
-            if (record.getState() == VIPOrderRecord.STATE_PAY) {
-                session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, id).executeUpdate();
-
-            }
-
-            if (record.getOrderType() == OrderType.vip) {
-                Date[] expireDate = addExpireTime(session, record.getUid(), payTime, record.getType());
-                record.setVipStartTime(expireDate[0]);
-                record.setVipEndTime(expireDate[1]);
-                if (expireDate == null) {
-                    throw new VIPException(2, "娣诲姞鐢ㄦ埛浼氬憳鏃堕棿鍑洪敊");
-                }
-                session.update(record);
-
-
-                if (record.getState() == VIPOrderRecord.STATE_PAY) {
-                    orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id);
-                    //璐拱VIP
-                    pptvVipManager.buyVIP(record);
-                    orderLogger.info("璐拱VIP鎴愬姛锛歩d-{}", id);
-                } else {
-                    orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id);
-                }
-
-            } else if (record.getOrderType() == OrderType.video) {
-                record.setVipStartTime(payTime);
-                //7澶╀箣鍐呮湁鏁�
-                record.setVipEndTime(new Date(payTime.getTime() + 1000 * 60 * 60L * 24 * 7));
-                session.update(record);
-                //鍗曠墖璐拱鎴愬姛锛�7澶╂湁鏁堟湡锛�
-                if (record.getState() == VIPOrderRecord.STATE_PAY) {
-                    orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id);
-                    //璐拱鍗曠墖
-                    pptvVipManager.buyVideo(record);
-                    orderLogger.info("璐拱鍗曠墖鎴愬姛锛歩d-{}", id);
-                } else {
-                    orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id);
-                }
-            }
-
-            return record;
+        if (successForm.getPayWay() != OrderRecord.PAY_WAY_GOLDCORN) {
+            record.setPayMoney(successForm.getPayMoney());
+            record.setMoneyPay(true);
+            record.setAppleTransactionId(successForm.getAppleTransactionId());
+            record.setAppleOriginalTransactionId(successForm.getAppleOriginalTransactionId());
         } else {
-            throw new VIPException(10, "璁㈠崟涓嶅瓨鍦�");
+            record.setGoldCornPay(true);
         }
+
+        record.setPayTime(successForm.getPayTime());
+        record.setUpdateTime(new Date());
+        record.setState(getPayState(record));
+
+        //宸茬粡鏀粯鎴愬姛
+        if (record.getState() == OrderRecord.STATE_PAY) {
+            session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, successForm.getId()).executeUpdate();
+        }
+
+        if (record.getOrderType() == OrderType.vip) {
+            Date[] expireDate = addExpireTime(session, record.getUid(), successForm.getPayTime(), record.getType());
+            record.setVipStartTime(expireDate[0]);
+            record.setVipEndTime(expireDate[1]);
+            if (expireDate == null) {
+                throw new VIPException(2, "娣诲姞鐢ㄦ埛浼氬憳鏃堕棿鍑洪敊");
+            }
+            session.update(record);
+
+
+            if (record.getState() == OrderRecord.STATE_PAY) {
+                orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", successForm.getId());
+                //璐拱VIP
+                pptvVipManager.buyVIP(record);
+                orderLogger.info("璐拱VIP鎴愬姛锛歩d-{}", successForm.getId());
+            } else {
+                orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", successForm.getId());
+            }
+
+        } else if (record.getOrderType() == OrderType.video) {
+            record.setVipStartTime(successForm.getPayTime());
+            //7澶╀箣鍐呮湁鏁�
+            record.setVipEndTime(new Date(successForm.getPayTime().getTime() + 1000 * 60 * 60L * 24 * 7));
+            session.update(record);
+            //鍗曠墖璐拱鎴愬姛锛�7澶╂湁鏁堟湡锛�
+            if (record.getState() == OrderRecord.STATE_PAY) {
+                orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", successForm.getId());
+                //璐拱鍗曠墖
+                pptvVipManager.buyVideo(record);
+                orderLogger.info("璐拱鍗曠墖鎴愬姛锛歩d-{}", successForm.getId());
+            } else {
+                orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", successForm.getId());
+            }
+        }
+
+        return record;
+
     }
 
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void cancelOrder(String id, String reason) throws OrderException {
+    public void cancelOrder(String id, String reason) throws OrderException, GoldCornException {
 
         Session session = vipOrderRecordDao.getSession();
-        Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(VIPOrderRecord.class).setCacheable(false).setParameter(0, id);
-        List<VIPOrderRecord> list = query.list();
+        Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, id);
+        List<OrderRecord> list = query.list();
         //璁㈠崟涓嶅瓨鍦�
         if (list == null || list.size() == 0)
             throw new OrderException(1, "璁㈠崟涓嶅瓨鍦�");
-        VIPOrderRecord record = list.get(0);
-        if (record.getState() == VIPOrderRecord.STATE_PAY) {
+        OrderRecord record = list.get(0);
+        if (record.getState() == OrderRecord.STATE_PAY) {
             throw new OrderException(1, "宸叉敮浠樻垚鍔熺殑璁㈠崟涓嶈兘鍙栨秷");
         }
 
-        if (record.getPayWay() != VIPOrderRecord.PAY_WAY_GOLDCORN && record.getMoneyPay() != null && record.getMoneyPay()) {
+        if (record.getPayWay() != OrderRecord.PAY_WAY_GOLDCORN && record.getMoneyPay() != null && record.getMoneyPay()) {
             throw new OrderException(2, "璧勯噾鏀粯鎴愬姛鐨勮鍗曚笉鑳藉彇娑�");
         }
 
         //杩斿洖璞�
         if (record.getGoldCornPay() != null && record.getGoldCornPay() && record.getGoldCorn() != null && record.getGoldCorn() > 0) {
-            //TODO 閫�鍥炲奖瑙嗚眴
-
-
+            try {
+                goldCornManager.drawbackGoldCorn(record);
+            } catch (Exception e) {
+                throw new GoldCornException(1, "褰辫璞嗛��娆惧け璐�");
+            }
         }
 
         //璁剧疆璁㈠崟鐘舵��
-        record.setState(VIPOrderRecord.STATE_CANCEL);
+        record.setState(OrderRecord.STATE_CANCEL);
         record.setUpdateTime(new Date());
         record.setRemarks(reason);
-        vipOrderRecordDao.update(record);
+        session.update(record);
         orderLogger.info("鍙栨秷璁㈠崟鎴愬姛锛歩d-{}", id);
+    }
+
+    @Override
+    public List<OrderRecord> getCanCancelOrderList(int page, int pageSize) {
+
+        OrderRecordDao.DaoQuery daoQuery = new OrderRecordDao.DaoQuery();
+        daoQuery.state = OrderRecord.STATE_NOT_PAY;
+        //30鍒嗛挓鏈敮浠樺彇娑堣鍗�
+        daoQuery.maxCreateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 30);
+        daoQuery.minCreateTime = new Date(daoQuery.maxCreateTime.getTime() - 1000 * 60 * 60L * 24);
+
+        return vipOrderRecordDao.list(daoQuery);
     }
 
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public VIPOrderRecord checkOrderPayState(String id) {
-        VIPOrderRecord record = vipOrderRecordDao.find(VIPOrderRecord.class, id);
-        if (record.getState() == VIPOrderRecord.STATE_PAY)
+    public OrderRecord checkOrderPayState(String id) {
+        OrderRecord record = vipOrderRecordDao.find(OrderRecord.class, id);
+        if (record.getState() == OrderRecord.STATE_PAY)
             return record;
 
         switch (record.getPayWay()) {
-            case VIPOrderRecord.PAY_WAY_ALIPAY: {
+            case OrderRecord.PAY_WAY_ALIPAY_GOLDCORN:
+            case OrderRecord.PAY_WAY_ALIPAY: {
                 //鏀粯瀹�
                 AlipayTradeQueryResponse res = null;
                 try {
@@ -285,7 +358,7 @@
                     //鏀粯鎴愬姛
                     if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) {
                         try {
-                            return paySuccess(id, VIPOrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getTotalAmount()), new Date());
+                            return paySuccess(new OrderPaySuccessForm(id, OrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getTotalAmount()), new Date()));
                         } catch (Exception e) {
                             e.printStackTrace();
                         }
@@ -296,12 +369,13 @@
             }
 
             break;
-            case VIPOrderRecord.PAY_WAY_WX: {
+            case OrderRecord.PAY_WAY_WX_GOLDCORN:
+            case OrderRecord.PAY_WAY_WX: {
                 //寰俊
                 try {
                     WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(VIPOrderUtil.getOutOrderNo(record.getOrderType(), id), VipUtil.getWXAPP());
                     if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) {
-                        paySuccess(id, record.getPayWay(), new BigDecimal(info.getAmount().getPayer_total()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR), new Date());
+                        paySuccess(new OrderPaySuccessForm(id, record.getPayWay(), new BigDecimal(info.getAmount().getPayer_total()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR), new Date()));
                         return record;
                     }
                 } catch (Exception e) {
@@ -314,30 +388,58 @@
 
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public OrderRecord checkApplePay(String orderNo, String receipt) throws Exception {
+        OrderRecord orderRecord = vipOrderRecordDao.find(OrderRecord.class, orderNo);
+        if (orderRecord == null) {
+            throw new OrderException(1, "璁㈠崟鍙蜂笉瀛樺湪");
+        }
+
+        if (!StringUtil.isNullOrEmpty(orderRecord.getAppleTransactionId())) {
+            throw new OrderException(2, "璁㈠崟宸叉敮浠�");
+        }
+
+        IOSAPPBuyVerifyResult result = IOSPayVerifyUtil.buyAppVerify(receipt, "28ca52e358b94c4eba3de41dfa7dd023", false);
+        List<IOSAPPBuyVerifyResult.OrderInfo> orderInfoList = result.getLatestReceiptInfo();
+        IOSAPPBuyVerifyResult.OrderInfo orderInfo = orderInfoList.get(0);
+        String productId = orderInfo.getProduct_id();
+        VIPPrice vipPrice = vipPriceDao.selectByIOSProductId(productId);
+        if (vipPrice == null)
+            throw new Exception("鍟嗗搧ID涓嶅瓨鍦�");
+        if (orderRecord.getType() != vipPrice.getType())
+            throw new Exception("浠锋牸绫诲瀷涓嶅尮閰�");
+//String id, int payWay, BigDecimal payMoney, Date payTime, String appleTransactionId, String appleOriginalTransactionId
+        OrderPaySuccessForm successForm = new OrderPaySuccessForm(orderRecord.getId(), OrderRecord.PAY_WAY_IAPP, new BigDecimal(0), new Date(orderInfo.getPurchaseDateMs()), orderInfo.getTransactionId(), orderInfo.getOriginalTransactionId());
+        paySuccess(successForm);
+        return null;
+    }
+
 
     @Override
-    public List<VIPOrderRecord> listOrderRecord(String uid, Integer state, int page, int pageSize) {
+    public List<OrderRecord> listOrderRecord(String uid, OrderType orderType, Integer state, int page, int pageSize) {
 
-        VIPOrderRecordDao.DaoQuery query = new VIPOrderRecordDao.DaoQuery();
+        OrderRecordDao.DaoQuery query = new OrderRecordDao.DaoQuery();
         query.start = (page - 1) * pageSize;
         query.count = pageSize;
         query.uid = uid;
         query.state = state;
-
+        query.orderType = orderType;
         return vipOrderRecordDao.list(query);
     }
 
     @Override
-    public long countOrderRecord(String uid, Integer state) {
-        VIPOrderRecordDao.DaoQuery query = new VIPOrderRecordDao.DaoQuery();
+    public long countOrderRecord(String uid, OrderType orderType, Integer state) {
+        OrderRecordDao.DaoQuery query = new OrderRecordDao.DaoQuery();
         query.uid = uid;
         query.state = state;
+        query.orderType = orderType;
         return vipOrderRecordDao.count(query);
     }
 
     @Override
-    public VIPOrderRecord getOrderRecord(String id) {
-        return vipOrderRecordDao.find(VIPOrderRecord.class, id);
+    public OrderRecord getOrderRecord(String id) {
+        return vipOrderRecordDao.find(OrderRecord.class, id);
     }
 
 
@@ -359,16 +461,18 @@
             UserVIPInfo vip = new UserVIPInfo();
             vip.setUid(uid);
             vip.setCreateTime(new Date());
-            vip.setExpireDate(getExpireTime(payTime, null, type));
+
+            Date[] expireDate = getExpireTime(payTime, null, type);
+            vip.setExpireDate(expireDate[1]);
             session.save(vip);
-            return new Date[]{payTime, vip.getExpireDate()};
+            return expireDate;
         } else {
             //淇敼
             UserVIPInfo vipInfo = (UserVIPInfo) list.get(0);
-            Date expireDate = getExpireTime(payTime, vipInfo.getExpireDate(), type);
-            session.createQuery("update UserVIPInfo i set i.expireDate=? ,i.updateTime=? where i.uid=?").setParameter(0, expireDate).setParameter(1, new Date()).setParameter(2, uid).executeUpdate();
+            Date[] expireDate = getExpireTime(payTime, vipInfo.getExpireDate(), type);
+            session.createQuery("update UserVIPInfo i set i.expireDate=? ,i.updateTime=? where i.uid=?").setParameter(0, expireDate[1]).setParameter(1, new Date()).setParameter(2, uid).executeUpdate();
 
-            return new Date[]{vipInfo.getExpireDate() == null ? new Date() : vipInfo.getExpireDate(), expireDate};
+            return expireDate;
         }
     }
 
@@ -380,13 +484,18 @@
      * @param type
      * @return
      */
-    private Date getExpireTime(Date payTime, Date expireTime, VIPPriceType type) {
+    private Date[] getExpireTime(Date payTime, Date expireTime, VIPPriceType type) {
         Calendar calendar = Calendar.getInstance();
         if (expireTime != null) {
-            calendar.setTimeInMillis(expireTime.getTime());
+            //涔嬪墠缁湡鏃堕棿鏄惁澶т簬浠樻鏃堕棿
+            if (payTime.getTime() < expireTime.getTime())
+                calendar.setTimeInMillis(expireTime.getTime());
+            else
+                calendar.setTimeInMillis(payTime.getTime());
         } else {
             calendar.setTimeInMillis(payTime.getTime());
         }
+        long startTime = calendar.getTimeInMillis();
         if (type == VIPPriceType.day) {
             calendar.add(Calendar.DAY_OF_WEEK, 1);
         } else if (type == VIPPriceType.week) {
@@ -400,7 +509,7 @@
         } else if (type == VIPPriceType.year) {
             calendar.add(Calendar.YEAR, 1);
         }
-        return new Date(calendar.getTimeInMillis());
+        return new Date[]{new Date(startTime), new Date(calendar.getTimeInMillis())};
     }
 
 

--
Gitblit v1.8.0