SysToolsController.cs 86 KB

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