SysToolsController.cs 84 KB

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