SysToolsController.cs 264 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655
  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 System.Data;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. using System.Text.RegularExpressions;
  20. using System.Security.Cryptography;
  21. using System.Security.Cryptography.X509Certificates;
  22. using System.Text;
  23. using System.Net;
  24. using System.Net.Security;
  25. using System.IO;
  26. namespace MySystem.Areas.Admin.Controllers
  27. {
  28. [Area("Admin")]
  29. [Route("Admin/[controller]/[action]")]
  30. public class SysToolsController : BaseController
  31. {
  32. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  33. {
  34. }
  35. #region 关联上下级
  36. public IActionResult RelationForUser(string right)
  37. {
  38. ViewBag.RightInfo = RightInfo;
  39. ViewBag.right = right;
  40. return View();
  41. }
  42. [HttpPost]
  43. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  44. {
  45. if (string.IsNullOrEmpty(MakerCode))
  46. {
  47. return "请输入创客编号";
  48. }
  49. if (string.IsNullOrEmpty(ParentMakerCode))
  50. {
  51. return "请输入上级创客编号";
  52. }
  53. MakerCode = MakerCode.ToUpper();
  54. ParentMakerCode = ParentMakerCode.ToUpper();
  55. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  56. if (puser != null)
  57. {
  58. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  59. if (user != null)
  60. {
  61. user.ParentUserId = puser.Id;
  62. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  63. if (IsTeam == 1)
  64. {
  65. RelationForUserSub(db, user.Id, user);
  66. }
  67. db.SaveChanges();
  68. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  69. return "success";
  70. }
  71. return "创客编号不存在";
  72. }
  73. return "上级创客编号不存在";
  74. }
  75. private void RelationForUserSub(WebCMSEntities dbnew, int ParentUserId, Users puser)
  76. {
  77. var subusers = dbnew.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  78. foreach (var subuser in subusers)
  79. {
  80. Users user = dbnew.Users.FirstOrDefault(m => m.Id == subuser.Id);
  81. if (user != null)
  82. {
  83. user.ParentUserId = puser.Id;
  84. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  85. RelationForUserSub(dbnew, user.Id, user);
  86. }
  87. }
  88. }
  89. #endregion
  90. #region 机具补录
  91. public IActionResult CheckMachine(string right)
  92. {
  93. ViewBag.RightInfo = RightInfo;
  94. ViewBag.right = right;
  95. return View();
  96. }
  97. [HttpPost]
  98. public string CheckMachineDo(string MakerCode, string PosSn, int AddActPrize = 0, int IsSend = 0)
  99. {
  100. if (string.IsNullOrEmpty(MakerCode))
  101. {
  102. return "请输入创客编号";
  103. }
  104. if (string.IsNullOrEmpty(PosSn))
  105. {
  106. return "请输入机具SN";
  107. }
  108. var MerNo = "";
  109. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  110. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  111. if (pos == null)
  112. {
  113. return "机具SN不存在";
  114. }
  115. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  116. if (user == null)
  117. {
  118. return "创客编号不存在";
  119. }
  120. if (pos.PreUserId > 0)
  121. {
  122. if (pos.BuyUserId == 0)
  123. {
  124. pos.BuyUserId = user.Id;
  125. }
  126. if (pos.UserId == 0)
  127. {
  128. pos.UserId = user.Id;
  129. }
  130. }
  131. if (pos.BindingState == 0)
  132. {
  133. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  134. if (bind != null)
  135. {
  136. pos.BindingState = 1;
  137. pos.BindingTime = bind.CreateTime;
  138. db.SaveChanges();
  139. MerNo = bind.MerNo;
  140. }
  141. }
  142. decimal CreditTrade = 0;
  143. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  144. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  145. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  146. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  147. if (check)
  148. {
  149. if (pos.BrandId == 1)
  150. {
  151. 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;
  152. }
  153. else if (pos.BrandId == 2)
  154. {
  155. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  156. }
  157. else if (pos.BrandId == 3)
  158. {
  159. 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;
  160. }
  161. else if (pos.BrandId == 4 || pos.BrandId == 5)
  162. {
  163. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  164. }
  165. else if (pos.BrandId == 6)
  166. {
  167. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  168. }
  169. else if (pos.BrandId == 7)
  170. {
  171. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  172. }
  173. else if (pos.BrandId == 8)
  174. {
  175. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  176. }
  177. else if (pos.BrandId == 9)
  178. {
  179. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  180. }
  181. else if (pos.BrandId == 10 || pos.BrandId == 11)
  182. {
  183. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  184. }
  185. else if (pos.BrandId == 12 || pos.BrandId == 13)
  186. {
  187. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
  188. }
  189. pos.CreditTrade = CreditTrade;
  190. db.SaveChanges();
  191. }
  192. if (AddActPrize == 1)
  193. {
  194. if (pos.BuyUserId == 0)
  195. {
  196. return "机具未划拨,无法补录激活奖励";
  197. }
  198. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  199. {
  200. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  201. if (has)
  202. {
  203. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  204. pos.SeoKeyword = chkAct.SeoTitle;
  205. db.SaveChanges();
  206. }
  207. }
  208. if (pos.BindingTime != null && pos.ActivationTime != null)
  209. {
  210. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  211. if (ts.TotalDays <= 30 || SysUserName == "admin")
  212. {
  213. AddAct(pos.Id);
  214. }
  215. }
  216. }
  217. decimal CheckMoney = 1000;
  218. if (pos.BrandId == 6)
  219. {
  220. CheckMoney = 5000;
  221. }
  222. if (pos.BuyUserId > 0)
  223. {
  224. if (pos.CreditTrade < CheckMoney)
  225. {
  226. return "该机具贷记卡累计交易不足" + CheckMoney;
  227. }
  228. if (pos.BindingTime != null && pos.ActivationTime != null)
  229. {
  230. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  231. if (ts.TotalDays > 30 && SysUserName != "admin")
  232. {
  233. return "机具划拨后已超过30天";
  234. }
  235. }
  236. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  237. {
  238. pos.ActivationState = 1;
  239. pos.ActivationTime = DateTime.Now;
  240. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  241. if (pos.ActivationState == 1 && mer != null)
  242. {
  243. mer.ActiveStatus = 1;
  244. mer.MerStandardDate = DateTime.Now;
  245. }
  246. }
  247. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  248. {
  249. if (AddActPrize == 1)
  250. {
  251. if (IsSend == 1)
  252. {
  253. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  254. {
  255. UserId = pos.BuyUserId, //接收创客
  256. MsgType = 2,
  257. Title = "补录成功通知", //标题
  258. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  259. CreateDate = DateTime.Now,
  260. }));
  261. }
  262. return "激活奖励已补录";
  263. }
  264. else
  265. {
  266. return "数据正常,无需补录";
  267. }
  268. }
  269. db.SaveChanges();
  270. return "success";
  271. }
  272. pos.UserId = user.Id;
  273. pos.BuyUserId = user.Id;
  274. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  275. {
  276. pos.ActivationState = 1;
  277. pos.ActivationTime = DateTime.Now;
  278. }
  279. PosMerchantInfo merchant = new PosMerchantInfo();
  280. if (!string.IsNullOrEmpty(MerNo))
  281. {
  282. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  283. if (merchant == null)
  284. {
  285. int TopUserId = 0;
  286. if (!string.IsNullOrEmpty(user.ParentNav))
  287. {
  288. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  289. }
  290. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  291. if (bind == null)
  292. {
  293. return "该机具尚未绑定";
  294. }
  295. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  296. if (Mer == null)
  297. {
  298. return "该机具尚未绑定";
  299. }
  300. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  301. {
  302. CreateDate = Mer.CreateTime,
  303. UpdateDate = Mer.UpdateTime,
  304. TopUserId = TopUserId,
  305. MerUserType = user.MerchantType,
  306. BrandId = int.Parse(Mer.ProductType),
  307. SnStoreId = pos.StoreId,
  308. SnType = pos.PosSnType,
  309. UserId = user.Id,
  310. MgrName = Mer.AgentName,
  311. MerStatus = 1,
  312. KqSnNo = Mer.SnNo,
  313. KqMerNo = Mer.MerNo,
  314. MerIdcardNo = Mer.MerIdcardNo,
  315. MerRealName = Mer.MerRealName,
  316. MerchantMobile = Mer.MerMobile,
  317. MerchantName = Mer.MerName,
  318. MerchantNo = Mer.MerNo,
  319. }).Entity;
  320. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  321. if (forMerNo == null)
  322. {
  323. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  324. {
  325. MerNo = Mer.MerNo,
  326. SnId = pos.Id,
  327. }).Entity;
  328. }
  329. else
  330. {
  331. forMerNo.SnId = pos.Id;
  332. }
  333. }
  334. }
  335. else
  336. {
  337. if (pos.BindMerchantId > 0)
  338. {
  339. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  340. }
  341. else
  342. {
  343. return "找不到机具所属商户";
  344. }
  345. }
  346. merchant.UserId = user.Id;
  347. if (pos.ActivationState == 1)
  348. {
  349. merchant.ActiveStatus = 1;
  350. merchant.MerStandardDate = DateTime.Now;
  351. }
  352. if (pos.BindMerchantId == 0)
  353. {
  354. pos.BindMerchantId = merchant.Id;
  355. }
  356. db.SaveChanges();
  357. RedisDbconn.Instance.AddList("AddTradeRecordByPosIdQueue", pos.Id.ToString());
  358. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize, "机具补录日志");
  359. return "success";
  360. }
  361. public IActionResult CheckMachine2(string right)
  362. {
  363. ViewBag.RightInfo = RightInfo;
  364. ViewBag.right = right;
  365. return View();
  366. }
  367. [HttpPost]
  368. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  369. {
  370. if (string.IsNullOrEmpty(MakerCode))
  371. {
  372. return "请输入创客编号";
  373. }
  374. if (string.IsNullOrEmpty(PosSn))
  375. {
  376. return "请输入机具SN";
  377. }
  378. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  379. if (pos == null)
  380. {
  381. return "机具SN不存在";
  382. }
  383. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  384. if (user == null)
  385. {
  386. return "创客编号不存在";
  387. }
  388. if (pos.BindingState == 0)
  389. {
  390. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  391. if (bind != null)
  392. {
  393. pos.BindingState = 1;
  394. pos.BindingTime = bind.CreateTime;
  395. db.SaveChanges();
  396. MerNo = bind.MerNo;
  397. }
  398. }
  399. decimal CreditTrade = 0;
  400. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  401. if (check)
  402. {
  403. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  404. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  405. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  406. if (pos.BrandId == 1)
  407. {
  408. 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;
  409. }
  410. else if (pos.BrandId == 2)
  411. {
  412. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  413. }
  414. else if (pos.BrandId == 3)
  415. {
  416. 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;
  417. }
  418. else if (pos.BrandId == 4 || pos.BrandId == 5)
  419. {
  420. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  421. }
  422. else if (pos.BrandId == 6)
  423. {
  424. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  425. }
  426. else if (pos.BrandId == 8)
  427. {
  428. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  429. }
  430. else if (pos.BrandId == 9)
  431. {
  432. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  433. }
  434. else if (pos.BrandId == 10 || pos.BrandId == 11)
  435. {
  436. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  437. }
  438. else if (pos.BrandId == 12 || pos.BrandId == 13)
  439. {
  440. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
  441. }
  442. pos.CreditTrade = CreditTrade;
  443. db.SaveChanges();
  444. }
  445. if (AddActPrize == 1)
  446. {
  447. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  448. {
  449. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  450. if (has)
  451. {
  452. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  453. pos.SeoKeyword = chkAct.SeoTitle;
  454. db.SaveChanges();
  455. }
  456. }
  457. AddAct(pos.Id);
  458. }
  459. if (pos.BuyUserId > 0)
  460. {
  461. if (pos.CreditTrade < 1000)
  462. {
  463. db.SaveChanges();
  464. return "该机具贷记卡累计交易不足1000";
  465. }
  466. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  467. {
  468. pos.ActivationState = 1;
  469. pos.ActivationTime = DateTime.Now;
  470. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  471. if (pos.ActivationState == 1 && mer != null)
  472. {
  473. mer.ActiveStatus = 1;
  474. mer.MerStandardDate = DateTime.Now;
  475. }
  476. }
  477. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  478. {
  479. if (AddActPrize == 1)
  480. {
  481. return "激活奖励已补录";
  482. }
  483. else
  484. {
  485. return "数据正常,无需补录";
  486. }
  487. }
  488. db.SaveChanges();
  489. return "success";
  490. }
  491. pos.UserId = user.Id;
  492. pos.BuyUserId = user.Id;
  493. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  494. {
  495. pos.ActivationState = 1;
  496. pos.ActivationTime = DateTime.Now;
  497. }
  498. PosMerchantInfo merchant = new PosMerchantInfo();
  499. if (!string.IsNullOrEmpty(MerNo))
  500. {
  501. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  502. if (merchant == null)
  503. {
  504. int TopUserId = 0;
  505. if (!string.IsNullOrEmpty(user.ParentNav))
  506. {
  507. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  508. }
  509. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  510. if (bind == null)
  511. {
  512. return "该机具尚未绑定";
  513. }
  514. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  515. if (Mer == null)
  516. {
  517. return "该机具尚未绑定";
  518. }
  519. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  520. {
  521. CreateDate = Mer.CreateTime,
  522. UpdateDate = Mer.UpdateTime,
  523. TopUserId = TopUserId,
  524. MerUserType = user.MerchantType,
  525. BrandId = int.Parse(Mer.ProductType),
  526. SnStoreId = pos.StoreId,
  527. SnType = pos.PosSnType,
  528. UserId = user.Id,
  529. MgrName = Mer.AgentName,
  530. MerStatus = 1,
  531. KqSnNo = Mer.SnNo,
  532. KqMerNo = Mer.MerNo,
  533. MerIdcardNo = Mer.MerIdcardNo,
  534. MerRealName = Mer.MerRealName,
  535. MerchantMobile = Mer.MerMobile,
  536. MerchantName = Mer.MerName,
  537. MerchantNo = Mer.MerNo,
  538. }).Entity;
  539. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  540. if (forMerNo == null)
  541. {
  542. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  543. {
  544. MerNo = Mer.MerNo,
  545. SnId = pos.Id,
  546. }).Entity;
  547. }
  548. else
  549. {
  550. forMerNo.SnId = pos.Id;
  551. }
  552. }
  553. }
  554. else
  555. {
  556. if (pos.BindMerchantId > 0)
  557. {
  558. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  559. }
  560. else
  561. {
  562. return "找不到机具所属商户";
  563. }
  564. }
  565. merchant.UserId = user.Id;
  566. if (pos.ActivationState == 1)
  567. {
  568. merchant.ActiveStatus = 1;
  569. merchant.MerStandardDate = DateTime.Now;
  570. }
  571. if (pos.BindMerchantId == 0)
  572. {
  573. pos.BindMerchantId = merchant.Id;
  574. }
  575. db.SaveChanges();
  576. return "success";
  577. }
  578. public IActionResult CheckMachineForTeam1(string right)//直营团队机具补录
  579. {
  580. ViewBag.RightInfo = RightInfo;
  581. ViewBag.right = right;
  582. return View();
  583. }
  584. [HttpPost]
  585. public string CheckMachineForTeam1Do(string MakerCode, string PosSn, int AddActPrize = 0, int IsSend = 0)
  586. {
  587. if (string.IsNullOrEmpty(MakerCode))
  588. {
  589. return "请输入创客编号";
  590. }
  591. if (string.IsNullOrEmpty(PosSn))
  592. {
  593. return "请输入机具SN";
  594. }
  595. var MerNo = "";
  596. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  597. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  598. if (pos == null)
  599. {
  600. return "机具SN不存在";
  601. }
  602. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  603. if (user == null)
  604. {
  605. return "创客编号不存在";
  606. }
  607. if (pos.PreUserId > 0)
  608. {
  609. if (pos.BuyUserId == 0)
  610. {
  611. pos.BuyUserId = user.Id;
  612. }
  613. if (pos.UserId == 0)
  614. {
  615. pos.UserId = user.Id;
  616. }
  617. }
  618. if (pos.BindingState == 0)
  619. {
  620. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  621. if (bind != null)
  622. {
  623. pos.BindingState = 1;
  624. pos.BindingTime = bind.CreateTime;
  625. db.SaveChanges();
  626. MerNo = bind.MerNo;
  627. }
  628. }
  629. decimal CreditTrade = 0;
  630. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  631. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  632. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  633. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  634. if (check)
  635. {
  636. if (pos.BrandId == 1)
  637. {
  638. 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;
  639. }
  640. else if (pos.BrandId == 2)
  641. {
  642. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  643. }
  644. else if (pos.BrandId == 3)
  645. {
  646. 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;
  647. }
  648. else if (pos.BrandId == 4 || pos.BrandId == 5)
  649. {
  650. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  651. }
  652. else if (pos.BrandId == 6)
  653. {
  654. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  655. }
  656. else if (pos.BrandId == 7)
  657. {
  658. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  659. }
  660. else if (pos.BrandId == 8)
  661. {
  662. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  663. }
  664. else if (pos.BrandId == 9)
  665. {
  666. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  667. }
  668. else if (pos.BrandId == 10 || pos.BrandId == 11)
  669. {
  670. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  671. }
  672. else if (pos.BrandId == 12 || pos.BrandId == 13)
  673. {
  674. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
  675. }
  676. pos.CreditTrade = CreditTrade;
  677. db.SaveChanges();
  678. }
  679. if (AddActPrize == 1)
  680. {
  681. if (pos.BuyUserId == 0)
  682. {
  683. return "机具未划拨,无法补录激活奖励";
  684. }
  685. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  686. {
  687. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  688. if (has)
  689. {
  690. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  691. pos.SeoKeyword = chkAct.SeoTitle;
  692. db.SaveChanges();
  693. }
  694. }
  695. if (pos.BindingTime != null && pos.ActivationTime != null)
  696. {
  697. // TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  698. // if (ts.TotalDays <= 30 || SysUserName == "admin")
  699. // {
  700. // AddAct(pos.Id);
  701. // }
  702. AddAct(pos.Id);
  703. }
  704. }
  705. decimal CheckMoney = 1000;
  706. if (pos.BrandId == 6)
  707. {
  708. CheckMoney = 5000;
  709. }
  710. if (pos.BuyUserId > 0)
  711. {
  712. if (pos.CreditTrade < CheckMoney)
  713. {
  714. return "该机具贷记卡累计交易不足" + CheckMoney;
  715. }
  716. // if (pos.BindingTime != null && pos.ActivationTime != null)
  717. // {
  718. // TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  719. // if (ts.TotalDays > 30 && SysUserName != "admin")
  720. // {
  721. // return "机具划拨后已超过30天";
  722. // }
  723. // }
  724. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  725. {
  726. pos.ActivationState = 1;
  727. pos.ActivationTime = DateTime.Now;
  728. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  729. if (pos.ActivationState == 1 && mer != null)
  730. {
  731. mer.ActiveStatus = 1;
  732. mer.MerStandardDate = DateTime.Now;
  733. }
  734. }
  735. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  736. {
  737. if (AddActPrize == 1)
  738. {
  739. if (IsSend == 1)
  740. {
  741. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  742. {
  743. UserId = pos.BuyUserId, //接收创客
  744. MsgType = 2,
  745. Title = "补录成功通知", //标题
  746. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  747. CreateDate = DateTime.Now,
  748. }));
  749. }
  750. return "激活奖励已补录";
  751. }
  752. else
  753. {
  754. return "数据正常,无需补录";
  755. }
  756. }
  757. db.SaveChanges();
  758. return "success";
  759. }
  760. pos.UserId = user.Id;
  761. pos.BuyUserId = user.Id;
  762. // if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  763. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  764. {
  765. pos.ActivationState = 1;
  766. pos.ActivationTime = DateTime.Now;
  767. }
  768. PosMerchantInfo merchant = new PosMerchantInfo();
  769. if (!string.IsNullOrEmpty(MerNo))
  770. {
  771. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  772. if (merchant == null)
  773. {
  774. int TopUserId = 0;
  775. if (!string.IsNullOrEmpty(user.ParentNav))
  776. {
  777. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  778. }
  779. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  780. if (bind == null)
  781. {
  782. return "该机具尚未绑定";
  783. }
  784. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  785. if (Mer == null)
  786. {
  787. return "该机具尚未绑定";
  788. }
  789. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  790. {
  791. CreateDate = Mer.CreateTime,
  792. UpdateDate = Mer.UpdateTime,
  793. TopUserId = TopUserId,
  794. MerUserType = user.MerchantType,
  795. BrandId = int.Parse(Mer.ProductType),
  796. SnStoreId = pos.StoreId,
  797. SnType = pos.PosSnType,
  798. UserId = user.Id,
  799. MgrName = Mer.AgentName,
  800. MerStatus = 1,
  801. KqSnNo = Mer.SnNo,
  802. KqMerNo = Mer.MerNo,
  803. MerIdcardNo = Mer.MerIdcardNo,
  804. MerRealName = Mer.MerRealName,
  805. MerchantMobile = Mer.MerMobile,
  806. MerchantName = Mer.MerName,
  807. MerchantNo = Mer.MerNo,
  808. }).Entity;
  809. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  810. if (forMerNo == null)
  811. {
  812. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  813. {
  814. MerNo = Mer.MerNo,
  815. SnId = pos.Id,
  816. }).Entity;
  817. }
  818. else
  819. {
  820. forMerNo.SnId = pos.Id;
  821. }
  822. }
  823. }
  824. else
  825. {
  826. if (pos.BindMerchantId > 0)
  827. {
  828. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  829. }
  830. else
  831. {
  832. return "找不到机具所属商户";
  833. }
  834. }
  835. merchant.UserId = user.Id;
  836. if (pos.ActivationState == 1)
  837. {
  838. merchant.ActiveStatus = 1;
  839. merchant.MerStandardDate = DateTime.Now;
  840. }
  841. if (pos.BindMerchantId == 0)
  842. {
  843. pos.BindMerchantId = merchant.Id;
  844. }
  845. db.SaveChanges();
  846. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize, "机具补录日志");
  847. return "success";
  848. }
  849. public void AddAct(int posid = 0)
  850. {
  851. WebCMSEntities db = new WebCMSEntities();
  852. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && m.Id == posid);
  853. if (pos != null)
  854. {
  855. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  856. if (merchant != null)
  857. {
  858. string ParentNav = "";
  859. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  860. if (user != null)
  861. {
  862. int GetUserId = user.Id;
  863. ParentNav = user.ParentNav;
  864. int TopUserId = 1;
  865. if (!string.IsNullOrEmpty(ParentNav))
  866. {
  867. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  868. if (ParentNavList.Length > 1)
  869. {
  870. TopUserId = int.Parse(ParentNavList[1]);
  871. }
  872. else if (ParentNavList.Length == 1)
  873. {
  874. TopUserId = int.Parse(ParentNavList[0]);
  875. }
  876. }
  877. List<decimal> prizes = new List<decimal>();
  878. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  879. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  880. {
  881. ActPrize = ActPrize / 100;
  882. }
  883. if (ActPrize > 0)
  884. {
  885. if (ActPrize == 99)
  886. {
  887. ActPrize = 100;
  888. }
  889. else if (ActPrize == 199)
  890. {
  891. ActPrize = 200;
  892. }
  893. else if (ActPrize == 299)
  894. {
  895. ActPrize = 300;
  896. }
  897. else if (ActPrize == 249)
  898. {
  899. ActPrize = 260;
  900. }
  901. prizes.Add(ActPrize);
  902. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  903. {
  904. prizes.Add(40);
  905. }
  906. }
  907. else if (pos.BrandId == 6 && ActPrize == 0) //立刷首台无押金机返50
  908. {
  909. prizes.Add(50);
  910. }
  911. else if ((pos.BrandId == 10 || pos.BrandId == 11) && pos.IsFirst == 1 && ActPrize == 0 && (DateTime.Now < DateTime.Parse("2023-05-01 00:00:00") || SysUserName == "admin")) //联动首台无押金机返50
  912. {
  913. prizes.Add(50);
  914. }
  915. else if ((pos.BrandId == 12 || pos.BrandId == 13) && pos.IsFirst == 1 && ActPrize == 0) //盒易付首台无押金机返50
  916. {
  917. prizes.Add(50);
  918. }
  919. foreach (decimal prize in prizes)
  920. {
  921. int ChangeType = prize == 40 ? 12 : 0;
  922. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  923. if (!check)
  924. {
  925. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  926. db.ActiveReward.Add(new ActiveReward()
  927. {
  928. CreateDate = DateTime.Now,
  929. UpdateDate = DateTime.Now,
  930. UserId = GetUserId, //创客
  931. MerchantId = pos.BindMerchantId, //商户
  932. StandardDate = pos.ActivationTime, //达标日期
  933. RewardAmount = prize, //奖励金额
  934. BrandId = pos.BrandId, //品牌
  935. UserNav = ParentNav, //创客父级
  936. DirectBuddyNo = merchant.UserId, //商户直属创客
  937. KqMerNo = merchant.KqMerNo, //渠道商户编号
  938. KqSnNo = pos.PosSn, //渠道SN号
  939. SnType = pos.PosSnType, //机具类型
  940. SnApplyUserId = pos.BuyUserId, //机具申请创客
  941. ActType = 0, //激活类型
  942. SnStoreId = pos.StoreId, //SN仓库
  943. RewardTips = "激活奖励", //奖励描述
  944. Remark = "激活奖励", //备注
  945. ActDate = pos.ActivationTime, //激活时间
  946. TopUserId = TopUserId, //顶级创客
  947. SeoTitle = machineUser.RealName,
  948. });
  949. db.SaveChanges();
  950. string IdBrand = GetUserId + "_" + pos.BrandId;
  951. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  952. if (userData == null)
  953. {
  954. userData = db.UserMachineData.Add(new UserMachineData()
  955. {
  956. IdBrand = IdBrand,
  957. }).Entity;
  958. db.SaveChanges();
  959. }
  960. userData.ActProfit += prize;
  961. db.SaveChanges();
  962. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  963. if (account == null)
  964. {
  965. account = db.UserAccount.Add(new UserAccount()
  966. {
  967. Id = GetUserId,
  968. UserId = GetUserId,
  969. }).Entity;
  970. db.SaveChanges();
  971. }
  972. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  973. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  974. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  975. account.BalanceAmount += prize;
  976. account.TotalAmount += prize;
  977. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  978. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  979. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  980. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  981. {
  982. CreateDate = DateTime.Now,
  983. UpdateDate = DateTime.Now,
  984. UserId = GetUserId, //创客
  985. ChangeType = ChangeType, //变动类型
  986. ProductType = pos.BrandId, //产品类型
  987. ChangeAmount = prize, //变更金额
  988. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  989. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  990. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  991. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  992. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  993. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  994. }).Entity;
  995. db.SaveChanges();
  996. PublicFunction.SplitUserAccountRecord(add);
  997. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  998. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  999. // 激活奖励列表
  1000. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  1001. if (!dates.Contains(dateString))
  1002. {
  1003. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  1004. }
  1005. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  1006. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  1007. if (!months.Contains(monthString))
  1008. {
  1009. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  1010. }
  1011. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  1012. // 激活奖励详情
  1013. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  1014. if (!actPrizeList.Contains(pos.BindMerchantId))
  1015. {
  1016. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  1017. }
  1018. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  1019. //收支明细
  1020. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, add);
  1021. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  1022. }
  1023. }
  1024. }
  1025. // }
  1026. }
  1027. }
  1028. db.Dispose();
  1029. }
  1030. #endregion
  1031. #region 设置商户代理
  1032. public IActionResult SetMerAgent(string right)
  1033. {
  1034. ViewBag.RightInfo = RightInfo;
  1035. ViewBag.right = right;
  1036. return View();
  1037. }
  1038. [HttpPost]
  1039. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  1040. {
  1041. if (string.IsNullOrEmpty(MakerCode))
  1042. {
  1043. return "请输入创客编号";
  1044. }
  1045. if (string.IsNullOrEmpty(PosSn))
  1046. {
  1047. return "请输入机具SN";
  1048. }
  1049. if (string.IsNullOrEmpty(MerNo))
  1050. {
  1051. return "请输入商户编号";
  1052. }
  1053. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  1054. if (pos == null)
  1055. {
  1056. return "机具SN不存在";
  1057. }
  1058. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  1059. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  1060. if (user == null)
  1061. {
  1062. return "创客编号不存在";
  1063. }
  1064. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1065. if (merchant == null)
  1066. {
  1067. return "商户编号不存在";
  1068. }
  1069. if (merchant.MerUserType > 0)
  1070. {
  1071. return "商户" + MerNo + "已经被设置";
  1072. }
  1073. pos.SeoTitle = user.Id.ToString();
  1074. pos.UserId = user.Id;
  1075. if (pos.BindMerchantId == 0)
  1076. {
  1077. pos.BindMerchantId = merchant.Id;
  1078. if (IsSend == 1)
  1079. {
  1080. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1081. {
  1082. UserId = pos.BuyUserId, //接收创客
  1083. MsgType = 2,
  1084. Title = "商户型代理设置成功", //标题
  1085. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  1086. CreateDate = DateTime.Now,
  1087. }));
  1088. }
  1089. }
  1090. user.MerchantType = 1;
  1091. merchant.UserId = user.Id;
  1092. merchant.MerUserType = 1;
  1093. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  1094. {
  1095. CreateDate = DateTime.Now,
  1096. SeoTitle = SysUserName + "_" + SysRealName,
  1097. IsRecyc = (ulong)pos.IsPurchase,
  1098. CreditAmount = pos.CreditTrade,
  1099. PosSnType = pos.PosSnType,
  1100. ActDate = pos.ActivationTime,
  1101. BindDate = pos.BindingTime,
  1102. ActStatus = (ulong)pos.ActivationState,
  1103. BindStatus = (ulong)pos.BindingState,
  1104. MerNo = MerNo,
  1105. PosSn = pos.PosSn,
  1106. Note = "后台设置商户型创客",
  1107. ToUserId = user.Id,
  1108. OperateType = 2,
  1109. FromUserId = pos.BuyUserId,
  1110. BuyUserId = pos.BuyUserId,
  1111. });
  1112. db.SaveChanges();
  1113. string text = string.Format("设置商户代理,创客编号: " + MakerCode + ",机具SN:" + PosSn + ",商户:" + MerNo + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  1114. function.WriteLog(text, "SetMerAgent-设置商户代理");//设置商户型代理日志
  1115. return "success";
  1116. }
  1117. #endregion
  1118. #region 取消商户代理
  1119. public IActionResult CancelMerAgent(string right)
  1120. {
  1121. ViewBag.RightInfo = RightInfo;
  1122. ViewBag.right = right;
  1123. return View();
  1124. }
  1125. [HttpPost]
  1126. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  1127. {
  1128. if (string.IsNullOrEmpty(MakerCode))
  1129. {
  1130. return "请输入创客编号";
  1131. }
  1132. if (string.IsNullOrEmpty(PosSn))
  1133. {
  1134. return "请输入机具SN";
  1135. }
  1136. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  1137. if (pos == null)
  1138. {
  1139. return "机具SN不存在";
  1140. }
  1141. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  1142. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  1143. if (user == null)
  1144. {
  1145. return "创客编号不存在";
  1146. }
  1147. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == PosSn) ?? new PosMerchantInfo();
  1148. if (merchant.Id == 0)
  1149. {
  1150. return "机具" + PosSn + "对应的商户不存在";
  1151. }
  1152. else if (merchant.MerUserType == 1 && merchant.UserId == user.Id)
  1153. {
  1154. pos.UserId = pos.BuyUserId;
  1155. merchant.UserId = pos.BuyUserId;
  1156. merchant.MerUserType = 0;
  1157. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  1158. {
  1159. CreateDate = DateTime.Now,
  1160. SeoTitle = SysUserName + "_" + SysRealName,
  1161. IsRecyc = (ulong)pos.IsPurchase,
  1162. CreditAmount = pos.CreditTrade,
  1163. PosSnType = pos.PosSnType,
  1164. ActDate = pos.ActivationTime,
  1165. BindDate = pos.BindingTime,
  1166. ActStatus = (ulong)pos.ActivationState,
  1167. BindStatus = (ulong)pos.BindingState,
  1168. MerNo = merchant.KqMerNo,
  1169. PosSn = pos.PosSn,
  1170. Note = "后台取消商户型创客",
  1171. ToUserId = user.Id,
  1172. FromUserId = pos.BuyUserId,
  1173. OperateType = 2,
  1174. BuyUserId = pos.BuyUserId,
  1175. });
  1176. db.SaveChanges();
  1177. var count = db.SetMerchantTypeRecord.Count(m => m.ToUserId == user.Id && m.OperateType == 1);
  1178. if (count == 0)
  1179. {
  1180. user.MerchantType = 0;
  1181. db.SaveChanges();
  1182. }
  1183. if (pos.BindMerchantId == 0)
  1184. {
  1185. pos.BindMerchantId = merchant.Id;
  1186. if (IsSend == 1)
  1187. {
  1188. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1189. {
  1190. UserId = pos.BuyUserId, //接收创客
  1191. MsgType = 2,
  1192. Title = "商户型代理取消成功", //标题
  1193. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  1194. CreateDate = DateTime.Now,
  1195. }));
  1196. }
  1197. }
  1198. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  1199. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  1200. }
  1201. else
  1202. {
  1203. return "未找到相关信息";
  1204. }
  1205. return "success";
  1206. }
  1207. #endregion
  1208. #region 查看SP原始数据日志
  1209. public IActionResult SeeSpLog(string right)
  1210. {
  1211. ViewBag.RightInfo = RightInfo;
  1212. ViewBag.right = right;
  1213. return View();
  1214. }
  1215. #endregion
  1216. #region 查询机具信息
  1217. public IActionResult SeeSnDetail(string right)
  1218. {
  1219. ViewBag.RightInfo = RightInfo;
  1220. ViewBag.right = right;
  1221. return View();
  1222. }
  1223. [HttpPost]
  1224. public string SeeSnDetailDo(string PosSn)
  1225. {
  1226. if (string.IsNullOrEmpty(PosSn))
  1227. {
  1228. return "请输入机具SN";
  1229. }
  1230. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  1231. if (pos == null)
  1232. {
  1233. return "机具SN不存在";
  1234. }
  1235. if (pos.Status == -1)
  1236. {
  1237. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1238. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1239. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11 && pos.BrandId != 12)
  1240. {
  1241. Deposits = Deposits / 100;
  1242. }
  1243. string DepositGets = "未领取";
  1244. string DepositUsers = "";
  1245. string aDepositGets = "";
  1246. // ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1247. // if (rewards.Id > 0)
  1248. // {
  1249. // Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  1250. // DepositGets = "已领取";
  1251. // DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1252. // }
  1253. // string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1254. var rewards = db.ActiveReward.Where(m => m.KqSnNo == pos.PosSn).ToList();
  1255. foreach (var item in rewards)
  1256. {
  1257. Users user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
  1258. var time = item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1259. aDepositGets += "已领取:" + item.RewardAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",领取时间:" + time + "\n";
  1260. }
  1261. var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  1262. string results = "该机具为故障机" + "\n";
  1263. results += "所在仓库:" + storeInfo.StoreNo + "\n";
  1264. results += "仓库名称:" + storeInfo.StoreName + "\n";
  1265. results += "服务费返现实际返现对象:" + DepositUsers + "\n";
  1266. results += "服务费:" + Deposits + "\n";
  1267. // results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  1268. results += "是否返现:" + DepositGets + "\n";
  1269. return results;
  1270. }
  1271. string merInfo = "";
  1272. string merName = "";
  1273. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1274. if (mer != null)
  1275. {
  1276. merInfo = mer.KqMerNo;
  1277. merName = mer.MerchantName;
  1278. }
  1279. else
  1280. {
  1281. merInfo = "未找到商户";
  1282. }
  1283. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  1284. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1285. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  1286. int TopUserId = 0;
  1287. if (!string.IsNullOrEmpty(posUser.ParentNav))
  1288. {
  1289. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1290. if (ParentNavs.Length > 1)
  1291. {
  1292. TopUserId = int.Parse(ParentNavs[1]);
  1293. }
  1294. if (ParentNavs.Length == 1)
  1295. {
  1296. TopUserId = int.Parse(ParentNavs[0]);
  1297. }
  1298. }
  1299. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1300. string bindResult = "", bindTime = "";
  1301. if (pos.BindingState == 0)
  1302. {
  1303. bindResult = "未绑定";
  1304. }
  1305. else
  1306. {
  1307. bindResult = "已绑定";
  1308. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1309. }
  1310. string activeResult = "", activeTime = "";
  1311. if (pos.ActivationState == 0)
  1312. {
  1313. if (pos.CreditTrade < 1000)
  1314. {
  1315. activeResult = "未刷满1000";
  1316. }
  1317. else if (pos.TransferTime == null)
  1318. {
  1319. activeResult = "未激活, 需补录";
  1320. }
  1321. }
  1322. else
  1323. {
  1324. activeResult = "已激活";
  1325. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1326. }
  1327. string tradeAmount = pos.CreditTrade.ToString();
  1328. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1329. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  1330. if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(Deposit.ToString()))
  1331. {
  1332. Deposit = Deposit / 100;
  1333. }
  1334. string DepositGet = "未领取";
  1335. string DepositUser = "";
  1336. string DepositToUser = "";
  1337. decimal headAmount = 0;
  1338. decimal footAmount = 0;
  1339. string aDepositGet = "";
  1340. // ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1341. // if (reward.Id > 0)
  1342. // {
  1343. // Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1344. // DepositGet = "已领取";
  1345. // DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1346. // var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1347. // if (fAmount != null)
  1348. // {
  1349. // headAmount = fAmount.RewardAmount;
  1350. // }
  1351. // var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1352. // if (lAmount != null)
  1353. // {
  1354. // footAmount = lAmount.RewardAmount;
  1355. // }
  1356. // }
  1357. // string DepositGet6 = "未领取";
  1358. // string DepositUser6 = "";
  1359. var reward = db.ActiveReward.Where(m => m.KqSnNo == pos.PosSn).ToList();
  1360. foreach (var item in reward)
  1361. {
  1362. Users user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
  1363. var time = item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1364. aDepositGet += "已领取:" + item.RewardAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",领取时间:" + time + "\n";
  1365. }
  1366. string FluxGet6 = "未领取";
  1367. string FluxUser6 = "";
  1368. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1369. if (flux.Id > 0)
  1370. {
  1371. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1372. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1373. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1374. }
  1375. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1376. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
  1377. string OpenUser10 = "未领取";
  1378. string OpenUser20 = "未领取";
  1379. string Leader10 = "未领取";
  1380. string YYZX5 = "未领取";
  1381. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1382. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1383. if (openreward.Id > 0)
  1384. {
  1385. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1386. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发放时间:" + openreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1387. }
  1388. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1389. if (openreward.Id > 0)
  1390. {
  1391. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1392. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1393. }
  1394. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1395. if (leader10.Id > 0)
  1396. {
  1397. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1398. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1399. }
  1400. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1401. if (yyzx5.Id > 0)
  1402. {
  1403. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1404. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1405. }
  1406. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1407. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1408. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1409. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1410. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1411. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1412. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1413. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1414. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1415. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1416. // string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1417. // string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1418. string result = "";
  1419. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1420. result += "\n";
  1421. result += "机具SN:" + pos.PosSn + "\n";
  1422. string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
  1423. result += "机具类型:" + PosSnType + "\n";
  1424. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1425. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
  1426. if (change.Id > 0)
  1427. {
  1428. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1429. }
  1430. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
  1431. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1432. if (pos.PreUserId > 0)
  1433. {
  1434. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1435. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1436. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1437. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
  1438. }
  1439. else
  1440. {
  1441. result += "机具所属小分仓:暂无小分仓\n";
  1442. }
  1443. result += "入库时间:" + CreateDate + "\n";
  1444. result += "循环到期时间:" + RecycEndDate + "\n";
  1445. result += "划拨时间:" + TransferTime + "\n";
  1446. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1447. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1448. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1449. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1450. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1451. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1452. result += "服务费:" + Deposit + "\n";
  1453. // result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1454. result += "是否返现:" + aDepositGet + "\n";
  1455. // result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
  1456. result += "服务费返现应返现对象:" + DepositToUser + "\n";
  1457. // result += "服务费返现实际返现对象:" + DepositUser + "\n";
  1458. // if (pos.BrandId == 6)
  1459. // {
  1460. // result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1461. // result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1462. // }
  1463. result += "流量费:" + FluxGet6 + "\n";
  1464. result += "流量费发放对象:" + FluxUser6 + "\n";
  1465. result += "开机奖20:" + OpenUser20 + "\n";
  1466. result += "盟主奖:" + Leader10 + "\n";
  1467. result += "运营中心奖:" + YYZX5 + "\n";
  1468. return result;
  1469. }
  1470. #endregion
  1471. #region 生成机具兑换码
  1472. public IActionResult MakeCoupons(string right)
  1473. {
  1474. ViewBag.RightInfo = RightInfo;
  1475. ViewBag.right = right;
  1476. return View();
  1477. }
  1478. [HttpPost]
  1479. public string MakeCouponsDo(int Kind, int Number)
  1480. {
  1481. DateTime checkTime = DateTime.Parse("1900-01-01");
  1482. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1483. if (!string.IsNullOrEmpty(checkTimeString))
  1484. {
  1485. checkTime = DateTime.Parse(checkTimeString);
  1486. }
  1487. if (checkTime.AddHours(1) < DateTime.Now)
  1488. {
  1489. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1490. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1491. return "生成程序已执行";
  1492. }
  1493. return "请稍后再试";
  1494. }
  1495. #endregion
  1496. #region 导出没有刷满1000的机具
  1497. public IActionResult ExportPos(string right)
  1498. {
  1499. ViewBag.RightInfo = RightInfo;
  1500. ViewBag.right = right;
  1501. return View();
  1502. }
  1503. [HttpPost]
  1504. public JsonResult ExportPosDo()
  1505. {
  1506. WebCMSEntities db = new WebCMSEntities();
  1507. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1508. int total = poses.Count;
  1509. int index = 0;
  1510. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1511. foreach (PosMachinesTwo pos in poses)
  1512. {
  1513. index += 1;
  1514. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1515. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1516. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1517. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1518. Dictionary<string, object> item = new Dictionary<string, object>();
  1519. string TopRealName = "";
  1520. string TopMakerCode = "";
  1521. string TopMobile = "";
  1522. string ParentNav = user.ParentNav;
  1523. if (!string.IsNullOrEmpty(ParentNav))
  1524. {
  1525. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1526. if (navlist.Length > 1)
  1527. {
  1528. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1529. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1530. TopRealName = tuser.RealName;
  1531. TopMakerCode = tuser.MakerCode;
  1532. TopMobile = tuser.Mobile;
  1533. }
  1534. }
  1535. item.Add("TopRealName", TopRealName); //顶级姓名
  1536. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1537. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1538. item.Add("UpRealName", puser.RealName); //上级姓名
  1539. item.Add("RealName", user.RealName); //代理姓名
  1540. item.Add("MakerCode", user.MakerCode); //代理编号
  1541. item.Add("Mobile", user.Mobile); //代理手机号
  1542. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1543. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1544. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1545. item.Add("Sn", pos.PosSn); //SN
  1546. list.Add(item);
  1547. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1548. }
  1549. db.Dispose();
  1550. Dictionary<string, object> result = new Dictionary<string, object>();
  1551. result.Add("Status", "1");
  1552. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1553. result.Add("Obj", list);
  1554. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1555. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1556. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1557. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1558. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1559. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1560. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1561. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1562. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1563. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1564. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1565. ReturnFields.Add("Sn", "SN"); //SN
  1566. result.Add("Fields", ReturnFields);
  1567. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1568. return Json(result);
  1569. }
  1570. public string ExportPosCheck()
  1571. {
  1572. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1573. if (content == "finish")
  1574. {
  1575. RedisDbconn.Instance.Clear("ExportPosCheck");
  1576. }
  1577. return content;
  1578. }
  1579. #endregion
  1580. #region 更换机具
  1581. public IActionResult ChangePos(string right)
  1582. {
  1583. ViewBag.RightInfo = RightInfo;
  1584. ViewBag.right = right;
  1585. return View();
  1586. }
  1587. [HttpPost]
  1588. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1589. {
  1590. if (string.IsNullOrEmpty(OldSn))
  1591. {
  1592. return "请输入原机具SN";
  1593. }
  1594. if (string.IsNullOrEmpty(NewSn))
  1595. {
  1596. return "请输入新机具SN";
  1597. }
  1598. if (string.IsNullOrEmpty(MerNo))
  1599. {
  1600. return "请输入商户编号";
  1601. }
  1602. string[] OldSnList = OldSn.Replace("\r", "").Split('\n');
  1603. string[] NewSnList = NewSn.Replace("\r", "").Split('\n');
  1604. if (OldSnList.Length != NewSnList.Length)
  1605. {
  1606. return "原机具SN数量和新机具SN数量不一致";
  1607. }
  1608. WebCMSEntities db = new WebCMSEntities();
  1609. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1610. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1611. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1612. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1613. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1614. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1615. KqProducts oldPosBrand = new KqProducts();
  1616. KqProducts newPosBrand = new KqProducts();
  1617. MachineChange add = db.MachineChange.Add(new MachineChange()
  1618. {
  1619. CreateDate = DateTime.Now,
  1620. UpdateDate = DateTime.Now,
  1621. CreateMan = SysUserName + "-" + SysRealName,
  1622. ChangeNo = ChangeNo, //转换单号
  1623. UserId = 0, //创客
  1624. ChangeTime = DateTime.Now, //转换时间
  1625. BackStoreId = BackStore.Id, //退回仓库
  1626. BackStoreName = BackStore.StoreName, //退回仓库名称
  1627. Remark = "机具更换", //订单备注
  1628. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1629. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1630. OutProductName = OutStore.ProductName, //出库产品名称
  1631. OutStoreId = OutStore.Id, //出库仓库
  1632. OutStoreName = OutStore.StoreName, //出库仓库名称
  1633. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1634. OutStoreAddress = OutStore.Address, //出库仓库地址
  1635. OutStoreManager = "", //出库仓库联系人
  1636. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1637. }).Entity;
  1638. db.SaveChanges();
  1639. int BackProductType = 0;
  1640. string BackProductName = "";
  1641. string ChangeDeviceName = "";
  1642. string ChangeSnExpand = "";
  1643. for (int i = 0; i < OldSnList.Length; i++)
  1644. {
  1645. string OldSnNum = OldSnList[i];
  1646. string NewSnNum = NewSnList[i];
  1647. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1648. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1649. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1650. if (oldpos == null)
  1651. {
  1652. return "原机具SN不正确";
  1653. }
  1654. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
  1655. if (newpos == null)
  1656. {
  1657. return "新机具SN不正确或不满足条件";
  1658. }
  1659. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1660. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1661. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1662. if (merchant == null)
  1663. {
  1664. CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
  1665. }
  1666. if (oldpos.OpId > 0)
  1667. {
  1668. if (oldpos.ActivationState == 0)
  1669. {
  1670. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  1671. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1672. opUserAccount.ValidAmount += oldpos.OpReserve3;
  1673. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  1674. opUserAccount.TotalAmt += oldpos.OpReserve1;
  1675. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1676. {
  1677. CreateDate = DateTime.Now,
  1678. UserId = oldpos.OpId,
  1679. SeoDescription = "机具换绑",
  1680. OperateType = 1,
  1681. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1682. BeforeAmount = TotalAmount,
  1683. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1684. }).Entity;
  1685. oldpos.OpReserve1 = 0;
  1686. oldpos.OpReserve2 = 0;
  1687. oldpos.OpReserve3 = 0;
  1688. }
  1689. else
  1690. {
  1691. if (newpos.OpId > 0)
  1692. {
  1693. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == newpos.OpId && m.UserId == newpos.OpId) ?? new OpModels.UserAccount();
  1694. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1695. opUserAccount.ValidAmount += newpos.OpReserve3;
  1696. opUserAccount.ValidForGetAmount += newpos.OpReserve2;
  1697. opUserAccount.TotalAmt += newpos.OpReserve1;
  1698. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1699. {
  1700. CreateDate = DateTime.Now,
  1701. UserId = newpos.OpId,
  1702. SeoDescription = "机具换绑",
  1703. OperateType = 1,
  1704. UseAmount = newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
  1705. BeforeAmount = TotalAmount,
  1706. AfterAmount = TotalAmount + newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
  1707. }).Entity;
  1708. newpos.OpReserve1 = 0;
  1709. newpos.OpReserve2 = 0;
  1710. newpos.OpReserve3 = 0;
  1711. }
  1712. }
  1713. }
  1714. opdb.SaveChanges();
  1715. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1716. newpos.BindMerchantId = merchant.Id;
  1717. newpos.BuyUserId = oldpos.BuyUserId;
  1718. newpos.UserId = oldpos.UserId;
  1719. newpos.RecycEndDate = oldpos.RecycEndDate;
  1720. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1721. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1722. newpos.CreditTrade = oldpos.CreditTrade;
  1723. newpos.PosSnType = oldpos.PosSnType;
  1724. newpos.TransferTime = oldpos.TransferTime;
  1725. newpos.IsPurchase = oldpos.IsPurchase;
  1726. newpos.BindingState = oldpos.BindingState;
  1727. newpos.ActivationState = oldpos.ActivationState;
  1728. newpos.BindingTime = oldpos.BindingTime;
  1729. newpos.ActivationTime = oldpos.ActivationTime;
  1730. newpos.IsFirst = oldpos.IsFirst;
  1731. newpos.SeoKeyword = oldpos.SeoKeyword;
  1732. newpos.PrizeParams = oldpos.PrizeParams;
  1733. newpos.LeaderUserId = oldpos.LeaderUserId;
  1734. oldpos.Status = -1;
  1735. //对应调整客小爽企业版数据
  1736. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1737. if (posInfo != null)
  1738. {
  1739. posInfo.PosSn = newpos.PosSn;
  1740. posInfo.PosId = newpos.Id;
  1741. db.SaveChanges();
  1742. }
  1743. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1744. if (forMerNo != null)
  1745. {
  1746. forMerNo.SnId = newpos.Id;
  1747. }
  1748. merchant.KqSnNo = NewSn;
  1749. merchant.ActiveStatus = newpos.ActivationState;
  1750. merchant.MerStandardDate = newpos.ActivationTime;
  1751. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1752. {
  1753. CreateDate = DateTime.Now,
  1754. UpdateDate = DateTime.Now,
  1755. CreateMan = SysUserName + "-" + SysRealName,
  1756. ChangeNo = ChangeNo, //订单号
  1757. ChangeId = add.Id, //订单Id
  1758. BackProductType = oldpos.BrandId, //退回产品类型
  1759. BackProductName = oldPosBrand.Name, //退回产品名称
  1760. UserId = 0, //创客
  1761. BackSnNo = oldpos.PosSn, //设备SN编号
  1762. OutProductType = newpos.BrandId, //出库产品类型
  1763. OutProductName = newPosBrand.Name, //出库产品名称
  1764. OutSnNo = newpos.PosSn, //出库设备SN编号
  1765. OutSnType = newpos.PosSnType, //出库SN机具类型
  1766. Remark = "机具更换", //备注
  1767. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1768. });
  1769. db.SaveChanges();
  1770. BackProductType = oldpos.BrandId;
  1771. BackProductName = newPosBrand.Name;
  1772. ChangeDeviceName = oldpos.DeviceName;
  1773. ChangeSnExpand += oldpos.PosSn + "\n";
  1774. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1775. //同步商户交易额
  1776. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  1777. }
  1778. add.BackProductType = BackProductType; //退回产品类型
  1779. add.BackProductName = BackProductName; //退回产品名称
  1780. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1781. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1782. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1783. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1784. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1785. db.SaveChanges();
  1786. db.Dispose();
  1787. if (IsSend == 1)
  1788. {
  1789. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1790. {
  1791. UserId = pos.BuyUserId, //接收创客
  1792. MsgType = 2,
  1793. Title = "换绑成功通知", //标题
  1794. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1795. CreateDate = DateTime.Now,
  1796. }));
  1797. }
  1798. if (BackStore.UserId != OutStore.UserId)
  1799. {
  1800. RedisDbconn.Instance.AddList("ResetStoreReserveQueue", BackStore.UserId);
  1801. RedisDbconn.Instance.AddList("ResetStoreReserveQueue", OutStore.UserId);
  1802. }
  1803. return "success";
  1804. }
  1805. #endregion
  1806. #region 坏机换新
  1807. public IActionResult ChangeBadPos(string right)
  1808. {
  1809. ViewBag.RightInfo = RightInfo;
  1810. ViewBag.right = right;
  1811. return View();
  1812. }
  1813. [HttpPost]
  1814. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1815. {
  1816. string[] OldSnList;
  1817. string[] NewSnList;
  1818. decimal amount = 0;
  1819. List<string> opData = new List<string>();
  1820. //创客坏机换新
  1821. if (ChangeType == "0")
  1822. {
  1823. if (string.IsNullOrEmpty(MakerCode))
  1824. {
  1825. return "请输入创客编号";
  1826. }
  1827. if (string.IsNullOrEmpty(OldSn))
  1828. {
  1829. return "请输入坏机SN";
  1830. }
  1831. if (string.IsNullOrEmpty(NewSn))
  1832. {
  1833. return "请输入新机SN";
  1834. }
  1835. if (string.IsNullOrEmpty(FromStoreNo))
  1836. {
  1837. return "请输入新机发货仓库编号";
  1838. }
  1839. if (string.IsNullOrEmpty(BackStoreNo))
  1840. {
  1841. return "请输入坏机退回仓库编号";
  1842. }
  1843. OldSnList = OldSn.Replace("\r", "").Split('\n');
  1844. NewSnList = NewSn.Replace("\r", "").Split('\n');
  1845. if (OldSnList.Length != NewSnList.Length)
  1846. {
  1847. return "原机具SN数量和新机具SN数量不一致";
  1848. }
  1849. for (int i = 0; i < OldSnList.Length; i++)
  1850. {
  1851. string OldSnNum = OldSnList[i];
  1852. string NewSnNum = NewSnList[i];
  1853. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1854. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1855. if (storeForCodeFrom.StoreId == 0)
  1856. {
  1857. return "您输入的新机发货仓库编号不存在";
  1858. }
  1859. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1860. if (storeForCodeBack.StoreId == 0)
  1861. {
  1862. return "您输入的坏机退回仓库编号不存在";
  1863. }
  1864. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1865. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1866. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1867. if (oldpos.Id == 0)
  1868. {
  1869. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1870. }
  1871. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1872. if (newpos.Id == 0)
  1873. {
  1874. return "您输入的新机SN不存在或不满足条件";
  1875. }
  1876. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1877. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1878. {
  1879. return "您输入的新机发货仓库不符新机机具对应品牌";
  1880. }
  1881. if (newpos.StoreId != storeFrom.Id)
  1882. {
  1883. return "您输入的新机SN不在新机发货仓库";
  1884. }
  1885. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1886. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1887. {
  1888. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1889. }
  1890. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1891. {
  1892. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1893. }
  1894. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1895. if (brandInfo.Name.Contains("大POS"))
  1896. {
  1897. amount = 300;
  1898. }
  1899. if (brandInfo.Name.Contains("电签"))
  1900. {
  1901. amount = 200;
  1902. }
  1903. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1904. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1905. storeFromUserAcount.ValidAmount += amount;
  1906. storeBackUserAcount.ValidAmount -= amount;
  1907. if (oldpos.OpId > 0)
  1908. {
  1909. if (newpos.OpId > 0)
  1910. {
  1911. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  1912. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1913. opUserAccount.ValidAmount += oldpos.OpReserve3;
  1914. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  1915. opUserAccount.TotalAmt += oldpos.OpReserve1;
  1916. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1917. {
  1918. CreateDate = DateTime.Now,
  1919. UserId = oldpos.OpId,
  1920. SeoDescription = "坏机换新",
  1921. OperateType = 1,
  1922. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1923. BeforeAmount = TotalAmount,
  1924. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1925. }).Entity;
  1926. }
  1927. if (newpos.OpId == 0)
  1928. {
  1929. newpos.OpReserve1 = oldpos.OpReserve1;
  1930. newpos.OpReserve2 = oldpos.OpReserve3;
  1931. newpos.OpReserve3 = oldpos.OpReserve1;
  1932. newpos.OpId = oldpos.OpId;
  1933. }
  1934. }
  1935. newpos.BuyUserId = oldpos.BuyUserId;
  1936. newpos.UserId = oldpos.UserId;
  1937. newpos.RecycEndDate = oldpos.RecycEndDate;
  1938. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1939. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1940. newpos.CreditTrade = oldpos.CreditTrade;
  1941. newpos.PosSnType = oldpos.PosSnType;
  1942. newpos.TransferTime = oldpos.TransferTime;
  1943. newpos.IsPurchase = oldpos.IsPurchase;
  1944. newpos.BindingState = oldpos.BindingState;
  1945. newpos.ActivationState = oldpos.ActivationState;
  1946. newpos.BindingTime = oldpos.BindingTime;
  1947. newpos.ActivationTime = oldpos.ActivationTime;
  1948. newpos.IsFirst = oldpos.IsFirst;
  1949. newpos.SeoKeyword = oldpos.SeoKeyword;
  1950. newpos.PrizeParams = oldpos.PrizeParams;
  1951. newpos.LeaderUserId = oldpos.LeaderUserId;
  1952. newpos.BindMerchantId = oldpos.BindMerchantId;
  1953. newpos.StoreId = oldpos.StoreId;
  1954. newpos.PreUserId = oldpos.PreUserId;
  1955. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1956. {
  1957. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1958. }
  1959. oldpos.StoreId = storeBack.Id;
  1960. oldpos.QueryCount = 0;
  1961. oldpos.UpdateDate = null;
  1962. oldpos.ActivityList = null;
  1963. oldpos.SeoKeyword = null;
  1964. oldpos.SeoDescription = null;
  1965. oldpos.OrderId = 0;
  1966. oldpos.RecycEndDate = null;
  1967. oldpos.RecycBackCount = 0;
  1968. oldpos.PrizeParams = null;
  1969. oldpos.ScanQrTrade = 0;
  1970. oldpos.BindMerchantId = 0;
  1971. oldpos.CreditTrade = 0;
  1972. oldpos.DebitCardTrade = 0;
  1973. oldpos.IsVip = 0;
  1974. oldpos.UserNav = null;
  1975. oldpos.TransferTime = null;
  1976. oldpos.IsPurchase = 0;
  1977. oldpos.Detail = null;
  1978. oldpos.BindingTime = null;
  1979. oldpos.BindingState = 0;
  1980. oldpos.ActivationTime = null;
  1981. oldpos.ActivationState = 0;
  1982. oldpos.LeaderUserId = 0;
  1983. oldpos.PreUserId = 0;
  1984. oldpos.IsFirst = 0;
  1985. oldpos.DownFeeMan = null;
  1986. oldpos.DownFeeFlag = 0;
  1987. oldpos.DownFeeDate = null;
  1988. oldpos.UpFeeMan = null;
  1989. oldpos.UpFeeFlag = 0;
  1990. oldpos.UpFeeDate = null;
  1991. oldpos.OpReserve1 = 0;
  1992. oldpos.OpReserve2 = 0;
  1993. oldpos.OpReserve3 = 0;
  1994. oldpos.OpId = 0;
  1995. oldpos.RecycStartDate = null;
  1996. oldpos.SourcePosSn = null;
  1997. oldpos.BuyUserId = 0;
  1998. oldpos.UserId = 0;
  1999. oldpos.Status = -1;
  2000. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2001. db.SaveChanges();
  2002. opdb.SaveChanges();
  2003. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  2004. if (merchant != null)
  2005. {
  2006. merchant.KqSnNo = newpos.PosSn;
  2007. merchant.ActiveStatus = newpos.ActivationState;
  2008. }
  2009. db.SaveChanges();
  2010. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2011. {
  2012. CreateDate = DateTime.Now,
  2013. CreateMan = SysUserName + "-" + SysRealName,
  2014. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2015. OutStoreId = storeFrom.Id,
  2016. BackStoreId = storeBack.Id,
  2017. OutProductType = newpos.BrandId,
  2018. BackProductType = oldpos.BrandId,
  2019. UserId = userForMakerCode.UserId, //创客
  2020. }).Entity;
  2021. db.SaveChanges();
  2022. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2023. {
  2024. CreateDate = DateTime.Now,
  2025. CreateMan = SysUserName + "-" + SysRealName,
  2026. OutSnNo = OldSnNum,
  2027. BackSnNo = NewSnNum,
  2028. ChangeNo = add.ChangeNo, //转换单号
  2029. ChangeId = add.Id, //转换记录Id
  2030. UserId = add.UserId, //创客
  2031. }).Entity;
  2032. db.SaveChanges();
  2033. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2034. if (IsSend == 1)
  2035. {
  2036. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2037. {
  2038. UserId = userForMakerCode.UserId, //接收创客
  2039. MsgType = 2,
  2040. Title = "坏机换新成功通知", //标题
  2041. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  2042. CreateDate = DateTime.Now,
  2043. }));
  2044. }
  2045. //同步商户交易额
  2046. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2047. }
  2048. }
  2049. //仓库坏机换新
  2050. else
  2051. {
  2052. if (string.IsNullOrEmpty(StoreCode))
  2053. {
  2054. return "请输入仓库编号";
  2055. }
  2056. if (string.IsNullOrEmpty(OldSn))
  2057. {
  2058. return "请输入坏机SN";
  2059. }
  2060. if (string.IsNullOrEmpty(NewSn))
  2061. {
  2062. return "请输入新机SN";
  2063. }
  2064. if (string.IsNullOrEmpty(FromStoreNo))
  2065. {
  2066. return "请输入新机发货仓库编号";
  2067. }
  2068. if (string.IsNullOrEmpty(BackStoreNo))
  2069. {
  2070. return "请输入坏机退回仓库编号";
  2071. }
  2072. OldSnList = OldSn.Replace("\r", "").Split('\n');
  2073. NewSnList = NewSn.Replace("\r", "").Split('\n');
  2074. if (OldSnList.Length != NewSnList.Length)
  2075. {
  2076. return "原机具SN数量和新机具SN数量不一致";
  2077. }
  2078. for (int i = 0; i < OldSnList.Length; i++)
  2079. {
  2080. string OldSnNum = OldSnList[i];
  2081. string NewSnNum = NewSnList[i];
  2082. StoreHouse store = new StoreHouse();
  2083. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  2084. if (storeForBadCode.StoreId > 0)
  2085. {
  2086. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  2087. }
  2088. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  2089. if (storeForCodeFrom.StoreId == 0)
  2090. {
  2091. return "您输入的新机发货仓库编号不存在";
  2092. }
  2093. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  2094. if (storeForCodeBack.StoreId == 0)
  2095. {
  2096. return "您输入的坏机退回仓库编号不存在";
  2097. }
  2098. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  2099. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  2100. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  2101. if (oldpos.Id == 0)
  2102. {
  2103. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  2104. }
  2105. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  2106. if (newpos.Id == 0)
  2107. {
  2108. return "您输入的新机SN不存在或不满足条件";
  2109. }
  2110. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  2111. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2112. {
  2113. return "您输入的新机发货仓库不符新机机具对应品牌";
  2114. }
  2115. if (newpos.StoreId != storeFrom.Id)
  2116. {
  2117. return "您输入的新机SN不在新机发货仓库";
  2118. }
  2119. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  2120. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2121. {
  2122. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  2123. }
  2124. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2125. if (brandInfo.Name.Contains("大POS"))
  2126. {
  2127. amount = 300;
  2128. }
  2129. if (brandInfo.Name.Contains("电签"))
  2130. {
  2131. amount = 200;
  2132. }
  2133. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  2134. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  2135. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  2136. storeFromUserAcount.ValidAmount += amount;
  2137. storeBackUserAcount.ValidAmount -= amount;
  2138. newpos.StoreId = oldpos.StoreId;
  2139. newpos.BuyUserId = oldpos.BuyUserId;
  2140. newpos.UserId = oldpos.UserId;
  2141. newpos.LeaderUserId = oldpos.LeaderUserId;
  2142. newpos.PreUserId = oldpos.PreUserId;
  2143. newpos.IsFirst = oldpos.IsFirst;
  2144. newpos.TransferTime = oldpos.TransferTime;
  2145. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  2146. {
  2147. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2148. }
  2149. if (oldpos.OpId > 0)
  2150. {
  2151. if (newpos.OpId > 0)
  2152. {
  2153. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  2154. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  2155. opUserAccount.ValidAmount += oldpos.OpReserve3;
  2156. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  2157. opUserAccount.TotalAmt += oldpos.OpReserve1;
  2158. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  2159. {
  2160. CreateDate = DateTime.Now,
  2161. UserId = oldpos.OpId,
  2162. SeoDescription = "坏机换新",
  2163. OperateType = 1,
  2164. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2165. BeforeAmount = TotalAmount,
  2166. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2167. }).Entity;
  2168. }
  2169. if (newpos.OpId == 0)
  2170. {
  2171. newpos.OpReserve1 = oldpos.OpReserve1;
  2172. newpos.OpReserve2 = oldpos.OpReserve3;
  2173. newpos.OpReserve3 = oldpos.OpReserve1;
  2174. newpos.OpId = oldpos.OpId;
  2175. }
  2176. }
  2177. oldpos.StoreId = storeBack.Id;
  2178. oldpos.QueryCount = 0;
  2179. oldpos.UpdateDate = null;
  2180. oldpos.ActivityList = null;
  2181. oldpos.SeoKeyword = null;
  2182. oldpos.SeoDescription = null;
  2183. oldpos.OrderId = 0;
  2184. oldpos.RecycEndDate = null;
  2185. oldpos.RecycBackCount = 0;
  2186. oldpos.PrizeParams = null;
  2187. oldpos.ScanQrTrade = 0;
  2188. oldpos.BindMerchantId = 0;
  2189. oldpos.CreditTrade = 0;
  2190. oldpos.DebitCardTrade = 0;
  2191. oldpos.IsVip = 0;
  2192. oldpos.UserNav = null;
  2193. oldpos.TransferTime = null;
  2194. oldpos.IsPurchase = 0;
  2195. oldpos.Detail = null;
  2196. oldpos.BindingTime = null;
  2197. oldpos.BindingState = 0;
  2198. oldpos.ActivationTime = null;
  2199. oldpos.ActivationState = 0;
  2200. oldpos.LeaderUserId = 0;
  2201. oldpos.PreUserId = 0;
  2202. oldpos.IsFirst = 0;
  2203. oldpos.DownFeeMan = null;
  2204. oldpos.DownFeeFlag = 0;
  2205. oldpos.DownFeeDate = null;
  2206. oldpos.UpFeeMan = null;
  2207. oldpos.UpFeeFlag = 0;
  2208. oldpos.UpFeeDate = null;
  2209. oldpos.OpReserve1 = 0;
  2210. oldpos.OpReserve2 = 0;
  2211. oldpos.OpReserve3 = 0;
  2212. oldpos.OpId = 0;
  2213. oldpos.RecycStartDate = null;
  2214. oldpos.SourcePosSn = null;
  2215. oldpos.BuyUserId = 0;
  2216. oldpos.UserId = 0;
  2217. oldpos.Status = -1;
  2218. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2219. db.SaveChanges();
  2220. opdb.SaveChanges();
  2221. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2222. {
  2223. CreateDate = DateTime.Now,
  2224. CreateMan = SysUserName + "-" + SysRealName,
  2225. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2226. OutStoreId = storeFrom.Id,
  2227. BackStoreId = storeBack.Id,
  2228. OutProductType = newpos.BrandId,
  2229. BackProductType = oldpos.BrandId,
  2230. UserId = store.UserId, //创客
  2231. }).Entity;
  2232. db.SaveChanges();
  2233. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2234. {
  2235. CreateDate = DateTime.Now,
  2236. CreateMan = SysUserName + "-" + SysRealName,
  2237. OutSnNo = OldSnNum,
  2238. BackSnNo = NewSnNum,
  2239. ChangeNo = add.ChangeNo, //转换单号
  2240. ChangeId = add.Id, //转换记录Id
  2241. UserId = add.UserId, //创客
  2242. }).Entity;
  2243. db.SaveChanges();
  2244. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2245. if (IsSend == 1)
  2246. {
  2247. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2248. {
  2249. UserId = store.UserId, //接收创客
  2250. MsgType = 2,
  2251. Title = "坏机换新成功通知", //标题
  2252. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  2253. CreateDate = DateTime.Now,
  2254. }));
  2255. }
  2256. //同步商户交易额
  2257. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2258. }
  2259. }
  2260. foreach (string sub in opData)
  2261. {
  2262. string[] datalist = sub.Split(":");
  2263. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2264. }
  2265. return "success";
  2266. }
  2267. #endregion
  2268. #region 创客跨品牌换机
  2269. public IActionResult ChangePosCrossBrand(string right)
  2270. {
  2271. ViewBag.RightInfo = RightInfo;
  2272. ViewBag.right = right;
  2273. return View();
  2274. }
  2275. [HttpPost]
  2276. public string ChangePosCrossBrandDo(string MakerCode, string OldSn, string BackStoreNo, string NewSn, string FromStoreNo, int IsSend = 0)
  2277. {
  2278. string[] OldSnList;
  2279. string[] NewSnList;
  2280. decimal amount = 0;
  2281. List<string> opData = new List<string>();
  2282. if (string.IsNullOrEmpty(MakerCode))
  2283. {
  2284. return "请输入创客编号";
  2285. }
  2286. if (string.IsNullOrEmpty(OldSn))
  2287. {
  2288. return "请输入旧机SN";
  2289. }
  2290. if (string.IsNullOrEmpty(BackStoreNo))
  2291. {
  2292. return "请输入旧机退回仓库编号";
  2293. }
  2294. if (string.IsNullOrEmpty(NewSn))
  2295. {
  2296. return "请输入新机SN";
  2297. }
  2298. if (string.IsNullOrEmpty(FromStoreNo))
  2299. {
  2300. return "请输入新机发货仓库编号";
  2301. }
  2302. OldSnList = OldSn.Replace("\r", "").Replace("\n", ",").Split(',');
  2303. NewSnList = NewSn.Replace("\r", "").Replace("\n", ",").Split(',');
  2304. if (OldSnList.Length != NewSnList.Length)
  2305. {
  2306. return "原机具SN数量和新机具SN数量不一致";
  2307. }
  2308. var ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  2309. for (int i = 0; i < OldSnList.Length; i++)
  2310. {
  2311. string OldSnNum = OldSnList[i];
  2312. string NewSnNum = NewSnList[i];
  2313. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  2314. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  2315. if (userInfo.Id == 0)
  2316. {
  2317. return MakerCode + "不存在或关联信息缺失";
  2318. }
  2319. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  2320. if (storeForCodeFrom.StoreId == 0)
  2321. {
  2322. return "您输入的新机发货仓库编号不存在";
  2323. }
  2324. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  2325. if (storeForCodeBack.StoreId == 0)
  2326. {
  2327. return "您输入的旧机退回仓库编号不存在";
  2328. }
  2329. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  2330. if (oldForSnNo.SnId == 0)
  2331. {
  2332. return OldSnNum + "不存在或关联信息缺失";
  2333. }
  2334. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  2335. if (newForSnNo.SnId == 0)
  2336. {
  2337. return NewSnNum + "不存在或关联信息缺失";
  2338. }
  2339. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  2340. if (oldpos.Id == 0)
  2341. {
  2342. return "您输入的旧机SN不存在或者不在" + MakerCode + "名下";
  2343. }
  2344. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.BuyUserId == 0 && m.UserId == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  2345. if (newpos.Id == 0)
  2346. {
  2347. return "您输入的新机SN不存在或不满足条件";
  2348. }
  2349. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  2350. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  2351. {
  2352. return "您输入的新机发货仓库不符新机机具对应品牌";
  2353. }
  2354. if (newpos.StoreId != storeFrom.Id)
  2355. {
  2356. return "您输入的新机SN不在新机发货仓库";
  2357. }
  2358. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  2359. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2360. {
  2361. return "您输入的旧机退回仓库不符旧机机具对应品牌";
  2362. }
  2363. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2364. var brandNew = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  2365. if (brandInfo.Kind != brandNew.Kind)
  2366. {
  2367. return "原机具和新机具不是同种机型(电签或大POS)";
  2368. }
  2369. if (brandInfo.Name.Contains("大POS"))
  2370. {
  2371. amount = 300;
  2372. }
  2373. if (brandInfo.Name.Contains("电签"))
  2374. {
  2375. amount = 200;
  2376. }
  2377. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  2378. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  2379. storeFromUserAcount.ValidAmount += amount;
  2380. storeBackUserAcount.ValidAmount -= amount;
  2381. storeFrom.LaveNum -= 1;
  2382. storeBack.LaveNum += 1;
  2383. if (oldpos.OpId > 0)
  2384. {
  2385. if (newpos.OpId > 0)
  2386. {
  2387. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  2388. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  2389. opUserAccount.ValidAmount += oldpos.OpReserve3;
  2390. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  2391. opUserAccount.TotalAmt += oldpos.OpReserve1;
  2392. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  2393. {
  2394. CreateDate = DateTime.Now,
  2395. UserId = oldpos.OpId,
  2396. SeoDescription = "创客跨品牌换机",
  2397. OperateType = 1,
  2398. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2399. BeforeAmount = TotalAmount,
  2400. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2401. }).Entity;
  2402. }
  2403. if (newpos.OpId == 0)
  2404. {
  2405. newpos.OpReserve1 = oldpos.OpReserve1;
  2406. newpos.OpReserve2 = oldpos.OpReserve3;
  2407. newpos.OpReserve3 = oldpos.OpReserve1;
  2408. newpos.OpId = oldpos.OpId;
  2409. }
  2410. }
  2411. //发出方
  2412. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2413. {
  2414. CreateDate = DateTime.Now,
  2415. UserId = userInfo.Id, //创客
  2416. BrandId = newpos.BrandId,//产品类型
  2417. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2418. TransType = 6, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2419. SnNo = newpos.PosSn, //SN编号
  2420. SnType = newpos.PosSnType, //SN机具类型
  2421. StockOpDirect = 1, //库存操作方向(0 入库 1 出库)
  2422. DeviceVendor = newpos.DeviceName, //设备厂商
  2423. DeviceModel = newpos.DeviceKind, //设备型号
  2424. DeviceType = newpos.DeviceType, //设备类型
  2425. // FromUserId = storeFrom.UserId, //出货创客
  2426. StoreId = storeFrom.Id,//出货仓库
  2427. FromDate = DateTime.Now, //出库时间
  2428. FromRemark = "跨品牌换机,出库", //出库备注
  2429. SourceStoreId = newpos.SourceStoreId, //源仓库
  2430. ToUserId = userInfo.Id,//收货创客
  2431. });
  2432. //接收方
  2433. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2434. {
  2435. CreateDate = DateTime.Now,
  2436. UserId = userInfo.Id, //创客
  2437. BrandId = oldpos.BrandId,//产品类型
  2438. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2439. TransType = 7, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2440. SnNo = oldpos.PosSn, //SN编号
  2441. SnType = oldpos.PosSnType, //SN机具类型
  2442. StockOpDirect = 0, //库存操作方向(0 入库 1 出库)
  2443. DeviceVendor = oldpos.DeviceName, //设备厂商
  2444. DeviceModel = oldpos.DeviceKind, //设备型号
  2445. DeviceType = oldpos.DeviceType, //设备类型
  2446. StoreId = oldpos.StoreId,//出货仓库
  2447. FromDate = DateTime.Now, //出库时间
  2448. FromRemark = "跨品牌换机,入库", //出库备注
  2449. SourceStoreId = oldpos.SourceStoreId, //源仓库
  2450. ToStoreId = storeBack.Id,//收货仓库
  2451. });
  2452. newpos.BuyUserId = oldpos.BuyUserId;
  2453. newpos.UserId = oldpos.UserId;
  2454. newpos.RecycEndDate = oldpos.RecycEndDate;
  2455. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  2456. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  2457. newpos.CreditTrade = oldpos.CreditTrade;
  2458. newpos.PosSnType = oldpos.PosSnType;
  2459. newpos.TransferTime = oldpos.TransferTime;
  2460. newpos.IsPurchase = oldpos.IsPurchase;
  2461. newpos.BindingState = oldpos.BindingState;
  2462. newpos.ActivationState = oldpos.ActivationState;
  2463. newpos.BindingTime = oldpos.BindingTime;
  2464. newpos.ActivationTime = oldpos.ActivationTime;
  2465. newpos.IsFirst = oldpos.IsFirst;
  2466. newpos.SeoKeyword = oldpos.SeoKeyword;
  2467. newpos.PrizeParams = oldpos.PrizeParams;
  2468. newpos.LeaderUserId = oldpos.LeaderUserId;
  2469. newpos.BindMerchantId = oldpos.BindMerchantId;
  2470. newpos.PreUserId = oldpos.PreUserId;
  2471. if (!opData.Contains(newpos.BuyUserId + ":" + newpos.BrandId))
  2472. {
  2473. opData.Add(newpos.BuyUserId + ":" + newpos.BrandId);
  2474. }
  2475. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  2476. {
  2477. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2478. }
  2479. oldpos.StoreId = storeBack.Id;
  2480. oldpos.QueryCount = 0;
  2481. oldpos.UpdateDate = null;
  2482. oldpos.ActivityList = null;
  2483. oldpos.SeoKeyword = null;
  2484. oldpos.SeoDescription = null;
  2485. oldpos.OrderId = 0;
  2486. oldpos.RecycEndDate = null;
  2487. oldpos.RecycBackCount = 0;
  2488. oldpos.PrizeParams = null;
  2489. oldpos.ScanQrTrade = 0;
  2490. oldpos.BindMerchantId = 0;
  2491. oldpos.CreditTrade = 0;
  2492. oldpos.DebitCardTrade = 0;
  2493. oldpos.IsVip = 0;
  2494. oldpos.UserNav = null;
  2495. oldpos.TransferTime = null;
  2496. oldpos.IsPurchase = 0;
  2497. oldpos.Detail = null;
  2498. oldpos.BindingTime = null;
  2499. oldpos.BindingState = 0;
  2500. oldpos.ActivationTime = null;
  2501. oldpos.ActivationState = 0;
  2502. oldpos.LeaderUserId = 0;
  2503. oldpos.PreUserId = 0;
  2504. oldpos.IsFirst = 0;
  2505. oldpos.DownFeeMan = null;
  2506. oldpos.DownFeeFlag = 0;
  2507. oldpos.DownFeeDate = null;
  2508. oldpos.UpFeeMan = null;
  2509. oldpos.UpFeeFlag = 0;
  2510. oldpos.UpFeeDate = null;
  2511. oldpos.OpReserve1 = 0;
  2512. oldpos.OpReserve2 = 0;
  2513. oldpos.OpReserve3 = 0;
  2514. oldpos.OpId = 0;
  2515. oldpos.RecycStartDate = null;
  2516. oldpos.SourcePosSn = null;
  2517. oldpos.BuyUserId = 0;
  2518. oldpos.UserId = 0;
  2519. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2520. db.SaveChanges();
  2521. opdb.SaveChanges();
  2522. if (IsSend == 1)
  2523. {
  2524. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2525. {
  2526. UserId = userForMakerCode.UserId, //接收创客
  2527. MsgType = 2,
  2528. Title = "创客跨品牌换机", //标题
  2529. Summary = "您的旧机 " + brandInfo.Name + " SN:" + OldSnNum + "已经成功为您换为" + brandNew.Name + "SN:" + NewSnNum + "。",
  2530. CreateDate = DateTime.Now,
  2531. }));
  2532. }
  2533. //同步商户交易额
  2534. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2535. }
  2536. foreach (string sub in opData)
  2537. {
  2538. string[] datalist = sub.Split(":");
  2539. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2540. }
  2541. return "success";
  2542. }
  2543. #endregion
  2544. #region 机具解绑
  2545. public IActionResult Unbind(string right)
  2546. {
  2547. ViewBag.RightInfo = RightInfo;
  2548. ViewBag.right = right;
  2549. return View();
  2550. }
  2551. [HttpPost]
  2552. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2553. {
  2554. if (string.IsNullOrEmpty(PosSn))
  2555. {
  2556. return "请输入机具SN";
  2557. }
  2558. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2559. if (forSnNo == null)
  2560. {
  2561. return "机具SN不存在";
  2562. }
  2563. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2564. if (pos == null)
  2565. {
  2566. return "机具SN不存在";
  2567. }
  2568. if (pos.ActivationState == 1)
  2569. {
  2570. return "机具已激活,不能解绑";
  2571. }
  2572. if (pos.BuyUserId == 0)
  2573. {
  2574. return "机具是仓库机,不支持解绑";
  2575. }
  2576. if (pos.BindingState == 0)
  2577. {
  2578. return "机具未绑定,不支持解绑";
  2579. }
  2580. // if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2581. // {
  2582. // return "机具绑定已超过30天,不支持解绑";
  2583. // }
  2584. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2585. {
  2586. return "该机具已交易,无法解绑";
  2587. }
  2588. if (pos.BrandId != 10 || pos.BrandId != 11)
  2589. {
  2590. if (string.IsNullOrEmpty(MakerCode))
  2591. {
  2592. return "请输入创客编号";
  2593. }
  2594. if (string.IsNullOrEmpty(MerNo))
  2595. {
  2596. return "请输入商户编号";
  2597. }
  2598. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2599. if (forMakerCode == null)
  2600. {
  2601. return "创客不存在";
  2602. }
  2603. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2604. if (forMerNo == null)
  2605. {
  2606. return "商户编号不存在";
  2607. }
  2608. if (pos.BuyUserId != forMakerCode.UserId)
  2609. {
  2610. return "机具SN和创客不匹配";
  2611. }
  2612. if (forMerNo != null)
  2613. {
  2614. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2615. if (merchant != null)
  2616. {
  2617. //机具解绑删除客小爽企业版对应数据
  2618. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2619. if (merInfo != null)
  2620. {
  2621. db.BusinessPartnerMerchant.Remove(merInfo);
  2622. }
  2623. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2624. if (posInfo != null)
  2625. {
  2626. db.BusinessPartnerPos.Remove(posInfo);
  2627. }
  2628. db.PosMerchantInfo.Remove(merchant);
  2629. }
  2630. db.MachineForMerNo.Remove(forMerNo);
  2631. db.SaveChanges();
  2632. }
  2633. }
  2634. else
  2635. {
  2636. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2637. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2638. if (forMerNo != null && posMerchantInfo != null)
  2639. {
  2640. //机具解绑删除客小爽企业版对应数据
  2641. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  2642. if (merInfo != null)
  2643. {
  2644. db.BusinessPartnerMerchant.Remove(merInfo);
  2645. }
  2646. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2647. if (posInfo != null)
  2648. {
  2649. db.BusinessPartnerPos.Remove(posInfo);
  2650. }
  2651. db.PosMerchantInfo.Remove(posMerchantInfo);
  2652. db.MachineForMerNo.Remove(forMerNo);
  2653. db.SaveChanges();
  2654. }
  2655. }
  2656. db.MachineUnBind.Add(new MachineUnBind()
  2657. {
  2658. CreateDate = DateTime.Now,
  2659. SeoTitle = SysUserName + "-" + SysRealName,
  2660. MerchantId = pos.BindMerchantId,
  2661. AuditDate = DateTime.Now,
  2662. AuditDesc = "平台操作解绑",
  2663. AuditStatus = 1,
  2664. SnNo = pos.PosSn,
  2665. BrandId = pos.BrandId,
  2666. UserId = pos.BuyUserId,
  2667. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2668. });
  2669. pos.BindMerchantId = 0;
  2670. pos.BindingState = 0;
  2671. pos.BindingTime = null;
  2672. pos.UserId = pos.BuyUserId;
  2673. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2674. db.SaveChanges();
  2675. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2676. if (IsSend == 1)
  2677. {
  2678. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2679. {
  2680. UserId = pos.BuyUserId, //接收创客
  2681. MsgType = 2,
  2682. Title = "解绑成功通知", //标题
  2683. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2684. CreateDate = DateTime.Now,
  2685. }));
  2686. }
  2687. return "success";
  2688. }
  2689. #endregion
  2690. #region 通过券码修改盟主标记
  2691. public IActionResult ChangeSignQuan(string right)
  2692. {
  2693. ViewBag.RightInfo = RightInfo;
  2694. ViewBag.right = right;
  2695. return View();
  2696. }
  2697. [HttpPost]
  2698. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2699. {
  2700. if (string.IsNullOrEmpty(Coupons))
  2701. {
  2702. return "请输入机具券码,多个券码用回车分隔";
  2703. }
  2704. if (string.IsNullOrEmpty(MakerCode))
  2705. {
  2706. return "请输入创客编号";
  2707. }
  2708. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2709. if (forMakerCode == null)
  2710. {
  2711. return "创客不存在";
  2712. }
  2713. string[] SnList = Coupons.Replace("\r", "").Split('\n');
  2714. foreach (var item in SnList)
  2715. {
  2716. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2717. if (coupos == null)
  2718. {
  2719. return "机具券不存在";
  2720. }
  2721. else
  2722. {
  2723. coupos.LeaderUserId = forMakerCode.UserId;
  2724. }
  2725. }
  2726. db.SaveChanges();
  2727. return "success";
  2728. }
  2729. #endregion
  2730. #region 通过机具SN修改盟主标记
  2731. public IActionResult ChangeSignSn(string right)
  2732. {
  2733. ViewBag.RightInfo = RightInfo;
  2734. ViewBag.right = right;
  2735. return View();
  2736. }
  2737. [HttpPost]
  2738. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2739. {
  2740. if (string.IsNullOrEmpty(PosSn))
  2741. {
  2742. return "请输入机具SN,多个SN用回车分隔";
  2743. }
  2744. if (string.IsNullOrEmpty(MakerCode))
  2745. {
  2746. return "请输入创客编号";
  2747. }
  2748. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2749. if (forMakerCode == null)
  2750. {
  2751. return "创客不存在";
  2752. }
  2753. string[] SnList = PosSn.Replace("\r", "").Split('\n');
  2754. foreach (var item in SnList)
  2755. {
  2756. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2757. if (pos == null)
  2758. {
  2759. return "该机具不存在";
  2760. }
  2761. else
  2762. {
  2763. pos.LeaderUserId = forMakerCode.UserId;
  2764. }
  2765. }
  2766. db.SaveChanges();
  2767. return "success";
  2768. }
  2769. #endregion
  2770. #region 机具循环列表
  2771. /// <summary>
  2772. /// 根据条件查询机具循环列表
  2773. /// </summary>
  2774. /// <returns></returns>
  2775. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2776. {
  2777. ViewBag.RightInfo = RightInfo;
  2778. ViewBag.right = right;
  2779. ViewBag.SwapSnExpand = SwapSnExpand;
  2780. ViewBag.SnNos = SnNos;
  2781. return View();
  2782. }
  2783. #endregion
  2784. #region 根据条件查询机具循环列表
  2785. /// <summary>
  2786. /// 机具循环列表
  2787. /// </summary>
  2788. /// <returns></returns>
  2789. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2790. {
  2791. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2792. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2793. Fields.Add("SnNos", "1"); //发货机具SN
  2794. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2795. if (!string.IsNullOrEmpty(SwapSnExpand))
  2796. {
  2797. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2798. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2799. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2800. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2801. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2802. for (int i = 0; i < SnNoList.Length; i++)
  2803. {
  2804. Dictionary<string, object> data = new Dictionary<string, object>();
  2805. data["ApplyNo"] = apply.ApplyNo;
  2806. data["OrderNo"] = order.OrderNo;
  2807. data["MakerCode"] = user.MakerCode;
  2808. data["RealName"] = user.RealName;
  2809. if (SnNoList.Length > i)
  2810. {
  2811. string SourceSn = SnNoList[i].Split(':')[0];
  2812. data["ComeSn"] = SnNoList[i];
  2813. data["ComeSnParam"] = SourceSn;
  2814. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2815. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2816. if (pos.LeaderUserId > 0)
  2817. {
  2818. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2819. data["ComeSnMakerCode"] = leader.MakerCode;
  2820. data["ComeSnRealName"] = leader.RealName;
  2821. }
  2822. }
  2823. if (OrderSnNo.Length > i)
  2824. {
  2825. string SendSn = OrderSnNo[i];
  2826. data["SendSn"] = OrderSnNo[i];
  2827. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2828. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2829. if (pos.LeaderUserId > 0)
  2830. {
  2831. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2832. data["SendSnMakerCode"] = leader.MakerCode;
  2833. data["SendSnRealName"] = leader.RealName;
  2834. }
  2835. }
  2836. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2837. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2838. dataList.Add(data);
  2839. }
  2840. }
  2841. else if (!string.IsNullOrEmpty(SnNos))
  2842. {
  2843. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2844. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2845. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2846. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2847. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2848. for (int i = 0; i < OrderSnNo.Length; i++)
  2849. {
  2850. Dictionary<string, object> data = new Dictionary<string, object>();
  2851. data["ApplyNo"] = apply.ApplyNo;
  2852. data["OrderNo"] = order.OrderNo;
  2853. data["MakerCode"] = user.MakerCode;
  2854. data["RealName"] = user.RealName;
  2855. if (SnNoList.Length > i)
  2856. {
  2857. string SourceSn = SnNoList[i].Split(':')[0];
  2858. data["ComeSn"] = SnNoList[i];
  2859. data["ComeSnParam"] = SourceSn;
  2860. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2861. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2862. if (pos.LeaderUserId > 0)
  2863. {
  2864. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2865. data["ComeSnMakerCode"] = leader.MakerCode;
  2866. data["ComeSnRealName"] = leader.RealName;
  2867. }
  2868. }
  2869. if (OrderSnNo.Length > i)
  2870. {
  2871. string SendSn = OrderSnNo[i];
  2872. data["SendSn"] = OrderSnNo[i];
  2873. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2874. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2875. if (pos.LeaderUserId > 0)
  2876. {
  2877. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2878. data["SendSnMakerCode"] = leader.MakerCode;
  2879. data["SendSnRealName"] = leader.RealName;
  2880. }
  2881. }
  2882. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2883. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2884. dataList.Add(data);
  2885. }
  2886. }
  2887. Dictionary<string, object> obj = new Dictionary<string, object>();
  2888. obj.Add("code", 0);
  2889. obj.Add("msg", "");
  2890. obj.Add("count", dataList.Count);
  2891. obj.Add("data", dataList);
  2892. return Json(obj);
  2893. }
  2894. #endregion
  2895. #region 查询机具循环
  2896. /// <summary>
  2897. /// 根据条件查询机具来源机具和券码
  2898. /// </summary>
  2899. /// <returns></returns>
  2900. public IActionResult SourceLoop(string right, string SnNos)
  2901. {
  2902. ViewBag.RightInfo = RightInfo;
  2903. ViewBag.right = right;
  2904. ViewBag.SnNos = SnNos;
  2905. return View();
  2906. }
  2907. #endregion
  2908. #region 根据条件查询机具来源机具和券码
  2909. /// <summary>
  2910. /// 机具循环列表
  2911. /// </summary>
  2912. /// <returns></returns>
  2913. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2914. {
  2915. var result = "";
  2916. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2917. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2918. if (pos.Id == 0)
  2919. {
  2920. return "机具:" + SnNo + "不存在";
  2921. }
  2922. else
  2923. {
  2924. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2925. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2926. result += "循环开始时间:" + stattime + "\n";
  2927. result += "循环结束时间:" + endtime + "\n";
  2928. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2929. }
  2930. return result;
  2931. }
  2932. #endregion
  2933. #region 查询创客直推奖
  2934. public IActionResult Prize100(string right)
  2935. {
  2936. ViewBag.RightInfo = RightInfo;
  2937. ViewBag.right = right;
  2938. return View();
  2939. }
  2940. [HttpPost]
  2941. public Dictionary<string, string> Prize100Do(string MakerCode)
  2942. {
  2943. Dictionary<string, string> dic = new Dictionary<string, string>();
  2944. string result = "";
  2945. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2946. if (forMakerCode == null)
  2947. {
  2948. result += "创客编号不存在\n";
  2949. dic.Add("code", "1");
  2950. dic.Add("result", result);
  2951. return dic;
  2952. }
  2953. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2954. if (OrderCount == 0)
  2955. {
  2956. result += "该创客未下单\n";
  2957. dic.Add("code", "1");
  2958. dic.Add("result", result);
  2959. return dic;
  2960. }
  2961. if (OrderCount > 1)
  2962. {
  2963. result += "该创客已不是首笔下单\n";
  2964. dic.Add("code", "1");
  2965. dic.Add("result", result);
  2966. return dic;
  2967. }
  2968. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2969. if (order.PayStatus < 1)
  2970. {
  2971. result += "未付款\n";
  2972. dic.Add("code", "1");
  2973. dic.Add("result", result);
  2974. return dic;
  2975. }
  2976. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2977. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2978. result += "订单号:" + order.OrderNo + "\n";
  2979. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2980. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2981. int posCouponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张未使用的券
  2982. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2983. if (posCouponCount + ActiveCount >= 3)
  2984. {
  2985. string IsGet = "未发放";
  2986. int ToUserId = 0;
  2987. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2988. if (item == null)
  2989. {
  2990. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2991. DateTime end = order.PayDate.Value.AddMinutes(2);
  2992. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2993. }
  2994. if (item != null)
  2995. {
  2996. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2997. ToUserId = item.UserId;
  2998. dic.Add("code", "1");
  2999. }
  3000. else
  3001. {
  3002. dic.Add("id", order.Id.ToString());
  3003. dic.Add("code", "0");
  3004. }
  3005. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  3006. result += "是否发放:" + IsGet + "\n";
  3007. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  3008. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  3009. }
  3010. else
  3011. {
  3012. result += "上级创客未满足条件\n手中有未使用券:" + posCouponCount + "张,激活机:" + ActiveCount + "台\n";
  3013. dic.Add("code", "1");
  3014. }
  3015. dic.Add("result", result);
  3016. return dic;
  3017. }
  3018. public string AddPrize100(int Id)
  3019. {
  3020. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  3021. if (order != null)
  3022. {
  3023. //机具券逻辑
  3024. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  3025. if (pro != null)
  3026. {
  3027. //推荐下单奖励
  3028. if (pro.ProductId == 10 || pro.ProductId == 11)
  3029. {
  3030. int OrderId = order.Id;
  3031. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  3032. if (!checkPrize)
  3033. {
  3034. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  3035. if (user != null)
  3036. {
  3037. bool directPrize = false; //直推奖标记
  3038. int ParentUserId = user.ParentUserId;
  3039. while (ParentUserId > 0)
  3040. {
  3041. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  3042. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  3043. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  3044. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  3045. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  3046. {
  3047. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  3048. directPrize = true;
  3049. db.SaveChanges();
  3050. return "发放成功";
  3051. }
  3052. ParentUserId = puser.ParentUserId;
  3053. }
  3054. }
  3055. }
  3056. return "已发放,请勿重复发放";
  3057. }
  3058. }
  3059. }
  3060. return "操作失败";
  3061. }
  3062. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  3063. {
  3064. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  3065. if (account == null)
  3066. {
  3067. account = db.UserAccount.Add(new UserAccount()
  3068. {
  3069. Id = UserId,
  3070. UserId = UserId,
  3071. }).Entity;
  3072. db.SaveChanges();
  3073. }
  3074. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3075. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3076. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3077. account.BalanceAmount += 100 * Count;
  3078. account.TotalAmount += 100 * Count;
  3079. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3080. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3081. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3082. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  3083. {
  3084. CreateDate = DateTime.Now,
  3085. UpdateDate = DateTime.Now,
  3086. UserId = UserId, //创客
  3087. ChangeType = 112, //变动类型
  3088. ChangeAmount = 100 * Count, //变更金额
  3089. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3090. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3091. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3092. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3093. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3094. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3095. QueryCount = OrderId,
  3096. }).Entity;
  3097. db.SaveChanges();
  3098. PublicFunction.SplitUserAccountRecord(add);
  3099. }
  3100. #endregion
  3101. #region 查询机具开机奖
  3102. public IActionResult OpenPrize(string right)
  3103. {
  3104. ViewBag.RightInfo = RightInfo;
  3105. ViewBag.right = right;
  3106. return View();
  3107. }
  3108. [HttpPost]
  3109. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  3110. {
  3111. Dictionary<string, string> dic = new Dictionary<string, string>();
  3112. string result = "";
  3113. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  3114. if (pos == null)
  3115. {
  3116. result += "机具SN号不存在\n";
  3117. dic.Add("code", "1");
  3118. dic.Add("result", result);
  3119. return dic;
  3120. }
  3121. if (pos.BindingState == 0)
  3122. {
  3123. result += "机具未绑定\n";
  3124. dic.Add("code", "1");
  3125. dic.Add("result", result);
  3126. return dic;
  3127. }
  3128. if (pos.ActivationState == 0)
  3129. {
  3130. result += "机具未激活\n";
  3131. dic.Add("code", "1");
  3132. dic.Add("result", result);
  3133. return dic;
  3134. }
  3135. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3136. if (merchant == null)
  3137. {
  3138. result += "商户不存在\n";
  3139. dic.Add("code", "1");
  3140. dic.Add("result", result);
  3141. return dic;
  3142. }
  3143. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3144. result += "机具号:" + PosSn + "\n";
  3145. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3146. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3147. string OpenUser10 = "未领取";
  3148. string OpenUser20 = "未领取";
  3149. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  3150. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  3151. if (openreward.Id > 0)
  3152. {
  3153. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  3154. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3155. }
  3156. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  3157. if (openreward.Id > 0)
  3158. {
  3159. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  3160. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3161. }
  3162. result += "开机奖20:" + OpenUser20 + "\n";
  3163. dic.Add("id", pos.Id.ToString());
  3164. dic.Add("code", "0");
  3165. dic.Add("result", result);
  3166. return dic;
  3167. }
  3168. public string AddOpenPrize(int Id)
  3169. {
  3170. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3171. if (pos == null)
  3172. {
  3173. return "机具未激活";
  3174. }
  3175. if (pos.BindingTime <= pos.TransferTime)
  3176. {
  3177. return "补录机,不能补发开机奖";
  3178. }
  3179. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3180. if (ActPrize == 0)
  3181. {
  3182. return "机具无押金";
  3183. }
  3184. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3185. if (merchant == null)
  3186. {
  3187. return "商户不存在";
  3188. }
  3189. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  3190. if (check)
  3191. {
  3192. return "开机奖励已发放,请勿重复操作";
  3193. }
  3194. // 从机具所属人上级开始分开机奖励
  3195. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  3196. if (user != null)
  3197. {
  3198. RedisDbconn.Instance.AddList("OpenRewardQueue", Id.ToString());
  3199. return "操作成功,请稍后查询";
  3200. }
  3201. db.Dispose();
  3202. return "操作失败";
  3203. }
  3204. #endregion
  3205. #region 查询机具流量费分佣
  3206. public IActionResult FluxPrize(string right)
  3207. {
  3208. ViewBag.RightInfo = RightInfo;
  3209. ViewBag.right = right;
  3210. return View();
  3211. }
  3212. [HttpPost]
  3213. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  3214. {
  3215. Dictionary<string, string> dic = new Dictionary<string, string>();
  3216. string result = "";
  3217. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  3218. if (pos == null)
  3219. {
  3220. result += "机具SN号不存在\n";
  3221. dic.Add("code", "1");
  3222. dic.Add("result", result);
  3223. return dic;
  3224. }
  3225. if (pos.BindingState == 0)
  3226. {
  3227. result += "机具未绑定\n";
  3228. dic.Add("code", "1");
  3229. dic.Add("result", result);
  3230. return dic;
  3231. }
  3232. if (pos.ActivationState == 0)
  3233. {
  3234. result += "机具未激活\n";
  3235. dic.Add("code", "1");
  3236. dic.Add("result", result);
  3237. return dic;
  3238. }
  3239. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3240. if (merchant == null)
  3241. {
  3242. result += "商户不存在\n";
  3243. dic.Add("code", "1");
  3244. dic.Add("result", result);
  3245. return dic;
  3246. }
  3247. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3248. result += "机具号:" + PosSn + "\n";
  3249. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3250. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3251. string FluxGet6 = "未领取";
  3252. string FluxUser6 = "";
  3253. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  3254. if (flux.Id > 0)
  3255. {
  3256. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  3257. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3258. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3259. }
  3260. result += "流量费:" + FluxGet6 + "\n";
  3261. result += "流量费发放对象:" + FluxUser6 + "\n";
  3262. dic.Add("id", pos.Id.ToString());
  3263. dic.Add("code", "0");
  3264. dic.Add("result", result);
  3265. return dic;
  3266. }
  3267. public string AddFluxPrize(int Id)
  3268. {
  3269. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3270. if (pos == null)
  3271. {
  3272. return "机具未激活";
  3273. }
  3274. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3275. if (ActPrize == 0)
  3276. {
  3277. return "机具无押金";
  3278. }
  3279. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3280. if (merchant == null)
  3281. {
  3282. return "商户不存在";
  3283. }
  3284. if (pos.BrandId == 6)
  3285. {
  3286. return "立刷不支持流量费分佣";
  3287. }
  3288. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  3289. {
  3290. return "无押金机,不支持流量费分佣";
  3291. }
  3292. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  3293. if (check)
  3294. {
  3295. return "流量费奖励已发放,请勿重复操作";
  3296. }
  3297. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  3298. if (trade != null)
  3299. {
  3300. try
  3301. {
  3302. string OrderNo = trade.TradeSerialNo; //单号
  3303. DateTime TradeDate = trade.CreateDate.Value;
  3304. string TradeMonth = TradeDate.ToString("yyyyMM");
  3305. decimal FeeAmount = trade.FeeAmount; //流量费
  3306. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  3307. {
  3308. FeeAmount = FeeAmount / 100;
  3309. }
  3310. string TradeSnNo = trade.TradeSnNo; //机具SN
  3311. decimal FluxProfit = 0;
  3312. if (trade.ProductType == "1" && FeeAmount == 60)
  3313. {
  3314. FluxProfit = 24;
  3315. }
  3316. else if (trade.ProductType == "7" && FeeAmount == 46)
  3317. {
  3318. FluxProfit = 10;
  3319. }
  3320. else if (trade.ProductType != "1" && FeeAmount == 48)
  3321. {
  3322. FluxProfit = 12;
  3323. }
  3324. if (FluxProfit > 0)
  3325. {
  3326. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3327. int GetUserId = user.Id;
  3328. int TopUserId = 0;
  3329. string ParentNav = user.ParentNav;
  3330. if (!string.IsNullOrEmpty(ParentNav))
  3331. {
  3332. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  3333. if (ParentNavList.Length > 1)
  3334. {
  3335. TopUserId = int.Parse(ParentNavList[1]);
  3336. }
  3337. else if (ParentNavList.Length == 1)
  3338. {
  3339. TopUserId = int.Parse(ParentNavList[0]);
  3340. }
  3341. }
  3342. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  3343. if (fluxProfit == null)
  3344. {
  3345. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  3346. {
  3347. CreateDate = DateTime.Now,
  3348. UpdateDate = DateTime.Now,
  3349. UserId = GetUserId, //创客
  3350. BrandId = pos.BrandId,
  3351. TopUserId = TopUserId, //顶级创客
  3352. TradeMonth = TradeMonth, //交易月
  3353. MerUserType = user.MerchantType, //商户创客类型
  3354. Remark = "流量卡分佣", //备注
  3355. }).Entity;
  3356. db.SaveChanges();
  3357. }
  3358. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  3359. db.FluxProfitDetail.Add(new FluxProfitDetail()
  3360. {
  3361. CreateDate = DateTime.Now,
  3362. UpdateDate = DateTime.Now,
  3363. RecordNo = OrderNo, //单号
  3364. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  3365. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  3366. TradeMonth = TradeMonth, //交易月
  3367. UserId = GetUserId, //创客
  3368. MerchantId = pos.BindMerchantId, //商户
  3369. MerchantUserId = pos.UserId, //商户直属人
  3370. MerNo = merchant.KqMerNo, //渠道商户编号
  3371. SnNo = pos.PosSn, //渠道SN号
  3372. FluxOrderNo = OrderNo, //流量扣费单号
  3373. TradeOrderNo = OrderNo, //交易流水号
  3374. TradeAmt = trade.TradeAmount, //商户交易额
  3375. FluxFeeAmt = FeeAmount, //流量费
  3376. FluxProfitAmt = FluxProfit, //流量分润总金额
  3377. PosType = pos.PosSnType.ToString(), //POS类型
  3378. Remark = "流量卡分佣", //备注
  3379. BrandId = pos.BrandId, //品牌
  3380. TopUserId = TopUserId, //顶级创客
  3381. MerUserType = user.MerchantType, //商户创客类型
  3382. });
  3383. string IdBrand = user.Id + "_" + pos.BrandId;
  3384. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  3385. if (userData == null)
  3386. {
  3387. userData = db.UserMachineData.Add(new UserMachineData()
  3388. {
  3389. IdBrand = IdBrand,
  3390. }).Entity;
  3391. db.SaveChanges();
  3392. }
  3393. userData.FluxProfit += FluxProfit;
  3394. db.SaveChanges();
  3395. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3396. if (account == null)
  3397. {
  3398. account = db.UserAccount.Add(new UserAccount()
  3399. {
  3400. Id = GetUserId,
  3401. UserId = GetUserId,
  3402. }).Entity;
  3403. db.SaveChanges();
  3404. }
  3405. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3406. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3407. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3408. account.BalanceAmount += FluxProfit;
  3409. account.TotalAmount += FluxProfit;
  3410. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3411. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3412. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3413. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  3414. {
  3415. CreateDate = DateTime.Now,
  3416. UpdateDate = DateTime.Now,
  3417. UserId = GetUserId, //创客
  3418. ChangeType = 60, //变动类型
  3419. ProductType = pos.BrandId, //产品类型
  3420. ChangeAmount = FluxProfit, //变更金额
  3421. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3422. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3423. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3424. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3425. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3426. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3427. }).Entity;
  3428. db.SaveChanges();
  3429. spdb.Dispose();
  3430. db.Dispose();
  3431. PublicFunction.SplitUserAccountRecord(add);
  3432. return "发放成功";
  3433. }
  3434. }
  3435. catch (Exception ex)
  3436. {
  3437. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3438. }
  3439. }
  3440. spdb.Dispose();
  3441. db.Dispose();
  3442. return "操作失败";
  3443. }
  3444. #endregion
  3445. #region 设置立刷费率
  3446. public IActionResult LisFee(string right)
  3447. {
  3448. ViewBag.RightInfo = RightInfo;
  3449. ViewBag.right = right;
  3450. return View();
  3451. }
  3452. [HttpPost]
  3453. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3454. {
  3455. if (string.IsNullOrEmpty(PosSns))
  3456. {
  3457. return "请输入机具号";
  3458. }
  3459. string result = SysUserName + "设置\n";
  3460. string[] PosSnList = PosSns.Replace("\r", "").Split('\n');
  3461. int total = PosSnList.Length;
  3462. int index = 0;
  3463. foreach (string SubPosSn in PosSnList)
  3464. {
  3465. index += 1;
  3466. string PosSn = SubPosSn.Replace("\r", "");
  3467. result += PosSn + ":" + Fee + "\n";
  3468. if (Kind == "M5")
  3469. {
  3470. result += SetLiSFee(PosSn, Fee) + "\n";
  3471. }
  3472. else if (Kind == "N1")
  3473. {
  3474. result += SetLiSDeposit(PosSn, (int)Fee);
  3475. }
  3476. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3477. }
  3478. result += "\n\n";
  3479. function.WriteLog(result, "设置立刷费率");
  3480. return result;
  3481. }
  3482. public string LisFeeProcess()
  3483. {
  3484. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3485. }
  3486. #region 立刷
  3487. string LiSAgentId = "50814834";
  3488. 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=";
  3489. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3490. public string LiSSign(string data)
  3491. {
  3492. var rsa = RSA.Create();
  3493. var key = Convert.FromBase64String(LiSPrivateKey);
  3494. var content = Encoding.UTF8.GetBytes(data);
  3495. rsa.ImportPkcs8PrivateKey(key, out _);
  3496. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3497. return Convert.ToBase64String(result);
  3498. }
  3499. // 设置费率
  3500. public string SetLiSFee(string sn, decimal serviceFee)
  3501. {
  3502. Dictionary<string, object> dic = new Dictionary<string, object>();
  3503. dic.Add("agentId", LiSAgentId);
  3504. dic.Add("deviceSn", sn);
  3505. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3506. Dictionary<string, object> item = new Dictionary<string, object>();
  3507. item.Add("feeCalcType", "M5");
  3508. item.Add("fixed", "0");
  3509. item.Add("rate", serviceFee);
  3510. feeList.Add(item);
  3511. dic.Add("feeList", feeList);
  3512. dic.Add("signMethod", "02");
  3513. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3514. string signstr = LiSSign(content);
  3515. dic.Add("signData", signstr);
  3516. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3517. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3518. return result;
  3519. }
  3520. // 设置押金
  3521. public string SetLiSDeposit(string sn, int serviceFee)
  3522. {
  3523. serviceFee = serviceFee * 100;
  3524. Dictionary<string, object> dic = new Dictionary<string, object>();
  3525. dic.Add("agentId", LiSAgentId);
  3526. dic.Add("deviceSn", sn);
  3527. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3528. Dictionary<string, object> item = new Dictionary<string, object>();
  3529. item.Add("feeCalcType", "N1");
  3530. item.Add("fixed", "1");
  3531. item.Add("rate", serviceFee);
  3532. feeList.Add(item);
  3533. dic.Add("feeList", feeList);
  3534. dic.Add("signMethod", "02");
  3535. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3536. string signstr = LiSSign(content);
  3537. dic.Add("signData", signstr);
  3538. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3539. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3540. return result;
  3541. }
  3542. #endregion
  3543. #endregion
  3544. #region 查询商户型创客设置信息
  3545. public IActionResult SeeMerchantType(string right)
  3546. {
  3547. ViewBag.RightInfo = RightInfo;
  3548. ViewBag.right = right;
  3549. return View();
  3550. }
  3551. [HttpPost]
  3552. public string SeeMerchantTypeDo(string PosSn)
  3553. {
  3554. if (string.IsNullOrEmpty(PosSn))
  3555. {
  3556. return "请输入机具SN或者创客编号";
  3557. }
  3558. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3559. if (PosSn.StartsWith("K"))
  3560. {
  3561. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3562. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3563. if (check)
  3564. {
  3565. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3566. }
  3567. }
  3568. else
  3569. {
  3570. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3571. if (check)
  3572. {
  3573. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3574. }
  3575. }
  3576. if (pos.Id == 0)
  3577. {
  3578. return "查无信息";
  3579. }
  3580. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3581. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3582. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3583. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3584. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3585. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3586. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3587. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3588. string result = "";
  3589. result += "机具SN:" + pos.PosSn + "\n";
  3590. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3591. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3592. result += "商户编号:" + pos.MerNo + "\n";
  3593. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3594. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3595. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3596. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3597. result += "是否循环:" + RecycFlag + "\n";
  3598. return result;
  3599. }
  3600. #endregion
  3601. #region 三要素验证
  3602. public IActionResult CheckThreeElements(string right)
  3603. {
  3604. ViewBag.RightInfo = RightInfo;
  3605. ViewBag.right = right;
  3606. return View();
  3607. }
  3608. [HttpPost]
  3609. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3610. {
  3611. var host = "https://bankcard3c.shumaidata.com";
  3612. var path = "/bankcard3c";
  3613. var method = "GET";
  3614. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3615. if (string.IsNullOrEmpty(bankcard))
  3616. {
  3617. return "结算银行卡号";
  3618. }
  3619. if (string.IsNullOrEmpty(idcard))
  3620. {
  3621. return "身份证号";
  3622. }
  3623. if (string.IsNullOrEmpty(name))
  3624. {
  3625. return "真实姓名";
  3626. }
  3627. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3628. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3629. function.WriteLog(querys, "验证三要素日志");
  3630. String bodys = "";
  3631. String url = host + path;
  3632. HttpWebRequest httpRequest = null;
  3633. HttpWebResponse httpResponse = null;
  3634. if (0 < querys.Length)
  3635. {
  3636. url = url + "?" + querys;
  3637. }
  3638. if (host.Contains("https://"))
  3639. {
  3640. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3641. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3642. }
  3643. else
  3644. {
  3645. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3646. }
  3647. httpRequest.Method = method;
  3648. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3649. if (0 < bodys.Length)
  3650. {
  3651. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3652. using (Stream stream = httpRequest.GetRequestStream())
  3653. {
  3654. stream.Write(data, 0, data.Length);
  3655. }
  3656. }
  3657. try
  3658. {
  3659. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3660. }
  3661. catch (WebException ex)
  3662. {
  3663. httpResponse = (HttpWebResponse)ex.Response;
  3664. }
  3665. Stream st = httpResponse.GetResponseStream();
  3666. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3667. string result = reader.ReadToEnd();
  3668. JsonData jsonObj = JsonMapper.ToObject(result);
  3669. result = jsonObj["data"]["desc"].ToString();
  3670. function.WriteLog(result, "验证三要素日志");
  3671. function.WriteLog("\n\n", "验证三要素日志");
  3672. return result;
  3673. }
  3674. #endregion
  3675. #region 四要素验证
  3676. public IActionResult CheckFourElements(string right)
  3677. {
  3678. ViewBag.RightInfo = RightInfo;
  3679. ViewBag.right = right;
  3680. return View();
  3681. }
  3682. [HttpPost]
  3683. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3684. {
  3685. var host = "https://bankcard4c.shumaidata.com";
  3686. var path = "/bankcard4c";
  3687. var method = "GET";
  3688. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3689. if (string.IsNullOrEmpty(bankcard))
  3690. {
  3691. return "请输入结算银行卡号";
  3692. }
  3693. if (string.IsNullOrEmpty(idcard))
  3694. {
  3695. return "请输入身份证号";
  3696. }
  3697. if (string.IsNullOrEmpty(mobile))
  3698. {
  3699. return "请输入银行预留手机号";
  3700. }
  3701. if (string.IsNullOrEmpty(name))
  3702. {
  3703. return "请输入真实姓名";
  3704. }
  3705. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3706. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3707. function.WriteLog(querys, "验证四要素日志");
  3708. String bodys = "";
  3709. String url = host + path;
  3710. HttpWebRequest httpRequest = null;
  3711. HttpWebResponse httpResponse = null;
  3712. if (0 < querys.Length)
  3713. {
  3714. url = url + "?" + querys;
  3715. }
  3716. if (host.Contains("https://"))
  3717. {
  3718. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3719. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3720. }
  3721. else
  3722. {
  3723. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3724. }
  3725. httpRequest.Method = method;
  3726. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3727. if (0 < bodys.Length)
  3728. {
  3729. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3730. using (Stream stream = httpRequest.GetRequestStream())
  3731. {
  3732. stream.Write(data, 0, data.Length);
  3733. }
  3734. }
  3735. try
  3736. {
  3737. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3738. }
  3739. catch (WebException ex)
  3740. {
  3741. httpResponse = (HttpWebResponse)ex.Response;
  3742. }
  3743. Stream st = httpResponse.GetResponseStream();
  3744. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3745. string result = reader.ReadToEnd();
  3746. JsonData jsonObj = JsonMapper.ToObject(result);
  3747. result = jsonObj["data"]["desc"].ToString();
  3748. function.WriteLog(result, "验证四要素日志");
  3749. function.WriteLog("\n\n", "验证四要素日志");
  3750. return result;
  3751. }
  3752. #endregion
  3753. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3754. {
  3755. return true;
  3756. }
  3757. #region 根据机具号同步商户激活状态
  3758. public IActionResult SyncMerchantStatus(string right)
  3759. {
  3760. ViewBag.RightInfo = RightInfo;
  3761. ViewBag.right = right;
  3762. return View();
  3763. }
  3764. [HttpPost]
  3765. public string SyncMerchantStatusDo(string PosSn)
  3766. {
  3767. if (string.IsNullOrEmpty(PosSn))
  3768. {
  3769. return "请输入机具号";
  3770. }
  3771. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3772. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3773. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3774. if (posInfo.Id == 0)
  3775. {
  3776. return "机具" + PosSn + "不存在";
  3777. }
  3778. if (posMerchant.Id == 0)
  3779. {
  3780. return "机具绑定商户不存在";
  3781. }
  3782. else
  3783. {
  3784. posMerchant.ActiveStatus = 1;
  3785. posMerchant.UpdateDate = DateTime.Now;
  3786. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3787. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3788. db.SaveChanges();
  3789. }
  3790. return "success";
  3791. }
  3792. #endregion
  3793. #region 根据机具号补发开机奖励
  3794. public IActionResult PosRewardReissued(string right)
  3795. {
  3796. ViewBag.RightInfo = RightInfo;
  3797. ViewBag.right = right;
  3798. return View();
  3799. }
  3800. [HttpPost]
  3801. public string PosRewardReissuedDo(string PosSn)
  3802. {
  3803. if (string.IsNullOrEmpty(PosSn))
  3804. {
  3805. return "请输入机具SN";
  3806. }
  3807. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3808. var PosId = "";
  3809. var error = "";
  3810. foreach (var item in PosSnList)
  3811. {
  3812. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3813. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3814. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3815. if (checkExist)
  3816. {
  3817. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3818. }
  3819. else
  3820. {
  3821. if (posInfo.Id > 0)
  3822. {
  3823. RedisDbconn.Instance.AddList("OpenRewardQueue", posInfo.Id.ToString());
  3824. }
  3825. }
  3826. }
  3827. if (!string.IsNullOrEmpty(error))
  3828. {
  3829. return "Warning|" + error;
  3830. }
  3831. PosId = PosId.TrimEnd(',');
  3832. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3833. return "success";
  3834. }
  3835. #endregion
  3836. #region 根据机具号设置费率
  3837. public IActionResult SetPosFee(string right)
  3838. {
  3839. ViewBag.RightInfo = RightInfo;
  3840. ViewBag.right = right;
  3841. return View();
  3842. }
  3843. [HttpPost]
  3844. public string SetPosFeeDo(string PosSn, string FeeType)
  3845. {
  3846. if (string.IsNullOrEmpty(PosSn))
  3847. {
  3848. return "请输入机具SN";
  3849. }
  3850. if (string.IsNullOrEmpty(FeeType))
  3851. {
  3852. return "请输入选择费率";
  3853. }
  3854. if (FeeType == "0")
  3855. {
  3856. FeeType = "0.6";
  3857. }
  3858. if (FeeType == "1")
  3859. {
  3860. FeeType = "0.63";
  3861. }
  3862. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3863. var PosId = "";
  3864. var RecordId = "";
  3865. var error = "";
  3866. foreach (var item in PosSnList)
  3867. {
  3868. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3869. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3870. if (posInfo.Id > 0)
  3871. {
  3872. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3873. {
  3874. Sort = posInfo.BrandId,
  3875. CreateDate = DateTime.Now,
  3876. PosId = posInfo.Id,
  3877. PosSn = posInfo.PosSn,
  3878. PosUserId = posInfo.UserId,
  3879. MerchantId = posInfo.BindMerchantId,
  3880. UserId = posInfo.UserId,
  3881. ChangeFee = decimal.Parse(FeeType),
  3882. }).Entity;
  3883. db.SaveChanges();
  3884. PosId += posInfo.Id + ",";
  3885. RecordId += query.Id + ",";
  3886. }
  3887. else
  3888. {
  3889. error += "机具" + PosSn + "不存在";
  3890. }
  3891. }
  3892. if (!string.IsNullOrEmpty(error))
  3893. {
  3894. return "Warning|" + error;
  3895. }
  3896. PosId = PosId.TrimEnd(',');
  3897. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3898. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3899. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3900. return "success";
  3901. }
  3902. #endregion
  3903. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3904. public IActionResult RelationPosAndMerchant(string right)
  3905. {
  3906. ViewBag.RightInfo = RightInfo;
  3907. ViewBag.right = right;
  3908. return View();
  3909. }
  3910. [HttpPost]
  3911. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3912. {
  3913. if (string.IsNullOrEmpty(PosSn))
  3914. {
  3915. return "请输入机具SN";
  3916. }
  3917. if (string.IsNullOrEmpty(MerchantNo))
  3918. {
  3919. return "请输入商户编号";
  3920. }
  3921. if (string.IsNullOrEmpty(MerchantName))
  3922. {
  3923. return "请输入商户姓名";
  3924. }
  3925. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3926. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3927. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3928. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3929. if (posMerchant.Id == 0)
  3930. {
  3931. return "商户" + MerchantNo + "不存在";
  3932. }
  3933. else if (pos.Id == 0)
  3934. {
  3935. return "机具" + PosSn + "不存在";
  3936. }
  3937. else
  3938. {
  3939. pos.BindMerchantId = posMerchant.Id;
  3940. db.SaveChanges();
  3941. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3942. }
  3943. return "success";
  3944. }
  3945. #endregion
  3946. #region 设置商户信息
  3947. public IActionResult SetMerchantInfo(string right)
  3948. {
  3949. ViewBag.RightInfo = RightInfo;
  3950. ViewBag.right = right;
  3951. return View();
  3952. }
  3953. [HttpPost]
  3954. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3955. {
  3956. if (string.IsNullOrEmpty(PosSn))
  3957. {
  3958. return "请输入机具SN";
  3959. }
  3960. if (string.IsNullOrEmpty(MerchantNo))
  3961. {
  3962. return "请输入商户编号";
  3963. }
  3964. if (string.IsNullOrEmpty(MerchantName))
  3965. {
  3966. return "请输入商户姓名";
  3967. }
  3968. if (string.IsNullOrEmpty(MerIdcardNo))
  3969. {
  3970. return "请输入商户身份证号";
  3971. }
  3972. if (string.IsNullOrEmpty(MerchantMobile))
  3973. {
  3974. return "请输入商户手机号";
  3975. }
  3976. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && (m.MerchantName.StartsWith(MerchantName.Substring(0, 1)) || m.MerchantName.Contains(MerchantName))) ?? new PosMerchantInfo();
  3977. var query = "";
  3978. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3979. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3980. if (posMerchant.Id == 0)
  3981. {
  3982. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3983. }
  3984. else
  3985. {
  3986. posMerchant.MerIdcardNo = MerIdcardNo;
  3987. posMerchant.MerchantName = MerchantName;
  3988. posMerchant.MerRealName = MerchantName;
  3989. posMerchant.MerchantMobile = MerchantMobile;
  3990. db.SaveChanges();
  3991. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3992. }
  3993. return "success";
  3994. }
  3995. #endregion
  3996. #region 认证创客
  3997. public IActionResult AuthMaker(string right)
  3998. {
  3999. ViewBag.RightInfo = RightInfo;
  4000. ViewBag.right = right;
  4001. return View();
  4002. }
  4003. [HttpPost]
  4004. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  4005. {
  4006. if (string.IsNullOrEmpty(MakerCode))
  4007. {
  4008. return "请输入创客编号";
  4009. }
  4010. if (string.IsNullOrEmpty(RealName))
  4011. {
  4012. return "请输入真实姓名";
  4013. }
  4014. if (string.IsNullOrEmpty(CertId))
  4015. {
  4016. return "请输入身份证号";
  4017. }
  4018. if (string.IsNullOrEmpty(BackCard))
  4019. {
  4020. return "请输入银行卡号";
  4021. }
  4022. if (string.IsNullOrEmpty(BackName))
  4023. {
  4024. return "请输入银行名称";
  4025. }
  4026. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  4027. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  4028. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  4029. if (userInfo.AuthFlag == 1)
  4030. {
  4031. return "已认证";
  4032. }
  4033. else
  4034. {
  4035. userInfo.UpdateDate = DateTime.Now;
  4036. userInfo.RealName = RealName;
  4037. userInfo.AuthFlag = 1;
  4038. if (userInfo.AuthDate == null)
  4039. {
  4040. userInfo.AuthDate = DateTime.Now;
  4041. }
  4042. userInfo.CertId = CertId;
  4043. userInfo.SettleBankCardNo = BackCard;
  4044. userInfo.SettleBankName = BackName;
  4045. db.SaveChanges();
  4046. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  4047. }
  4048. return "success";
  4049. }
  4050. #endregion
  4051. #region 划拨创客机具
  4052. public IActionResult TransferPos(string right)
  4053. {
  4054. ViewBag.RightInfo = RightInfo;
  4055. ViewBag.right = right;
  4056. return View();
  4057. }
  4058. [HttpPost]
  4059. // public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  4060. // {
  4061. // if (string.IsNullOrEmpty(PosSn))
  4062. // {
  4063. // return "请输入机具SN";
  4064. // }
  4065. // if (string.IsNullOrEmpty(FromMakerCode))
  4066. // {
  4067. // return "请输入机具来源创客编号";
  4068. // }
  4069. // if (string.IsNullOrEmpty(ToMakerCode))
  4070. // {
  4071. // return "请输入划拨对象创客编号";
  4072. // }
  4073. // var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  4074. // var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4075. // var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4076. // if (posInfo.Id == 0)
  4077. // {
  4078. // return "机具" + PosSn + "不存在";
  4079. // }
  4080. // var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4081. // var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4082. // var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4083. // if (fUserId.Id == 0)
  4084. // {
  4085. // return "来源创客" + FromMakerCode + "不存在";
  4086. // }
  4087. // var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4088. // if (tUserId.Id == 0)
  4089. // {
  4090. // return "划拨创客" + ToMakerCode + "不存在";
  4091. // }
  4092. // if (posInfo.BindingState == 0)
  4093. // {
  4094. // if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  4095. // {
  4096. // posInfo.BuyUserId = tUserId.Id;
  4097. // posInfo.UserId = tUserId.Id;
  4098. // }
  4099. // else
  4100. // {
  4101. // posInfo.BuyUserId = tUserId.Id;
  4102. // }
  4103. // var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4104. // var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4105. // fUserPos.TotalMachineCount -= 1;
  4106. // fUserPos.UnBindCount -= 1;
  4107. // tUserPos.TotalMachineCount += 1;
  4108. // tUserPos.UnBindCount += 1;
  4109. // db.SaveChanges();
  4110. // function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  4111. // }
  4112. // else
  4113. // {
  4114. // return "机具" + PosSn + "已使用";
  4115. // }
  4116. // return "success";
  4117. // }
  4118. // #endregion
  4119. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  4120. {
  4121. if (string.IsNullOrEmpty(PosSn))
  4122. {
  4123. return "请输入机具SN";
  4124. }
  4125. if (string.IsNullOrEmpty(FromMakerCode))
  4126. {
  4127. return "请输入机具来源创客编号";
  4128. }
  4129. if (string.IsNullOrEmpty(ToMakerCode))
  4130. {
  4131. return "请输入划拨对象创客编号";
  4132. }
  4133. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4134. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4135. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4136. if (fUserId.Id == 0)
  4137. {
  4138. return "来源创客" + FromMakerCode + "不存在";
  4139. }
  4140. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4141. if (tUserId.Id == 0)
  4142. {
  4143. return "划拨创客" + ToMakerCode + "不存在";
  4144. }
  4145. List<int> SnIds = new List<int>();
  4146. string[] PosSnList = PosSn.Replace("\r", "").Replace("\n", ",").Split(',');
  4147. string error = "";
  4148. foreach (string Sn in PosSnList)
  4149. {
  4150. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.BindingState == 0 && m.ActivationState == 0 && m.PosSn == Sn && (m.BuyUserId == fUserId.Id || m.UserId == fUserId.Id)) ?? new PosMachinesTwo();
  4151. if (posInfo.Id == 0)
  4152. {
  4153. error += "以下操作失败" + Sn + ',' + "不存在或者不符合条件" + '\n';
  4154. }
  4155. else
  4156. {
  4157. SnIds.Add(posInfo.Id);
  4158. }
  4159. }
  4160. if (!string.IsNullOrEmpty(error))
  4161. {
  4162. return "Warning|" + error;
  4163. }
  4164. else
  4165. {
  4166. var ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  4167. foreach (int SnId in SnIds)
  4168. {
  4169. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
  4170. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  4171. {
  4172. posInfo.BuyUserId = tUserId.Id;
  4173. posInfo.UserId = tUserId.Id;
  4174. }
  4175. else
  4176. {
  4177. posInfo.BuyUserId = tUserId.Id;
  4178. }
  4179. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4180. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4181. fUserPos.TotalMachineCount -= 1;
  4182. fUserPos.UnBindCount -= 1;
  4183. tUserPos.TotalMachineCount += 1;
  4184. tUserPos.UnBindCount += 1;
  4185. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4186. {
  4187. CreateDate = DateTime.Now,
  4188. UserId = fUserId.Id, //创客
  4189. BrandId = posInfo.BrandId,//产品类型
  4190. // ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  4191. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4192. TransType = 1, //交易类型
  4193. SnNo = posInfo.PosSn, //SN编号
  4194. SnType = posInfo.PosSnType, //SN机具类型
  4195. StockOpDirect = 1, //库存操作方向
  4196. DeviceVendor = posInfo.DeviceName, //设备厂商
  4197. DeviceModel = posInfo.DeviceKind, //设备型号
  4198. DeviceType = posInfo.DeviceType, //设备类型
  4199. FromUserId = fUserId.Id, //出货创客
  4200. FromDate = DateTime.Now, //出库时间
  4201. FromRemark = "划拨创客机具", //出库备注
  4202. SourceStoreId = posInfo.SourceStoreId, //源仓库
  4203. ToUserId = tUserId.Id,//收货创客
  4204. });
  4205. UserStoreChange userstore = db.UserStoreChange.Add(new UserStoreChange()
  4206. {
  4207. CreateDate = DateTime.Now,
  4208. UserId = fUserId.Id, //创客
  4209. BrandId = posInfo.BrandId, //产品类型
  4210. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4211. TransType = 0, //交易类型
  4212. SnNo = posInfo.PosSn, //SN编号
  4213. SnType = posInfo.PosSnType, //SN机具类型
  4214. StockOpDirect = 0, //库存操作方向
  4215. DeviceVendor = posInfo.DeviceName, //设备厂商
  4216. DeviceType = posInfo.DeviceKind, //设备类型
  4217. DeviceModel = posInfo.DeviceType, //设备型号
  4218. ToUserId = tUserId.Id, //收货创客
  4219. ToDate = DateTime.Now, //入库时间
  4220. SourceStoreId = posInfo.SourceStoreId, //源仓库
  4221. SnStatus = 1, //SN状态
  4222. BindStatus = (int)posInfo.BindingState, //绑定状态
  4223. BindMerchantId = posInfo.BindMerchantId, //绑定商户
  4224. ActiveStatus = (int)posInfo.ActivationState, //激活状态
  4225. ActRewardUserId = posInfo.BuyUserId, //激活奖励创客
  4226. BrandType = posInfo.DeviceType, //品牌类型
  4227. }).Entity;
  4228. }
  4229. var query = SnIds + ";" + FromMakerCode + ";" + ToMakerCode;
  4230. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  4231. db.SaveChanges();
  4232. db.Dispose();
  4233. }
  4234. return "success";
  4235. }
  4236. #endregion
  4237. #region 还原提现订单状态
  4238. public IActionResult RestoreStatus(string right)
  4239. {
  4240. ViewBag.RightInfo = RightInfo;
  4241. ViewBag.right = right;
  4242. return View();
  4243. }
  4244. [HttpPost]
  4245. public string RestoreStatusDo(string OrderNo)
  4246. {
  4247. if (string.IsNullOrEmpty(OrderNo))
  4248. {
  4249. return "请输入提现订单编号";
  4250. }
  4251. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  4252. var error = "";
  4253. foreach (var item in OrderNoList)
  4254. {
  4255. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  4256. if (cash.Id > 0)
  4257. {
  4258. cash.QueryCount = 0;
  4259. cash.Status = 0;
  4260. db.SaveChanges();
  4261. }
  4262. else
  4263. {
  4264. error += "订单" + item + "不存在" + '\n';
  4265. }
  4266. }
  4267. if (!string.IsNullOrEmpty(error))
  4268. {
  4269. return "Warning|" + error;
  4270. }
  4271. return "success";
  4272. }
  4273. #endregion
  4274. #region 查询创客循环资格
  4275. public IActionResult SeeUserLoop(string right)
  4276. {
  4277. ViewBag.RightInfo = RightInfo;
  4278. ViewBag.right = right;
  4279. return View();
  4280. }
  4281. [HttpPost]
  4282. public string SeeUserLoopDo(string MakerCode)
  4283. {
  4284. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  4285. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  4286. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  4287. var brandList = db.KqProducts.ToList();
  4288. var info = "";
  4289. foreach (var item in brandList)
  4290. {
  4291. var brand = item.Name;
  4292. //已过期
  4293. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4294. //可申请
  4295. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4296. //已使用
  4297. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  4298. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  4299. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  4300. }
  4301. return info;
  4302. }
  4303. #endregion
  4304. #region 提交到代付排除的创客名单
  4305. public IActionResult CashWithoutUser(string right)
  4306. {
  4307. ViewBag.RightInfo = RightInfo;
  4308. ViewBag.right = right;
  4309. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser") ?? new CustomTagSet();
  4310. ViewBag.set = set;
  4311. return View();
  4312. }
  4313. public string CashWithoutUserDo(string Content)
  4314. {
  4315. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  4316. if (set == null)
  4317. {
  4318. set = db.CustomTagSet.Add(new CustomTagSet()
  4319. {
  4320. Tags = "CashWithoutUser",
  4321. Title = "提交到代付排除的创客名单"
  4322. }).Entity;
  4323. db.SaveChanges();
  4324. }
  4325. set.Contents = Content;
  4326. db.SaveChanges();
  4327. db.Dispose();
  4328. return "success";
  4329. }
  4330. #endregion
  4331. #region 坏机回仓
  4332. public IActionResult BadPosToStore(string right)
  4333. {
  4334. ViewBag.RightInfo = RightInfo;
  4335. ViewBag.right = right;
  4336. return View();
  4337. }
  4338. [HttpPost]
  4339. public string BadPosToStoreDo(string OldSn)
  4340. {
  4341. string[] OldSnList;
  4342. OldSnList = OldSn.Replace("\r", "").Split('\n');
  4343. string error = "";
  4344. List<string> opData = new List<string>();
  4345. for (int i = 0; i < OldSnList.Length; i++)
  4346. {
  4347. string OldSnNum = OldSnList[i];
  4348. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  4349. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  4350. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  4351. {
  4352. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  4353. }
  4354. oldpos.Status = 1;
  4355. oldpos.PosSnType = 0;
  4356. oldpos.QueryCount = 0;
  4357. oldpos.UpdateDate = null;
  4358. oldpos.ActivityList = null;
  4359. oldpos.SeoKeyword = null;
  4360. oldpos.SeoDescription = null;
  4361. oldpos.OrderId = 0;
  4362. oldpos.RecycEndDate = null;
  4363. oldpos.RecycBackCount = 0;
  4364. oldpos.PrizeParams = null;
  4365. oldpos.ScanQrTrade = 0;
  4366. oldpos.BindMerchantId = 0;
  4367. oldpos.CreditTrade = 0;
  4368. oldpos.DebitCardTrade = 0;
  4369. oldpos.IsVip = 0;
  4370. oldpos.UserNav = null;
  4371. oldpos.TransferTime = null;
  4372. oldpos.IsPurchase = 0;
  4373. oldpos.Detail = null;
  4374. oldpos.BindingTime = null;
  4375. oldpos.BindingState = 0;
  4376. oldpos.ActivationTime = null;
  4377. oldpos.ActivationState = 0;
  4378. oldpos.LeaderUserId = 0;
  4379. oldpos.PreUserId = 0;
  4380. oldpos.IsFirst = 0;
  4381. oldpos.DownFeeMan = null;
  4382. oldpos.DownFeeFlag = 0;
  4383. oldpos.DownFeeDate = null;
  4384. oldpos.UpFeeMan = null;
  4385. oldpos.UpFeeFlag = 0;
  4386. oldpos.UpFeeDate = null;
  4387. oldpos.OpReserve1 = 0;
  4388. oldpos.OpReserve2 = 0;
  4389. oldpos.OpReserve3 = 0;
  4390. oldpos.OpId = 0;
  4391. oldpos.RecycStartDate = null;
  4392. oldpos.SourcePosSn = null;
  4393. oldpos.BuyUserId = 0;
  4394. oldpos.UserId = 0;
  4395. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  4396. }
  4397. if (!string.IsNullOrEmpty(error))
  4398. {
  4399. return "Warning|" + error;
  4400. }
  4401. db.SaveChanges();
  4402. foreach (string sub in opData)
  4403. {
  4404. string[] datalist = sub.Split(":");
  4405. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4406. }
  4407. return "success";
  4408. }
  4409. #endregion
  4410. #region 划拨创客机具券
  4411. public IActionResult TransferPosCoupon(string right)
  4412. {
  4413. ViewBag.RightInfo = RightInfo;
  4414. ViewBag.right = right;
  4415. return View();
  4416. }
  4417. public string TransferPosCouponDo(string Kind, string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  4418. {
  4419. if (string.IsNullOrEmpty(Kind))
  4420. {
  4421. return "请选择划拨的券类型";
  4422. }
  4423. if (string.IsNullOrEmpty(PosCouponCodes))
  4424. {
  4425. return "请输入机具券码";
  4426. }
  4427. if (string.IsNullOrEmpty(FromMakerCode))
  4428. {
  4429. return "请输入机具来源创客编号";
  4430. }
  4431. if (string.IsNullOrEmpty(ToMakerCode))
  4432. {
  4433. return "请输入划拨对象创客编号";
  4434. }
  4435. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4436. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4437. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4438. if (fUserId.Id == 0)
  4439. {
  4440. return "来源创客" + FromMakerCode + "不存在";
  4441. }
  4442. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4443. if (tUserId.Id == 0)
  4444. {
  4445. return "划拨创客" + ToMakerCode + "不存在";
  4446. }
  4447. int LeaderUserId = 0;
  4448. if (!string.IsNullOrEmpty(LeaderMakerCode))
  4449. {
  4450. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  4451. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  4452. if (LeaderUserItem.Id == 0)
  4453. {
  4454. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  4455. }
  4456. LeaderUserId = leaderuser.UserId;
  4457. }
  4458. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  4459. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  4460. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  4461. foreach (string PosCouponCode in PosCouponList)
  4462. {
  4463. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  4464. if (item.UserId != fUserId.Id)
  4465. {
  4466. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  4467. }
  4468. if (item.Id == 0)
  4469. {
  4470. return "机具券" + PosCouponCode + "不存在";
  4471. }
  4472. if (item.IsUse == 1)
  4473. {
  4474. return "机具券" + PosCouponCode + "已使用";
  4475. }
  4476. if (item.QueryCount != int.Parse(Kind))
  4477. {
  4478. return "机具券" + PosCouponCode + "类型和您选择的类型不同";
  4479. }
  4480. item.UserId = tUserId.Id;
  4481. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  4482. {
  4483. item.LeaderUserId = LeaderUserId;
  4484. }
  4485. PosCouponRecord posCouponRecord = db.PosCouponRecord.Add(new PosCouponRecord()
  4486. {
  4487. QueryCount = item.QueryCount,//券类型(1 电签 2 大POS)
  4488. CreateDate = DateTime.Now,
  4489. ChangeKind = 1,//类型(0购买,1划拨,2使⽤,3申请机具循环驳回)
  4490. OrderNo = ChangeRecordNo,
  4491. ToUserId = tUserId.Id,
  4492. FromUserId = fUserId.Id,
  4493. PosCouponId = item.Id,
  4494. }).Entity;
  4495. }
  4496. int CouponCount = PosCouponList.Length;
  4497. PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
  4498. {
  4499. QueryCount = int.Parse(Kind),
  4500. CreateDate = DateTime.Now,
  4501. ChangeKind = 2,
  4502. ChangeCount = CouponCount,
  4503. // AfterOut = AfterOut,
  4504. // AfterTotal = AfterTotal,
  4505. // AfterStock = AfterStock,
  4506. // BeforeOut = BeforeOut,
  4507. // BeforeTotal = BeforeTotal,
  4508. // BeforeStock = BeforeStock,
  4509. OrderNo = ChangeRecordNo,
  4510. ToUserId = tUserId.Id,
  4511. FromUserId = fUserId.Id,
  4512. }).Entity;
  4513. PosCouponOrders tostat = db.PosCouponOrders.Add(new PosCouponOrders()
  4514. {
  4515. QueryCount = int.Parse(Kind),
  4516. CreateDate = DateTime.Now,
  4517. ChangeKind = 1,
  4518. ChangeCount = CouponCount,
  4519. // AfterOut = AfterOut,
  4520. // AfterTotal = AfterTotal,
  4521. // AfterStock = AfterStock,
  4522. // BeforeOut = BeforeOut,
  4523. // BeforeTotal = BeforeTotal,
  4524. // BeforeStock = BeforeStock,
  4525. OrderNo = ChangeRecordNo,
  4526. ToUserId = fUserId.Id,
  4527. FromUserId = tUserId.Id,
  4528. }).Entity;
  4529. db.SaveChanges();
  4530. db.Dispose();
  4531. return "success";
  4532. }
  4533. #endregion
  4534. #region 机具回仓退款
  4535. public IActionResult RefundPosFee(string right)
  4536. {
  4537. ViewBag.RightInfo = RightInfo;
  4538. ViewBag.right = right;
  4539. return View();
  4540. }
  4541. [HttpPost]
  4542. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  4543. {
  4544. if (string.IsNullOrEmpty(PosSn))
  4545. {
  4546. return "请输入机具SN";
  4547. }
  4548. if (IsBack == 1)
  4549. {
  4550. if (string.IsNullOrEmpty(BackStoreNo))
  4551. {
  4552. return "请输入仓库编号";
  4553. }
  4554. }
  4555. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  4556. WebCMSEntities db = new WebCMSEntities();
  4557. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  4558. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  4559. StoreForCode storeForBack = new StoreForCode();
  4560. StoreHouse BackStore = new StoreHouse();
  4561. List<string> opData = new List<string>();
  4562. foreach (var item in PosSnList)
  4563. {
  4564. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  4565. if (machineForSnNo.SnId == 0)
  4566. {
  4567. return "未找到机具" + item + "关联数据";
  4568. }
  4569. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4570. if (pos.Id == 0)
  4571. {
  4572. return "机具" + item + "不存在或者不满足条件";
  4573. }
  4574. if (IsBack == 1)
  4575. {
  4576. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4577. if (storeForBack.StoreId == 0)
  4578. {
  4579. return "未找到" + BackStoreNo + "关联数据";
  4580. }
  4581. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4582. if (BackStore.Id == 0)
  4583. {
  4584. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4585. }
  4586. }
  4587. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4588. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4589. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4590. var amount = 0;
  4591. if (brandInfo.Name.Contains("电签"))
  4592. {
  4593. amount = 200;
  4594. }
  4595. if (brandInfo.Name.Contains("大POS"))
  4596. {
  4597. amount = 300;
  4598. }
  4599. if (IsBack == 1)
  4600. {
  4601. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4602. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4603. {
  4604. CreateDate = DateTime.Now,
  4605. CreateMan = SysUserName,
  4606. StoreId = pos.StoreId, //出货仓库
  4607. BrandId = pos.BrandId, //产品类型
  4608. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4609. TransType = 5, //交易类型
  4610. SnNo = item, //SN编号
  4611. StockOpDirect = 0, //库存操作方向
  4612. SnStatus = 1, //SN状态
  4613. DeviceVendor = pos.DeviceName, //设备厂商
  4614. DeviceModel = pos.DeviceKind, //设备型号
  4615. DeviceType = pos.DeviceType, //设备类型
  4616. FromUserId = pos.BuyUserId, //来源创客
  4617. ToRemark = "过期机具回仓退款", //入库备注
  4618. ToStoreId = BackStore.Id, //退货收货仓库
  4619. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4620. BrandType = pos.DeviceType, //品牌类型
  4621. }).Entity;
  4622. string ChangeNo = "HCTK";
  4623. int StoreStockChangeId = stockchange.Id;
  4624. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4625. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4626. {
  4627. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4628. }
  4629. ChangeNo += StoreStockChangeIdString;
  4630. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4631. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4632. {
  4633. CreateDate = DateTime.Now,
  4634. BrandId = pos.BrandId, //产品类型
  4635. ChangeRecordNo = ChangeNo, //变更记录单号
  4636. TransType = 5, //交易类型
  4637. SnNo = item, //SN编号
  4638. SnType = pos.PosSnType, //SN机具类型
  4639. StockOpDirect = 0, //库存操作方向
  4640. DeviceVendor = pos.DeviceName, //设备厂商
  4641. DeviceModel = pos.DeviceKind, //设备型号
  4642. DeviceType = pos.DeviceType, //设备类型
  4643. FromUserId = pos.BuyUserId, //来源创客
  4644. ToRemark = "过期机具回仓退款", //入库备注
  4645. SourceStoreId = pos.SourceStoreId, //源仓库
  4646. StoreId = pos.StoreId, //出货仓库
  4647. });
  4648. db.MachineReturn.Add(new MachineReturn()
  4649. {
  4650. CreateDate = DateTime.Now,
  4651. Operator = SysUserName + "_" + SysRealName,//操作人
  4652. BrandId = pos.BrandId, //产品类型
  4653. DeviceSnNos = pos.PosSn,
  4654. ToStoreId = BackStore.Id,
  4655. ApplyNo = ChangeNo, //变更记录单号
  4656. UserId = pos.BuyUserId, //来源创客
  4657. Remark = "过期机具回仓退款", //入库备注
  4658. });
  4659. if (pos.ScanQrTrade > 0)
  4660. {
  4661. decimal ChangeAmount = 0;
  4662. decimal BeforeBalanceAmount = 0;
  4663. decimal AfterBalanceAmount = 0;
  4664. if (pos.ScanQrTrade == 999)
  4665. {
  4666. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4667. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4668. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4669. ChangeAmount = amount;
  4670. }
  4671. else
  4672. {
  4673. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4674. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4675. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4676. ChangeAmount = pos.ScanQrTrade;
  4677. }
  4678. db.UserAccountRecord.Add(new UserAccountRecord()
  4679. {
  4680. CreateDate = DateTime.Now,
  4681. UpdateDate = DateTime.Now,
  4682. UserId = pos.BuyUserId, //创客
  4683. ChangeType = 126, //变动类型(机具货款退还)
  4684. ProductType = 0, //产品类型
  4685. ChangeAmount = ChangeAmount, //变更金额
  4686. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4687. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4688. });
  4689. }
  4690. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4691. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4692. userMachineData.TotalMachineCount += 1;
  4693. userMachineData.UnBindCount += 1;
  4694. BackStore.LaveNum += 1;
  4695. BackStore.TotalNum += 1;
  4696. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4697. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4698. userMachineDatas.TotalMachineCount -= 1;
  4699. userMachineDatas.UnBindCount -= 1;
  4700. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  4701. {
  4702. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  4703. }
  4704. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4705. pos.Status = 1;
  4706. pos.QueryCount = 0;
  4707. pos.UpdateDate = null;
  4708. pos.ActivityList = null;
  4709. pos.SeoKeyword = null;
  4710. pos.SeoDescription = null;
  4711. pos.OrderId = 0;
  4712. pos.RecycEndDate = null;
  4713. pos.RecycBackCount = 0;
  4714. pos.PrizeParams = null;
  4715. pos.ScanQrTrade = 0;
  4716. pos.BindMerchantId = 0;
  4717. pos.CreditTrade = 0;
  4718. pos.DebitCardTrade = 0;
  4719. pos.IsVip = 0;
  4720. pos.UserNav = null;
  4721. pos.TransferTime = null;
  4722. pos.IsPurchase = 0;
  4723. pos.Detail = null;
  4724. pos.BindingTime = null;
  4725. pos.BindingState = 0;
  4726. pos.ActivationTime = null;
  4727. pos.ActivationState = 0;
  4728. pos.LeaderUserId = 0;
  4729. pos.PreUserId = 0;
  4730. pos.IsFirst = 0;
  4731. pos.DownFeeMan = null;
  4732. pos.DownFeeFlag = 0;
  4733. pos.DownFeeDate = null;
  4734. pos.UpFeeMan = null;
  4735. pos.UpFeeFlag = 0;
  4736. pos.UpFeeDate = null;
  4737. pos.OpReserve1 = 0;
  4738. pos.OpReserve2 = 0;
  4739. pos.OpReserve3 = 0;
  4740. pos.OpId = 0;
  4741. pos.RecycStartDate = null;
  4742. pos.SourcePosSn = null;
  4743. pos.BuyUserId = 0;
  4744. pos.UserId = 0;
  4745. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4746. }
  4747. else
  4748. {
  4749. if (pos.ScanQrTrade > 0)
  4750. {
  4751. decimal ChangeAmount = 0;
  4752. decimal BeforeBalanceAmount = 0;
  4753. decimal AfterBalanceAmount = 0;
  4754. if (pos.ScanQrTrade == 999)
  4755. {
  4756. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4757. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4758. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4759. ChangeAmount = amount;
  4760. }
  4761. else
  4762. {
  4763. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4764. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4765. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4766. ChangeAmount = pos.ScanQrTrade;
  4767. }
  4768. pos.ScanQrTrade = 0;
  4769. db.UserAccountRecord.Add(new UserAccountRecord()
  4770. {
  4771. CreateDate = DateTime.Now,
  4772. UpdateDate = DateTime.Now,
  4773. UserId = pos.BuyUserId, //创客
  4774. ChangeType = 126, //变动类型(机具货款退还)
  4775. ProductType = 0, //产品类型
  4776. ChangeAmount = ChangeAmount, //变更金额
  4777. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4778. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4779. });
  4780. }
  4781. }
  4782. }
  4783. db.SaveChanges();
  4784. foreach (string sub in opData)
  4785. {
  4786. string[] datalist = sub.Split(":");
  4787. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4788. }
  4789. return "success";
  4790. }
  4791. #endregion
  4792. #region 添加商户信息
  4793. public IActionResult AddMerchantnfo(string right)
  4794. {
  4795. ViewBag.RightInfo = RightInfo;
  4796. ViewBag.right = right;
  4797. return View();
  4798. }
  4799. [HttpPost]
  4800. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4801. {
  4802. if (string.IsNullOrEmpty(PosSn))
  4803. {
  4804. return "请输入机具号";
  4805. }
  4806. if (string.IsNullOrEmpty(MerSn))
  4807. {
  4808. return "请输入商户号";
  4809. }
  4810. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4811. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4812. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4813. if (machineForSnNo.SnId == 0)
  4814. {
  4815. return "未找到机具" + PosSn + "关联数据";
  4816. }
  4817. if (pos.Id == 0)
  4818. {
  4819. return "未找到机具" + PosSn;
  4820. }
  4821. if (merchantInfo.Id > 0)
  4822. {
  4823. return "机具" + PosSn + "以经存在绑定商户";
  4824. }
  4825. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4826. if (spInfo.Id > 0)
  4827. {
  4828. var MerUserType = 0;
  4829. var ActiveStatus = 0;
  4830. if (pos.BuyUserId != pos.UserId)
  4831. {
  4832. MerUserType = 1;
  4833. }
  4834. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4835. {
  4836. ActiveStatus = 1;
  4837. }
  4838. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4839. {
  4840. CreateDate = pos.BindingTime,
  4841. TopUserId = 1,
  4842. BrandId = pos.BrandId,
  4843. SnStoreId = pos.StoreId,
  4844. MerStandardDate = pos.ActivationTime,
  4845. SnType = pos.PosSnType,
  4846. MerUserType = MerUserType,
  4847. UserId = pos.UserId,
  4848. ActiveStatus = ActiveStatus,
  4849. MerStatus = 1,
  4850. KqSnNo = PosSn,
  4851. KqMerNo = MerSn,
  4852. MerIdcardNo = spInfo.SeoKeyword,
  4853. MerchantMobile = spInfo.MerNewSnNo,
  4854. MerchantName = spInfo.MerName,
  4855. MerchantNo = spInfo.MerNo,
  4856. }).Entity;
  4857. db.SaveChanges();
  4858. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4859. function.WriteLog(text, "设置商户信息");
  4860. }
  4861. return "success";
  4862. }
  4863. #endregion
  4864. #region 查询商户达标明细
  4865. public IActionResult SeeMerchantTradeDetail(string right)
  4866. {
  4867. ViewBag.RightInfo = RightInfo;
  4868. ViewBag.right = right;
  4869. return View();
  4870. }
  4871. [HttpPost]
  4872. public string SeeMerchantTradeDetailDo(string PosSn)
  4873. {
  4874. if (string.IsNullOrEmpty(PosSn))
  4875. {
  4876. return "请输入机具SN";
  4877. }
  4878. var result = "";
  4879. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  4880. if (pos.Id > 0)
  4881. {
  4882. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4883. if (mer.Id > 0)
  4884. {
  4885. var info = "";
  4886. var IsFirst = "";//是否首台机具
  4887. if (function.CheckNull(mer.MerIdcardNo).Contains("*") || function.CheckNull(mer.MerchantMobile).Contains("*") || function.CheckNull(mer.MerRealName).Contains("*") || string.IsNullOrEmpty(mer.MerRealName))
  4888. {
  4889. info = "机具" + PosSn + "所对应的商户未认证";
  4890. }
  4891. var merchantId = db.PosMerchantInfo.Where(m => m.MerIdcardNo == mer.MerIdcardNo && m.MerRealName == mer.MerRealName && m.MerchantMobile == mer.MerchantMobile).Min(m => m.Id);
  4892. // if (mer.Id <= merchantId)
  4893. // {
  4894. // IsFirst = "首台";
  4895. // }
  4896. // else
  4897. // {
  4898. // IsFirst = "非首台";
  4899. // }
  4900. if (pos.IsFirst == 1)
  4901. {
  4902. IsFirst = "首台";
  4903. }
  4904. else
  4905. {
  4906. IsFirst = "非首台";
  4907. }
  4908. var depositRreturn = db.MerchantDepositReturns.Where(m => m.MerchantId == mer.Id).OrderByDescending(m => m.CreateDate).FirstOrDefault() ?? new MerchantDepositReturns();
  4909. var IsOk = "";//是否达标
  4910. var timeInfo = "";
  4911. if (mer.StandardStatus == -2)
  4912. {
  4913. IsOk = "人工已退";
  4914. }
  4915. else
  4916. {
  4917. if (mer.StandardMonths < 10)
  4918. {
  4919. IsOk = "未达标";
  4920. }
  4921. if (mer.StandardMonths == 10)
  4922. {
  4923. IsOk = "已达标";
  4924. }
  4925. if (mer.StandardMonths >= 0 && mer.StandardStatus == -1)
  4926. {
  4927. IsOk = "达标失败";
  4928. }
  4929. if (mer.StandardStatus == 1 && depositRreturn.Status == 1)
  4930. {
  4931. IsOk = "已返还";
  4932. }
  4933. if (mer.StandardStatus == 101)
  4934. {
  4935. IsOk = "待领取达标奖";
  4936. }
  4937. if (mer.StandardStatus == 1 && depositRreturn.Status == 0)
  4938. {
  4939. IsOk = "达标奖发放中";
  4940. }
  4941. }
  4942. result += info + "\n";
  4943. result += IsFirst + "\n";
  4944. result += IsOk + "\n";
  4945. var BindingTime = pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  4946. var ActivationTime = pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  4947. result += "开机时间:" + BindingTime + "\n";
  4948. result += "激活时间:" + ActivationTime + "\n";
  4949. result += "商户姓名:" + mer.MerRealName + "\n";
  4950. if (pos.ActivationTime != null)
  4951. {
  4952. result += "明细:\n";
  4953. for (int i = 0; i < 12; i++)
  4954. {
  4955. var time = pos.ActivationTime.Value.AddMonths(i + 1).ToString("yyyyMM");//达标计算开始时间
  4956. timeInfo += "," + time;
  4957. }
  4958. timeInfo = timeInfo + ",";
  4959. var merTradeInfo = db.PosMerchantTradeSummay.Where(m => m.MerchantId == mer.Id && timeInfo.Contains("," + m.TradeMonth + ",")).ToList();
  4960. string[] month = timeInfo.TrimStart(',').TrimEnd(',').Split(',');
  4961. foreach (var item in month)
  4962. {
  4963. var tradeAmount = merTradeInfo.Where(m => m.TradeMonth == item).Sum(m => m.TradeAmount);
  4964. result += item + "交易额:" + tradeAmount + "\n";
  4965. }
  4966. }
  4967. }
  4968. else
  4969. {
  4970. return "未找到机具" + PosSn + "所对应的商户";
  4971. }
  4972. }
  4973. else
  4974. {
  4975. return "未找到机具" + PosSn;
  4976. }
  4977. return result;
  4978. }
  4979. #endregion
  4980. #region 指定文件Excel导出
  4981. public IActionResult ExportExcel(string right)
  4982. {
  4983. ViewBag.RightInfo = RightInfo;
  4984. ViewBag.right = right;
  4985. return View();
  4986. }
  4987. [HttpPost]
  4988. public string ExportExcelDo(string FileName, string Operator, string Sql, int Number = 0)
  4989. {
  4990. if (string.IsNullOrEmpty(FileName))
  4991. {
  4992. return "请输入文件名";
  4993. }
  4994. if (string.IsNullOrEmpty(Operator))
  4995. {
  4996. return "请输入后台操作人";
  4997. }
  4998. if (string.IsNullOrEmpty(Sql))
  4999. {
  5000. return "请输入SQL语句";
  5001. }
  5002. var SqlString = "";
  5003. if (Number == 0)
  5004. {
  5005. SqlString = Sql;
  5006. }
  5007. if (Number > 0)
  5008. {
  5009. SqlString = Sql + " LIMIT " + Number;
  5010. }
  5011. string[] Operators = Operator.Replace("\r", "").Replace("\n", ",").Split(',');
  5012. foreach (var item in Operators)
  5013. {
  5014. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == item && m.Status > -1);
  5015. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"" + Number + "\"}";
  5016. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  5017. }
  5018. return "success";
  5019. }
  5020. #endregion
  5021. #region 服务费返现注册查询
  5022. public IActionResult SeeMerchantAuthInfo(string right)
  5023. {
  5024. ViewBag.RightInfo = RightInfo;
  5025. ViewBag.right = right;
  5026. return View();
  5027. }
  5028. #endregion
  5029. #region 服务费返现注册查询
  5030. public JsonResult SeeMerchantAuthInfoDo(string RealName, string Mobile, string CertId, int page = 1, int limit = 30)
  5031. {
  5032. var query = db.UserFamilyMember.Where(m => m.Status > -1);
  5033. if (string.IsNullOrEmpty(RealName) && string.IsNullOrEmpty(Mobile) && string.IsNullOrEmpty(CertId))
  5034. {
  5035. Dictionary<string, object> objs = new Dictionary<string, object>();
  5036. return Json(objs);
  5037. }
  5038. else
  5039. {
  5040. if (!string.IsNullOrEmpty(RealName))
  5041. {
  5042. query = query.Where(m => m.Name == RealName);
  5043. }
  5044. if (!string.IsNullOrEmpty(Mobile))
  5045. {
  5046. query = query.Where(m => m.Mobile == Mobile);
  5047. }
  5048. if (!string.IsNullOrEmpty(CertId))
  5049. {
  5050. query = query.Where(m => m.IdCardNo.ToUpper() == CertId.ToUpper());
  5051. }
  5052. }
  5053. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5054. foreach (var subdata in query.ToList())
  5055. {
  5056. Dictionary<string, object> data = new Dictionary<string, object>();
  5057. if (subdata.Id > 0)
  5058. {
  5059. data["IsRegist"] = "已注册";
  5060. if (subdata.Status == 1)
  5061. {
  5062. data["IsAuth"] = "已认证";
  5063. data["Name"] = subdata.Name;
  5064. data["Mobile"] = subdata.Mobile;
  5065. data["IdcardNo"] = subdata.IdCardNo;
  5066. var linkCount = db.PosMerchantInfo.Count(m => m.MerRealName == subdata.Name && m.MerchantMobile == subdata.Mobile && m.MerIdcardNo.ToUpper() == subdata.IdCardNo.ToUpper());
  5067. data["Count"] = linkCount;
  5068. }
  5069. else
  5070. {
  5071. data["IsAuth"] = "未认证";
  5072. data["Name"] = "";
  5073. data["Mobile"] = subdata.Mobile;
  5074. data["IdcardNo"] = "";
  5075. data["Count"] = "";
  5076. }
  5077. }
  5078. else
  5079. {
  5080. data["IsRegist"] = "未注册";
  5081. data["IsAuth"] = "未认证";
  5082. data["Name"] = "";
  5083. data["Mobile"] = "";
  5084. data["IdcardNo"] = "";
  5085. data["Count"] = "";
  5086. }
  5087. dataList.Add(data);
  5088. }
  5089. Dictionary<string, object> obj = new Dictionary<string, object>();
  5090. obj.Add("code", 0);
  5091. obj.Add("msg", "");
  5092. obj.Add("count", dataList.Count);
  5093. obj.Add("data", dataList);
  5094. return Json(obj);
  5095. }
  5096. #endregion
  5097. #region 注销30天内恢复创客信息
  5098. public IActionResult RestoreUserInfo(string right)
  5099. {
  5100. ViewBag.RightInfo = RightInfo;
  5101. ViewBag.right = right;
  5102. return View();
  5103. }
  5104. [HttpPost]
  5105. public string RestoreUserInfoDo(string MakerCode)
  5106. {
  5107. var user = db.Users.FirstOrDefault(m => m.Status == -1 && m.MakerCode == MakerCode) ?? new Users();
  5108. if (user.Id == 0)
  5109. {
  5110. return "创客" + MakerCode + "不存在";
  5111. }
  5112. else
  5113. {
  5114. if (user.LogOutDate.Value.ToString("yyyyMM") == DateTime.Now.ToString("yyyyMM"))
  5115. {
  5116. user.Status = 0;
  5117. user.LogOutDate = null;
  5118. user.Mobile = user.Mobile.TrimEnd('d');
  5119. user.CertId = user.CertId.TrimEnd('d');
  5120. db.UserForMobile.Add(new UserForMobile()
  5121. {
  5122. Mobile = user.Mobile,
  5123. UserId = user.Id,
  5124. });
  5125. db.UserForMakerCode.Add(new UserForMakerCode()
  5126. {
  5127. MakerCode = user.MakerCode,
  5128. UserId = user.Id,
  5129. });
  5130. AddSysLog(user.Id.ToString(), "注销30天内恢复创客信息", "修改" + SysUserName + "_" + SysRealName);
  5131. db.SaveChanges();
  5132. }
  5133. else
  5134. {
  5135. return "创客" + MakerCode + "不满足恢复条件";
  5136. }
  5137. }
  5138. return "success";
  5139. }
  5140. #endregion
  5141. #region 码牌加密
  5142. public IActionResult QrCodeEncryption(string right)
  5143. {
  5144. ViewBag.RightInfo = RightInfo;
  5145. ViewBag.right = right;
  5146. return View();
  5147. }
  5148. [HttpPost]
  5149. public string QrCodeEncryptionDo(string SnNos)
  5150. {
  5151. string[] SnNo = SnNos.Replace("\r", "").Replace("\n", ",").Split(',');
  5152. string code = "";
  5153. string sn = "";
  5154. for (int a = 0; a < SnNo.Length; a++)
  5155. {
  5156. string start = SnNo[a];
  5157. for (int i = 0; i <= 9999; i++)
  5158. {
  5159. string num = i.ToString();
  5160. for (int j = 0; j < 4 - i.ToString().Length; j++)
  5161. {
  5162. num = "0" + num;
  5163. }
  5164. sn = dbconn.Encrypt3DES(start + num + function.get_Random(8), "l2k0b2#3");
  5165. sn = sn.Substring(0, sn.Length - 1);
  5166. }
  5167. code += System.Web.HttpUtility.UrlEncode(sn) + "<br />\n";
  5168. }
  5169. return "success" + "|" + code;
  5170. }
  5171. #endregion
  5172. #region 直营团队数据
  5173. public IActionResult Team1Info(string right)
  5174. {
  5175. ViewBag.RightInfo = RightInfo;
  5176. ViewBag.right = right;
  5177. return View();
  5178. }
  5179. #endregion
  5180. #region 直营团队数据
  5181. public JsonResult Team1InfoDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId, int page = 1, int limit = 30)
  5182. {
  5183. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  5184. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5185. string condition = " where 1=1";
  5186. var UserId = 0;
  5187. var bstart = "";
  5188. var bend = "";
  5189. var astart = "";
  5190. var aend = "";
  5191. if (!string.IsNullOrEmpty(MakerCode))
  5192. {
  5193. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  5194. UserId = user.Id;
  5195. }
  5196. if (!string.IsNullOrEmpty(BindingTime))
  5197. {
  5198. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5199. bstart = datelist[0] + " 00:00:00";
  5200. bend = datelist[1] + " 23:59:59";
  5201. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
  5202. }
  5203. if (!string.IsNullOrEmpty(ActivationTime))
  5204. {
  5205. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5206. astart = datelist[0] + " 00:00:00";
  5207. aend = datelist[1] + " 23:59:59";
  5208. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
  5209. }
  5210. if (!string.IsNullOrEmpty(PosFeeSelect))
  5211. {
  5212. if (PosFeeSelect == "0")
  5213. {
  5214. condition += " and tb.SeoKeyword is null";
  5215. }
  5216. else
  5217. {
  5218. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  5219. }
  5220. }
  5221. if (!string.IsNullOrEmpty(BrandId))
  5222. {
  5223. condition += " and tb.BrandId=" + BrandId;
  5224. }
  5225. DataTable dt = CustomerSqlConn.dtable("select wname,k.`Name`,PosSnType,PosSn,(CASE WHEN tb.SeoKeyword IS NULL AND tb.PrizeParams=0 THEN 0 ELSE tb.SeoKeyword END) SeoKeyword,TransferTime,BindingTime,ActivationTime,PrizeParams from (select (select Name from BusinessPartner where Id=(select PartnerId from BusinessPartnerPos where PosId=pos.Id and `Status`>-1 limit 1)) wname,BrandId,PosSnType,PosSn,(CASE WHEN BrandId not in(2,7,10,11) THEN ROUND(CAST(SeoKeyword AS DECIMAL)/100, 2) ELSE SeoKeyword end) SeoKeyword,TransferTime,BindingTime,ActivationTime,PrizeParams from PosMachinesTwo pos where BindingState=1 and `Status`>=-1 and BuyUserId=" + UserId + " and Id in (select PosId from BusinessPartnerPos)) tb left join KqProducts k on tb.BrandId=k.Id" + condition, conn);
  5226. foreach (DataRow item in dt.Rows)
  5227. {
  5228. Dictionary<string, object> curData = new Dictionary<string, object>();
  5229. curData.Add("wname", item["wname"].ToString()); //伙伴名称
  5230. curData.Add("Name", item["Name"].ToString()); //机具品牌
  5231. curData.Add("PosSn", item["PosSn"].ToString()); //机具Sn
  5232. curData.Add("SeoKeyword", item["SeoKeyword"].ToString()); //服务费
  5233. curData.Add("BindingTime", string.IsNullOrEmpty(item["BindingTime"].ToString()) ? "" : Convert.ToDateTime(item["BindingTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  5234. curData.Add("ActivationTime", string.IsNullOrEmpty(item["ActivationTime"].ToString()) ? "" : Convert.ToDateTime(item["ActivationTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  5235. dataList.Add(curData);
  5236. }
  5237. Dictionary<string, object> obj = new Dictionary<string, object>();
  5238. obj.Add("code", 0);
  5239. obj.Add("msg", "");
  5240. obj.Add("count", dataList.Count);
  5241. obj.Add("data", dataList);
  5242. return Json(obj);
  5243. }
  5244. #endregion
  5245. #region 直营团队数据导出
  5246. public IActionResult ExportTeam1InfoExcel(string right)
  5247. {
  5248. ViewBag.RightInfo = RightInfo;
  5249. ViewBag.right = right;
  5250. return View();
  5251. }
  5252. [HttpPost]
  5253. public string ExportTeam1InfoExcelDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId)
  5254. {
  5255. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  5256. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5257. var RealName = "";
  5258. string condition = " where 1=1";
  5259. var UserId = 0;
  5260. var bstart = "";
  5261. var bend = "";
  5262. var astart = "";
  5263. var aend = "";
  5264. if (!string.IsNullOrEmpty(MakerCode))
  5265. {
  5266. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  5267. UserId = user.Id;
  5268. RealName = user.RealName;
  5269. }
  5270. if (!string.IsNullOrEmpty(BindingTime))
  5271. {
  5272. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5273. bstart = datelist[0] + " 00:00:00";
  5274. bend = datelist[1] + " 23:59:59";
  5275. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
  5276. }
  5277. if (!string.IsNullOrEmpty(ActivationTime))
  5278. {
  5279. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5280. astart = datelist[0] + " 00:00:00";
  5281. aend = datelist[1] + " 23:59:59";
  5282. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
  5283. }
  5284. if (!string.IsNullOrEmpty(PosFeeSelect))
  5285. {
  5286. if (PosFeeSelect == "0")
  5287. {
  5288. condition += " and tb.SeoKeyword is null";
  5289. }
  5290. else
  5291. {
  5292. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  5293. }
  5294. }
  5295. if (!string.IsNullOrEmpty(BrandId))
  5296. {
  5297. condition += " and tb.BrandId=" + BrandId;
  5298. }
  5299. var Sql = "select wname '伙伴名称',k.`Name` '机具品牌',PosSn '机具Sn',(CASE WHEN tb.SeoKeyword IS NULL AND tb.PrizeParams=0 THEN 0 ELSE tb.SeoKeyword END) '服务费',DATE_FORMAT(BindingTime,'%Y-%m-%d %H:%i:%s') '绑定时间',DATE_FORMAT(ActivationTime,'%Y-%m-%d %H:%i:%s') '激活时间' from (select (select Name from BusinessPartner where Id=(select PartnerId from BusinessPartnerPos where PosId=pos.Id and `Status`>-1 limit 1)) wname,BrandId,PosSnType,PosSn,(CASE WHEN BrandId not in(2,7,10,11) THEN ROUND(CAST(SeoKeyword AS DECIMAL)/100, 2) ELSE SeoKeyword end) SeoKeyword,TransferTime,BindingTime,ActivationTime,PrizeParams from PosMachinesTwo pos where BindingState=1 and `Status`>=-1 and BuyUserId=" + UserId + " and Id in (select PosId from BusinessPartnerPos)) tb left join KqProducts k on tb.BrandId=k.Id" + condition;
  5300. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  5301. var FileName = MakerCode + RealName + "直营团队数据记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  5302. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  5303. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  5304. return "success";
  5305. }
  5306. #endregion
  5307. }
  5308. }