SysToolsController.cs 96 KB

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