SysToolsController.cs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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. result += "划拨时间:" + TransferTime + "\n";
  940. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  941. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  942. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  943. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  944. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  945. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  946. result += "押金:" + Deposit + "\n";
  947. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  948. result += "押金返现应返现对象:" + DepositToUser + "\n";
  949. result += "押金返现实际返现对象:" + DepositUser + "\n";
  950. if (pos.BrandId == 6)
  951. {
  952. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  953. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  954. }
  955. result += "流量费:" + FluxGet6 + "\n";
  956. result += "流量费发放对象:" + FluxUser6 + "\n";
  957. result += "开机奖20:" + OpenUser20 + "\n";
  958. result += "开机奖10:" + OpenUser10 + "\n";
  959. return result;
  960. }
  961. //解析金控日志
  962. // public decimal CheckLog(DateTime startDate, string PosSn)
  963. // {
  964. // bool op = true;
  965. // decimal result = 0;
  966. // DateTime today = DateTime.Now;
  967. // int i = 0;
  968. // while (op)
  969. // {
  970. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  971. // if (check <= today)
  972. // {
  973. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  974. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  975. // foreach (Match sub in mc)
  976. // {
  977. // string content = sub.Value;
  978. // JsonData jsonObj = JsonMapper.ToObject(content);
  979. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  980. // string posSnCheck = jsonObj["posSn"].ToString();
  981. // if (posSnCheck == PosSn && serviceAmount > 0)
  982. // {
  983. // result = serviceAmount / 100;
  984. // op = false;
  985. // }
  986. // }
  987. // }
  988. // else
  989. // {
  990. // op = false;
  991. // }
  992. // i += 1;
  993. // }
  994. // return result;
  995. // }
  996. #endregion
  997. #region 生成机具兑换码
  998. public IActionResult MakeCoupons(string right)
  999. {
  1000. ViewBag.RightInfo = RightInfo;
  1001. ViewBag.right = right;
  1002. return View();
  1003. }
  1004. [HttpPost]
  1005. public string MakeCouponsDo(int Kind, int Number)
  1006. {
  1007. DateTime checkTime = DateTime.Parse("1900-01-01");
  1008. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1009. if (!string.IsNullOrEmpty(checkTimeString))
  1010. {
  1011. checkTime = DateTime.Parse(checkTimeString);
  1012. }
  1013. if (checkTime.AddHours(1) < DateTime.Now)
  1014. {
  1015. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1016. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1017. return "生成程序已执行";
  1018. }
  1019. return "请稍后再试";
  1020. }
  1021. #endregion
  1022. #region 导出没有刷满1000的机具
  1023. public IActionResult ExportPos(string right)
  1024. {
  1025. ViewBag.RightInfo = RightInfo;
  1026. ViewBag.right = right;
  1027. return View();
  1028. }
  1029. [HttpPost]
  1030. public JsonResult ExportPosDo()
  1031. {
  1032. WebCMSEntities db = new WebCMSEntities();
  1033. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1034. int total = poses.Count;
  1035. int index = 0;
  1036. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1037. foreach (PosMachinesTwo pos in poses)
  1038. {
  1039. index += 1;
  1040. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1041. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1042. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1043. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1044. Dictionary<string, object> item = new Dictionary<string, object>();
  1045. string TopRealName = "";
  1046. string TopMakerCode = "";
  1047. string TopMobile = "";
  1048. string ParentNav = user.ParentNav;
  1049. if (!string.IsNullOrEmpty(ParentNav))
  1050. {
  1051. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1052. if (navlist.Length > 1)
  1053. {
  1054. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1055. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1056. TopRealName = tuser.RealName;
  1057. TopMakerCode = tuser.MakerCode;
  1058. TopMobile = tuser.Mobile;
  1059. }
  1060. }
  1061. item.Add("TopRealName", TopRealName); //顶级姓名
  1062. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1063. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1064. item.Add("UpRealName", puser.RealName); //上级姓名
  1065. item.Add("RealName", user.RealName); //代理姓名
  1066. item.Add("MakerCode", user.MakerCode); //代理编号
  1067. item.Add("Mobile", user.Mobile); //代理手机号
  1068. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1069. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1070. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1071. item.Add("Sn", pos.PosSn); //SN
  1072. list.Add(item);
  1073. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1074. }
  1075. db.Dispose();
  1076. Dictionary<string, object> result = new Dictionary<string, object>();
  1077. result.Add("Status", "1");
  1078. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1079. result.Add("Obj", list);
  1080. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1081. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1082. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1083. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1084. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1085. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1086. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1087. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1088. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1089. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1090. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1091. ReturnFields.Add("Sn", "SN"); //SN
  1092. result.Add("Fields", ReturnFields);
  1093. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1094. return Json(result);
  1095. }
  1096. public string ExportPosCheck()
  1097. {
  1098. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1099. if (content == "finish")
  1100. {
  1101. RedisDbconn.Instance.Clear("ExportPosCheck");
  1102. }
  1103. return content;
  1104. }
  1105. #endregion
  1106. #region 更换机具
  1107. public IActionResult ChangePos(string right)
  1108. {
  1109. ViewBag.RightInfo = RightInfo;
  1110. ViewBag.right = right;
  1111. return View();
  1112. }
  1113. [HttpPost]
  1114. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "")
  1115. {
  1116. if (string.IsNullOrEmpty(OldSn))
  1117. {
  1118. return "请输入原机具SN";
  1119. }
  1120. if (string.IsNullOrEmpty(NewSn))
  1121. {
  1122. return "请输入新机具SN";
  1123. }
  1124. string[] OldSnList = OldSn.Split('\n');
  1125. string[] NewSnList = NewSn.Split('\n');
  1126. if (OldSnList.Length != NewSnList.Length)
  1127. {
  1128. return "原机具SN数量和新机具SN数量不一致";
  1129. }
  1130. WebCMSEntities db = new WebCMSEntities();
  1131. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1132. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1133. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1134. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1135. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1136. MachineChange add = db.MachineChange.Add(new MachineChange()
  1137. {
  1138. CreateDate = DateTime.Now,
  1139. UpdateDate = DateTime.Now,
  1140. ChangeNo = ChangeNo, //转换单号
  1141. UserId = 0, //创客
  1142. ChangeTime = DateTime.Now, //转换时间
  1143. BackStoreId = BackStore.Id, //退回仓库
  1144. BackStoreName = BackStore.StoreName, //退回仓库名称
  1145. Remark = "机具更换", //订单备注
  1146. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1147. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1148. OutProductName = OutStore.ProductName, //出库产品名称
  1149. OutStoreId = OutStore.Id, //出库仓库
  1150. OutStoreName = OutStore.StoreName, //出库仓库名称
  1151. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1152. OutStoreAddress = OutStore.Address, //出库仓库地址
  1153. OutStoreManager = "", //出库仓库联系人
  1154. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1155. }).Entity;
  1156. db.SaveChanges();
  1157. int BackProductType = 0;
  1158. string BackProductName = "";
  1159. string ChangeDeviceName = "";
  1160. string ChangeSnExpand = "";
  1161. for (int i = 0; i < OldSnList.Length; i++)
  1162. {
  1163. string OldSnNum = OldSnList[i];
  1164. string NewSnNum = NewSnList[i];
  1165. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1166. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1167. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1168. if (oldpos == null)
  1169. {
  1170. return "原机具SN不正确";
  1171. }
  1172. // if (oldpos.BindingState != 1)
  1173. // {
  1174. // return "原机具未绑定";
  1175. // }
  1176. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1177. if (oldpos == null)
  1178. {
  1179. return "新机具SN不正确";
  1180. }
  1181. KqProducts oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1182. KqProducts newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1183. PosMerchantInfo merchant = new PosMerchantInfo();
  1184. if (!string.IsNullOrEmpty(MerNo))
  1185. {
  1186. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1187. }
  1188. else
  1189. {
  1190. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1191. }
  1192. newpos.BindMerchantId = merchant.Id;
  1193. newpos.BuyUserId = oldpos.BuyUserId;
  1194. newpos.UserId = oldpos.UserId;
  1195. newpos.RecycEndDate = oldpos.RecycEndDate;
  1196. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1197. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1198. newpos.CreditTrade = oldpos.CreditTrade;
  1199. newpos.PosSnType = oldpos.PosSnType;
  1200. newpos.TransferTime = oldpos.TransferTime;
  1201. newpos.IsPurchase = oldpos.IsPurchase;
  1202. newpos.BindingState = oldpos.BindingState;
  1203. newpos.ActivationState = oldpos.ActivationState;
  1204. newpos.BindingTime = oldpos.BindingTime;
  1205. newpos.ActivationTime = oldpos.ActivationTime;
  1206. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1207. // if (!checkActReward)
  1208. // {
  1209. newpos.SeoKeyword = oldpos.SeoKeyword;
  1210. newpos.PrizeParams = oldpos.PrizeParams;
  1211. newpos.LeaderUserId= oldpos.LeaderUserId;
  1212. // }
  1213. // oldpos.BuyUserId = 0;
  1214. // oldpos.UserId = 0;
  1215. oldpos.Status = -1;
  1216. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1217. if (forMerNo != null)
  1218. {
  1219. forMerNo.SnId = newpos.Id;
  1220. }
  1221. merchant.KqSnNo = NewSn;
  1222. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1223. {
  1224. CreateDate = DateTime.Now,
  1225. UpdateDate = DateTime.Now,
  1226. ChangeNo = ChangeNo, //订单号
  1227. ChangeId = add.Id, //订单Id
  1228. BackProductType = oldpos.BrandId, //退回产品类型
  1229. BackProductName = oldPosBrand.Name, //退回产品名称
  1230. UserId = 0, //创客
  1231. BackSnNo = oldpos.PosSn, //设备SN编号
  1232. OutProductType = newpos.BrandId, //出库产品类型
  1233. OutProductName = newPosBrand.Name, //出库产品名称
  1234. OutSnNo = newpos.PosSn, //出库设备SN编号
  1235. OutSnType = newpos.PosSnType, //出库SN机具类型
  1236. Remark = "机具更换", //备注
  1237. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1238. });
  1239. db.SaveChanges();
  1240. BackProductType = oldpos.BrandId;
  1241. BackProductName = newPosBrand.Name;
  1242. ChangeDeviceName = oldpos.DeviceName;
  1243. ChangeSnExpand += oldpos.PosSn + "\n";
  1244. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1245. }
  1246. add.BackProductType = BackProductType; //退回产品类型
  1247. add.BackProductName = BackProductName; //退回产品名称
  1248. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1249. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1250. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1251. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1252. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1253. db.SaveChanges();
  1254. db.Dispose();
  1255. return "success";
  1256. }
  1257. #endregion
  1258. #region 机具解绑
  1259. public IActionResult Unbind(string right)
  1260. {
  1261. ViewBag.RightInfo = RightInfo;
  1262. ViewBag.right = right;
  1263. return View();
  1264. }
  1265. [HttpPost]
  1266. public string UnbindDo(string PosSn, string MakerCode, string MerNo)
  1267. {
  1268. if (string.IsNullOrEmpty(PosSn))
  1269. {
  1270. return "请输入机具SN";
  1271. }
  1272. if (string.IsNullOrEmpty(MakerCode))
  1273. {
  1274. return "请输入创客编号";
  1275. }
  1276. if (string.IsNullOrEmpty(MerNo))
  1277. {
  1278. return "请输入商户编号";
  1279. }
  1280. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1281. if (forSnNo == null)
  1282. {
  1283. return "机具SN不存在";
  1284. }
  1285. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1286. if (forMakerCode == null)
  1287. {
  1288. return "创客不存在";
  1289. }
  1290. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1291. if (forMerNo == null)
  1292. {
  1293. return "商户编号不存在";
  1294. }
  1295. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.Id == forMerNo.SnId);
  1296. if (pos == null)
  1297. {
  1298. return "机具SN不存在";
  1299. }
  1300. if (pos.BuyUserId != forMakerCode.UserId)
  1301. {
  1302. return "机具SN和创客不匹配";
  1303. }
  1304. if (pos.ActivationState == 1)
  1305. {
  1306. return "机具已激活,不能解绑";
  1307. }
  1308. if (pos.BuyUserId == 0)
  1309. {
  1310. return "机具是仓库机,不支持解绑";
  1311. }
  1312. if (pos.BindingState == 0)
  1313. {
  1314. return "机具未绑定,不支持解绑";
  1315. }
  1316. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  1317. {
  1318. return "机具绑定已超过30天,不支持解绑";
  1319. }
  1320. if (forMerNo != null)
  1321. {
  1322. db.MachineForMerNo.Remove(forMerNo);
  1323. db.SaveChanges();
  1324. }
  1325. db.MachineUnBind.Add(new MachineUnBind()
  1326. {
  1327. CreateDate = DateTime.Now,
  1328. SeoTitle = SysUserName + "-" + SysRealName,
  1329. MerchantId = pos.BindMerchantId,
  1330. AuditDate = DateTime.Now,
  1331. AuditDesc = "平台操作解绑",
  1332. AuditStatus = 1,
  1333. SnNo = pos.PosSn,
  1334. BrandId = pos.BrandId,
  1335. UserId = pos.BuyUserId,
  1336. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1337. });
  1338. pos.BindMerchantId = 0;
  1339. pos.BindingState = 0;
  1340. pos.BindingTime = DateTime.Parse("1900-01-01");
  1341. pos.UserId = pos.BuyUserId;
  1342. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1343. db.SaveChanges();
  1344. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1345. return "success";
  1346. }
  1347. #endregion
  1348. #region 查询创客直推奖
  1349. public IActionResult Prize100(string right)
  1350. {
  1351. ViewBag.RightInfo = RightInfo;
  1352. ViewBag.right = right;
  1353. return View();
  1354. }
  1355. [HttpPost]
  1356. public Dictionary<string, string> Prize100Do(string MakerCode)
  1357. {
  1358. Dictionary<string, string> dic = new Dictionary<string, string>();
  1359. string result = "";
  1360. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1361. if (forMakerCode == null)
  1362. {
  1363. result += "创客编号不存在\n";
  1364. dic.Add("code", "1");
  1365. dic.Add("result", result);
  1366. return dic;
  1367. }
  1368. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  1369. if (OrderCount == 0)
  1370. {
  1371. result += "该创客未下单\n";
  1372. dic.Add("code", "1");
  1373. dic.Add("result", result);
  1374. return dic;
  1375. }
  1376. if (OrderCount > 1)
  1377. {
  1378. result += "该创客已不是首笔下单\n";
  1379. dic.Add("code", "1");
  1380. dic.Add("result", result);
  1381. return dic;
  1382. }
  1383. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  1384. if (order.PayStatus < 1)
  1385. {
  1386. result += "未付款\n";
  1387. dic.Add("code", "1");
  1388. dic.Add("result", result);
  1389. return dic;
  1390. }
  1391. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1392. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1393. result += "订单号:" + order.OrderNo + "\n";
  1394. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1395. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1396. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  1397. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1398. if (machineCount + ActiveCount >= 3)
  1399. {
  1400. string IsGet = "未发放";
  1401. int ToUserId = 0;
  1402. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id);
  1403. if (item == null)
  1404. {
  1405. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1406. DateTime end = order.PayDate.Value.AddMinutes(2);
  1407. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1408. }
  1409. if (item != null)
  1410. {
  1411. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1412. ToUserId = item.UserId;
  1413. dic.Add("code", "1");
  1414. }
  1415. else
  1416. {
  1417. dic.Add("id", order.Id.ToString());
  1418. dic.Add("code", "0");
  1419. }
  1420. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1421. result += "是否发放:" + IsGet + "\n";
  1422. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1423. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1424. }
  1425. else
  1426. {
  1427. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1428. dic.Add("code", "1");
  1429. }
  1430. dic.Add("result", result);
  1431. return dic;
  1432. }
  1433. public string AddPrize100(int Id)
  1434. {
  1435. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1436. if (order != null)
  1437. {
  1438. //机具券逻辑
  1439. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1440. if (pro != null)
  1441. {
  1442. //推荐下单奖励
  1443. if (pro.ProductId == 10 || pro.ProductId == 11)
  1444. {
  1445. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1446. if (user != null)
  1447. {
  1448. int ParentUserId = user.ParentUserId;
  1449. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  1450. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1451. if (machineCount + ActiveCount >= 3)
  1452. {
  1453. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  1454. if (account == null)
  1455. {
  1456. account = db.UserAccount.Add(new UserAccount()
  1457. {
  1458. Id = ParentUserId,
  1459. UserId = ParentUserId,
  1460. }).Entity;
  1461. db.SaveChanges();
  1462. }
  1463. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1464. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1465. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1466. account.BalanceAmount += 100;
  1467. account.TotalAmount += 100;
  1468. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1469. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1470. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1471. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  1472. {
  1473. CreateDate = DateTime.Now,
  1474. UpdateDate = DateTime.Now,
  1475. UserId = ParentUserId, //创客
  1476. ChangeType = 112, //变动类型
  1477. ChangeAmount = 100, //变更金额
  1478. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1479. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1480. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1481. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1482. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1483. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1484. QueryCount = order.Id,
  1485. }).Entity;
  1486. db.SaveChanges();
  1487. RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  1488. //推荐下单上级获得30天的机具循环天数
  1489. 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();
  1490. foreach (var subPos in posList)
  1491. {
  1492. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1493. if (pos != null)
  1494. {
  1495. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1496. }
  1497. }
  1498. db.SaveChanges();
  1499. return "success";
  1500. }
  1501. else
  1502. {
  1503. return "上级创客未满足条件:购买机:" + machineCount + "台,激活机:" + ActiveCount + "台";
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. return "操作失败";
  1510. }
  1511. #endregion
  1512. #region 设置立刷费率
  1513. public IActionResult LisFee(string right)
  1514. {
  1515. ViewBag.RightInfo = RightInfo;
  1516. ViewBag.right = right;
  1517. return View();
  1518. }
  1519. [HttpPost]
  1520. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  1521. {
  1522. if (string.IsNullOrEmpty(PosSns))
  1523. {
  1524. return "请输入机具号";
  1525. }
  1526. string result = SysUserName + "设置\n";
  1527. string[] PosSnList = PosSns.Split('\n');
  1528. int total = PosSnList.Length;
  1529. int index = 0;
  1530. foreach (string SubPosSn in PosSnList)
  1531. {
  1532. index += 1;
  1533. string PosSn = SubPosSn.Replace("\r", "");
  1534. result += PosSn + ":" + Fee + "\n";
  1535. if (Kind == "M5")
  1536. {
  1537. result += SetLiSFee(PosSn, Fee) + "\n";
  1538. }
  1539. else if (Kind == "N1")
  1540. {
  1541. result += SetLiSDeposit(PosSn, (int)Fee);
  1542. }
  1543. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  1544. }
  1545. result += "\n\n";
  1546. function.WriteLog(result, "设置立刷费率");
  1547. return result;
  1548. }
  1549. public string LisFeeProcess()
  1550. {
  1551. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  1552. }
  1553. #region 立刷
  1554. string LiSAgentId = "50814834";
  1555. string LiSPrivateKey = "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";
  1556. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  1557. public string LiSSign(string data)
  1558. {
  1559. var rsa = RSA.Create();
  1560. var key = Convert.FromBase64String(LiSPrivateKey);
  1561. var content = Encoding.UTF8.GetBytes(data);
  1562. rsa.ImportPkcs8PrivateKey(key, out _);
  1563. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1564. return Convert.ToBase64String(result);
  1565. }
  1566. // 设置费率
  1567. public string SetLiSFee(string sn, decimal serviceFee)
  1568. {
  1569. Dictionary<string, object> dic = new Dictionary<string, object>();
  1570. dic.Add("agentId", LiSAgentId);
  1571. dic.Add("deviceSn", sn);
  1572. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1573. Dictionary<string, object> item = new Dictionary<string, object>();
  1574. item.Add("feeCalcType", "M5");
  1575. item.Add("fixed", "0");
  1576. item.Add("rate", serviceFee);
  1577. feeList.Add(item);
  1578. dic.Add("feeList", feeList);
  1579. dic.Add("signMethod", "02");
  1580. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  1581. string signstr = LiSSign(content);
  1582. dic.Add("signData", signstr);
  1583. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1584. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1585. return result;
  1586. }
  1587. // 设置押金
  1588. public string SetLiSDeposit(string sn, int serviceFee)
  1589. {
  1590. serviceFee = serviceFee * 100;
  1591. Dictionary<string, object> dic = new Dictionary<string, object>();
  1592. dic.Add("agentId", LiSAgentId);
  1593. dic.Add("deviceSn", sn);
  1594. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1595. Dictionary<string, object> item = new Dictionary<string, object>();
  1596. item.Add("feeCalcType", "N1");
  1597. item.Add("fixed", "1");
  1598. item.Add("rate", serviceFee);
  1599. feeList.Add(item);
  1600. dic.Add("feeList", feeList);
  1601. dic.Add("signMethod", "02");
  1602. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  1603. string signstr = LiSSign(content);
  1604. dic.Add("signData", signstr);
  1605. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1606. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1607. return result;
  1608. }
  1609. #endregion
  1610. #endregion
  1611. #region 查询商户型创客设置信息
  1612. public IActionResult SeeMerchantType(string right)
  1613. {
  1614. ViewBag.RightInfo = RightInfo;
  1615. ViewBag.right = right;
  1616. return View();
  1617. }
  1618. [HttpPost]
  1619. public string SeeMerchantTypeDo(string PosSn)
  1620. {
  1621. if (string.IsNullOrEmpty(PosSn))
  1622. {
  1623. return "请输入机具SN";
  1624. }
  1625. SetMerchantTypeRecord pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.PosSn == PosSn);
  1626. if (pos == null)
  1627. {
  1628. return "查无信息";
  1629. }
  1630. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  1631. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  1632. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1633. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1634. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1635. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  1636. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  1637. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  1638. string result = "";
  1639. result += "机具SN:" + pos.PosSn + "\n";
  1640. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  1641. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  1642. result += "商户编号:" + pos.MerNo + "\n";
  1643. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  1644. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1645. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1646. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  1647. result += "是否循环:" + RecycFlag + "\n";
  1648. return result;
  1649. }
  1650. #endregion
  1651. }
  1652. }