lcl 1 gadu atpakaļ
vecāks
revīzija
54b5b667d7
1 mainītis faili ar 15 papildinājumiem un 31 dzēšanām
  1. 15 31
      AppStart/Helper/SycnProfitServiceV3.cs

+ 15 - 31
AppStart/Helper/SycnProfitServiceV3.cs

@@ -61,56 +61,38 @@ namespace MySystem
         private void DoTradeProfit(int BrandId, string date, string SysUserName)
         {
             WebCMSEntities db = new WebCMSEntities();
-            OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
             string StartId = function.ReadInstance("/PublicParams/ProfitRewardRecordId" + date + ".txt");
             if(string.IsNullOrEmpty(StartId))
             {
                 StartId = "0";
             }
-            OtherMySqlConn.op("insert into ProfitRecord (CreateDate,CreateMan,SeoTitle,BrandId,UserId,DirectFlag,ProfitAmount) select now(),'root','" + date + "'," + BrandId + ",UserId,ProfitType,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord p where Id>=" + StartId + " and CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "' group by UserId,ProfitType order by UserId");
-
-            DataTable dt = OtherMySqlConn.dtable("select UserId,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord where Id>=" + StartId + " and CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "' group by UserId");
-            function.WriteLog("分润:" + BrandId + ":" + dt.Rows.Count, "同步分润数据");
-            int index = 0;
-            foreach (DataRow dr in dt.Rows)
-            {
-                index += 1;
-                int UserId = int.Parse(dr["UserId"].ToString());
-                decimal ProfitMoney = decimal.Parse(dr[1].ToString());
-                try
-                {
-                    string content = UserId + "|" + BrandId + "|" + ProfitMoney + "|" + index;
-                    RedisDbconn.Instance.AddList("DoTradeProfitQueue", content);
-                }
-                catch (Exception ex)
-                {
-                    function.WriteLog(DateTime.Now.ToString() + "\n" + UserId + "," + ProfitMoney + "\n" + ex.ToString(), "同步到余额异常");
-                }
-                function.WriteLog(index.ToString(), "同步分润数据");
-            }
-            OtherMySqlConn.op("update ProfitRewardRecord set CheckStatus=1 where Id>=" + StartId + " and CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "'");
+            CustomerSqlConn.op("insert into ProfitRecord (CreateDate,CreateMan,SeoTitle,BrandId,UserId,DirectFlag,ProfitAmount) select now(),'root','" + date + "'," + BrandId + ",UserId,ProfitType,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord p where Id>=" + StartId + " and CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "' group by UserId,ProfitType order by UserId", MysqlConn.connstr);
+            
+            CustomerSqlConn.op("update ProfitRewardRecord set CheckStatus=1 where Id>=" + StartId + " and CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "'", MysqlConn.connstr);
 
             db.Dispose();
-            dt.Dispose();
-
-            RedisDbconn.Instance.AddList("DoTradeProfitQueue", "end");
-            SycnProfitServiceV2.Instance.StartProfit();
         }
         private void DoTradeProfit2(int BrandId, string date, string SysUserName)
         {
-            CustomerSqlConn.op("insert into UserAccountRecord (CreateDate,UpdateDate,UserId,ProductType,ChangeType,ChangeAmount,Remark) select now() CreateDate,now() UpdateDate,UserId," + BrandId + " ProductType,1 ChangeType,ProfitAmount,(case when DirectFlag=1 then '直拓商户分润' else '品牌推广服务费' end) Remark from ProfitRecord where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0 order by Id", MysqlConn.connstr);
-
-            CustomerSqlConn.op("update ProfitRecord set Version=1 where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0", MysqlConn.connstr);
+            // CustomerSqlConn.op("insert into UserAccountRecord (CreateDate,UpdateDate,UserId,ProductType,ChangeType,ChangeAmount,Remark) select now() CreateDate,now() UpdateDate,UserId," + BrandId + " ProductType,301 ChangeType,ProfitAmount,(case when DirectFlag=1 then '直拓商户分润' else '品牌推广服务费' end) Remark from ProfitRecord where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0 order by Id", MysqlConn.connstr);
 
             string start = date.Substring(0, 4) + "-" + date.Substring(4) + "-01 00:00:00";
             string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
             string sql = "";
-            DataTable dt = CustomerSqlConn.dtable("select UserId,sum(ChangeAmount) from UserAccountRecord where CreateDate>='" + start + "' and CreateDate<'" + end + "' group by UserId", MysqlConn.connstr);
+            DataTable dt = CustomerSqlConn.dtable("select UserId," + BrandId + " ProductType,301 ChangeType,ProfitAmount,(case when DirectFlag=1 then '直拓商户分润' else '品牌推广服务费' end) Remark from ProfitRecord where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0 order by Id", MysqlConn.connstr);
             int num = 0;
             foreach(DataRow dr in dt.Rows)
             {
+                string CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                string UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                string UserId = dr["UserId"].ToString();
+                string ProductType = dr["ProductType"].ToString();
+                string ChangeType = dr["ChangeType"].ToString();
+                string ChangeAmount = dr["ProfitAmount"].ToString();
+                string Remark = dr["Remark"].ToString();
                 num += 1;
                 sql += "update UserAccount set BalanceAmount=BalanceAmount+" + dr[1].ToString() + ",TotalAmount=TotalAmount+" + dr[1].ToString() + " where Id=" + dr["UserId"].ToString() + ";";
+                sql += "insert into UserAccountRecord (CreateDate,UpdateDate,UserId,ProductType,ChangeType,ChangeAmount,Remark) values ('" + CreateDate + "','" + UpdateDate + "'," + UserId + "," + ProductType + "," + ChangeType + "," + ChangeAmount + ",'" + Remark + "');";
                 if(num >= 20)
                 {
                     CustomerSqlConn.op(sql, MysqlConn.kxsconnstr);
@@ -122,6 +104,8 @@ namespace MySystem
             {
                 CustomerSqlConn.op(sql, MysqlConn.kxsconnstr);
             }
+
+            CustomerSqlConn.op("update ProfitRecord set Version=1 where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0", MysqlConn.connstr);
         }
 
         #region