123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using MySystem.Models.Main;
- using Library;
- using LitJson;
- using System.Threading;
- namespace MySystem
- {
- /// <summary>
- /// 好哒测试服务
- /// </summary>
- public class TestHaoDaService
- {
- public readonly static TestHaoDaService Instance = new TestHaoDaService();
- private TestHaoDaService()
- { }
- public void Start()
- {
- Thread th = new Thread(StartListen);
- th.IsBackground = true;
- th.Start();
- }
- public void StartListen()
- {
- //开户意愿申请
- // RedisDbconn.Instance.AddList("AlipayForHaoDaQueue",824);
- // RedisDbconn.Instance.AddList("WeChatForHaoDaQueue",824);
- // AlipayAddInfo(826);//提交支付宝开户意愿申请单
- // AlipayAddInfo(828,"202309011037906510");//查询支付宝开户意愿申请状态
- // WeChatAddInfo(826);//提交微信开户意愿申请单
- // WeChatAddInfo(825,"2000002424428809");//查询微信开户意愿申请状态
- // QueryMerchantStatus(867);//新建商户查询状态
- // ConfiemMer(808);//新建商户
- // ChangeMerchantCard(1);//商户修改银行卡
- // AddOpenDivideAccounts(832); //添加分账方
- // QueryAuthStatus(1845);//查询实名认证状态
- // WeChatFunctionForHD.Instance.QueryAuthMerchant("600955391");
- // AlipayFunctionForHD.Instance.AuthOrderAuthQuery("2088820718243322");
- // StartProfitShareListen();
- // HaoDaHelper.Instance.BindWeChatAppId("1490230", "21622558", AppConfig.Haoda.SubAppId);
- // HaoDaHelper.Instance.OrderDivideAccountsQuery("FZ2023110315225748140470708", "1492500"); //查询分账结果
- // WebCMSEntities db = new WebCMSEntities();
- // List<int> ids = new List<int>();
- // foreach(int id in ids)
- // {
- // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == id) ?? new ConsumerOrders();
- // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
- // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
- // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
- // string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
- // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
- // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
- // string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
- // // decimal hdfee = 0.0038M * order.PayMoney;
- // // hdfee = decimal.Parse(hdfee.ToString("f2"));
- // // decimal servicefee = 0.01M * order.PayMoney;
- // // servicefee = decimal.Parse(servicefee.ToString("f2"));
- // // decimal amount = order.PayMoney - hdfee - servicefee;
- // // amount = amount * 100; //金额(分)
- // // servicefee = servicefee * 100;
- // // string seviceAmount = servicefee.ToString("f0"); //服务费
- // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, "1", "0"));
- // }
- // string content = function.ReadInstance("content.txt");
- // string[] list = content.Split('\n');
- // foreach(string sub in list)
- // {
- // JsonData jsonObj = JsonMapper.ToObject(sub);
- // string orderNo = jsonObj["orderNo"].ToString();
- // JsonData detail = jsonObj["detail"];
- // string me = detail[0]["amount"].ToString();
- // string mer = detail[1]["amount"].ToString();
- // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
- // if(order.SettleAmount > 0)
- // {
- // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
- // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
- // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
- // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
- // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
- // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
- // decimal settleAmount = (decimal)order.SettleAmount / 100M;
- // decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
- // divideAmt = decimal.Parse(divideAmt.ToString("f2"));
- // decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
- // hdfee = decimal.Parse(hdfee.ToString("f2"));
- // decimal servicefee = 0.01M * order.PayMoney - hdfee;
- // servicefee = decimal.Parse(servicefee.ToString("f2"));
- // decimal amount = order.PayMoney*(1-0.0038M) - servicefee;
- // amount = decimal.Parse(amount.ToString("f2"));
- // decimal otherAmt = settleAmount - servicefee - amount;
- // if(otherAmt != 0)
- // {
- // amount += otherAmt;
- // }
- // amount -= decimal.Parse(mer) / 100M;
- // servicefee -= decimal.Parse(me) / 100M;
- // if(amount > 0)
- // {
- // if(servicefee < 0) servicefee = 0;
- // amount = amount * 100 - 1; //金额(分)
- // servicefee = servicefee * 100;
- // string seviceAmount = servicefee.ToString("f0"); //服务费
- // string amountAmount = amount.ToString("f0");
- // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
- // }
- // }
- // }
- // List<string> list = new List<string>();
- // list.Add("{\"orderNo\":\"G2231124C02180937731\",\"settle\":\"29687\",\"part\":\"29575\"}");
- // foreach(string sub in list)
- // {
- // JsonData jsonObj = JsonMapper.ToObject(sub);
- // string orderNo = jsonObj["orderNo"].ToString();
- // string settle = jsonObj["settle"].ToString();
- // string part = jsonObj["part"].ToString();
- // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
- // if(order.SettleAmount > 0)
- // {
- // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
- // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
- // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
- // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
- // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
- // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
- // decimal settleamount = decimal.Parse(settle);
- // decimal partamount = decimal.Parse(part);
- // decimal amount = settleamount - partamount;
- // if(amount > 0)
- // {
- // decimal servicefee = amount / 100M;
- // servicefee = decimal.Parse(servicefee.ToString("f0"));
- // amount -= servicefee;
- // string seviceAmount = servicefee.ToString("f0"); //服务费
- // string amountAmount = amount.ToString("f0");
- // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
- // }
- // }
- // }
- // db.Dispose();
- }
- public void StartProfitShareListen()
- {
- bool op = true;
- while (op)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- var list = db.ConsumerOrders.Where(m => m.Status == 1 && m.IsAct == 0).OrderByDescending(m => m.Id).ToList();
- foreach (var sub in list)
- {
- ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
- if (order != null)
- {
- int Status = 2;
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
- MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
- MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
- //发起分账
- string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
- string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
- string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
- string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
- string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
- string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
- decimal amount = order.PayMoney * (1M - 0.0038M) * 100;
- string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amount.ToString().Split('.')[0], "0"));
- if (result.Contains("\"resultCode\":\"0\"") && result.Contains("分账金额不足"))
- {
- Status = 1;
- }
- order.Status = Status;
- }
- }
- db.SaveChanges();
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒分账队列异常");
- }
- Thread.Sleep(2000);
- }
- }
- //新建商户查询状态
- public void QueryMerchantStatus(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- var BrhCode = HaodaUnionParam.BrhCode;
- if (AddInfo.BrandId == 1) BrhCode = HaodaParam.BrhCode;
- var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, AddInfo.MchtNo);
- // string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
- db.Dispose();
- }
- //提交支付宝开户意愿申请单
- public void AlipayAddInfo(int Id)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
- JsonData jsonObj = JsonMapper.ToObject(result);
- Dictionary<string, object> reqdic = new Dictionary<string, object>();
- reqdic.Add("Id", Id); // 商户Id
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
- LogHelper.Instance.WriteLog(req, "提交支付宝商户意愿申请单");
- Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
- string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
- LogHelper.Instance.WriteLog("请求参数\n" + req, "提交支付宝商户意愿申请单");
- LogHelper.Instance.WriteLog(result, "提交支付宝商户意愿申请单");
- if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
- {
- LogHelper.Instance.WriteLog("success", "提交支付宝商户意愿申请单");
- string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
- // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
- LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
- }
- else
- {
- LogHelper.Instance.WriteLog("false", "提交支付宝商户意愿申请单");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
- LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
- }
- }
- //查询支付宝开户意愿申请状态
- public void AlipayAddInfo(int Id, string OrderNo)
- {
- try
- {
- LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
- JsonData jsonObj = JsonMapper.ToObject(result);
- Dictionary<string, object> reqdic = new Dictionary<string, object>();
- reqdic.Add("Id", Id); // 商户Id
- reqdic.Add("OrderNo", OrderNo); // 商户Id
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
- LogHelper.Instance.WriteLog(req, "查询支付宝商户意愿申请状态");
- Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
- string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
- LogHelper.Instance.WriteLog("请求参数\n" + req, "查询支付宝商户意愿申请状态");
- LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
- if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
- {
- LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
- string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
- if (order_status == "CONTACT_CONFIRM")
- {
- LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = 1;
- merchant.QueryCount = 1;
- info.AlipayRemark = "";
- info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
- db.SaveChanges();
- // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
- LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
- }
- else if (order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
- {
- LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
- LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
- db.SaveChanges();
- }
- else if (order_status == "AUDIT_PASS")
- {
- LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = 2;
- merchant.QueryCount = 2;
- info.AlipayRemark = "";
- LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
- if (merchant.Latitude == 0)
- {
- //签约成功调用腾讯地图接口获取地址
- RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
- }
- db.SaveChanges();
- }
- // else
- // {
- // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
- // }
- }
- else
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
- }
- }
- //提交微信开户意愿申请单
- public void WeChatAddInfo(int Id)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = WeChatFunctionForHD.Instance.MerchantApply(info);
- Dictionary<string, object> reqdic = new Dictionary<string, object>();
- reqdic.Add("Id", Id); // 商户Id
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
- LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
- Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
- string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
- LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
- LogHelper.Instance.WriteLog(result, "提交微信商户意愿申请单");
- if (result.Contains("\"applyment_id\":"))
- {
- LogHelper.Instance.WriteLog("success", "提交微信商户意愿申请单");
- JsonData json = JsonMapper.ToObject(result);
- string applyment_id = json["applyment_id"].ToString();
- // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
- LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
- }
- else if (result.Contains("\"message\":"))
- {
- LogHelper.Instance.WriteLog("false", "提交微信商户意愿申请单");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- JsonData jsonObj = JsonMapper.ToObject(result);
- info.Status = -1;
- merchant.Status = -1;
- info.WeChatRemark = jsonObj["message"].ToString();
- LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
- }
- }
- //查询微信开户意愿申请状态
- public void WeChatAddInfo(int Id, string ApplymentId)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
- Dictionary<string, object> reqdic = new Dictionary<string, object>();
- reqdic.Add("Id", Id); // 商户Id
- reqdic.Add("ApplymentId", ApplymentId); // 商户Id
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
- LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
- Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
- string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
- LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
- JsonData jsonObj = JsonMapper.ToObject(result);
- if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.Status = 1;
- merchant.Status = 1;
- info.WeChatRemark = "";
- info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
- db.SaveChanges();
- // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
- }
- else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.Status = -1;
- merchant.Status = -1;
- info.WeChatRemark = jsonObj["reject_reason"].ToString();
- db.SaveChanges();
- }
- // else
- // {
- // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
- // }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
- }
- }
- //添加分账接收方账户
- public void AddOpenDivideAccounts(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- string result = HaoDaHelper.Instance.AddOpenDivideAccounts(AddOpenDivideAccountsUtil.AddValue(AddInfo));
- db.Dispose();
- }
- public void ConfiemMer(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
- if (AddInfo != null && merchant != null)
- {
- string BusinessCode = AddInfo.BusinessCode;
- if (string.IsNullOrEmpty(BusinessCode))
- {
- BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
- AddInfo.BusinessCode = BusinessCode;
- }
- string pwd = AddInfo.MobilePhone.Substring(5);
- merchant.LoginPwd = function.MD532(pwd);
- MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
- if (query == null)
- {
- query = new MerchantParamSet();
- query.IsAll = 1;
- db.MerchantParamSet.Add(query);
- db.SaveChanges();
- }
- MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
- if (merchantForMobile == null)
- {
- merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
- {
- Mobile = AddInfo.MobilePhone,
- }).Entity;
- db.SaveChanges();
- }
- merchantForMobile.MerchantId = MerchantId;
- db.SaveChanges();
- Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == AddInfo.MobilePhone);
- if (info == null)
- {
- info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
- {
- LoginMobile = AddInfo.MobilePhone,
- }).Entity;
- db1.SaveChanges();
- }
- info.LoginPwd = function.MD532(pwd);
- db1.SaveChanges();
- Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == MerchantId && m.Kind == 2);
- if (infolink == null)
- {
- infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
- {
- LoginId = info.Id,
- MerchantId = MerchantId,
- Kind = 2,
- }).Entity;
- db1.SaveChanges();
- }
- if (AddInfo.Status <= 0)
- {
- //好哒新建商户
- string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
- JsonData jsonObj = JsonMapper.ToObject(result);
- //创建成功
- if (jsonObj["resultCode"].ToString() == "1")
- {
- AddInfo.WeChatRemark = "";
- if (string.IsNullOrEmpty(AddInfo.MchtNo))
- {
- AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
- }
- AddInfo.Status = 0;
- merchant.Status = 0;
- db.SaveChanges();
- QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
- queryMerchantStatus.MerchantId = MerchantId.ToString();
- queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
- // RedisDbconn.Instance.AddList("WeChatSignHdQueue", queryMerchantStatus);
- }
- //创建失败
- else
- {
- AddInfo.Status = -1;
- merchant.Status = -1;
- AddInfo.WeChatRemark = jsonObj["errorDesc"].ToString();
- // if (string.IsNullOrEmpty(AddInfo.MchtNo))
- // {
- // if (jsonObj.ToJson().Contains("mchtNo"))
- // {
- // AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
- // }
- // }
- db.SaveChanges();
- }
- }
- }
- db.Dispose();
- db1.Dispose();
- }
- //商户开通分账
- public void OpenDivideAccounts(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- string result = HaoDaHelper.Instance.OpenDivideAccounts(AddInfo.OutMchtNo, AddInfo.StoreNo);
- db.Dispose();
- }
- //分账接收方签约
- public void DivideAccountsSign(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- string result = HaoDaHelper.Instance.DivideAccountsSign("230817000000000278", AddInfo.OutMchtNo, AddInfo.StoreNo);
- db.Dispose();
- }
- //查询实名认证状态
- public void QueryAuthStatus(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- string result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
- db.Dispose();
- }
- //商户修改银行卡
- public void ChangeMerchantCard(int MerchantId)
- {
- WebCMSEntities db = new WebCMSEntities();
- // MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
- // var request = TestChangeMerchantCardSetUtil.SetValue(AddInfo);
- // JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.ChangeMerchantCard(request));
- // JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["taskId"].ToString()));
- //TODO:修改结算卡变更商户相关信息
- // AccountNumber
- // BankName
- // BankBranchId
- // BankAddressCode
- // BankAccountType
- // OpenUnionNo
- // OpenCollectBankCode
- // OpenBankRegionCode
- // OpenBankAccout
- // OpenBankAccName
- // ZbankRegionCode
- // ZBankNo
- db.Dispose();
- }
- public void refund()
- {
- Thread th = new Thread(refunddo);
- th.IsBackground = true;
- th.Start();
- }
- public void refunddo()
- {
- for (int month = 10; month <= 11; month++)
- {
- for (int day = 1; day <= 31; day++)
- {
- string content = function.ReadInstance("/log/好哒聚合支付退款/2023/" + month + "/" + day + "/content.log");
- if (!string.IsNullOrEmpty(content))
- {
- content = content.Replace("\n\n\n", "####");
- content = content.Replace("\n", "");
- content = content.Replace("####", "\n");
- MatchCollection mc = Regex.Matches(content, "请求参数.*?退款次数超出限制");
- foreach (Match m in mc)
- {
- string mchtNo = Regex.Match(m.Value, "\"mchtNo\":\".*?\"").Value.Replace("\"mchtNo\":\"", "").Replace("\"", "");
- string storeNo = Regex.Match(m.Value, "\"storeNo\":\".*?\"").Value.Replace("\"storeNo\":\"", "").Replace("\"", "");
- string outOrderNo = Regex.Match(m.Value, "\"outOrderNo\":\".*?\"").Value.Replace("\"outOrderNo\":\"", "").Replace("\"", "");
- string refundAmount = Regex.Match(m.Value, "\"refundAmount\":\".*?\"").Value.Replace("\"refundAmount\":\"", "").Replace("\"", "");
- function.WriteLog("mchtNo:" + mchtNo + ";storeNo:" + storeNo + ";outOrderNo:" + outOrderNo + ";refundAmount:" + refundAmount + ";", "补充退款日志");
- var info = HaoDaHelper.Instance.AggregatedPayRefund(mchtNo, storeNo, "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), outOrderNo, refundAmount);
- function.WriteLog(info + "\n\n", "补充退款日志");
- Thread.Sleep(1000);
- }
- }
- }
- }
- }
- }
- }
|