SysToolsController.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*
  2. * 机具激活限制信息
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. using System.Text.RegularExpressions;
  19. using System.Security.Cryptography;
  20. using System.Text;
  21. namespace MySystem.Areas.Admin.Controllers
  22. {
  23. [Area("Admin")]
  24. [Route("Admin/[controller]/[action]")]
  25. public class SysToolsController : BaseController
  26. {
  27. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  28. {
  29. }
  30. #region 关联上下级
  31. public IActionResult RelationForUser(string right)
  32. {
  33. ViewBag.RightInfo = RightInfo;
  34. ViewBag.right = right;
  35. return View();
  36. }
  37. [HttpPost]
  38. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  39. {
  40. if (string.IsNullOrEmpty(MakerCode))
  41. {
  42. return "请输入创客编号";
  43. }
  44. if (string.IsNullOrEmpty(ParentMakerCode))
  45. {
  46. return "请输入上级创客编号";
  47. }
  48. MakerCode = MakerCode.ToUpper();
  49. ParentMakerCode = ParentMakerCode.ToUpper();
  50. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  51. if (puser != null)
  52. {
  53. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  54. if (user != null)
  55. {
  56. if (IsTeam == 1)
  57. {
  58. RelationForUserSub(user.Id, user);
  59. }
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. db.SaveChanges();
  63. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  64. return "success";
  65. }
  66. return "创客编号不存在";
  67. }
  68. return "上级创客编号不存在";
  69. }
  70. private void RelationForUserSub(int ParentUserId, Users puser)
  71. {
  72. var subusers = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  73. foreach (var subuser in subusers)
  74. {
  75. Users user = db.Users.FirstOrDefault(m => m.Id == subuser.Id);
  76. if (user != null)
  77. {
  78. user.ParentUserId = puser.Id;
  79. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  80. db.SaveChanges();
  81. RelationForUserSub(user.Id, user);
  82. }
  83. }
  84. }
  85. #endregion
  86. #region 机具补录
  87. public IActionResult CheckMachine(string right)
  88. {
  89. ViewBag.RightInfo = RightInfo;
  90. ViewBag.right = right;
  91. return View();
  92. }
  93. [HttpPost]
  94. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  95. {
  96. if (string.IsNullOrEmpty(MakerCode))
  97. {
  98. return "请输入创客编号";
  99. }
  100. if (string.IsNullOrEmpty(PosSn))
  101. {
  102. return "请输入机具SN";
  103. }
  104. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  105. if (pos == null)
  106. {
  107. return "机具SN不存在";
  108. }
  109. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  110. if (user == null)
  111. {
  112. return "创客编号不存在";
  113. }
  114. if (pos.BindingState == 0)
  115. {
  116. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  117. if (bind != null)
  118. {
  119. pos.BindingState = 1;
  120. pos.BindingTime = bind.CreateTime;
  121. db.SaveChanges();
  122. MerNo = bind.MerNo;
  123. }
  124. }
  125. decimal CreditTrade = 0;
  126. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  127. if (check)
  128. {
  129. if (pos.BrandId == 1)
  130. {
  131. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  132. }
  133. else if (pos.BrandId == 2)
  134. {
  135. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  136. }
  137. else if (pos.BrandId == 3)
  138. {
  139. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  140. }
  141. else if (pos.BrandId == 4 || pos.BrandId == 5)
  142. {
  143. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  144. }
  145. else if (pos.BrandId == 6)
  146. {
  147. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  148. }
  149. else if (pos.BrandId == 7)
  150. {
  151. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  152. }
  153. pos.CreditTrade = CreditTrade;
  154. db.SaveChanges();
  155. StatTradeAmount(pos.PosSn);
  156. }
  157. if (AddActPrize == 1)
  158. {
  159. if (pos.BuyUserId == 0)
  160. {
  161. return "机具未划拨,无法补录激活奖励";
  162. }
  163. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  164. {
  165. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  166. if (has)
  167. {
  168. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  169. pos.SeoKeyword = chkAct.SeoTitle;
  170. db.SaveChanges();
  171. }
  172. }
  173. if (pos.BindingTime != null && pos.ActivationTime != null)
  174. {
  175. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  176. if (ts.TotalDays <= 30)
  177. {
  178. AddAct(pos.Id);
  179. }
  180. }
  181. }
  182. decimal CheckMoney = 1000;
  183. if(pos.BrandId == 6)
  184. {
  185. CheckMoney = 5000;
  186. }
  187. if (pos.BuyUserId > 0)
  188. {
  189. if (pos.CreditTrade < CheckMoney)
  190. {
  191. return "该机具贷记卡累计交易不足" + CheckMoney;
  192. }
  193. if (pos.BindingTime != null && pos.ActivationTime != null)
  194. {
  195. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  196. if (ts.TotalDays > 30)
  197. {
  198. return "机具划拨后已超过30天";
  199. }
  200. }
  201. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  202. {
  203. // pos.IsPurchase = 0;
  204. pos.ActivationState = 1;
  205. pos.ActivationTime = DateTime.Now;
  206. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  207. if (pos.ActivationState == 1 && mer != null)
  208. {
  209. mer.ActiveStatus = 1;
  210. mer.MerStandardDate = DateTime.Now;
  211. RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
  212. }
  213. }
  214. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  215. {
  216. if (AddActPrize == 1)
  217. {
  218. return "激活奖励已补录";
  219. }
  220. else
  221. {
  222. return "数据正常,无需补录";
  223. }
  224. }
  225. db.SaveChanges();
  226. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  227. return "success";
  228. }
  229. pos.UserId = user.Id;
  230. pos.BuyUserId = user.Id;
  231. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-30))
  232. {
  233. // pos.IsPurchase = 0;
  234. pos.ActivationState = 1;
  235. pos.ActivationTime = DateTime.Now;
  236. }
  237. PosMerchantInfo merchant = new PosMerchantInfo();
  238. if (!string.IsNullOrEmpty(MerNo))
  239. {
  240. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  241. if (merchant == null)
  242. {
  243. int TopUserId = 0;
  244. if (!string.IsNullOrEmpty(user.ParentNav))
  245. {
  246. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  247. }
  248. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  249. if (bind == null)
  250. {
  251. return "该机具尚未绑定";
  252. }
  253. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  254. if (Mer == null)
  255. {
  256. return "该机具尚未绑定";
  257. }
  258. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  259. {
  260. CreateDate = Mer.CreateTime,
  261. UpdateDate = Mer.UpdateTime,
  262. TopUserId = TopUserId,
  263. MerUserType = user.MerchantType,
  264. BrandId = int.Parse(Mer.ProductType),
  265. SnStoreId = pos.StoreId,
  266. SnType = pos.PosSnType,
  267. UserId = user.Id,
  268. MgrName = Mer.AgentName,
  269. MerStatus = 1,
  270. KqSnNo = Mer.SnNo,
  271. KqMerNo = Mer.MerNo,
  272. MerIdcardNo = Mer.MerIdcardNo,
  273. MerRealName = Mer.MerRealName,
  274. MerchantMobile = Mer.MerMobile,
  275. MerchantName = Mer.MerName,
  276. MerchantNo = Mer.MerNo,
  277. }).Entity;
  278. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  279. if (forMerNo == null)
  280. {
  281. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  282. {
  283. MerNo = Mer.MerNo,
  284. SnId = pos.Id,
  285. }).Entity;
  286. }
  287. else
  288. {
  289. forMerNo.SnId = pos.Id;
  290. }
  291. }
  292. }
  293. else
  294. {
  295. if (pos.BindMerchantId > 0)
  296. {
  297. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  298. }
  299. else
  300. {
  301. return "找不到机具所属商户";
  302. }
  303. }
  304. merchant.UserId = user.Id;
  305. if (pos.ActivationState == 1)
  306. {
  307. merchant.ActiveStatus = 1;
  308. merchant.MerStandardDate = DateTime.Now;
  309. }
  310. if (pos.BindMerchantId == 0)
  311. {
  312. pos.BindMerchantId = merchant.Id;
  313. }
  314. db.SaveChanges();
  315. RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
  316. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  317. return "success";
  318. }
  319. public IActionResult CheckMachine2(string right)
  320. {
  321. ViewBag.RightInfo = RightInfo;
  322. ViewBag.right = right;
  323. return View();
  324. }
  325. [HttpPost]
  326. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  327. {
  328. if (string.IsNullOrEmpty(MakerCode))
  329. {
  330. return "请输入创客编号";
  331. }
  332. if (string.IsNullOrEmpty(PosSn))
  333. {
  334. return "请输入机具SN";
  335. }
  336. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  337. if (pos == null)
  338. {
  339. return "机具SN不存在";
  340. }
  341. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  342. if (user == null)
  343. {
  344. return "创客编号不存在";
  345. }
  346. if (pos.BindingState == 0)
  347. {
  348. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  349. if (bind != null)
  350. {
  351. pos.BindingState = 1;
  352. pos.BindingTime = bind.CreateTime;
  353. db.SaveChanges();
  354. MerNo = bind.MerNo;
  355. }
  356. }
  357. decimal CreditTrade = 0;
  358. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  359. if (check)
  360. {
  361. if (pos.BrandId == 1)
  362. {
  363. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  364. }
  365. else if (pos.BrandId == 2)
  366. {
  367. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  368. }
  369. else if (pos.BrandId == 3)
  370. {
  371. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  372. }
  373. else if (pos.BrandId == 4 || pos.BrandId == 5)
  374. {
  375. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  376. }
  377. else if (pos.BrandId == 6)
  378. {
  379. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  380. }
  381. pos.CreditTrade = CreditTrade;
  382. db.SaveChanges();
  383. StatTradeAmount(pos.PosSn);
  384. }
  385. if (AddActPrize == 1)
  386. {
  387. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  388. {
  389. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  390. if (has)
  391. {
  392. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  393. pos.SeoKeyword = chkAct.SeoTitle;
  394. db.SaveChanges();
  395. }
  396. }
  397. AddAct(pos.Id);
  398. }
  399. if (pos.BuyUserId > 0)
  400. {
  401. if (pos.CreditTrade < 1000)
  402. {
  403. // pos.IsPurchase = 99;
  404. db.SaveChanges();
  405. return "该机具贷记卡累计交易不足1000";
  406. }
  407. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  408. {
  409. // pos.IsPurchase = 0;
  410. pos.ActivationState = 1;
  411. pos.ActivationTime = DateTime.Now;
  412. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  413. if (pos.ActivationState == 1 && mer != null)
  414. {
  415. mer.ActiveStatus = 1;
  416. mer.MerStandardDate = DateTime.Now;
  417. RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
  418. }
  419. }
  420. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  421. {
  422. if (AddActPrize == 1)
  423. {
  424. return "激活奖励已补录";
  425. }
  426. else
  427. {
  428. return "数据正常,无需补录";
  429. }
  430. }
  431. db.SaveChanges();
  432. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  433. return "success";
  434. }
  435. pos.UserId = user.Id;
  436. pos.BuyUserId = user.Id;
  437. // if (pos.CreditTrade < 1000)
  438. // {
  439. // pos.IsPurchase = 99;
  440. // }
  441. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  442. {
  443. // pos.IsPurchase = 0;
  444. pos.ActivationState = 1;
  445. pos.ActivationTime = DateTime.Now;
  446. }
  447. PosMerchantInfo merchant = new PosMerchantInfo();
  448. if (!string.IsNullOrEmpty(MerNo))
  449. {
  450. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  451. if (merchant == null)
  452. {
  453. int TopUserId = 0;
  454. if (!string.IsNullOrEmpty(user.ParentNav))
  455. {
  456. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  457. }
  458. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  459. if (bind == null)
  460. {
  461. return "该机具尚未绑定";
  462. }
  463. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  464. if (Mer == null)
  465. {
  466. return "该机具尚未绑定";
  467. }
  468. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  469. {
  470. CreateDate = Mer.CreateTime,
  471. UpdateDate = Mer.UpdateTime,
  472. TopUserId = TopUserId,
  473. MerUserType = user.MerchantType,
  474. BrandId = int.Parse(Mer.ProductType),
  475. SnStoreId = pos.StoreId,
  476. SnType = pos.PosSnType,
  477. UserId = user.Id,
  478. MgrName = Mer.AgentName,
  479. MerStatus = 1,
  480. KqSnNo = Mer.SnNo,
  481. KqMerNo = Mer.MerNo,
  482. MerIdcardNo = Mer.MerIdcardNo,
  483. MerRealName = Mer.MerRealName,
  484. MerchantMobile = Mer.MerMobile,
  485. MerchantName = Mer.MerName,
  486. MerchantNo = Mer.MerNo,
  487. }).Entity;
  488. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  489. if (forMerNo == null)
  490. {
  491. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  492. {
  493. MerNo = Mer.MerNo,
  494. SnId = pos.Id,
  495. }).Entity;
  496. }
  497. else
  498. {
  499. forMerNo.SnId = pos.Id;
  500. }
  501. }
  502. }
  503. else
  504. {
  505. if (pos.BindMerchantId > 0)
  506. {
  507. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  508. }
  509. else
  510. {
  511. return "找不到机具所属商户";
  512. }
  513. }
  514. merchant.UserId = user.Id;
  515. if (pos.ActivationState == 1)
  516. {
  517. merchant.ActiveStatus = 1;
  518. merchant.MerStandardDate = DateTime.Now;
  519. }
  520. if (pos.BindMerchantId == 0)
  521. {
  522. pos.BindMerchantId = merchant.Id;
  523. }
  524. db.SaveChanges();
  525. RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
  526. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  527. return "success";
  528. }
  529. public void AddAct(int posid = 0)
  530. {
  531. WebCMSEntities db = new WebCMSEntities();
  532. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  533. if (pos != null)
  534. {
  535. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  536. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  537. if (merchant != null)
  538. {
  539. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  540. // if (otherInfo != null)
  541. // {
  542. // otherInfo.PrizeFlag1 = 1;
  543. // db.SaveChanges();
  544. string ParentNav = "";
  545. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  546. if (user != null)
  547. {
  548. int GetUserId = user.Id;
  549. ParentNav = user.ParentNav;
  550. int TopUserId = 1;
  551. if (!string.IsNullOrEmpty(ParentNav))
  552. {
  553. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  554. if (ParentNavList.Length > 1)
  555. {
  556. TopUserId = int.Parse(ParentNavList[1]);
  557. }
  558. else if (ParentNavList.Length == 1)
  559. {
  560. TopUserId = int.Parse(ParentNavList[0]);
  561. }
  562. }
  563. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  564. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6)
  565. {
  566. ActPrize = ActPrize / 100;
  567. }
  568. if (ActPrize > 0)
  569. {
  570. if (ActPrize == 99)
  571. {
  572. ActPrize = 100;
  573. }
  574. else if (ActPrize == 199)
  575. {
  576. ActPrize = 200;
  577. }
  578. else if (ActPrize == 299)
  579. {
  580. ActPrize = 300;
  581. }
  582. else if (ActPrize == 249)
  583. {
  584. ActPrize = 260;
  585. }
  586. List<decimal> prizes = new List<decimal>();
  587. prizes.Add(ActPrize);
  588. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  589. {
  590. prizes.Add(40);
  591. }
  592. foreach(decimal prize in prizes)
  593. {
  594. int ChangeType = prize == 40 ? 12 : 0;
  595. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  596. if (!check)
  597. {
  598. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  599. db.ActiveReward.Add(new ActiveReward()
  600. {
  601. CreateDate = DateTime.Now,
  602. UpdateDate = DateTime.Now,
  603. UserId = GetUserId, //创客
  604. MerchantId = pos.BindMerchantId, //商户
  605. StandardDate = pos.ActivationTime, //达标日期
  606. RewardAmount = prize, //奖励金额
  607. BrandId = pos.BrandId, //品牌
  608. UserNav = ParentNav, //创客父级
  609. DirectBuddyNo = merchant.UserId, //商户直属创客
  610. KqMerNo = merchant.KqMerNo, //渠道商户编号
  611. KqSnNo = pos.PosSn, //渠道SN号
  612. SnType = pos.PosSnType, //机具类型
  613. SnApplyUserId = pos.BuyUserId, //机具申请创客
  614. ActType = 0, //激活类型
  615. SnStoreId = pos.StoreId, //SN仓库
  616. RewardTips = "激活奖励", //奖励描述
  617. Remark = "激活奖励", //备注
  618. ActDate = pos.ActivationTime, //激活时间
  619. TopUserId = TopUserId, //顶级创客
  620. SeoTitle = machineUser.RealName,
  621. });
  622. db.SaveChanges();
  623. string IdBrand = GetUserId + "_" + pos.BrandId;
  624. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  625. if (userData == null)
  626. {
  627. userData = db.UserMachineData.Add(new UserMachineData()
  628. {
  629. IdBrand = IdBrand,
  630. }).Entity;
  631. db.SaveChanges();
  632. }
  633. userData.ActProfit += prize;
  634. db.SaveChanges();
  635. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
  636. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  637. if (account == null)
  638. {
  639. account = db.UserAccount.Add(new UserAccount()
  640. {
  641. Id = GetUserId,
  642. UserId = GetUserId,
  643. }).Entity;
  644. db.SaveChanges();
  645. }
  646. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  647. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  648. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  649. account.BalanceAmount += prize;
  650. account.TotalAmount += prize;
  651. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  652. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  653. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  654. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  655. {
  656. CreateDate = DateTime.Now,
  657. UpdateDate = DateTime.Now,
  658. UserId = GetUserId, //创客
  659. ChangeType = ChangeType, //变动类型
  660. ProductType = pos.BrandId, //产品类型
  661. ChangeAmount = prize, //变更金额
  662. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  663. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  664. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  665. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  666. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  667. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  668. }).Entity;
  669. db.SaveChanges();
  670. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  671. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  672. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  673. // 激活奖励列表
  674. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  675. if (!dates.Contains(dateString))
  676. {
  677. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  678. }
  679. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  680. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  681. if (!months.Contains(monthString))
  682. {
  683. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  684. }
  685. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  686. // 激活奖励详情
  687. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  688. if (!actPrizeList.Contains(pos.BindMerchantId))
  689. {
  690. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  691. }
  692. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  693. //收支明细
  694. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  695. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  696. }
  697. }
  698. }
  699. }
  700. // }
  701. }
  702. }
  703. db.Dispose();
  704. }
  705. //重置交易额
  706. public void StatTradeAmount(string PosSn)
  707. {
  708. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  709. if (DateTime.Now.Day == 1)
  710. {
  711. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  712. }
  713. DateTime end = DateTime.Now;
  714. SycnSpTradeService.Instance.Start(PosSn, start, end);
  715. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  716. }
  717. #endregion
  718. #region 设置商户代理
  719. public IActionResult SetMerAgent(string right)
  720. {
  721. ViewBag.RightInfo = RightInfo;
  722. ViewBag.right = right;
  723. return View();
  724. }
  725. [HttpPost]
  726. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo)
  727. {
  728. if (string.IsNullOrEmpty(MakerCode))
  729. {
  730. return "请输入创客编号";
  731. }
  732. if (string.IsNullOrEmpty(PosSn))
  733. {
  734. return "请输入机具SN";
  735. }
  736. if (string.IsNullOrEmpty(MerNo))
  737. {
  738. return "请输入商户编号";
  739. }
  740. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  741. if (pos == null)
  742. {
  743. return "机具SN不存在";
  744. }
  745. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  746. if (user == null)
  747. {
  748. return "创客编号不存在";
  749. }
  750. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  751. if (merchant == null)
  752. {
  753. return "商户编号不存在";
  754. }
  755. pos.SeoTitle = user.Id.ToString();
  756. if (pos.BindMerchantId == 0)
  757. {
  758. pos.BindMerchantId = merchant.Id;
  759. }
  760. user.MerchantType = 1;
  761. merchant.UserId = user.Id;
  762. merchant.MerUserType = 1;
  763. db.SaveChanges();
  764. return "success";
  765. }
  766. #endregion
  767. #region 查看SP原始数据日志
  768. public IActionResult SeeSpLog(string right)
  769. {
  770. ViewBag.RightInfo = RightInfo;
  771. ViewBag.right = right;
  772. return View();
  773. }
  774. #endregion
  775. #region 查询机具信息
  776. public IActionResult SeeSnDetail(string right)
  777. {
  778. ViewBag.RightInfo = RightInfo;
  779. ViewBag.right = right;
  780. return View();
  781. }
  782. [HttpPost]
  783. public string SeeSnDetailDo(string PosSn)
  784. {
  785. if (string.IsNullOrEmpty(PosSn))
  786. {
  787. return "请输入机具SN";
  788. }
  789. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  790. if (pos == null)
  791. {
  792. return "机具SN不存在";
  793. }
  794. if (pos.Status == -1)
  795. {
  796. return "该机具为故障机";
  797. }
  798. string merInfo = "";
  799. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  800. if (mer != null)
  801. {
  802. merInfo = mer.KqMerNo;
  803. }
  804. else
  805. {
  806. merInfo = "未找到商户";
  807. }
  808. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  809. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  810. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  811. int TopUserId = 0;
  812. if (!string.IsNullOrEmpty(posUser.ParentNav))
  813. {
  814. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  815. if (ParentNavs.Length > 1)
  816. {
  817. TopUserId = int.Parse(ParentNavs[1]);
  818. }
  819. if (ParentNavs.Length == 1)
  820. {
  821. TopUserId = int.Parse(ParentNavs[0]);
  822. }
  823. }
  824. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  825. string bindResult = "", bindTime = "";
  826. if (pos.BindingState == 0)
  827. {
  828. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  829. if (bind != null)
  830. {
  831. if (bind.Status != 1)
  832. {
  833. bindResult = "执行中";
  834. }
  835. }
  836. else
  837. {
  838. bindResult = "未绑定";
  839. }
  840. }
  841. else
  842. {
  843. bindResult = "已绑定";
  844. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  845. }
  846. string activeResult = "", activeTime = "";
  847. if (pos.ActivationState == 0)
  848. {
  849. if (pos.CreditTrade < 1000)
  850. {
  851. activeResult = "未刷满1000";
  852. }
  853. else if (pos.TransferTime == null)
  854. {
  855. activeResult = "未激活, 需补录";
  856. }
  857. }
  858. else
  859. {
  860. activeResult = "已激活";
  861. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  862. }
  863. string tradeAmount = pos.CreditTrade.ToString();
  864. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  865. if (pos.BrandId != 2 && pos.BrandId != 7)
  866. {
  867. Deposit = Deposit / 100;
  868. }
  869. string DepositGet = "未领取";
  870. string DepositUser = "";
  871. string DepositToUser = "";
  872. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  873. if (reward.Id > 0)
  874. {
  875. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  876. DepositGet = "已领取";
  877. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  878. }
  879. string DepositGet6 = "未领取";
  880. string DepositUser6 = "";
  881. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  882. if (lisreward.Id > 0)
  883. {
  884. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  885. DepositGet6 = "已领取";
  886. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  887. }
  888. string FluxGet6 = "未领取";
  889. string FluxUser6 = "";
  890. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn && m.BrandId == 6) ?? new FluxProfitDetail();
  891. if (flux.Id > 0)
  892. {
  893. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  894. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  895. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  896. }
  897. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  898. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  899. string OpenUser10 = "未领取";
  900. string OpenUser20 = "未领取";
  901. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  902. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  903. if (openreward.Id > 0)
  904. {
  905. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  906. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  907. }
  908. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  909. if (openreward.Id > 0)
  910. {
  911. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  912. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  913. }
  914. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  915. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  916. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  917. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  918. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  919. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  920. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  921. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  922. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  923. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  924. string result = "";
  925. result += "机具SN:" + pos.PosSn + "\n";
  926. result += "商户编号:" + merInfo + "\n";
  927. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  928. if (change.Id > 0)
  929. {
  930. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  931. }
  932. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  933. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  934. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  935. result += "划拨时间:" + TransferTime + "\n";
  936. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  937. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  938. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  939. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  940. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  941. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  942. result += "押金:" + Deposit + "\n";
  943. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  944. result += "押金返现应返现对象:" + DepositToUser + "\n";
  945. result += "押金返现实际返现对象:" + DepositUser + "\n";
  946. if (pos.BrandId == 6)
  947. {
  948. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  949. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  950. }
  951. result += "流量费:" + FluxGet6 + "\n";
  952. result += "流量费发放对象:" + FluxUser6 + "\n";
  953. result += "开机奖20:" + OpenUser20 + "\n";
  954. result += "开机奖10:" + OpenUser10 + "\n";
  955. return result;
  956. }
  957. //解析金控日志
  958. // public decimal CheckLog(DateTime startDate, string PosSn)
  959. // {
  960. // bool op = true;
  961. // decimal result = 0;
  962. // DateTime today = DateTime.Now;
  963. // int i = 0;
  964. // while (op)
  965. // {
  966. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  967. // if (check <= today)
  968. // {
  969. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  970. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  971. // foreach (Match sub in mc)
  972. // {
  973. // string content = sub.Value;
  974. // JsonData jsonObj = JsonMapper.ToObject(content);
  975. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  976. // string posSnCheck = jsonObj["posSn"].ToString();
  977. // if (posSnCheck == PosSn && serviceAmount > 0)
  978. // {
  979. // result = serviceAmount / 100;
  980. // op = false;
  981. // }
  982. // }
  983. // }
  984. // else
  985. // {
  986. // op = false;
  987. // }
  988. // i += 1;
  989. // }
  990. // return result;
  991. // }
  992. #endregion
  993. #region 生成机具兑换码
  994. public IActionResult MakeCoupons(string right)
  995. {
  996. ViewBag.RightInfo = RightInfo;
  997. ViewBag.right = right;
  998. return View();
  999. }
  1000. [HttpPost]
  1001. public string MakeCouponsDo(int Kind, int Number)
  1002. {
  1003. DateTime checkTime = DateTime.Parse("1900-01-01");
  1004. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1005. if (!string.IsNullOrEmpty(checkTimeString))
  1006. {
  1007. checkTime = DateTime.Parse(checkTimeString);
  1008. }
  1009. if (checkTime.AddHours(1) < DateTime.Now)
  1010. {
  1011. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1012. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1013. return "生成程序已执行";
  1014. }
  1015. return "请稍后再试";
  1016. }
  1017. #endregion
  1018. #region 导出没有刷满1000的机具
  1019. public IActionResult ExportPos(string right)
  1020. {
  1021. ViewBag.RightInfo = RightInfo;
  1022. ViewBag.right = right;
  1023. return View();
  1024. }
  1025. [HttpPost]
  1026. public JsonResult ExportPosDo()
  1027. {
  1028. WebCMSEntities db = new WebCMSEntities();
  1029. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1030. int total = poses.Count;
  1031. int index = 0;
  1032. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1033. foreach (PosMachinesTwo pos in poses)
  1034. {
  1035. index += 1;
  1036. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1037. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1038. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1039. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1040. Dictionary<string, object> item = new Dictionary<string, object>();
  1041. string TopRealName = "";
  1042. string TopMakerCode = "";
  1043. string TopMobile = "";
  1044. string ParentNav = user.ParentNav;
  1045. if (!string.IsNullOrEmpty(ParentNav))
  1046. {
  1047. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1048. if (navlist.Length > 1)
  1049. {
  1050. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1051. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1052. TopRealName = tuser.RealName;
  1053. TopMakerCode = tuser.MakerCode;
  1054. TopMobile = tuser.Mobile;
  1055. }
  1056. }
  1057. item.Add("TopRealName", TopRealName); //顶级姓名
  1058. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1059. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1060. item.Add("UpRealName", puser.RealName); //上级姓名
  1061. item.Add("RealName", user.RealName); //代理姓名
  1062. item.Add("MakerCode", user.MakerCode); //代理编号
  1063. item.Add("Mobile", user.Mobile); //代理手机号
  1064. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1065. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1066. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1067. item.Add("Sn", pos.PosSn); //SN
  1068. list.Add(item);
  1069. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1070. }
  1071. db.Dispose();
  1072. Dictionary<string, object> result = new Dictionary<string, object>();
  1073. result.Add("Status", "1");
  1074. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1075. result.Add("Obj", list);
  1076. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1077. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1078. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1079. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1080. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1081. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1082. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1083. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1084. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1085. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1086. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1087. ReturnFields.Add("Sn", "SN"); //SN
  1088. result.Add("Fields", ReturnFields);
  1089. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1090. return Json(result);
  1091. }
  1092. public string ExportPosCheck()
  1093. {
  1094. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1095. if (content == "finish")
  1096. {
  1097. RedisDbconn.Instance.Clear("ExportPosCheck");
  1098. }
  1099. return content;
  1100. }
  1101. #endregion
  1102. #region 更换机具
  1103. public IActionResult ChangePos(string right)
  1104. {
  1105. ViewBag.RightInfo = RightInfo;
  1106. ViewBag.right = right;
  1107. return View();
  1108. }
  1109. [HttpPost]
  1110. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "")
  1111. {
  1112. if (string.IsNullOrEmpty(OldSn))
  1113. {
  1114. return "请输入原机具SN";
  1115. }
  1116. if (string.IsNullOrEmpty(NewSn))
  1117. {
  1118. return "请输入新机具SN";
  1119. }
  1120. string[] OldSnList = OldSn.Split('\n');
  1121. string[] NewSnList = NewSn.Split('\n');
  1122. if (OldSnList.Length != NewSnList.Length)
  1123. {
  1124. return "原机具SN数量和新机具SN数量不一致";
  1125. }
  1126. WebCMSEntities db = new WebCMSEntities();
  1127. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1128. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1129. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1130. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1131. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1132. MachineChange add = db.MachineChange.Add(new MachineChange()
  1133. {
  1134. CreateDate = DateTime.Now,
  1135. UpdateDate = DateTime.Now,
  1136. ChangeNo = ChangeNo, //转换单号
  1137. UserId = 0, //创客
  1138. ChangeTime = DateTime.Now, //转换时间
  1139. BackStoreId = BackStore.Id, //退回仓库
  1140. BackStoreName = BackStore.StoreName, //退回仓库名称
  1141. Remark = "机具更换", //订单备注
  1142. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1143. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1144. OutProductName = OutStore.ProductName, //出库产品名称
  1145. OutStoreId = OutStore.Id, //出库仓库
  1146. OutStoreName = OutStore.StoreName, //出库仓库名称
  1147. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1148. OutStoreAddress = OutStore.Address, //出库仓库地址
  1149. OutStoreManager = "", //出库仓库联系人
  1150. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1151. }).Entity;
  1152. db.SaveChanges();
  1153. int BackProductType = 0;
  1154. string BackProductName = "";
  1155. string ChangeDeviceName = "";
  1156. string ChangeSnExpand = "";
  1157. for (int i = 0; i < OldSnList.Length; i++)
  1158. {
  1159. string OldSnNum = OldSnList[i];
  1160. string NewSnNum = NewSnList[i];
  1161. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1162. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1163. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1164. if (oldpos == null)
  1165. {
  1166. return "原机具SN不正确";
  1167. }
  1168. // if (oldpos.BindingState != 1)
  1169. // {
  1170. // return "原机具未绑定";
  1171. // }
  1172. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1173. if (oldpos == null)
  1174. {
  1175. return "新机具SN不正确";
  1176. }
  1177. KqProducts oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1178. KqProducts newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1179. PosMerchantInfo merchant = new PosMerchantInfo();
  1180. if (!string.IsNullOrEmpty(MerNo))
  1181. {
  1182. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1183. }
  1184. else
  1185. {
  1186. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1187. }
  1188. newpos.BindMerchantId = merchant.Id;
  1189. newpos.BuyUserId = oldpos.BuyUserId;
  1190. newpos.UserId = oldpos.UserId;
  1191. newpos.RecycEndDate = oldpos.RecycEndDate;
  1192. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1193. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1194. newpos.CreditTrade = oldpos.CreditTrade;
  1195. newpos.PosSnType = oldpos.PosSnType;
  1196. newpos.TransferTime = oldpos.TransferTime;
  1197. newpos.IsPurchase = oldpos.IsPurchase;
  1198. newpos.BindingState = oldpos.BindingState;
  1199. newpos.ActivationState = oldpos.ActivationState;
  1200. newpos.BindingTime = oldpos.BindingTime;
  1201. newpos.ActivationTime = oldpos.ActivationTime;
  1202. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1203. // if (!checkActReward)
  1204. // {
  1205. newpos.SeoKeyword = oldpos.SeoKeyword;
  1206. newpos.PrizeParams = oldpos.PrizeParams;
  1207. newpos.LeaderUserId= oldpos.LeaderUserId;
  1208. // }
  1209. // oldpos.BuyUserId = 0;
  1210. // oldpos.UserId = 0;
  1211. oldpos.Status = -1;
  1212. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1213. if (forMerNo != null)
  1214. {
  1215. forMerNo.SnId = newpos.Id;
  1216. }
  1217. merchant.KqSnNo = NewSn;
  1218. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1219. {
  1220. CreateDate = DateTime.Now,
  1221. UpdateDate = DateTime.Now,
  1222. ChangeNo = ChangeNo, //订单号
  1223. ChangeId = add.Id, //订单Id
  1224. BackProductType = oldpos.BrandId, //退回产品类型
  1225. BackProductName = oldPosBrand.Name, //退回产品名称
  1226. UserId = 0, //创客
  1227. BackSnNo = oldpos.PosSn, //设备SN编号
  1228. OutProductType = newpos.BrandId, //出库产品类型
  1229. OutProductName = newPosBrand.Name, //出库产品名称
  1230. OutSnNo = newpos.PosSn, //出库设备SN编号
  1231. OutSnType = newpos.PosSnType, //出库SN机具类型
  1232. Remark = "机具更换", //备注
  1233. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1234. });
  1235. db.SaveChanges();
  1236. BackProductType = oldpos.BrandId;
  1237. BackProductName = newPosBrand.Name;
  1238. ChangeDeviceName = oldpos.DeviceName;
  1239. ChangeSnExpand += oldpos.PosSn + "\n";
  1240. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1241. }
  1242. add.BackProductType = BackProductType; //退回产品类型
  1243. add.BackProductName = BackProductName; //退回产品名称
  1244. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1245. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1246. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1247. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1248. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1249. db.SaveChanges();
  1250. db.Dispose();
  1251. return "success";
  1252. }
  1253. #endregion
  1254. #region 机具解绑
  1255. public IActionResult Unbind(string right)
  1256. {
  1257. ViewBag.RightInfo = RightInfo;
  1258. ViewBag.right = right;
  1259. return View();
  1260. }
  1261. [HttpPost]
  1262. public string UnbindDo(string PosSn, string MakerCode, string MerNo)
  1263. {
  1264. if (string.IsNullOrEmpty(PosSn))
  1265. {
  1266. return "请输入机具SN";
  1267. }
  1268. if (string.IsNullOrEmpty(MakerCode))
  1269. {
  1270. return "请输入创客编号";
  1271. }
  1272. if (string.IsNullOrEmpty(MerNo))
  1273. {
  1274. return "请输入商户编号";
  1275. }
  1276. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1277. if (forSnNo == null)
  1278. {
  1279. return "机具SN不存在";
  1280. }
  1281. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1282. if (forMakerCode == null)
  1283. {
  1284. return "创客不存在";
  1285. }
  1286. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1287. if (forMerNo == null)
  1288. {
  1289. return "商户编号不存在";
  1290. }
  1291. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.Id == forMerNo.SnId);
  1292. if (pos == null)
  1293. {
  1294. return "机具SN不存在";
  1295. }
  1296. if (pos.BuyUserId != forMakerCode.UserId)
  1297. {
  1298. return "机具SN和创客不匹配";
  1299. }
  1300. if (pos.ActivationState == 1)
  1301. {
  1302. return "机具已激活,不能解绑";
  1303. }
  1304. if (pos.BuyUserId == 0)
  1305. {
  1306. return "机具是仓库机,不支持解绑";
  1307. }
  1308. if (pos.BindingState == 0)
  1309. {
  1310. return "机具未绑定,不支持解绑";
  1311. }
  1312. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  1313. {
  1314. return "机具绑定已超过30天,不支持解绑";
  1315. }
  1316. if (forMerNo != null)
  1317. {
  1318. db.MachineForMerNo.Remove(forMerNo);
  1319. db.SaveChanges();
  1320. }
  1321. db.MachineUnBind.Add(new MachineUnBind()
  1322. {
  1323. CreateDate = DateTime.Now,
  1324. SeoTitle = SysUserName + "-" + SysRealName,
  1325. MerchantId = pos.BindMerchantId,
  1326. AuditDate = DateTime.Now,
  1327. AuditDesc = "平台操作解绑",
  1328. AuditStatus = 1,
  1329. SnNo = pos.PosSn,
  1330. BrandId = pos.BrandId,
  1331. UserId = pos.BuyUserId,
  1332. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1333. });
  1334. pos.BindMerchantId = 0;
  1335. pos.BindingState = 0;
  1336. pos.BindingTime = DateTime.Parse("1900-01-01");
  1337. pos.UserId = pos.BuyUserId;
  1338. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1339. db.SaveChanges();
  1340. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1341. return "success";
  1342. }
  1343. #endregion
  1344. #region 查询创客直推奖
  1345. public IActionResult Prize100(string right)
  1346. {
  1347. ViewBag.RightInfo = RightInfo;
  1348. ViewBag.right = right;
  1349. return View();
  1350. }
  1351. [HttpPost]
  1352. public Dictionary<string, string> Prize100Do(string MakerCode)
  1353. {
  1354. Dictionary<string, string> dic = new Dictionary<string, string>();
  1355. string result = "";
  1356. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1357. if (forMakerCode == null)
  1358. {
  1359. result += "创客编号不存在\n";
  1360. dic.Add("code", "1");
  1361. dic.Add("result", result);
  1362. return dic;
  1363. }
  1364. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  1365. if (OrderCount == 0)
  1366. {
  1367. result += "该创客未下单\n";
  1368. dic.Add("code", "1");
  1369. dic.Add("result", result);
  1370. return dic;
  1371. }
  1372. if (OrderCount > 1)
  1373. {
  1374. result += "该创客已不是首笔下单\n";
  1375. dic.Add("code", "1");
  1376. dic.Add("result", result);
  1377. return dic;
  1378. }
  1379. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  1380. if (order.PayStatus < 1)
  1381. {
  1382. result += "未付款\n";
  1383. dic.Add("code", "1");
  1384. dic.Add("result", result);
  1385. return dic;
  1386. }
  1387. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1388. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1389. result += "订单号:" + order.OrderNo + "\n";
  1390. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1391. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1392. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  1393. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1394. if (machineCount + ActiveCount >= 3)
  1395. {
  1396. string IsGet = "未发放";
  1397. int ToUserId = 0;
  1398. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id);
  1399. if (item == null)
  1400. {
  1401. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1402. DateTime end = order.PayDate.Value.AddMinutes(2);
  1403. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1404. }
  1405. if (item != null)
  1406. {
  1407. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1408. ToUserId = item.UserId;
  1409. dic.Add("code", "1");
  1410. }
  1411. else
  1412. {
  1413. dic.Add("id", order.Id.ToString());
  1414. dic.Add("code", "0");
  1415. }
  1416. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1417. result += "是否发放:" + IsGet + "\n";
  1418. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1419. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1420. }
  1421. else
  1422. {
  1423. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1424. dic.Add("code", "1");
  1425. }
  1426. dic.Add("result", result);
  1427. return dic;
  1428. }
  1429. public string AddPrize100(int Id)
  1430. {
  1431. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1432. if (order != null)
  1433. {
  1434. //机具券逻辑
  1435. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1436. if (pro != null)
  1437. {
  1438. //推荐下单奖励
  1439. if (pro.ProductId == 10 || pro.ProductId == 11)
  1440. {
  1441. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1442. if (user != null)
  1443. {
  1444. int ParentUserId = user.ParentUserId;
  1445. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  1446. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1447. if (machineCount + ActiveCount >= 3)
  1448. {
  1449. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  1450. if (account == null)
  1451. {
  1452. account = db.UserAccount.Add(new UserAccount()
  1453. {
  1454. Id = ParentUserId,
  1455. UserId = ParentUserId,
  1456. }).Entity;
  1457. db.SaveChanges();
  1458. }
  1459. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1460. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1461. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1462. account.BalanceAmount += 100;
  1463. account.TotalAmount += 100;
  1464. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1465. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1466. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1467. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  1468. {
  1469. CreateDate = DateTime.Now,
  1470. UpdateDate = DateTime.Now,
  1471. UserId = ParentUserId, //创客
  1472. ChangeType = 112, //变动类型
  1473. ChangeAmount = 100, //变更金额
  1474. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1475. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1476. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1477. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1478. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1479. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1480. QueryCount = order.Id,
  1481. }).Entity;
  1482. db.SaveChanges();
  1483. RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  1484. //推荐下单上级获得30天的机具循环天数
  1485. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
  1486. foreach (var subPos in posList)
  1487. {
  1488. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1489. if (pos != null)
  1490. {
  1491. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1492. }
  1493. }
  1494. db.SaveChanges();
  1495. return "success";
  1496. }
  1497. else
  1498. {
  1499. return "上级创客未满足条件:购买机:" + machineCount + "台,激活机:" + ActiveCount + "台";
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. return "操作失败";
  1506. }
  1507. #endregion
  1508. #region 设置立刷费率
  1509. public IActionResult LisFee(string right)
  1510. {
  1511. ViewBag.RightInfo = RightInfo;
  1512. ViewBag.right = right;
  1513. return View();
  1514. }
  1515. [HttpPost]
  1516. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  1517. {
  1518. if (string.IsNullOrEmpty(PosSns))
  1519. {
  1520. return "请输入机具号";
  1521. }
  1522. string result = SysUserName + "设置\n";
  1523. string[] PosSnList = PosSns.Split('\n');
  1524. int total = PosSnList.Length;
  1525. int index = 0;
  1526. foreach (string SubPosSn in PosSnList)
  1527. {
  1528. index += 1;
  1529. string PosSn = SubPosSn.Replace("\r", "");
  1530. result += PosSn + ":" + Fee + "\n";
  1531. if (Kind == "M5")
  1532. {
  1533. result += SetLiSFee(PosSn, Fee) + "\n";
  1534. }
  1535. else if (Kind == "N1")
  1536. {
  1537. result += SetLiSDeposit(PosSn, (int)Fee);
  1538. }
  1539. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  1540. }
  1541. result += "\n\n";
  1542. function.WriteLog(result, "设置立刷费率");
  1543. return result;
  1544. }
  1545. public string LisFeeProcess()
  1546. {
  1547. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  1548. }
  1549. #region 立刷
  1550. string LiSAgentId = "50814834";
  1551. string LiSPrivateKey = "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";
  1552. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  1553. public string LiSSign(string data)
  1554. {
  1555. var rsa = RSA.Create();
  1556. var key = Convert.FromBase64String(LiSPrivateKey);
  1557. var content = Encoding.UTF8.GetBytes(data);
  1558. rsa.ImportPkcs8PrivateKey(key, out _);
  1559. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1560. return Convert.ToBase64String(result);
  1561. }
  1562. // 设置费率
  1563. public string SetLiSFee(string sn, decimal serviceFee)
  1564. {
  1565. Dictionary<string, object> dic = new Dictionary<string, object>();
  1566. dic.Add("agentId", LiSAgentId);
  1567. dic.Add("deviceSn", sn);
  1568. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1569. Dictionary<string, object> item = new Dictionary<string, object>();
  1570. item.Add("feeCalcType", "M5");
  1571. item.Add("fixed", "0");
  1572. item.Add("rate", serviceFee);
  1573. feeList.Add(item);
  1574. dic.Add("feeList", feeList);
  1575. dic.Add("signMethod", "02");
  1576. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  1577. string signstr = LiSSign(content);
  1578. dic.Add("signData", signstr);
  1579. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1580. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1581. return result;
  1582. }
  1583. // 设置押金
  1584. public string SetLiSDeposit(string sn, int serviceFee)
  1585. {
  1586. serviceFee = serviceFee * 100;
  1587. Dictionary<string, object> dic = new Dictionary<string, object>();
  1588. dic.Add("agentId", LiSAgentId);
  1589. dic.Add("deviceSn", sn);
  1590. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1591. Dictionary<string, object> item = new Dictionary<string, object>();
  1592. item.Add("feeCalcType", "N1");
  1593. item.Add("fixed", "1");
  1594. item.Add("rate", serviceFee);
  1595. feeList.Add(item);
  1596. dic.Add("feeList", feeList);
  1597. dic.Add("signMethod", "02");
  1598. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  1599. string signstr = LiSSign(content);
  1600. dic.Add("signData", signstr);
  1601. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1602. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1603. return result;
  1604. }
  1605. #endregion
  1606. #endregion
  1607. #region 查询商户型创客设置信息
  1608. public IActionResult SeeMerchantType(string right)
  1609. {
  1610. ViewBag.RightInfo = RightInfo;
  1611. ViewBag.right = right;
  1612. return View();
  1613. }
  1614. [HttpPost]
  1615. public string SeeMerchantTypeDo(string PosSn)
  1616. {
  1617. if (string.IsNullOrEmpty(PosSn))
  1618. {
  1619. return "请输入机具SN";
  1620. }
  1621. SetMerchantTypeRecord pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.PosSn == PosSn);
  1622. if (pos == null)
  1623. {
  1624. return "查无信息";
  1625. }
  1626. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  1627. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  1628. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1629. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1630. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1631. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  1632. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  1633. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  1634. string result = "";
  1635. result += "机具SN:" + pos.PosSn + "\n";
  1636. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  1637. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  1638. result += "商户编号:" + pos.MerNo + "\n";
  1639. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  1640. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1641. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1642. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  1643. result += "是否循环:" + RecycFlag + "\n";
  1644. return result;
  1645. }
  1646. #endregion
  1647. }
  1648. }