1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Linq;
- using Microsoft.Extensions.Hosting;
- using MySystem;
- using MySystem.Models;
- using LitJson;
- using Library;
- using MySystem.Models.Main;
- public class HaoDaFeeHelper
- {
- public readonly static HaoDaFeeHelper Instance = new HaoDaFeeHelper();
- private HaoDaFeeHelper()
- {
- }
- public void Start()
- {
- Thread th = new Thread(StartDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("HaoDaFeeQueue");
- if (!string.IsNullOrEmpty(content))
- {
- SetFee(int.Parse(content));
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void SetFee(int Id)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo addinfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id);
- MerchantInfo info = db.MerchantInfo.FirstOrDefault(m => m.Id == Id);
- if(info != null && addinfo != null)
- {
- string FeeRate = addinfo.FeeRate;
- if(string.IsNullOrEmpty(FeeRate)) FeeRate = "0.38";
- string result = HaoDaHelper.Instance.SetFee(addinfo.MchtNo, FeeRate, addinfo.BrandId, addinfo.AgentName);
- JsonData jsonObj = JsonMapper.ToObject(result);
- result = result.Replace("null", "\"\"");
- int Status = 0;
- string Remark = "";
- string resultCode = jsonObj["resultCode"].ToString();
- if(resultCode != "1")
- {
- Remark = jsonObj["errorDesc"].ToString();
- }
- else
- {
- Status = 1;
- }
- db.MerchantFeeRecord.Add(new MerchantFeeRecord()
- {
- Status = Status,
- CreateDate = DateTime.Now,
- SettleFee = FeeRate,
- MerchantId = addinfo.Id,
- UserId = info.UserId,
- Remark = Remark,
- });
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "修改商户费率异常");
- }
- }
- }
|