SysToolsController.cs 102 KB

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