HomeController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using MySystem.PxcModels;
  10. using System.Threading;
  11. using Library;
  12. using LitJson;
  13. using System.Security.Cryptography;
  14. namespace MySystem.Controllers
  15. {
  16. public class HomeController : Controller
  17. {
  18. private readonly ILogger<HomeController> _logger;
  19. public HomeController(ILogger<HomeController> logger)
  20. {
  21. _logger = logger;
  22. }
  23. public IActionResult Index()
  24. {
  25. return View();
  26. }
  27. public IActionResult Error()
  28. {
  29. string isapi = Request.Headers["Api"].ToString();
  30. if (isapi != "1")
  31. {
  32. if (Response.StatusCode == 500)
  33. {
  34. return Redirect("/public/errpage/pc/500.html");
  35. }
  36. else if (Response.StatusCode == 502)
  37. {
  38. return Redirect("/public/errpage/pc/502.html");
  39. }
  40. else if (Response.StatusCode == 404)
  41. {
  42. return Redirect("/public/errpage/pc/404.html");
  43. }
  44. }
  45. return View();
  46. }
  47. // 大盟主标记扫描
  48. public string leaderflag()
  49. {
  50. WebCMSEntities db = new WebCMSEntities();
  51. List<int> ids = new List<int>();
  52. // List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 597).ToList();
  53. // foreach(PosCouponRecord record in records)
  54. // {
  55. // ids.Add(record.PosCouponId);
  56. // }
  57. ids.Add(6843);
  58. List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
  59. foreach (PosCoupons coupon in coupons)
  60. {
  61. PosSns.Add(coupon.ExchangeCode);
  62. }
  63. foreach (PosCoupons coupon in coupons)
  64. {
  65. ChildNo(db, coupon.ExchangeCode, coupon.ExchangeCode, coupon.LeaderUserId);
  66. }
  67. // db.SaveChanges();
  68. db.Dispose();
  69. return "ok";
  70. }
  71. List<string> nos = new List<string>();
  72. private void ChildNo(WebCMSEntities db, string RootCheckNo, string CheckNo, int LeaderUserId)
  73. {
  74. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
  75. if(apply != null)
  76. {
  77. int len = 0;
  78. string[] SnList = apply.SwapSnExpand.TrimEnd('\n').Split('\n');
  79. foreach(string sn in SnList)
  80. {
  81. if(PosSns.Contains(sn.Split(':')[0]) || nos.Contains(sn.Split(':')[0]))
  82. {
  83. len += 1;
  84. }
  85. }
  86. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  87. if(order != null)
  88. {
  89. if(!string.IsNullOrEmpty(order.SnNos))
  90. {
  91. if(order.SnNos.Contains(","))
  92. {
  93. string[] SwapSnExpands = order.SnNos.TrimEnd(',').Split(',');
  94. int index = 0;
  95. foreach(string no in SwapSnExpands)
  96. {
  97. if(!nos.Contains(no) && index < len)
  98. {
  99. index += 1;
  100. nos.Add(no);
  101. ChildNo(db, RootCheckNo, no, LeaderUserId);
  102. }
  103. }
  104. }
  105. else
  106. {
  107. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  108. int index = 0;
  109. foreach(string no in SwapSnExpands)
  110. {
  111. if(!nos.Contains(no) && index < len)
  112. {
  113. index += 1;
  114. nos.Add(no);
  115. ChildNo(db, RootCheckNo, no, LeaderUserId);
  116. }
  117. }
  118. }
  119. }
  120. else
  121. {
  122. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  123. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  124. if(pos != null)
  125. {
  126. // pos.LeaderUserId = LeaderUserId;
  127. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
  128. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  129. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  130. }
  131. }
  132. }
  133. }
  134. else
  135. {
  136. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  137. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  138. if(pos != null)
  139. {
  140. // pos.LeaderUserId = LeaderUserId;
  141. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  142. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  143. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  144. }
  145. }
  146. }
  147. List<string> PosSns = new List<string>();
  148. public string ScanNos()
  149. {
  150. PosSns = new List<string>();
  151. PosSns.Add("00005002681889125851");
  152. WebCMSEntities db = new WebCMSEntities();
  153. foreach(string PosSn in PosSns)
  154. {
  155. ChildNo(db, PosSn, PosSn, 0);
  156. }
  157. db.Dispose();
  158. return "ok";
  159. }
  160. public string test()
  161. {
  162. OpModels.WebCMSEntities db = new OpModels.WebCMSEntities();
  163. List<int> ids = new List<int>();
  164. List<OpModels.ChangeTypes> typelist = db.ChangeTypes.ToList();
  165. List<OpModels.AmountRecord> list = db.AmountRecord.OrderBy(m => m.Id).ToList();
  166. int index = 0;
  167. foreach(OpModels.AmountRecord sub in list)
  168. {
  169. index += 1;
  170. if(!ids.Contains(sub.Id))
  171. {
  172. int OperateType = sub.OperateType;
  173. OpModels.ChangeTypes type = typelist.FirstOrDefault(m => m.Name == sub.SeoDescription) ?? new OpModels.ChangeTypes();
  174. decimal UseAmount = sub.UseAmount;
  175. decimal UseTotalAmt = 0;
  176. decimal UseValidForGetAmount = 0;
  177. decimal UseValidAmount = 0;
  178. if(type.Name == "商城购机" || type.Name == "购买小盟主" || type.Name == "购买运营中心")
  179. {
  180. UseTotalAmt = UseAmount;
  181. UseValidForGetAmount = UseAmount;
  182. OpModels.AmountRecord same = db.AmountRecord.FirstOrDefault(m => m.UserId == sub.UserId && m.CreateDate >= sub.CreateDate && m.CreateDate <= sub.CreateDate.Value.AddSeconds(5) && m.UseAmount == UseAmount && m.SeoDescription == sub.SeoDescription && m.OperateType == 1) ?? new OpModels.AmountRecord();
  183. ids.Add(same.Id);
  184. OperateType = 0;
  185. }
  186. else
  187. {
  188. if(sub.Version == 1)
  189. {
  190. UseTotalAmt = UseAmount;
  191. }
  192. else if(sub.Version == 2)
  193. {
  194. UseValidForGetAmount = UseAmount;
  195. }
  196. else if(sub.Version == 3)
  197. {
  198. UseValidAmount = UseAmount;
  199. }
  200. else
  201. {
  202. if(OperateType == 1)
  203. {
  204. UseTotalAmt = UseAmount;
  205. }
  206. else
  207. {
  208. UseTotalAmt = -UseAmount;
  209. }
  210. }
  211. }
  212. OpModels.AmountRecordNew add = db.AmountRecordNew.Add(new OpModels.AmountRecordNew()
  213. {
  214. CreateDate = sub.CreateDate,
  215. UpdateDate = sub.UpdateDate,
  216. ChangeTypeId = type.Id,
  217. Remark = sub.SeoDescription,
  218. AfterValidForGetAmount = sub.AfterValidForGetAmount,
  219. AfterTotalAmt = sub.AfterTotalAmt,
  220. AfterValidAmount = sub.AfterValidAmount,
  221. OperateType = OperateType,
  222. AfterAmount = sub.AfterAmount,
  223. BeforeAmount = sub.BeforeAmount,
  224. UseAmount = UseAmount,
  225. UserId = sub.UserId,
  226. UseValidForGetAmount = UseValidForGetAmount,
  227. UseTotalAmt = UseTotalAmt,
  228. UseValidAmount = UseValidAmount,
  229. }).Entity;
  230. if(index % 100 == 0)
  231. {
  232. db.SaveChanges();
  233. }
  234. }
  235. }
  236. db.SaveChanges();
  237. db.Dispose();
  238. return "ok";
  239. }
  240. public string setlee()
  241. {
  242. WebCMSEntities db = new WebCMSEntities();
  243. List<string> poslist = new List<string>();
  244. poslist.Add("00003102722201179816714");
  245. foreach(string PosSn in poslist)
  246. {
  247. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  248. if(pos != null)
  249. {
  250. string info = "{\"RecordId\":\"\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  251. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  252. }
  253. }
  254. db.Dispose();
  255. return "ok";
  256. }
  257. public string add()
  258. {
  259. WebCMSEntities db = new WebCMSEntities();
  260. List<string> poslist = new List<string>();
  261. poslist.Add("0000320226636450184025");
  262. poslist.Add("000087022103231200004221");
  263. poslist.Add("000087022103231200004805");
  264. poslist.Add("00005702280118966019");
  265. foreach(string PosSn in poslist)
  266. {
  267. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  268. if(pos != null)
  269. {
  270. SycnSpTradeService.Instance.ActPos(db, pos, 1000, 30);
  271. }
  272. }
  273. db.Dispose();
  274. return "ok";
  275. }
  276. //金控自备机,补商户信息
  277. public string jkmerinfo(string sn)
  278. {
  279. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  280. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  281. var Bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == sn && m.Field1 == "解绑");
  282. if (Bind != null)
  283. {
  284. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  285. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  286. if (pos != null)
  287. {
  288. pos.BindingState = 1;
  289. pos.BindingTime = Bind.CreateTime;
  290. pos.Status = 0;
  291. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  292. if (merFor == null)
  293. {
  294. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  295. {
  296. MerNo = Bind.MerNo,
  297. SnId = pos.Id,
  298. }).Entity;
  299. }
  300. else
  301. {
  302. merFor.SnId = pos.Id;
  303. }
  304. db.SaveChanges();
  305. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  306. int TopUserId = 0;
  307. if (!string.IsNullOrEmpty(user.ParentNav))
  308. {
  309. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  310. }
  311. int BrandId = pos.BrandId;
  312. PxcModels.TradeRecord trade = db.TradeRecord.FirstOrDefault(m => m.SnNo == sn) ?? new PxcModels.TradeRecord();
  313. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.MerNo);
  314. if (add == null)
  315. {
  316. if(trade.MerchantId > 0)
  317. {
  318. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  319. {
  320. CreateDate = Bind.CreateTime,
  321. KqMerNo = Bind.MerNo,
  322. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  323. Id = trade.MerchantId,
  324. }).Entity;
  325. db.SaveChanges();
  326. }
  327. else
  328. {
  329. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  330. {
  331. CreateDate = Bind.CreateTime,
  332. KqMerNo = Bind.MerNo,
  333. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  334. }).Entity;
  335. db.SaveChanges();
  336. }
  337. }
  338. add.UpdateDate = Bind.UpdateTime;
  339. add.TopUserId = TopUserId;
  340. add.BrandId = BrandId;
  341. add.SnStoreId = pos.StoreId;
  342. add.SnType = pos.PosSnType;
  343. add.UserId = pos.UserId;
  344. add.MerStatus = 1;
  345. add.KqSnNo = Bind.MerSnNo;
  346. add.MerIdcardNo = function.CheckNull(Bind.SeoKeyword).ToUpper();
  347. add.MerRealName = Bind.MerName;
  348. add.MerchantMobile = Bind.MerNewSnNo;
  349. add.MerchantName = Bind.MerName;
  350. pos.BindMerchantId = add.Id;
  351. pos.LastMerchantId = add.Id;
  352. db.SaveChanges();
  353. RedisDbconn.Instance.AddList("DepositReturnStatQueue", add.Id.ToString());
  354. PxcModels.Users buser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  355. if(buser.BusinessFlag == 1)
  356. {
  357. bool checkMer = db.BusinessPartnerMerchant.Any(m => m.MerchantId == add.Id);
  358. if(!checkMer)
  359. {
  360. PxcModels.BusinessPartnerPos bpos = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id) ?? new PxcModels.BusinessPartnerPos();
  361. db.BusinessPartnerMerchant.Add(new PxcModels.BusinessPartnerMerchant()
  362. {
  363. CreateDate = DateTime.Now,
  364. MerNo = Bind.MerNo,
  365. MerchantId = add.Id,
  366. PartnerId = bpos.PartnerId,
  367. UserId = pos.BuyUserId,
  368. });
  369. db.SaveChanges();
  370. }
  371. }
  372. }
  373. }
  374. spdb.Dispose();
  375. db.Dispose();
  376. return "ok";
  377. }
  378. public string sycnTrade(int Id)
  379. {
  380. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  381. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
  382. if(merchant != null)
  383. {
  384. DepositReturnStatService.Instance.DoSomething(db, merchant);
  385. }
  386. return "ok";
  387. }
  388. }
  389. }