123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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);
- }
- }
- }
- }
|