浏览代码

同步维权订单

dodo hold 2 年之前
父节点
当前提交
06b5f7ce58

文件差异内容过多而无法显示
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 13 - 0
molilian.core/DTO/alimama/TkReportDTO.cs

@@ -127,6 +127,19 @@
         public int order_ord_num_13 { get; set; } = 0;
         public int order_ord_num_14 { get; set; } = 0;
 
+        public decimal refund_order_ord_amt { get; set; } = 0;
+        public decimal refund_order_ord_tfee { get; set; } = 0;
+        public int refund_order_ord_num { get; set; } = 0;
+
+        public decimal refund_order_ord_amt_4 { get; set; } = 0;
+        public decimal refund_order_ord_tfee_4 { get; set; } = 0;
+        public int refund_order_ord_num_4 { get; set; } = 0;
+
+        
+        public decimal refund_order_ord_deduct_tfee { get; set; } = 0;
+        public decimal refund_order_ord_freeze_tfee { get; set; } = 0;
+        public decimal refund_order_ord_unfreeze_tfee { get; set; } = 0;
+
 
         public int total_count { get; set; } = 0;
         public int abandon_count { get; set; } = 0;

+ 188 - 134
molilian.core/Plus/Alimama/RefundOrders.cs

@@ -39,76 +39,102 @@ namespace molilian.core
             //当日往前查询
             (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkRefundOrders(startTime, endTime, DateTime.MinValue, false, sleep);
 
-
             //#endif       
 
-            //            string sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
-            //        COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num, 
-            //    tr.order_ord_tfee = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_12 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_13 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_14 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"UPDATE tk_report 
-            //SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
-            // WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+            string sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(tbTradeCreateTime) AS date, SUM(refundFee) AS refund_order_ord_amt,
+                    COUNT(*) AS refund_order_ord_num, SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(tbTradeCreateTime) IN @orderTimes AND refundStatus=2 AND accountId=@accountId
+                GROUP BY DATE(tbTradeCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_amt = sub.refund_order_ord_amt, 
+                tr.refund_order_ord_tfee = sub.refund_order_ord_tfee, 
+                tr.refund_order_ord_num = sub.refund_order_ord_num;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(tbTradeCreateTime) AS date, SUM(refundFee) AS refund_order_ord_amt,
+                    COUNT(*) AS refund_order_ord_num, SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(tbTradeCreateTime) IN @orderTimes AND refundStatus=4 AND accountId=@accountId
+                GROUP BY DATE(tbTradeCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_amt_4 = sub.refund_order_ord_amt, 
+                tr.refund_order_ord_tfee_4 = sub.refund_order_ord_tfee, 
+                tr.refund_order_ord_num_4 = sub.refund_order_ord_num;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundCreateTime) AS date, 
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundCreateTime) IN @orderTimes AND accountId=@accountId
+                GROUP BY DATE(RefundCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_freeze_tfee = 0-sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundFinishTime) AS date,
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundFinishTime) IN @orderTimes AND refundStatus=2 AND accountId=@accountId
+                GROUP BY DATE(RefundFinishTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_deduct_tfee = 0-sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundFinishTime) AS date,
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundFinishTime) IN @orderTimes AND refundStatus IN (2,3) AND accountId=@accountId
+                GROUP BY DATE(RefundFinishTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_unfreeze_tfee = sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+
+            //refundStatus3  失败
+            //2 成功
+            //4创建
+
+            //public decimal refund_order_ord_deduct_tfee { get; set; } = 0;
+            //public decimal refund_order_ord_freeze_tfee { get; set; } = 0;
+            //public decimal refund_order_ord_unfreeze_tfee { get; set; } = 0;
+
+
 
-            return total;
 
+            return total;
         }
         public int GetIncyRefundOrders(int sleep)
         {
@@ -140,72 +166,86 @@ namespace molilian.core
                 RedisHelper.Set(cacheKey, max_modifiedTime);
             }
 
-            //todo 根据orderTimes、settlementTimes 更新被影响的相关行 
-
-            //            string sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
-            //        COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num, 
-            //    tr.order_ord_tfee = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_12 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_13 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"
-            //UPDATE tk_report tr
-            //JOIN (
-            //    SELECT
-            //        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
-            //        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
-            //    FROM tk_order_details
-            //    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
-            //    GROUP BY DATE(tbPaidTime), accountId
-            //) AS sub
-            //ON tr.accountId = sub.accountId AND tr.report_date = sub.date
-            //SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num, 
-            //    tr.order_ord_tfee_14 = sub.order_ord_tfee;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
-
-            //            sql = @"UPDATE tk_report 
-            //SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
-            // WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
-            //            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+            string sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(tbTradeCreateTime) AS date, SUM(refundFee) AS refund_order_ord_amt,
+                    COUNT(*) AS refund_order_ord_num, SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(tbTradeCreateTime) IN @orderTimes AND refundStatus=2 AND accountId=@accountId
+                GROUP BY DATE(tbTradeCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_amt = sub.refund_order_ord_amt, 
+                tr.refund_order_ord_tfee = sub.refund_order_ord_tfee, 
+                tr.refund_order_ord_num = sub.refund_order_ord_num;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(tbTradeCreateTime) AS date, SUM(refundFee) AS refund_order_ord_amt,
+                    COUNT(*) AS refund_order_ord_num, SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(tbTradeCreateTime) IN @orderTimes AND refundStatus=4 AND accountId=@accountId
+                GROUP BY DATE(tbTradeCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_amt_4 = sub.refund_order_ord_amt, 
+                tr.refund_order_ord_tfee_4 = sub.refund_order_ord_tfee, 
+                tr.refund_order_ord_num_4 = sub.refund_order_ord_num;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundCreateTime) AS date, 
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundCreateTime) IN @orderTimes AND accountId=@accountId
+                GROUP BY DATE(RefundCreateTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_freeze_tfee = 0-sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundFinishTime) AS date,
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundFinishTime) IN @orderTimes AND refundStatus=2 AND accountId=@accountId
+                GROUP BY DATE(RefundFinishTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_deduct_tfee = 0-sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
+
+            sql = @"
+            UPDATE tk_report tr
+            JOIN (
+                SELECT
+                    accountId, DATE(RefundFinishTime) AS date,
+                    SUM(showReturnFee) AS refund_order_ord_tfee
+                FROM tk_refund_order_details
+                WHERE DATE(RefundFinishTime) IN @orderTimes AND refundStatus IN (2,3) AND accountId=@accountId
+                GROUP BY DATE(RefundFinishTime), accountId
+            ) AS sub
+            ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+            SET tr.refund_order_ord_unfreeze_tfee = sub.refund_order_ord_tfee;";
+            DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
+
 
             return total;
         }
@@ -323,7 +363,6 @@ namespace molilian.core
 
                 try
                 {
-
                     foreach (var order in data.ElementRead("result").EnumerateArray())
                     {
                         TkRefundOrderDetailDTO item = order.GetRawText().Convert2Object<TkRefundOrderDetailDTO>();
@@ -340,7 +379,22 @@ namespace molilian.core
                         }
 
                         //进行订单和转链匹配
-                        orderTimes.Add(item.RefundCreateTime.Date);
+                        orderTimes.Add(item.TbTradeCreateTime.Date);
+                        switch (item.RefundStatus)
+                        {
+                            case 4:
+                                orderTimes.Add(item.RefundCreateTime.Date);
+                                break;
+                            case 2:
+                            case 3:
+                                orderTimes.Add(item.RefundFinishTime.Date);
+                                break;
+                        }
+
+                        if (item.ShowReturnFee == 0)
+                        {
+                            item.ShowReturnFee = Math.Round(item.PubShareFee / item.AlipayTotalPrice * item.RefundFee, 2);
+                        }
                         int? id = conn.Replace(item);
                         if (id != null)
                         {

部分文件因为文件数量过多而无法显示