From f87850bb6c6109a3bda06ab474575631407bbf09 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期五, 01 三月 2024 19:09:12 +0800
Subject: [PATCH] 爆款活动-退款处理

---
 phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java     |   17 ++---
 phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java |   80 ++++++++++++++++----------
 phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java            |   48 ++++++++++++++-
 3 files changed, 101 insertions(+), 44 deletions(-)

diff --git a/phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java b/phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java
index 8c37ebe..3c74c7f 100644
--- a/phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java
+++ b/phi_platform_common/src/main/java/com/hx/phip/tool/order/OrderTool.java
@@ -2,11 +2,13 @@
 
 import com.hx.common.service.CommonService;
 import com.hx.mybatisTool.SqlSentence;
+import com.hx.phiappt.common.OrderTotalConstants;
 import com.hx.phiappt.model.consume.ConsumePayItem;
 import com.hx.phiappt.model.order.OrdersTotal;
 import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
 import com.hx.phip.dao.mapper.ConsumePayItemMapper;
 import com.hx.phip.dao.mapper.UserMoneyUnclaimedMapper;
+import com.hx.util.StringUtils;
 
 import java.util.HashMap;
 import java.util.List;
@@ -44,17 +46,55 @@
     }
 
     /**鑾峰彇鐢ㄦ埛娲诲姩璧犻�佽祫閲戝鍔辫褰�-鏈夋晥*/
-    public static List<UserMoneyUnclaimed> getActivityGive(String userId,String commonId, CommonService commonService){
+    public static List<UserMoneyUnclaimed> getActivityGive(String userId,String commonId,Integer isValid, CommonService commonService){
         //鏌ユ壘棰嗗彇璁板綍閲婃斁瀛樺湪
         //棰嗗彇璁板綍鏄惁宸查鍙�
         SqlSentence sqlSentence = new SqlSentence();
         Map<String,Object> values = new HashMap<>();
+        StringBuilder sql = new StringBuilder();
 
-        values.put("userId",userId);
-        values.put("commonId",commonId);
-        sqlSentence.sqlSentence("SELECT * FROM user_money_unclaimed WHERE isDel = 0 AND isValid = 1 AND userId = #{m.userId} AND commonId = #{m.commonId}",values);
+        sql.append("SELECT * FROM user_money_unclaimed WHERE isDel = 0");
+        if(isValid != null){
+            values.put("isValid",isValid);
+            sql.append(" AND isValid = #{m.isValid}");
+        }
+        if(StringUtils.noNull(userId)){
+            values.put("userId",userId);
+            sql.append(" AND userId = #{m.userId}");
+        }
+        if(StringUtils.noNull(commonId)){
+            values.put("commonId",commonId);
+            sql.append(" AND commonId = #{m.commonId}");
+        }
+        sqlSentence.sqlSentence(sql.toString(),values);
         return commonService.selectList(UserMoneyUnclaimedMapper.class,sqlSentence);
     }
 
+    /**鑾峰彇鐢ㄦ埛娲诲姩璧犻�佽祫閲戝鍔辫褰�-鑾峰彇涓�鏉�*/
+    public static UserMoneyUnclaimed getActivityGiveByOrder(OrdersTotal ordersTotal,Integer isValid, CommonService commonService){
+        //鏍规嵁褰撳墠鐢ㄦ埛锛岃幏鍙栧埌鎵�鏈夌殑璁板綍
+        //棰嗗彇璁板綍鏄惁宸查鍙�
+        SqlSentence sqlSentence = new SqlSentence();
+        Map<String,Object> values = new HashMap<>();
+        StringBuilder sql = new StringBuilder();
+
+        values.put("commonId",ordersTotal.getActivityPageCode());
+        values.put("userId",ordersTotal.getUserId());
+        values.put("payStatus", OrderTotalConstants.PAY_STATUS_SUC);
+        values.put("activityPageType", ordersTotal.getActivityPageType());
+        values.put("activityPageCode", ordersTotal.getActivityPageCode());
+        sql.append("SELECT umu.* FROM orders_total ot ");
+        sql.append(" JOIN user_money_unclaimed umu ON umu.orderId = ot.id AND umu.isDel = 0 AND umu.commonId = #{m.commonId}");
+        if(isValid != null){
+            values.put("isValid",isValid);
+            sql.append(" AND umu.isValid = #{m.isValid}");
+        }
+        sql.append(" WHERE ot.isDel = 0 AND ot.activityPageType = #{m.activityPageType} AND ot.activityPageCode = #{m.activityPageCode}" +
+                " AND ot.userId = #{m.userId} AND ot.payStatus = #{m.payStatus} ORDER BY umu.createTime ASC LIMIT 1");
+
+        sqlSentence.sqlSentence(sql.toString(),values);
+        return commonService.selectOne(UserMoneyUnclaimedMapper.class,sqlSentence);
+    }
+
 
 }
diff --git a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java
index f1595d3..3f864c5 100644
--- a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java
+++ b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/OrderRefundCancelTool.java
@@ -446,44 +446,62 @@
         //鏌ユ壘鏄惁澶勭悊浜嗚禒閫佺殑澧炲�奸噾
         SqlSentence sqlSentence = new SqlSentence();
         Map<String,Object> values = new HashMap<>();
-        values.put("isDel",102);
+        values.put("isDel",RefundUserAssets.DEL_BURST);
         values.put("orderId",refundRecord.getOrderId());
         sqlSentence.sqlSentence("SELECT * FROM refund_user_assets rua WHERE rua.isDel = #{m.isDel} AND rua.status = 1 AND rua.amountStatus IN(1,3) AND rua.orderId = #{m.orderId}",values);
         List<RefundUserAssets> refundUserAssetsList = commonService.selectList(RefundUserAssetsMapper.class,sqlSentence);
         if(refundUserAssetsList.size() == 0){
-            return;
-        }
-
-        for(RefundUserAssets refundUserAssets:refundUserAssetsList){
-            //鍒ゆ柇鏄惁宸茬粡瀛樺湪浜嗗埆鐨勮禒閫佽褰�
-            if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),commonService).size() == 0){
-                //鏄惁鏈夋墸鍑忕敤鎴疯祫浜�
-                if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){
-                    orderNodeBuilder.append("锛屾椿鍔ㄨ禒閫佸鍔犳垚鍔�");
-                    UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"閫�娆句綔搴�:娲诲姩璧犻�佽祫閲戝洖閫�浣滃簾",refundUserAssets.getOperatorId()
-                            ,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType()
-                            ,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES);
-                }else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){
-                    //鐢ㄦ埛鏈鍙栬褰曪紝杩樺師
-                    orderNodeBuilder.append("锛屾椿鍔ㄨ禒閫佺敤鎴锋湭棰嗗彇锛屼綔搴熺殑棰嗗彇璁板綍杩樺師");
-                    values.clear();
-                    values.put("id",refundUserAssets.getUserMoneyUnclaimedId());
-                    values.put("status",UserMoneyUnclaimed.STATUS_WAI);
-                    sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values);
-                    if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
-                        throw new TipsException("娲诲姩璧犻�佽祫浜ц褰曠姸鎬佸凡鍙樺寲[浣滃簾]锛�");
+            //---鏃犳搷浣滆褰�
+            //鑾峰彇鏈夋晥鐨勶紝濡傛灉鏈夛紝閭d箞灏变笉鍋氬鐞�
+            UserMoneyUnclaimed userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.YES,commonService);
+            if(userMoneyUnclaimed != null){
+                return;
+            }
+            //鑾峰彇鏃犳晥鐨勶紝濡傛灉鏈夛紝閭d箞灏辫澶勭悊瑙勫垯锛屾病鏈夊氨璺宠繃
+            userMoneyUnclaimed = OrderTool.getActivityGiveByOrder(ordersTotal,BaseEntity.NO,commonService);
+            if(userMoneyUnclaimed == null){
+                return;
+            }
+            Integer opType = BaseEntity.YES;
+            if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
+                opType = BaseEntity.NO;
+            }
+            //澧炲�奸噾鍒拌处澶勭悊
+            userMoneyUnclaimed = UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()
+                    ,ordersTotal.getId(),ordersTotal.getActivityPageCode(),userMoneyUnclaimed.getMoneyRuleId(),commonService);
+        }else{
+            //鏈夋搷浣滆褰�
+            for(RefundUserAssets refundUserAssets:refundUserAssetsList){
+                //鍒ゆ柇鏄惁宸茬粡瀛樺湪浜嗗埆鐨勮禒閫佽褰�
+                if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),BaseEntity.YES,commonService).size() == 0){
+                    //鏄惁鏈夋墸鍑忕敤鎴疯祫浜�
+                    if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){
+                        orderNodeBuilder.append("锛屾椿鍔ㄨ禒閫佸鍔犳垚鍔�");
+                        UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"閫�娆句綔搴�:娲诲姩璧犻�佽祫閲戝洖閫�浣滃簾",refundUserAssets.getOperatorId()
+                                ,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType()
+                                ,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES);
+                    }else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){
+                        //鐢ㄦ埛鏈鍙栬褰曪紝杩樺師
+                        orderNodeBuilder.append("锛屾椿鍔ㄨ禒閫佺敤鎴锋湭棰嗗彇锛屼綔搴熺殑棰嗗彇璁板綍杩樺師");
+                        values.clear();
+                        values.put("id",refundUserAssets.getUserMoneyUnclaimedId());
+                        values.put("status",UserMoneyUnclaimed.STATUS_WAI);
+                        sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values);
+                        if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
+                            throw new TipsException("娲诲姩璧犻�佽祫浜ц褰曠姸鎬佸凡鍙樺寲[浣滃簾]锛�");
+                        }
                     }
                 }
-            }
 
-            //璁板綍浣滃簾
-            values.clear();
-            values.put("id",refundUserAssets.getId());
-            values.put("status",RefundUserAssets.STATUS_CANCEL);
-            values.put("oldStatus",RefundUserAssets.STATUS_NORMAL);
-            sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
-            if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){
-                throw new TipsException("娲诲姩璧犻�佽祫浜ч��娆捐褰曠姸鎬佸凡鍙樺寲[浣滃簾]锛�");
+                //璁板綍浣滃簾
+                values.clear();
+                values.put("id",refundUserAssets.getId());
+                values.put("status",RefundUserAssets.STATUS_CANCEL);
+                values.put("oldStatus",RefundUserAssets.STATUS_NORMAL);
+                sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values);
+                if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){
+                    throw new TipsException("娲诲姩璧犻�佽祫浜ч��娆捐褰曠姸鎬佸凡鍙樺寲[浣滃簾]锛�");
+                }
             }
         }
     }
diff --git a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
index 25d96b7..b81619a 100644
--- a/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
+++ b/phi_platform_user/src/main/java/com/hx/phip/tool/refund/PartialRefundUtil.java
@@ -189,7 +189,7 @@
         }
 
         //鐖嗘娲诲姩瑙勫垯閫�娆撅紝鏆傛椂涓嶅睆钄戒繚瀛樻彁绀�
-        activityPageGiveIncrease(ordersTotal,refundRecord,operationId,0,commonService);
+        activityPageGiveIncrease(ordersTotal,refundRecord,0,commonService);
 
         //鍒濆鍖栧垵澶嶈瘖淇℃伅
         if(OrderTotalConstants.STATUS_CANCEL == ordersTotal.getStatus()){
@@ -902,11 +902,10 @@
     /**椤甸潰娲诲姩璧犻�佺殑澧炲�奸噾閫�娆惧鐞�
      * @param ordersTotal 璁㈠崟
      * @param refundRecord 閫�娆捐鍗�
-     * @param operationId 鎿嶄綔浜烘爣璇�
      * @param circulateNum 閬垮厤姝诲惊鐜紝璋冪敤鐨勬椂鍊欎紶0
      * @param commonService 鏄犲皠
      */
-    public static void activityPageGiveIncrease(OrdersTotal ordersTotal,RefundRecord refundRecord,String operationId,int circulateNum,CommonService commonService){
+    public static void activityPageGiveIncrease(OrdersTotal ordersTotal,RefundRecord refundRecord,int circulateNum,CommonService commonService){
 
         if(circulateNum > 1){
             return;
@@ -932,8 +931,8 @@
         RefundUserAssets refundUserAssets;
         //鐢熸垚璁板綍
         refundUserAssets = new RefundUserAssets();
-        //璁剧疆鏈�102鏄綋鍓嶇殑璁板綍绫诲瀷
-        refundUserAssets.setIsDel(102);
+        //璁剧疆涓�102鏄綋鍓嶇殑璁板綍绫诲瀷
+        refundUserAssets.setIsDel(RefundUserAssets.DEL_BURST);
         refundUserAssets.setType(userMoneyUnclaimed.getOperationReason());
         refundUserAssets.setStatus(RefundUserAssets.STATUS_NORMAL);
         refundUserAssets.setAmountType(userMoneyUnclaimed.getFundType());
@@ -966,7 +965,7 @@
             sqlSentence.sqlWhere("isValid = #{m.isValid} WHERE id = #{m.id} AND status = #{m.status}",values);
             if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){
                 circulateNum++;
-                activityPageGiveIncrease(ordersTotal,refundRecord,operationId,circulateNum,commonService);
+                activityPageGiveIncrease(ordersTotal,refundRecord,circulateNum,commonService);
             }
         }
         //淇濆瓨璁板綍锛屾甯告墸鍑忓拰鏈鍙栨墠鍘讳繚瀛樿繖涓褰�
@@ -980,12 +979,12 @@
         values.put("activityPageType",ordersTotal.getActivityPageType());
         values.put("activityPageCode",ordersTotal.getActivityPageCode());
         sqlSentence.sqlSentence("SELECT * FROM orders_total WHERE isDel = 0 AND status != #{m.status} AND payStatus = #{m.payStatus}" +
-                " AND id != #{m.id} AND activityPageType = #{m.activityPageType} AND activityPageCode = #{m.activityPageCode} ORDER BY createTime ASC LIMIT 1",values);
+                " AND id != #{m.id} AND activityPageType = #{m.activityPageType} AND activityPageCode = #{m.activityPageCode} ORDER BY payTime ASC LIMIT 1",values);
         OrdersTotal ordersTotal1 = commonService.selectOne(OrdersTotalMapper.class,sqlSentence);
         if(ordersTotal1 != null){
-            Integer opType = BaseEntity.NO;
+            Integer opType = BaseEntity.YES;
             if(userMoneyUnclaimed.getStatus() == UserMoneyUnclaimed.STATUS_SUCCEED){
-                opType = BaseEntity.YES;
+                opType = BaseEntity.NO;
             }
             //澧炲�奸噾鍒拌处澶勭悊
             UserMoneyUtil.setUserMoneyHandle(userMoneyUnclaimed.getUserId(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,userMoneyUnclaimed.getOpNumber(),opType, OperationReasonConstants.OP_REASON_INVITE_ORDER,userMoneyUnclaimed.getOriginSubject(),userMoneyUnclaimed.getRemarks(),userMoneyUnclaimed.getOperatorId()

--
Gitblit v1.8.0