SysToolsController.cs 89 KB

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