SysToolsController.cs 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  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. List<decimal> prizes = new List<decimal>();
  564. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  565. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6)
  566. {
  567. ActPrize = ActPrize / 100;
  568. }
  569. if (ActPrize > 0)
  570. {
  571. if (ActPrize == 99)
  572. {
  573. ActPrize = 100;
  574. }
  575. else if (ActPrize == 199)
  576. {
  577. ActPrize = 200;
  578. }
  579. else if (ActPrize == 299)
  580. {
  581. ActPrize = 300;
  582. }
  583. else if (ActPrize == 249)
  584. {
  585. ActPrize = 260;
  586. }
  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. }
  593. else if(pos.BrandId == 6 && ActPrize == 0)
  594. {
  595. prizes.Add(50);
  596. }
  597. foreach(decimal prize in prizes)
  598. {
  599. int ChangeType = prize == 40 ? 12 : 0;
  600. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  601. if (!check)
  602. {
  603. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  604. db.ActiveReward.Add(new ActiveReward()
  605. {
  606. CreateDate = DateTime.Now,
  607. UpdateDate = DateTime.Now,
  608. UserId = GetUserId, //创客
  609. MerchantId = pos.BindMerchantId, //商户
  610. StandardDate = pos.ActivationTime, //达标日期
  611. RewardAmount = prize, //奖励金额
  612. BrandId = pos.BrandId, //品牌
  613. UserNav = ParentNav, //创客父级
  614. DirectBuddyNo = merchant.UserId, //商户直属创客
  615. KqMerNo = merchant.KqMerNo, //渠道商户编号
  616. KqSnNo = pos.PosSn, //渠道SN号
  617. SnType = pos.PosSnType, //机具类型
  618. SnApplyUserId = pos.BuyUserId, //机具申请创客
  619. ActType = 0, //激活类型
  620. SnStoreId = pos.StoreId, //SN仓库
  621. RewardTips = "激活奖励", //奖励描述
  622. Remark = "激活奖励", //备注
  623. ActDate = pos.ActivationTime, //激活时间
  624. TopUserId = TopUserId, //顶级创客
  625. SeoTitle = machineUser.RealName,
  626. });
  627. db.SaveChanges();
  628. string IdBrand = GetUserId + "_" + pos.BrandId;
  629. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  630. if (userData == null)
  631. {
  632. userData = db.UserMachineData.Add(new UserMachineData()
  633. {
  634. IdBrand = IdBrand,
  635. }).Entity;
  636. db.SaveChanges();
  637. }
  638. userData.ActProfit += prize;
  639. db.SaveChanges();
  640. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
  641. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  642. if (account == null)
  643. {
  644. account = db.UserAccount.Add(new UserAccount()
  645. {
  646. Id = GetUserId,
  647. UserId = GetUserId,
  648. }).Entity;
  649. db.SaveChanges();
  650. }
  651. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  652. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  653. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  654. account.BalanceAmount += prize;
  655. account.TotalAmount += prize;
  656. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  657. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  658. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  659. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  660. {
  661. CreateDate = DateTime.Now,
  662. UpdateDate = DateTime.Now,
  663. UserId = GetUserId, //创客
  664. ChangeType = ChangeType, //变动类型
  665. ProductType = pos.BrandId, //产品类型
  666. ChangeAmount = prize, //变更金额
  667. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  668. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  669. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  670. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  671. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  672. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  673. }).Entity;
  674. db.SaveChanges();
  675. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  676. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  677. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  678. // 激活奖励列表
  679. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  680. if (!dates.Contains(dateString))
  681. {
  682. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  683. }
  684. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  685. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  686. if (!months.Contains(monthString))
  687. {
  688. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  689. }
  690. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  691. // 激活奖励详情
  692. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  693. if (!actPrizeList.Contains(pos.BindMerchantId))
  694. {
  695. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  696. }
  697. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  698. //收支明细
  699. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  700. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  701. }
  702. }
  703. }
  704. // }
  705. }
  706. }
  707. db.Dispose();
  708. }
  709. //重置交易额
  710. public void StatTradeAmount(string PosSn)
  711. {
  712. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  713. if (DateTime.Now.Day == 1)
  714. {
  715. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  716. }
  717. DateTime end = DateTime.Now;
  718. SycnSpTradeService.Instance.Start(PosSn, start, end);
  719. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  720. }
  721. #endregion
  722. #region 设置商户代理
  723. public IActionResult SetMerAgent(string right)
  724. {
  725. ViewBag.RightInfo = RightInfo;
  726. ViewBag.right = right;
  727. return View();
  728. }
  729. [HttpPost]
  730. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo)
  731. {
  732. if (string.IsNullOrEmpty(MakerCode))
  733. {
  734. return "请输入创客编号";
  735. }
  736. if (string.IsNullOrEmpty(PosSn))
  737. {
  738. return "请输入机具SN";
  739. }
  740. if (string.IsNullOrEmpty(MerNo))
  741. {
  742. return "请输入商户编号";
  743. }
  744. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  745. if (pos == null)
  746. {
  747. return "机具SN不存在";
  748. }
  749. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  750. if (user == null)
  751. {
  752. return "创客编号不存在";
  753. }
  754. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  755. if (merchant == null)
  756. {
  757. return "商户编号不存在";
  758. }
  759. pos.SeoTitle = user.Id.ToString();
  760. if (pos.BindMerchantId == 0)
  761. {
  762. pos.BindMerchantId = merchant.Id;
  763. }
  764. user.MerchantType = 1;
  765. merchant.UserId = user.Id;
  766. merchant.MerUserType = 1;
  767. db.SaveChanges();
  768. return "success";
  769. }
  770. #endregion
  771. #region 查看SP原始数据日志
  772. public IActionResult SeeSpLog(string right)
  773. {
  774. ViewBag.RightInfo = RightInfo;
  775. ViewBag.right = right;
  776. return View();
  777. }
  778. #endregion
  779. #region 查询机具信息
  780. public IActionResult SeeSnDetail(string right)
  781. {
  782. ViewBag.RightInfo = RightInfo;
  783. ViewBag.right = right;
  784. return View();
  785. }
  786. [HttpPost]
  787. public string SeeSnDetailDo(string PosSn)
  788. {
  789. if (string.IsNullOrEmpty(PosSn))
  790. {
  791. return "请输入机具SN";
  792. }
  793. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  794. if (pos == null)
  795. {
  796. return "机具SN不存在";
  797. }
  798. if (pos.Status == -1)
  799. {
  800. return "该机具为故障机";
  801. }
  802. string merInfo = "";
  803. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  804. if (mer != null)
  805. {
  806. merInfo = mer.KqMerNo;
  807. }
  808. else
  809. {
  810. merInfo = "未找到商户";
  811. }
  812. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  813. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  814. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  815. int TopUserId = 0;
  816. if (!string.IsNullOrEmpty(posUser.ParentNav))
  817. {
  818. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  819. if (ParentNavs.Length > 1)
  820. {
  821. TopUserId = int.Parse(ParentNavs[1]);
  822. }
  823. if (ParentNavs.Length == 1)
  824. {
  825. TopUserId = int.Parse(ParentNavs[0]);
  826. }
  827. }
  828. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  829. string bindResult = "", bindTime = "";
  830. if (pos.BindingState == 0)
  831. {
  832. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  833. if (bind != null)
  834. {
  835. if (bind.Status != 1)
  836. {
  837. bindResult = "执行中";
  838. }
  839. }
  840. else
  841. {
  842. bindResult = "未绑定";
  843. }
  844. }
  845. else
  846. {
  847. bindResult = "已绑定";
  848. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  849. }
  850. string activeResult = "", activeTime = "";
  851. if (pos.ActivationState == 0)
  852. {
  853. if (pos.CreditTrade < 1000)
  854. {
  855. activeResult = "未刷满1000";
  856. }
  857. else if (pos.TransferTime == null)
  858. {
  859. activeResult = "未激活, 需补录";
  860. }
  861. }
  862. else
  863. {
  864. activeResult = "已激活";
  865. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  866. }
  867. string tradeAmount = pos.CreditTrade.ToString();
  868. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  869. if (pos.BrandId != 2 && pos.BrandId != 7)
  870. {
  871. Deposit = Deposit / 100;
  872. }
  873. string DepositGet = "未领取";
  874. string DepositUser = "";
  875. string DepositToUser = "";
  876. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  877. if (reward.Id > 0)
  878. {
  879. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  880. DepositGet = "已领取";
  881. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  882. }
  883. string DepositGet6 = "未领取";
  884. string DepositUser6 = "";
  885. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  886. if (lisreward.Id > 0)
  887. {
  888. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  889. DepositGet6 = "已领取";
  890. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  891. }
  892. string FluxGet6 = "未领取";
  893. string FluxUser6 = "";
  894. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn && m.BrandId == 6) ?? new FluxProfitDetail();
  895. if (flux.Id > 0)
  896. {
  897. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  898. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  899. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  900. }
  901. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  902. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  903. string OpenUser10 = "未领取";
  904. string OpenUser20 = "未领取";
  905. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  906. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  907. if (openreward.Id > 0)
  908. {
  909. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  910. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  911. }
  912. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  913. if (openreward.Id > 0)
  914. {
  915. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  916. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  917. }
  918. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  919. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  920. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  921. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  922. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  923. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  924. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  925. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  926. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  927. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  928. string result = "";
  929. result += "机具SN:" + pos.PosSn + "\n";
  930. result += "商户编号:" + merInfo + "\n";
  931. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  932. if (change.Id > 0)
  933. {
  934. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  935. }
  936. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  937. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  938. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  939. if(pos.PreUserId > 0)
  940. {
  941. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  942. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  943. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  944. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  945. }
  946. else
  947. {
  948. result += "机具所属小分仓:暂无小分仓\n";
  949. }
  950. result += "划拨时间:" + TransferTime + "\n";
  951. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  952. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  953. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  954. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  955. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  956. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  957. result += "押金:" + Deposit + "\n";
  958. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  959. result += "押金返现应返现对象:" + DepositToUser + "\n";
  960. result += "押金返现实际返现对象:" + DepositUser + "\n";
  961. if (pos.BrandId == 6)
  962. {
  963. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  964. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  965. }
  966. result += "流量费:" + FluxGet6 + "\n";
  967. result += "流量费发放对象:" + FluxUser6 + "\n";
  968. result += "开机奖20:" + OpenUser20 + "\n";
  969. result += "开机奖10:" + OpenUser10 + "\n";
  970. return result;
  971. }
  972. //解析金控日志
  973. // public decimal CheckLog(DateTime startDate, string PosSn)
  974. // {
  975. // bool op = true;
  976. // decimal result = 0;
  977. // DateTime today = DateTime.Now;
  978. // int i = 0;
  979. // while (op)
  980. // {
  981. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  982. // if (check <= today)
  983. // {
  984. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  985. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  986. // foreach (Match sub in mc)
  987. // {
  988. // string content = sub.Value;
  989. // JsonData jsonObj = JsonMapper.ToObject(content);
  990. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  991. // string posSnCheck = jsonObj["posSn"].ToString();
  992. // if (posSnCheck == PosSn && serviceAmount > 0)
  993. // {
  994. // result = serviceAmount / 100;
  995. // op = false;
  996. // }
  997. // }
  998. // }
  999. // else
  1000. // {
  1001. // op = false;
  1002. // }
  1003. // i += 1;
  1004. // }
  1005. // return result;
  1006. // }
  1007. #endregion
  1008. #region 生成机具兑换码
  1009. public IActionResult MakeCoupons(string right)
  1010. {
  1011. ViewBag.RightInfo = RightInfo;
  1012. ViewBag.right = right;
  1013. return View();
  1014. }
  1015. [HttpPost]
  1016. public string MakeCouponsDo(int Kind, int Number)
  1017. {
  1018. DateTime checkTime = DateTime.Parse("1900-01-01");
  1019. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1020. if (!string.IsNullOrEmpty(checkTimeString))
  1021. {
  1022. checkTime = DateTime.Parse(checkTimeString);
  1023. }
  1024. if (checkTime.AddHours(1) < DateTime.Now)
  1025. {
  1026. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1027. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1028. return "生成程序已执行";
  1029. }
  1030. return "请稍后再试";
  1031. }
  1032. #endregion
  1033. #region 导出没有刷满1000的机具
  1034. public IActionResult ExportPos(string right)
  1035. {
  1036. ViewBag.RightInfo = RightInfo;
  1037. ViewBag.right = right;
  1038. return View();
  1039. }
  1040. [HttpPost]
  1041. public JsonResult ExportPosDo()
  1042. {
  1043. WebCMSEntities db = new WebCMSEntities();
  1044. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1045. int total = poses.Count;
  1046. int index = 0;
  1047. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1048. foreach (PosMachinesTwo pos in poses)
  1049. {
  1050. index += 1;
  1051. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1052. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1053. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1054. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1055. Dictionary<string, object> item = new Dictionary<string, object>();
  1056. string TopRealName = "";
  1057. string TopMakerCode = "";
  1058. string TopMobile = "";
  1059. string ParentNav = user.ParentNav;
  1060. if (!string.IsNullOrEmpty(ParentNav))
  1061. {
  1062. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1063. if (navlist.Length > 1)
  1064. {
  1065. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1066. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1067. TopRealName = tuser.RealName;
  1068. TopMakerCode = tuser.MakerCode;
  1069. TopMobile = tuser.Mobile;
  1070. }
  1071. }
  1072. item.Add("TopRealName", TopRealName); //顶级姓名
  1073. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1074. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1075. item.Add("UpRealName", puser.RealName); //上级姓名
  1076. item.Add("RealName", user.RealName); //代理姓名
  1077. item.Add("MakerCode", user.MakerCode); //代理编号
  1078. item.Add("Mobile", user.Mobile); //代理手机号
  1079. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1080. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1081. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1082. item.Add("Sn", pos.PosSn); //SN
  1083. list.Add(item);
  1084. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1085. }
  1086. db.Dispose();
  1087. Dictionary<string, object> result = new Dictionary<string, object>();
  1088. result.Add("Status", "1");
  1089. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1090. result.Add("Obj", list);
  1091. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1092. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1093. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1094. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1095. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1096. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1097. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1098. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1099. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1100. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1101. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1102. ReturnFields.Add("Sn", "SN"); //SN
  1103. result.Add("Fields", ReturnFields);
  1104. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1105. return Json(result);
  1106. }
  1107. public string ExportPosCheck()
  1108. {
  1109. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1110. if (content == "finish")
  1111. {
  1112. RedisDbconn.Instance.Clear("ExportPosCheck");
  1113. }
  1114. return content;
  1115. }
  1116. #endregion
  1117. #region 更换机具
  1118. public IActionResult ChangePos(string right)
  1119. {
  1120. ViewBag.RightInfo = RightInfo;
  1121. ViewBag.right = right;
  1122. return View();
  1123. }
  1124. [HttpPost]
  1125. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "")
  1126. {
  1127. if (string.IsNullOrEmpty(OldSn))
  1128. {
  1129. return "请输入原机具SN";
  1130. }
  1131. if (string.IsNullOrEmpty(NewSn))
  1132. {
  1133. return "请输入新机具SN";
  1134. }
  1135. string[] OldSnList = OldSn.Split('\n');
  1136. string[] NewSnList = NewSn.Split('\n');
  1137. if (OldSnList.Length != NewSnList.Length)
  1138. {
  1139. return "原机具SN数量和新机具SN数量不一致";
  1140. }
  1141. WebCMSEntities db = new WebCMSEntities();
  1142. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1143. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1144. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1145. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1146. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1147. MachineChange add = db.MachineChange.Add(new MachineChange()
  1148. {
  1149. CreateDate = DateTime.Now,
  1150. UpdateDate = DateTime.Now,
  1151. ChangeNo = ChangeNo, //转换单号
  1152. UserId = 0, //创客
  1153. ChangeTime = DateTime.Now, //转换时间
  1154. BackStoreId = BackStore.Id, //退回仓库
  1155. BackStoreName = BackStore.StoreName, //退回仓库名称
  1156. Remark = "机具更换", //订单备注
  1157. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1158. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1159. OutProductName = OutStore.ProductName, //出库产品名称
  1160. OutStoreId = OutStore.Id, //出库仓库
  1161. OutStoreName = OutStore.StoreName, //出库仓库名称
  1162. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1163. OutStoreAddress = OutStore.Address, //出库仓库地址
  1164. OutStoreManager = "", //出库仓库联系人
  1165. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1166. }).Entity;
  1167. db.SaveChanges();
  1168. int BackProductType = 0;
  1169. string BackProductName = "";
  1170. string ChangeDeviceName = "";
  1171. string ChangeSnExpand = "";
  1172. for (int i = 0; i < OldSnList.Length; i++)
  1173. {
  1174. string OldSnNum = OldSnList[i];
  1175. string NewSnNum = NewSnList[i];
  1176. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1177. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1178. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1179. if (oldpos == null)
  1180. {
  1181. return "原机具SN不正确";
  1182. }
  1183. // if (oldpos.BindingState != 1)
  1184. // {
  1185. // return "原机具未绑定";
  1186. // }
  1187. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1188. if (oldpos == null)
  1189. {
  1190. return "新机具SN不正确";
  1191. }
  1192. KqProducts oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1193. KqProducts newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1194. PosMerchantInfo merchant = new PosMerchantInfo();
  1195. if (!string.IsNullOrEmpty(MerNo))
  1196. {
  1197. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1198. }
  1199. else
  1200. {
  1201. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1202. }
  1203. newpos.BindMerchantId = merchant.Id;
  1204. newpos.BuyUserId = oldpos.BuyUserId;
  1205. newpos.UserId = oldpos.UserId;
  1206. newpos.RecycEndDate = oldpos.RecycEndDate;
  1207. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1208. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1209. newpos.CreditTrade = oldpos.CreditTrade;
  1210. newpos.PosSnType = oldpos.PosSnType;
  1211. newpos.TransferTime = oldpos.TransferTime;
  1212. newpos.IsPurchase = oldpos.IsPurchase;
  1213. newpos.BindingState = oldpos.BindingState;
  1214. newpos.ActivationState = oldpos.ActivationState;
  1215. newpos.BindingTime = oldpos.BindingTime;
  1216. newpos.ActivationTime = oldpos.ActivationTime;
  1217. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1218. // if (!checkActReward)
  1219. // {
  1220. newpos.SeoKeyword = oldpos.SeoKeyword;
  1221. newpos.PrizeParams = oldpos.PrizeParams;
  1222. newpos.LeaderUserId= oldpos.LeaderUserId;
  1223. // }
  1224. // oldpos.BuyUserId = 0;
  1225. // oldpos.UserId = 0;
  1226. oldpos.Status = -1;
  1227. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1228. if (forMerNo != null)
  1229. {
  1230. forMerNo.SnId = newpos.Id;
  1231. }
  1232. merchant.KqSnNo = NewSn;
  1233. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1234. {
  1235. CreateDate = DateTime.Now,
  1236. UpdateDate = DateTime.Now,
  1237. ChangeNo = ChangeNo, //订单号
  1238. ChangeId = add.Id, //订单Id
  1239. BackProductType = oldpos.BrandId, //退回产品类型
  1240. BackProductName = oldPosBrand.Name, //退回产品名称
  1241. UserId = 0, //创客
  1242. BackSnNo = oldpos.PosSn, //设备SN编号
  1243. OutProductType = newpos.BrandId, //出库产品类型
  1244. OutProductName = newPosBrand.Name, //出库产品名称
  1245. OutSnNo = newpos.PosSn, //出库设备SN编号
  1246. OutSnType = newpos.PosSnType, //出库SN机具类型
  1247. Remark = "机具更换", //备注
  1248. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1249. });
  1250. db.SaveChanges();
  1251. BackProductType = oldpos.BrandId;
  1252. BackProductName = newPosBrand.Name;
  1253. ChangeDeviceName = oldpos.DeviceName;
  1254. ChangeSnExpand += oldpos.PosSn + "\n";
  1255. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1256. }
  1257. add.BackProductType = BackProductType; //退回产品类型
  1258. add.BackProductName = BackProductName; //退回产品名称
  1259. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1260. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1261. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1262. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1263. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1264. db.SaveChanges();
  1265. db.Dispose();
  1266. return "success";
  1267. }
  1268. #endregion
  1269. #region 机具解绑
  1270. public IActionResult Unbind(string right)
  1271. {
  1272. ViewBag.RightInfo = RightInfo;
  1273. ViewBag.right = right;
  1274. return View();
  1275. }
  1276. [HttpPost]
  1277. public string UnbindDo(string PosSn, string MakerCode, string MerNo)
  1278. {
  1279. if (string.IsNullOrEmpty(PosSn))
  1280. {
  1281. return "请输入机具SN";
  1282. }
  1283. if (string.IsNullOrEmpty(MakerCode))
  1284. {
  1285. return "请输入创客编号";
  1286. }
  1287. if (string.IsNullOrEmpty(MerNo))
  1288. {
  1289. return "请输入商户编号";
  1290. }
  1291. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1292. if (forSnNo == null)
  1293. {
  1294. return "机具SN不存在";
  1295. }
  1296. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1297. if (forMakerCode == null)
  1298. {
  1299. return "创客不存在";
  1300. }
  1301. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1302. if (forMerNo == null)
  1303. {
  1304. return "商户编号不存在";
  1305. }
  1306. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.Id == forMerNo.SnId);
  1307. if (pos == null)
  1308. {
  1309. return "机具SN不存在";
  1310. }
  1311. if (pos.BuyUserId != forMakerCode.UserId)
  1312. {
  1313. return "机具SN和创客不匹配";
  1314. }
  1315. if (pos.ActivationState == 1)
  1316. {
  1317. return "机具已激活,不能解绑";
  1318. }
  1319. if (pos.BuyUserId == 0)
  1320. {
  1321. return "机具是仓库机,不支持解绑";
  1322. }
  1323. if (pos.BindingState == 0)
  1324. {
  1325. return "机具未绑定,不支持解绑";
  1326. }
  1327. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  1328. {
  1329. return "机具绑定已超过30天,不支持解绑";
  1330. }
  1331. if (forMerNo != null)
  1332. {
  1333. db.MachineForMerNo.Remove(forMerNo);
  1334. db.SaveChanges();
  1335. }
  1336. db.MachineUnBind.Add(new MachineUnBind()
  1337. {
  1338. CreateDate = DateTime.Now,
  1339. SeoTitle = SysUserName + "-" + SysRealName,
  1340. MerchantId = pos.BindMerchantId,
  1341. AuditDate = DateTime.Now,
  1342. AuditDesc = "平台操作解绑",
  1343. AuditStatus = 1,
  1344. SnNo = pos.PosSn,
  1345. BrandId = pos.BrandId,
  1346. UserId = pos.BuyUserId,
  1347. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1348. });
  1349. pos.BindMerchantId = 0;
  1350. pos.BindingState = 0;
  1351. pos.BindingTime = DateTime.Parse("1900-01-01");
  1352. pos.UserId = pos.BuyUserId;
  1353. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1354. db.SaveChanges();
  1355. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1356. return "success";
  1357. }
  1358. #endregion
  1359. #region 查询创客直推奖
  1360. public IActionResult Prize100(string right)
  1361. {
  1362. ViewBag.RightInfo = RightInfo;
  1363. ViewBag.right = right;
  1364. return View();
  1365. }
  1366. [HttpPost]
  1367. public Dictionary<string, string> Prize100Do(string MakerCode)
  1368. {
  1369. Dictionary<string, string> dic = new Dictionary<string, string>();
  1370. string result = "";
  1371. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1372. if (forMakerCode == null)
  1373. {
  1374. result += "创客编号不存在\n";
  1375. dic.Add("code", "1");
  1376. dic.Add("result", result);
  1377. return dic;
  1378. }
  1379. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  1380. if (OrderCount == 0)
  1381. {
  1382. result += "该创客未下单\n";
  1383. dic.Add("code", "1");
  1384. dic.Add("result", result);
  1385. return dic;
  1386. }
  1387. if (OrderCount > 1)
  1388. {
  1389. result += "该创客已不是首笔下单\n";
  1390. dic.Add("code", "1");
  1391. dic.Add("result", result);
  1392. return dic;
  1393. }
  1394. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  1395. if (order.PayStatus < 1)
  1396. {
  1397. result += "未付款\n";
  1398. dic.Add("code", "1");
  1399. dic.Add("result", result);
  1400. return dic;
  1401. }
  1402. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1403. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1404. result += "订单号:" + order.OrderNo + "\n";
  1405. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1406. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1407. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  1408. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1409. if (machineCount + ActiveCount >= 3)
  1410. {
  1411. string IsGet = "未发放";
  1412. int ToUserId = 0;
  1413. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id);
  1414. if (item == null)
  1415. {
  1416. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1417. DateTime end = order.PayDate.Value.AddMinutes(2);
  1418. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1419. }
  1420. if (item != null)
  1421. {
  1422. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1423. ToUserId = item.UserId;
  1424. dic.Add("code", "1");
  1425. }
  1426. else
  1427. {
  1428. dic.Add("id", order.Id.ToString());
  1429. dic.Add("code", "0");
  1430. }
  1431. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1432. result += "是否发放:" + IsGet + "\n";
  1433. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1434. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1435. }
  1436. else
  1437. {
  1438. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1439. dic.Add("code", "1");
  1440. }
  1441. dic.Add("result", result);
  1442. return dic;
  1443. }
  1444. public string AddPrize100(int Id)
  1445. {
  1446. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1447. if (order != null)
  1448. {
  1449. //机具券逻辑
  1450. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1451. if (pro != null)
  1452. {
  1453. //推荐下单奖励
  1454. if (pro.ProductId == 10 || pro.ProductId == 11)
  1455. {
  1456. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1457. if (user != null)
  1458. {
  1459. int ParentUserId = user.ParentUserId;
  1460. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  1461. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1462. if (machineCount + ActiveCount >= 3)
  1463. {
  1464. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  1465. if (account == null)
  1466. {
  1467. account = db.UserAccount.Add(new UserAccount()
  1468. {
  1469. Id = ParentUserId,
  1470. UserId = ParentUserId,
  1471. }).Entity;
  1472. db.SaveChanges();
  1473. }
  1474. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1475. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1476. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1477. account.BalanceAmount += 100;
  1478. account.TotalAmount += 100;
  1479. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1480. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1481. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1482. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  1483. {
  1484. CreateDate = DateTime.Now,
  1485. UpdateDate = DateTime.Now,
  1486. UserId = ParentUserId, //创客
  1487. ChangeType = 112, //变动类型
  1488. ChangeAmount = 100, //变更金额
  1489. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1490. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1491. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1492. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1493. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1494. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1495. QueryCount = order.Id,
  1496. }).Entity;
  1497. db.SaveChanges();
  1498. RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  1499. //推荐下单上级获得30天的机具循环天数
  1500. 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();
  1501. foreach (var subPos in posList)
  1502. {
  1503. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1504. if (pos != null)
  1505. {
  1506. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1507. }
  1508. }
  1509. db.SaveChanges();
  1510. return "success";
  1511. }
  1512. else
  1513. {
  1514. return "上级创客未满足条件:购买机:" + machineCount + "台,激活机:" + ActiveCount + "台";
  1515. }
  1516. }
  1517. }
  1518. }
  1519. }
  1520. return "操作失败";
  1521. }
  1522. #endregion
  1523. #region 设置立刷费率
  1524. public IActionResult LisFee(string right)
  1525. {
  1526. ViewBag.RightInfo = RightInfo;
  1527. ViewBag.right = right;
  1528. return View();
  1529. }
  1530. [HttpPost]
  1531. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  1532. {
  1533. if (string.IsNullOrEmpty(PosSns))
  1534. {
  1535. return "请输入机具号";
  1536. }
  1537. string result = SysUserName + "设置\n";
  1538. string[] PosSnList = PosSns.Split('\n');
  1539. int total = PosSnList.Length;
  1540. int index = 0;
  1541. foreach (string SubPosSn in PosSnList)
  1542. {
  1543. index += 1;
  1544. string PosSn = SubPosSn.Replace("\r", "");
  1545. result += PosSn + ":" + Fee + "\n";
  1546. if (Kind == "M5")
  1547. {
  1548. result += SetLiSFee(PosSn, Fee) + "\n";
  1549. }
  1550. else if (Kind == "N1")
  1551. {
  1552. result += SetLiSDeposit(PosSn, (int)Fee);
  1553. }
  1554. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  1555. }
  1556. result += "\n\n";
  1557. function.WriteLog(result, "设置立刷费率");
  1558. return result;
  1559. }
  1560. public string LisFeeProcess()
  1561. {
  1562. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  1563. }
  1564. #region 立刷
  1565. string LiSAgentId = "50814834";
  1566. string LiSPrivateKey = "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";
  1567. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  1568. public string LiSSign(string data)
  1569. {
  1570. var rsa = RSA.Create();
  1571. var key = Convert.FromBase64String(LiSPrivateKey);
  1572. var content = Encoding.UTF8.GetBytes(data);
  1573. rsa.ImportPkcs8PrivateKey(key, out _);
  1574. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1575. return Convert.ToBase64String(result);
  1576. }
  1577. // 设置费率
  1578. public string SetLiSFee(string sn, decimal serviceFee)
  1579. {
  1580. Dictionary<string, object> dic = new Dictionary<string, object>();
  1581. dic.Add("agentId", LiSAgentId);
  1582. dic.Add("deviceSn", sn);
  1583. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1584. Dictionary<string, object> item = new Dictionary<string, object>();
  1585. item.Add("feeCalcType", "M5");
  1586. item.Add("fixed", "0");
  1587. item.Add("rate", serviceFee);
  1588. feeList.Add(item);
  1589. dic.Add("feeList", feeList);
  1590. dic.Add("signMethod", "02");
  1591. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  1592. string signstr = LiSSign(content);
  1593. dic.Add("signData", signstr);
  1594. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1595. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1596. return result;
  1597. }
  1598. // 设置押金
  1599. public string SetLiSDeposit(string sn, int serviceFee)
  1600. {
  1601. serviceFee = serviceFee * 100;
  1602. Dictionary<string, object> dic = new Dictionary<string, object>();
  1603. dic.Add("agentId", LiSAgentId);
  1604. dic.Add("deviceSn", sn);
  1605. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1606. Dictionary<string, object> item = new Dictionary<string, object>();
  1607. item.Add("feeCalcType", "N1");
  1608. item.Add("fixed", "1");
  1609. item.Add("rate", serviceFee);
  1610. feeList.Add(item);
  1611. dic.Add("feeList", feeList);
  1612. dic.Add("signMethod", "02");
  1613. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  1614. string signstr = LiSSign(content);
  1615. dic.Add("signData", signstr);
  1616. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1617. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1618. return result;
  1619. }
  1620. #endregion
  1621. #endregion
  1622. #region 查询商户型创客设置信息
  1623. public IActionResult SeeMerchantType(string right)
  1624. {
  1625. ViewBag.RightInfo = RightInfo;
  1626. ViewBag.right = right;
  1627. return View();
  1628. }
  1629. [HttpPost]
  1630. public string SeeMerchantTypeDo(string PosSn)
  1631. {
  1632. if (string.IsNullOrEmpty(PosSn))
  1633. {
  1634. return "请输入机具SN";
  1635. }
  1636. SetMerchantTypeRecord pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.PosSn == PosSn);
  1637. if (pos == null)
  1638. {
  1639. return "查无信息";
  1640. }
  1641. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  1642. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  1643. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1644. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1645. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1646. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  1647. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  1648. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  1649. string result = "";
  1650. result += "机具SN:" + pos.PosSn + "\n";
  1651. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  1652. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  1653. result += "商户编号:" + pos.MerNo + "\n";
  1654. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  1655. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1656. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1657. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  1658. result += "是否循环:" + RecycFlag + "\n";
  1659. return result;
  1660. }
  1661. #endregion
  1662. }
  1663. }