|
@@ -0,0 +1,63 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Threading;
|
|
|
+using System.Linq;
|
|
|
+using System.Data;
|
|
|
+using MySystem;
|
|
|
+using MySystem.PxcModels;
|
|
|
+using Library;
|
|
|
+using LitJson;
|
|
|
+
|
|
|
+public class UserMonthFeeHelper
|
|
|
+{
|
|
|
+ public readonly static UserMonthFeeHelper Instance = new UserMonthFeeHelper();
|
|
|
+ private UserMonthFeeHelper()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Start()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(DoWorks);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoWorks()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string content = RedisDbconn.Instance.RPop<string>("UserMonthFeeQueue");
|
|
|
+ if(!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ DoSomething(db);
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "创客每月月费扣款异常");
|
|
|
+ }
|
|
|
+ function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "创客每月月费扣款日志");
|
|
|
+ Thread.Sleep(60000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DoSomething(WebCMSEntities db)
|
|
|
+ {
|
|
|
+ var Users = db.UserAccount.Select(m => new { m.Id, m.BalanceAmount }).Where(m => m.BalanceAmount > 0).ToList();
|
|
|
+ foreach(var User in Users)
|
|
|
+ {
|
|
|
+ if(User.BalanceAmount > 10)
|
|
|
+ {
|
|
|
+ AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -10, 125);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -User.BalanceAmount, 125);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|