SysToolsController.cs 88 KB

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