1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.PxcModels;
- using Library;
- using LitJson;
- namespace MySystem
- {
- public class BalancePayBackService
- {
- public readonly static BalancePayBackService Instance = new BalancePayBackService();
- private BalancePayBackService()
- { }
- public void Start()
- {
- Thread th = new Thread(dosomething);
- th.IsBackground = true;
- th.Start();
- }
-
- private void dosomething()
- {
- while (true)
- {
- try
- {
- string content = RedisDbconn.Instance.RPop<string>("BalancePayQueue");
- if (!string.IsNullOrEmpty(content))
- {
- sloveAlipayCallBack(content);
- }
- else
- {
- Thread.Sleep(2000);
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单余额支付异常");
- Thread.Sleep(2000);
- }
- }
- }
- public void sloveAlipayCallBack(string content)
- {
- int OrderId = int.Parse(function.CheckInt(content));
- WebCMSEntities db = new WebCMSEntities();
- AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
- Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 3 && m.PayStatus == 1);
- if(order != null)
- {
- UserAccount account = db.UserAccount.FirstOrDefault(m=>m.Id == order.UserId);
- if(account != null)
- {
- account.FreezeAmount -= order.TotalPrice;
- db.SaveChanges();
- }
- }
- db.Dispose();
- }
- }
- }
|