SysToolsController.cs 206 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387
  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.Security.Cryptography.X509Certificates;
  21. using System.Text;
  22. using System.Net;
  23. using System.Net.Security;
  24. using System.IO;
  25. namespace MySystem.Areas.Admin.Controllers
  26. {
  27. [Area("Admin")]
  28. [Route("Admin/[controller]/[action]")]
  29. public class SysToolsController : BaseController
  30. {
  31. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  32. {
  33. }
  34. #region 关联上下级
  35. public IActionResult RelationForUser(string right)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. return View();
  40. }
  41. [HttpPost]
  42. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  43. {
  44. if (string.IsNullOrEmpty(MakerCode))
  45. {
  46. return "请输入创客编号";
  47. }
  48. if (string.IsNullOrEmpty(ParentMakerCode))
  49. {
  50. return "请输入上级创客编号";
  51. }
  52. MakerCode = MakerCode.ToUpper();
  53. ParentMakerCode = ParentMakerCode.ToUpper();
  54. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  55. if (puser != null)
  56. {
  57. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  58. if (user != null)
  59. {
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. if (IsTeam == 1)
  63. {
  64. RelationForUserSub(db, user.Id, user);
  65. }
  66. db.SaveChanges();
  67. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  68. return "success";
  69. }
  70. return "创客编号不存在";
  71. }
  72. return "上级创客编号不存在";
  73. }
  74. private void RelationForUserSub(WebCMSEntities dbnew, int ParentUserId, Users puser)
  75. {
  76. var subusers = dbnew.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  77. foreach (var subuser in subusers)
  78. {
  79. Users user = dbnew.Users.FirstOrDefault(m => m.Id == subuser.Id);
  80. if (user != null)
  81. {
  82. user.ParentUserId = puser.Id;
  83. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  84. RelationForUserSub(dbnew, user.Id, user);
  85. }
  86. }
  87. }
  88. #endregion
  89. #region 机具补录
  90. public IActionResult CheckMachine(string right)
  91. {
  92. ViewBag.RightInfo = RightInfo;
  93. ViewBag.right = right;
  94. return View();
  95. }
  96. [HttpPost]
  97. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0, int IsPre = 0, int IsSend = 0)
  98. {
  99. if (string.IsNullOrEmpty(MakerCode))
  100. {
  101. return "请输入创客编号";
  102. }
  103. if (string.IsNullOrEmpty(PosSn))
  104. {
  105. return "请输入机具SN";
  106. }
  107. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  108. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  109. if (pos == null)
  110. {
  111. return "机具SN不存在";
  112. }
  113. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  114. if (user == null)
  115. {
  116. return "创客编号不存在";
  117. }
  118. if (IsPre == 1)
  119. {
  120. if (pos.BuyUserId == 0)
  121. {
  122. pos.BuyUserId = user.Id;
  123. }
  124. if (pos.UserId == 0)
  125. {
  126. pos.UserId = user.Id;
  127. }
  128. }
  129. if (pos.BindingState == 0)
  130. {
  131. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  132. if (bind != null)
  133. {
  134. pos.BindingState = 1;
  135. pos.BindingTime = bind.CreateTime;
  136. db.SaveChanges();
  137. MerNo = bind.MerNo;
  138. }
  139. }
  140. decimal CreditTrade = 0;
  141. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  142. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  143. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  144. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  145. if (check)
  146. {
  147. if (pos.BrandId == 1)
  148. {
  149. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  150. }
  151. else if (pos.BrandId == 2)
  152. {
  153. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  154. }
  155. else if (pos.BrandId == 3)
  156. {
  157. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  158. }
  159. else if (pos.BrandId == 4 || pos.BrandId == 5)
  160. {
  161. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  162. }
  163. else if (pos.BrandId == 6)
  164. {
  165. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  166. }
  167. else if (pos.BrandId == 7)
  168. {
  169. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  170. }
  171. else if (pos.BrandId == 8)
  172. {
  173. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  174. }
  175. else if (pos.BrandId == 9)
  176. {
  177. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  178. }
  179. else if (pos.BrandId == 10 || pos.BrandId == 11)
  180. {
  181. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  182. }
  183. else if (pos.BrandId == 12)
  184. {
  185. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
  186. }
  187. pos.CreditTrade = CreditTrade;
  188. db.SaveChanges();
  189. }
  190. if (AddActPrize == 1)
  191. {
  192. if (pos.BuyUserId == 0)
  193. {
  194. return "机具未划拨,无法补录激活奖励";
  195. }
  196. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  197. {
  198. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  199. if (has)
  200. {
  201. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  202. pos.SeoKeyword = chkAct.SeoTitle;
  203. db.SaveChanges();
  204. }
  205. }
  206. if (pos.BindingTime != null && pos.ActivationTime != null)
  207. {
  208. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  209. if (ts.TotalDays <= 30 || SysUserName == "admin")
  210. {
  211. AddAct(pos.Id);
  212. }
  213. }
  214. }
  215. decimal CheckMoney = 1000;
  216. if (pos.BrandId == 6)
  217. {
  218. CheckMoney = 5000;
  219. }
  220. if (pos.BuyUserId > 0)
  221. {
  222. if (pos.CreditTrade < CheckMoney)
  223. {
  224. return "该机具贷记卡累计交易不足" + CheckMoney;
  225. }
  226. if (pos.BindingTime != null && pos.ActivationTime != null)
  227. {
  228. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  229. if (ts.TotalDays > 30 && SysUserName != "admin")
  230. {
  231. return "机具划拨后已超过30天";
  232. }
  233. }
  234. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  235. {
  236. pos.ActivationState = 1;
  237. pos.ActivationTime = DateTime.Now;
  238. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  239. if (pos.ActivationState == 1 && mer != null)
  240. {
  241. mer.ActiveStatus = 1;
  242. mer.MerStandardDate = DateTime.Now;
  243. }
  244. }
  245. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  246. {
  247. if (AddActPrize == 1)
  248. {
  249. if (IsSend == 1)
  250. {
  251. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  252. {
  253. UserId = pos.BuyUserId, //接收创客
  254. MsgType = 2,
  255. Title = "补录成功通知", //标题
  256. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  257. CreateDate = DateTime.Now,
  258. }));
  259. }
  260. return "激活奖励已补录";
  261. }
  262. else
  263. {
  264. return "数据正常,无需补录";
  265. }
  266. }
  267. db.SaveChanges();
  268. return "success";
  269. }
  270. pos.UserId = user.Id;
  271. pos.BuyUserId = user.Id;
  272. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  273. {
  274. pos.ActivationState = 1;
  275. pos.ActivationTime = DateTime.Now;
  276. }
  277. PosMerchantInfo merchant = new PosMerchantInfo();
  278. if (!string.IsNullOrEmpty(MerNo))
  279. {
  280. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  281. if (merchant == null)
  282. {
  283. int TopUserId = 0;
  284. if (!string.IsNullOrEmpty(user.ParentNav))
  285. {
  286. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  287. }
  288. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  289. if (bind == null)
  290. {
  291. return "该机具尚未绑定";
  292. }
  293. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  294. if (Mer == null)
  295. {
  296. return "该机具尚未绑定";
  297. }
  298. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  299. {
  300. CreateDate = Mer.CreateTime,
  301. UpdateDate = Mer.UpdateTime,
  302. TopUserId = TopUserId,
  303. MerUserType = user.MerchantType,
  304. BrandId = int.Parse(Mer.ProductType),
  305. SnStoreId = pos.StoreId,
  306. SnType = pos.PosSnType,
  307. UserId = user.Id,
  308. MgrName = Mer.AgentName,
  309. MerStatus = 1,
  310. KqSnNo = Mer.SnNo,
  311. KqMerNo = Mer.MerNo,
  312. MerIdcardNo = Mer.MerIdcardNo,
  313. MerRealName = Mer.MerRealName,
  314. MerchantMobile = Mer.MerMobile,
  315. MerchantName = Mer.MerName,
  316. MerchantNo = Mer.MerNo,
  317. }).Entity;
  318. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  319. if (forMerNo == null)
  320. {
  321. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  322. {
  323. MerNo = Mer.MerNo,
  324. SnId = pos.Id,
  325. }).Entity;
  326. }
  327. else
  328. {
  329. forMerNo.SnId = pos.Id;
  330. }
  331. }
  332. }
  333. else
  334. {
  335. if (pos.BindMerchantId > 0)
  336. {
  337. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  338. }
  339. else
  340. {
  341. return "找不到机具所属商户";
  342. }
  343. }
  344. merchant.UserId = user.Id;
  345. if (pos.ActivationState == 1)
  346. {
  347. merchant.ActiveStatus = 1;
  348. merchant.MerStandardDate = DateTime.Now;
  349. }
  350. if (pos.BindMerchantId == 0)
  351. {
  352. pos.BindMerchantId = merchant.Id;
  353. }
  354. db.SaveChanges();
  355. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  356. return "success";
  357. }
  358. public IActionResult CheckMachine2(string right)
  359. {
  360. ViewBag.RightInfo = RightInfo;
  361. ViewBag.right = right;
  362. return View();
  363. }
  364. [HttpPost]
  365. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  366. {
  367. if (string.IsNullOrEmpty(MakerCode))
  368. {
  369. return "请输入创客编号";
  370. }
  371. if (string.IsNullOrEmpty(PosSn))
  372. {
  373. return "请输入机具SN";
  374. }
  375. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  376. if (pos == null)
  377. {
  378. return "机具SN不存在";
  379. }
  380. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  381. if (user == null)
  382. {
  383. return "创客编号不存在";
  384. }
  385. if (pos.BindingState == 0)
  386. {
  387. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  388. if (bind != null)
  389. {
  390. pos.BindingState = 1;
  391. pos.BindingTime = bind.CreateTime;
  392. db.SaveChanges();
  393. MerNo = bind.MerNo;
  394. }
  395. }
  396. decimal CreditTrade = 0;
  397. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  398. if (check)
  399. {
  400. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  401. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  402. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  403. if (pos.BrandId == 1)
  404. {
  405. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  406. }
  407. else if (pos.BrandId == 2)
  408. {
  409. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  410. }
  411. else if (pos.BrandId == 3)
  412. {
  413. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  414. }
  415. else if (pos.BrandId == 4 || pos.BrandId == 5)
  416. {
  417. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  418. }
  419. else if (pos.BrandId == 6)
  420. {
  421. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  422. }
  423. else if (pos.BrandId == 8)
  424. {
  425. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  426. }
  427. else if (pos.BrandId == 9)
  428. {
  429. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  430. }
  431. else if (pos.BrandId == 10 || pos.BrandId == 11)
  432. {
  433. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  434. }
  435. else if (pos.BrandId == 12)
  436. {
  437. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
  438. }
  439. pos.CreditTrade = CreditTrade;
  440. db.SaveChanges();
  441. }
  442. if (AddActPrize == 1)
  443. {
  444. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  445. {
  446. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  447. if (has)
  448. {
  449. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  450. pos.SeoKeyword = chkAct.SeoTitle;
  451. db.SaveChanges();
  452. }
  453. }
  454. AddAct(pos.Id);
  455. }
  456. if (pos.BuyUserId > 0)
  457. {
  458. if (pos.CreditTrade < 1000)
  459. {
  460. db.SaveChanges();
  461. return "该机具贷记卡累计交易不足1000";
  462. }
  463. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  464. {
  465. pos.ActivationState = 1;
  466. pos.ActivationTime = DateTime.Now;
  467. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  468. if (pos.ActivationState == 1 && mer != null)
  469. {
  470. mer.ActiveStatus = 1;
  471. mer.MerStandardDate = DateTime.Now;
  472. }
  473. }
  474. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  475. {
  476. if (AddActPrize == 1)
  477. {
  478. return "激活奖励已补录";
  479. }
  480. else
  481. {
  482. return "数据正常,无需补录";
  483. }
  484. }
  485. db.SaveChanges();
  486. return "success";
  487. }
  488. pos.UserId = user.Id;
  489. pos.BuyUserId = user.Id;
  490. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  491. {
  492. pos.ActivationState = 1;
  493. pos.ActivationTime = DateTime.Now;
  494. }
  495. PosMerchantInfo merchant = new PosMerchantInfo();
  496. if (!string.IsNullOrEmpty(MerNo))
  497. {
  498. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  499. if (merchant == null)
  500. {
  501. int TopUserId = 0;
  502. if (!string.IsNullOrEmpty(user.ParentNav))
  503. {
  504. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  505. }
  506. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  507. if (bind == null)
  508. {
  509. return "该机具尚未绑定";
  510. }
  511. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  512. if (Mer == null)
  513. {
  514. return "该机具尚未绑定";
  515. }
  516. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  517. {
  518. CreateDate = Mer.CreateTime,
  519. UpdateDate = Mer.UpdateTime,
  520. TopUserId = TopUserId,
  521. MerUserType = user.MerchantType,
  522. BrandId = int.Parse(Mer.ProductType),
  523. SnStoreId = pos.StoreId,
  524. SnType = pos.PosSnType,
  525. UserId = user.Id,
  526. MgrName = Mer.AgentName,
  527. MerStatus = 1,
  528. KqSnNo = Mer.SnNo,
  529. KqMerNo = Mer.MerNo,
  530. MerIdcardNo = Mer.MerIdcardNo,
  531. MerRealName = Mer.MerRealName,
  532. MerchantMobile = Mer.MerMobile,
  533. MerchantName = Mer.MerName,
  534. MerchantNo = Mer.MerNo,
  535. }).Entity;
  536. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  537. if (forMerNo == null)
  538. {
  539. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  540. {
  541. MerNo = Mer.MerNo,
  542. SnId = pos.Id,
  543. }).Entity;
  544. }
  545. else
  546. {
  547. forMerNo.SnId = pos.Id;
  548. }
  549. }
  550. }
  551. else
  552. {
  553. if (pos.BindMerchantId > 0)
  554. {
  555. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  556. }
  557. else
  558. {
  559. return "找不到机具所属商户";
  560. }
  561. }
  562. merchant.UserId = user.Id;
  563. if (pos.ActivationState == 1)
  564. {
  565. merchant.ActiveStatus = 1;
  566. merchant.MerStandardDate = DateTime.Now;
  567. }
  568. if (pos.BindMerchantId == 0)
  569. {
  570. pos.BindMerchantId = merchant.Id;
  571. }
  572. db.SaveChanges();
  573. return "success";
  574. }
  575. public void AddAct(int posid = 0)
  576. {
  577. WebCMSEntities db = new WebCMSEntities();
  578. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  579. if (pos != null)
  580. {
  581. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  582. if (merchant != null)
  583. {
  584. string ParentNav = "";
  585. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  586. if (user != null)
  587. {
  588. int GetUserId = user.Id;
  589. ParentNav = user.ParentNav;
  590. int TopUserId = 1;
  591. if (!string.IsNullOrEmpty(ParentNav))
  592. {
  593. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  594. if (ParentNavList.Length > 1)
  595. {
  596. TopUserId = int.Parse(ParentNavList[1]);
  597. }
  598. else if (ParentNavList.Length == 1)
  599. {
  600. TopUserId = int.Parse(ParentNavList[0]);
  601. }
  602. }
  603. List<decimal> prizes = new List<decimal>();
  604. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  605. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  606. {
  607. ActPrize = ActPrize / 100;
  608. }
  609. if (ActPrize > 0)
  610. {
  611. if (ActPrize == 99)
  612. {
  613. ActPrize = 100;
  614. }
  615. else if (ActPrize == 199)
  616. {
  617. ActPrize = 200;
  618. }
  619. else if (ActPrize == 299)
  620. {
  621. ActPrize = 300;
  622. }
  623. else if (ActPrize == 249)
  624. {
  625. ActPrize = 260;
  626. }
  627. prizes.Add(ActPrize);
  628. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  629. {
  630. prizes.Add(40);
  631. }
  632. }
  633. else if (pos.BrandId == 6 && ActPrize == 0) //立刷首台无押金机返50
  634. {
  635. prizes.Add(50);
  636. }
  637. else if ((pos.BrandId == 10 || pos.BrandId == 11) && pos.IsFirst == 1 && ActPrize == 0) //联动首台无押金机返50
  638. {
  639. prizes.Add(50);
  640. }
  641. else if (pos.BrandId == 12 && pos.IsFirst == 1 && ActPrize == 0) //盒易付首台无押金机返50
  642. {
  643. prizes.Add(50);
  644. }
  645. foreach (decimal prize in prizes)
  646. {
  647. int ChangeType = prize == 40 ? 12 : 0;
  648. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  649. if (!check)
  650. {
  651. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  652. db.ActiveReward.Add(new ActiveReward()
  653. {
  654. CreateDate = DateTime.Now,
  655. UpdateDate = DateTime.Now,
  656. UserId = GetUserId, //创客
  657. MerchantId = pos.BindMerchantId, //商户
  658. StandardDate = pos.ActivationTime, //达标日期
  659. RewardAmount = prize, //奖励金额
  660. BrandId = pos.BrandId, //品牌
  661. UserNav = ParentNav, //创客父级
  662. DirectBuddyNo = merchant.UserId, //商户直属创客
  663. KqMerNo = merchant.KqMerNo, //渠道商户编号
  664. KqSnNo = pos.PosSn, //渠道SN号
  665. SnType = pos.PosSnType, //机具类型
  666. SnApplyUserId = pos.BuyUserId, //机具申请创客
  667. ActType = 0, //激活类型
  668. SnStoreId = pos.StoreId, //SN仓库
  669. RewardTips = "激活奖励", //奖励描述
  670. Remark = "激活奖励", //备注
  671. ActDate = pos.ActivationTime, //激活时间
  672. TopUserId = TopUserId, //顶级创客
  673. SeoTitle = machineUser.RealName,
  674. });
  675. db.SaveChanges();
  676. string IdBrand = GetUserId + "_" + pos.BrandId;
  677. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  678. if (userData == null)
  679. {
  680. userData = db.UserMachineData.Add(new UserMachineData()
  681. {
  682. IdBrand = IdBrand,
  683. }).Entity;
  684. db.SaveChanges();
  685. }
  686. userData.ActProfit += prize;
  687. db.SaveChanges();
  688. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  689. if (account == null)
  690. {
  691. account = db.UserAccount.Add(new UserAccount()
  692. {
  693. Id = GetUserId,
  694. UserId = GetUserId,
  695. }).Entity;
  696. db.SaveChanges();
  697. }
  698. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  699. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  700. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  701. account.BalanceAmount += prize;
  702. account.TotalAmount += prize;
  703. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  704. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  705. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  706. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  707. {
  708. CreateDate = DateTime.Now,
  709. UpdateDate = DateTime.Now,
  710. UserId = GetUserId, //创客
  711. ChangeType = ChangeType, //变动类型
  712. ProductType = pos.BrandId, //产品类型
  713. ChangeAmount = prize, //变更金额
  714. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  715. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  716. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  717. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  718. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  719. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  720. }).Entity;
  721. db.SaveChanges();
  722. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  723. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  724. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  725. // 激活奖励列表
  726. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  727. if (!dates.Contains(dateString))
  728. {
  729. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  730. }
  731. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  732. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  733. if (!months.Contains(monthString))
  734. {
  735. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  736. }
  737. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  738. // 激活奖励详情
  739. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  740. if (!actPrizeList.Contains(pos.BindMerchantId))
  741. {
  742. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  743. }
  744. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  745. //收支明细
  746. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  747. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  748. }
  749. }
  750. }
  751. // }
  752. }
  753. }
  754. db.Dispose();
  755. }
  756. #endregion
  757. #region 设置商户代理
  758. public IActionResult SetMerAgent(string right)
  759. {
  760. ViewBag.RightInfo = RightInfo;
  761. ViewBag.right = right;
  762. return View();
  763. }
  764. [HttpPost]
  765. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  766. {
  767. if (string.IsNullOrEmpty(MakerCode))
  768. {
  769. return "请输入创客编号";
  770. }
  771. if (string.IsNullOrEmpty(PosSn))
  772. {
  773. return "请输入机具SN";
  774. }
  775. if (string.IsNullOrEmpty(MerNo))
  776. {
  777. return "请输入商户编号";
  778. }
  779. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  780. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  781. if (pos == null)
  782. {
  783. return "机具SN不存在";
  784. }
  785. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  786. if (user == null)
  787. {
  788. return "创客编号不存在";
  789. }
  790. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  791. if (merchant == null)
  792. {
  793. return "商户编号不存在";
  794. }
  795. pos.SeoTitle = user.Id.ToString();
  796. pos.UserId = user.Id;
  797. if (pos.BindMerchantId == 0)
  798. {
  799. pos.BindMerchantId = merchant.Id;
  800. if (IsSend == 1)
  801. {
  802. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  803. {
  804. UserId = pos.BuyUserId, //接收创客
  805. MsgType = 2,
  806. Title = "商户型代理设置成功", //标题
  807. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  808. CreateDate = DateTime.Now,
  809. }));
  810. }
  811. }
  812. user.MerchantType = 1;
  813. merchant.UserId = user.Id;
  814. merchant.MerUserType = 1;
  815. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  816. {
  817. CreateDate = DateTime.Now,
  818. IsRecyc = (ulong)pos.IsPurchase,
  819. CreditAmount = pos.CreditTrade,
  820. PosSnType = pos.PosSnType,
  821. ActDate = pos.ActivationTime,
  822. BindDate = pos.BindingTime,
  823. ActStatus = (ulong)pos.ActivationState,
  824. BindStatus = (ulong)pos.BindingState,
  825. MerNo = MerNo,
  826. PosSn = pos.PosSn,
  827. Note = "后台设置商户型创客",
  828. ToUserId = user.Id,
  829. FromUserId = pos.BuyUserId,
  830. });
  831. db.SaveChanges();
  832. return "success";
  833. }
  834. #endregion
  835. #region 取消商户代理
  836. public IActionResult CancelMerAgent(string right)
  837. {
  838. ViewBag.RightInfo = RightInfo;
  839. ViewBag.right = right;
  840. return View();
  841. }
  842. [HttpPost]
  843. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  844. {
  845. if (string.IsNullOrEmpty(MakerCode))
  846. {
  847. return "请输入创客编号";
  848. }
  849. if (string.IsNullOrEmpty(PosSn))
  850. {
  851. return "请输入机具SN";
  852. }
  853. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  854. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  855. if (pos == null)
  856. {
  857. return "机具SN不存在";
  858. }
  859. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  860. if (user == null)
  861. {
  862. return "创客编号不存在";
  863. }
  864. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  865. pos.UserId = pos.BuyUserId;
  866. merchant.UserId = pos.BuyUserId;
  867. merchant.MerUserType = 0;
  868. user.MerchantType = 0;
  869. db.SaveChanges();
  870. if (pos.BindMerchantId == 0)
  871. {
  872. pos.BindMerchantId = merchant.Id;
  873. if (IsSend == 1)
  874. {
  875. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  876. {
  877. UserId = pos.BuyUserId, //接收创客
  878. MsgType = 2,
  879. Title = "商户型代理取消成功", //标题
  880. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  881. CreateDate = DateTime.Now,
  882. }));
  883. }
  884. }
  885. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  886. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  887. return "success";
  888. }
  889. #endregion
  890. #region 查看SP原始数据日志
  891. public IActionResult SeeSpLog(string right)
  892. {
  893. ViewBag.RightInfo = RightInfo;
  894. ViewBag.right = right;
  895. return View();
  896. }
  897. #endregion
  898. #region 查询机具信息
  899. public IActionResult SeeSnDetail(string right)
  900. {
  901. ViewBag.RightInfo = RightInfo;
  902. ViewBag.right = right;
  903. return View();
  904. }
  905. [HttpPost]
  906. public string SeeSnDetailDo(string PosSn)
  907. {
  908. if (string.IsNullOrEmpty(PosSn))
  909. {
  910. return "请输入机具SN";
  911. }
  912. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  913. if (pos == null)
  914. {
  915. return "机具SN不存在";
  916. }
  917. if (pos.Status == -1)
  918. {
  919. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  920. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  921. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11 && pos.BrandId != 12)
  922. {
  923. Deposits = Deposits / 100;
  924. }
  925. string DepositGets = "未领取";
  926. string DepositUsers = "";
  927. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  928. if (rewards.Id > 0)
  929. {
  930. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  931. DepositGets = "已领取";
  932. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  933. }
  934. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  935. var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  936. string results = "该机具为故障机" + "\n";
  937. results += "所在仓库:" + storeInfo.StoreNo + "\n";
  938. results += "仓库名称:" + storeInfo.StoreName + "\n";
  939. results += "服务费返现实际返现对象:" + DepositUsers + "\n";
  940. results += "服务费:" + Deposits + "\n";
  941. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  942. return results;
  943. }
  944. string merInfo = "";
  945. string merName = "";
  946. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  947. if (mer != null)
  948. {
  949. merInfo = mer.KqMerNo;
  950. merName = mer.MerchantName;
  951. }
  952. else
  953. {
  954. merInfo = "未找到商户";
  955. }
  956. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  957. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  958. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  959. int TopUserId = 0;
  960. if (!string.IsNullOrEmpty(posUser.ParentNav))
  961. {
  962. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  963. if (ParentNavs.Length > 1)
  964. {
  965. TopUserId = int.Parse(ParentNavs[1]);
  966. }
  967. if (ParentNavs.Length == 1)
  968. {
  969. TopUserId = int.Parse(ParentNavs[0]);
  970. }
  971. }
  972. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  973. string bindResult = "", bindTime = "";
  974. if (pos.BindingState == 0)
  975. {
  976. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  977. if (bind != null)
  978. {
  979. if (bind.Status != 1)
  980. {
  981. bindResult = "执行中";
  982. }
  983. }
  984. else
  985. {
  986. bindResult = "未绑定";
  987. }
  988. }
  989. else
  990. {
  991. bindResult = "已绑定";
  992. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  993. }
  994. string activeResult = "", activeTime = "";
  995. if (pos.ActivationState == 0)
  996. {
  997. if (pos.CreditTrade < 1000)
  998. {
  999. activeResult = "未刷满1000";
  1000. }
  1001. else if (pos.TransferTime == null)
  1002. {
  1003. activeResult = "未激活, 需补录";
  1004. }
  1005. }
  1006. else
  1007. {
  1008. activeResult = "已激活";
  1009. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1010. }
  1011. string tradeAmount = pos.CreditTrade.ToString();
  1012. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1013. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11 && pos.BrandId != 12)
  1014. {
  1015. Deposit = Deposit / 100;
  1016. }
  1017. string DepositGet = "未领取";
  1018. string DepositUser = "";
  1019. string DepositToUser = "";
  1020. decimal headAmount = 0;
  1021. decimal footAmount = 0;
  1022. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1023. if (reward.Id > 0)
  1024. {
  1025. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1026. DepositGet = "已领取";
  1027. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1028. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1029. if (fAmount != null)
  1030. {
  1031. headAmount = fAmount.RewardAmount;
  1032. }
  1033. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1034. if (lAmount != null)
  1035. {
  1036. footAmount = lAmount.RewardAmount;
  1037. }
  1038. }
  1039. string DepositGet6 = "未领取";
  1040. string DepositUser6 = "";
  1041. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1042. if (lisreward.Id > 0)
  1043. {
  1044. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1045. DepositGet6 = "已领取";
  1046. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1047. }
  1048. string FluxGet6 = "未领取";
  1049. string FluxUser6 = "";
  1050. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1051. if (flux.Id > 0)
  1052. {
  1053. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1054. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1055. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1056. }
  1057. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1058. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
  1059. string OpenUser10 = "未领取";
  1060. string OpenUser20 = "未领取";
  1061. string Leader10 = "未领取";
  1062. string YYZX5 = "未领取";
  1063. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1064. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1065. if (openreward.Id > 0)
  1066. {
  1067. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1068. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + "发放时间:" + openreward.CreateDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  1069. }
  1070. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1071. if (openreward.Id > 0)
  1072. {
  1073. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1074. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1075. }
  1076. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1077. if (leader10.Id > 0)
  1078. {
  1079. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1080. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1081. }
  1082. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1083. if (yyzx5.Id > 0)
  1084. {
  1085. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1086. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1087. }
  1088. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1089. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1090. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1091. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1092. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1093. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1094. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1095. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1096. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1097. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1098. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1099. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1100. string result = "";
  1101. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1102. result += "\n";
  1103. result += "机具SN:" + pos.PosSn + "\n";
  1104. string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
  1105. result += "机具类型:" + PosSnType + "\n";
  1106. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1107. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
  1108. if (change.Id > 0)
  1109. {
  1110. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1111. }
  1112. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
  1113. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1114. if (pos.PreUserId > 0)
  1115. {
  1116. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1117. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1118. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1119. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
  1120. }
  1121. else
  1122. {
  1123. result += "机具所属小分仓:暂无小分仓\n";
  1124. }
  1125. result += "入库时间:" + CreateDate + "\n";
  1126. result += "循环到期时间:" + RecycEndDate + "\n";
  1127. result += "划拨时间:" + TransferTime + "\n";
  1128. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1129. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1130. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1131. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1132. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1133. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1134. result += "服务费:" + Deposit + "\n";
  1135. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1136. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
  1137. result += "服务费返现应返现对象:" + DepositToUser + "\n";
  1138. result += "服务费返现实际返现对象:" + DepositUser + "\n";
  1139. if (pos.BrandId == 6)
  1140. {
  1141. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1142. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1143. }
  1144. result += "流量费:" + FluxGet6 + "\n";
  1145. result += "流量费发放对象:" + FluxUser6 + "\n";
  1146. result += "开机奖20:" + OpenUser20 + "\n";
  1147. result += "盟主奖:" + Leader10 + "\n";
  1148. result += "运营中心奖:" + YYZX5 + "\n";
  1149. return result;
  1150. }
  1151. #endregion
  1152. #region 生成机具兑换码
  1153. public IActionResult MakeCoupons(string right)
  1154. {
  1155. ViewBag.RightInfo = RightInfo;
  1156. ViewBag.right = right;
  1157. return View();
  1158. }
  1159. [HttpPost]
  1160. public string MakeCouponsDo(int Kind, int Number)
  1161. {
  1162. DateTime checkTime = DateTime.Parse("1900-01-01");
  1163. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1164. if (!string.IsNullOrEmpty(checkTimeString))
  1165. {
  1166. checkTime = DateTime.Parse(checkTimeString);
  1167. }
  1168. if (checkTime.AddHours(1) < DateTime.Now)
  1169. {
  1170. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1171. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1172. return "生成程序已执行";
  1173. }
  1174. return "请稍后再试";
  1175. }
  1176. #endregion
  1177. #region 导出没有刷满1000的机具
  1178. public IActionResult ExportPos(string right)
  1179. {
  1180. ViewBag.RightInfo = RightInfo;
  1181. ViewBag.right = right;
  1182. return View();
  1183. }
  1184. [HttpPost]
  1185. public JsonResult ExportPosDo()
  1186. {
  1187. WebCMSEntities db = new WebCMSEntities();
  1188. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1189. int total = poses.Count;
  1190. int index = 0;
  1191. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1192. foreach (PosMachinesTwo pos in poses)
  1193. {
  1194. index += 1;
  1195. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1196. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1197. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1198. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1199. Dictionary<string, object> item = new Dictionary<string, object>();
  1200. string TopRealName = "";
  1201. string TopMakerCode = "";
  1202. string TopMobile = "";
  1203. string ParentNav = user.ParentNav;
  1204. if (!string.IsNullOrEmpty(ParentNav))
  1205. {
  1206. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1207. if (navlist.Length > 1)
  1208. {
  1209. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1210. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1211. TopRealName = tuser.RealName;
  1212. TopMakerCode = tuser.MakerCode;
  1213. TopMobile = tuser.Mobile;
  1214. }
  1215. }
  1216. item.Add("TopRealName", TopRealName); //顶级姓名
  1217. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1218. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1219. item.Add("UpRealName", puser.RealName); //上级姓名
  1220. item.Add("RealName", user.RealName); //代理姓名
  1221. item.Add("MakerCode", user.MakerCode); //代理编号
  1222. item.Add("Mobile", user.Mobile); //代理手机号
  1223. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1224. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1225. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1226. item.Add("Sn", pos.PosSn); //SN
  1227. list.Add(item);
  1228. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1229. }
  1230. db.Dispose();
  1231. Dictionary<string, object> result = new Dictionary<string, object>();
  1232. result.Add("Status", "1");
  1233. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1234. result.Add("Obj", list);
  1235. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1236. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1237. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1238. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1239. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1240. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1241. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1242. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1243. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1244. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1245. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1246. ReturnFields.Add("Sn", "SN"); //SN
  1247. result.Add("Fields", ReturnFields);
  1248. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1249. return Json(result);
  1250. }
  1251. public string ExportPosCheck()
  1252. {
  1253. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1254. if (content == "finish")
  1255. {
  1256. RedisDbconn.Instance.Clear("ExportPosCheck");
  1257. }
  1258. return content;
  1259. }
  1260. #endregion
  1261. #region 更换机具
  1262. public IActionResult ChangePos(string right)
  1263. {
  1264. ViewBag.RightInfo = RightInfo;
  1265. ViewBag.right = right;
  1266. return View();
  1267. }
  1268. [HttpPost]
  1269. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1270. {
  1271. if (string.IsNullOrEmpty(OldSn))
  1272. {
  1273. return "请输入原机具SN";
  1274. }
  1275. if (string.IsNullOrEmpty(NewSn))
  1276. {
  1277. return "请输入新机具SN";
  1278. }
  1279. if (string.IsNullOrEmpty(MerNo))
  1280. {
  1281. return "请输入商户编号";
  1282. }
  1283. string[] OldSnList = OldSn.Split('\n');
  1284. string[] NewSnList = NewSn.Split('\n');
  1285. if (OldSnList.Length != NewSnList.Length)
  1286. {
  1287. return "原机具SN数量和新机具SN数量不一致";
  1288. }
  1289. WebCMSEntities db = new WebCMSEntities();
  1290. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1291. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1292. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1293. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1294. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1295. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1296. KqProducts oldPosBrand = new KqProducts();
  1297. KqProducts newPosBrand = new KqProducts();
  1298. MachineChange add = db.MachineChange.Add(new MachineChange()
  1299. {
  1300. CreateDate = DateTime.Now,
  1301. UpdateDate = DateTime.Now,
  1302. CreateMan = SysUserName + "-" + SysRealName,
  1303. ChangeNo = ChangeNo, //转换单号
  1304. UserId = 0, //创客
  1305. ChangeTime = DateTime.Now, //转换时间
  1306. BackStoreId = BackStore.Id, //退回仓库
  1307. BackStoreName = BackStore.StoreName, //退回仓库名称
  1308. Remark = "机具更换", //订单备注
  1309. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1310. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1311. OutProductName = OutStore.ProductName, //出库产品名称
  1312. OutStoreId = OutStore.Id, //出库仓库
  1313. OutStoreName = OutStore.StoreName, //出库仓库名称
  1314. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1315. OutStoreAddress = OutStore.Address, //出库仓库地址
  1316. OutStoreManager = "", //出库仓库联系人
  1317. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1318. }).Entity;
  1319. db.SaveChanges();
  1320. int BackProductType = 0;
  1321. string BackProductName = "";
  1322. string ChangeDeviceName = "";
  1323. string ChangeSnExpand = "";
  1324. for (int i = 0; i < OldSnList.Length; i++)
  1325. {
  1326. string OldSnNum = OldSnList[i];
  1327. string NewSnNum = NewSnList[i];
  1328. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1329. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1330. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1331. if (oldpos == null)
  1332. {
  1333. return "原机具SN不正确";
  1334. }
  1335. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
  1336. if (newpos == null)
  1337. {
  1338. return "新机具SN不正确或不满足条件";
  1339. }
  1340. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1341. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1342. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1343. if (merchant == null)
  1344. {
  1345. CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
  1346. }
  1347. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1348. newpos.BindMerchantId = merchant.Id;
  1349. newpos.BuyUserId = oldpos.BuyUserId;
  1350. newpos.UserId = oldpos.UserId;
  1351. newpos.RecycEndDate = oldpos.RecycEndDate;
  1352. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1353. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1354. newpos.CreditTrade = oldpos.CreditTrade;
  1355. newpos.PosSnType = oldpos.PosSnType;
  1356. newpos.TransferTime = oldpos.TransferTime;
  1357. newpos.IsPurchase = oldpos.IsPurchase;
  1358. newpos.BindingState = oldpos.BindingState;
  1359. newpos.ActivationState = oldpos.ActivationState;
  1360. newpos.BindingTime = oldpos.BindingTime;
  1361. newpos.ActivationTime = oldpos.ActivationTime;
  1362. newpos.IsFirst = oldpos.IsFirst;
  1363. newpos.SeoKeyword = oldpos.SeoKeyword;
  1364. newpos.PrizeParams = oldpos.PrizeParams;
  1365. newpos.LeaderUserId = oldpos.LeaderUserId;
  1366. oldpos.Status = -1;
  1367. //对应调整客小爽企业版数据
  1368. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1369. if (posInfo != null)
  1370. {
  1371. posInfo.PosSn = newpos.PosSn;
  1372. posInfo.PosId = newpos.Id;
  1373. db.SaveChanges();
  1374. }
  1375. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1376. if (forMerNo != null)
  1377. {
  1378. forMerNo.SnId = newpos.Id;
  1379. }
  1380. merchant.KqSnNo = NewSn;
  1381. merchant.ActiveStatus = newpos.ActivationState;
  1382. merchant.MerStandardDate = newpos.ActivationTime;
  1383. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1384. {
  1385. CreateDate = DateTime.Now,
  1386. UpdateDate = DateTime.Now,
  1387. CreateMan = SysUserName + "-" + SysRealName,
  1388. ChangeNo = ChangeNo, //订单号
  1389. ChangeId = add.Id, //订单Id
  1390. BackProductType = oldpos.BrandId, //退回产品类型
  1391. BackProductName = oldPosBrand.Name, //退回产品名称
  1392. UserId = 0, //创客
  1393. BackSnNo = oldpos.PosSn, //设备SN编号
  1394. OutProductType = newpos.BrandId, //出库产品类型
  1395. OutProductName = newPosBrand.Name, //出库产品名称
  1396. OutSnNo = newpos.PosSn, //出库设备SN编号
  1397. OutSnType = newpos.PosSnType, //出库SN机具类型
  1398. Remark = "机具更换", //备注
  1399. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1400. });
  1401. db.SaveChanges();
  1402. BackProductType = oldpos.BrandId;
  1403. BackProductName = newPosBrand.Name;
  1404. ChangeDeviceName = oldpos.DeviceName;
  1405. ChangeSnExpand += oldpos.PosSn + "\n";
  1406. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1407. }
  1408. add.BackProductType = BackProductType; //退回产品类型
  1409. add.BackProductName = BackProductName; //退回产品名称
  1410. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1411. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1412. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1413. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1414. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1415. db.SaveChanges();
  1416. db.Dispose();
  1417. if (IsSend == 1)
  1418. {
  1419. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1420. {
  1421. UserId = pos.BuyUserId, //接收创客
  1422. MsgType = 2,
  1423. Title = "换绑成功通知", //标题
  1424. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1425. CreateDate = DateTime.Now,
  1426. }));
  1427. }
  1428. return "success";
  1429. }
  1430. #endregion
  1431. #region 坏机换新
  1432. public IActionResult ChangeBadPos(string right)
  1433. {
  1434. ViewBag.RightInfo = RightInfo;
  1435. ViewBag.right = right;
  1436. return View();
  1437. }
  1438. [HttpPost]
  1439. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1440. {
  1441. string[] OldSnList;
  1442. string[] NewSnList;
  1443. decimal amount = 0;
  1444. List<string> opData = new List<string>();
  1445. //创客坏机换新
  1446. if (ChangeType == "0")
  1447. {
  1448. if (string.IsNullOrEmpty(MakerCode))
  1449. {
  1450. return "请输入创客编号";
  1451. }
  1452. if (string.IsNullOrEmpty(OldSn))
  1453. {
  1454. return "请输入坏机SN";
  1455. }
  1456. if (string.IsNullOrEmpty(NewSn))
  1457. {
  1458. return "请输入新机SN";
  1459. }
  1460. if (string.IsNullOrEmpty(FromStoreNo))
  1461. {
  1462. return "请输入新机发货仓库编号";
  1463. }
  1464. if (string.IsNullOrEmpty(BackStoreNo))
  1465. {
  1466. return "请输入坏机退回仓库编号";
  1467. }
  1468. OldSnList = OldSn.Split('\n');
  1469. NewSnList = NewSn.Split('\n');
  1470. if (OldSnList.Length != NewSnList.Length)
  1471. {
  1472. return "原机具SN数量和新机具SN数量不一致";
  1473. }
  1474. for (int i = 0; i < OldSnList.Length; i++)
  1475. {
  1476. string OldSnNum = OldSnList[i];
  1477. string NewSnNum = NewSnList[i];
  1478. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1479. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1480. if (storeForCodeFrom.StoreId == 0)
  1481. {
  1482. return "您输入的新机发货仓库编号不存在";
  1483. }
  1484. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1485. if (storeForCodeBack.StoreId == 0)
  1486. {
  1487. return "您输入的坏机退回仓库编号不存在";
  1488. }
  1489. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1490. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1491. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1492. if (oldpos.Id == 0)
  1493. {
  1494. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1495. }
  1496. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1497. if (newpos.Id == 0)
  1498. {
  1499. return "您输入的新机SN不存在或不满足条件";
  1500. }
  1501. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1502. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1503. {
  1504. return "您输入的新机发货仓库不符新机机具对应品牌";
  1505. }
  1506. if (newpos.StoreId != storeFrom.Id)
  1507. {
  1508. return "您输入的新机SN不在新机发货仓库";
  1509. }
  1510. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1511. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1512. {
  1513. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1514. }
  1515. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1516. {
  1517. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1518. }
  1519. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1520. if (brandInfo.Name.Contains("大POS"))
  1521. {
  1522. amount = 300;
  1523. }
  1524. if (brandInfo.Name.Contains("电签"))
  1525. {
  1526. amount = 200;
  1527. }
  1528. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1529. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1530. storeFromUserAcount.ValidAmount += amount;
  1531. storeBackUserAcount.ValidAmount -= amount;
  1532. newpos.BuyUserId = oldpos.BuyUserId;
  1533. newpos.UserId = oldpos.UserId;
  1534. newpos.RecycEndDate = oldpos.RecycEndDate;
  1535. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1536. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1537. newpos.CreditTrade = oldpos.CreditTrade;
  1538. newpos.PosSnType = oldpos.PosSnType;
  1539. newpos.TransferTime = oldpos.TransferTime;
  1540. newpos.IsPurchase = oldpos.IsPurchase;
  1541. newpos.BindingState = oldpos.BindingState;
  1542. newpos.ActivationState = oldpos.ActivationState;
  1543. newpos.BindingTime = oldpos.BindingTime;
  1544. newpos.ActivationTime = oldpos.ActivationTime;
  1545. newpos.IsFirst = oldpos.IsFirst;
  1546. newpos.SeoKeyword = oldpos.SeoKeyword;
  1547. newpos.PrizeParams = oldpos.PrizeParams;
  1548. newpos.LeaderUserId = oldpos.LeaderUserId;
  1549. newpos.BindMerchantId = oldpos.BindMerchantId;
  1550. newpos.StoreId = oldpos.StoreId;
  1551. newpos.UserId = oldpos.UserId;
  1552. newpos.PreUserId = oldpos.PreUserId;
  1553. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1554. {
  1555. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1556. }
  1557. oldpos.StoreId = storeBack.Id;
  1558. oldpos.QueryCount = 0;
  1559. oldpos.UpdateDate = null;
  1560. oldpos.ActivityList = null;
  1561. oldpos.SeoKeyword = null;
  1562. oldpos.SeoDescription = null;
  1563. oldpos.OrderId = 0;
  1564. oldpos.RecycEndDate = null;
  1565. oldpos.RecycBackCount = 0;
  1566. oldpos.PrizeParams = null;
  1567. oldpos.ScanQrTrade = 0;
  1568. oldpos.BindMerchantId = 0;
  1569. oldpos.CreditTrade = 0;
  1570. oldpos.DebitCardTrade = 0;
  1571. oldpos.IsVip = 0;
  1572. oldpos.UserNav = null;
  1573. oldpos.TransferTime = null;
  1574. oldpos.IsPurchase = 0;
  1575. oldpos.Detail = null;
  1576. oldpos.BindingTime = null;
  1577. oldpos.BindingState = 0;
  1578. oldpos.ActivationTime = null;
  1579. oldpos.ActivationState = 0;
  1580. oldpos.LeaderUserId = 0;
  1581. oldpos.PreUserId = 0;
  1582. oldpos.IsFirst = 0;
  1583. oldpos.DownFeeMan = null;
  1584. oldpos.DownFeeFlag = 0;
  1585. oldpos.DownFeeDate = null;
  1586. oldpos.UpFeeMan = null;
  1587. oldpos.UpFeeFlag = 0;
  1588. oldpos.UpFeeDate = null;
  1589. oldpos.OpReserve1 = 0;
  1590. oldpos.OpReserve2 = 0;
  1591. oldpos.OpReserve3 = 0;
  1592. oldpos.OpId = 0;
  1593. oldpos.RecycStartDate = null;
  1594. oldpos.SourcePosSn = null;
  1595. oldpos.BuyUserId = 0;
  1596. oldpos.UserId = 0;
  1597. oldpos.Status = -1;
  1598. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1599. db.SaveChanges();
  1600. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1601. if (merchant != null)
  1602. {
  1603. merchant.KqSnNo = newpos.PosSn;
  1604. merchant.ActiveStatus = newpos.ActivationState;
  1605. }
  1606. db.SaveChanges();
  1607. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1608. {
  1609. CreateDate = DateTime.Now,
  1610. CreateMan = SysUserName + "-" + SysRealName,
  1611. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1612. OutStoreId = storeFrom.Id,
  1613. BackStoreId = storeBack.Id,
  1614. OutProductType = newpos.BrandId,
  1615. BackProductType = oldpos.BrandId,
  1616. UserId = userForMakerCode.UserId, //创客
  1617. }).Entity;
  1618. db.SaveChanges();
  1619. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1620. {
  1621. CreateDate = DateTime.Now,
  1622. CreateMan = SysUserName + "-" + SysRealName,
  1623. OutSnNo = OldSnNum,
  1624. BackSnNo = NewSnNum,
  1625. ChangeNo = add.ChangeNo, //转换单号
  1626. ChangeId = add.Id, //转换记录Id
  1627. UserId = add.UserId, //创客
  1628. }).Entity;
  1629. db.SaveChanges();
  1630. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1631. if (IsSend == 1)
  1632. {
  1633. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1634. {
  1635. UserId = userForMakerCode.UserId, //接收创客
  1636. MsgType = 2,
  1637. Title = "坏机换新成功通知", //标题
  1638. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1639. CreateDate = DateTime.Now,
  1640. }));
  1641. }
  1642. }
  1643. }
  1644. //仓库坏机换新
  1645. else
  1646. {
  1647. if (string.IsNullOrEmpty(StoreCode))
  1648. {
  1649. return "请输入仓库编号";
  1650. }
  1651. if (string.IsNullOrEmpty(OldSn))
  1652. {
  1653. return "请输入坏机SN";
  1654. }
  1655. if (string.IsNullOrEmpty(NewSn))
  1656. {
  1657. return "请输入新机SN";
  1658. }
  1659. if (string.IsNullOrEmpty(FromStoreNo))
  1660. {
  1661. return "请输入新机发货仓库编号";
  1662. }
  1663. if (string.IsNullOrEmpty(BackStoreNo))
  1664. {
  1665. return "请输入坏机退回仓库编号";
  1666. }
  1667. OldSnList = OldSn.Split('\n');
  1668. NewSnList = NewSn.Split('\n');
  1669. if (OldSnList.Length != NewSnList.Length)
  1670. {
  1671. return "原机具SN数量和新机具SN数量不一致";
  1672. }
  1673. for (int i = 0; i < OldSnList.Length; i++)
  1674. {
  1675. string OldSnNum = OldSnList[i];
  1676. string NewSnNum = NewSnList[i];
  1677. StoreHouse store = new StoreHouse();
  1678. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1679. if (storeForBadCode.StoreId > 0)
  1680. {
  1681. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1682. }
  1683. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1684. if (storeForCodeFrom.StoreId == 0)
  1685. {
  1686. return "您输入的新机发货仓库编号不存在";
  1687. }
  1688. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1689. if (storeForCodeBack.StoreId == 0)
  1690. {
  1691. return "您输入的坏机退回仓库编号不存在";
  1692. }
  1693. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1694. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1695. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1696. if (oldpos.Id == 0)
  1697. {
  1698. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1699. }
  1700. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1701. if (newpos.Id == 0)
  1702. {
  1703. return "您输入的新机SN不存在或不满足条件";
  1704. }
  1705. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1706. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1707. {
  1708. return "您输入的新机发货仓库不符新机机具对应品牌";
  1709. }
  1710. if (newpos.StoreId != storeFrom.Id)
  1711. {
  1712. return "您输入的新机SN不在新机发货仓库";
  1713. }
  1714. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1715. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1716. {
  1717. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1718. }
  1719. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1720. if (brandInfo.Name.Contains("大POS"))
  1721. {
  1722. amount = 300;
  1723. }
  1724. if (brandInfo.Name.Contains("电签"))
  1725. {
  1726. amount = 200;
  1727. }
  1728. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1729. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1730. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1731. storeFromUserAcount.ValidAmount += amount;
  1732. storeBackUserAcount.ValidAmount -= amount;
  1733. newpos.StoreId = oldpos.StoreId;
  1734. newpos.BuyUserId = oldpos.BuyUserId;
  1735. newpos.UserId = oldpos.UserId;
  1736. newpos.LeaderUserId = oldpos.LeaderUserId;
  1737. newpos.PreUserId = oldpos.PreUserId;
  1738. newpos.IsFirst = oldpos.IsFirst;
  1739. newpos.TransferTime = oldpos.TransferTime;
  1740. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1741. {
  1742. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1743. }
  1744. oldpos.StoreId = storeBack.Id;
  1745. oldpos.QueryCount = 0;
  1746. oldpos.UpdateDate = null;
  1747. oldpos.ActivityList = null;
  1748. oldpos.SeoKeyword = null;
  1749. oldpos.SeoDescription = null;
  1750. oldpos.OrderId = 0;
  1751. oldpos.RecycEndDate = null;
  1752. oldpos.RecycBackCount = 0;
  1753. oldpos.PrizeParams = null;
  1754. oldpos.ScanQrTrade = 0;
  1755. oldpos.BindMerchantId = 0;
  1756. oldpos.CreditTrade = 0;
  1757. oldpos.DebitCardTrade = 0;
  1758. oldpos.IsVip = 0;
  1759. oldpos.UserNav = null;
  1760. oldpos.TransferTime = null;
  1761. oldpos.IsPurchase = 0;
  1762. oldpos.Detail = null;
  1763. oldpos.BindingTime = null;
  1764. oldpos.BindingState = 0;
  1765. oldpos.ActivationTime = null;
  1766. oldpos.ActivationState = 0;
  1767. oldpos.LeaderUserId = 0;
  1768. oldpos.PreUserId = 0;
  1769. oldpos.IsFirst = 0;
  1770. oldpos.DownFeeMan = null;
  1771. oldpos.DownFeeFlag = 0;
  1772. oldpos.DownFeeDate = null;
  1773. oldpos.UpFeeMan = null;
  1774. oldpos.UpFeeFlag = 0;
  1775. oldpos.UpFeeDate = null;
  1776. oldpos.OpReserve1 = 0;
  1777. oldpos.OpReserve2 = 0;
  1778. oldpos.OpReserve3 = 0;
  1779. oldpos.OpId = 0;
  1780. oldpos.RecycStartDate = null;
  1781. oldpos.SourcePosSn = null;
  1782. oldpos.BuyUserId = 0;
  1783. oldpos.UserId = 0;
  1784. oldpos.Status = -1;
  1785. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1786. db.SaveChanges();
  1787. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1788. {
  1789. CreateDate = DateTime.Now,
  1790. CreateMan = SysUserName + "-" + SysRealName,
  1791. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1792. OutStoreId = storeFrom.Id,
  1793. BackStoreId = storeBack.Id,
  1794. OutProductType = newpos.BrandId,
  1795. BackProductType = oldpos.BrandId,
  1796. UserId = store.UserId, //创客
  1797. }).Entity;
  1798. db.SaveChanges();
  1799. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1800. {
  1801. CreateDate = DateTime.Now,
  1802. CreateMan = SysUserName + "-" + SysRealName,
  1803. OutSnNo = OldSnNum,
  1804. BackSnNo = NewSnNum,
  1805. ChangeNo = add.ChangeNo, //转换单号
  1806. ChangeId = add.Id, //转换记录Id
  1807. UserId = add.UserId, //创客
  1808. }).Entity;
  1809. db.SaveChanges();
  1810. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1811. if (IsSend == 1)
  1812. {
  1813. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1814. {
  1815. UserId = store.UserId, //接收创客
  1816. MsgType = 2,
  1817. Title = "坏机换新成功通知", //标题
  1818. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1819. CreateDate = DateTime.Now,
  1820. }));
  1821. }
  1822. }
  1823. }
  1824. foreach (string sub in opData)
  1825. {
  1826. string[] datalist = sub.Split(":");
  1827. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  1828. }
  1829. return "success";
  1830. }
  1831. #endregion
  1832. #region 机具解绑
  1833. public IActionResult Unbind(string right)
  1834. {
  1835. ViewBag.RightInfo = RightInfo;
  1836. ViewBag.right = right;
  1837. return View();
  1838. }
  1839. [HttpPost]
  1840. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1841. {
  1842. if (string.IsNullOrEmpty(PosSn))
  1843. {
  1844. return "请输入机具SN";
  1845. }
  1846. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1847. if (forSnNo == null)
  1848. {
  1849. return "机具SN不存在";
  1850. }
  1851. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  1852. if (pos == null)
  1853. {
  1854. return "机具SN不存在";
  1855. }
  1856. if (pos.ActivationState == 1)
  1857. {
  1858. return "机具已激活,不能解绑";
  1859. }
  1860. if (pos.BuyUserId == 0)
  1861. {
  1862. return "机具是仓库机,不支持解绑";
  1863. }
  1864. if (pos.BindingState == 0)
  1865. {
  1866. return "机具未绑定,不支持解绑";
  1867. }
  1868. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  1869. {
  1870. return "机具绑定已超过30天,不支持解绑";
  1871. }
  1872. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  1873. {
  1874. return "该机具已交易,无法解绑";
  1875. }
  1876. if (pos.BrandId != 10 || pos.BrandId != 11)
  1877. {
  1878. if (string.IsNullOrEmpty(MakerCode))
  1879. {
  1880. return "请输入创客编号";
  1881. }
  1882. if (string.IsNullOrEmpty(MerNo))
  1883. {
  1884. return "请输入商户编号";
  1885. }
  1886. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1887. if (forMakerCode == null)
  1888. {
  1889. return "创客不存在";
  1890. }
  1891. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1892. if (forMerNo == null)
  1893. {
  1894. return "商户编号不存在";
  1895. }
  1896. if (pos.BuyUserId != forMakerCode.UserId)
  1897. {
  1898. return "机具SN和创客不匹配";
  1899. }
  1900. if (forMerNo != null)
  1901. {
  1902. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1903. if (merchant != null)
  1904. {
  1905. //机具解绑删除客小爽企业版对应数据
  1906. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  1907. if (merInfo != null)
  1908. {
  1909. db.BusinessPartnerMerchant.Remove(merInfo);
  1910. }
  1911. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  1912. if (posInfo != null)
  1913. {
  1914. db.BusinessPartnerPos.Remove(posInfo);
  1915. }
  1916. db.PosMerchantInfo.Remove(merchant);
  1917. }
  1918. db.MachineForMerNo.Remove(forMerNo);
  1919. db.SaveChanges();
  1920. }
  1921. }
  1922. else
  1923. {
  1924. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1925. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1926. if (forMerNo != null && posMerchantInfo != null)
  1927. {
  1928. //机具解绑删除客小爽企业版对应数据
  1929. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  1930. if (merInfo != null)
  1931. {
  1932. db.BusinessPartnerMerchant.Remove(merInfo);
  1933. }
  1934. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  1935. if (posInfo != null)
  1936. {
  1937. db.BusinessPartnerPos.Remove(posInfo);
  1938. }
  1939. db.PosMerchantInfo.Remove(posMerchantInfo);
  1940. db.MachineForMerNo.Remove(forMerNo);
  1941. db.SaveChanges();
  1942. }
  1943. }
  1944. db.MachineUnBind.Add(new MachineUnBind()
  1945. {
  1946. CreateDate = DateTime.Now,
  1947. SeoTitle = SysUserName + "-" + SysRealName,
  1948. MerchantId = pos.BindMerchantId,
  1949. AuditDate = DateTime.Now,
  1950. AuditDesc = "平台操作解绑",
  1951. AuditStatus = 1,
  1952. SnNo = pos.PosSn,
  1953. BrandId = pos.BrandId,
  1954. UserId = pos.BuyUserId,
  1955. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1956. });
  1957. pos.BindMerchantId = 0;
  1958. pos.BindingState = 0;
  1959. pos.BindingTime = DateTime.Parse("1900-01-01");
  1960. pos.UserId = pos.BuyUserId;
  1961. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1962. db.SaveChanges();
  1963. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1964. if (IsSend == 1)
  1965. {
  1966. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1967. {
  1968. UserId = pos.BuyUserId, //接收创客
  1969. MsgType = 2,
  1970. Title = "解绑成功通知", //标题
  1971. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  1972. CreateDate = DateTime.Now,
  1973. }));
  1974. }
  1975. return "success";
  1976. }
  1977. #endregion
  1978. #region 通过券码修改盟主标记
  1979. public IActionResult ChangeSignQuan(string right)
  1980. {
  1981. ViewBag.RightInfo = RightInfo;
  1982. ViewBag.right = right;
  1983. return View();
  1984. }
  1985. [HttpPost]
  1986. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  1987. {
  1988. if (string.IsNullOrEmpty(Coupons))
  1989. {
  1990. return "请输入机具券码,多个券码用回车分隔";
  1991. }
  1992. if (string.IsNullOrEmpty(MakerCode))
  1993. {
  1994. return "请输入创客编号";
  1995. }
  1996. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1997. if (forMakerCode == null)
  1998. {
  1999. return "创客不存在";
  2000. }
  2001. string[] SnList = Coupons.Split('\n');
  2002. foreach (var item in SnList)
  2003. {
  2004. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2005. if (coupos == null)
  2006. {
  2007. return "机具券不存在";
  2008. }
  2009. else
  2010. {
  2011. coupos.LeaderUserId = forMakerCode.UserId;
  2012. }
  2013. }
  2014. db.SaveChanges();
  2015. return "success";
  2016. }
  2017. #endregion
  2018. #region 通过机具SN修改盟主标记
  2019. public IActionResult ChangeSignSn(string right)
  2020. {
  2021. ViewBag.RightInfo = RightInfo;
  2022. ViewBag.right = right;
  2023. return View();
  2024. }
  2025. [HttpPost]
  2026. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2027. {
  2028. if (string.IsNullOrEmpty(PosSn))
  2029. {
  2030. return "请输入机具SN,多个SN用回车分隔";
  2031. }
  2032. if (string.IsNullOrEmpty(MakerCode))
  2033. {
  2034. return "请输入创客编号";
  2035. }
  2036. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2037. if (forMakerCode == null)
  2038. {
  2039. return "创客不存在";
  2040. }
  2041. string[] SnList = PosSn.Split('\n');
  2042. foreach (var item in SnList)
  2043. {
  2044. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2045. if (pos == null)
  2046. {
  2047. return "该机具不存在";
  2048. }
  2049. else
  2050. {
  2051. pos.LeaderUserId = forMakerCode.UserId;
  2052. }
  2053. }
  2054. db.SaveChanges();
  2055. return "success";
  2056. }
  2057. #endregion
  2058. #region 机具循环列表
  2059. /// <summary>
  2060. /// 根据条件查询机具循环列表
  2061. /// </summary>
  2062. /// <returns></returns>
  2063. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2064. {
  2065. ViewBag.RightInfo = RightInfo;
  2066. ViewBag.right = right;
  2067. ViewBag.SwapSnExpand = SwapSnExpand;
  2068. ViewBag.SnNos = SnNos;
  2069. return View();
  2070. }
  2071. #endregion
  2072. #region 根据条件查询机具循环列表
  2073. /// <summary>
  2074. /// 机具循环列表
  2075. /// </summary>
  2076. /// <returns></returns>
  2077. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2078. {
  2079. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2080. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2081. Fields.Add("SnNos", "1"); //发货机具SN
  2082. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2083. if (!string.IsNullOrEmpty(SwapSnExpand))
  2084. {
  2085. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2086. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2087. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2088. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2089. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2090. for (int i = 0; i < SnNoList.Length; i++)
  2091. {
  2092. Dictionary<string, object> data = new Dictionary<string, object>();
  2093. data["ApplyNo"] = apply.ApplyNo;
  2094. data["OrderNo"] = order.OrderNo;
  2095. data["MakerCode"] = user.MakerCode;
  2096. data["RealName"] = user.RealName;
  2097. if (SnNoList.Length > i)
  2098. {
  2099. string SourceSn = SnNoList[i].Split(':')[0];
  2100. data["ComeSn"] = SnNoList[i];
  2101. data["ComeSnParam"] = SourceSn;
  2102. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2103. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2104. if (pos.LeaderUserId > 0)
  2105. {
  2106. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2107. data["ComeSnMakerCode"] = leader.MakerCode;
  2108. data["ComeSnRealName"] = leader.RealName;
  2109. }
  2110. }
  2111. if (OrderSnNo.Length > i)
  2112. {
  2113. string SendSn = OrderSnNo[i];
  2114. data["SendSn"] = OrderSnNo[i];
  2115. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2116. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2117. if (pos.LeaderUserId > 0)
  2118. {
  2119. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2120. data["SendSnMakerCode"] = leader.MakerCode;
  2121. data["SendSnRealName"] = leader.RealName;
  2122. }
  2123. }
  2124. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2125. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2126. dataList.Add(data);
  2127. }
  2128. }
  2129. else if (!string.IsNullOrEmpty(SnNos))
  2130. {
  2131. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2132. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2133. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2134. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2135. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2136. for (int i = 0; i < OrderSnNo.Length; i++)
  2137. {
  2138. Dictionary<string, object> data = new Dictionary<string, object>();
  2139. data["ApplyNo"] = apply.ApplyNo;
  2140. data["OrderNo"] = order.OrderNo;
  2141. data["MakerCode"] = user.MakerCode;
  2142. data["RealName"] = user.RealName;
  2143. if (SnNoList.Length > i)
  2144. {
  2145. string SourceSn = SnNoList[i].Split(':')[0];
  2146. data["ComeSn"] = SnNoList[i];
  2147. data["ComeSnParam"] = SourceSn;
  2148. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2149. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2150. if (pos.LeaderUserId > 0)
  2151. {
  2152. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2153. data["ComeSnMakerCode"] = leader.MakerCode;
  2154. data["ComeSnRealName"] = leader.RealName;
  2155. }
  2156. }
  2157. if (OrderSnNo.Length > i)
  2158. {
  2159. string SendSn = OrderSnNo[i];
  2160. data["SendSn"] = OrderSnNo[i];
  2161. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2162. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2163. if (pos.LeaderUserId > 0)
  2164. {
  2165. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2166. data["SendSnMakerCode"] = leader.MakerCode;
  2167. data["SendSnRealName"] = leader.RealName;
  2168. }
  2169. }
  2170. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2171. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2172. dataList.Add(data);
  2173. }
  2174. }
  2175. Dictionary<string, object> obj = new Dictionary<string, object>();
  2176. obj.Add("code", 0);
  2177. obj.Add("msg", "");
  2178. obj.Add("count", dataList.Count);
  2179. obj.Add("data", dataList);
  2180. return Json(obj);
  2181. }
  2182. #endregion
  2183. #region 查询机具循环
  2184. /// <summary>
  2185. /// 根据条件查询机具来源机具和券码
  2186. /// </summary>
  2187. /// <returns></returns>
  2188. public IActionResult SourceLoop(string right, string SnNos)
  2189. {
  2190. ViewBag.RightInfo = RightInfo;
  2191. ViewBag.right = right;
  2192. ViewBag.SnNos = SnNos;
  2193. return View();
  2194. }
  2195. #endregion
  2196. #region 根据条件查询机具来源机具和券码
  2197. /// <summary>
  2198. /// 机具循环列表
  2199. /// </summary>
  2200. /// <returns></returns>
  2201. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2202. {
  2203. var result = "";
  2204. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2205. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2206. if (pos.Id == 0)
  2207. {
  2208. return "机具:" + SnNo + "不存在";
  2209. }
  2210. else
  2211. {
  2212. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2213. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2214. result += "循环开始时间:" + stattime + "\n";
  2215. result += "循环结束时间:" + endtime + "\n";
  2216. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2217. }
  2218. return result;
  2219. }
  2220. #endregion
  2221. #region 查询创客直推奖
  2222. public IActionResult Prize100(string right)
  2223. {
  2224. ViewBag.RightInfo = RightInfo;
  2225. ViewBag.right = right;
  2226. return View();
  2227. }
  2228. [HttpPost]
  2229. public Dictionary<string, string> Prize100Do(string MakerCode)
  2230. {
  2231. Dictionary<string, string> dic = new Dictionary<string, string>();
  2232. string result = "";
  2233. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2234. if (forMakerCode == null)
  2235. {
  2236. result += "创客编号不存在\n";
  2237. dic.Add("code", "1");
  2238. dic.Add("result", result);
  2239. return dic;
  2240. }
  2241. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2242. if (OrderCount == 0)
  2243. {
  2244. result += "该创客未下单\n";
  2245. dic.Add("code", "1");
  2246. dic.Add("result", result);
  2247. return dic;
  2248. }
  2249. if (OrderCount > 1)
  2250. {
  2251. result += "该创客已不是首笔下单\n";
  2252. dic.Add("code", "1");
  2253. dic.Add("result", result);
  2254. return dic;
  2255. }
  2256. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2257. if (order.PayStatus < 1)
  2258. {
  2259. result += "未付款\n";
  2260. dic.Add("code", "1");
  2261. dic.Add("result", result);
  2262. return dic;
  2263. }
  2264. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2265. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2266. result += "订单号:" + order.OrderNo + "\n";
  2267. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2268. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2269. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2270. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2271. if (machineCount + ActiveCount >= 3)
  2272. {
  2273. string IsGet = "未发放";
  2274. int ToUserId = 0;
  2275. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2276. if (item == null)
  2277. {
  2278. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2279. DateTime end = order.PayDate.Value.AddMinutes(2);
  2280. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2281. }
  2282. if (item != null)
  2283. {
  2284. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2285. ToUserId = item.UserId;
  2286. dic.Add("code", "1");
  2287. }
  2288. else
  2289. {
  2290. dic.Add("id", order.Id.ToString());
  2291. dic.Add("code", "0");
  2292. }
  2293. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2294. result += "是否发放:" + IsGet + "\n";
  2295. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2296. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2297. }
  2298. else
  2299. {
  2300. result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2301. dic.Add("code", "1");
  2302. }
  2303. dic.Add("result", result);
  2304. return dic;
  2305. }
  2306. public string AddPrize100(int Id)
  2307. {
  2308. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2309. if (order != null)
  2310. {
  2311. //机具券逻辑
  2312. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2313. if (pro != null)
  2314. {
  2315. //推荐下单奖励
  2316. if (pro.ProductId == 10 || pro.ProductId == 11)
  2317. {
  2318. int OrderId = order.Id;
  2319. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2320. if (!checkPrize)
  2321. {
  2322. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2323. if (user != null)
  2324. {
  2325. bool directPrize = false; //直推奖标记
  2326. int ParentUserId = user.ParentUserId;
  2327. while (ParentUserId > 0)
  2328. {
  2329. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2330. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  2331. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2332. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2333. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2334. {
  2335. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2336. directPrize = true;
  2337. db.SaveChanges();
  2338. return "发放成功";
  2339. }
  2340. ParentUserId = puser.ParentUserId;
  2341. }
  2342. }
  2343. }
  2344. return "已发放,请勿重复发放";
  2345. }
  2346. }
  2347. }
  2348. return "操作失败";
  2349. }
  2350. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2351. {
  2352. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2353. if (account == null)
  2354. {
  2355. account = db.UserAccount.Add(new UserAccount()
  2356. {
  2357. Id = UserId,
  2358. UserId = UserId,
  2359. }).Entity;
  2360. db.SaveChanges();
  2361. }
  2362. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2363. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2364. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2365. account.BalanceAmount += 100 * Count;
  2366. account.TotalAmount += 100 * Count;
  2367. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2368. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2369. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2370. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2371. {
  2372. CreateDate = DateTime.Now,
  2373. UpdateDate = DateTime.Now,
  2374. UserId = UserId, //创客
  2375. ChangeType = 112, //变动类型
  2376. ChangeAmount = 100 * Count, //变更金额
  2377. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2378. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2379. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2380. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2381. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2382. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2383. QueryCount = OrderId,
  2384. }).Entity;
  2385. db.SaveChanges();
  2386. }
  2387. #endregion
  2388. #region 查询机具开机奖
  2389. public IActionResult OpenPrize(string right)
  2390. {
  2391. ViewBag.RightInfo = RightInfo;
  2392. ViewBag.right = right;
  2393. return View();
  2394. }
  2395. [HttpPost]
  2396. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2397. {
  2398. Dictionary<string, string> dic = new Dictionary<string, string>();
  2399. string result = "";
  2400. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2401. if (pos == null)
  2402. {
  2403. result += "机具SN号不存在\n";
  2404. dic.Add("code", "1");
  2405. dic.Add("result", result);
  2406. return dic;
  2407. }
  2408. if (pos.BindingState == 0)
  2409. {
  2410. result += "机具未绑定\n";
  2411. dic.Add("code", "1");
  2412. dic.Add("result", result);
  2413. return dic;
  2414. }
  2415. if (pos.ActivationState == 0)
  2416. {
  2417. result += "机具未激活\n";
  2418. dic.Add("code", "1");
  2419. dic.Add("result", result);
  2420. return dic;
  2421. }
  2422. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2423. if (merchant == null)
  2424. {
  2425. result += "商户不存在\n";
  2426. dic.Add("code", "1");
  2427. dic.Add("result", result);
  2428. return dic;
  2429. }
  2430. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2431. result += "机具号:" + PosSn + "\n";
  2432. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2433. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2434. string OpenUser10 = "未领取";
  2435. string OpenUser20 = "未领取";
  2436. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2437. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2438. if (openreward.Id > 0)
  2439. {
  2440. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2441. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2442. }
  2443. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2444. if (openreward.Id > 0)
  2445. {
  2446. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2447. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2448. }
  2449. result += "开机奖20:" + OpenUser20 + "\n";
  2450. dic.Add("id", pos.Id.ToString());
  2451. dic.Add("code", "0");
  2452. dic.Add("result", result);
  2453. return dic;
  2454. }
  2455. public string AddOpenPrize(int Id)
  2456. {
  2457. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2458. if (pos == null)
  2459. {
  2460. return "机具未激活";
  2461. }
  2462. if (pos.BindingTime <= pos.TransferTime)
  2463. {
  2464. return "补录机,不能补发开机奖";
  2465. }
  2466. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2467. if (ActPrize == 0)
  2468. {
  2469. return "机具无押金";
  2470. }
  2471. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2472. if (merchant == null)
  2473. {
  2474. return "商户不存在";
  2475. }
  2476. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2477. if (check)
  2478. {
  2479. return "开机奖励已发放,请勿重复操作";
  2480. }
  2481. // 从机具所属人上级开始分开机奖励
  2482. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2483. if (user != null)
  2484. {
  2485. if (!string.IsNullOrEmpty(user.ParentNav))
  2486. {
  2487. decimal Prize = 20;
  2488. List<string> PrizeFlag = new List<string>();
  2489. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2490. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2491. {
  2492. int UserId = int.Parse(ParentNavs[i]);
  2493. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2494. if (puser != null && Prize > 0)
  2495. {
  2496. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2497. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2498. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2499. if (machineCount + ActiveCount + couponCount >= 3)
  2500. {
  2501. int pTopUserId = 0;
  2502. if (!string.IsNullOrEmpty(puser.ParentNav))
  2503. {
  2504. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2505. }
  2506. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2507. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2508. {
  2509. CreateDate = DateTime.Now,
  2510. UpdateDate = DateTime.Now,
  2511. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2512. TradeDate = pos.ActivationTime, //达标日期
  2513. UserId = puser.Id, //创客
  2514. BrandId = pos.BrandId, //品牌
  2515. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2516. MerchantId = pos.BindMerchantId, //商户
  2517. DirectUserId = merchant.UserId, //商户直属人
  2518. SnNo = pos.PosSn, //SN号
  2519. MerNo = merchant.KqMerNo, //渠道商户号
  2520. SnType = pos.PosSnType, //机具类型
  2521. StandardDate = pos.ActivationTime, //商户的激活日期
  2522. SnStoreId = pos.StoreId, //SN仓库
  2523. MerBuddyType = puser.MerchantType, //商户创客类型
  2524. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2525. RewardTips = "开机奖励", //奖励描述
  2526. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2527. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2528. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2529. RewardDesc = "开机奖励", //奖励描述
  2530. TopUserId = pTopUserId, //顶级创客
  2531. SeoTitle = machineUser.RealName,
  2532. }).Entity;
  2533. db.OpenReward.Add(new OpenReward()
  2534. {
  2535. CreateDate = DateTime.Now,
  2536. UpdateDate = DateTime.Now,
  2537. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2538. TradeDate = DateTime.Now, //达标日期
  2539. UserId = puser.Id, //创客
  2540. BrandId = pos.BrandId, //品牌
  2541. RewardType = 2, //奖励类型
  2542. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2543. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2544. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2545. RewardDesc = "开机奖励", //奖励描述
  2546. TopUserId = pTopUserId, //顶级创客
  2547. });
  2548. string IdBrand = puser.Id + "_" + pos.BrandId;
  2549. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2550. if (userData == null)
  2551. {
  2552. userData = db.UserMachineData.Add(new UserMachineData()
  2553. {
  2554. IdBrand = IdBrand,
  2555. }).Entity;
  2556. db.SaveChanges();
  2557. }
  2558. userData.OpenProfit += Prize;
  2559. db.SaveChanges();
  2560. //账户入库
  2561. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2562. if (account == null)
  2563. {
  2564. account = db.UserAccount.Add(new UserAccount()
  2565. {
  2566. Id = puser.Id,
  2567. UserId = puser.Id,
  2568. }).Entity;
  2569. db.SaveChanges();
  2570. }
  2571. //收支明细入库
  2572. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2573. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2574. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2575. account.BalanceAmount += Prize;
  2576. account.TotalAmount += Prize;
  2577. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2578. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2579. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2580. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2581. {
  2582. CreateDate = DateTime.Now,
  2583. UpdateDate = DateTime.Now,
  2584. UserId = puser.Id, //创客
  2585. ChangeType = 50, //变动类型
  2586. ProductType = pos.BrandId, //产品类型
  2587. ChangeAmount = Prize, //变更金额
  2588. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2589. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2590. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2591. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2592. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2593. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2594. }).Entity;
  2595. db.SaveChanges();
  2596. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2597. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2598. string monthString = DateTime.Now.ToString("yyyyMM");
  2599. // 开机奖励列表
  2600. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2601. if (!dates.Contains(dateString))
  2602. {
  2603. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2604. }
  2605. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2606. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2607. if (!months.Contains(monthString))
  2608. {
  2609. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2610. }
  2611. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2612. // 开机奖励详情
  2613. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2614. //收支明细
  2615. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2616. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2617. Prize = 0;
  2618. PrizeFlag.Add(Prize.ToString("f0"));
  2619. }
  2620. }
  2621. }
  2622. string result = "";
  2623. if (string.IsNullOrEmpty(result))
  2624. {
  2625. return "发放成功";
  2626. }
  2627. return result;
  2628. }
  2629. }
  2630. db.Dispose();
  2631. return "操作失败";
  2632. }
  2633. #endregion
  2634. #region 查询机具流量费分佣
  2635. public IActionResult FluxPrize(string right)
  2636. {
  2637. ViewBag.RightInfo = RightInfo;
  2638. ViewBag.right = right;
  2639. return View();
  2640. }
  2641. [HttpPost]
  2642. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2643. {
  2644. Dictionary<string, string> dic = new Dictionary<string, string>();
  2645. string result = "";
  2646. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2647. if (pos == null)
  2648. {
  2649. result += "机具SN号不存在\n";
  2650. dic.Add("code", "1");
  2651. dic.Add("result", result);
  2652. return dic;
  2653. }
  2654. if (pos.BindingState == 0)
  2655. {
  2656. result += "机具未绑定\n";
  2657. dic.Add("code", "1");
  2658. dic.Add("result", result);
  2659. return dic;
  2660. }
  2661. if (pos.ActivationState == 0)
  2662. {
  2663. result += "机具未激活\n";
  2664. dic.Add("code", "1");
  2665. dic.Add("result", result);
  2666. return dic;
  2667. }
  2668. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2669. if (merchant == null)
  2670. {
  2671. result += "商户不存在\n";
  2672. dic.Add("code", "1");
  2673. dic.Add("result", result);
  2674. return dic;
  2675. }
  2676. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2677. result += "机具号:" + PosSn + "\n";
  2678. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2679. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2680. string FluxGet6 = "未领取";
  2681. string FluxUser6 = "";
  2682. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2683. if (flux.Id > 0)
  2684. {
  2685. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2686. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2687. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2688. }
  2689. result += "流量费:" + FluxGet6 + "\n";
  2690. result += "流量费发放对象:" + FluxUser6 + "\n";
  2691. dic.Add("id", pos.Id.ToString());
  2692. dic.Add("code", "0");
  2693. dic.Add("result", result);
  2694. return dic;
  2695. }
  2696. public string AddFluxPrize(int Id)
  2697. {
  2698. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2699. if (pos == null)
  2700. {
  2701. return "机具未激活";
  2702. }
  2703. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2704. if (ActPrize == 0)
  2705. {
  2706. return "机具无押金";
  2707. }
  2708. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2709. if (merchant == null)
  2710. {
  2711. return "商户不存在";
  2712. }
  2713. if (pos.BrandId == 6)
  2714. {
  2715. return "立刷不支持流量费分佣";
  2716. }
  2717. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2718. {
  2719. return "无押金机,不支持流量费分佣";
  2720. }
  2721. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2722. if (check)
  2723. {
  2724. return "流量费奖励已发放,请勿重复操作";
  2725. }
  2726. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2727. if (trade != null)
  2728. {
  2729. try
  2730. {
  2731. string OrderNo = trade.TradeSerialNo; //单号
  2732. DateTime TradeDate = trade.CreateDate.Value;
  2733. string TradeMonth = TradeDate.ToString("yyyyMM");
  2734. decimal FeeAmount = trade.FeeAmount; //流量费
  2735. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2736. {
  2737. FeeAmount = FeeAmount / 100;
  2738. }
  2739. string TradeSnNo = trade.TradeSnNo; //机具SN
  2740. decimal FluxProfit = 0;
  2741. if (trade.ProductType == "1" && FeeAmount == 60)
  2742. {
  2743. FluxProfit = 24;
  2744. }
  2745. else if (trade.ProductType == "7" && FeeAmount == 46)
  2746. {
  2747. FluxProfit = 10;
  2748. }
  2749. else if (trade.ProductType != "1" && FeeAmount == 48)
  2750. {
  2751. FluxProfit = 12;
  2752. }
  2753. if (FluxProfit > 0)
  2754. {
  2755. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2756. int GetUserId = user.Id;
  2757. int TopUserId = 0;
  2758. string ParentNav = user.ParentNav;
  2759. if (!string.IsNullOrEmpty(ParentNav))
  2760. {
  2761. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2762. if (ParentNavList.Length > 1)
  2763. {
  2764. TopUserId = int.Parse(ParentNavList[1]);
  2765. }
  2766. else if (ParentNavList.Length == 1)
  2767. {
  2768. TopUserId = int.Parse(ParentNavList[0]);
  2769. }
  2770. }
  2771. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2772. if (fluxProfit == null)
  2773. {
  2774. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2775. {
  2776. CreateDate = DateTime.Now,
  2777. UpdateDate = DateTime.Now,
  2778. UserId = GetUserId, //创客
  2779. BrandId = pos.BrandId,
  2780. TopUserId = TopUserId, //顶级创客
  2781. TradeMonth = TradeMonth, //交易月
  2782. MerUserType = user.MerchantType, //商户创客类型
  2783. Remark = "流量卡分佣", //备注
  2784. }).Entity;
  2785. db.SaveChanges();
  2786. }
  2787. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2788. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2789. {
  2790. CreateDate = DateTime.Now,
  2791. UpdateDate = DateTime.Now,
  2792. RecordNo = OrderNo, //单号
  2793. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2794. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2795. TradeMonth = TradeMonth, //交易月
  2796. UserId = GetUserId, //创客
  2797. MerchantId = pos.BindMerchantId, //商户
  2798. MerchantUserId = pos.UserId, //商户直属人
  2799. MerNo = merchant.KqMerNo, //渠道商户编号
  2800. SnNo = pos.PosSn, //渠道SN号
  2801. FluxOrderNo = OrderNo, //流量扣费单号
  2802. TradeOrderNo = OrderNo, //交易流水号
  2803. TradeAmt = trade.TradeAmount, //商户交易额
  2804. FluxFeeAmt = FeeAmount, //流量费
  2805. FluxProfitAmt = FluxProfit, //流量分润总金额
  2806. PosType = pos.PosSnType.ToString(), //POS类型
  2807. Remark = "流量卡分佣", //备注
  2808. BrandId = pos.BrandId, //品牌
  2809. TopUserId = TopUserId, //顶级创客
  2810. MerUserType = user.MerchantType, //商户创客类型
  2811. });
  2812. string IdBrand = user.Id + "_" + pos.BrandId;
  2813. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2814. if (userData == null)
  2815. {
  2816. userData = db.UserMachineData.Add(new UserMachineData()
  2817. {
  2818. IdBrand = IdBrand,
  2819. }).Entity;
  2820. db.SaveChanges();
  2821. }
  2822. userData.FluxProfit += FluxProfit;
  2823. db.SaveChanges();
  2824. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  2825. if (account == null)
  2826. {
  2827. account = db.UserAccount.Add(new UserAccount()
  2828. {
  2829. Id = GetUserId,
  2830. UserId = GetUserId,
  2831. }).Entity;
  2832. db.SaveChanges();
  2833. }
  2834. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2835. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2836. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2837. account.BalanceAmount += FluxProfit;
  2838. account.TotalAmount += FluxProfit;
  2839. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2840. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2841. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2842. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2843. {
  2844. CreateDate = DateTime.Now,
  2845. UpdateDate = DateTime.Now,
  2846. UserId = GetUserId, //创客
  2847. ChangeType = 60, //变动类型
  2848. ProductType = pos.BrandId, //产品类型
  2849. ChangeAmount = FluxProfit, //变更金额
  2850. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2851. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2852. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2853. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2854. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2855. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2856. }).Entity;
  2857. db.SaveChanges();
  2858. spdb.Dispose();
  2859. db.Dispose();
  2860. return "发放成功";
  2861. }
  2862. }
  2863. catch (Exception ex)
  2864. {
  2865. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  2866. }
  2867. }
  2868. spdb.Dispose();
  2869. db.Dispose();
  2870. return "操作失败";
  2871. }
  2872. #endregion
  2873. #region 设置立刷费率
  2874. public IActionResult LisFee(string right)
  2875. {
  2876. ViewBag.RightInfo = RightInfo;
  2877. ViewBag.right = right;
  2878. return View();
  2879. }
  2880. [HttpPost]
  2881. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  2882. {
  2883. if (string.IsNullOrEmpty(PosSns))
  2884. {
  2885. return "请输入机具号";
  2886. }
  2887. string result = SysUserName + "设置\n";
  2888. string[] PosSnList = PosSns.Split('\n');
  2889. int total = PosSnList.Length;
  2890. int index = 0;
  2891. foreach (string SubPosSn in PosSnList)
  2892. {
  2893. index += 1;
  2894. string PosSn = SubPosSn.Replace("\r", "");
  2895. result += PosSn + ":" + Fee + "\n";
  2896. if (Kind == "M5")
  2897. {
  2898. result += SetLiSFee(PosSn, Fee) + "\n";
  2899. }
  2900. else if (Kind == "N1")
  2901. {
  2902. result += SetLiSDeposit(PosSn, (int)Fee);
  2903. }
  2904. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  2905. }
  2906. result += "\n\n";
  2907. function.WriteLog(result, "设置立刷费率");
  2908. return result;
  2909. }
  2910. public string LisFeeProcess()
  2911. {
  2912. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  2913. }
  2914. #region 立刷
  2915. string LiSAgentId = "50814834";
  2916. 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=";
  2917. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  2918. public string LiSSign(string data)
  2919. {
  2920. var rsa = RSA.Create();
  2921. var key = Convert.FromBase64String(LiSPrivateKey);
  2922. var content = Encoding.UTF8.GetBytes(data);
  2923. rsa.ImportPkcs8PrivateKey(key, out _);
  2924. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  2925. return Convert.ToBase64String(result);
  2926. }
  2927. // 设置费率
  2928. public string SetLiSFee(string sn, decimal serviceFee)
  2929. {
  2930. Dictionary<string, object> dic = new Dictionary<string, object>();
  2931. dic.Add("agentId", LiSAgentId);
  2932. dic.Add("deviceSn", sn);
  2933. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2934. Dictionary<string, object> item = new Dictionary<string, object>();
  2935. item.Add("feeCalcType", "M5");
  2936. item.Add("fixed", "0");
  2937. item.Add("rate", serviceFee);
  2938. feeList.Add(item);
  2939. dic.Add("feeList", feeList);
  2940. dic.Add("signMethod", "02");
  2941. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  2942. string signstr = LiSSign(content);
  2943. dic.Add("signData", signstr);
  2944. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2945. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2946. return result;
  2947. }
  2948. // 设置押金
  2949. public string SetLiSDeposit(string sn, int serviceFee)
  2950. {
  2951. serviceFee = serviceFee * 100;
  2952. Dictionary<string, object> dic = new Dictionary<string, object>();
  2953. dic.Add("agentId", LiSAgentId);
  2954. dic.Add("deviceSn", sn);
  2955. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2956. Dictionary<string, object> item = new Dictionary<string, object>();
  2957. item.Add("feeCalcType", "N1");
  2958. item.Add("fixed", "1");
  2959. item.Add("rate", serviceFee);
  2960. feeList.Add(item);
  2961. dic.Add("feeList", feeList);
  2962. dic.Add("signMethod", "02");
  2963. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  2964. string signstr = LiSSign(content);
  2965. dic.Add("signData", signstr);
  2966. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2967. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2968. return result;
  2969. }
  2970. #endregion
  2971. #endregion
  2972. #region 查询商户型创客设置信息
  2973. public IActionResult SeeMerchantType(string right)
  2974. {
  2975. ViewBag.RightInfo = RightInfo;
  2976. ViewBag.right = right;
  2977. return View();
  2978. }
  2979. [HttpPost]
  2980. public string SeeMerchantTypeDo(string PosSn)
  2981. {
  2982. if (string.IsNullOrEmpty(PosSn))
  2983. {
  2984. return "请输入机具SN或者创客编号";
  2985. }
  2986. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  2987. if (PosSn.StartsWith("K"))
  2988. {
  2989. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  2990. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  2991. if (check)
  2992. {
  2993. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  2994. }
  2995. }
  2996. else
  2997. {
  2998. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  2999. if (check)
  3000. {
  3001. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3002. }
  3003. }
  3004. if (pos.Id == 0)
  3005. {
  3006. return "查无信息";
  3007. }
  3008. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3009. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3010. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3011. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3012. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3013. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3014. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3015. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3016. string result = "";
  3017. result += "机具SN:" + pos.PosSn + "\n";
  3018. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3019. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3020. result += "商户编号:" + pos.MerNo + "\n";
  3021. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3022. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3023. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3024. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3025. result += "是否循环:" + RecycFlag + "\n";
  3026. return result;
  3027. }
  3028. #endregion
  3029. #region 三要素验证
  3030. public IActionResult CheckThreeElements(string right)
  3031. {
  3032. ViewBag.RightInfo = RightInfo;
  3033. ViewBag.right = right;
  3034. return View();
  3035. }
  3036. [HttpPost]
  3037. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3038. {
  3039. var host = "https://bankcard3c.shumaidata.com";
  3040. var path = "/bankcard3c";
  3041. var method = "GET";
  3042. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3043. if (string.IsNullOrEmpty(bankcard))
  3044. {
  3045. return "结算银行卡号";
  3046. }
  3047. if (string.IsNullOrEmpty(idcard))
  3048. {
  3049. return "身份证号";
  3050. }
  3051. if (string.IsNullOrEmpty(name))
  3052. {
  3053. return "真实姓名";
  3054. }
  3055. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3056. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3057. function.WriteLog(querys, "验证三要素日志");
  3058. String bodys = "";
  3059. String url = host + path;
  3060. HttpWebRequest httpRequest = null;
  3061. HttpWebResponse httpResponse = null;
  3062. if (0 < querys.Length)
  3063. {
  3064. url = url + "?" + querys;
  3065. }
  3066. if (host.Contains("https://"))
  3067. {
  3068. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3069. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3070. }
  3071. else
  3072. {
  3073. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3074. }
  3075. httpRequest.Method = method;
  3076. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3077. if (0 < bodys.Length)
  3078. {
  3079. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3080. using (Stream stream = httpRequest.GetRequestStream())
  3081. {
  3082. stream.Write(data, 0, data.Length);
  3083. }
  3084. }
  3085. try
  3086. {
  3087. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3088. }
  3089. catch (WebException ex)
  3090. {
  3091. httpResponse = (HttpWebResponse)ex.Response;
  3092. }
  3093. Stream st = httpResponse.GetResponseStream();
  3094. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3095. string result = reader.ReadToEnd();
  3096. JsonData jsonObj = JsonMapper.ToObject(result);
  3097. result = jsonObj["data"]["desc"].ToString();
  3098. function.WriteLog(result, "验证三要素日志");
  3099. function.WriteLog("\n\n", "验证三要素日志");
  3100. return result;
  3101. }
  3102. #endregion
  3103. #region 四要素验证
  3104. public IActionResult CheckFourElements(string right)
  3105. {
  3106. ViewBag.RightInfo = RightInfo;
  3107. ViewBag.right = right;
  3108. return View();
  3109. }
  3110. [HttpPost]
  3111. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3112. {
  3113. var host = "https://bankcard4c.shumaidata.com";
  3114. var path = "/bankcard4c";
  3115. var method = "GET";
  3116. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3117. if (string.IsNullOrEmpty(bankcard))
  3118. {
  3119. return "请输入结算银行卡号";
  3120. }
  3121. if (string.IsNullOrEmpty(idcard))
  3122. {
  3123. return "请输入身份证号";
  3124. }
  3125. if (string.IsNullOrEmpty(mobile))
  3126. {
  3127. return "请输入银行预留手机号";
  3128. }
  3129. if (string.IsNullOrEmpty(name))
  3130. {
  3131. return "请输入真实姓名";
  3132. }
  3133. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3134. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3135. function.WriteLog(querys, "验证四要素日志");
  3136. String bodys = "";
  3137. String url = host + path;
  3138. HttpWebRequest httpRequest = null;
  3139. HttpWebResponse httpResponse = null;
  3140. if (0 < querys.Length)
  3141. {
  3142. url = url + "?" + querys;
  3143. }
  3144. if (host.Contains("https://"))
  3145. {
  3146. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3147. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3148. }
  3149. else
  3150. {
  3151. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3152. }
  3153. httpRequest.Method = method;
  3154. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3155. if (0 < bodys.Length)
  3156. {
  3157. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3158. using (Stream stream = httpRequest.GetRequestStream())
  3159. {
  3160. stream.Write(data, 0, data.Length);
  3161. }
  3162. }
  3163. try
  3164. {
  3165. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3166. }
  3167. catch (WebException ex)
  3168. {
  3169. httpResponse = (HttpWebResponse)ex.Response;
  3170. }
  3171. Stream st = httpResponse.GetResponseStream();
  3172. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3173. string result = reader.ReadToEnd();
  3174. JsonData jsonObj = JsonMapper.ToObject(result);
  3175. result = jsonObj["data"]["desc"].ToString();
  3176. function.WriteLog(result, "验证四要素日志");
  3177. function.WriteLog("\n\n", "验证四要素日志");
  3178. return result;
  3179. }
  3180. #endregion
  3181. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3182. {
  3183. return true;
  3184. }
  3185. #region 根据机具号同步商户激活状态
  3186. public IActionResult SyncMerchantStatus(string right)
  3187. {
  3188. ViewBag.RightInfo = RightInfo;
  3189. ViewBag.right = right;
  3190. return View();
  3191. }
  3192. [HttpPost]
  3193. public string SyncMerchantStatusDo(string PosSn)
  3194. {
  3195. if (string.IsNullOrEmpty(PosSn))
  3196. {
  3197. return "请输入机具号";
  3198. }
  3199. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3200. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3201. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3202. if (posInfo.Id == 0)
  3203. {
  3204. return "机具" + PosSn + "不存在";
  3205. }
  3206. if (posMerchant.Id == 0)
  3207. {
  3208. return "机具绑定商户不存在";
  3209. }
  3210. else
  3211. {
  3212. posMerchant.ActiveStatus = 1;
  3213. posMerchant.UpdateDate = DateTime.Now;
  3214. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3215. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3216. db.SaveChanges();
  3217. }
  3218. return "success";
  3219. }
  3220. #endregion
  3221. #region 根据机具号补发开机奖励
  3222. public IActionResult PosRewardReissued(string right)
  3223. {
  3224. ViewBag.RightInfo = RightInfo;
  3225. ViewBag.right = right;
  3226. return View();
  3227. }
  3228. [HttpPost]
  3229. public string PosRewardReissuedDo(string PosSn)
  3230. {
  3231. if (string.IsNullOrEmpty(PosSn))
  3232. {
  3233. return "请输入机具SN";
  3234. }
  3235. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3236. var PosId = "";
  3237. var error = "";
  3238. foreach (var item in PosSnList)
  3239. {
  3240. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3241. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3242. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3243. if (checkExist)
  3244. {
  3245. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3246. }
  3247. else
  3248. {
  3249. if (posInfo.Id > 0)
  3250. {
  3251. RedisDbconn.Instance.AddList("OpenRewardQueue", posInfo.Id.ToString());
  3252. }
  3253. }
  3254. }
  3255. if (!string.IsNullOrEmpty(error))
  3256. {
  3257. return "Warning|" + error;
  3258. }
  3259. PosId = PosId.TrimEnd(',');
  3260. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3261. return "success";
  3262. }
  3263. #endregion
  3264. #region 根据机具号设置费率
  3265. public IActionResult SetPosFee(string right)
  3266. {
  3267. ViewBag.RightInfo = RightInfo;
  3268. ViewBag.right = right;
  3269. return View();
  3270. }
  3271. [HttpPost]
  3272. public string SetPosFeeDo(string PosSn, string FeeType)
  3273. {
  3274. if (string.IsNullOrEmpty(PosSn))
  3275. {
  3276. return "请输入机具SN";
  3277. }
  3278. if (string.IsNullOrEmpty(FeeType))
  3279. {
  3280. return "请输入选择费率";
  3281. }
  3282. if (FeeType == "0")
  3283. {
  3284. FeeType = "0.6";
  3285. }
  3286. if (FeeType == "1")
  3287. {
  3288. FeeType = "0.63";
  3289. }
  3290. string[] PosSnList = PosSn.Split('\n');
  3291. var PosId = "";
  3292. var RecordId = "";
  3293. var error = "";
  3294. foreach (var item in PosSnList)
  3295. {
  3296. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3297. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3298. if (posInfo.Id > 0)
  3299. {
  3300. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3301. {
  3302. Sort = posInfo.BrandId,
  3303. CreateDate = DateTime.Now,
  3304. PosId = posInfo.Id,
  3305. PosSn = posInfo.PosSn,
  3306. PosUserId = posInfo.UserId,
  3307. MerchantId = posInfo.BindMerchantId,
  3308. UserId = posInfo.UserId,
  3309. ChangeFee = decimal.Parse(FeeType),
  3310. }).Entity;
  3311. db.SaveChanges();
  3312. PosId += posInfo.Id + ",";
  3313. RecordId += query.Id + ",";
  3314. }
  3315. else
  3316. {
  3317. error += "机具" + PosSn + "不存在";
  3318. }
  3319. }
  3320. if (!string.IsNullOrEmpty(error))
  3321. {
  3322. return "Warning|" + error;
  3323. }
  3324. PosId = PosId.TrimEnd(',');
  3325. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3326. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3327. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3328. return "success";
  3329. }
  3330. #endregion
  3331. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3332. public IActionResult RelationPosAndMerchant(string right)
  3333. {
  3334. ViewBag.RightInfo = RightInfo;
  3335. ViewBag.right = right;
  3336. return View();
  3337. }
  3338. [HttpPost]
  3339. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3340. {
  3341. if (string.IsNullOrEmpty(PosSn))
  3342. {
  3343. return "请输入机具SN";
  3344. }
  3345. if (string.IsNullOrEmpty(MerchantNo))
  3346. {
  3347. return "请输入商户编号";
  3348. }
  3349. if (string.IsNullOrEmpty(MerchantName))
  3350. {
  3351. return "请输入商户姓名";
  3352. }
  3353. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3354. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3355. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3356. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3357. if (posMerchant.Id == 0)
  3358. {
  3359. return "商户" + MerchantNo + "不存在";
  3360. }
  3361. else if (pos.Id == 0)
  3362. {
  3363. return "机具" + PosSn + "不存在";
  3364. }
  3365. else
  3366. {
  3367. pos.BindMerchantId = posMerchant.Id;
  3368. db.SaveChanges();
  3369. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3370. }
  3371. return "success";
  3372. }
  3373. #endregion
  3374. #region 设置商户信息
  3375. public IActionResult SetMerchantInfo(string right)
  3376. {
  3377. ViewBag.RightInfo = RightInfo;
  3378. ViewBag.right = right;
  3379. return View();
  3380. }
  3381. [HttpPost]
  3382. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3383. {
  3384. if (string.IsNullOrEmpty(PosSn))
  3385. {
  3386. return "请输入机具SN";
  3387. }
  3388. if (string.IsNullOrEmpty(MerchantNo))
  3389. {
  3390. return "请输入商户编号";
  3391. }
  3392. if (string.IsNullOrEmpty(MerchantName))
  3393. {
  3394. return "请输入商户姓名";
  3395. }
  3396. if (string.IsNullOrEmpty(MerIdcardNo))
  3397. {
  3398. return "请输入商户身份证号";
  3399. }
  3400. if (string.IsNullOrEmpty(MerchantMobile))
  3401. {
  3402. return "请输入商户手机号";
  3403. }
  3404. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
  3405. var query = "";
  3406. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3407. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3408. if (posMerchant.Id == 0)
  3409. {
  3410. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3411. }
  3412. else
  3413. {
  3414. posMerchant.MerIdcardNo = MerIdcardNo;
  3415. posMerchant.MerchantName = MerchantName;
  3416. posMerchant.MerchantMobile = MerchantMobile;
  3417. db.SaveChanges();
  3418. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3419. }
  3420. return "success";
  3421. }
  3422. #endregion
  3423. #region 认证创客
  3424. public IActionResult AuthMaker(string right)
  3425. {
  3426. ViewBag.RightInfo = RightInfo;
  3427. ViewBag.right = right;
  3428. return View();
  3429. }
  3430. [HttpPost]
  3431. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3432. {
  3433. if (string.IsNullOrEmpty(MakerCode))
  3434. {
  3435. return "请输入创客编号";
  3436. }
  3437. if (string.IsNullOrEmpty(RealName))
  3438. {
  3439. return "请输入真实姓名";
  3440. }
  3441. if (string.IsNullOrEmpty(CertId))
  3442. {
  3443. return "请输入身份证号";
  3444. }
  3445. if (string.IsNullOrEmpty(BackCard))
  3446. {
  3447. return "请输入银行卡号";
  3448. }
  3449. if (string.IsNullOrEmpty(BackName))
  3450. {
  3451. return "请输入银行名称";
  3452. }
  3453. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3454. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3455. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3456. if (userInfo.AuthFlag == 1)
  3457. {
  3458. return "已认证";
  3459. }
  3460. else
  3461. {
  3462. userInfo.UpdateDate = DateTime.Now;
  3463. userInfo.RealName = RealName;
  3464. userInfo.AuthFlag = 1;
  3465. if (userInfo.AuthDate == null)
  3466. {
  3467. userInfo.AuthDate = DateTime.Now;
  3468. }
  3469. userInfo.CertId = CertId;
  3470. userInfo.SettleBankCardNo = BackCard;
  3471. userInfo.SettleBankName = BackName;
  3472. db.SaveChanges();
  3473. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3474. }
  3475. return "success";
  3476. }
  3477. #endregion
  3478. #region 划拨创客机具
  3479. public IActionResult TransferPos(string right)
  3480. {
  3481. ViewBag.RightInfo = RightInfo;
  3482. ViewBag.right = right;
  3483. return View();
  3484. }
  3485. [HttpPost]
  3486. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3487. {
  3488. if (string.IsNullOrEmpty(PosSn))
  3489. {
  3490. return "请输入机具SN";
  3491. }
  3492. if (string.IsNullOrEmpty(FromMakerCode))
  3493. {
  3494. return "请输入机具来源创客编号";
  3495. }
  3496. if (string.IsNullOrEmpty(ToMakerCode))
  3497. {
  3498. return "请输入划拨对象创客编号";
  3499. }
  3500. var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3501. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3502. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3503. if (posInfo.Id == 0)
  3504. {
  3505. return "机具" + PosSn + "不存在";
  3506. }
  3507. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3508. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3509. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3510. if (fUserId.Id == 0)
  3511. {
  3512. return "来源创客" + FromMakerCode + "不存在";
  3513. }
  3514. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3515. if (tUserId.Id == 0)
  3516. {
  3517. return "划拨创客" + ToMakerCode + "不存在";
  3518. }
  3519. if (posInfo.BindingState == 0)
  3520. {
  3521. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  3522. {
  3523. posInfo.BuyUserId = tUserId.Id;
  3524. posInfo.UserId = tUserId.Id;
  3525. }
  3526. else
  3527. {
  3528. posInfo.BuyUserId = tUserId.Id;
  3529. }
  3530. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3531. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3532. fUserPos.TotalMachineCount -= 1;
  3533. fUserPos.UnBindCount -= 1;
  3534. tUserPos.TotalMachineCount += 1;
  3535. tUserPos.UnBindCount += 1;
  3536. db.SaveChanges();
  3537. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3538. }
  3539. else
  3540. {
  3541. return "机具" + PosSn + "已使用";
  3542. }
  3543. return "success";
  3544. }
  3545. #endregion
  3546. #region 还原提现订单状态
  3547. public IActionResult RestoreStatus(string right)
  3548. {
  3549. ViewBag.RightInfo = RightInfo;
  3550. ViewBag.right = right;
  3551. return View();
  3552. }
  3553. [HttpPost]
  3554. public string RestoreStatusDo(string OrderNo)
  3555. {
  3556. if (string.IsNullOrEmpty(OrderNo))
  3557. {
  3558. return "请输入提现订单编号";
  3559. }
  3560. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  3561. var error = "";
  3562. foreach (var item in OrderNoList)
  3563. {
  3564. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  3565. if (cash.Id > 0)
  3566. {
  3567. cash.QueryCount = 0;
  3568. cash.Status = 0;
  3569. db.SaveChanges();
  3570. }
  3571. else
  3572. {
  3573. error += "订单" + item + "不存在" + '\n';
  3574. }
  3575. }
  3576. if (!string.IsNullOrEmpty(error))
  3577. {
  3578. return "Warning|" + error;
  3579. }
  3580. return "success";
  3581. }
  3582. #endregion
  3583. #region 查询创客循环资格
  3584. public IActionResult SeeUserLoop(string right)
  3585. {
  3586. ViewBag.RightInfo = RightInfo;
  3587. ViewBag.right = right;
  3588. return View();
  3589. }
  3590. [HttpPost]
  3591. public string SeeUserLoopDo(string MakerCode)
  3592. {
  3593. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3594. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3595. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  3596. var brandList = db.KqProducts.ToList();
  3597. var info = "";
  3598. foreach (var item in brandList)
  3599. {
  3600. var brand = item.Name;
  3601. //已过期
  3602. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3603. //可申请
  3604. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3605. //已使用
  3606. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  3607. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  3608. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  3609. }
  3610. return info;
  3611. }
  3612. #endregion
  3613. #region 提交到代付排除的创客名单
  3614. public IActionResult CashWithoutUser(string right)
  3615. {
  3616. ViewBag.RightInfo = RightInfo;
  3617. ViewBag.right = right;
  3618. return View();
  3619. }
  3620. public string CashWithoutUserDo(string Content)
  3621. {
  3622. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  3623. if (set == null)
  3624. {
  3625. set = db.CustomTagSet.Add(new CustomTagSet()
  3626. {
  3627. Tags = "CashWithoutUser",
  3628. Title = "提交到代付排除的创客名单"
  3629. }).Entity;
  3630. db.SaveChanges();
  3631. }
  3632. set.Contents = Content;
  3633. db.SaveChanges();
  3634. db.Dispose();
  3635. return "success";
  3636. }
  3637. #endregion
  3638. #region 坏机回仓
  3639. public IActionResult BadPosToStore(string right)
  3640. {
  3641. ViewBag.RightInfo = RightInfo;
  3642. ViewBag.right = right;
  3643. return View();
  3644. }
  3645. [HttpPost]
  3646. public string BadPosToStoreDo(string OldSn)
  3647. {
  3648. string[] OldSnList;
  3649. OldSnList = OldSn.Replace("\r", "").Split('\n');
  3650. string error = "";
  3651. List<string> opData = new List<string>();
  3652. for (int i = 0; i < OldSnList.Length; i++)
  3653. {
  3654. string OldSnNum = OldSnList[i];
  3655. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  3656. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  3657. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  3658. {
  3659. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  3660. }
  3661. oldpos.Status = 1;
  3662. oldpos.PosSnType = 0;
  3663. oldpos.QueryCount = 0;
  3664. oldpos.UpdateDate = null;
  3665. oldpos.ActivityList = null;
  3666. oldpos.SeoKeyword = null;
  3667. oldpos.SeoDescription = null;
  3668. oldpos.OrderId = 0;
  3669. oldpos.RecycEndDate = null;
  3670. oldpos.RecycBackCount = 0;
  3671. oldpos.PrizeParams = null;
  3672. oldpos.ScanQrTrade = 0;
  3673. oldpos.BindMerchantId = 0;
  3674. oldpos.CreditTrade = 0;
  3675. oldpos.DebitCardTrade = 0;
  3676. oldpos.IsVip = 0;
  3677. oldpos.UserNav = null;
  3678. oldpos.TransferTime = null;
  3679. oldpos.IsPurchase = 0;
  3680. oldpos.Detail = null;
  3681. oldpos.BindingTime = null;
  3682. oldpos.BindingState = 0;
  3683. oldpos.ActivationTime = null;
  3684. oldpos.ActivationState = 0;
  3685. oldpos.LeaderUserId = 0;
  3686. oldpos.PreUserId = 0;
  3687. oldpos.IsFirst = 0;
  3688. oldpos.DownFeeMan = null;
  3689. oldpos.DownFeeFlag = 0;
  3690. oldpos.DownFeeDate = null;
  3691. oldpos.UpFeeMan = null;
  3692. oldpos.UpFeeFlag = 0;
  3693. oldpos.UpFeeDate = null;
  3694. oldpos.OpReserve1 = 0;
  3695. oldpos.OpReserve2 = 0;
  3696. oldpos.OpReserve3 = 0;
  3697. oldpos.OpId = 0;
  3698. oldpos.RecycStartDate = null;
  3699. oldpos.SourcePosSn = null;
  3700. oldpos.BuyUserId = 0;
  3701. oldpos.UserId = 0;
  3702. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  3703. }
  3704. if (!string.IsNullOrEmpty(error))
  3705. {
  3706. return "Warning|" + error;
  3707. }
  3708. db.SaveChanges();
  3709. foreach (string sub in opData)
  3710. {
  3711. string[] datalist = sub.Split(":");
  3712. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  3713. }
  3714. return "success";
  3715. }
  3716. #endregion
  3717. #region 划拨创客机具券
  3718. public IActionResult TransferPosCoupon(string right)
  3719. {
  3720. ViewBag.RightInfo = RightInfo;
  3721. ViewBag.right = right;
  3722. return View();
  3723. }
  3724. public string TransferPosCouponDo(string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  3725. {
  3726. if (string.IsNullOrEmpty(PosCouponCodes))
  3727. {
  3728. return "请输入机具券码";
  3729. }
  3730. if (string.IsNullOrEmpty(FromMakerCode))
  3731. {
  3732. return "请输入机具来源创客编号";
  3733. }
  3734. if (string.IsNullOrEmpty(ToMakerCode))
  3735. {
  3736. return "请输入划拨对象创客编号";
  3737. }
  3738. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3739. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3740. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3741. if (fUserId.Id == 0)
  3742. {
  3743. return "来源创客" + FromMakerCode + "不存在";
  3744. }
  3745. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3746. if (tUserId.Id == 0)
  3747. {
  3748. return "划拨创客" + ToMakerCode + "不存在";
  3749. }
  3750. int LeaderUserId = 0;
  3751. if (!string.IsNullOrEmpty(LeaderMakerCode))
  3752. {
  3753. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  3754. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  3755. if (LeaderUserItem.Id == 0)
  3756. {
  3757. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  3758. }
  3759. LeaderUserId = leaderuser.UserId;
  3760. }
  3761. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  3762. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  3763. foreach (string PosCouponCode in PosCouponList)
  3764. {
  3765. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  3766. if (item.UserId != fUserId.Id)
  3767. {
  3768. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  3769. }
  3770. if (item.Id == 0)
  3771. {
  3772. return "机具券" + PosCouponCode + "不存在";
  3773. }
  3774. if (item.IsUse == 1)
  3775. {
  3776. return "机具券" + PosCouponCode + "已使用";
  3777. }
  3778. item.UserId = tUserId.Id;
  3779. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  3780. {
  3781. item.LeaderUserId = LeaderUserId;
  3782. }
  3783. }
  3784. db.SaveChanges();
  3785. db.Dispose();
  3786. return "success";
  3787. }
  3788. #endregion
  3789. #region 机具回仓退款
  3790. public IActionResult RefundPosFee(string right)
  3791. {
  3792. ViewBag.RightInfo = RightInfo;
  3793. ViewBag.right = right;
  3794. return View();
  3795. }
  3796. [HttpPost]
  3797. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  3798. {
  3799. if (string.IsNullOrEmpty(PosSn))
  3800. {
  3801. return "请输入机具SN";
  3802. }
  3803. if (IsBack == 1)
  3804. {
  3805. if (string.IsNullOrEmpty(BackStoreNo))
  3806. {
  3807. return "请输入仓库编号";
  3808. }
  3809. }
  3810. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3811. WebCMSEntities db = new WebCMSEntities();
  3812. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  3813. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  3814. StoreForCode storeForBack = new StoreForCode();
  3815. StoreHouse BackStore = new StoreHouse();
  3816. List<string> opData = new List<string>();
  3817. foreach (var item in PosSnList)
  3818. {
  3819. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3820. if (machineForSnNo.SnId == 0)
  3821. {
  3822. return "未找到机具" + item + "关联数据";
  3823. }
  3824. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  3825. if (pos.Id == 0)
  3826. {
  3827. return "机具" + item + "不存在或者不满足条件";
  3828. }
  3829. if (IsBack == 1)
  3830. {
  3831. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  3832. if (storeForBack.StoreId == 0)
  3833. {
  3834. return "未找到" + BackStoreNo + "关联数据";
  3835. }
  3836. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  3837. if (BackStore.Id == 0)
  3838. {
  3839. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  3840. }
  3841. }
  3842. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  3843. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  3844. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  3845. var amount = 0;
  3846. if (brandInfo.Name.Contains("电签"))
  3847. {
  3848. amount = 200;
  3849. }
  3850. if (brandInfo.Name.Contains("大POS"))
  3851. {
  3852. amount = 300;
  3853. }
  3854. if (IsBack == 1)
  3855. {
  3856. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  3857. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  3858. {
  3859. CreateDate = DateTime.Now,
  3860. CreateMan = SysUserName,
  3861. StoreId = pos.StoreId, //出货仓库
  3862. BrandId = pos.BrandId, //产品类型
  3863. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  3864. TransType = 5, //交易类型
  3865. SnNo = item, //SN编号
  3866. StockOpDirect = 0, //库存操作方向
  3867. SnStatus = 1, //SN状态
  3868. DeviceVendor = pos.DeviceName, //设备厂商
  3869. DeviceModel = pos.DeviceKind, //设备型号
  3870. DeviceType = pos.DeviceType, //设备类型
  3871. FromUserId = pos.BuyUserId, //来源创客
  3872. ToRemark = "过期机具回仓退款", //入库备注
  3873. ToStoreId = BackStore.Id, //退货收货仓库
  3874. SourceStoreId = pos.SourceStoreId, //源仓库编号
  3875. BrandType = pos.DeviceType, //品牌类型
  3876. }).Entity;
  3877. string ChangeNo = "HCTK";
  3878. int StoreStockChangeId = stockchange.Id;
  3879. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  3880. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  3881. {
  3882. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  3883. }
  3884. ChangeNo += StoreStockChangeIdString;
  3885. stockchange.ChangeNo = ChangeNo; //交易流水编号
  3886. db.StoreChangeHistory.Add(new StoreChangeHistory()
  3887. {
  3888. CreateDate = DateTime.Now,
  3889. BrandId = pos.BrandId, //产品类型
  3890. ChangeRecordNo = ChangeNo, //变更记录单号
  3891. TransType = 5, //交易类型
  3892. SnNo = item, //SN编号
  3893. SnType = pos.PosSnType, //SN机具类型
  3894. StockOpDirect = 0, //库存操作方向
  3895. DeviceVendor = pos.DeviceName, //设备厂商
  3896. DeviceModel = pos.DeviceKind, //设备型号
  3897. DeviceType = pos.DeviceType, //设备类型
  3898. FromUserId = pos.BuyUserId, //来源创客
  3899. ToRemark = "过期机具回仓退款", //入库备注
  3900. SourceStoreId = pos.SourceStoreId, //源仓库
  3901. StoreId = pos.StoreId, //出货仓库
  3902. });
  3903. db.MachineReturn.Add(new MachineReturn()
  3904. {
  3905. CreateDate = DateTime.Now,
  3906. Operator = SysUserName + "_" + SysRealName,//操作人
  3907. BrandId = pos.BrandId, //产品类型
  3908. DeviceSnNos = pos.PosSn,
  3909. ToStoreId = BackStore.Id,
  3910. ApplyNo = ChangeNo, //变更记录单号
  3911. UserId = pos.BuyUserId, //来源创客
  3912. Remark = "过期机具回仓退款", //入库备注
  3913. });
  3914. if (pos.ScanQrTrade > 0)
  3915. {
  3916. decimal ChangeAmount = 0;
  3917. decimal BeforeBalanceAmount = 0;
  3918. decimal AfterBalanceAmount = 0;
  3919. if (pos.ScanQrTrade == 999)
  3920. {
  3921. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  3922. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  3923. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  3924. ChangeAmount = amount;
  3925. }
  3926. else
  3927. {
  3928. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  3929. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  3930. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  3931. ChangeAmount = pos.ScanQrTrade;
  3932. }
  3933. db.UserAccountRecord.Add(new UserAccountRecord()
  3934. {
  3935. CreateDate = DateTime.Now,
  3936. UpdateDate = DateTime.Now,
  3937. UserId = pos.BuyUserId, //创客
  3938. ChangeType = 126, //变动类型(机具货款退还)
  3939. ProductType = 0, //产品类型
  3940. ChangeAmount = ChangeAmount, //变更金额
  3941. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3942. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3943. });
  3944. }
  3945. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  3946. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  3947. userMachineData.TotalMachineCount += 1;
  3948. userMachineData.UnBindCount += 1;
  3949. BackStore.LaveNum += 1;
  3950. BackStore.TotalNum += 1;
  3951. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  3952. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  3953. userMachineDatas.TotalMachineCount -= 1;
  3954. userMachineDatas.UnBindCount -= 1;
  3955. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  3956. {
  3957. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  3958. }
  3959. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  3960. pos.Status = 1;
  3961. pos.QueryCount = 0;
  3962. pos.UpdateDate = null;
  3963. pos.ActivityList = null;
  3964. pos.SeoKeyword = null;
  3965. pos.SeoDescription = null;
  3966. pos.OrderId = 0;
  3967. pos.RecycEndDate = null;
  3968. pos.RecycBackCount = 0;
  3969. pos.PrizeParams = null;
  3970. pos.ScanQrTrade = 0;
  3971. pos.BindMerchantId = 0;
  3972. pos.CreditTrade = 0;
  3973. pos.DebitCardTrade = 0;
  3974. pos.IsVip = 0;
  3975. pos.UserNav = null;
  3976. pos.TransferTime = null;
  3977. pos.IsPurchase = 0;
  3978. pos.Detail = null;
  3979. pos.BindingTime = null;
  3980. pos.BindingState = 0;
  3981. pos.ActivationTime = null;
  3982. pos.ActivationState = 0;
  3983. pos.LeaderUserId = 0;
  3984. pos.PreUserId = 0;
  3985. pos.IsFirst = 0;
  3986. pos.DownFeeMan = null;
  3987. pos.DownFeeFlag = 0;
  3988. pos.DownFeeDate = null;
  3989. pos.UpFeeMan = null;
  3990. pos.UpFeeFlag = 0;
  3991. pos.UpFeeDate = null;
  3992. pos.OpReserve1 = 0;
  3993. pos.OpReserve2 = 0;
  3994. pos.OpReserve3 = 0;
  3995. pos.OpId = 0;
  3996. pos.RecycStartDate = null;
  3997. pos.SourcePosSn = null;
  3998. pos.BuyUserId = 0;
  3999. pos.UserId = 0;
  4000. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4001. }
  4002. else
  4003. {
  4004. if (pos.ScanQrTrade > 0)
  4005. {
  4006. decimal ChangeAmount = 0;
  4007. decimal BeforeBalanceAmount = 0;
  4008. decimal AfterBalanceAmount = 0;
  4009. if (pos.ScanQrTrade == 999)
  4010. {
  4011. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4012. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4013. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4014. ChangeAmount = amount;
  4015. }
  4016. else
  4017. {
  4018. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4019. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4020. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4021. ChangeAmount = pos.ScanQrTrade;
  4022. }
  4023. pos.ScanQrTrade = 0;
  4024. db.UserAccountRecord.Add(new UserAccountRecord()
  4025. {
  4026. CreateDate = DateTime.Now,
  4027. UpdateDate = DateTime.Now,
  4028. UserId = pos.BuyUserId, //创客
  4029. ChangeType = 126, //变动类型(机具货款退还)
  4030. ProductType = 0, //产品类型
  4031. ChangeAmount = ChangeAmount, //变更金额
  4032. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4033. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4034. });
  4035. }
  4036. }
  4037. }
  4038. db.SaveChanges();
  4039. foreach (string sub in opData)
  4040. {
  4041. string[] datalist = sub.Split(":");
  4042. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4043. }
  4044. return "success";
  4045. }
  4046. #endregion
  4047. #region 添加商户信息
  4048. public IActionResult AddMerchantnfo(string right)
  4049. {
  4050. ViewBag.RightInfo = RightInfo;
  4051. ViewBag.right = right;
  4052. return View();
  4053. }
  4054. [HttpPost]
  4055. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4056. {
  4057. if (string.IsNullOrEmpty(PosSn))
  4058. {
  4059. return "请输入机具号";
  4060. }
  4061. if (string.IsNullOrEmpty(MerSn))
  4062. {
  4063. return "请输入商户号";
  4064. }
  4065. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4066. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4067. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4068. if (machineForSnNo.SnId == 0)
  4069. {
  4070. return "未找到机具" + PosSn + "关联数据";
  4071. }
  4072. if (pos.Id == 0)
  4073. {
  4074. return "未找到机具" + PosSn;
  4075. }
  4076. if (merchantInfo.Id > 0)
  4077. {
  4078. return "机具" + PosSn + "以经存在绑定商户";
  4079. }
  4080. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4081. if (spInfo.Id > 0)
  4082. {
  4083. var MerUserType = 0;
  4084. var ActiveStatus = 0;
  4085. if (pos.BuyUserId != pos.UserId)
  4086. {
  4087. MerUserType = 1;
  4088. }
  4089. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4090. {
  4091. ActiveStatus = 1;
  4092. }
  4093. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4094. {
  4095. CreateDate = pos.BindingTime,
  4096. TopUserId = 1,
  4097. BrandId = pos.BrandId,
  4098. SnStoreId = pos.StoreId,
  4099. MerStandardDate = pos.ActivationTime,
  4100. SnType = pos.PosSnType,
  4101. MerUserType = MerUserType,
  4102. UserId = pos.UserId,
  4103. ActiveStatus = ActiveStatus,
  4104. MerStatus = 1,
  4105. KqSnNo = PosSn,
  4106. KqMerNo = MerSn,
  4107. MerIdcardNo = spInfo.SeoKeyword,
  4108. MerchantMobile = spInfo.MerNewSnNo,
  4109. MerchantName = spInfo.MerName,
  4110. MerchantNo = spInfo.MerNo,
  4111. }).Entity;
  4112. db.SaveChanges();
  4113. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4114. function.WriteLog(text, "设置商户信息");
  4115. }
  4116. return "success";
  4117. }
  4118. #endregion
  4119. }
  4120. }